Jump to content

Script problem: Server status.


Hangwire

Recommended Posts

Hi all!  :shy:

Yet again I have a problem. I really couldn't find what the heck's wrong with this thing. It's extremely simple and still...

I'm trying to put a php script in my website to monitor the status of my FTP and HFS servers. Help?

 

<TITLE>Server Status</TITLE>
<?php 
$data .= " 
    </div>
    <center> 
     <div style=\"border-bottom:1px #999999 solid;width:480;\"><b> 
       <font size='1' color='#3896CC'>Server Status</font></b> 
     </div>  
   </center> 
<br>"; 

//configure script 
$timeout = "1"; 

//set service checks
$port[1] = "80";            $service[1] = "Apache";            $ip[1] = "localhost";    $icon[1] = "habbo.jpg";        $alt[1] = "Apache";
$port[2] = "8080";            $service[2] = "HFS Server";        $ip[2] = "localhost";    $icon[2] = "web.png";        $alt[2] = "HFS Server";  
$port[3] = "21";            $service[3] = "FTP Server";        $ip[3] = "localhost";  $icon[3] = "web.png";        $alt[3] = "FTP Server";

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

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

//beggin table for status 
$data .= "<table width='480' border='1' cellspacing='0' cellpadding='3' style='border-collapse:none' bordercolor='#CCCCCC' align='center'>"; 

while($count < $ports){ 

     if($ip[$count]==""){ 
       $ip[$count] = "localhost"; 
     } 
        $fp = @fsockopen("$ip[$count]", $port[$count], $errno, $errstr, $timeout); 
        if (!$fp) { 
            $data .= "<tr><td width='18' align='center'><img src='http://127.0.0.1/stat/$icon[$count]' title='$alt[$count]' alt='$alt[$count]'></td><td>$service[$count]</td><td width='18' align='center'><img src='http://127.0.0.1/stat/off.png'></td></tr>"; 
        } else { 
            $data .= "<tr><td width='18' align='center'><img src='http://127.0.0.1/stat/$icon[$count]' title='$alt[$count]' alt='$alt[$count]'></td><td>$service[$count]</td><td width='18' align='center'><img src='http://127.0.0.1/stat/on.png'></td></tr>"; 
            fclose($fp); 
        } 
    $count++; 

}  

//close table 
$data .= "</table><div>"; 

echo $data; 

?>

 

The output of this is...

 

Parse error: syntax error, unexpected T_VARIABLE in D:\Program Files\xampp\xampp\htdocs\stat\server.php on line 18

 

Also, does somebody have a link or something to a tutorial/pre-made script (although I'd like to follow instructions about it) about server statistics? I want to have data on how much a certain partition on the server has free or full. Thank you in advance.

 

;)

Link to comment
Share on other sites

Thank you for the quick reply!

I took good look at what you gave me, I tried it, but again, to no avail.

I added <?php include(server2.php); ?> on the place i needed it, but it doesn't show up, but when I open server2.php from the server I can see it works and displays everything properly.

My server2.php (the script) is in the main directory of apache (htdocs). I also tried to put it in the folder of the current index im working on, but again - it doesn't work.

 

Help?  :(

Link to comment
Share on other sites

Alright, well I've decided to let that old script go and try with this:

 

<?php
function check_port($port) {
    $conn = @fsockopen("127.0.0.1", $port, $errno, $errstr, 0.2);
    if ($conn) {
        fclose($conn);
        return true;
    }
}

function server_report() {
    $report = array();
    $svcs = array('21'=>'FTP',
                  '22'=>'SSH',
                  '25'=>'SMTP',
                  '80'=>'HTTP',
                  '110'=>'POP3',
                  '143'=>'IMAP',
                  '3306'=>'MySQL');
    foreach ($svcs as $port=>$service) {
        $report[$service] = check_port($port);
    }
    return $report;
}

$report = server_report();
?>
<table>
    <tr>
        <td>Service</td>
        <td>Status</td>
    </tr>
    <tr>
        <td>FTP</td>
        <td><?php echo $report['FTP'] ? "Online" : "Offline"; ?></td>
    </tr>
    <tr>
        <td>SSH</td>
        <td><?php echo $report['SSH'] ? "Online" : "Offline"; ?></td>
    </tr>
    <tr>
        <td>SMTP</td>
        <td><?php echo $report['SMTP'] ? "Online" : "Offline"; ?></td>
    </tr>
    <tr>
        <td>HTTP</td>
        <td><?php echo $report['HTTP'] ? "Online" : "Offline"; ?></td>
    </tr>
    <tr>
        <td>POP3</td>
        <td><?php echo $report['POP3'] ? "Online" : "Offline"; ?></td>
    </tr>
    <tr>
        <td>IMAP</td>
        <td><?php echo $report['IMAP'] ? "Online" : "Offline"; ?></td>
    </tr>
    <tr>
        <td>MySQL</td>
        <td><?php echo $report['MySQL'] ? "Online" : "Offline"; ?></td>
    </tr>
</table>

 

So far so good, it works like a charm on its own but I can't implement it into anything. For example, when I put

 

 

<?php include("server2.php"); ?>

 

In the right place on my website, it doesn't show anything. The script is in the same folder...

 

Help?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.