commit version 22.12.12447

This commit is contained in:
2023-01-01 22:36:12 -05:00
parent af1b03d79f
commit b948283a96
744 changed files with 620715 additions and 27381 deletions

View File

@ -6,36 +6,26 @@
*
* @package observium
* @subpackage web
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
if ($vars['editing'])
{
if ($readonly)
{
if ($vars['editing']) {
if ($readonly) {
print_error_permission('You have insufficient permissions to edit settings.');
}
else if (get_db_version() < 169)
{
// FIXME. Remove this block in r7000
print_warning("DB scheme is old, must update first. Device Geolocation not changed.");
} else {
$updated = 0;
if ($vars['submit'] === 'save')
{
if ($vars['submit'] === 'save') {
if (get_var_true($vars['reset_geolocation'])) {
$updated = dbDelete('devices_locations', '`device_id` = ?', array($device['device_id']));
$updated = dbDelete('devices_locations', '`device_id` = ?', [ $device['device_id'] ]);
} elseif ((bool)$vars['location_manual']) {
// Set manual coordinates if present
$pattern = '/(?:^|[\[(])\s*(?<lat>[+-]?\d+(?:\.\d+)*)\s*[,; ]\s*(?<lon>[+-]?\d+(?:\.\d+)*)\s*(?:[\])]|$)/';
if (preg_match($pattern, $vars['coordinates'], $matches))
{
if (preg_match($pattern, $vars['coordinates'], $matches)) {
//r($matches);
if ($matches['lat'] >= -90 && $matches['lat'] <= 90 &&
$matches['lon'] >= -180 && $matches['lon'] <= 180)
{
$matches['lon'] >= -180 && $matches['lon'] <= 180) {
$update_geo['location_lat'] = $matches['lat'];
$update_geo['location_lon'] = $matches['lon'];
$update_geo['location_country'] = '';
@ -47,29 +37,28 @@ if ($vars['editing'])
//r($vars);
}
if ((bool)$device['location_manual'] && !(bool)$vars['location_manual'])
{
if ((bool)$device['location_manual'] && !(bool)$vars['location_manual']) {
// Reset manual flag, rediscover geo info
$update_geo['location_lat'] = array('NULL');
$update_geo['location_lon'] = array('NULL');
$update_geo['location_lat'] = [ 'NULL' ];
$update_geo['location_lon'] = [ 'NULL' ];
$update_geo['location_manual'] = 0;
$updated++;
}
if ($updated)
{
if ($updated) {
//r($update_geo);
dbUpdate($update_geo, 'devices_locations', '`location_id` = ?', array($device['location_id']));
$geo_db = dbFetchRow("SELECT * FROM `devices_locations` WHERE `device_id` = ?", array($device['device_id']));
if (count($geo_db))
{
if (!safe_empty($update_geo)) {
dbUpdate($update_geo, 'devices_locations', '`location_id` = ?', [ $device['location_id'] ]);
}
$geo_db = dbFetchRow("SELECT * FROM `devices_locations` WHERE `device_id` = ?", [ $device['device_id'] ]);
if (safe_count($geo_db)) {
if (get_var_true($vars['reset_geolocation'])) {
print_warning("Device Geo location dropped. Country/city will be updated on next poll.");
} else {
print_success("Device Geolocation updated. Country/city will be updated on next poll.");
}
}
$device = array_merge($device, $geo_db);
$device = array_merge($device, (array)$geo_db);
unset($updated, $update_geo, $geo_db);
} else {
print_warning("Some input data wrong. Device Geolocation not changed.");
@ -78,37 +67,32 @@ if ($vars['editing'])
}
}
$location = array('location_text' => $device['location']);
$location = [ 'location_text' => $device['location'] ];
$override_sysLocation_bool = get_dev_attrib($device,'override_sysLocation_bool');
if ($override_sysLocation_bool)
{
if ($override_sysLocation_bool) {
$override_sysLocation_string = get_dev_attrib($device,'override_sysLocation_string');
if ($override_sysLocation_string != $device['location'])
{
// Device not polled since location overrided
if ($override_sysLocation_string != $device['location']) {
// Device not polled since location override
$location['location_help'] = 'NOTE, device not polled since location overridden, Geolocation is old.';
$location['location_text'] = $override_sysLocation_string;
}
}
if ($location['location_text'] == '') { $location['location_text'] = OBS_VAR_UNSET; }
foreach (array('location_lat', 'location_lon', 'location_city', 'location_county', 'location_state', 'location_country',
'location_geoapi', 'location_status', 'location_manual', 'location_updated') as $param)
{
if (safe_empty($location['location_text'])) { $location['location_text'] = OBS_VAR_UNSET; }
foreach ([ 'location_lat', 'location_lon', 'location_city', 'location_county', 'location_state', 'location_country',
'location_geoapi', 'location_status', 'location_manual', 'location_updated' ] as $param) {
$location[$param] = $device[$param];
}
if (is_numeric($location['location_lat']) && is_numeric($location['location_lon']))
{
if (is_numeric($location['location_lat']) && is_numeric($location['location_lon'])) {
// Generate link to Google maps
// http://maps.google.com/maps?q=46.090271,6.657248+description+(name)
$location['coordinates'] = $location['location_lat'].','.$location['location_lon'];
$location['coordinates_manual'] = $location['coordinates'];
$location['location_link'] = '<a target="_blank" href="http://maps.google.com/maps?q='.urlencode($location['coordinates']).'"><i class="'.$config['icon']['map'].'"></i> View this location on a map</a>';
$location['location_link'] = '<a target="_blank" href="https://maps.google.com/maps?q='.urlencode($location['coordinates']).'"><i class="'.$config['icon']['map'].'"></i> View this location on a map</a>';
$location['location_geo'] = country_from_code($location['location_country']).' (Country), '.$location['location_state'].' (State), ';
$location['location_geo'] .= $location['location_county'] .' (County), ' .$location['location_city'] .' (City)';
switch ($location['location_geoapi'])
{
switch ($location['location_geoapi']) {
//case 'yandex':
// // Generate link to Yandex maps
// $location['location_link'] = '<a target="_blank" href="http://maps.google.com/maps?q='.urlencode($location['coordinates']).'"><i class="oicon-map"></i> View this location on a map</a>';
@ -122,8 +106,7 @@ if (is_numeric($location['location_lat']) && is_numeric($location['location_lon'
$location['coordinates_manual'] = $config['geocoding']['default']['lat'].','.$config['geocoding']['default']['lon'];
}
if ($updated && $update_message)
{
if ($updated && $update_message) {
print_message($update_message);
} elseif ($update_message) {
print_error($update_message);

View File

@ -225,8 +225,7 @@ foreach ($snmp_errors as $mib => $entries)
}
$text_class = (count(explode(' ', $error_db['oid'])) > 3 ? '' : 'text-nowrap');
echo('<tr width="100%" class="'.$error_class2.'"><td style="width: 50%;" class="'.$text_class.'"><strong><i class="glyphicon glyphicon-exclamation-sign"></i>&nbsp;'.$error_db['oid'].'</strong></td>' . PHP_EOL);
$timediff = $GLOBALS['config']['time']['now'] - $error_db['updated'];
echo('<td style="width: 100px; white-space: nowrap; text-align: right;">'.generate_tooltip_link('', format_uptime($timediff, "short-3").' ago', format_unixtime($error_db['updated'])).'</td>' . PHP_EOL);
echo('<td style="width: 100px; white-space: nowrap; text-align: right;">'.generate_tooltip_time($error_db['updated'], 'ago').'</td>' . PHP_EOL);
echo('<td style="width: 80px; white-space: nowrap;"><span class="text-'.$error_class.'">'.$error_codes[$error_db['error_code']]['reason'].'</span></td>' . PHP_EOL);
echo('<td style="width: 40px; text-align: right;"><span class="label">'.$error_db['error_count'].'</span></td>' . PHP_EOL);
echo('<td style="width: 80px; text-align: right;"><span class="label">'.round($error_db['error_rate'], 2).'/poll</span></td>' . PHP_EOL);

View File

@ -6,16 +6,16 @@
*
* @package observium
* @subpackage web
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
$ok = FALSE;
if ($vars['editing']) {
if (get_var_true($vars['editing']) && request_token_valid($vars)) {
if ($readonly) {
print_error_permission('You have insufficient permissions to edit settings.');
} else {
$update = array();
$update = [];
switch ($vars['snmp_version']) {
case 'v3':
switch ($vars['snmp_authlevel']) {
@ -55,9 +55,34 @@ if ($vars['editing']) {
}
break;
}
if ($ok && $snmpable = trim($vars['snmpable'])) {
$snmp_oids = [];
foreach (explode(' ', $snmpable) as $oid) {
if (preg_match(OBS_PATTERN_SNMP_OID_NUM, $oid)) {
$snmp_oids[] = $oid;
$oid_num = $oid;
} elseif (str_contains($oid, '::') && $oid_num = snmp_translate($oid)) {
// Named MIB::Oid which we can translate
$snmp_oids[] = $oid_num;
} else {
print_warning("Invalid or unknown OID: ".$oid);
break;
}
$data = snmp_get_oid($device, $oid_num);
if (!snmp_status()) {
print_warning("Device currently not respond by OID $oid!");
}
}
if (empty($snmp_oids)) {
$ok = FALSE;
$error = 'Incorrect or not numeric OIDs passed for check device availability';
}
}
if ($ok) {
$update['snmp_version'] = $vars['snmp_version'];
if (in_array($vars['snmp_transport'], $config['snmp']['transports'])) {
if (in_array($vars['snmp_transport'], $config['snmp']['transports'], TRUE)) {
$update['snmp_transport'] = $vars['snmp_transport'];
} else {
$update['snmp_transport'] = 'udp';
@ -72,13 +97,13 @@ if ($vars['editing']) {
$update['snmp_timeout'] = (int)$vars['snmp_timeout'];
} else {
if (strlen($vars['snmp_timeout'])) { print_warning('Passed incorrect SNMP timeout ('.$vars['snmp_timeout'].'). Should be between 1 and 120 sec.'); }
$update['snmp_timeout'] = array('NULL');
$update['snmp_timeout'] = [ 'NULL' ];
}
if (is_valid_param($vars['snmp_retries'], 'snmp_retries')) {
$update['snmp_retries'] = (int)$vars['snmp_retries'];
} else {
if (strlen($vars['snmp_retries'])) { print_warning('Passed incorrect SNMP retries ('.$vars['snmp_retries'].'). Should be between 1 and 10.'); }
$update['snmp_retries'] = array('NULL');
$update['snmp_retries'] = [ 'NULL' ];
}
// SNMPbulk max repetitions, allow 0 for disable snmpbulk(walk|get)
@ -89,13 +114,21 @@ if ($vars['editing']) {
$update['snmp_maxrep'] = [ 'NULL' ];
}
if ($snmpable) {
if ($device['snmpable'] !== $snmpable) {
$update['snmpable'] = $snmpable;
}
} elseif (!empty($device['snmpable'])) {
$update['snmpable'] = [ 'NULL' ];
}
if (strlen(trim($vars['snmp_context']))) {
$update['snmp_context'] = trim($vars['snmp_context']);
} else {
$update['snmp_context'] = [ 'NULL' ];
}
if (dbUpdate($update, 'devices', '`device_id` = ?', array($device['device_id']))) {
if (dbUpdate($update, 'devices', '`device_id` = ?', [ $device['device_id'] ])) {
print_success("Device SNMP configuration updated");
log_event('Device SNMP configuration changed.', $device['device_id'], 'device', $device['device_id'], 5);
} else {
@ -115,7 +148,7 @@ if ($vars['editing']) {
}
$device = device_by_id_cache($device['device_id'], $ok);
$transports = array();
$transports = [];
foreach ($config['snmp']['transports'] as $transport) {
$transports[$transport] = strtoupper($transport);
}
@ -146,172 +179,207 @@ $cryptoalgo = [
'AES-256-C' => [ 'name' => 'AES-256 Cisco', 'class' => 'bg-warning', 'subtext' => 'Poller required net-snmp >= 5.8 compiled with --enable-blumenthal-aes' ],
];
$form = array('type' => 'horizontal',
'id' => 'edit',
//'space' => '20px',
//'title' => 'General',
//'class' => 'box',
);
$form = [
'type' => 'horizontal',
'id' => 'edit',
//'space' => '20px',
//'title' => 'General',
//'class' => 'box',
];
// top row div
$form['fieldset']['edit'] = array('div' => 'top',
'title' => 'Basic Configuration',
'class' => 'col-md-6');
$form['fieldset']['snmpv2'] = array('div' => 'top',
'title' => 'SNMP v1/v2c Authentication',
//'right' => TRUE,
'class' => 'col-md-6 col-md-pull-0');
$form['fieldset']['snmpv3'] = array('div' => 'top',
'title' => 'SNMP v3 Authentication',
//'right' => TRUE,
'class' => 'col-md-6 col-md-pull-0');
$form['fieldset']['snmpextra'] = array('div' => 'top',
'title' => 'Extra Configuration',
//'right' => TRUE,
'class' => 'col-sm-12 col-md-6 pull-right');
$form['fieldset']['edit'] = [
'div' => 'top',
'title' => 'Basic Configuration',
'class' => 'col-md-6'
];
$form['fieldset']['snmpv2'] = [
'div' => 'top',
'title' => 'SNMP v1/v2c Authentication',
//'right' => TRUE,
'class' => 'col-md-6 col-md-pull-0'
];
$form['fieldset']['snmpv3'] = [
'div' => 'top',
'title' => 'SNMP v3 Authentication',
//'right' => TRUE,
'class' => 'col-md-6 col-md-pull-0'
];
$form['fieldset']['snmpextra'] = [
'div' => 'top',
'title' => 'Extra Configuration',
//'right' => TRUE,
'class' => 'col-sm-12 col-md-6 pull-right'
];
// bottom row div
$form['fieldset']['submit'] = array('div' => 'bottom',
'style' => 'padding: 0px;',
'class' => 'col-md-12');
$form['fieldset']['submit'] = [
'div' => 'bottom',
'style' => 'padding: 0px;',
'class' => 'col-md-12'
];
$form['row'][0]['editing'] = array(
'type' => 'hidden',
'value' => 'yes');
$form['row'][0]['editing'] = [
'type' => 'hidden',
'value' => 'yes'
];
// left fieldset
$form['row'][1]['snmp_version'] = array(
'type' => 'select',
'fieldset' => 'edit',
'name' => 'Protocol Version',
'width' => '250px',
'readonly' => $readonly,
'values' => array('v1' => 'v1', 'v2c' => 'v2c', 'v3' => 'v3'),
'value' => $device['snmp_version']);
$form['row'][2]['snmp_transport'] = array(
'type' => 'select',
'fieldset' => 'edit',
'name' => 'Transport',
'width' => '250px',
'readonly' => $readonly,
'values' => $transports,
'value' => $device['snmp_transport']);
$form['row'][3]['snmp_port'] = array(
'type' => 'text',
'fieldset' => 'edit',
'name' => 'Port',
'width' => '250px',
'placeholder' => '1-65535. Default 161.',
'readonly' => $readonly,
'value' => $device['snmp_port']);
$form['row'][4]['snmp_timeout'] = array(
'type' => 'text',
'fieldset' => 'edit',
'name' => 'Timeout',
'width' => '250px',
'placeholder' => '1-120 sec. Default 1 sec.',
'readonly' => $readonly,
'value' => $device['snmp_timeout']);
$form['row'][5]['snmp_retries'] = array(
'type' => 'text',
'fieldset' => 'edit',
'name' => 'Retries',
'width' => '250px',
'placeholder' => '1-10. Default 5.',
'readonly' => $readonly,
'value' => $device['snmp_retries']);
$form['row'][1]['snmp_version'] = [
'type' => 'select',
'fieldset' => 'edit',
'name' => 'Protocol Version',
'width' => '250px',
'readonly' => $readonly,
'values' => [ 'v1' => 'v1', 'v2c' => 'v2c', 'v3' => 'v3' ],
'value' => $device['snmp_version']
];
$form['row'][2]['snmp_transport'] = [
'type' => 'select',
'fieldset' => 'edit',
'name' => 'Transport',
'width' => '250px',
'readonly' => $readonly,
'values' => $transports,
'value' => $device['snmp_transport']
];
$form['row'][3]['snmp_port'] = [
'type' => 'text',
'fieldset' => 'edit',
'name' => 'Port',
'width' => '250px',
'placeholder' => '1-65535. Default 161.',
'readonly' => $readonly,
'value' => $device['snmp_port']
];
$form['row'][4]['snmp_timeout'] = [
'type' => 'text',
'fieldset' => 'edit',
'name' => 'Timeout',
'width' => '250px',
'placeholder' => '1-120 sec. Default 1 sec.',
'readonly' => $readonly,
'value' => $device['snmp_timeout']
];
$form['row'][5]['snmp_retries'] = [
'type' => 'text',
'fieldset' => 'edit',
'name' => 'Retries',
'width' => '250px',
'placeholder' => '1-10. Default 5.',
'readonly' => $readonly,
'value' => $device['snmp_retries']
];
$form['row'][6]['snmp_maxrep'] = [
'type' => 'text',
'fieldset' => 'edit',
'name' => 'Max Repetitions',
'width' => '250px',
'placeholder' => '0-500. Default 10. 0 for disable snmpbulk.',
'readonly' => $readonly,
'value' => $device['snmp_maxrep']
];
$form['row'][6]['snmp_maxrep'] = array(
'type' => 'text',
'fieldset' => 'edit',
'name' => 'Max Repetitions',
'width' => '250px',
'placeholder' => '0-500. Default 10. 0 for disable snmpbulk.',
'readonly' => $readonly,
'value' => $device['snmp_maxrep']);
// Snmp v1/2c fieldset
$form['row'][7]['snmp_community'] = array(
'type' => 'password',
'fieldset' => 'snmpv2',
'name' => 'SNMP Community',
'width' => '250px',
'readonly' => $readonly,
'show_password' => !$readonly,
'value' => $device['snmp_community']); // FIXME. For passwords we should use filter instead escape!
$form['row'][7]['snmp_community'] = [
'type' => 'password',
'fieldset' => 'snmpv2',
'name' => 'SNMP Community',
'width' => '250px',
'readonly' => $readonly,
'show_password' => !$readonly,
'value' => $device['snmp_community'] // FIXME. For passwords we should use filter instead escape!
];
// Snmp v3 fieldset
$form['row'][8]['snmp_authlevel'] = array(
'type' => 'select',
'fieldset' => 'snmpv3',
'name' => 'Auth Level',
'width' => '250px',
'readonly' => $readonly,
'values' => array('noAuthNoPriv' => 'noAuthNoPriv',
'authNoPriv' => 'authNoPriv',
'authPriv' => 'authPriv'),
'value' => $device['snmp_authlevel']);
$form['row'][8]['snmp_authlevel'] = [
'type' => 'select',
'fieldset' => 'snmpv3',
'name' => 'Auth Level',
'width' => '250px',
'readonly' => $readonly,
'values' => [
'noAuthNoPriv' => 'noAuthNoPriv',
'authNoPriv' => 'authNoPriv',
'authPriv' => 'authPriv'
],
'value' => $device['snmp_authlevel']
];
$form['row'][9]['snmp_authname'] = [
'type' => 'password',
'fieldset' => 'snmpv3',
'name' => 'Auth Username',
'width' => '250px',
'readonly' => $readonly,
'show_password' => !$readonly,
'value' => $device['snmp_authname']
];
$form['row'][10]['snmp_authpass'] = [
'type' => 'password',
'fieldset' => 'snmpv3',
'name' => 'Auth Password',
'width' => '250px',
'readonly' => $readonly,
'show_password' => !$readonly,
'value' => $device['snmp_authpass'] // FIXME. For passwords we should use filter instead escape!
];
$form['row'][11]['snmp_authalgo'] = [
'type' => 'select',
'fieldset' => 'snmpv3',
'name' => 'Auth Algorithm',
'width' => '250px',
'readonly' => $readonly,
'values' => $authalgo,
'value' => $device['snmp_authalgo']
];
$form['row'][12]['snmp_cryptopass'] = [
'type' => 'password',
'fieldset' => 'snmpv3',
'name' => 'Crypto Password',
'width' => '250px',
'readonly' => $readonly,
'show_password' => !$readonly,
'value' => $device['snmp_cryptopass'] // FIXME. For passwords we should use filter instead escape!
];
$form['row'][13]['snmp_cryptoalgo'] = [
'type' => 'select',
'fieldset' => 'snmpv3',
'name' => 'Crypto Algorithm',
'width' => '250px',
'readonly' => $readonly,
'values' => $cryptoalgo,
'value' => $device['snmp_cryptoalgo']
];
$form['row'][9]['snmp_authname'] = array(
'type' => 'password',
'fieldset' => 'snmpv3',
'name' => 'Auth Username',
'width' => '250px',
'readonly' => $readonly,
'show_password' => !$readonly,
'value' => $device['snmp_authname']);
// Extra fields
$form['row'][14]['snmpable'] = [
'type' => 'text',
'fieldset' => 'snmpextra',
'name' => 'SNMPable OIDs',
'width' => '250px',
'readonly' => $readonly,
'placeholder' => '(Optional) Numeric OIDs for check device availability',
'value' => $device['snmpable']
];
$form['row'][15]['snmp_context'] = [
'type' => 'password',
'fieldset' => 'snmpextra',
'name' => 'SNMP Context',
'width' => '250px',
'readonly' => $readonly,
'show_password' => !$readonly,
'placeholder' => '(Optional) Context',
'value' => $device['snmp_context'] // FIXME. For passwords we should use filter instead escape!
];
$form['row'][10]['snmp_authpass'] = array(
'type' => 'password',
'fieldset' => 'snmpv3',
'name' => 'Auth Password',
'width' => '250px',
'readonly' => $readonly,
'show_password' => !$readonly,
'value' => $device['snmp_authpass']); // FIXME. For passwords we should use filter instead escape!
$form['row'][11]['snmp_authalgo'] = array(
'type' => 'select',
'fieldset' => 'snmpv3',
'name' => 'Auth Algorithm',
'width' => '250px',
'readonly' => $readonly,
'values' => $authalgo,
'value' => $device['snmp_authalgo']);
$form['row'][12]['snmp_cryptopass'] = array(
'type' => 'password',
'fieldset' => 'snmpv3',
'name' => 'Crypto Password',
'width' => '250px',
'readonly' => $readonly,
'show_password' => !$readonly,
'value' => $device['snmp_cryptopass']); // FIXME. For passwords we should use filter instead escape!
$form['row'][13]['snmp_cryptoalgo'] = array(
'type' => 'select',
'fieldset' => 'snmpv3',
'name' => 'Crypto Algorithm',
'width' => '250px',
'readonly' => $readonly,
'values' => $cryptoalgo,
'value' => $device['snmp_cryptoalgo']);
$form['row'][15]['snmp_context'] = array(
'type' => 'password',
'fieldset' => 'snmpextra',
'name' => 'SNMP Context',
'width' => '250px',
'readonly' => $readonly,
'show_password' => !$readonly,
'placeholder' => '(Optional) Context',
'value' => $device['snmp_context']); // FIXME. For passwords we should use filter instead escape!
$form['row'][20]['submit'] = array(
'type' => 'submit',
'fieldset' => 'submit',
'name' => 'Save Changes',
'icon' => 'icon-ok icon-white',
//'right' => TRUE,
'class' => 'btn-primary',
'readonly' => $readonly,
'value' => 'save');
$form['row'][20]['submit'] = [
'type' => 'submit',
'fieldset' => 'submit',
'name' => 'Save Changes',
'icon' => 'icon-ok icon-white',
//'right' => TRUE,
'class' => 'btn-primary',
'readonly' => $readonly,
'value' => 'save'
];
print_form_box($form);
unset($form);