Location: PHPKode > projects > Limph > limph-1.9.7/host_edit.php
<?php
 /*
   Limph Is Monitoring Pingable Hosts
   Copyright (C) 2006 Jonathan Ciesla
   
   This program 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.
   
   This program 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 this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  */
require_once("config.php");
require_once("functionlib.php");
session_start();
favicon();

$link = dbms_connect($dbhost, $dbuser, $dbpass, $dbname);

authentication(0,0);

echo "<link rel=stylesheet href=css.php>";
echo "<title>Limph: $sitetitle</title>";
echo "<h3>Limph: $sitetitle</h3>";

$number = $_POST['host'];
$query = "SELECT name,ip,hostgroup,enabled,timeout,type,port,number,parent,autoupdateip FROM hosts WHERE number = '$number';";
$result = dbms_query($query);
$line = dbms_fetch_array($result, "NUM");
dbms_free_result($result);

$hostname = $line[0];
$host = $line[7];

if($line[9]=="1"){ $autouip = "checked"; } else { $autouip = ""; };

//update diskfree
if($_POST['updatediskfree']=="yes"){
  $diskfree = $_POST['diskfree'];
  $disk = $_POST['disk'];
  $query = "SELECT number FROM thresholds ORDER BY number DESC LIMIT 1;";
  $result = dbms_query($query);
  $line1 = dbms_fetch_array($result, "NUM");
  $value = $line1[0];
  $value++;
  dbms_free_result($result);
  
  $query1 = "SELECT value FROM thresholds WHERE disk = '$disk' AND hostname = '$hostname' AND type = 'diskfree';";
  $query2 = "INSERT INTO thresholds (number,hostname,type,value,disk) VALUES ('$value','$hostname','diskfree','$diskfree','$disk');";
  $query3 = "UPDATE thresholds SET value = '$diskfree' WHERE hostname = '$hostname' AND type = 'diskfree' AND disk = '$disk';";
  $result1 = dbms_query($query1, $link);
  $booda = dbms_fetch_array($result1, "ASSOC");
  if(!$booda){$result2 = dbms_query($query2, $link);};
  dbms_free_result($result1);
  $result3 = dbms_query($query3, $link);
  
 };

//update sysload
if($_POST['updatesysload']=="yes"){
  $sysload1 = $_POST['sysload1'];
  $sysload5 = $_POST['sysload5'];
  $sysload15 = $_POST['sysload15'];
  
  $sysload = $sysload1 . "#" . $sysload5 . "#" . $sysload15;

  $query = "SELECT number FROM thresholds ORDER BY number DESC LIMIT 1;";
  $result = dbms_query($query);
  $line1 = dbms_fetch_array($result, "NUM");
  $value = $line1[0];
  $value++;
  dbms_free_result($result);
  
  $query1 = "SELECT value FROM thresholds WHERE hostname = '$hostname' AND type = 'sysload';";
  $query2 = "INSERT INTO thresholds (number,hostname,type,value) VALUES ('$value','$hostname','sysload','$sysload');";
  $query3 = "UPDATE thresholds SET value = '$sysload' WHERE hostname = '$hostname' AND type = 'sysload';";
  $result1 = dbms_query($query1, $link);
  $booda = dbms_fetch_array($result1, "ASSOC");
  if(!$booda){$result2 = dbms_query($query2, $link);};
  dbms_free_result($result1);
  $result3 = dbms_query($query3, $link);
  
 };

echo "<br />";
echo "<form action=index.php method=post>";
echo "<input type=submit value=Back />";
echo "</form>";

echo "<table border=1 align=center>";
echo "<tr><td valign=top>";

echo "<table border=1 cellpadding=5 align=center>";
echo "<tr><th>Edit Host Info</th></tr>";
echo "<tr><td align=center>";
echo "<form action=index.php method=post>";
echo "<input type=submit value=Delete />";
echo "<input type=hidden name=number value=$number>";
echo "<input type=hidden name=deletehost value=yes>";
echo "</form>";
echo "</td></tr>";
echo "<form action=index.php method=post>";
echo "<tr><td align=right>Name:<input type=text name=name value=\"{$line['0']}\"></td></tr>";
echo "<tr><td align=right>IP:<input type=text name=ip value=\"{$line['1']}\">";
echo "<br />Autoupdate(DHCP)<input type=checkbox name=autoupdateip $autouip>";
echo "<br />Leave blank to obtain from DNS</td></tr>";
if($line[5]=="udp"){$udpflag = "checked";};
if($line[5]=="tcp"){$tcpflag = "checked";};
if($line[5]=="icmp"){$icmpflag = "checked";};
echo "<tr><td>";
echo "Protocol:  ";
echo "ICMP:<input type=radio name=prot value=icmp $icmpflag> UDP:<input type=radio name=prot value=udp $udpflag> TCP:<input type=radio name=prot value=tcp $tcpflag>";
echo "TCP port:<input type=text size=6 name=port value=\"{$line['6']}\">";
echo "</td></tr>";
echo "<tr><td align=right>Group:<select name=group>";
$query = "SELECT number,name FROM groups ORDER BY name;";
$result = dbms_query($query);
while($line2=dbms_fetch_array($result, "NUM")){
  if($line2[0]==$line[2]){
    $flag = "selected";
  } else {
    $flag = "";
  };
  echo "<option value={$line2['0']} $flag>{$line2['1']}";
 };
