"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 */ if (!isset($_REQUEST["action"])) { $_REQUEST["action"] = ""; } switch ($_REQUEST["action"]) { case 'save': form_save(); break; case 'actions': form_actions(); break; case 'edit': include_once("./include/top_header.php"); manager_edit(); include_once("./include/bottom_footer.php"); break; default: include_once("./include/top_header.php"); manager(); include_once("./include/bottom_footer.php"); break; } function manager(){ global $colors, $manager_actions; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("page")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* clean up sort_column */ if (isset($_REQUEST["sort_column"])) { $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column")); } /* clean up sort_direction string */ if (isset($_REQUEST["sort_direction"])) { $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction")); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { kill_session_var("sess_snmpagent_manager_current_page"); kill_session_var("sess_snmpagent_manager_filter"); kill_session_var("sess_snmpagent_manager_sort_column"); kill_session_var("sess_snmpagent_manager_sort_direction"); unset($_REQUEST["page"]); unset($_REQUEST["filter"]); unset($_REQUEST["sort_column"]); unset($_REQUEST["sort_direction"]); } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("page", "sess_snmpagent_manager_current_page", "1"); load_current_session_value("filter", "sess_snmpagent_manager_filter", ""); load_current_session_value("sort_column", "sess_snmpagent_manager_sort_column", "hostname"); load_current_session_value("sort_direction", "sess_snmpagent_manager_sort_direction", "ASC"); display_output_messages(); html_start_box("SNMP Notification Receivers", "100%", "", "3", "center", "managers.php?action=edit"); ?>
Search: ">
'>
\n"; html_start_box("", "100%", $colors["header"], "3", "center", ""); $total_rows = db_fetch_cell("SELECT COUNT(plugin_snmpagent_managers.id) FROM plugin_snmpagent_managers $sql_where"); $managers = db_fetch_assoc("SELECT plugin_snmpagent_managers.id, plugin_snmpagent_managers.description, plugin_snmpagent_managers.hostname, plugin_snmpagent_managers.disabled, plugin_snmpagent_managers_notifications.count_notify, plugin_snmpagent_notifications_log.count_log FROM plugin_snmpagent_managers LEFT JOIN ( SELECT COUNT(*) as count_notify, manager_id FROM plugin_snmpagent_managers_notifications GROUP BY manager_id) AS plugin_snmpagent_managers_notifications ON plugin_snmpagent_managers_notifications.manager_id = plugin_snmpagent_managers.id LEFT JOIN ( SELECT COUNT(*) as count_log, manager_id FROM plugin_snmpagent_notifications_log GROUP BY manager_id) AS plugin_snmpagent_notifications_log ON plugin_snmpagent_notifications_log.manager_id = plugin_snmpagent_managers.id $sql_where ORDER BY " . get_request_var_request("sort_column") . " " . get_request_var_request("sort_direction") . " LIMIT " . (read_config_option("num_rows_device")*(get_request_var_request("page")-1)) . "," . read_config_option("num_rows_device")); /* generate page list */ $url_page_select = get_page_list(get_request_var_request("page"), MAX_DISPLAY_PAGES, read_config_option("num_rows_device"), $total_rows, "managers.php?filter=" . get_request_var_request("filter")); $nav = " \n \n \n
<< "; if (get_request_var_request("page") > 1) { $nav .= ""; } $nav .= "Previous"; if (get_request_var_request("page") > 1) { $nav .= ""; } $nav .= " Showing Rows " . ((read_config_option("num_rows_device")*(get_request_var_request("page")-1))+1) . " to " . ((($total_rows < read_config_option("num_rows_device")) || ($total_rows < (read_config_option("num_rows_device")*get_request_var_request("page")))) ? $total_rows : (read_config_option("num_rows_device")*get_request_var_request("page"))) . " of $total_rows [$url_page_select] "; if ((get_request_var_request("page") * read_config_option("num_rows_device")) < $total_rows) { $nav .= ""; } $nav .= "Next"; if ((get_request_var_request("page") * read_config_option("num_rows_device")) < $total_rows) { $nav .= ""; } $nav .= " >>
\n"; print $nav; $display_text = array( "description" => 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") ); html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction"), false); $i = 0; if (sizeof($managers) > 0) { foreach ($managers as $item) { $description = (strlen(get_request_var_request("filter")) ? (preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "\\1", $item["description"])) : $item["description"]); $hostname = (strlen(get_request_var_request("filter")) ? (preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "\\1", $item["hostname"])): $item["hostname"]); form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $item["id"]); $i++; form_selectable_cell( '' . $description . '', $item["id"]); form_selectable_cell( $item["id"], $item["id"]); form_selectable_cell( $item["disabled"] ? "disabled" : "active", $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(); } print $nav; }else{ print "No SNMP Notification Receivers"; } html_end_box(false); form_hidden_box('action_receivers', '1', ''); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($manager_actions); print "\n"; } function manager_edit() { global $colors, $snmp_auth_protocols, $snmp_priv_protocols, $snmp_versions, $tabs_manager_edit, $fields_manager_edit, $manager_notification_actions; /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ if (!isset($_REQUEST["tab"])) $_REQUEST["tab"] = "general"; $id = (isset($_REQUEST['id']) ? $_REQUEST['id'] : '0'); if($id) { $manager = db_fetch_row("select * from plugin_snmpagent_managers where id=" . $_GET["id"]); $header_label = "[edit: " . htmlspecialchars($manager["description"]) . "]"; }else{ $header_label = "[new]"; } print "\n"; foreach (array_keys($tabs_manager_edit) as $tab_short_name) { print "\n\n"; } print "\n
"; if (($id == 0 & $tab_short_name != 'general')){ echo "$tabs_manager_edit[$tab_short_name]"; }elseif ($id == 0 & $tab_short_name == 'general'){ echo "$tabs_manager_edit[$tab_short_name]"; }else { $link = "managers.php?action=edit&id=$id&tab=$tab_short_name"; echo "$tabs_manager_edit[$tab_short_name]"; } echo "
\n"; html_start_box("SNMP Notification Receiver $header_label", "100%", $colors["header"], "3", "center", ""); switch($_REQUEST['tab']){ case 'notifications': manager_notifications($id); break; case 'logs': manager_logs($id); break; default: draw_edit_form(array( "config" => array("form_name" => "chk"), "fields" => inject_form_variables($fields_manager_edit, (isset($manager) ? $manager : array())) )); ?> "; html_end_box(); switch($_REQUEST['tab']){ case 'notifications': /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($manager_notification_actions); break; case 'logs': break; default: form_save_button("managers.php", "return"); } } function manager_notifications($id){ global $colors; $mibs = db_fetch_assoc("SELECT DISTINCT mib FROM plugin_snmpagent_cache"); $registered_mibs = array(); if($mibs && $mibs >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_request("mib"), $registered_mibs) && get_request_var_request("mib") != '-1' && get_request_var_request("mib") != "") { die_html_input_error(); } input_validate_input_number(get_request_var_request("page")); /* ==================================================== */ /* clean up search filter */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_snmpagent__manager_notifications_x"])) { kill_session_var("sess_snmpagent__manager_notifications_cache_mib"); kill_session_var("sess_snmpagent__manager_notifications_cache_current_page"); kill_session_var("sess_snmpagent__manager_notifications_cache_filter"); unset($_REQUEST["mib"]); unset($_REQUEST["page"]); unset($_REQUEST["filter"]); } /* reset the current page if the user changed the mib filter*/ if(isset($_SESSION["sess_snmpagent__manager_notifications_cache_mib"]) && get_request_var_request("mib") != $_SESSION["sess_snmpagent__manager_notifications_cache_mib"]) { kill_session_var("sess_snmpagent__manager_notifications_cache_current_page"); unset($_REQUEST["page"]); } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("page", "sess_snmpagent__manager_notifications_cache_current_page", "1"); load_current_session_value("mib", "sess_snmpagent__manager_notifications_cache_mib", "-1"); load_current_session_value("filter", "sess_snmpagent__manager_notifications_cache_filter", ""); ?> ">
MIB:   Search:  ">  
\n"; html_start_box("", "100%", $colors["header"], "3", "center", ""); $total_rows = db_fetch_cell("SELECT COUNT(*) FROM plugin_snmpagent_cache WHERE 1 $sql_where"); $snmp_cache_sql = "SELECT * FROM plugin_snmpagent_cache WHERE 1 $sql_where LIMIT " . (read_config_option("num_rows_data_source")*(get_request_var_request("page")-1)) . "," . read_config_option("num_rows_data_source"); $snmp_cache = db_fetch_assoc($snmp_cache_sql); $registered_notifications = db_fetch_assoc("SELECT notification, mib from plugin_snmpagent_managers_notifications WHERE manager_id = $id"); $notifications = array(); if($registered_notifications && sizeof($registered_notifications)>0) { foreach($registered_notifications as $registered_notification) { $notifications[$registered_notification["mib"]][$registered_notification["notification"]] = 1; } } /* generate page list */ $url_page_select = get_page_list(get_request_var_request("page"), MAX_DISPLAY_PAGES, read_config_option("num_rows_data_source"), $total_rows, "managers.php?action=edit&id=" . $id . "&tab=notifications&mib=" . get_request_var_request("mib") . "&filter=" . get_request_var_request("filter")); $nav = " \n \n \n
<< "; if (get_request_var_request("page") > 1) { $nav .= ""; } $nav .= "Previous"; if (get_request_var_request("page") > 1) { $nav .= ""; } $nav .= " Showing Rows " . ((read_config_option("num_rows_data_source")*(get_request_var_request("page")-1))+1) . " to " . ((($total_rows < read_config_option("num_rows_data_source")) || ($total_rows < (read_config_option("num_rows_data_source")*get_request_var_request("page")))) ? $total_rows : (read_config_option("num_rows_data_source")*get_request_var_request("page"))) . " of $total_rows [$url_page_select] "; if ((get_request_var_request("page") * read_config_option("num_rows_data_source")) < $total_rows) { $nav .= ""; } $nav .= "Next"; if ((get_request_var_request("page") * read_config_option("num_rows_data_source")) < $total_rows) { $nav .= ""; } $nav .= " >>
\n"; print $nav; html_header_checkbox( array("Name", "OID", "MIB", "Kind", "Max-Access", "Monitored"), true, "managers.php?action=edit&tab=notifications&id=" . $id); $i = 0; if (sizeof($snmp_cache) > 0) { foreach ($snmp_cache as $item) { $row_id = $item["mib"] . '__' . $item["name"]; $oid = (strlen(get_request_var_request("filter")) ? (preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "\\1", $item["oid"])) : $item["oid"]); $name = (strlen(get_request_var_request("filter")) ? (preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "\\1", $item["name"])): $item["name"]); $mib = (strlen(get_request_var_request("filter")) ? (preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "\\1", $item["mib"])): $item["mib"]); form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $row_id); $i++; if($item["description"]) { $description = ''; $lines = preg_split( '/\r\n|\r|\n/', $item['description']); foreach($lines as $line) { $description .= addslashes(trim($line)) . '
'; } 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"; } ?> ">
Severity:   Search:  ">  
\n"; html_start_box("", "100%", $colors["header"], "3", "center", ""); $total_rows = db_fetch_cell("SELECT COUNT(*) FROM plugin_snmpagent_notifications_log WHERE $sql_where"); $logs = db_fetch_assoc($sql_query); /* generate page list */ $url_page_select = get_page_list(get_request_var_request("page"), MAX_DISPLAY_PAGES, read_config_option("num_rows_data_source"), $total_rows, "managers.php?action=edit&id=" . $id . "&tab=logs&mib=" . get_request_var_request("mib") . "&filter=" . get_request_var_request("filter")); $nav = " \n \n \n
<< "; if (get_request_var_request("page") > 1) { $nav .= ""; } $nav .= "Previous"; if (get_request_var_request("page") > 1) { $nav .= ""; } $nav .= " Showing Rows " . ((read_config_option("num_rows_data_source")*(get_request_var_request("page")-1))+1) . " to " . ((($total_rows < read_config_option("num_rows_data_source")) || ($total_rows < (read_config_option("num_rows_data_source")*get_request_var_request("page")))) ? $total_rows : (read_config_option("num_rows_data_source")*get_request_var_request("page"))) . " of $total_rows [$url_page_select] "; if ((get_request_var_request("page") * read_config_option("num_rows_data_source")) < $total_rows) { $nav .= ""; } $nav .= "Next"; if ((get_request_var_request("page") * read_config_option("num_rows_data_source")) < $total_rows) { $nav .= ""; } $nav .= " >>
\n"; print $nav; html_header( array(" ", "Time", "Notification", "Varbinds" ), true ); $i = 0; if (sizeof($logs) > 0) { foreach ($logs as $item) { $varbinds = (strlen(get_request_var_request("filter")) ? (preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "\\1", $item["varbinds"])): $item["varbinds"]); form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $item['id']); $i++; 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 .= addslashes(trim($line)) . '
'; } print '' . $item["notification"] . ''; }else { print "{$item["notification"]}"; } print "$varbinds"; form_end_row(); } print $nav; }else{ print "No SNMP Notification Log Entries"; } ?> $notifications) { $mib = mysql_real_escape_string($mib); foreach($notifications as $notification => $state) { $notification = mysql_real_escape_string($notification); db_execute("DELETE FROM plugin_snmpagent_managers_notifications WHERE `manager_id` = {$_POST["id"]} AND `mib` = '$mib' AND `notification` = '$notification' LIMIT 1"); } } }elseif ($_POST["drp_action"] == "1") { /* enable */ foreach($selected_items as $mib => $notifications) { $mib = mysql_real_escape_string($mib); foreach($notifications as $notification => $state) { $notification = mysql_real_escape_string($notification); db_execute("INSERT IGNORE INTO plugin_snmpagent_managers_notifications (`manager_id`, `notification`, `mib`) VALUES ('{$_POST["id"]}', '$notification', '$mib')"); } } } header("Location: managers.php?action=edit&id=" . $_POST["id"] . "&tab=notifications"); exit; } }else { if(isset($_POST["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("SELECT description FROM plugin_snmpagent_managers WHERE id = " . $id) . "
  • "; $selected_items[] = $id; } } include_once("./include/top_header.php"); html_start_box("" . $manager_actions{$_POST["drp_action"]} . "", "60%", $colors["header_panel"], "3", "center", ""); print "
    \n"; if (sizeof($selected_items)) { print "

    When you click \"Continue\", the following notification receiver(s) will be " . strtolower($manager_actions[$_POST["drp_action"]]) . "d.

    \n"; $save_html = " "; } else { print "You must select at least one notification receiver.\n"; $save_html = ""; } print " $save_html \n"; html_end_box(); include_once("./include/bottom_footer.php"); }else { $selected_items = array(); $list = ""; /* ================= input validation ================= */ input_validate_input_number( get_request_var_post("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; } } include_once("./include/top_header.php"); html_start_box("" . $manager_notification_actions[ $_POST["drp_action"] ] . "", "60%", $colors["header_panel"], "3", "center", ""); print "\n"; if (sizeof($selected_items)) { $msg = ($_POST["drp_action"] == 1) ? "When you click \"Continue\", events for following notification objects will be forwarded to this noticification receiver." : "When you click \"Continue\", events for following notification objects won't be forwarded to this noticification receiver any longer."; 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(); include_once("./include/bottom_footer.php"); } } } ?>