From 462b41c4f8dc1f5b9bf5044e86ed10ee1622fe13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awomir=20Paszkiewicz?= Date: Fri, 9 Oct 2015 19:41:19 +0200 Subject: [PATCH] - applied changes made by f0o --- discovery.php | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/discovery.php b/discovery.php index c1c4ef635..e29b4d60d 100755 --- a/discovery.php +++ b/discovery.php @@ -22,8 +22,8 @@ require 'includes/discovery/functions.inc.php'; $start = utime(); $runtime_stats = array(); - -$options = getopt('h:m:i:n:d::a::q',['os:']); +$sqlparams = array(); +$options = getopt('h:m:i:n:d::a::q',array('os:','type:')); if (!isset($options['q'])) { echo $config['project_name_version']." Discovery\n"; @@ -47,10 +47,6 @@ if (isset($options['h'])) { $where = 'AND `last_discovered` IS NULL'; $doing = 'new'; } - else if ($options['h'] == 'linux') { - $where = 'AND os = "linux"'; - $doing = 'linux'; - } else if ($options['h']) { if (is_numeric($options['h'])) { $where = "AND `device_id` = '".$options['h']."'"; @@ -64,17 +60,17 @@ if (isset($options['h'])) { }//end if if (isset($options['os'])) { - $where = $where." AND os = '".$options['os']."'"; - $doing = $options['os']; + $where .= " AND os = ?"; + $sqlparams[] = $options['os']; } if (isset($options['type'])) { - $where = $where." AND type = '".$options['type']."'"; - $doing = $options['type']; + $where .= " AND type = ?"; + $sqlparams[] = $options['type']; } if (isset($options['i']) && $options['i'] && isset($options['n'])) { - $where = 'AND MOD(device_id,'.$options['i'].") = '".$options['n']."'"; + $where .= ' AND MOD(device_id,'.$options['i'].") = '".$options['n']."'"; $doing = $options['n'].'/'.$options['i']; } @@ -100,10 +96,10 @@ if (!$where) { echo "-h even Poll even numbered devices (same as -i 2 -n 1)\n"; echo "-h all Poll all devices\n"; echo "-h new Poll all devices that have not had a discovery run before\n"; - echo "-h [odd|even|new|all] --os Poll devices only with specified operating system\n"; - echo "-h [odd|even|new|all] --type Poll devices only with specified type\n\n"; + echo "--os Poll devices only with specified operating system\n"; + echo "--type Poll devices only with specified type\n"; echo "-i -n Poll as instance of \n"; - echo " Instances start at 0. 0-3 for -n 4\n\n"; + echo " Instances start at 0. 0-3 for -n 4\n"; echo "\n"; echo "Debugging and testing options:\n"; echo "-d Enable debugging output\n"; @@ -121,7 +117,7 @@ if ($config['distributed_poller'] === true) { $where .= ' AND poller_group IN('.$config['distributed_poller_group'].')'; } -foreach (dbFetch("SELECT * FROM `devices` WHERE status = 1 AND disabled = 0 $where ORDER BY device_id DESC") as $device) { +foreach (dbFetch("SELECT * FROM `devices` WHERE status = 1 AND disabled = 0 $where ORDER BY device_id DESC",$sqlparams) as $device) { discover_device($device, $options); }