Location: PHPKode > projects > Limph > limph-1.9.7/bulk_add.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();

echo "<html><head><title>$sitetitle</title></head>";
echo "<body><h1>$sitetitle: Bulk Host Addition</h1>";

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

$user_id = dbms_escape_string($_SESSION['limphid']);

$admin_level =$_SESSION['limphadmin'];
authentication($admin_level,1);

echo "<link rel=stylesheet href=css.php>";

foreach($_POST['udp'] as $udp){
  $query = "SELECT number FROM hosts ORDER BY number DESC LIMIT 1;";
  $result = dbms_query($query);
  $line = dbms_fetch_array($result, "NUM");
  $value = $line[0];
  $value++;
  dbms_free_result($result);
  
  $name = dbms_escape_string(gethostbyaddr($udp));

  $query = "INSERT INTO hosts (number,name,ip,hostgroup,status,enabled,timeout,type,port,parent) VALUES ('$value','$name','$udp','0','1','1','1','udp','0','0');";
  $result = dbms_query($query);
  echo $udp . " UDP check added.";
  echo "<br />";
};
  foreach($_POST['tcp'] as $tcp){
    $pars = explode(":", $tcp);
    $query = "SELECT number FROM hosts ORDER BY number DESC LIMIT 1;";
    $result = dbms_query($query);
    $line = dbms_fetch_array($result, "NUM");
    $value = $line[0];
    $value++;
    dbms_free_result($result);
    
    $name = dbms_escape_string(gethostbyaddr($pars[0]));
  
    $query = "INSERT INTO hosts (number,name,ip,hostgroup,status,enabled,timeout,type,port,parent) VALUES ('$value','$name','{$pars[0]}','0','1','1','1','tcp','{$pars[1]}','0');";
    $result = dbms_query($query);
    echo $pars[0] . ":" . $pars[1] . " TCP check added.";
    echo "<br />";
  };

echo "<br />";
echo "<form action=ungrouped.php method=post>";
echo "<input type=submit value=\"View Ungrouped Hosts\" />";
echo "</form>";

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

?>
Return current item: Limph