From cb41d5009471d274b9654b10927e39baacd9bebc Mon Sep 17 00:00:00 2001 From: bohdan-s Date: Sat, 21 Jun 2014 08:02:27 -0400 Subject: [PATCH 1/4] Add IPv6 only host support --- html/pages/addhost.inc.php | 15 ++++++++++++--- includes/functions.php | 5 +++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/html/pages/addhost.inc.php b/html/pages/addhost.inc.php index b2bb5e792..f5a84f420 100644 --- a/html/pages/addhost.inc.php +++ b/html/pages/addhost.inc.php @@ -24,7 +24,8 @@ if ($_POST['hostname']) $snmpver = mres($_POST['snmpver']); if ($_POST['port']) { $port = mres($_POST['port']); } else { $port = $config['snmp']['port']; } - print_message("Adding host $hostname communit" . (count($config['snmp']['community']) == 1 ? "y" : "ies") . " " . implode(', ',$config['snmp']['community']) . " port $port"); + $transport = mres($_POST['transport']); + print_message("Adding host $hostname communit" . (count($config['snmp']['community']) == 1 ? "y" : "ies") . " " . implode(', ',$config['snmp']['community']) . " port $port using $transport"); } elseif ($_POST['snmpver'] === "v3") { @@ -48,7 +49,7 @@ if ($_POST['hostname']) { print_error("Unsupported SNMP Version. There was a dropdown menu, how did you reach this error ?"); } - $result = addHost($hostname, $snmpver, $port); + $result = addHost($hostname, $snmpver, $port, $transport); if ($result) { print_message("Device added ($result)"); @@ -75,7 +76,7 @@ $pagetitle[] = "Add host";
-
+
+
+ +
diff --git a/includes/functions.php b/includes/functions.php index c6eefb8de..38932d516 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -261,7 +261,8 @@ function addHost($host, $snmpver, $port = '161', $transport = 'udp') if (dbFetchCell("SELECT COUNT(*) FROM `devices` WHERE `hostname` = ?", array($host)) == '0') { // Test DNS lookup - if (gethostbyname($host) != $host) + //if (gethostbyname($host) != $host) + if (!(inet_pton($host))) { // Test reachability if (isPingable($host)) @@ -350,7 +351,7 @@ function addHost($host, $snmpver, $port = '161', $transport = 'udp') print_error("Could not ping $host"); } } else { // Failed DNS lookup - print_error("Could not resolve $host"); } + print_error("$host looks like an IP address, please use FQDN"); } } else { // found in database print_error("Already got host $host"); From b5f38f6a30beb5e6c5541c9a12622d7bb5bb6383 Mon Sep 17 00:00:00 2001 From: bohdan-s Date: Sat, 21 Jun 2014 08:06:28 -0400 Subject: [PATCH 2/4] Fix typo --- includes/functions.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index 38932d516..4ab9d9d83 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -260,8 +260,7 @@ function addHost($host, $snmpver, $port = '161', $transport = 'udp') // Test Database Exists if (dbFetchCell("SELECT COUNT(*) FROM `devices` WHERE `hostname` = ?", array($host)) == '0') { - // Test DNS lookup - //if (gethostbyname($host) != $host) + // Test if IP or Hostname if (!(inet_pton($host))) { // Test reachability From f9a7441b4e546cfd23b21802ab2ecae240bf7cb1 Mon Sep 17 00:00:00 2001 From: bohdan-s Date: Mon, 23 Jun 2014 19:29:53 -0400 Subject: [PATCH 3/4] Fix $transport not defined bug --- html/pages/addhost.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/pages/addhost.inc.php b/html/pages/addhost.inc.php index f5a84f420..828ab19f8 100644 --- a/html/pages/addhost.inc.php +++ b/html/pages/addhost.inc.php @@ -24,7 +24,7 @@ if ($_POST['hostname']) $snmpver = mres($_POST['snmpver']); if ($_POST['port']) { $port = mres($_POST['port']); } else { $port = $config['snmp']['port']; } - $transport = mres($_POST['transport']); + if ($_POST['transport']) { $transport = mres($_POST['transport']); } else { $transport = "udp"; } print_message("Adding host $hostname communit" . (count($config['snmp']['community']) == 1 ? "y" : "ies") . " " . implode(', ',$config['snmp']['community']) . " port $port using $transport"); } elseif ($_POST['snmpver'] === "v3") From df9a5ee65f2850cb65ed4c3248863e2dcfe07067 Mon Sep 17 00:00:00 2001 From: bohdan-s Date: Mon, 23 Jun 2014 20:20:48 -0400 Subject: [PATCH 4/4] Move SNMP Transport & Port check to common area --- html/pages/addhost.inc.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/html/pages/addhost.inc.php b/html/pages/addhost.inc.php index 828ab19f8..2e3202b8e 100644 --- a/html/pages/addhost.inc.php +++ b/html/pages/addhost.inc.php @@ -13,7 +13,10 @@ if ($_POST['hostname']) { if ($_SESSION['userlevel'] > '5') { + // Settings common to SNMPv2 & v3 $hostname = mres($_POST['hostname']); + if ($_POST['port']) { $port = mres($_POST['port']); } else { $port = $config['snmp']['port']; } + if ($_POST['transport']) { $transport = mres($_POST['transport']); } else { $transport = "udp"; } if ($_POST['snmpver'] === "v2c" or $_POST['snmpver'] === "v1") { @@ -23,8 +26,6 @@ if ($_POST['hostname']) } $snmpver = mres($_POST['snmpver']); - if ($_POST['port']) { $port = mres($_POST['port']); } else { $port = $config['snmp']['port']; } - if ($_POST['transport']) { $transport = mres($_POST['transport']); } else { $transport = "udp"; } print_message("Adding host $hostname communit" . (count($config['snmp']['community']) == 1 ? "y" : "ies") . " " . implode(', ',$config['snmp']['community']) . " port $port using $transport"); } elseif ($_POST['snmpver'] === "v3") @@ -41,8 +42,6 @@ if ($_POST['hostname']) array_push($config['snmp']['v3'], $v3); $snmpver = "v3"; - - if ($_POST['port']) { $port = mres($_POST['port']); } else { $port = $config['snmp']['port']; } print_message("Adding SNMPv3 host $hostname port $port"); } else