Location: PHPKode > projects > LSMS SNMP to MRTG toolset > www/snmpmrtg/phpping/index.php
<?php
// (C)Copyright John Baker 2004/2005/2006
//
// This file is part of lsms2mrtg.
//
// lsms2mrtg is free software;you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation;either version 2 of the License, or
// (at your option) any later version.
//
// lsms2mrtg is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY;without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with lsms2mrtg;if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// For more informationn please visit http://gnulsms2mrtg.sourceforge.net/
include '../generic.inc';
include '../jbsnmplib.inc';
include '../BrickSNMPlib.inc';
include 'ping.inc';
echo $htmlheader;
error_reporting(2);
echo "<font size=+2 color=$globaltitlecolour><B>PHP Pinger</B></font><HR><BR>";
if (file_exists("run.pinger")) {
    $tmp1=file2array("run.pinger");
    $listend=$tmp1[0];
}
else
{
    $listend=0;
}
$nodisp=0;
$cmdcounter1=0;
$hostdown=0;
$refreshpage=(30+($listend*2));
if ($listend!=0) {
    $pingerlist=$tmp1[1];
    SORT($pingerlist);
    echo "<TABLE valign=middle cellpadding=0 border=1 bgcolor=$gentablebg bordercolor=$gentableborder class=\"framelook\">";
    echo "<TH ><font color=$gentabletext>Check</TH><TH ><font color=$gentabletext>Manage By</TH>";
    while ($cmdcounter1 <= $listend)
    {
        $readpingerline=trim($pingerlist[$cmdcounter1]);
        list($pingdesc,$pinghost,$pingcount,$pingvnc,$pingwww,$pingtelnet,$pingwwwport,$pingftp,$pingsnmp,$pingcommunity,$pingactive,$pinghttps) = split(",",$readpingerline);
        $pinngerlen=strlen($readpingerline);
        if ($pingactive=="1") {
            $pinngerlen=0;
            $nodisp++;
        }
        if (($pinngerlen>5) && ($pingcount!=0)) {
            if ($phppingersocket==1)
            {
                $ping = new Net_Ping;
                $ping->ping("$pinghost");
                if ($ping->time)
                {
                    $pline1=0;
                    echo "<TR valign=middle><TD bgcolor=$upbgcolour VALIGN=MIDDLE class=\"celllook\"><font color=$uptextcolour><B>$pingdesc is UP</B></font></TD>";
                    echo "<TD valign=middle bgcolor=$upbgcolour class=\"celllook\">";
                    if ($pingertime==1) echo "<input type=button name=\"RESPOND\" STYLE=$okbuttonstyle value=\"Time ".$ping->time."\">";
                    if ($pingtelnet==1) {
                        $pline1++;
                        echo "<input type=button name=\"telnet$cmdcounter1\" STYLE=$okbuttonstyle value=\"Telnet\" onClick=\"javascript:window.open('telnet.php?pinghost=$pinghost','TELNET')\"> ";
                    }
                    if ($pingwww==1) {
                        $pline1++;
                        if ($pingwwwport=="") {
                            $pingwwwport="80";
                        }
                        if ($pinghttps=="") {
                            $pinghttps="http";
                        }
                        echo "<input type=button name=\"www$cmdcounter1\" STYLE=$okbuttonstyle value=\"WWW\" onClick=\"javascript:window.open('$pinghttps://$pinghost:"."$pingwwwport','WEBPAGE')\"> ";
                    }
                    if ($pingftp==1) {
                        $pline1++;
                        echo "<input type=button name=\"www$cmdcounter1\" STYLE=$okbuttonstyle value=\"FTP\" onClick=\"javascript:window.open('ftp://$pinghost','FTP')\"> ";
                    }
                    if ($pingvnc=="1") {
                        $pline1++;
                        $filewrite="[connection]\nhost=$pinghost\nport=5900\npassword= ";
                        $filename="ping.$pinghost.vnc";
                        // append into file
                        if (!$handle = fopen($filename, 'w+')) {
                            print "Cannot open file ($filename)";
                            exit;
                        }
                        if (!fwrite($handle, $filewrite)) {
                            print "Cannot write to file ($filename)";
                            exit;
                        }
                        fclose ($handle);
                        echo "<input type=button name=\"vnc$cmdcounter1\" STYLE=$okbuttonstyle value=\"VNC\" onClick=\"javascript:window.open('$filename')\"> ";
                    }
                    if ($pline1=="0") {
                        echo "&nbsp;";
                    }
                    echo "</TD>";
                }
                else
                {
                    $hostdown++;
                    echo "<TR VALIGN=\"MIDDLE\" class=\"celllook\"><TD bgcolor=$downbgcolour valign=middle class=\"celllook\"><font color=$downtextcolour><B>$pingdesc is DOWN</B></font></TD>";
                    echo "<TD VALIGN=\"MIDDLE\" align=center bgcolor=$downbgcolour class=\"celllook\">&nbsp";
                    //echo "<input type=button value=\"N/A\" STYLE=$errorbuttonstyle>";
                    echo"</TD>";
                }
                echo "</TR>";
            }
            else
            {
                if ($pinngerlen>5) {
                    $pingarray=phpping($pinghost,$pingcount,$pingsystem);
                    if ($pingarray[2]>0) {
                        echo "<TR VALIGN=\"MIDDLE\" class=\"celllook\"><TD bgcolor=$downbgcolour valign=middle class=\"celllook\"><font color=$downtextcolour><B>$pingdesc is DOWN</B></font></TD>";
                        echo "<TD VALIGN=\"MIDDLE\" align=center bgcolor=$downbgcolour class=\"celllook\">&nbsp";
                        //echo "<input type=button value=\"N/A\" STYLE=$errorbuttonstyle>";
                        echo"</TD>";
                    }
                    else
                    {
                        $pline1=0;
                        echo "<TR valign=middle><TD bgcolor=$upbgcolour VALIGN=MIDDLE class=\"celllook\"><font color=$uptextcolour><B>$pingdesc is UP</B></font></TD>";
                        echo "<TD valign=middle bgcolor=$upbgcolour class=\"celllook\">";
                        if ($pingtelnet==1) {
                            $pline1++;
                            echo "<input type=button name=\"telnet$cmdcounter1\" STYLE=$okbuttonstyle value=\"Telnet\" onClick=\"javascript:window.open('telnet.php?pinghost=$pinghost','TELNET')\"> ";
                        }
                        if ($pingwww==1) {
                            $pline1++;
                            if ($pingwwwport=="") {
                                $pingwwwport="80";
                            }
                            if ($pinghttps=="") {
                                $pinghttps="http";
                            }
                            echo "<input type=button name=\"www$cmdcounter1\" STYLE=$okbuttonstyle value=\"WWW\" onClick=\"javascript:window.open('$pinghttps://$pinghost:"."$pingwwwport','WEBPAGE')\"> ";
                        }
                        if ($pingftp==1) {
                            $pline1++;
                            echo "<input type=button name=\"www$cmdcounter1\" STYLE=$okbuttonstyle value=\"FTP\" onClick=\"javascript:window.open('ftp://$pinghost','FTP')\"> ";
                        }
                        if ($pingvnc=="1") {
                            $pline1++;
                            $filewrite="[connection]\nhost=$pinghost\nport=5900\npassword= ";
                            $filename="ping.$pinghost.vnc";
                            // append into file
                            if (!$handle = fopen($filename, 'w+')) {
                                print "Cannot open file ($filename)";
                                exit;
                            }
                            if (!fwrite($handle, $filewrite)) {
                                print "Cannot write to file ($filename)";
                                exit;
                            }
                            fclose ($handle);
                            echo "<input type=button name=\"vnc$cmdcounter1\" STYLE=$okbuttonstyle value=\"VNC\" onClick=\"javascript:window.open('$filename')\"> ";
                        }
                        if ($pline1=="0") {
                            echo "&nbsp;";
                        }
                        echo "</TD>";
                    }
                    echo "</TR>";
                }
            }
        }
        $cmdcounter1++;
    }
    echo "</table>";
    if ($nodisp!=0) {
        echo "<BR>".($listend - $nodisp )." entries checked with $nodisp ";
        if ($nodisp>1) {
            echo "entries ";
        }
        else {
            echo " entry ";
        }
        echo "disabled";
        if ($hostdown==1) echo " and $hostdown host that did not respond.";
        if ($hostdown>1) echo " and $hostdown hosts that did not respond.";
        if ($hostdown==0) echo ".";
        echo "<BR>This page will update every ".$refreshpage." Seconds";
    }
    else {
        echo "<BR>".($listend - $nodisp )." entries checked. ";
        if ($hostdown==1) echo " and $hostdown host that did not respond.";
        if ($hostdown>1) echo " and $hostdown hosts that did not respond.";
        if ($hostdown==0) echo ".";
        echo "<BR>This page will update every ".$refreshpage." Seconds";
    }
}
if ($listend==0) {
    echo "No hosts defined<BR>";
}
echo "<table border=0 CELLPADDING=0 CELLSPACING=0 ><TR><TD>";
jsrefresh();
echo "</td><TD>";
echo jsinputbutton("Add or Edit Pinger file","edit.php");
echo "</td></TR></table>";
?>
Return current item: LSMS SNMP to MRTG toolset