electrum-bitcoinprivate/server/electrum.php

51 lines
1.6 KiB
PHP
Raw Normal View History

2011-11-09 12:44:34 -08:00
<?
2011-11-22 13:26:36 -08:00
function do_query($q){
$q .= "#";
2011-11-09 12:44:34 -08:00
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
}
$result = socket_connect($socket, 'ecdsa.org', 50000);
if ($result === false) {
echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
}
2011-11-22 13:26:36 -08:00
socket_write($socket, $q, strlen($q));
2011-11-09 12:44:34 -08:00
$buf='ex';
if (false == ($bytes = socket_recv($socket, $buf, 2048, MSG_WAITALL))) {
echo "socket_recv() failed; reason: " . socket_strerror(socket_last_error($socket)) . "\n";
}
socket_close($socket);
2011-11-22 13:26:36 -08:00
return $buf;
}
2011-11-23 02:16:36 -08:00
$pass = '';
2011-11-22 13:26:36 -08:00
$query = $_POST['q'];
if( !$query ) {
echo "Welcome to <a href=\"http://ecdsa.org/electrum/\">Electrum</a><br/>";
echo "This server uses ports 80 (http), 443 (https) and 50000 (raw)<br/>";
echo "Port 50000 is recommended for efficiency.<br/><br/>";
echo "Server status:<br/>";
echo "Number of blocks: ". do_query( "('b','')" ) ."<br/>";
2011-11-23 02:16:36 -08:00
echo "Current load: ". do_query( "('load','$pass')" ) ."<br/><br/>";
2011-11-22 13:26:36 -08:00
echo "List of active servers:<br/>\n";
$str = do_query( "('peers','')" );
2011-11-23 02:16:36 -08:00
// preg_match_all("/\('(.*?)', '(\d+\.\d+\.\d+\.\d+)'\)/",$str,$matches,PREG_SET_ORDER);
preg_match_all("/\('(.*?)', '(.*?)'\)/", $str, $matches, PREG_SET_ORDER);
2011-11-22 13:26:36 -08:00
echo "<ul>";
2011-11-23 02:16:36 -08:00
foreach( $matches as $m){
echo "<li><a href=\"http://" . $m[2] . "/electrum.php\">" . $m[2]."</a> <small>[".$m[1]."]</small></li>";
2011-11-22 13:26:36 -08:00
}
echo "</ul>";
2011-11-09 12:44:34 -08:00
2011-11-22 13:26:36 -08:00
} else {
$buf = do_query($query);
echo $buf;
}
2011-11-09 12:44:34 -08:00
?>