* @license GPL * @copyright (c) 2012 Andreas Schamanek * */ $version = 'netstat-kiss.php by Andreas Schamanek ~ v0.02 ~ 2019-01-28 ~ GPL licensed'; /* --- Settings --- */ // // Either change settings here, or, better, copy them to a file called // netstat.conf.php and make sure the file is readable for the web server // (e.g. chmod 644 netstat.conf.php) // $checks (use pipes (|) with care ;) // syntax: ' host or IP to check | port | description ' // if $port = 'ping' an ICMP ping will be executed // if $port = 'headline' $host is printed as a headline $checks = array( 'Examples testing localhost |headline', 'localhost | ping| ICMP ping (ping)', 'localhost | 80 | WWW server (port 80)', '127.0.0.2 | 443 | WWW server (SSL, port 443)', '127.0.0.1 | 22 | SSH server (port 22)', '127.0.0.3 | 21 | FTP server (port 21)', ); $configfile = 'netstat.conf.php'; $title = 'Our Network Status'; $headline = $title; error_reporting(0); $alertfile='netstat.txt'; // will be shown ahead if readable $ping_command = 'ping -c3 -w1 -q'; // maybe try 'ping -l3 -c3 -w1 -q' $ping6_command = 'ping6 -c3 -w1 -q'; $timeout = 6; // fsockopen timeout, leave it as it is :) $online = 'Online'; $offline = 'Offline'; $datetime = 'l, F j, Y, H:i:s T'; // HTML/page header $htmlheader = << $title
EOH; // HTML/page footer $htmlfooter = "
\n\n"; /* That's it */ // ------------------------------------------------- main part of script // including $configfile if available if (file_exists($configfile) && is_readable($configfile)) @include($configfile); // output HTML/page header echo $htmlheader; // headline, date and time and start of table echo "

$headline

\n"; if ($datetime) echo '

as of ' . date($datetime) . "

\n"; // show the contents of $alertfile if it is readable and larger than 7 bytes if (file_exists($alertfile)) { clearstatcache(true, $alertfile); if ((is_readable($alertfile) && (filesize($alertfile) > 7))) { echo "
\n"; @include($alertfile); echo "
\n"; } } // flush output buffers (if any)/send content to browser @ob_flush(); @flush(); echo '' . "\n"; // main loop of checks foreach ($checks as $check) { $status = $offline; // default state $diagnostics = ''; // mouse-over for tooltips $output = true; // print a line or print no line list($host,$port,$description) = explode('|',"$check||"); // the 2 extra '|'s are to avoid notices about undefined offsets $host = trim($host); $port = trim($port); switch ($port) { case '': // ignore lines with empty or no "ports", and ignore ... case (substr($port,0,1)=='-'): // negative ports, '-ping', and // any "port" starting with '-' is considered a disabled check $output = false; break; case 'headline': // print a headline within the status table // we enclose it with invisible
== == for nicer text output echo '\n"; $output = false; break; case 'ping': // do an ICMP ping $ping=exec("$ping_command $host",$pingoutput,$pingreturn); // Continues on into ping6 as they share all but the command. case 'ping6': // do an ICMP IPv6 ping if (!isset($ping)) { $ping=exec("$ping6_command $host",$pingoutput,$pingreturn); } if(strlen($ping)>10) { // strlen($ping)>10 works around a bug in Debian ping (", pipe 3") // https://bugs.debian.org/456192 $status = $online; $diagnostics = "$ping :: $pingreturn"; } else $diagnostics = "$ping :: $pingreturn"; unset($ping); break; default: // look if a TCP connection to port can be opened $time_start = microtime(true); $fp = @fsockopen($host, $port, $errno, $errstr, $timeout); $time_end = microtime(true); $time = number_format(($time_end - $time_start)*1000,1); if ($fp) { // fsockopen worked, service is online $status = $online; $diagnostics = "$time ms"; fclose($fp); } else if ($errno<0) { $diagnostics = "errno=$errno; Host unknown?"; } else { $diagnostics = $errstr; } } // output results if ($output) echo "\n"; // flush output buffers (if any)/send content to browser @ob_flush(); @flush(); } echo "
' . '' . $host . '' . "
$description$status
\n"; // output $version and HTML/page footer if (!empty($version)) echo "

$version

\n"; echo "$htmlfooter\n"; /* * License * * This script is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This script is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this script; if not, write to the * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307 USA * History * * 0.01 * 2012-08-05 KISSified netstat-kiss.php based on netstat.php v0.15 * 0.02 * 2019-01-28 merged minor tweaks from netstat.php v0.16 * */