function main() { global $argv, $argc; if ($argc != 2) { print "Usage: " . $argv[0] . " [port]\n"; exit; } $port = $argv[1]; error_reporting(E_ALL); /* Allow the script to hang around waiting for connections. */ set_time_limit(0); /* Turn on implicit output flushing so we see what we're getting * as it comes in. */ ob_implicit_flush(); if (($sock = socket_create_listen($port, 10)) === false) { print "Cannot listen on {$port}!\n"; exit; } $open = array(); while (true) { // Accept a connection and receive a file descriptor $sock_array = array($sock); $num_changed_sockets = socket_select($sock_array, $write = NULL, $exc = NULL, 0, 100000); // 0.1 sec if ($num_changed_sockets == 1) { $fd = socket_accept($sock); socket_getpeername($fd, $remoteAddr, $remotePort); log_dictLog("Client connected from {$remoteAddr}"); socket_write($fd, "220 dict protocol implementation for DEX\r\n"); array_push($open, $fd); } // Duplicate $open and perform I/O on each available handle $dup = $open; if (count($dup)) { $num_changed_sockets = socket_select($dup, $write = NULL, $exc = NULL, 0, 100000); // 0.1 sec } foreach ($dup as $available_fd) { if (handle_line($available_fd) != 0) { // Remove $available_fd from $open $pos = array_search($available_fd, $open); if ($pos !== false) { array_splice($open, $pos, 1); } } } } }
require 'inc.php'; ?> <CENTER> <?php if (is_file($status_file)) { $file = file_get_contents($status_file); } if (!$file) { echo "<CENTER><FONT COLOR=\"red\" SIZE=+2>Failed to open Status file "; echo "<br /><br /><br /><img src=\"loading.gif\"></FONT></CENTER><BR>\n"; die; } $line = explode("}", $file); for ($x = 0; $x < count($line); $x++) { handle_line($line[$x]); } ?> <?php if (is_array($hlist)) { foreach (array_keys($hlist) as $hkey) { // Print the number of hosts in the different states if (isset($hlist[$hkey]["host"]["status"])) { if ($hlist[$hkey]["host"]["status"] == "0") { $hlist[$hkey]["host"]["status"] = "UP"; } if ($hlist[$hkey]["host"]["status"] == "1") { $hlist[$hkey]["host"]["status"] = "DOWN"; } if ($hlist[$hkey]["host"]["status"] == "2") {