From 6e164d35ff1864f48f905fbf4ba9186c852ed42d Mon Sep 17 00:00:00 2001 From: Adam Amstrong Date: Thu, 12 May 2011 14:10:50 +0000 Subject: [PATCH] safer createHost() git-svn-id: http://www.observium.org/svn/observer/trunk@2280 61d68cd4-352d-0410-923a-c4978735b2b8 --- includes/functions.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index 48277932d7..c8ccb2aa34 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -365,15 +365,17 @@ function utime() function createHost($host, $community, $snmpver, $port = 161, $transport = 'udp') { $host = trim(strtolower($host)); - $device = deviceArray($host, $community, $snmpver, $port, $transport); - $host_os = getHostOS($device); + $device = array('hostname' => $host, 'sysName' => $host, 'community' => $community, 'port' => $port, 'transport' => $transport, 'status' => '1', 'snmpver' => $snmpver); + $device['os'] = getHostOS($device); - if ($host_os) + if ($device['os']) { - $sql = mysql_query("INSERT INTO `devices` (`hostname`, `sysName`, `community`, `port`, `transport`, `os`, `status`,`snmpver`) VALUES ('$host', '$host', '$community', '$port', '$transport', '$host_os', '1','$snmpver')"); - if (mysql_affected_rows()) + + $id = dbInsert($device, 'devices'); + + if ($id) { - return("Created host : $host (id:".mysql_insert_id().") (os:$host_os)"); + return("Created host : $host (id:".$id.") (os:".$device['os'].")"); } else {