Log in

View Full Version : [TUT] Making a Server Status/ System Check page



-::Mr.Dave::-
21-09-2006, 03:50 PM
Today i bring to you my first piece of php work which i find to be quite nice.

It may not be the hardest thing to do but some people will like this

This is an adaption of a simple free existing script but vastly improved and styles so using images instead of words to show online services and offline services and it has had more added to it

Example: http://www.xtremehosts.co.uk/server

First off start by opening up a blank notepad

Then copy and paste this into it:

<style type="text/css">
<!--
.style3 {
font-family: verdana;
font-size: 12px;
}
-->
</style>
<p class="style3"> Use this page to check the status of any system on our server</p>
<p class="style3">Server Status:<br />
</p>
<?php
//You can replace the domain with an IP if you wish
$site = "Your IP Goes here";
$http = fsockopen($site, 80);
$ftp = fsockopen($site, 21);
$pop3 = fsockopen($site, 110);
$cPanel = fsockopen($site, 2082);
$WHM = fsockopen($site, 2086);
if ($http) {
$status .= '<p><font face="Verdana" size="2">Http Status: <img src="/images/ball_green.gif"></p>';
}
else {
$status .= '<p><font face="Verdana" size="2">Http Status: <img src="/images/ball_red.gif"></p>';
}
if ($ftp) {
$status .= '<p><font face="Verdana" size="2">FTP Status: <img src="/images/ball_green.gif"></p>';
}
else {
$status .= '<p><font face="Verdana" size="2">FTP Status: <img src="/images/ball_red.gif"></p>';
}
if ($pop3) {
$status .= '<p><font face="Verdana" size="2">POP3/SMTP Status: <img src="/images/ball_green.gif"></p>';
}
else {
$status .= '<p><font face="Verdana" size="2">POP3/SMTP Status: <img src="/images/ball_red.gif"></p>';
}
if ($cPanel) {
$status .= '<p><font face="Verdana" size="2">cPanel Status: <img src="/images/ball_green.gif"></p>';
}
else {
$status .= '<p><font face="Verdana" size="2">cPanel Status: <img src="/images/ball_red.gif"></p>';
}
if ($WHM) {
$status .= '<p><font face="Verdana" size="2">WHM Status: <img src="/images/ball_green.gif"></p>';
}
else {
$status .= '<p><font face="Verdana" size="2">WHM Status: <img src="/images/ball_red.gif"></p>';
}
echo("$status");

?>


Ok now the breakdown

This code is the IP/Domain of the server we are going to check:

$site = "Your IP Goes here";

This code checks the status of each port. For example we have Port 80 and Port 21 which are http and Ftp. You can have it check any Port on the server but in this it checks:
HTTP
FTP
POP3/SMTP
cPanel
WHM

$http = fsockopen($site, 80);
$ftp = fsockopen($site, 21);
$pop3 = fsockopen($site, 110);
$cPanel = fsockopen($site, 2082);
$WHM = fsockopen($site, 2086);

This part of the code displays the results of the check

if ($http) {
$status .= '<p><font face="Verdana" size="2">Http Status: <img src="/images/ball_green.gif"></p>';
}
else {
$status .= '<p><font face="Verdana" size="2">Http Status: <img src="/images/ball_red.gif"></p>';
}
if ($ftp) {
$status .= '<p><font face="Verdana" size="2">FTP Status: <img src="/images/ball_green.gif"></p>';
}
else {
$status .= '<p><font face="Verdana" size="2">FTP Status: <img src="/images/ball_red.gif"></p>';
}
if ($pop3) {
$status .= '<p><font face="Verdana" size="2">POP3/SMTP Status: <img src="/images/ball_green.gif"></p>';
}
else {
$status .= '<p><font face="Verdana" size="2">POP3/SMTP Status: <img src="/images/ball_red.gif"></p>';
}
if ($cPanel) {
$status .= '<p><font face="Verdana" size="2">cPanel Status: <img src="/images/ball_green.gif"></p>';
}
else {
$status .= '<p><font face="Verdana" size="2">cPanel Status: <img src="/images/ball_red.gif"></p>';
}
if ($WHM) {
$status .= '<p><font face="Verdana" size="2">WHM Status: <img src="/images/ball_green.gif"></p>';
}
else {
$status .= '<p><font face="Verdana" size="2">WHM Status: <img src="/images/ball_red.gif"></p>';
}


And finally this part of the code echo's the output and makes it visible on the PHP page we have created:

echo("$status");


This is my first tutorial on how to make a Server System check page. This is a seriously modified version of a simple PHP code on hostpapers

There is obviously room for expansion and more for what you can do with this and if you do modify do share your changes with people so that we can all update our script to include any new features you may develop. Remember to leave a link to a working Demo

Thanks and Enjoy

(please note replace the path to the online and offline images with your own as the ones i have are the ones i have chosen to use. You may have a different choice as to what you wish to use. Mine are from WHMCS billing system)

J1MI (Forum Moderator) - Thread moved to Website Tutorials. Nice Tut

Speed-networks2
21-09-2006, 03:51 PM
ent this from techtuts :P

OK edit veryt sorry as daves just explained on msn

-::Mr.Dave::-
21-09-2006, 03:53 PM
No techtuts one displays this http://www.xtremehosts.co.uk/serverload.php

Recursion
21-09-2006, 04:07 PM
wont work on non cpanel hosts though :P

-::Mr.Dave::-
21-09-2006, 05:15 PM
wont work on non cpanel hosts though :P


Thats easy change the ports to their respective ports for Plesk etc

This was written for cPanel

Can be easily modified to work with plesk if you change the ports

Recursion
21-09-2006, 06:54 PM
how would i get it to work with 1and1 CP?

Jamie.
21-09-2006, 08:17 PM
Today i bring to you my first piece of php work which i find to be quite nice.

It may not be the hardest thing to do but some people will like this

This is an adaption of a simple free existing script but vastly improved and styles so using images instead of words to show online services and offline services and it has had more added to it

Example: http://www.xtremehosts.co.uk/server

First off start by opening up a blank notepad

Then copy and paste this into it:

<style type="text/css">
<!--
.style3 {
font-family: verdana;
font-size: 12px;
}
-->
</style>
<p class="style3"> Use this page to check the status of any system on our server</p>
<p class="style3">Server Status:<br />
</p>
<?php
//You can replace the domain with an IP if you wish
$site = "Your IP Goes here";
$http = fsockopen($site, 80);
$ftp = fsockopen($site, 21);
$pop3 = fsockopen($site, 110);
$cPanel = fsockopen($site, 2082);
$WHM = fsockopen($site, 2086);
if ($http) {
$status .= '<p><font face="Verdana" size="2">Http Status: <img src="/images/ball_green.gif"></p>';
}
else {
$status .= '<p><font face="Verdana" size="2">Http Status: <img src="/images/ball_red.gif"></p>';
}
if ($ftp) {
$status .= '<p><font face="Verdana" size="2">FTP Status: <img src="/images/ball_green.gif"></p>';
}
else {
$status .= '<p><font face="Verdana" size="2">FTP Status: <img src="/images/ball_red.gif"></p>';
}
if ($pop3) {
$status .= '<p><font face="Verdana" size="2">POP3/SMTP Status: <img src="/images/ball_green.gif"></p>';
}
else {
$status .= '<p><font face="Verdana" size="2">POP3/SMTP Status: <img src="/images/ball_red.gif"></p>';
}
if ($cPanel) {
$status .= '<p><font face="Verdana" size="2">cPanel Status: <img src="/images/ball_green.gif"></p>';
}
else {
$status .= '<p><font face="Verdana" size="2">cPanel Status: <img src="/images/ball_red.gif"></p>';
}
if ($WHM) {
$status .= '<p><font face="Verdana" size="2">WHM Status: <img src="/images/ball_green.gif"></p>';
}
else {
$status .= '<p><font face="Verdana" size="2">WHM Status: <img src="/images/ball_red.gif"></p>';
}
echo("$status");

?>


Ok now the breakdown

This code is the IP/Domain of the server we are going to check:

$site = "Your IP Goes here";

This code checks the status of each port. For example we have Port 80 and Port 21 which are http and Ftp. You can have it check any Port on the server but in this it checks:
HTTP
FTP
POP3/SMTP
cPanel
WHM

$http = fsockopen($site, 80);
$ftp = fsockopen($site, 21);
$pop3 = fsockopen($site, 110);
$cPanel = fsockopen($site, 2082);
$WHM = fsockopen($site, 2086);

This part of the code displays the results of the check

if ($http) {
$status .= '<p><font face="Verdana" size="2">Http Status: <img src="/images/ball_green.gif"></p>';
}
else {
$status .= '<p><font face="Verdana" size="2">Http Status: <img src="/images/ball_red.gif"></p>';
}
if ($ftp) {
$status .= '<p><font face="Verdana" size="2">FTP Status: <img src="/images/ball_green.gif"></p>';
}
else {
$status .= '<p><font face="Verdana" size="2">FTP Status: <img src="/images/ball_red.gif"></p>';
}
if ($pop3) {
$status .= '<p><font face="Verdana" size="2">POP3/SMTP Status: <img src="/images/ball_green.gif"></p>';
}
else {
$status .= '<p><font face="Verdana" size="2">POP3/SMTP Status: <img src="/images/ball_red.gif"></p>';
}
if ($cPanel) {
$status .= '<p><font face="Verdana" size="2">cPanel Status: <img src="/images/ball_green.gif"></p>';
}
else {
$status .= '<p><font face="Verdana" size="2">cPanel Status: <img src="/images/ball_red.gif"></p>';
}
if ($WHM) {
$status .= '<p><font face="Verdana" size="2">WHM Status: <img src="/images/ball_green.gif"></p>';
}
else {
$status .= '<p><font face="Verdana" size="2">WHM Status: <img src="/images/ball_red.gif"></p>';
}


And finally this part of the code echo's the output and makes it visible on the PHP page we have created:

echo("$status");


This is my first tutorial on how to make a Server System check page. This is a seriously modified version of a simple PHP code on hostpapers

There is obviously room for expansion and more for what you can do with this and if you do modify do share your changes with people so that we can all update our script to include any new features you may develop. Remember to leave a link to a working Demo

Thanks and Enjoy

(please note replace the path to the online and offline images with your own as the ones i have are the ones i have chosen to use. You may have a different choice as to what you wish to use. Mine are from WHMCS billing system)

hmm that is perfectly coded, also works, maybe put in tut section (mod) :)

-::Mr.Dave::-
21-09-2006, 08:35 PM
Thanks

Im continuing to develop the server file and may look into adding more pages to it

Im working on uptime and showing space used in a bar

Its not easy making a bar show space used out of 100%

If anyone feels like helping feel free to try and post on this thread

-::Mr.Dave::-
27-09-2006, 06:26 AM
harder than i thought to develop :P

Echo-Host
27-09-2006, 11:23 AM
Nice tut I Would of +rep but nah I only +reps to people who are kind!

Lilian
01-10-2006, 04:07 PM
Nice tut, and nicerly done thanks for that and well done with your first PHP script!:eusa_clap

Simie
03-10-2006, 07:13 PM
Maybe use @fsockopen() to hide the errors that come up when it can't connect?

-::Mr.Dave::-
05-10-2006, 03:14 PM
+Rep Simie

Thanks for the idea it shall be put to use

James.Easy
29-10-2006, 11:53 PM
Maybe add server load tut from tech-tuts too.

-::Mr.Dave::-
30-10-2006, 04:08 PM
thats quite easy to do on its own

-::Mr.Dave::-
12-11-2006, 03:38 PM
the fsockopen() just produces an error

-::Mr.Dave::-
02-12-2006, 08:25 PM
anyone else got suggestions for the script?

[WF][10] Col.TheNick
02-12-2006, 08:26 PM
You tripple posted.. Nope none at all

-::Mr.Dave::-
02-12-2006, 08:29 PM
well theres a long time between all 3 posts

Carlsta
19-04-2007, 09:46 AM
www.carlstac.com/server.php - EEK

Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/carlstac/public_html/server.php on line 15

Warning: fsockopen() [function.fsockopen]: unable to connect to http://www.carlstaccom:80 in /home/carlstac/public_html/server.php on line 15

Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/carlstac/public_html/server.php on line 16

Warning: fsockopen() [function.fsockopen]: unable to connect to http://www.carlstaccom:21 in /home/carlstac/public_html/server.php on line 16

Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/carlstac/public_html/server.php on line 17

Warning: fsockopen() [function.fsockopen]: unable to connect to http://www.carlstaccom:110 in /home/carlstac/public_html/server.php on line 17

Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/carlstac/public_html/server.php on line 18

Warning: fsockopen() [function.fsockopen]: unable to connect to http://www.carlstaccom:2082 in /home/carlstac/public_html/server.php on line 18

Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/carlstac/public_html/server.php on line 19

Warning: fsockopen() [function.fsockopen]: unable to connect to http://www.carlstaccom:2086 in /home/carlstac/public_html/server.php on line 19

Mashi
20-04-2007, 09:35 PM
Ace TUT!

Want to hide these adverts? Register an account for free!