hasGlobalAdmin()) { $force_save = ($_POST['force_save'] == 'on'); $poller_group = isset($_POST['poller_group']) ? clean($_POST['poller_group']) : 0; $snmp_enabled = ($_POST['snmp'] == 'on'); if ($snmp_enabled) { $max_repeaters = clean($_POST['max_repeaters']); $max_oid = clean($_POST['max_oid']); $port = $_POST['port'] ? clean($_POST['port']) : Config::get('snmp.port'); $port_assoc_mode = clean($_POST['port_assoc_mode']); $retries = clean($_POST['retries']); $snmpver = clean($_POST['snmpver']); $transport = $_POST['transport'] ? clean($_POST['transport']) : $transport = 'udp'; $timeout = clean($_POST['timeout']); $update = array( 'poller_group' => $poller_group, 'port' => $port, 'port_association_mode' => $port_assoc_mode, 'snmp_disable' => 0, 'snmpver' => $snmpver, 'transport' => $transport, ); if ($retries) { $update['retries'] = $retries; } else { $update['retries'] = array('NULL'); } if ($snmpver != "v3") { $community = clean($_POST['community']); $update['community' ] = $community; } if ($timeout) { $update['timeout'] = $timeout; } else { $update['timeout'] = array('NULL'); } $v3 = array(); if ($snmpver == "v3") { $community = ''; // if v3 works, we don't need a community $v3['authalgo'] = clean($_POST['authalgo']); $v3['authlevel'] = clean($_POST['authlevel']); $v3['authname'] = clean($_POST['authname']); $v3['authpass'] = clean($_POST['authpass']); $v3['cryptoalgo'] = clean($_POST['cryptoalgo']); $v3['cryptopass'] = clean($_POST['cryptopass']); $update = array_merge($update, $v3); } } else { // snmp is disabled $update['features'] = null; $update['hardware'] = clean($_POST['hardware']); $update['icon'] = null; $update['os'] = $_POST['os'] ? clean($_POST['os_id']) : "ping"; $update['poller_group'] = $poller_group; $update['snmp_disable'] = 1; $update['sysName'] = $_POST['sysName'] ? clean($_POST['sysName']) : null; $update['version'] = null; } $device_is_snmpable = false; $rows_updated=0; if ($force_save !== true && $snmp_enabled) { $device_snmp_details = deviceArray($device['hostname'], $community, $snmpver, $port, $transport, $v3, $port_assoc_mode); $device_issnmpable= isSNMPable($device_snmp_details); } if ($force_save === true || !$snmp_enabled || $device_issnmpable) { // update devices table $rows_updated = dbUpdate($update, 'devices', '`device_id` = ?', array($device['device_id'])); } if ($snmp_enabled && ($force_save === true || $device_issnmpable)) { // update devices_attribs table // note: // set_dev_attrib and del_dev_attrib *only* return (bool) // setAttrib() returns true if it was set and false if it was not (e.g. it didn't change) // forgetAttrib() returns true if it was deleted and false if it was not (e.g. it didn't exist) // Symfony throws FatalThrowableError on error $devices_attribs=array('snmp_max_repeaters', 'snmp_max_oid'); foreach ($devices_attribs as $devices_attrib) { // defaults $feedback_prefix=$devices_attrib; $form_value=null; $form_value_is_numeric=false; // does not need to be a number greater than zero if ($devices_attrib == 'snmp_max_repeaters') { $feedback_prefix="SNMP Max Repeaters"; $form_value=$max_repeaters; $form_value_is_numeric=true; } if ($devices_attrib == 'snmp_max_oid') { $feedback_prefix="SNMP Max OID"; $form_value=$max_oid; $form_value_is_numeric=true; } $get_devices_attrib = get_dev_attrib($device, $devices_attrib); $set_devices_attrib = false; // testing $set_devices_attrib === false is not a true indicator of a failure if ($form_value != $get_devices_attrib && $form_value_is_numeric && is_numeric($form_value) && $form_value != 0) { $set_devices_attrib=set_dev_attrib($device, $devices_attrib, $form_value); } if ($form_value != $get_devices_attrib && !$form_value_is_numeric) { $set_devices_attrib=set_dev_attrib($device, $devices_attrib, $form_value); } if ($form_value != $get_devices_attrib && $form_value_is_numeric && !is_numeric($form_value)) { $set_devices_attrib=del_dev_attrib($device, $devices_attrib); } if ($form_value != $get_devices_attrib && !$form_value_is_numeric && $form_value == '') { $set_devices_attrib=del_dev_attrib($device, $devices_attrib); } if ($form_value != $get_devices_attrib && $set_devices_attrib) { $set_devices_attrib = get_dev_attrib($device, $devices_attrib); // re-check the db value } if ($form_value != $get_devices_attrib && $form_value == $set_devices_attrib && (is_null($set_devices_attrib) || $set_devices_attrib == '')) { $update_message[] = "$feedback_prefix deleted"; } if ($form_value != $get_devices_attrib && $form_value == $set_devices_attrib && (!is_null($set_devices_attrib) && $set_devices_attrib != '')) { $update_message[] = "$feedback_prefix updated to $set_devices_attrib"; } if ($form_value != $get_devices_attrib && $form_value != $set_devices_attrib) { $update_failed_message[] = "$feedback_prefix update failed."; } unset($get_devices_attrib, $set_devices_attrib); } unset($devices_attrib); } if ($rows_updated > 0) { $update_message[] = 'Device record updated'; } if ($snmp_enabled && ($force_save !== true && !$device_issnmpable)) { $update_failed_message[] = "Could not connect to " . $device['hostname'] . " with those SNMP settings. To save anyway, turn on Force Save."; $update_message[] = 'SNMP settings reverted'; } if ($rows_updated == 0 && !isset($update_message) && !isset($update_failed_message)) { $update_message[] = 'SNMP settings did not change'; } }//end if (Auth::user()->hasGlobalAdmin()) }//end if ($_POST['editing']) // the following unsets are for security; the database is authoritative // i.e. prevent unintentional artifacts from being saved or used (again), posting around the form, etc. unset($_POST); // these are only used for editing and should not be used as-is unset($force_save, $poller_group, $snmp_enabled); unset($community, $max_repeaters, $max_oid, $port, $port_assoc_mode, $retries, $snmpver, $transport, $timeout); // get up-to-date database values for use on the form $device = dbFetchRow('SELECT * FROM `devices` WHERE `device_id` = ?', array($device['device_id'])); $max_oid = get_dev_attrib($device, 'snmp_max_oid'); $max_repeaters = get_dev_attrib($device, 'snmp_max_repeaters'); echo "

SNMP Settings

"; // use Toastr to print normal (success) messages, similar to Device Settings if (isset($update_message)) { $toastr_options=array(); if (is_array($update_message)) { foreach ($update_message as $message) { Toastr::success($message, null, $toastr_options); } } if (is_string($update_message)) { Toastr::success($update_message, null, $toastr_options); } unset($message, $toastr_options, $update_message); } // use Toastr:error to call attention to the problem; don't let it time out if (isset($update_failed_message)) { $toastr_options=array(); $toastr_options["closeButton"]=true; $toastr_options["extendedTimeOut"]=0; $toastr_options["timeOut"]=0; if (is_array($update_failed_message)) { foreach ($update_failed_message as $error) { Toastr::error($error, null, $toastr_options); } } if (is_string($update_failed_message)) { Toastr::error($update_failed_message, null, $toastr_options); } unset($error, $update_failed_message); } echo "
" . csrf_field() . "
"; ?>
'; }//end if ?>