__('Delete'),
2 => __('Enable'),
3 => __('Disable')
);
$manager_notification_actions = array(
0 => __('Disable'),
1 => __('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 $manager_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_CALLBACK,
'pageset' => true,
'default' => '',
'options' => array('options' => 'sanitize_search_string')
),
'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 (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( '' . $description . ' ', $item['id']);
form_selectable_cell( $item['id'], $item['id']);
form_selectable_cell( $item['disabled'] ? '' . __('Disabled') . ' ' : '' . __('Enabled') . ' ', $item['id']);
form_selectable_cell( $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 (sizeof($managers)) {
print $nav;
}
form_hidden_box('action_receivers', '1', '');
draw_actions_dropdown($manager_actions);
form_end();
}
function manager_edit() {
global $config, $snmp_auth_protocols, $snmp_priv_protocols, $snmp_versions,
$tabs_manager_edit, $fields_manager_edit, $manager_notification_actions;
/* ================= 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 = __('SNMP Notification Receiver [edit: %s]', htmlspecialchars($manager['description']));
}else{
$header_label = __('SNMP Notification Receiver [new]');
}
if (sizeof($tabs_manager_edit) && isset_request_var('id')) {
$i = 0;
/* draw the tabs */
print "\n";
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();
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();
}
if (!in_array(get_request_var('mib'), $registered_mibs) && get_request_var('mib') != '-1' && get_request_var('mib') != '') {
die_html_input_error();
}
/* ==================================================== */
/* ================= 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_CALLBACK,
'pageset' => true,
'default' => '',
'options' => array('options' => 'sanitize_search_string')
),
'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');
}
?>
0) {
foreach($registered_notifications as $registered_notification) {
$notifications[$registered_notification['mib']][$registered_notification['notification']] = 1;
}
}
/* 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, 11, '', 'page', 'main');
print $nav;
html_header_checkbox( array( __('Name'), __('OID'), __('MIB'), __('Kind'), __('Max-Access'), __('Monitored') ), true, 'managers.php?action=edit&tab=notifications&id=' . $id);
if (sizeof($snmp_cache) > 0) {
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();
}
print $nav;
}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();
}
if (!in_array(get_request_var('severity'), array_keys($severity_levels)) && get_request_var('severity') != '-1' && get_request_var('severity') != '') {
die_html_input_error();
}
get_filter_request_var('page');
/* ==================================================== */
/* ================= 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_CALLBACK,
'pageset' => true,
'default' => '',
'options' => array('options' => 'sanitize_search_string')
),
'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');
}
?>
\\1", htmlspecialchars($item['varbinds']))): htmlspecialchars($item['varbinds']));
form_alternate_row('line' . $item['id'], true);
print " ";
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 .= htmlspecialchars(trim($line)) . ' ';
}
print '' . $item['notification'] . ' ';
}else {
print "{$item['notification']} ";
}
print "$varbinds ";
form_end_row();
}
print $nav;
}else{
print '' . __('No SNMP Notification Log Entries') . ' ';
}
?>
'>
$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') == '1') { /* 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&header=false');
exit;
}
}else {
if (isset_request_var('action_receivers')) {
$selected_items = array();
$list = '';
foreach($_POST as $key => $value) {
if (strstr($key, 'chk_')) {
/* grep manager's id */
$id = substr($key, 4);
/* ================= input validation ================= */
input_validate_input_number($id);
/* ==================================================== */
$list .= '' . db_fetch_cell_prepared('SELECT description FROM snmpagent_managers WHERE id = ?', array($id)) . ' ';
$selected_items[] = $id;
}
}
top_header();
form_start('managers.php');
html_start_box($manager_actions{get_nfilter_request_var('drp_action')}, '60%', '', '3', 'center', '');
if (sizeof($selected_items)) {
if (get_nfilter_request_var('drp_action') == '1') { /* delete */
$msg = __n('Click \'Continue\' to delete the following Notification Receiver', 'Click \'Continue\' to delete following Notification Receiver', sizeof($selected_items));
}elseif (get_nfilter_request_var('drp_action') == '2') { /* enable */
$msg = __n('Click \'Continue\' to enable the following Notification Receiver', 'Click \'Continue\' to enable following Notification Receiver', sizeof($selected_items));
}elseif (get_nfilter_request_var('drp_action') == '3') { /* disable */
$msg = __n('Click \'Continue\' to disable the following Notification Receiver', 'Click \'Continue\' to disable following Notification Receiver', sizeof($selected_items));
}
print "
$msg
\n";
$save_html = " ";
} else {
print "You must select at least one Notification Receiver. \n";
$save_html = " ";
}
print "
$save_html
\n";
html_end_box();
form_end();
bottom_footer();
}else {
$selected_items = array();
$list = '';
/* ================= 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);
$list .= '' . $name . ' (' . $mib .') ';
$selected_items[$mib][$name] = 1;
}
}
top_header();
form_start('managers.php');
html_start_box($manager_notification_actions[get_nfilter_request_var('drp_action')], '60%', '', '3', 'center', '');
if (sizeof($selected_items)) {
$msg = (get_nfilter_request_var('drp_action') == 1)
? __('Click \'Continue\' to forward the following Notification Objects to this Notification Receiver.')
: __('Click \'Continue\' to disable forwarding the following Notification Objects to this Noticification Receiver.');
print "
$msg
\n";
$save_html = " ";
} else {
print "" . __('You must select at least one notification object.') . " \n";
$save_html = " ";
}
print "
$save_html
\n";
html_end_box();
form_end();
bottom_footer();
}
}
}