<?php
# index.php
#######################################
# HTTP Viewer Captcha Version © 2012 Scott Connell
# Created: 2012/10/04 (year/month/day)
# License: Free for personal and commercial use.
# Terms: Redistribution/republishing strictly forbidden.
# Source: http://scottconnell.orgfree.com
#######################################
include_once("config.php");
function printForm()
{
global $domain,$options;
if(!isset($domain))
{
$domain = "http://";
}
$action = $_SERVER["PHP_SELF"];
$timenow = time();
print <<<ENDHTM
<form method="post" action="$action">
<p>URL <input type="text" name="www" size="30" value="$domain" /></p>
<p>Method <select name="methods">
ENDHTM;
foreach($options as $o)
{
print "<option value=\"$o\">$o</option>\n";
}
print <<<ENDHTM
</select></p>
<p><img src="captcha.php?$timenow" alt="Loading image..." /></p>
<p><input type="text" name="security" size="3" value="" />
<input type="submit" value="Send" /></p>
</form>
ENDHTM;
}
function fetchURL($o)
{
global $domain;
$xHost = parse_url($domain, PHP_URL_HOST);
if(!$xPath = @parse_url($domain, PHP_URL_PATH))
{
$xPath = "/";
}
if(!$xQuery = @parse_url($domain, PHP_URL_QUERY))
{
$xPage = $xPath;
}
else
{
$xPage = $xPath . "?" . $xQuery;
}
$open_socket = @fsockopen($xHost, "80", $errno, $errstr, 30);
if($open_socket)
{
$message = $o ." ". $xPage . " HTTP/1.1\r\n";
$message .= "Host: $xHost\r\n";
$message .= "User-Agent: " . $_SERVER["HTTP_USER_AGENT"] . "\r\n";
$message .= "Connection: close\r\n\r\n";
fputs($open_socket, "$message\n");
$response = "";
while ($read_text = fgets($open_socket, 4096))
{
$response .= htmlspecialchars($read_text, ENT_QUOTES);
}
return $response;
}
}
$options = array('GET','HEAD','POST','OPTIONS','TRACE','BASELINE_CONTROL','CHECKIN',
'CHECKOUT','CONNECT','COPY','DELETE','INVALID','LABEL','LOCK','MERGE','MKACTIVITY','MKCOL',
'MKWORKSPACE','MOVE','PATCH','PROPFIND','PROPPATCH','PUT','REPORT','UNCHECKOUT','UNLOCK',
'UPDATE','VERSION_CONTROL');
if(isset($_REQUEST['www']))
{
$domain = $_REQUEST['www'];
if($_REQUEST['security'] == $_COOKIE['UID'])
{
if(!$xHost = parse_url($domain, PHP_URL_HOST))
{
$title = "Error: Could not parse URL";
include_once($header_path);
printForm();
exit(include_once($footer_path));
}
if(!$fp = @fsockopen($xHost, 80, $errno, $errstr, 30))
{
$title = "Error: Could not connect to $xHost";
include_once($header_path);
printForm();
exit(include_once($footer_path));
}
else
{
$title = "HTTP Viewer";
include_once($header_path);
printForm();
$result = fetchURL($_REQUEST['methods']);
print "<h2>". $_REQUEST['methods'] ." Request</h2>\n";
print "<pre>$result</pre>\n\n";
}
}
else
{
$title = "Error: Security Code does not match";
include_once($header_path);
printForm();
exit(include_once($footer_path));
}
}
else
{
$title = "HTTP Viewer";
include_once($header_path);
printForm();
}
include_once($footer_path);
?>