Here is msproxy.php from the former umapper googlegroups files repository.
<?php
// MaPoint Credentials
$username = "134571";
$password = "sddl349>Jutm.4";
$auth = array(
"nonce" => "",
"qop" => "",
"realm" => "",
"count" => 0
);
if (isset($_POST["endpoint"]))
{
// get request parameters
$request = stripslashes($_POST["data"]);
$name = $_POST["name"];
$endpoint = $_POST["endpoint"];
// extract host and uri
preg_match("/(^http:\/\/|^)([\w.]+)(\S+)/i", $endpoint, $matches) or die("Incorrect endpoint url: $endpoint");
$proto = $matches[1];
$host = $matches[2];
$uri = $matches[3];
// check protocol
if ($proto != "http://" && $proto != "") die("Incorrect endpoint protocol, need http://");
if ($request != "")
{
// replace [CLIENT_IP] with actual ip
$request = str_replace("[CLIENT_IP]", getRealIpAddr(), $request);
$result = postRequest($request, $name);
if (!$result)
{
$result = postRequest($request, $name);
if (!$result)
{
die("Can't post data\n");
}
}
}
else
{
$result = restRequest();
if (!$result)
{
die("Invalid request.");
}
}
print "$result";
}
function postRequest($request, $name)
{
global $host, $uri;
// calculate valid response
$auth_header = getAuthHeader("POST");
$req = "POST $uri HTTP/1.1\r\n";
$req .= "Host: $host\r\n";
$req .= "Connection: Close\r\n";
if (strlen($auth_header) > 0) $req .= "Authorization: $auth_header\r\n";
$req .= "Content-Type: text/xml; charset=utf-8\r\n";
$req .= "Content-Length: " . strlen($request) . "\r\n";
$req .= "SOAPAction: \"" . $name . "\"\r\n";
$req .= "\r\n";
$req .= $request;
$result = sendAndRecieve($host, $req);
if (!$result) return 0;
// get status
if (!preg_match("/HTTP\/1.1 (\d\d\d) \w+/", $result, $matches)) return 0;
$status = $matches[1];
if ($status == 401)
{
if (!getNonce($result))
{
die ("Unable to get auth info!\n");
}
return 0;
}
else
{
// return only bottom part, response content
$parts = explode("\r\n\r\n", $result);
return $parts[1];
}
}
function restRequest()
{
global $host, $uri;
$req = "GET $uri HTTP/1.1\r\n";
$req .= "Host: $host\r\n";
$req .= "Connection: Close\r\n";
$req .= "\r\n";
$result = sendAndRecieve($host, $req);
if (!$result) return 0;
// get status
if (!preg_match("/HTTP\/1.1 (\d\d\d) \w+/", $result, $matches)) return 0;
$status = $matches[1];
if ($status != 200)
{
return 0;
}
// return response body
$parts = explode("\r\n\r\n", $result);
return $parts[1];
}
// perfomes a simple request without authentication to get the nonce
function getNonce($result)
{
global $auth;
if (!$result) return 0;
// parse result
$pattern = '/(\w+)="(\w+)"/';
if (!preg_match_all($pattern, $result, $matches))
{
return 0;
}
$names = $matches[1];
$values = $matches[2];
for ($idx = 0; $idx < count($names); $idx++)
{
$auth[$names[$idx]] = $values[$idx];
}
// back to 0
$auth["count"] = 0;
return 1;
}
// calculates valid auth header for digest authentication
function getAuthHeader($type)
{
global $username, $password;
global $auth;
global $uri;
if ($auth["nonce"] == "") return "";
// calculate cnonce and ncount
$cnonce = substr(md5(time()), 16);
$ncount = str_pad(dechex(++$auth["count"]), 8, "0", STR_PAD_LEFT);
$str = "Digest ";
$str .= "username=\"" . $username . "\", ";
$str .= "realm=\"" . $auth["realm"] . "\", ";
$str .= "nonce=\"" . $auth["nonce"] . "\", ";
$str .= "qop=\"" . $auth["qop"] . "\", ";
$str .= "uri=\"" . $uri . "\", ";
// calculate response
$ha1 = md5($username . ":" . $auth["realm"] . ":" . $password);
$ha2 = md5($type . ":" . $uri);
$response = md5($ha1 . ":" . $auth["nonce"] . ":" . $ncount . ":" . $cnonce . ":" . $auth["qop"] . ":" . $ha2);
$str .= "response=\"" . $response . "\", ";
$str .= "nc=\"" . $ncount . "\", ";
$str .= "cnonce=\"" . $cnonce . "\"";
return $str;
}
// send the data to socket and recives the answer
function sendAndRecieve($host, $request)
{
$fp = fsockopen($host, 80, $errno, $errstr, 30);
if (!$fp)
{
die ("Can't open socket to $host:80");
}
fwrite($fp, $request);
$answer = "";
while (!feof($fp))
{
$answer .= fgets($fp, 128);
}
fclose($fp);
return $answer;
}
// find out the real ip address
function getRealIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}
?>