Dear epimeth,
please excuse me for not responding to your posting, but I was out of office for some days.
I post the code of the scripts ( very ugly 🙂 ) , maybe you can have a look.
<<<<Main script: execute.php:>>>>
<?php
$ReqBody = "";
$URI = "";
$URL = "";
$Hst = "";
$test= 0;
$RemoteHostAddr = $REMOTE_ADDR;
while (list($key, $val) = each($HTTP_GET_VARS)) {
if ($ReqBody && ($test== 0)) { $ReqBody.= "&"; }
if ($key == "url"){
$length = (strlen($val)-3);
$val = substr($val, 1, $length);
$URL = ereg_replace("'http://", "", $val);
$URL = ereg_replace("'", "", $URL);
$Hst = substr($URL, 0, strpos($URL, "/"));
$URI = strstr($URL, "/");
$ReqBody.= $URI."?";
$test = 1;
}
else {
if ($key == "pushurl"){
$length = (strlen($val)-4);
$val = substr($val, 2, $length);
$PushURL = urlencode($val);
}
else {
$ReqBody.= $key."=".urlencode($val);
$test = 0;
}
}
}
// echo $ReqBody;
// echo $RemoteHostAddr;
include("switchit.php");
include("pushit.php");
$filename = './execute.log';
if (file_exists($filename)) {
$handle = fopen($filename, "a");
}
else {
print " The logfile $filename could not be opened\n";
print "Trying to create new log file\n";
$datum = date(" F j, Y, g:i a");
$today = "Date: $datum\n\n";
$handle=fopen($filename,"w+");
fwrite($handle, $today);
fclose($handle);
$handle = fopen($filename, "a");
};
$Result = @SwitchIt($Hst, $ReqBody);
if (isset($Result["errno"])) {
$errno = $Result["errno"]; $errstr = $Result["errstr"];
switch ($errno) {
case 0:
$val = "Unknown Host $Hst\n";
print "$val";
fwrite($handle, $val);
break;
case 110:
$val = "Connection to Host $Hst timed out\n";
print "$val";
fwrite($handle, $val);
break;
case 111:
$val = "Host $Hst refuses connection\n";
print "$val";
fwrite($handle, $val);
break;
case 113:
$val = "Phone $Hst unreachable\n";
print "$val";
fwrite($handle, $val);
break;
default:
$val = "Error $errno\n $errstr\n";
print "$val";
fwrite($handle, $val);
fclose($handle);
exit;
}
}
else {
while (list($key, $val) = each($Result)) {
fwrite($handle, ("Switch: ".$val));
}
// echo "\r\nLights switched\r\n";
fwrite($handle, ("\nPushurl: ".$PushURL."\n"));
$PushResult = @pushit($PushURL,$RemoteHostAddr);
while (list($key, $val) = each($PushResult)) {
fwrite($handle, ("Push: ".$val));
}
};
fclose($handle);
?>
<<<Funktion pushit.php:>>>
<?php
function PushIt($PushUrl, $Host) {
$User = "service";
$Pass = "pushit";
// User password pair encryption
$userpass = $User.":".$Pass
;
$wwwpass = base64_encode($userpass);
// Form up the request body
$ReqBody =
"XML=%3CCiscoIPPhoneExecute%3E%0D%0A%09%3CExecuteItem+URL%3D%22".$PushUrl."%22%2F%3E%0D%0A%3C%2FCiscoIPPhoneExecute%3E%0D%0A\r\n";
// echo $ReqBody;
$ContentLength = strlen($ReqBody);
// Generate the request header
$ReqHeader =
"POST /CGI/Execute HTTP/1.1\r\n".
"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint, /\r\n".
"Accept-Language: de\r\n".
"Content-Type: application/x-www-form-urlencoded\r\n".
"Accept-Encoding: gzip,deflate\r\n".
"User-Agent: NOVApush/0.1\r\n".
"Host: $Host\r\n".
"Content-Length: $ContentLength\r\n".
"Connection: Keep-Alive\r\n".
"Cache-Control: no-cache\r\n".
"Authorization: Basic $wwwpass\r\n\n".
"$ReqBody\r\n";
// Open the connection to the host
$PushSocket = fsockopen($Host, 80, &$errno, &$errstr);
if (!$PushSocket) {
$Result["errno"] = $errno;
$Result["errstr"] = $errstr;
echo "<B>Error $errno</B> $errstr";
return $Result;
}
$idx = 0;
fputs($PushSocket, $ReqHeader);
while (!feof($PushSocket)) {
$Result[$idx++] = fgets($PushSocket, 128);
}
return $Result;
}
?>
<<<<Funktion switchit.php:>>>>
<?php
function SwitchIt($Host, $lparm) {
/ Generate the request header
/
$ReqHeader =
"GET $lparm HTTP/1.1\r\n".
"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, /\r\n".
"Accept-Language: de\r\n".
"Accept-Encoding: gzip, deflate\r\n".
"User-Agent: PushIt/0.1\r\n".
"Host: $Host\r\n".
"Connection: close\r\n\r\n";
// "Connection: Keep-Alive\r\n\r\n";
/ Open the connection to the host
/
$socket = fsockopen($Host, 80, &$errno, &$errstr, 3);
if (!$socket) {
$Result["errno"] = $errno;
$Result["errstr"] = $errstr;
return $Result;
}
$idx = 0;
fputs($socket, $ReqHeader);
while (!feof($socket)) {
$Result[$idx++] = fgets($socket, 128);
}
return $Result;
}
?>
thank you for your help
best regards
Andreas