PHP版WebRoller

pack()の使い方はよく知らないので適当。動くことは動いた。


<?php
$host = $_REQUEST["host"];
$port = $_REQUEST["port"];

function roll($host, $port) {
$fp = fsockopen($host, $port, $errno, $errstr, 30);

if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = pack("n", 0x0008)."RollOver";
fwrite($fp, $out);
$rc = fgets($fp, 128);

if($rc == pack("n", 0x0002)."OK") {
echo "Roll over signal acknowledged by remote appender.<br>";
} else {
echo "Unexpected return code $rc from remote entity.<br>";
}

fclose($fp);
}
}
?>
<html>
<head>
<title>Web Roller</title>
</head>
<body>
<?php
if ($host && $port) {
roll($host, $port);
}
?>
<form action="roller.php" method="post">
=>java org.apache.log4j.varia.Roller 
<input type="text" name="host" value="localhost">
<input type="text" name="port" value="8938"><br>
<input type="submit" value="実行">
</form>
</body>
</hdml>