dbms_free_result($result);
echo "</select></td></tr>";
echo "<tr><td align=right>Parent:<select name=parent>";
echo "<option value=\"\">";
$query = "SELECT number,name FROM hosts ORDER BY name;";
$result = dbms_query($query);
while($line2=dbms_fetch_array($result, "NUM")){
  if($line2[0]==$line[8]){
    $flag = "selected";
  } else {
    $flag = "";
  };
  echo "<option value={$line2['0']} $flag>{$line2['1']}";
 };
dbms_free_result($result);
echo "</select></td></tr>";
if($line[3]=="1"){ $flag = "checked"; } else { $flag = ""; };
echo "<tr><td align=right>Enabled<input type=checkbox name=enabled $flag></td></tr>";
echo "<tr><td align=right>Timeout:<input type=text size=3 name=timeout value={$line['4']}></td></tr>";
echo "<input type=hidden name=edithost value=yes>";
echo "<input type=hidden name=number value=$number>";
echo "<tr><td align=center><input type=submit value=\"Change Host\"></form></td></tr>";
echo "<tr><td align=center>";
echo "<form action=host_notif.php method=post>";
echo "<input type=hidden name=host value=$number />";
echo "<input type=submit value=\"User Notifications\" />";
echo "</form></td></tr>";
echo "</table>";

echo "</td><td valign=top>"; //history

echo "<iframe src=history_data.php?hostname=$hostname width=200 height=400 scrolling=auto frameborder=0></iframe>";

$query = "SELECT COUNT(number) FROM state WHERE hostname = '$hostname';";
$result = dbms_query($query);
$line = dbms_fetch_array($result, "NUM");
dbms_free_result($result);
if($line[0]>0){
  echo "</td><td valign=top>";  //state
  //thresholds
  
  echo "<table border=1 align=center>";
  echo "<tr><th colspan=2>Thresholds</th></tr>";
  
  $query = "SELECT DISTINCT type FROM state WHERE hostname = '$hostname';";
  $result4 = dbms_query($query);
  while($types = dbms_fetch_array($result4, "ASSOC")){
    if($types['type']=="diskfree"){
      $query = "SELECT DISTINCT disk FROM state WHERE hostname = '$hostname' AND type = '{$types['type']}';";
      $result5 = dbms_query($query);
      while($disks = dbms_fetch_array($result5, "ASSOC")){
	
	//get existing diskfree threshold
	$query = "SELECT value FROM thresholds WHERE disk = '{$disks['disk']}' AND hostname = '$hostname' AND type = 'diskfree';";
	$result = dbms_query($query);
	$line = dbms_fetch_array($result, "ASSOC");
	dbms_free_result($result);
	$diskfree = $line['value'];
	
	echo "<form action=host_edit.php method=post>";
	
	echo "<tr>";
	echo "<td>Diskfree(bytes)</td>";
	echo "<td align=right>{$disks['disk']} <input type=text size=10 name=diskfree value=\"$diskfree\">";
	echo "<input type=submit value=\"\">";
	echo "</tr>";
	echo "<input type=hidden name=disk value=\"{$disks['disk']}\">";
	echo "<input type=hidden name=host value=\"$host\">";
	echo "<input type=hidden name=updatediskfree value=yes>";
	echo "</form>";
	
      };
      dbms_free_result($result5);
    };
    if($types['type']=="sysload"){
      //get existing sysload threshold
      $query = "SELECT value FROM thresholds WHERE hostname = '$hostname' and type = 'sysload';";
      $result = dbms_query($query);
      $line = dbms_fetch_array($result, "ASSOC");
      $sysload = $line['value'];
      dbms_free_result($result);
      echo "<form action=host_edit.php method=post>";
      
      $sysload_a = explode("#", $sysload);

      echo "<tr>";
      echo "<td>Sysload(1/5/15 min)</td>";
      echo "<td align=center>";
      echo "<input type=text size=2 name=sysload1 value=\"{$sysload_a['0']}\">";
      echo "<input type=text size=2 name=sysload5 value=\"{$sysload_a['1']}\">";
      echo "<input type=text size=2 name=sysload15 value=\"{$sysload_a['2']}\">";
      echo "<input type=submit value=\"\"></td>"; 
      echo "</tr>";
      echo "<input type=hidden name=host value=\"$host\">";
      echo "<input type=hidden name=updatesysload value=yes>";
      echo "</form>";
    };
  };

  dbms_free_result($result4);

  echo "</table>";
  
  //state history iframe
  echo "<iframe src=history_state.php?hostname=$hostname height=320 scrolling=auto frameborder=0></iframe>";
  
  dbms_close($link);
};

echo "</td><td valign=top>"; //portscan iframe
echo "<iframe src=port_scan.php height=400></iframe>";

echo "</td></tr></table>";

echo "<br />";
echo "<form action=index.php method=post>";
echo "<input type=submit value=Back />";
echo "</form>";

?>
Return current item: Limph