icon Get the most out of Surmunity, read our tips here! Need an interesting blog to read? You've got to read the Surpass Blog! | Welcome! Please register to access all of our features.

» Surpass Web Hosting Forums » Discussions » All Things Techy » Site Maintenance » Server Status script not working

Site Maintenance Program updates, securing your website, creating backups.

Reply
 
LinkBack Thread Tools Search this Thread
Old December 2nd, 2007, 3:37 PM   #1 (permalink)
Surpass Fan
On a golden path...
 
Joined in Mar 2006
Hosted on SH100
458 posts
Gave thanks: 75
Thanked 17 times
Question Server Status script not working

I use the following server status script to monitor my websites on a shared server here. I don't know where I originally got it but it works really well. Until now

Code:
<?php

/*
*   +------------------------------------------------------------------------------+
*       CPANEL STATUS SCRIPT
*   +------------------------------------------------------------------------------+
*       Copyright Notice(s)
*   +------------------------------------------------------------------------------+
*       Disclaimer Notice(s)
*       ex: This code is freely given to you and given "AS IS", SO if it damages
*       your computer, formats your HDs, or burns your house I am not the one to
*       blame.
*       Moreover, don't forget to include my copyright notices and name.
*   +------------------------------------------------------------------------------+
*       Author(s): Crooty.co.uk (Adam C)
*   +------------------------------------------------------------------------------+
*/

// Configure script 
$timeout = 1; 

// Set service checks 
$port[1]    = 80;
$service[1] = 'Apache';
$ip[1]      = '';

$port[2]    = 21;
$service[2] = 'FTP';
$ip[2]      = '';

$port[3]    = 3306;
$service[3] = 'MYSQL';
$ip[3]      = '';

$port[4]    = 25;
$service[4] = 'Email(POP3)';
$ip[4]      = '';

$port[5]    = 143;
$service[5] = 'Email(IMAP)';
$ip[5]      = '';

$port[6]    = 2095;
$service[6] = 'Webmail';
$ip[6]      = '';

$port[7]    = 2082;
$service[7] = 'Cpanel';
$ip[7]      = '';

$port[8]    = 80;
$service[8] = 'Internet Connection';
$ip[8]      = 'google.com';

$port[9]    = 2086;
$service[9] = 'WHM';
$ip[9]      = '';

//
// NO NEED TO EDIT BEYOND HERE UNLESS YOU WISH TO CHANGE STYLE OF RESULTS
//

?>
<html>
<head>
<title>Service Status</title>
<style type="text/css">
<!--

td, body
{
  font-family: Arial, Helvetica, sans-serif;
  font-size: 8pt;
  color: #444444;
}

.status_header
{
  border-bottom: 1px solid #999999;
  width: 480;
  color: #3896CC;
}

.status_table
{
  border: 1px solid #333333;
  border-collapse: collapse;
  width: 480;
}

td
{
  border: 1px solid #333333;
}

.online
{
  background-color: #D9FFB3
}

.offline
{
  background-color: #FFC6C6;
}

-->
</style>
</head>

<body>

<br />
<center>
  <div class="status_header"><strong>Service Status</strong></div>
</center>
<br />

<table class="status_table" cellspacing="0" cellpadding="3" align="center">
<?php 

// Count arrays
$ports = count($port) + 1;
$count = 1;

while ($count < $ports)
{
    if ($ip[$count] == '')
    {
        $ip[$count] = 'localhost';
    }

    $fp = @fsockopen($ip[$count], $port[$count], $errno, $errstr, $timeout);

    if (!$fp)
    {
        echo "<tr>\n  <td>{$service[$count]}</td>\n  <td class=\"offline\">Offline</td>\n</tr>\n";
        fclose($fp);
    }
    else
    {
        echo "<tr>\n  <td>{$service[$count]}</td>\n  <td class=\"online\">Online</td>\n</tr>\n";
        fclose($fp);
    }
    $count++;
}

//
// SERVER INFORMATION
//
?>
</table>

<br />
<center>
  <div class="status_header"><strong>Server Information</strong></div>
</center>
<br />

<table class="status_table" cellspacing="0" cellpadding="3" align="center">

<?php

// GET SERVER LOADS
$loadresult = @exec('uptime');
preg_match("/averages?: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/", $loadresult, $avgs);

// GET SERVER UPTIME
$uptime = explode(' up ', $loadresult);
$uptime = explode(',', $uptime[1]);
$uptime = $uptime[0] . ', ' . $uptime[1];

echo "<tr>\n  <td>Server Load Averages</td>\n  <td>$avgs[1], $avgs[2], $avgs[3]</td>\n</tr>\n<tr>\n  <td>Server Uptime</td>\n  <td>$uptime</td>\n</tr>\n"; 

?>
</table>

</body>
</html>
This script seems to work fine on 2 of the 3 servers I have here but I have one account on a new server (SH131) and for some reason this script is not working on that one. You can see it in action here...
http://www.usasentinel.com/status.php

