diff --git a/src/www/services_snmp.php b/src/www/services_snmp.php index 33e6c3191..ce387ef70 100644 --- a/src/www/services_snmp.php +++ b/src/www/services_snmp.php @@ -1,30 +1,30 @@ . - All rights reserved. + Copyright (C) 2014-2016 Deciso B.V. + Copyright (C) 2003-2004 Manuel Kasper . + All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. */ require_once("guiconfig.inc"); @@ -32,468 +32,321 @@ require_once("interfaces.inc"); require_once("services.inc"); require_once("system.inc"); -if (!is_array($config['snmpd'])) { - $config['snmpd'] = array(); - $config['snmpd']['rocommunity'] = "public"; - $config['snmpd']['pollport'] = "161"; + +if ($_SERVER['REQUEST_METHOD'] === 'GET') { + $pconfig = array(); + if (empty($config['snmpd']) || !is_array($config['snmpd'])) { + // set defaults (no config) + $pconfig['rocommunity'] = "public"; + $pconfig['pollport'] = "161"; + $pconfig['mibii'] = true; + $pconfig['netgraph'] = true; + $pconfig['pf'] = true; + $pconfig['hostres'] = true; + $pconfig['bridge'] = true; + $pconfig['ucd'] = true; + $pconfig['regex'] = true; + } else { + // modules + foreach (array('mibii', 'netgraph', 'pf', 'hostres', 'bridge', 'ucd', 'regex') as $module) { + $pconfig[$module] = !empty($config['snmpd']['modules'][$module]); + } + // booleans + $pconfig['enable'] = isset($config['snmpd']['enable']); + $pconfig['trapenable'] = isset($config['snmpd']['trapenable']); + // text fields + foreach (array('rocommunity', 'pollport', 'syslocation', 'syscontact', + 'trapserver', 'trapserverport', 'trapstring', 'bindip') as $fieldname) { + $pconfig[$fieldname] = !empty($config['snmpd'][$fieldname]) ? $config['snmpd'][$fieldname] : null; + } + } +} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { + $input_errors = array(); + $pconfig = $_POST; + // input validation + if (strstr($pconfig['syslocation'],"#")) { + $input_errors[] = gettext("Invalid character '#' in system location"); + } + if (strstr($pconfig['syscontact'],"#")) { + $input_errors[] = gettext("Invalid character '#' in system contact"); + } + if (strstr($pconfig['rocommunity'],"#")) { + $input_errors[] = gettext("Invalid character '#' in read community string"); + } + + if (!empty($pconfig['enable'])) { + $reqdfields = array("rocommunity", "pollport"); + $reqdfieldsn = array(gettext("Community"), gettext("Polling Port")); + do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors); + } + + if (strstr($pconfig['trapstring'],"#")) { + $input_errors[] = gettext("Invalid character '#' in SNMP trap string"); + } + + if (!empty($pconfig['trapenable'])) { + $reqdfields = array("trapserver", "trapserverport", "trapstring"); + $reqdfieldsn = array(gettext("Trap server"), gettext("Trap server port"), gettext("Trap string")); + do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors); + } + + if (count($input_errors) == 0) { + // save form data + // modules + $snmp = array(); + $snmp['modules'] = array(); + foreach (array('mibii', 'netgraph', 'pf', 'hostres', 'bridge', 'ucd', 'regex') as $module) { + $snmp['modules'][$module] = !empty($pconfig[$module]); + } + // booleans + $snmp['enable'] = !empty($pconfig['enable']); + $snmp['trapenable'] = !empty($pconfig['trapenable']); + // text fields + foreach (array('rocommunity', 'pollport', 'syslocation', 'syscontact', + 'trapserver', 'trapserverport', 'trapstring', 'bindip') as $fieldname) { + $snmp[$fieldname] = $pconfig[$fieldname]; + } + $config['snmpd'] = $snmp; + // save and apply + write_config(); + services_snmpd_configure(); + get_std_save_message(); + header("Location: services_snmp.php"); + exit; + } } -if (!is_array($config['snmpd']['modules'])) { - $config['snmpd']['modules'] = array(); - $config['snmpd']['modules']['mibii'] = true; - $config['snmpd']['modules']['netgraph'] = true; - $config['snmpd']['modules']['pf'] = true; - $config['snmpd']['modules']['hostres'] = true; - $config['snmpd']['modules']['bridge'] = true; - $config['snmpd']['modules']['ucd'] = true; - $config['snmpd']['modules']['regex'] = true; -} -$pconfig['enable'] = isset($config['snmpd']['enable']); -$pconfig['pollport'] = $config['snmpd']['pollport']; -$pconfig['syslocation'] = $config['snmpd']['syslocation']; -$pconfig['syscontact'] = $config['snmpd']['syscontact']; -$pconfig['rocommunity'] = $config['snmpd']['rocommunity']; -/* disabled until some docs show up on what this does. -$pconfig['rwenable'] = isset($config['snmpd']['rwenable']); -$pconfig['rwcommunity'] = $config['snmpd']['rwcommunity']; -*/ -$pconfig['trapenable'] = isset($config['snmpd']['trapenable']); -$pconfig['trapserver'] = $config['snmpd']['trapserver']; -$pconfig['trapserverport'] = $config['snmpd']['trapserverport']; -$pconfig['trapstring'] = $config['snmpd']['trapstring']; - -$pconfig['mibii'] = isset($config['snmpd']['modules']['mibii']); -$pconfig['netgraph'] = isset($config['snmpd']['modules']['netgraph']); -$pconfig['pf'] = isset($config['snmpd']['modules']['pf']); -$pconfig['hostres'] = isset($config['snmpd']['modules']['hostres']); -$pconfig['bridge'] = isset($config['snmpd']['modules']['bridge']); -$pconfig['ucd'] = isset($config['snmpd']['modules']['ucd']); -$pconfig['regex'] = isset($config['snmpd']['modules']['regex']); -$pconfig['bindip'] = $config['snmpd']['bindip']; - -if ($_POST) { - - unset($input_errors); - $pconfig = $_POST; - - /* input validation */ - if ($_POST['enable']) { - if (strstr($_POST['syslocation'],"#")) $input_errors[] = gettext("Invalid character '#' in system location"); - if (strstr($_POST['syscontact'],"#")) $input_errors[] = gettext("Invalid character '#' in system contact"); - if (strstr($_POST['rocommunity'],"#")) $input_errors[] = gettext("Invalid character '#' in read community string"); - - $reqdfields = explode(" ", "rocommunity"); - $reqdfieldsn = array(gettext("Community")); - do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors); - - $reqdfields = explode(" ", "pollport"); - $reqdfieldsn = array(gettext("Polling Port")); - do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors); - - - } - - if ($_POST['trapenable']) { - if (strstr($_POST['trapstring'],"#")) $input_errors[] = gettext("Invalid character '#' in SNMP trap string"); - - $reqdfields = explode(" ", "trapserver"); - $reqdfieldsn = array(gettext("Trap server")); - do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors); - - $reqdfields = explode(" ", "trapserverport"); - $reqdfieldsn = array(gettext("Trap server port")); - do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors); - - $reqdfields = explode(" ", "trapstring"); - $reqdfieldsn = array(gettext("Trap string")); - do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors); - } - - -/* disabled until some docs show up on what this does. - if ($_POST['rwenable']) { - $reqdfields = explode(" ", "rwcommunity"); - $reqdfieldsn = explode(",", "Write community string"); - do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors); - } -*/ - - - - if (!$input_errors) { - $config['snmpd']['enable'] = $_POST['enable'] ? true : false; - $config['snmpd']['pollport'] = $_POST['pollport']; - $config['snmpd']['syslocation'] = $_POST['syslocation']; - $config['snmpd']['syscontact'] = $_POST['syscontact']; - $config['snmpd']['rocommunity'] = $_POST['rocommunity']; - /* disabled until some docs show up on what this does. - $config['snmpd']['rwenable'] = $_POST['rwenable'] ? true : false; - $config['snmpd']['rwcommunity'] = $_POST['rwcommunity']; - */ - $config['snmpd']['trapenable'] = $_POST['trapenable'] ? true : false; - $config['snmpd']['trapserver'] = $_POST['trapserver']; - $config['snmpd']['trapserverport'] = $_POST['trapserverport']; - $config['snmpd']['trapstring'] = $_POST['trapstring']; - - $config['snmpd']['modules']['mibii'] = $_POST['mibii'] ? true : false; - $config['snmpd']['modules']['netgraph'] = $_POST['netgraph'] ? true : false; - $config['snmpd']['modules']['pf'] = $_POST['pf'] ? true : false; - $config['snmpd']['modules']['hostres'] = $_POST['hostres'] ? true : false; - $config['snmpd']['modules']['bridge'] = $_POST['bridge'] ? true : false; - $config['snmpd']['modules']['ucd'] = $_POST['ucd'] ? true : false; - $config['snmpd']['modules']['regex'] = $_POST['regex'] ? true : false; - $config['snmpd']['bindip'] = $_POST['bindip']; - - write_config(); - - $retval = 0; - $retval = services_snmpd_configure(); - $savemsg = get_std_save_message(); - } -} $service_hook = 'bsnmpd'; - +legacy_html_escape_form_data($pconfig); include("head.inc"); - ?> - +
+
+
+ 0) print_input_errors($input_errors); ?> +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +    +
+ /> +
+ + +
+ +
+ +
+ + +
+
+
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
+ /> +
+ + +
+ + +
+ + +
+
+
+
+
+
+
+ + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ /> +
+ /> +
+ /> +
+ /> +
+ /> +
+ /> +
+
+
+
+
+
+
+
+ + + + + + + + + + + + + + + + +
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - ?> -
- onclick="enable_change(this)" /> -
- -

-
- -
- -
- -

-
  - onclick="enable_change(this)" /> - Enable Write Community String -
Write community string - -
Please use something other than "private" here
-
- - - - - -
-
- -
-

-
- -
- - -
- - - - - - - - - - - - - - - - - - - - - - - -
- onclick="enable_change(this)" /> -
- -

-
- -

-
- -

-
-
-
- -
-
-
-
- -
-

-
- -
- - -
- - - - - - - - -
- /> -
- /> -
- /> -
- /> -
- /> -
- /> -
-
-
-
- -
-
-
-
- -
-

-
- -
- - -
- - - - - - - - - - -
- -
  - " onclick="enable_change(true)" /> -
-
-
-
-
- - - - - - + + + +
  + " /> +
+
+
+
+ +
+
+