Jump to content

Server Status display wizardry


redrat

Recommended Posts

Good morning. OK, I've been playing around with the whole Server Status display conundrum from a 'one-server host provider perspective' and have made a very useful discovery that is an ideal solution for me atm and may well be for others in a similar position.

 

Client Area Objectives

 

1. Server Status only available when logged in so no public access other than that whatsoever.

2. When logged in display meaningful and useful indicators to clients.

3. Only to display information relevant to the server clients are actually hosted on.

4. Not to display text such as, "The table below shows the status of our server. You can use this page to check if any of the services on our servers are down.", above the display. This is because it then makes it obvious that I only have one server and that is not what I want to present as it causes unnecessary concern about how 'big' my operation is and that is not desirable from a marketing point of view.

5. Not to display the phpinfo link. a) It mentions "Linux Notmy.serverserver.com 2.6.18-53.el5 #1 SMP Mon Nov 12 02:14:55 EST 2007 x86_6" right at the top and that makes for confusion and suspicion that, as well as having only one server, I am also very likely a reseller. b) I can easily provide all php information by other means with that reference removed.

 

So, of all possibilities, this is what I want clients to see:

serverstatusinnoxa0.jpg

and not this:

serverstatusny8.jpg

or this:

whmcs3.7.jpg

 

Clients can get a very good picture of what is happening with the server from cPanel anyway and the uptime information can be easily provided by other means.

 

Admin Area objective

 

1. Very simply to be able to see all of the Server Status information that WHMCS is capable of displaying with no blank table cells.

 

So I want to see this in my Admin Area:

whmcsAdminServerStatus.jpg

 

Well now I have exactly that so I thought I ought to share i with you guys. This is how it is achieved:

 

Client Area: Overwrite your /WHMCS/templates/portal/serverstatus.tpl code 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 rowspan=\"2\"><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 rowspan=\"2\"><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 rowspan=\"2\"><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 rowspan=\"2\"><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 rowspan=\"2\"><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 rowspan=\"2\"><img src=\"imagesfailed.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: Place the following code in a new file - /public_html/status/index.php

<?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/configservers.php?action=edit&id=1 the URL you have to use as the Server Status Address is: http://yourdomain.com/status/ (with the trailing slash)

 

Bob's your Uncle! It works like a dream. I am using the latest 3.7.1 but this will also work for 3.6.2 or so I believe. I have not tested the latter but can see no reason why not.

 

Important

It is a solution for which I have not written any code whatsoever and all credit goes to those who did. I just experimented a little and made my discovery purely by accident.

 

Enjoy!

Link to comment
Share on other sites

  • Replies 148
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

Well done boys.

 

Just a tip, though. Rather than have the client run all over the site looking for infromation, why not drop a couple of includes into the client area home page to give them a summary.

 

(Disclaimer:- this is great for small clients, but not so good for resellers or clients with hundreds of domains etc)

 

eg.

 

{include file='serverstatus.tpl'}

{include file='upcomingdomainrenewal.tpl'}

{include file='recentannouncements.tpl'}

{include file='clientareanotes.tpl'}

 

Plus a couple of other customs, as per the screenshot, notes, etc

 

Drop in a couple of hyperlinks to the relevant sections, and you have a nice one page snapshot summary of the client.

support_homepage.jpg

Link to comment
Share on other sites

Well done boys.

 

Just a tip, though. Rather than have the client run all over the site looking for infromation, why not drop a couple of includes into the client area home page to give them a summary.

 

(Disclaimer:- this is great for small clients, but not so good for resellers or clients with hundreds of domains etc)

 

eg.

 

{include file='serverstatus.tpl'}

{include file='upcomingdomainrenewal.tpl'}

{include file='recentannouncements.tpl'}

{include file='clientareanotes.tpl'}

 

Plus a couple of other customs, as per the screenshot, notes, etc

 

Drop in a couple of hyperlinks to the relevant sections, and you have a nice one page snapshot summary of the client.

That's a cool idea. Is it really just as simple as including the tpl files on the page??

 

The problem with the messed up status display a few posts up is due to HTML i believe. Unfortunately, I did not make any changes to the output of the status script i modified, so I have no experience with it.

Link to comment
Share on other sites

  • 1 month later...
Thank you :D

Your Template have a error ?

"Client Area: Overwrite your /WHMCS/templates/portal/serverstatus.tpl code with this code:"

attachment.php?attachmentid=335&d=1221341687

regards

 

The problem with multiple plans can be solved replacing all occurences of:

<td rowspan=\"2\"><img src=\"images/statusfailed.gif\"></td>

and

<td rowspan=\"2\"><img src=\"imagesfailed.gif\"></td>

 

with:

<td><img src=\"images/statusfailed.gif\"></td>

 

:)

Edited by RenatoMN
Link to comment
Share on other sites

Thanks to Renato for resolving the problem with broken displays where multiple servers are used: Here is the amended code for /WHMCS/templates/portal/serverstatus.tpl

{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}

Please refer to the very first post in this thread for the rest of the code and instructions.:)

Link to comment
Share on other sites

Have you put everything in the right folders on your server? Please check that first. The correct file paths for both files needed for this to work are as shown above. And you will need the second file at the beginning of this thread. This is: /WHMCS/templates/portal/serverstatus.tpl Then you need to add the latest code for this new file /public_html/status/index.php which you have to create and then add code for.

 

All that should get this working for you. Post back either way. :)

Edited by redrat
Link to comment
Share on other sites

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