Notice at the bottom that the server information section is blank. On my other 2 servers it shows the correct info.

Does anyone have any ideas as to why this is not working with sh131 when it is working fine with sh100 and sh124?
__________________
SH100 , SH131 & SH124
Sentinel is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old December 2nd, 2007, 5:10 PM   #2 (permalink)
Race Surpass
Super #1
 
MarkRH's Avatar
 
Joined in Jul 2006
Lives in Oklahoma City, OK
Hosted on sh102
1,222 posts
Gave thanks: 18
Thanked 86 times
Something tells me $loadresult = exec('uptime'); is failing. You might remove the "" in front of exec so that it will echo any warnings or errors. It's also possible that the exec() function was/is disabled on that server.
MarkRH is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
This user thanks MarkRH for this great post!
Sentinel (December 3rd, 2007)
Old December 3rd, 2007, 8:43 AM   #3 (permalink)
Surpass Fan
On a golden path...
 
Joined in Mar 2006
Hosted on SH100
458 posts
Gave thanks: 75
Thanked 17 times
I will check that out later today. Thanks.
__________________
SH100 , SH131 & SH124
Sentinel is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old December 3rd, 2007, 11:32 PM   #4 (permalink)
Marketing Maven
Surpass Staff
 
Kayla's Avatar
 
Joined in May 2003
Lives in Orlando
24,749 posts
Gave thanks: 946
Thanked 806 times
Was that it? : (
__________________
Follow Surpass on Twitter and Facebook
Check out the Surpass Blog



Kayla is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old December 4th, 2007, 10:40 AM   #5 (permalink)
Surpass Fan
On a golden path...
 
Joined in Mar 2006
Hosted on SH100
458 posts
Gave thanks: 75
Thanked 17 times
Sorry it took me so long to reply.

Yes, that did the trick. I mean it did not fix it but I don't think your intention was to fix it but to help me find out what was wrong, and removing the "" symbol from that line resulted in the following error code...
Code:
Warning: exec() has been disabled for security reasons in /home/myusername/public_html/status.php on line 164
So apprently you were correct and the exec() function (whatever that is ) is disabled. I don't know why ... mainly because I don't know what it does Does disabling/enabling it have anything to do with the security of the server? Is it off by default?
__________________
SH100 , SH131 & SH124
Sentinel is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old December 4th, 2007, 9:18 PM   #6 (permalink)
Surpass Fan
On a golden path...
 
Joined in Mar 2006
Hosted on SH100
458 posts
Gave thanks: 75
Thanked 17 times
Surpass has enabled it for me and I love this place and these guys are great. But you know what? I just asked them to change it back. Apparently this thing is a security feature and should be off by default. If that's so then I don't want to be the cause of it being on just for a dopey script. This script doesn't mean that much to me to lessen security on the server.

For me security is king. Yes, I am the kind of guy that locks my car in the garage
__________________
SH100 , SH131 & SH124
Sentinel is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old December 4th, 2007, 9:42 PM   #7 (permalink)
Race Surpass
Super #1
 
MarkRH's Avatar
 
Joined in Jul 2006
Lives in Oklahoma City, OK
Hosted on sh102
1,222 posts
Gave thanks: 18
Thanked 86 times
Well, for Gallery2 to use ImageMagick to process images, it has to be on since it uses a command line interface with the convert executable. Of course, you can always use PHP's GD instead, but ImageMagick does seem to create slightly better looking images.
MarkRH is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old December 4th, 2007, 10:26 PM   #8 (permalink)
Operations
Super #1
 
Joined in Jun 2005
Lives in surpass headquarters
1,028 posts
Gave thanks: 67
Thanked 127 times
the exec() php option is disabled by default on newer servers as a security precaution. So adding a local php.ini and removing exec from disabled functions is the workaround.

Sentinel, if you still want to use the status script you can place the script file and the php.ini I created for you in a sub folder instead of in public_html root. This would almost eliminate the security risk.
__________________
Mike
Surpass Special Operations
Mike is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
These users thank Mike for this great post!
MarkRH (December 4th, 2007), Sentinel (December 5th, 2007)
Old December 4th, 2007, 11:38 PM   #9 (permalink)
Race Surpass
Super #1
 
MarkRH's Avatar
 
Joined in Jul 2006
Lives in Oklahoma City, OK
Hosted on sh102
1,222 posts
Gave thanks: 18
Thanked 86 times
Hmmm... I may have do that to explicitly disable that function where I want. Hopefully php has been configured on his server to recognize local php.ini files.

Edit:
Actually, I just realized that this is what I've been doing. These functions are disabled by default with PHP5 on my server:

exec, shellexec, passthru, system, escapeshellcmd,

I've just been using my own php.ini the whole time which doesn't disable them. However, they were all disabled on my companyofvalor domain as it's using the default config. I need to put my own php.ini in there as the server actually has allow_url_fopen on by default.
MarkRH is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On