Jump to content

Server Status display wizardry


redrat

Recommended Posts

Hi John. Well, I reckon what you're asking for requires quite a bit of further customisation and I'm not sure where to start, not being a coder myself. (I mess around sometimes that's all) I'm sorry to say this is a bit out of my league. Hopefully, someone will pick up your idea and help out or you could just get a quote from Matt who, I'm pretty certain, wouldn't want much to develop it for you.

 

Asides from that, I'm pretty darn certain I've seen exactly what you want somewhere.......perhaps it was on someone's site? I'm just not sure. There are a few different versions of this kicking around these forums and it may be that I followed a link to a site belonging to someone who had posted in one of these threads and that could be where I saw it.

 

In this instance, John, I'm afraid that I cannot really be of any further help but it would be good to know how you resolve this if you'd like to post back at any stage.

 

Regards,

 

Chris

Link to comment
Share on other sites

  • Replies 148
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

Hi Redrat, many thanks for the comment about or site, we are still always adding and changing parts of it.

 

We love this script and it does the job perfectly, but I would like to show the status of the uptime of the server or have the option to, how can we do this?

 

I am trying to get a page which is seperate to this to show all our servers, ideally being able to add a specific port number for each to show media servers are up with uptime, any ideas on how we can do this?

 

Thanks, John

 

This can be done with a script called StatusMon, it is free. I have changed the .php to my server status and created a new template for it.

 

You can setup the servers it monitors and each service. It also has options to calculate the uptime. The data is stored in a MySQL Database, and is updated when your cron runs. I have the script running every 2 minutes. The script loads very fast as it's just pulling the data from the database and not running all the fsock open checks which make the older status pages take long to load. Basically the status information is cached. This work works very well, PM me for more information :)

Link to comment
Share on other sites

  • 4 weeks later...

ATTN: Freedom_Internet:

RE: http://forum.whmcs.com/showpost.php?p=93622&postcount=44

 

Line 86 has a mistake!

 

Change from:

echo "<td><img src=\"imagesfailed.gif\" alt=\"SMTP\"></td>";

To:

echo "<td><img src=\"images/statusfailed.gif\" alt=\"SMTP\"></td>";

 

Also is there any possible way to speed up the script. It takes a good 30 seconds to do anything, and always reports hosting and pop3 and smtp and webmail as not working....

 

I've simply changed the ports to reflect linux WHM/Cpanel hosting, those being:

 

Changed Plesk to cPanel and Port:

CPANEL: 2082

 

Webmail: 80 -> 2095

HTTP: 80

FTP: 21

POP3: 110

SMTP: 25

 

 

Not working...

Thanks for your help so far!

Link to comment
Share on other sites

The only way to speed up the script is to run the checks via cron (eg every 2 minutes) and store the information in a database. This would result in mysql query when then load the page instead of checking each port on each server. Basically the status results would be cached.

Link to comment
Share on other sites

Redrat's method is the f-f-f-fastest...

Something in Freedom_Internet's script causes excessive lag...

 

The only difference i can see is the webmail check... perhaps that's what is slowing things down....?

 

I've also changed a few things around.

 

I've managed to split it up, so for a logged in user, it displays:

- Your Servers(array) - Detailed Info

 

Then below shows:

- All Servers(array) - Default WHMCS Summary

 

However for guest's or users without a service etc.... it will just show All Server's(array) - Default WHMCS Summary

 

Make sense?

If anyone is interested, or having trouble with this script, then i'll be happy to post all source code...

 

(:

Edited by flip
Link to comment
Share on other sites

  • 2 weeks later...

I seem to be having problems with this.

 

I can get the regular server status page, no problem.

When I change the portal template, and status/index.php

 

I go to the serverstatus page and it has no servers listed, is this a port problem?

I've gone through it multiple times and have yet to figure it out.

 

Thanks

Link to comment
Share on other sites

Hi Mike. Please go back to post #1 and make sure that you are following all of the instructions there carefully. If the problem still persists post back here.

 

I will just add that I'm a bit of a noob at all this but will do my best to help you. Virtually everyone else here knows way more than I do. ;)

Edited by redrat
Link to comment
Share on other sites

  • 1 month later...

The variables supplied allow you to add services you want to see and even version info for PHP and MySql

 

I don't think you needed to write code to do this.

I have done this with basic code such as {get_port_status num="$num" port="2082"} for Cpanel

Or {$server.phpver} For PHP Version

 

I have removed the phpinfo link and replaced it with php version for my status page.

Only adding these lines to the basic template works fine.

I would guess there is a check that can be added to see if a person has logged in.

 

No changes need be made to index.php

 

It's simple as they give you what you need but they don't document it.

 

http://www.cw3host.com/members/serverstatus.php

Link to comment
Share on other sites

  • 2 weeks later...
The variables supplied allow you to add services you want to see and even version info for PHP and MySql

 

I don't think you needed to write code to do this.

I have done this with basic code such as {get_port_status num="$num" port="2082"} for Cpanel

Or {$server.phpver} For PHP Version

 

I have removed the phpinfo link and replaced it with php version for my status page.

Only adding these lines to the basic template works fine.

I would guess there is a check that can be added to see if a person has logged in.

 

No changes need be made to index.php

 

It's simple as they give you what you need but they don't document it.

 

http://www.cw3host.com/members/serverstatus.php

 

Care to share the code? I like the way you setup that status.

Link to comment
Share on other sites

@vincent. Very nice btw but the whole purpose of the schema adopted for this thread is specifically not to show phpinfo or uptime and yet to show more ports detail than the WHMCS standard setup.

 

That said, I guess people just leave out those two items and your method is great. Thanks for posting. Care to share the code?

Link to comment
Share on other sites

Apologies vincent. I just realised that you are not displaying phpinfo at all. Very nice job you've done and I like the use of phpSysInfo-2.5.4 links on the left. Hmmmmmm. Got me thinking now. ;)

 

I'm still not sure of the value in showing the uptime link since you could have a server that has accumulated excellent uptime but which is suddenly reverted to zero if there is any downtime so is a bit meaningless really. At least, I find it so.

Edited by redrat
Link to comment
Share on other sites

which file do I have to edit to replace the code with yours ?

 

Hi!

 

This is a great contrib!

 

I made some modifications that might be useful. First one is simlpe - I use Plesk and as such needed to change the port number and column label accordingly. The next one was to replace the use of the IP address when checking each service with the domain name. I've also added ALT tags for each of the status markers because at one point I screwed up while swapping the position around on a couple of them and had a status marker sitting off to the side with no clue as to what it was for. The final one was to add a status for web mail in case I decide not to provide this service or the service goes down for some reason.

 

Code:

 
{if $loggedin}
<table  width="100%" class="clientareatable" align="center" cellspacing="1">
<tr class="clientareatableheading">
<td>{$LANG.servername}</td>
<td>Hosting</td>
<td>Plesk</td>
<td>HTTP</td>
<td>FTP</td>
<td>POP3</td>
<td>SMTP</td>
<td>WebMail</td>
</tr>
<tr>
{php}
$query1 = "SELECT * FROM tblservers ORDER BY name";
$result1 = mysql_query($query1);
while ($row1 = mysql_fetch_array($result1)) {
$serverid = $row1['id'];
$servername = $row1['name'];
$host = $row1['ipaddress'];
$hosteddomains="";
$query2 = "SELECT * FROM tblhosting WHERE userid='".$_SESSION["uid"]."' AND domainstatus='Active' AND server='".$serverid."'";
$result2 = mysql_query($query2);
while ($row2 = mysql_fetch_array($result2)) {
$hosteddomain = $row2['domain'];
$hosteddomains.=$hosteddomain."<br>";
}
if ($hosteddomains) {
$hosteddomains=substr($hosteddomains,0,-4);
if ($host) {
//Plesk
$port = 8443;
$fp = fsockopen($hosteddomains,$port,$errno,$errstr,10);
if(!$fp)
{
echo "<tr class=\"clientareatableactive\">";
echo "<td><b>".$servername."</b> </td>";
echo "<td>" .$hosteddomains."</td>";
echo "<td><img src=\"images/statusfailed.gif\" alt=\"Plesk\"></td>";

}else{
echo "<tr class=\"clientareatableactive\">";
echo "<td>".$servername." </td>";
echo "<td>" .$hosteddomains."</td>";
echo "<td><img src=\"images/statusok.gif\" alt=\"Plesk\"></td>";
fclose($fp);
}
//HTTP
$port = 80;
$fp = fsockopen($hosteddomains,$port,$errno,$errstr,10);
if(!$fp)
{
echo "<td><img src=\"images/statusfailed.gif\" alt=\"HTTP\"></td>";
}
else{
echo "<td><img src=\"images/statusok.gif\" alt=\"HTTP\"></td>";
fclose($fp);
}
//FTP
$port = 21;
$fp = fsockopen('ftp.'.$hosteddomains,$port,$errno,$errstr,10);
if(!$fp)
{
echo "<td><img src=\"images/statusfailed.gif\" alt=\"FTP\"></td>";

}else{
echo "<td><img src=\"images/statusok.gif\" alt=\"FTP\"></td>";
fclose($fp);
}
//POP3
$port = 110;
$fp = fsockopen('mail.'.$hosteddomains,$port,$errno,$errstr,10);
if(!$fp)
{
echo "<td><img src=\"images/statusfailed.gif\" alt=\"POP3\"></td>";

}else{
echo "<td><img src=\"images/statusok.gif\" alt=\"POP3\"></td>";
fclose($fp);
}
//SMTP
$port = 25;
$fp = fsockopen('mail.'.$hosteddomains,$port,$errno,$errstr,10);
if(!$fp)
{
echo "<td><img src=\"imagesfailed.gif\" alt=\"SMTP\"></td>";

}else{
echo "<td><img src=\"images/statusok.gif\" alt=\"SMTP\"></td>";
fclose($fp);
}
$this->assign('serverid',$serverid);
$this->assign('servername',$servername);
//WEBMAIL
$port = 80;
$fp = fsockopen('webmail.'.$hosteddomains,$port,$errno,$errstr,10);
if(!$fp)
{
echo "<td><img src=\"images/statusfailed.gif\" alt=\"WebMail\"></td>";

}else{
echo "<td><img src=\"images/statusok.gif\" alt=\"WebMail\"></td>";
fclose($fp);
}
{/php}
{php}
echo "</td></tr>";
} else {
echo "<tr class=\"clientareatableactive\">";
echo "<td>".$servername."</td>";
echo "<td>" .$hosteddomains."</td>";
echo "<td colspan=\"5\"><strong><font color=\"#AAAAAA\">Not Monitored Here</font></strong></td>";
}}}
{/php}
</table>
{else}
<p>{$LANG.loginintrotext}</p>
<form action="dologin.php?goto=serverstatus" method="post">
<table align="center">
<tr><td align="right">{$LANG.loginemail}:</td><td><input type="text" name="username" size="40" value="{$username}"></td></tr>
<tr><td align="right">{$LANG.loginpassword}:</td><td><input type="password" name="password" size="25" value="{$password}"></td></tr>
</table>
<p align="center"><input type="submit" value="{$LANG.loginbutton}"><br><input type="checkbox" name="rememberme"{$rememberme}> {$LANG.loginrememberme}</p>
</form>
<p><b>{$LANG.loginforgotten}</B> <a href="passwordreminder.php">{$LANG.loginforgotteninstructions}</a>.</p>
{/if}

 

One thing that has stumped me and I'm not sure if anyone else will see this or not is that the status of WebMail will alternate between being available and not available even though the service is available without issue.

Link to comment
Share on other sites

OK. I can see what is wrong now. You have not precisely followed the instructions in the first post, that's all. So it's fairly simple to correct this. Please adopt the following procedure carefully and it should work perfectly for you.

 

Client Area: Overwrite your /WHMCS/templates/yourtemplate/serverstatus.tpl file with this code:

{if $loggedin}
<table  width="100%" class="clientareatable" align="center" cellspacing="1">
<tr class="clientareatableheading">
<td>{$LANG.servername}</td>
<td>Hosting</td>
<td>HTTP</td>
<td>WHM</td>
<td>CPanel</td>
<td>FTP</td>
<td>POP3</td>
<td>SMTP</td>
</tr>
<tr>
{php}
$query1 = "SELECT * FROM tblservers ORDER BY name";
$result1 = mysql_query($query1);
while ($row1 = mysql_fetch_array($result1)) {

$serverid = $row1['id'];
$servername = $row1['name'];
$host = $row1['ipaddress'];

$hosteddomains="";

$query2 = "SELECT * FROM tblhosting WHERE userid='".$_SESSION["uid"]."' AND domainstatus='Active' AND server='".$serverid."'";

$result2 = mysql_query($query2);
while ($row2 = mysql_fetch_array($result2)) {

$hosteddomain = $row2['domain'];
$hosteddomains.=$hosteddomain."<br>";
}
if ($hosteddomains) {
$hosteddomains=substr($hosteddomains,0,-4);

if ($host) {
//HTTP
$port = 80;

$fp = fsockopen($host,$port,$errno,$errstr,10);
if(!$fp)
{
echo "<tr class=\"clientareatableactive\">";
echo "<td><b>".$servername."</b> </td>";
echo "<td>" .$hosteddomains."</td>";
echo "<td><img src=\"images/statusfailed.gif\"></td>";
}

else{
echo "<tr class=\"clientareatableactive\">";
echo "<td>".$servername." </td>";
echo "<td>" .$hosteddomains."</td>";
echo "<td><img src=\"images/statusok.gif\"></td>";
fclose($fp);
}

//CPanel
$port = 2082;

$fp = fsockopen($host,$port,$errno,$errstr,10);
if(!$fp)
{
echo "<td><img src=\"images/statusfailed.gif\"></td>";


}else{
echo "<td><img src=\"images/statusok.gif\"></td>";

fclose($fp);
}

//WHM
$port = 2086;

$fp = fsockopen($host,$port,$errno,$errstr,10);
if(!$fp)
{
echo "<td><img src=\"images/statusfailed.gif\"></td>";


}else{
echo "<td><img src=\"images/statusok.gif\"></td>";

fclose($fp);
}

//FTP
$port = 21;

$fp = fsockopen($host,$port,$errno,$errstr,10);
if(!$fp)
{
echo "<td><img src=\"images/statusfailed.gif\"></td>";


}else{
echo "<td><img src=\"images/statusok.gif\"></td>";

fclose($fp);
}

//POP3
$port = 110;

$fp = fsockopen($host,$port,$errno,$errstr,10);
if(!$fp)
{
echo "<td><img src=\"images/statusfailed.gif\"></td>";


}else{
echo "<td><img src=\"images/statusok.gif\"></td>";

fclose($fp);
}

//SMTP
$port = 25;

$fp = fsockopen($host,$port,$errno,$errstr,10);
if(!$fp)
{
echo "<td><img src=\"images/statusfailed.gif\"></td>";


}else{
echo "<td><img src=\"images/statusok.gif\"></td>";

fclose($fp);
}
$this->assign('serverid',$serverid);
$this->assign('servername',$servername);

{/php}

{php}
echo "</td></tr>";
} else {
echo "<tr class=\"clientareatableactive\">";
echo "<td>".$servername."</td>";
echo "<td>" .$hosteddomains."</td>";
echo "<td colspan=\"5\"><strong><font color=\"#AAAAAA\">Not Monitored Here</font></strong></td>";
}}}
{/php}
</table>
{else}
<p>{$LANG.loginintrotext}</p>

<form action="dologin.php?goto=serverstatus" method="post">

<table align="center">
<tr><td align="right">{$LANG.loginemail}:</td><td><input type="text" name="username" size="40" value="{$username}"></td></tr>
<tr><td align="right">{$LANG.loginpassword}:</td><td><input type="password" name="password" size="25" value="{$password}"></td></tr>
</table>

<p align="center"><input type="submit" value="{$LANG.loginbutton}"><br><input type="checkbox" name="rememberme"{$rememberme}> {$LANG.loginrememberme}</p>
</form>
<p><b>{$LANG.loginforgotten}</B> <a href="passwordreminder.php">{$LANG.loginforgotteninstructions}</a>.</p>
{/if}

Admin Area: Create a new file - /public_html/status/index.php and insert the following code:

<?php



error_reporting(0);



if (ini_get('disable_functions')) {

   $disabled_funcs=array_map('trim',explode(',',ini_get('disable_functions')));

}



$action=$_GET["action"];



if ($action=="phpinfo") {

   phpinfo();

} else {

   $users[0]="Unavailable";

   $users[1]="--";

   $loadnow="Unavailable";

   $load15="--";

   $load30="--";

   if (in_array('exec',$disabled_funcs)) {

       $load=file_get_contents("/proc/loadavg");

       $load=explode(' ',$load);

       $loadnow=$load[0];

       $load15=$load[1];

       $load30=$load[2];

   } else {

       $reguptime=trim(exec("uptime"));

       if ($reguptime) {

           if (preg_match("/, *(\d) (users?), .*: (.*), (.*), (.*)/",$reguptime,$uptime)) {

               $users[0]=$uptime[1];

               $users[1]=$uptime[2];

               $loadnow=$uptime[3];

               $load15=$uptime[4];

               $load30=$uptime[5];

           }

       }

   }

   if (in_array('shell_exec',$disabled_funcs)) {

       $uptime_text=file_get_contents("/proc/uptime");

       $uptime=substr($uptime_text,0,strpos($uptime_text," "));

   } else {

       $uptime=shell_exec("cut -d. -f1 /proc/uptime");

   }

   $days=floor($uptime/60/60/24);

   $hours=str_pad($uptime/60/60%24,2,"0",STR_PAD_LEFT);

   $mins=str_pad($uptime/60%60,2,"0",STR_PAD_LEFT);

   $secs=str_pad($uptime%60,2,"0",STR_PAD_LEFT);

   $phpver=phpversion();

   $mysqlver=mysql_get_client_info();

   $zendver=zend_version();

   echo "<load>$loadnow</load>\n";

   echo "<uptime>$days Days $hours:$mins:$secs</uptime>\n";

   echo "<phpver>$phpver</phpver>\n";

   echo "<mysqlver>$mysqlver</mysqlver>\n";

   echo "<zendver>$zendver</zendver>\n";

}

Finally, there is just one important last thing you must do for this to work:

 

In the Admin Configuration/Servers section @ http://yourdomain.com/whmcs/admin/co...tion=edit&id=1 the URL you have to use as the Server Status Address is: http://yourdomain.com/status/ (with the trailing slash)

 

If you do all of the above correctly, it should work right off the bat! Let us know how you get on. Best wishes. ;)

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated