Log in

View Full Version : php server status page?



munkynpunky
11-02-2006, 07:06 PM
Hey,

I have three different servers, and I want to have a status page to show that services such as POP3, SMTP, HTTP, etc etc would be shown as active or failed...

could anyone point me in the correct direction please?

ItsMeOnly
11-02-2006, 07:35 PM
well, basically it's a better job for a perl script. Either way, you didn't specify platform you'll be running the script on. That has to be said, because Windoze handles that different than UNIX/Linux

Twey
11-02-2006, 07:45 PM
well, basically it's a better job for a perl script.Why? PHP is quite capable of doing it.
Either way, you didn't specify platform you'll be running the script on. That has to be said, because Windoze handles that different than UNIX/LinuxNo, PHP glosses over the differences quite nicely.
<?php
$servers = array (http://www.php.net/array)(
'Server One' => 'server1.com',
'Server Two' => 'server2.com',
'Server Three' => 'server3.com'
);

$services = array(
'SMTP' => 25,
'HTTP' => 80,
'POP' => 110
);

foreach (http://www.php.net/foreach)($servers as $svrName => $host) {
?>
<table class="serviceTable">
<tr>
<th colspan="2" class="serverName">
<?php echo (http://www.php.net/echo)($svrName); ?>
</th>
</tr>
<?php
foreach($services as $svcName => $port) {
$status = 'Available';
$f;
if(!($f = fsockopen (http://www.php.net/fsockopen)($host, $port, $errno, $errstr, 3)))
// The number above is a timeout. A bigger
// number will result in better accuracy but
// longer page loading time.
$status = 'Unavailable';
else fclose (http://www.php.net/fclose)($f);
// The connection worked; we don't need to
// do anything else with the socket, so we
// close it.
?>
<tr>
<td class="serviceName">
<?php echo($svcName); ?>
</td>
<td class="serviceStatus">
<?php echo($status); ?>
</td>
</tr>
<?php
}
?>
</table>
<?php
}
?>Untested.

munkynpunky
11-02-2006, 08:13 PM
oh sorry, its a linux Fedora Core VPS with webfusion (http://www.webfusion.co.uk/virtual-private-servers/fusion-value-linux/)..

munkynpunky
11-02-2006, 08:29 PM
excellent thank you, What other port numbers would be useful?

munkynpunky
11-02-2006, 08:32 PM
scrub that, found this (http://www.webopedia.com/quick_ref/portnumbers.asp)

Twey
11-02-2006, 08:46 PM
Ouch. If you're going to check all those, it might be wise to just display/parse the output of nmap (http://insecure.org/nmap/index.html).

munkynpunky
11-02-2006, 08:58 PM
hmm, i'm trying to check mysql, but 118 158 and 3006 dont work.. any ideas?

munkynpunky
11-02-2006, 09:03 PM
no i dont want them all lol... just FTP, HTTP, SMTP, POP3, Mysql and shoutcast

munkynpunky
11-02-2006, 09:06 PM
hmm, i'm trying to check mysql, but 118 158 and 3006 dont work.. any ideas?

done lol

munkynpunky
11-02-2006, 09:07 PM
although shoutcast is active but not showing correctly...

ports 8000 and 8001..

any ideas?

munkynpunky
11-02-2006, 09:29 PM
nope, actually mysql and shoutcast isnt reporting correctly.. any idea?

Twey
11-02-2006, 10:12 PM
You should note that the ports shown on that list are only defaults; they may not be the same on your server.

Also, shoutcast is (as far as I know; I'm no expert in this area) a datagram protocol. That is to say, it's connectionless. This method won't work with it. I'm not entirely sure how one would check a datagram service. Perhaps send a packet and see if it responds?

munkynpunky
11-02-2006, 10:13 PM
oh ok, stupid question, how would i know what port the mysql server is using?

Cheers
drew

ItsMeOnly
11-03-2006, 12:35 PM
$services = array(
'SMTP' => 25,
'HTTP' => 80,
'POP' => 110
);

Hummps, I guess I'm always step ahead of the question, of course I stand corrected, but I was thinking more about checking if daemons are running of course, not port scan.

Twey
11-03-2006, 03:45 PM
oh ok, stupid question, how would i know what port the mysql server is using?If you don't specify it when you connect, it's the default.
I was thinking more about checking if daemons are running of course, not port scan.Checking if the port is open is probably one of the easiest ways of checking if the daemon is running. Failing that (and if the script was running on the same machine, which we know is not the case, thus rendering this approach impossible), it may be necessary to look for the daemon's lock file. However, Perl is not required, and indeed I can think of very few cases where Perl would be required over PHP (although the job may at times be made easier by a module).