Skip to content

Instantly share code, notes, and snippets.

@edwinm
Created November 25, 2009 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edwinm/243066 to your computer and use it in GitHub Desktop.
Save edwinm/243066 to your computer and use it in GitHub Desktop.
Logs in to US Robotics router and turns on computer with Wake-on-lan
<html>
<head>
<title>Power on</title>
</head>
<body>
<h3>Power on</h3>
<p>Powering on machine <?php echo $mac ?></p>
<?php
//$host = "node-c-5b2f.a2000.nl";
$host = "node-c-5b07.a2000.nl";
$port = 88;
$passwd = "zip";
$match1 = "<p><INPUT TYPE=HIDDEN VALUE=\"([^\"]*)\" NAME=RC><INPUT TYPE=HIDDEN VALUE=\"root\" NAME=ACCT><INPUT TYPE=HIDDEN VALUE=\"([^\"]*)\" NAME=PSWD>Enter System Password<BR>";
$match2 = "<BR><INPUT TYPE=PASSWORD NAME=URL SIZE=9 MAXLENGTH=9><BR><BR>Then Press the<br>&quot;Log in&quot; button<p><INPUT TYPE=HIDDEN VALUE=\"([^\"]*)\" NAME=KEY><INPUT TYPE=HIDDEN VALUE=\"([^\"]*)\" NAME=htm>";
$request = "GET /menu.htm HTTP/1.0\r\n\r\n";
$fp = fsockopen( $host, $port, $errno, $errstr, 30 );
if ( !$fp ) {
echo "$errstr ($errno)<br>\n";
} else {
fputs( $fp, $request );
while ( !feof($fp ) ) {
$in = fgets( $fp, 256 );
//echo nl2br( htmlspecialchars( $in ) );
if ( ereg( $match1, $in, $regs ) ) {
$rc = $regs[1];
$pswd = $regs[2];
}
if ( ereg( $match2, $in, $regs ) ) {
$key = $regs[1];
$htm = $regs[2];
}
}
fclose( $fp );
}
$login = "RC=".urlEncode($rc)."&ACCT=root&PSWD=".urlEncode($pswd)."&URL=".urlEncode($passwd)."&KEY=".urlEncode($key)."&htm=".urlEncode($htm);
$loginLength = strlen( $login );
$post = "POST /cgi-bin/logi HTTP/1.0\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: $loginLength\r\n\r\n$login";
//echo "[$post]<br>\n";
$fp = fsockopen( $host, $port, $errno, $errstr, 30 );
if ( !$fp ) {
echo "$errstr ($errno)<br>\n";
} else {
fputs( $fp, $post );
$in = fgets( $fp, 256 );
if ( !ereg( "HTTP/[0-9.]+ 200 OK", $in, $regs ) ) {
echo "Error!";
}
fclose( $fp );
}
$time = time();
$powerup = "GET /cgi-bin/misc?RC=@&XX=00FC&lm=Y&LM=$mac&ZT=$time HTTP/1.0\r\n\r\n";
//echo "[$powerup]<br>\n";
$fp = fsockopen( $host, $port, $errno, $errstr, 30 );
if ( !$fp ) {
echo "$errstr ($errno)<br>\n";
} else {
fputs( $fp, $powerup );
$in = fgets( $fp, 256 );
if ( !ereg( "HTTP/[0-9.]+ 200 OK", $in, $regs ) ) {
echo "Error!";
} else {
echo "<p>Done</p>";
}
fclose( $fp );
}
//function urlEncode( $str ) {
//$str = rawurlencode( $str );
//$str = str_replace( "+", "%20", $str );
//return $str;
//}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment