Location: PHPKode > projects > LSMS SNMP to MRTG toolset > www/snmpmrtg/phpping/update.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';
echo $htmlheader;
$command=$HTTP_GET_VARS["command"];
if ($command =="" ) $command = $HTTP_POST_VARS["command"];
$pinghost=$HTTP_GET_VARS["pinghost"];
if ($pinghost =="" ) $pinghost = $HTTP_POST_VARS["pinghost"];
$pingdesc=$HTTP_GET_VARS["pingdesc"];
if ($pingdesc =="" ) $pingdesc = $HTTP_POST_VARS["pingdesc"];
$pingcount=$HTTP_GET_VARS["pingcount"];
if ($pingcount =="" ) $pingcount = $HTTP_POST_VARS["pingcount"];
$pingvnc=$HTTP_GET_VARS["pingvnc"];
if ($pingvnc =="" ) $pingvnc = $HTTP_POST_VARS["pingvnc"];
$pingwww=$HTTP_GET_VARS["pingwww"];
if ($pingwww =="" ) $pingwww = $HTTP_POST_VARS["pingwww"];
$pingwwwport=$HTTP_GET_VARS["pingwwwport"];
if ($pingwwwport =="" ) $pingwwwport = $HTTP_POST_VARS["pingwwwport"];
$pingftp=$HTTP_GET_VARS["pingftp"];
if ($pingftp =="" ) $pingftp = $HTTP_POST_VARS["pingftp"];
$pingsnmp=$HTTP_GET_VARS["pingsnmp"];
if ($pingsnmp =="" ) $pingsnmp = $HTTP_POST_VARS["pingsnmp"];
$pingcommunity=$HTTP_GET_VARS["pingcommunity"];
if ($pingcommunity =="" ) $pingcommunity = $HTTP_POST_VARS["pingcommunity"];
$pingtelnet=$HTTP_GET_VARS["pingtelnet"];
if ($pingtelnet =="" ) $pingtelnet = $HTTP_POST_VARS["pingtelnet"];
$pingline=$HTTP_GET_VARS["pingline"];
if ($pingline =="" ) $pingline = $HTTP_POST_VARS["pingline"];
$pingactive=$HTTP_GET_VARS["pingactive"];
$pinghttps=$HTTP_GET_VARS["pinghttps"];
if ($pingcount=="on") {$pingcount="1";} else {$pingcount="0";}
if ($pinghttps =="" ) $pinghttps = $HTTP_POST_VARS["pinghttps"];
if ($pingactive =="" ) $pingactive = $HTTP_POST_VARS["pingactive"];
if ($pingwww=="on") {$pingwww="1";} else {$pingwww="0";}
if ($pingvnc=="on") {$pingvnc="1";} else {$pingvnc="0";}
if ($pingftp=="on") {$pingftp="1";} else {$pingftp="0";}
if ($pingsnmp=="on") {$pingsnmp="1";} else {$pingsnmp="0";}
if ($pingwwwport=="") {$pingwwwport="80";}
if ($pingtelnet=="on") {$pingtelnet="1";} else {$pingtelnet="0";}
if ($pingactive=="on") {$pingactive="1";} else {$pingactive="0";}

$redirurl=gethtmlpath($pingsystem);

echo "<script type=\"text/javascript\">";
echo "
function exticode()
{
    top.maintop.location=\"../top.php?toprebuild=yes\"
    top.mainright.location=\"".$redirurl."/index.php\"
}
</script>";

if ($command=="add")
{
    $handleout = fopen ("run.pinger", "a+");
    $outline=trim("$pingdesc,$pinghost,$pingcount,$pingvnc,$pingwww,$pingtelnet,$pingwwwport,$pingftp,$pingsnmp,$pingcommunity,$pingactive,$pinghttps");
    fwrite($handleout,"$outline\n");
    fclose ($handleout);
    echo "<BODY onLoad=\"exticode()\">";
}
if ($command=="update")
{
    $tmp1=file2array("run.pinger");
    $cmdcounter1=0;
    $cmdcounter2=0;
    $listend=$tmp1[0];
    $refreshpage=(30+($listend*2));
    $pinglist=array();
    $pinglist1=array();
    if ($listend!=0) {
        $pingerlist=$tmp1[1];
        SORT($pingerlist);
        while ($cmdcounter1 <= $listend)
        {
            $readpingerline=$pingerlist[$cmdcounter1];
            if ($pingline == $cmdcounter1) {
                $readpingerline=trim("$pingdesc,$pinghost,$pingcount,$pingvnc,$pingwww,$pingtelnet,$pingwwwport,$pingftp,$pingsnmp,$pingcommunity,$pingactive,$pinghttps");
            }
            else
            {
                $readpingerline=trim($pingerlist[$cmdcounter1]);
            }
            if ($pingwwwport=="") {$pingwwwport="80";}
            if ($pinghttps=="") {$pinghttps="http";}
            $pinglist1[]=$readpingerline;
            $cmdcounter1++;
        }
        $cmdcounter1=0;
        $cmdcounter2=0;
        $listend2=$listend;
        $handle = fopen ("run.pinger", "w+");
        while ($cmdcounter1 <= $listend2)
        {
            fwrite($handle,"$pinglist1[$cmdcounter1]\n");
            $cmdcounter1++;
        }
        fclose ($handle);
    }
    echo "<BODY onLoad=\"exticode()\">";
}
if ($command=="delete")
{
    $tmp1=file2array("run.pinger");
    $cmdcounter1=0;
    $cmdcounter2=0;
    $listend=$tmp1[0];
    $refreshpage=(30+($listend*2));
    $pinglist=array();
    $pinglist1=array();
    if ($listend!=0) {
        $pingerlist=$tmp1[1];
        SORT($pingerlist);
        while ($cmdcounter1 <= $listend)
        {
            $readpingerline=$pingerlist[$cmdcounter1];
            if ($cmdcounter1!=$pingline) {$pinglist1[]=$readpingerline;}
            $cmdcounter1++;
        }
        $cmdcounter1=0;
        $cmdcounter2=0;
        $listend2=$listend - 1;
        $handle = fopen ("run.pinger", "w+");
        while ($cmdcounter1 <= $listend2)
        {
            fwrite($handle,"$pinglist1[$cmdcounter1]");
            $cmdcounter1++;
        }
        fclose ($handle);
    }
    echo "<BODY onLoad=\"exticode()\">";
}
?>
Return current item: LSMS SNMP to MRTG toolset