/* +-------------------------------------------------------------------------+ | Copyright (C) 2002 Ian Berry | | | | This program is free software; you can redistribute it and/or | | modify it under the terms of the GNU General Public License | | as published by the Free Software Foundation; either version 2 | | of the License, or (at your option) any later version. | | | | This program is distributed in the hope that it will be useful, | | but WITHOUT ANY WARRANTY; without even the implied warranty of | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | | GNU General Public License for more details. | +-------------------------------------------------------------------------+ | cacti: the rrdtool frontend [php-auth, php-tree, php-form] | +-------------------------------------------------------------------------+ | This code is currently maintained and debugged by Ian Berry, any | | questions or comments regarding this code should be directed to: | | - iberry@raxnet.net | +-------------------------------------------------------------------------+ | - raXnet - http://www.raxnet.net/ | +-------------------------------------------------------------------------+ */?> $section = "Add/Edit Graphs"; include ('include/auth.php'); include_once ("include/functions.php"); include_once ("include/config_arrays.php"); include_once ('include/form.php'); switch ($_REQUEST["action"]) { case 'save': $redirect_location = form_save(); header ("Location: $redirect_location"); exit; break; case 'remove': snmp_remove(); header ("Location: snmp.php"); break; case 'edit': include_once ("include/top_header.php"); snmp_edit(); include_once ("include/bottom_footer.php"); break; default: include_once ("include/top_header.php"); snmp(); include_once ("include/bottom_footer.php"); break; } /* -------------------------- The Save Function -------------------------- */ function form_save() { if (isset($_POST["save_component_snmp_query"])) { $url = snmp_save(); return $url; } } /* --------------------- SNMP Query Functions --------------------- */ function snmp_remove() { global $config; if ((read_config_option("remove_verification") == "on") && ($_GET["confirm"] != "yes")) { include ('include/top_header.php'); DrawConfirmForm("Are You Sure?", "Are you sure you want to delete the CDEF '" . db_fetch_cell("select name from cdef where id=" . $_GET["id"]) . "'?", getenv("HTTP_REFERER"), "snmp.php?action=remove&id=" . $_GET["id"]); include ('include/bottom_footer.php'); exit; } if ((read_config_option("remove_verification") == "") || ($_GET["confirm"] == "yes")) { db_execute("delete from cdef where id=" . $_GET["id"]); db_execute("delete from cdef_items where cdef_id=" . $_GET["id"]); } } function snmp_save() { $save["id"] = $_POST["id"]; $save["name"] = form_input_validate($_POST["name"], "name", "", false, 3); $save["description"] = form_input_validate($_POST["description"], "description", "", true, 3); $save["xml_path"] = form_input_validate($_POST["xml_path"], "xml_path", "", false, 3); $save["graph_template_id"] = $_POST["graph_template_id"]; $save["data_input_id"] = $_POST["data_input_id"]; $snmp_query_id = sql_save($save, "snmp_query"); db_execute ("delete from snmp_query_dt_field where snmp_query_id=$snmp_query_id"); db_execute ("delete from snmp_query_dt_rrd where snmp_query_id=$snmp_query_id"); while (list($var, $val) = each($_POST)) { if (eregi("^mdt_([0-9]+)_([0-9]+)_check", $var)) { $data_template_id = ereg_replace("^mdt_([0-9]+)_([0-9]+).+", "\\1", $var); $data_input_field_id = ereg_replace("^mdt_([0-9]+)_([0-9]+).+", "\\2", $var); //if (isset($_POST{"dt_" . $data_template_id})) { db_execute ("replace into snmp_query_dt_field (snmp_query_id,data_template_id,data_input_field_id,action_id) values($snmp_query_id,$data_template_id,$data_input_field_id," . $_POST{"mdt_" . $data_template_id . "_" . $data_input_field_id . "_action_id"} . ")"); //} }elseif (eregi("^dsdt_([0-9]+)_([0-9]+)_check", $var)) { $data_template_id = ereg_replace("^dsdt_([0-9]+)_([0-9]+).+", "\\1", $var); $data_template_rrd_id = ereg_replace("^dsdt_([0-9]+)_([0-9]+).+", "\\2", $var); //if (isset($_POST{"dt_" . $data_template_id})) { db_execute ("replace into snmp_query_dt_rrd (snmp_query_id,data_template_id,data_template_rrd_id,snmp_field_name) values($snmp_query_id,$data_template_id,$data_template_rrd_id,'" . $_POST{"dsdt_" . $data_template_id . "_" . $data_template_rrd_id . "_snmp_field_output"} . "')"); //} } } if (is_error_message()) { return $_SERVER["HTTP_REFERER"]; }else{ if (empty($_POST["id"])) { return "snmp.php?action=edit&id=$snmp_query_id"; }else{ return "snmp.php"; } } } function snmp_edit() { include_once ("include/xml_functions.php"); global $colors, $paths, $snmp_query_field_actions; display_output_messages(); start_box("SNMP Queries [edit]", "98%", $colors["header"], "3", "center", ""); if (isset($_GET["id"])) { $snmp_query = db_fetch_row("select * from snmp_query where id=" . $_GET["id"]); }else{ unset($snmp_query); } ?>
end_box(); } function snmp() { global $colors; display_output_messages(); start_box("SNMP Queries", "98%", $colors["header"], "3", "center", "snmp.php?action=edit"); print "