__('Delete'),
2 => __('Disable'),
3 => __('Enable'),
);
$mactions = array(
1 => __('Disable'),
2 => __('Enable')
);
$tabs_manager_edit = array(
'general' => __('General'),
'notifications' => __('Notifications'),
'logs' => __('Logs'),
);
/* set default action */
set_default_action();
get_filter_request_var('tab', FILTER_CALLBACK, array('options' => 'sanitize_search_string'));
switch (get_request_var('action')) {
case 'save':
form_save();
break;
case 'actions':
form_actions();
break;
case 'edit':
top_header();
manager_edit();
bottom_footer();
break;
default:
top_header();
manager();
bottom_footer();
break;
}
function manager() {
global $config, $actions, $item_rows;
/* ================= input validation and session storage ================= */
$filters = array(
'rows' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'filter' => array(
'filter' => FILTER_DEFAULT,
'pageset' => true,
'default' => ''
),
'sort_column' => array(
'filter' => FILTER_CALLBACK,
'default' => 'hostname',
'options' => array('options' => 'sanitize_search_string')
),
'sort_direction' => array(
'filter' => FILTER_CALLBACK,
'default' => 'ASC',
'options' => array('options' => 'sanitize_search_string')
)
);
validate_store_request_vars($filters, 'sess_snmp_mgr');
/* ================= input validation ================= */
if (get_request_var('rows') == '-1') {
$rows = read_config_option('num_rows_table');
} else {
$rows = get_request_var('rows');
}
?>
|
|
array( __('Description'), 'ASC'),
'id' => array( __('Id'), 'ASC'),
'disabled' => array( __('Status'), 'ASC'),
'hostname' => array( __('Hostname'), 'ASC'),
'count_notify' => array( __('Notifications'), 'ASC'),
'count_log' => array( __('Logs'), 'ASC')
);
/* generate page list */
$nav = html_nav_bar('managers.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 11, __('Receivers'), 'page', 'main');
form_start('managers.php', 'chk');
print $nav;
html_start_box('', '100%', '', '3', 'center', '');
html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false);
$i = 0;
if (cacti_sizeof($managers)) {
foreach ($managers as $item) {
$description = filter_value($item['description'], get_request_var('filter'));
$hostname = filter_value($item['hostname'], get_request_var('filter'));
form_alternate_row('line' . $item['id'], false);
form_selectable_cell('' . html_escape($description) . '', $item['id']);
form_selectable_cell($item['id'], $item['id']);
form_selectable_cell($item['disabled'] ? '' . __('Disabled') . '' : '' . __('Enabled') . '', $item['id']);
form_selectable_ecell($hostname, $item['id']);
form_selectable_cell('' . ($item['count_notify'] ? $item['count_notify'] : 0) . '' , $item['id']);
form_selectable_cell('' . ($item['count_log'] ? $item['count_log'] : 0) . '', $item['id']);
form_checkbox_cell($item['description'], $item['id']);
form_end_row();
}
} else {
print '| ' . __('No SNMP Notification Receivers') . ' |
';
}
html_end_box(false);
if (cacti_sizeof($managers)) {
print $nav;
}
form_hidden_box('action_receivers', '1', '');
draw_actions_dropdown($actions);
form_end();
}
function manager_edit() {
global $config, $snmp_auth_protocols, $snmp_priv_protocols, $snmp_versions,
$tabs_manager_edit, $fields_manager_edit, $mactions;
/* ================= input validation ================= */
get_filter_request_var('id');
/* ==================================================== */
if (!isset_request_var('tab')) {
set_request_var('tab', 'general');
}
$id = (isset_request_var('id') ? get_request_var('id') : '0');
if ($id) {
$manager = db_fetch_row_prepared('SELECT * FROM snmpagent_managers WHERE id = ?', array(get_request_var('id')));
$header_label = __esc('SNMP Notification Receiver [edit: %s]', $manager['description']);
} else {
$header_label = __('SNMP Notification Receiver [new]');
}
if (cacti_sizeof($tabs_manager_edit) && isset_request_var('id')) {
$i = 0;
/* draw the tabs */
print "';
if (read_config_option('legacy_menu_nav') != 'on') { ?>
array('no_form_tag' => true),
'fields' => inject_form_variables($fields_manager_edit, (isset($manager) ? $manager : array()))
)
);
html_end_box(true, true);
form_save_button('managers.php', 'return');
?>
0) {
foreach ($mibs as $mib) {
$registered_mibs[] = $mib['mib'];
}
}
/* ================= input validation ================= */
if (!$id | !is_numeric($id)) {
die_html_input_error('id');
}
if (!in_array(get_request_var('mib'), $registered_mibs, true) && get_request_var('mib') != '-1' && get_request_var('mib') != '') {
die_html_input_error('mib');
}
/* ==================================================== */
/* ================= input validation and session storage ================= */
$filters = array(
'rows' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'filter' => array(
'filter' => FILTER_DEFAULT,
'pageset' => true,
'default' => ''
),
'mib' => array(
'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '-1',
'options' => array('options' => 'sanitize_search_string')
),
'sort_column' => array(
'filter' => FILTER_CALLBACK,
'default' => 'name',
'options' => array('options' => 'sanitize_search_string')
),
'sort_direction' => array(
'filter' => FILTER_CALLBACK,
'default' => 'ASC',
'options' => array('options' => 'sanitize_search_string')
)
);
validate_store_request_vars($filters, 'sess_snmp_cache');
/* ================= input validation ================= */
if (get_request_var('rows') == '-1') {
$rows = read_config_option('num_rows_table');
} else {
$rows = get_request_var('rows');
}
html_start_box($header_label, '100%', '', '3', 'center', '');
?>
|
|
0) {
foreach ($registered_notifications as $registered_notification) {
$notifications[$registered_notification['mib']][$registered_notification['notification']] = 1;
}
}
$display_text = array(
__('Name'),
__('OID'),
__('MIB'),
__('Kind'),
__('Max-Access'),
__('Monitored')
);
/* generate page list */
$nav = html_nav_bar('managers.php?action=edit&id=' . $id . '&tab=notifications&mib=' . get_request_var('mib') . '&filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, cacti_sizeof($display_text) + 1, __('Notifications'), 'page', 'main');
print $nav;
html_start_box('', '100%', '', '3', 'center', '');
html_header_checkbox($display_text, true, 'managers.php?action=edit&tab=notifications&id=' . $id);
if (cacti_sizeof($snmp_cache)) {
foreach ($snmp_cache as $item) {
$row_id = $item['mib'] . '__' . $item['name'];
$oid = filter_value($item['oid'], get_request_var('filter'));
$name = filter_value($item['name'], get_request_var('filter'));
$mib = filter_value($item['mib'], get_request_var('filter'));
form_alternate_row('line' . $row_id, false);
if ($item['description']) {
print '' . $name . ' | ';
} else {
form_selectable_cell($name, $row_id);
}
form_selectable_cell($oid, $row_id);
form_selectable_cell($mib, $row_id);
form_selectable_cell($item['kind'], $row_id);
form_selectable_cell($item['max-access'],$row_id);
form_selectable_cell(((isset($notifications[$item['mib']]) && isset($notifications[$item['mib']][$item['name']])) ? '' . __('Enabled'):'' . __('Disabled')) . '', $row_id);
form_checkbox_cell($item['oid'], $row_id);
form_end_row();
}
} else {
print '| ' . __('No SNMP Notifications') . ' |
';
}
?>
'>
'LOW',
SNMPAGENT_EVENT_SEVERITY_MEDIUM => 'MEDIUM',
SNMPAGENT_EVENT_SEVERITY_HIGH => 'HIGH',
SNMPAGENT_EVENT_SEVERITY_CRITICAL => 'CRITICAL'
);
$severity_colors = array(
SNMPAGENT_EVENT_SEVERITY_LOW => '#00FF00',
SNMPAGENT_EVENT_SEVERITY_MEDIUM => '#FFFF00',
SNMPAGENT_EVENT_SEVERITY_HIGH => '#FF0000',
SNMPAGENT_EVENT_SEVERITY_CRITICAL => '#FF00FF'
);
if (isset_request_var('purge')) {
db_execute_prepared('DELETE FROM snmpagent_notifications_log WHERE manager_id = ?', array($id));
set_request_var('clear', true);
}
/* ================= input validation ================= */
if (!$id | !is_numeric($id)) {
die_html_input_error('id');
}
if (!in_array(get_request_var('severity'), array_keys($severity_levels), true) && get_request_var('severity') != '-1' && get_request_var('severity') != '') {
die_html_input_error('severity');
}
/* ==================================================== */
/* ================= input validation and session storage ================= */
$filters = array(
'rows' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'filter' => array(
'filter' => FILTER_DEFAULT,
'pageset' => true,
'default' => ''
),
'severity' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '-1'
)
);
validate_store_request_vars($filters, 'sess_snmp_logs');
/* ================= input validation ================= */
if (get_request_var('rows') == '-1') {
$rows = read_config_option('num_rows_table');
} else {
$rows = get_request_var('rows');
}
html_start_box($header_label, '100%', '', '3', 'center', '');
?>
|
|
";
print "" . date('Y/m/d H:i:s', $item['time']) . ' | ';
if ($item['description']) {
$description = '';
$lines = preg_split('/\r\n|\r|\n/', $item['description']);
foreach ($lines as $line) {
$description .= html_escape(trim($line)) . '
';
}
print '' . $item['notification'] . ' | ';
} else {
print "{$item['notification']} | ";
}
print "$varbinds | ";
form_end_row();
}
} else {
print '| ' . __('No SNMP Notification Log Entries') . ' |
';
}
html_end_box();
if (cacti_sizeof($logs)) {
print $nav;
}
?>
'>
$notifications) {
foreach ($notifications as $notification => $state) {
db_execute_prepared('DELETE FROM snmpagent_managers_notifications
WHERE `manager_id` = ?
AND `mib` = ?
AND `notification` = ?
LIMIT 1',
array(get_nfilter_request_var('id'), $mib, $notification));
}
}
} elseif (get_nfilter_request_var('drp_action') == '2') { // enable
foreach ($selected_items as $mib => $notifications) {
foreach ($notifications as $notification => $state) {
db_execute_prepared('INSERT IGNORE INTO snmpagent_managers_notifications
(`manager_id`, `notification`, `mib`)
VALUES (?, ?, ?)',
array(get_nfilter_request_var('id'), $notification, $mib));
}
}
}
}
header('Location: managers.php?action=edit&id=' . get_nfilter_request_var('id') . '&tab=notifications');
exit;
}
} elseif (isset_request_var('action_receivers')) {
$ilist = '';
$iarray = array();
foreach ($_POST as $key => $value) {
if (strstr($key, 'chk_')) {
/* grep manager's id */
$id = substr($key, 4);
/* ================= input validation ================= */
input_validate_input_number($id, 'id');
/* ==================================================== */
$ilist .= '' . html_escape(db_fetch_cell_prepared('SELECT description FROM snmpagent_managers WHERE id = ?', array($id))) . '';
$iarray[] = $id;
}
}
$form_data = array(
'general' => array(
'page' => 'managers.php',
'actions' => $actions,
'eaction' => 'action_receivers',
'optvar' => 'drp_action',
'item_array' => $iarray,
'item_list' => $ilist
),
'options' => array(
1 => array(
'smessage' => __('Click \'Continue\' to Delete the following Notification Receiver.'),
'pmessage' => __('Click \'Continue\' to Delete following Notification Receivers.'),
'scont' => __('Delete Notification Receiver'),
'pcont' => __('Delete Notification Receivers')
),
2 => array(
'smessage' => __('Click \'Continue\' to Disable the following Notification Receiver.'),
'pmessage' => __('Click \'Continue\' to Disable following Notification Receivers.'),
'scont' => __('Disable Notification Receiver'),
'pcont' => __('Disable Notification Receivers')
),
3 => array(
'smessage' => __('Click \'Continue\' to Enable the following Notification Receiver.'),
'pmessage' => __('Click \'Continue\' to Enable following Notification Receivers.'),
'scont' => __('Enable Notification Receiver'),
'pcont' => __('Enable Notification Receivers'),
)
)
);
form_continue_confirmation($form_data);
} else {
$ilist = '';
$iarray = array();
/* ================= input validation ================= */
get_filter_request_var('id');
/* ==================================================== */
foreach ($_POST as $key => $value) {
if (strstr($key, 'chk_')) {
/* grep mib and notification name */
$row_id = substr($key, 4);
list($mib, $name) = explode('__', $row_id);
$ilist .= '' . html_escape($name) . ' (' . html_escape($mib) .')';
$iarray[$mib][$name] = 1;
}
}
$form_data = array(
'general' => array(
'page' => 'managers.php?action=edit&tab=notifications&id=' . get_request_var('id'),
'actions' => $mactions,
'eaction' => 'action_receiver_notifications',
'optvar' => 'drp_action',
'item_array' => $iarray,
'item_list' => $ilist
),
'options' => array(
1 => array(
'smessage' => __('Click \'Continue\' to Disable Forwarding the following Notification Object the following Notification Receiver.'),
'pmessage' => __('Click \'Continue\' to Disable Forwarding the following Notification Objects to the following Notification Receiver.'),
'scont' => __('Disable Forwarding Object'),
'pcont' => __('Disable Forwarding Objects')
),
2 => array(
'smessage' => __('Click \'Continue\' to Enable Forwarding the following Notification Object to this Notification Receiver.'),
'pmessage' => __('Click \'Continue\' to Enable Forwarding the following Notification Objects Notification Receivers.'),
'scont' => __('Enable Forwarding Object'),
'pcont' => __('Enable Forwarding Objects')
)
)
);
form_continue_confirmation($form_data);
}
}