From f93b7e58f5962753900a2d43fa6eb4a4afa892b3 Mon Sep 17 00:00:00 2001 From: Ian Berry Date: Thu, 6 Feb 2003 06:04:00 +0000 Subject: [PATCH] form save validation checks; save code unification/cleaup git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/trunk/cacti@472 860744bd-22fc-0310-8c96-e9fe5004b5ca --- cdef.php | 113 +++++++------- color.php | 48 +++--- data_input.php | 188 +++++++++++------------ data_queries.php | 100 +++++------- data_sources.php | 320 +++++++++++++++++--------------------- data_templates.php | 237 ++++++++++++++-------------- graph_templates.php | 366 ++++++++++++++++++++++---------------------- graphs.php | 320 +++++++++++++++++--------------------- host.php | 175 ++++++++++----------- host_templates.php | 80 +++++----- rra.php | 73 +++++---- tree.php | 127 +++++++-------- user_admin.php | 325 ++++++++++++++++++--------------------- 13 files changed, 1152 insertions(+), 1320 deletions(-) diff --git a/cdef.php b/cdef.php index bc45f9482..6282f071a 100644 --- a/cdef.php +++ b/cdef.php @@ -32,9 +32,8 @@ include_once ('include/form.php'); switch ($_REQUEST["action"]) { case 'save': - $redirect_location = form_save(); + form_save(); - header ("Location: $redirect_location"); exit; break; case 'item_movedown': item_movedown(); @@ -99,11 +98,59 @@ function draw_cdef_preview($cdef_id) { function form_save() { if (isset($_POST["save_component_cdef"])) { - cdef_save(); - return "cdef.php"; + $save["id"] = $_POST["id"]; + $save["name"] = form_input_validate($_POST["name"], "name", "", false, 3); + + if (!is_error_message()) { + $cdef_id = sql_save($save, "cdef"); + + if ($cdef_id) { + raise_message(1); + }else{ + raise_message(2); + } + } + + if (is_error_message()) { + header ("Location: cdef.php?action=edit&id=" . (empty($cdef_id) ? $_POST["id"] : $cdef_id)); + }else{ + header ("Location: cdef.php"); + } }elseif (isset($_POST["save_component_item"])) { - item_save(); - return "cdef.php?action=edit&id=" . $_POST["cdef_id"]; + if ($_POST["value_function"] != "0") { $current_type = 1; $current_value = $_POST["value_function"]; } + if ($_POST["value_operator"] != "0") { $current_type = 2; $current_value = $_POST["value_operator"]; } + if ($_POST["value_special_data_source"] != "0") { $current_type = 4; $current_value = $_POST["value_special_data_source"]; } + if ($_POST["value_cdef"] != "0") { $current_type = 5; $current_value = $_POST["value_cdef"]; } + if ($_POST["value_custom"] != "") { $current_type = 6; $current_value = $_POST["value_custom"]; } + + if (!(isset($current_type))) { + /* YOU MUST SELECT SOMETHING */ + header ("Location: cdef.php?action=edit&id=" . $_POST["cdef_id"]); exit; + } + + $sequence = get_sequence($_POST["id"], "sequence", "cdef_items", "cdef_id=" . $_POST["cdef_id"]); + + $save["id"] = $_POST["id"]; + $save["cdef_id"] = $_POST["cdef_id"]; + $save["sequence"] = $sequence; + $save["type"] = $current_type; + $save["value"] = $current_value; + + if (!is_error_message()) { + $cdef_item_id = sql_save($save, "cdef_items"); + + if ($cdef_item_id) { + raise_message(1); + }else{ + raise_message(2); + } + } + + if (is_error_message()) { + header ("Location: cdef.php?action=item_edit&cdef_id=" . $_POST["cdef_id"] . "&id=" . (empty($cdef_item_id) ? $_POST["id"] : $cdef_item_id)); + }else{ + header ("Location: cdef.php?action=edit&id=$cdef_id"); + } } } @@ -123,29 +170,6 @@ function item_remove() { db_execute("delete from cdef_items where id=" . $_GET["id"]); } -function item_save() { - if ($_POST["value_function"] != "0") { $current_type = 1; $current_value = $_POST["value_function"]; } - if ($_POST["value_operator"] != "0") { $current_type = 2; $current_value = $_POST["value_operator"]; } - if ($_POST["value_special_data_source"] != "0") { $current_type = 4; $current_value = $_POST["value_special_data_source"]; } - if ($_POST["value_cdef"] != "0") { $current_type = 5; $current_value = $_POST["value_cdef"]; } - if ($_POST["value_custom"] != "") { $current_type = 6; $current_value = $_POST["value_custom"]; } - - if (!(isset($current_type))) { - /* YOU MUST SELECT SOMETHING */ - header ("Location: cdef.php?action=edit&id=" . $_POST["cdef_id"]); exit; - } - - $sequence = get_sequence($_POST["id"], "sequence", "cdef_items", "cdef_id=" . $_POST["cdef_id"]); - - $save["id"] = $_POST["id"]; - $save["cdef_id"] = $_POST["cdef_id"]; - $save["sequence"] = $sequence; - $save["type"] = $current_type; - $save["value"] = $current_value; - - sql_save($save, "cdef_items"); -} - function item_edit() { global $colors, $cdef_functions, $cdef_operators, $custom_data_source_types; @@ -153,8 +177,6 @@ function item_edit() { $cdef = db_fetch_row("select * from cdef_items where id=" . $_GET["id"]); $current_type = $cdef["type"]; $values[$current_type] = $cdef["value"]; - }else{ - unset($cdef); } start_box("", "98%", "aaaaaa", "3", "center", ""); @@ -213,16 +235,7 @@ function item_edit() { form_hidden_box("save_component_item","1",""); end_box(); - start_box("", "98%", $colors["header"], "3", "center", ""); - ?> - - - - - - - - - - - - - - Colors [edit]", "98%", $colors["header"], "3", "center", ""); + start_box("Colors $header_label", "98%", $colors["header"], "3", "center", ""); ?>
@@ -101,20 +110,13 @@ function color_edit() { - - - - -
- - - /", $_POST["input_string"], $matches)) { + $j = 0; + for ($i=0; ($i < count($matches[1])); $i++) { + if (in_array($matches[1][$i], $registered_cacti_names) == false) { + $j++; db_execute("update data_input_fields set sequence=$j where data_input_id=" . $_POST["id"] . " and input_output='in' and data_name='" . $matches[1][$i] . "'"); + } + } + } + + if (preg_match_all("/<([_a-zA-Z0-9]+)>/", $_POST["output_string"], $matches)) { + $j = 0; + for ($i=0; ($i < count($matches[1])); $i++) { + if (in_array($matches[1][$i], $registered_cacti_names) == false) { + $j++; db_execute("update data_input_fields set sequence=$j where data_input_id=" . $_POST["id"] . " and input_output='out' and data_name='" . $matches[1][$i] . "'"); + } + } + } + } + }else{ + raise_message(2); + } + } + + if ((is_error_message()) || (empty($_POST["id"]))) { + header ("Location: data_input.php?action=edit&id=" . (empty($data_input_id) ? $_POST["id"] : $data_input_id)); + }else{ + header ("Location: data_input.php"); + } }elseif (isset($_POST["save_component_field"])) { - field_save(); - return "data_input.php?action=edit&id=" . $_POST["data_input_id"]; + $save["id"] = $_POST["id"]; + $save["data_input_id"] = $_POST["data_input_id"]; + $save["name"] = form_input_validate($_POST["name"], "name", "", false, 3); + $save["data_name"] = form_input_validate($_POST["data_name"], "data_name", "", true, 3); + $save["input_output"] = $_POST["input_output"]; + $save["update_rra"] = form_input_validate($_POST["update_rra"], "update_rra", "", true, 3); + $save["sequence"] = $_POST["sequence"]; + $save["type_code"] = form_input_validate($_POST["type_code"], "type_code", "", true, 3); + $save["regexp_match"] = form_input_validate($_POST["regexp_match"], "regexp_match", "", true, 3); + $save["allow_nulls"] = form_input_validate($_POST["allow_nulls"], "allow_nulls", "", true, 3); + + if (!is_error_message()) { + $data_input_field_id = sql_save($save, "data_input_fields"); + + if ($data_input_field_id) { + raise_message(1); + + if (!empty($data_input_field_id)) { + if (preg_match_all("/<([_a-zA-Z0-9]+)>/", db_fetch_cell("select " . $_POST["input_output"] . "put_string from data_input where id=" . $_POST["data_input_id"]), $matches)) { + $j = 0; + for ($i=0; ($i < count($matches[1])); $i++) { + if (in_array($matches[1][$i], $registered_cacti_names) == false) { + $j++; + if ($matches[1][$i] == $_POST["data_name"]) { + db_execute("update data_input_fields set sequence=$j where data_input_id=" . $_POST["data_input_id"] . " and input_output='" . $_POST["input_output"]. "' and data_name='" . $matches[1][$i] . "'"); + } + } + } + } + } + }else{ + raise_message(2); + } + } + + if (is_error_message()) { + header ("Location: data_input.php?action=field_edit&data_input_id=" . $_POST["data_input_id"] . "&id=" . (empty($data_input_field_id) ? $_POST["id"] : $data_input_field_id)); + }else{ + header ("Location: data_input.php?action=edit&id=" . $_POST["data_input_id"]); + } } } @@ -86,7 +168,7 @@ function form_save() { -------------------------- */ function field_remove() { - global $config, $registered_cacti_names; + global $registered_cacti_names; if ((read_config_option("remove_verification") == "on") && ($_GET["confirm"] != "yes")) { include ('include/top_header.php'); @@ -114,37 +196,6 @@ function field_remove() { } } -function field_save() { - global $registered_cacti_names; - - $save["id"] = $_POST["id"]; - $save["data_input_id"] = $_POST["data_input_id"]; - $save["name"] = $_POST["name"]; - $save["data_name"] = $_POST["data_name"]; - $save["input_output"] = $_POST["input_output"]; - $save["update_rra"] = $_POST["update_rra"]; - $save["sequence"] = $_POST["sequence"]; - $save["type_code"] = $_POST["type_code"]; - $save["regexp_match"] = $_POST["regexp_match"]; - $save["allow_nulls"] = $_POST["allow_nulls"]; - - $data_input_field_id = sql_save($save, "data_input_fields"); - - if (!empty($data_input_field_id)) { - if (preg_match_all("/<([_a-zA-Z0-9]+)>/", db_fetch_cell("select " . $_POST["input_output"] . "put_string from data_input where id=" . $_POST["data_input_id"]), $matches)) { - $j = 0; - for ($i=0; ($i < count($matches[1])); $i++) { - if (in_array($matches[1][$i], $registered_cacti_names) == false) { - $j++; - if ($matches[1][$i] == $_POST["data_name"]) { - db_execute("update data_input_fields set sequence=$j where data_input_id=" . $_POST["data_input_id"] . " and input_output='" . $_POST["input_output"]. "' and data_name='" . $matches[1][$i] . "'"); - } - } - } - } - } -} - function field_edit() { global $colors, $registered_cacti_names; @@ -260,16 +311,7 @@ function field_edit() { form_hidden_box("save_component_field","1",""); end_box(); - start_box("", "98%", $colors["header"], "3", "center", ""); - ?> - - - - - - - /", $_POST["input_string"], $matches)) { - $j = 0; - for ($i=0; ($i < count($matches[1])); $i++) { - if (in_array($matches[1][$i], $registered_cacti_names) == false) { - $j++; db_execute("update data_input_fields set sequence=$j where data_input_id=" . $_POST["id"] . " and input_output='in' and data_name='" . $matches[1][$i] . "'"); - } - } - } - - if (preg_match_all("/<([_a-zA-Z0-9]+)>/", $_POST["output_string"], $matches)) { - $j = 0; - for ($i=0; ($i < count($matches[1])); $i++) { - if (in_array($matches[1][$i], $registered_cacti_names) == false) { - $j++; db_execute("update data_input_fields set sequence=$j where data_input_id=" . $_POST["id"] . " and input_output='out' and data_name='" . $matches[1][$i] . "'"); - } - } - } - } - - if (empty($_POST["id"])) { - return "data_input.php?action=edit&id=$data_input_id"; - }else{ - return "data_input.php"; - } -} - function data_edit() { global $colors, $input_types; @@ -459,16 +460,7 @@ function data_edit() { form_hidden_box("save_component_data_input","1",""); - start_box("", "98%", $colors["header"], "3", "center", ""); - ?> - - - - - - - - - - - - - - SNMP Queries", "98%", $colors["header"], "3", "center", "snmp.php?action=edit"); print ""; diff --git a/data_sources.php b/data_sources.php index 44d366126..bf3d2ffda 100644 --- a/data_sources.php +++ b/data_sources.php @@ -31,9 +31,8 @@ include_once ('include/form.php'); switch ($_REQUEST["action"]) { case 'save': - $redirect_location = form_save(); + form_save(); - header ("Location: $redirect_location"); exit; break; case 'data_edit': include_once ("include/top_header.php"); @@ -69,27 +68,145 @@ switch ($_REQUEST["action"]) { -------------------------- */ function form_save() { - if ((isset($_POST["save_component_data_source"])) && (isset($_POST["save_component_data"]))) { - $url = ds_save(); - data_save(); + include_once ("include/utility_functions.php"); + + if (isset($_POST["save_component_data_source"])) { + $save["id"] = $_POST["local_data_id"]; + $save["data_template_id"] = $_POST["data_template_id"]; + $save["host_id"] = $_POST["host_id"]; - if (is_error_message()) { - return $_SERVER["HTTP_REFERER"]; - }elseif (($_POST["data_template_id"] != $_POST["_data_template_id"]) || ($_POST["host_id"] != $_POST["_host_id"])) { - return $url; - }else{ - return "data_sources.php"; - } - }elseif (isset($_POST["save_component_data_source"])) { - return ds_save(); - }elseif (isset($_POST["save_component_data"])) { - data_save(); + $local_data_id = sql_save($save, "data_local"); + unset($save); - if (read_config_option("full_view_data_source") == "") { - return "data_sources.php?action=ds_edit&local_data_id=" . $_POST["local_data_id"] . "&view_rrd=" . $_POST["current_rrd"]; - }elseif (read_config_option("full_view_data_source") == "on") { - return "data_sources.php"; + $save["id"] = $_POST["data_template_data_id"]; + $save["local_data_template_data_id"] = $_POST["local_data_template_data_id"]; + $save["local_data_id"] = $local_data_id; + $save["data_template_id"] = form_input_validate($_POST["data_template_id"], "data_template_id", "", true, 3); + $save["data_input_id"] = form_input_validate($_POST["data_input_id"], "data_input_id", "", true, 3); + $save["name"] = form_input_validate($_POST["name"], "name", "", false, 3); + $save["data_source_path"] = form_input_validate($_POST["data_source_path"], "data_source_path", "", true, 3); + $save["active"] = form_input_validate($_POST["active"], "active", "", true, 3); + $save["rrd_step"] = form_input_validate($_POST["rrd_step"], "rrd_step", "^[0-9]+$", false, 3); + + if (!is_error_message()) { + $data_template_data_id = sql_save($save, "data_template_data"); + + if ($data_template_data_id) { + raise_message(1); + + /* if no data source path has been entered, generate one */ + if (empty($_POST["data_source_path"])) { + generate_data_source_path($local_data_id); + } + + /* save entried in 'selected rras' field */ + db_execute("delete from data_template_data_rra where data_template_data_id=$data_template_data_id"); + + for ($i=0; ($i < count($_POST["rra_id"])); $i++) { + db_execute("insert into data_template_data_rra (rra_id,data_template_data_id) + values (" . $_POST["rra_id"][$i] . ",$data_template_data_id)"); + } + }else{ + raise_message(2); + } } + + unset($save); + + /* if this is a new data source and a template has been selected, skip item creation this time + otherwise it throws off the templatate creation because of the NULL data */ + if ($_POST["data_template_id"] == $_POST["_data_template_id"]) { + $save["id"] = $_POST["data_template_rrd_id"]; + $save["local_data_template_rrd_id"] = $_POST["local_data_template_rrd_id"]; + $save["local_data_id"] = $local_data_id; + $save["data_template_id"] = form_input_validate($_POST["data_template_id"], "data_template_id", "", true, 3); + $save["rrd_maximum"] = form_input_validate($_POST["rrd_maximum"], "rrd_maximum", "^[0-9]+$", false, 3); + $save["rrd_minimum"] = form_input_validate($_POST["rrd_minimum"], "rrd_minimum", "^[0-9]+$", false, 3); + $save["rrd_heartbeat"] = form_input_validate($_POST["rrd_heartbeat"], "rrd_heartbeat", "^[0-9]+$", false, 3); + $save["data_source_type_id"] = $_POST["data_source_type_id"]; + $save["data_source_name"] = form_input_validate($_POST["data_source_name"], "data_source_name", "^[a-zA-Z0-9_]{1,19}$", false, 3); + $save["data_input_field_id"] = $_POST["data_input_field_id"]; + + if (!is_error_message()) { + $data_template_rrd_id = sql_save($save, "data_template_rrd"); + + if ($data_template_rrd_id) { + raise_message(1); + }else{ + raise_message(2); + } + } + } + + if (!is_error_message()) { + update_poller_cache($local_data_id); + + if ($_POST["host_id"] != $_POST["_host_id"]) { + /* push out all nessesary host information */ + push_out_host($_POST["host_id"]); + + /* reset current host for display purposes */ + $_SESSION["sess_data_source_current_host_id"] = $_POST["host_id"]; + } + + if ($_POST["data_template_id"] != $_POST["_data_template_id"]) { + /* update all nessesary template information */ + change_data_template($local_data_id, $_POST["data_template_id"]); + } + } + } + + if ((isset($_POST["save_component_data"])) && (!is_error_message())) { + /* ok, first pull out all 'input' values so we know how much to save */ + $input_fields = db_fetch_assoc("select + data_template_data.data_input_id, + data_local.host_id + data_input_fields.id, + data_input_fields.input_output, + data_input_fields.data_name, + data_input_fields.regexp_match, + data_input_fields.allow_nulls, + data_input_fields.type_code + from data_template_data + left join data_input_fields on data_input_fields.data_input_id=data_template_data.data_input_id + left join data_local on data_template_data.local_data_id=data_local.id + where data_template_data.id=" . $_POST["data_template_data_id"] . " + and data_input_fields.input_output='in'"); + + if (sizeof($input_fields) > 0) { + foreach ($input_fields as $input_field) { + /* save the data into the 'data_input_data' table */ + $form_name = "value_" . $input_field["data_name"]; + $form_value = $_POST[$form_name]; + + if (isset($_POST[$form_name])) { + if ($input_field["allow_nulls"] == "on") { + $allow_nulls = true; + }elseif (empty($input_field["allow_nulls"])) { + $allow_nulls = false; + } + + /* run regexp match on input string */ + $form_value = form_input_validate($form_value, $form_name, $input_field["regexp_match"], $allow_nulls, 3); + + /* make sure we don't overwrite 'host fields' */ + if ((!is_error_message()) && ((empty($input_field["host_id"]) || (empty($input_field["type_code"]))))) { + db_execute("replace into data_input_data (data_input_field_id,data_template_data_id,t_value,value) values + (" . $input_field["id"] . "," . $_POST["data_template_data_id"] . ",'" . db_fetch_cell("select t_value from data_input_data where data_input_field_id=" . $input_field["id"] . " and data_template_data_id=" . $_POST["data_template_data_id"]) . "','$form_value')"); + } + } + } + } + + if ((read_config_option("full_view_data_source") == "") && (is_error_message())) { + /* ds data edit page */ + } + } + + if ((is_error_message()) || ($_POST["data_template_id"] != $_POST["_data_template_id"]) || ($_POST["host_id"] != $_POST["_host_id"])) { + header ("Location: data_sources.php?action=ds_edit&local_data_id=" . (empty($local_data_id) ? $_POST["local_data_id"] : $local_data_id) . "&host_id=" . $_POST["host_id"] . "&view_rrd=" . $_POST["view_rrd"]); + }else{ + header ("Location: data_sources.php"); } } @@ -125,54 +242,9 @@ function draw_data_form_select($main_action) { data - Custom Data ---------------------------- */ -function data_save() { - /* ok, first pull out all 'input' values so we know how much to save */ - $input_fields = db_fetch_assoc("select - data_template_data.data_input_id, - data_local.host_id - data_input_fields.id, - data_input_fields.input_output, - data_input_fields.data_name, - data_input_fields.regexp_match, - data_input_fields.allow_nulls, - data_input_fields.type_code - from data_template_data - left join data_input_fields on data_input_fields.data_input_id=data_template_data.data_input_id - left join data_local on data_template_data.local_data_id=data_local.id - where data_template_data.id=" . $_POST["data_template_data_id"] . " - and data_input_fields.input_output='in'"); - - if (sizeof($input_fields) > 0) { - foreach ($input_fields as $input_field) { - /* save the data into the 'data_input_data' table */ - $form_name = "value_" . $input_field["data_name"]; - $form_value = $_POST[$form_name]; - - if (isset($_POST[$form_name])) { - if ($input_field["allow_nulls"] == "on") { - $allow_nulls = true; - }elseif (empty($input_field["allow_nulls"])) { - $allow_nulls = false; - } - - /* run regexp match on input string */ - $form_value = form_input_validate($form_value, $form_name, $input_field["regexp_match"], $allow_nulls, 3); - - /* make sure we don't overwrite 'host fields' */ - if ((!is_error_message()) && ((empty($input_field["host_id"]) || (empty($input_field["type_code"]))))) { - db_execute("replace into data_input_data (data_input_field_id,data_template_data_id,t_value,value) values - (" . $input_field["id"] . "," . $_POST["data_template_data_id"] . ",'" . db_fetch_cell("select t_value from data_input_data where data_input_field_id=" . $input_field["id"] . " and data_template_data_id=" . $_POST["data_template_data_id"]) . "','$form_value')"); - } - } - } - } -} - function data_edit() { global $config, $colors; - display_output_messages(); - if (isset($_GET["local_data_id"])) { $data = db_fetch_row("select id,data_input_id,data_template_id,name from data_template_data where local_data_id=" . $_GET["local_data_id"]); $template_data = db_fetch_row("select id,data_input_id from data_template_data where data_template_id=" . $data["data_template_id"] . " and local_data_id=0"); @@ -246,16 +318,7 @@ function data_edit() { form_hidden_box("save_component_data","1",""); if (read_config_option("full_view_data_source") == "") { - start_box("", "98%", $colors["header"], "3", "center", ""); - ?> - - - - - - - - - - - - - - Data Sources", "98%", $colors["header"], "3", "center", "data_sources.php?action=ds_edit"); ?> diff --git a/data_templates.php b/data_templates.php index 10a0aee50..7d9f72200 100644 --- a/data_templates.php +++ b/data_templates.php @@ -30,9 +30,8 @@ include_once ("include/config_arrays.php"); switch ($_REQUEST["action"]) { case 'save': - $redirect_location = form_save(); + form_save(); - header ("Location: $redirect_location"); exit; break; case 'template_remove': template_remove(); @@ -60,10 +59,128 @@ switch ($_REQUEST["action"]) { -------------------------- */ function form_save() { - global $config; + include_once ("include/utility_functions.php"); if (isset($_POST["save_component_template"])) { - return template_save(); + /* save: data_template */ + $save["id"] = $_POST["data_template_id"]; + $save["name"] = form_input_validate($_POST["template_name"], "template_name", "", false, 3); + $save["graph_template_id"] = 0; + + if (!is_error_message()) { + $data_template_id = sql_save($save, "data_template"); + + if ($data_template_id) { + raise_message(1); + }else{ + raise_message(2); + } + } + + unset ($save); + + /* save: data_template_data */ + $save["id"] = $_POST["data_template_data_id"]; + $save["local_data_template_data_id"] = 0; + $save["local_data_id"] = 0; + $save["data_template_id"] = $data_template_id; + $save["data_input_id"] = form_input_validate($_POST["data_input_id"], "data_input_id", "", true, 3); + $save["t_name"] = form_input_validate($_POST["t_name"], "t_name", "", true, 3); + $save["name"] = form_input_validate($_POST["name"], "name", "", false, 3); + $save["t_active"] = form_input_validate($_POST["t_active"], "t_active", "", true, 3); + $save["active"] = form_input_validate($_POST["active"], "active", "", true, 3); + $save["t_rrd_step"] = form_input_validate($_POST["t_rrd_step"], "t_rrd_step", "", true, 3); + $save["rrd_step"] = form_input_validate($_POST["rrd_step"], "rrd_step", "^[0-9]+$", false, 3); + $save["t_rra_id"] = form_input_validate($_POST["t_rra_id"], "t_rra_id", "", true, 3); + + if (!is_error_message()) { + $data_template_data_id = sql_save($save, "data_template_data"); + + if ($data_template_data_id) { + raise_message(1); + }else{ + raise_message(2); + } + } + + unset ($save); + + /* save: data_template_rrd */ + $save["id"] = $_POST["data_template_rrd_id"]; + $save["local_data_template_rrd_id"] = 0; + $save["local_data_id"] = 0; + $save["data_template_id"] = $data_template_id; + $save["t_rrd_maximum"] = form_input_validate($_POST["t_rrd_maximum"], "t_rrd_maximum", "", true, 3); + $save["rrd_maximum"] = form_input_validate($_POST["rrd_maximum"], "rrd_maximum", "^[0-9]+$", false, 3); + $save["t_rrd_minimum"] = form_input_validate($_POST["t_rrd_minimum"], "t_rrd_minimum", "", true, 3); + $save["rrd_minimum"] = form_input_validate($_POST["rrd_minimum"], "rrd_minimum", "^[0-9]+$", false, 3); + $save["t_rrd_heartbeat"] = form_input_validate($_POST["t_rrd_heartbeat"], "t_rrd_heartbeat", "", true, 3); + $save["rrd_heartbeat"] = form_input_validate($_POST["rrd_heartbeat"], "rrd_heartbeat", "^[0-9]+$", false, 3); + $save["t_data_source_type_id"] = form_input_validate($_POST["t_data_source_type_id"], "t_data_source_type_id", "", true, 3); + $save["data_source_type_id"] = form_input_validate($_POST["data_source_type_id"], "data_source_type_id", "", true, 3); + $save["t_data_source_name"] = form_input_validate($_POST["t_data_source_name"], "t_data_source_name", "", true, 3); + $save["data_source_name"] = form_input_validate($_POST["data_source_name"], "data_source_name", "^[a-zA-Z0-9_]{1,19}$", false, 3); + $save["data_input_field_id"] = $_POST["data_input_field_id"]; + + if (!is_error_message()) { + $data_template_rrd_id = sql_save($save, "data_template_rrd"); + + if ($data_template_rrd_id) { + raise_message(1); + }else{ + raise_message(2); + } + } + + if (!is_error_message()) { + /* save entried in 'selected rras' field */ + db_execute("delete from data_template_data_rra where data_template_data_id=$data_template_data_id"); + + for ($i=0; ($i < count($_POST["rra_id"])); $i++) { + db_execute("insert into data_template_data_rra (rra_id,data_template_data_id) + values (" . $_POST["rra_id"][$i] . ",$data_template_data_id)"); + } + + /* push out all data source settings to child data source using this template */ + push_out_data_source($data_template_data_id); + push_out_data_source_item($data_template_rrd_id); + + /* ok, first pull out all 'input' values so we know how much to save */ + $input_fields = db_fetch_assoc("select + id, + input_output, + data_name + from data_input_fields + where data_input_id=" . $_POST["data_input_id"] . " + and input_output='in'"); + + db_execute("delete from data_input_data where data_template_data_id=$data_template_data_id"); + + if (sizeof($input_fields) > 0) { + foreach ($input_fields as $input_field) { + /* save the data into the 'host_template_data' table */ + $form_value = "value_" . $input_field["data_name"]; + $form_value = $_POST[$form_value]; + + $form_is_templated_value = "t_value_" . $input_field["data_name"]; + $form_is_templated_value = $_POST[$form_is_templated_value]; + + if ((!empty($form_value)) || (!empty($form_is_templated_value))) { + db_execute("insert into data_input_data (data_input_field_id,data_template_data_id,t_value,value) + values (" . $input_field["id"] . ",$data_template_data_id,'$form_is_templated_value','$form_value')"); + } + } + } + + /* push out all "custom data" for this data source template */ + push_out_data_template($data_template_id); + } + + if ((is_error_message()) || (empty($_POST["data_template_id"]))) { + header ("Location: data_templates.php?action=template_edit&data_template_id=" . (empty($data_template_id) ? $_POST["data_template_id"] : $data_template_id)) . "&view_rrd=" . ($_POST["current_rrd"] ? $_POST["current_rrd"] : $data_template_rrd_id); + }else{ + header ("Location: data_templates.php"); + } } } @@ -72,8 +189,6 @@ function form_save() { ---------------------------- */ function template_remove() { - global $config; - if ((read_config_option("remove_verification") == "on") && ($_GET["confirm"] != "yes")) { include ('include/top_header.php'); form_confirm("Are You Sure?", "Are you sure you want to delete the data template '" . db_fetch_cell("select name from data_template where id=" . $_GET["data_template_id"]) . "'? This is generally not a good idea if you have data sources attached to this template even though it should not affect any data sources.", getenv("HTTP_REFERER"), "data_templates.php?action=template_remove&data_template_id=" . $_GET["data_template_id"]); @@ -93,105 +208,6 @@ function template_remove() { } } -function template_save() { - include_once ("include/utility_functions.php"); - - if ($_POST["rrd_maximum"] == "") { $_POST["rrd_maximum"] = 0; } - if ($_POST["rrd_minimum"] == "") { $_POST["rrd_minimum"] = 0; } - - /* save: data_template */ - $save["id"] = $_POST["data_template_id"]; - $save["name"] = $_POST["template_name"]; - $save["graph_template_id"] = 0; - - $data_template_id = sql_save($save, "data_template"); - unset ($save); - - /* save: data_template_data */ - $save["id"] = $_POST["data_template_data_id"]; - $save["local_data_template_data_id"] = 0; - $save["local_data_id"] = 0; - $save["data_template_id"] = $data_template_id; - $save["data_input_id"] = $_POST["data_input_id"]; - $save["t_name"] = $_POST["t_name"]; - $save["name"] = $_POST["name"]; - $save["t_active"] = $_POST["t_active"]; - $save["active"] = $_POST["active"]; - $save["t_rrd_step"] = $_POST["t_rrd_step"]; - $save["rrd_step"] = $_POST["rrd_step"]; - $save["t_rra_id"] = $_POST["t_rra_id"]; - - $data_template_data_id = sql_save($save, "data_template_data"); - unset ($save); - - /* save: data_template_rrd */ - $save["id"] = $_POST["data_template_rrd_id"]; - $save["local_data_template_rrd_id"] = 0; - $save["local_data_id"] = 0; - $save["data_template_id"] = $data_template_id; - $save["t_rrd_maximum"] = $_POST["t_rrd_maximum"]; - $save["rrd_maximum"] = $_POST["rrd_maximum"]; - $save["t_rrd_minimum"] = $_POST["t_rrd_minimum"]; - $save["rrd_minimum"] = $_POST["rrd_minimum"]; - $save["t_rrd_heartbeat"] = $_POST["t_rrd_heartbeat"]; - $save["rrd_heartbeat"] = $_POST["rrd_heartbeat"]; - $save["t_data_source_type_id"] = $_POST["t_data_source_type_id"]; - $save["data_source_type_id"] = $_POST["data_source_type_id"]; - $save["t_data_source_name"] = $_POST["t_data_source_name"]; - $save["data_source_name"] = $_POST["data_source_name"]; - $save["data_input_field_id"] = $_POST["data_input_field_id"]; - - $data_template_rrd_id = sql_save($save, "data_template_rrd"); - - /* save entried in 'selected rras' field */ - db_execute("delete from data_template_data_rra where data_template_data_id=$data_template_data_id"); - - for ($i=0; ($i < count($_POST["rra_id"])); $i++) { - db_execute("insert into data_template_data_rra (rra_id,data_template_data_id) - values (" . $_POST["rra_id"][$i] . ",$data_template_data_id)"); - } - - /* push out all data source settings to child data source using this template */ - push_out_data_source($data_template_data_id); - push_out_data_source_item($data_template_rrd_id); - - /* ok, first pull out all 'input' values so we know how much to save */ - $input_fields = db_fetch_assoc("select - id, - input_output, - data_name - from data_input_fields - where data_input_id=" . $_POST["data_input_id"] . " - and input_output='in'"); - - db_execute("delete from data_input_data where data_template_data_id=$data_template_data_id"); - - if (sizeof($input_fields) > 0) { - foreach ($input_fields as $input_field) { - /* save the data into the 'host_template_data' table */ - $form_value = "value_" . $input_field["data_name"]; - $form_value = $_POST[$form_value]; - - $form_is_templated_value = "t_value_" . $input_field["data_name"]; - $form_is_templated_value = $_POST[$form_is_templated_value]; - - if ((!empty($form_value)) || (!empty($form_is_templated_value))) { - db_execute("insert into data_input_data (data_input_field_id,data_template_data_id,t_value,value) - values (" . $input_field["id"] . ",$data_template_data_id,'$form_is_templated_value','$form_value')"); - } - } - } - - /* push out all "custom data" for this data source template */ - push_out_data_template($data_template_id); - - if (empty($_POST["data_template_id"])) { - return "data_templates.php?action=template_edit&data_template_id=" . $data_template_id . "&view_rrd=" . ($_POST["current_rrd"] ? $_POST["current_rrd"] : $data_template_rrd_id); - }else{ - return "data_templates.php"; - } -} - function template_edit() { global $colors, $struct_data_source, $struct_data_source_item, $data_source_types; @@ -343,16 +359,7 @@ function template_edit() { form_hidden_id("current_rrd",$_GET["view_rrd"]); form_hidden_box("save_component_template","1",""); - start_box("", "98%", $colors["header"], "3", "center", ""); - ?> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/graphs.php b/graphs.php index f1f426ad3..5be92076a 100644 --- a/graphs.php +++ b/graphs.php @@ -32,9 +32,8 @@ define("ROWS_PER_PAGE", 30); switch ($_REQUEST["action"]) { case 'save': - $redirect_location = form_save(); + form_save(); - header ("Location: $redirect_location"); exit; break; case 'graph_diff': include_once ("include/top_header.php"); @@ -133,28 +132,142 @@ function draw_graph_form_select($main_action) { -------------------------- */ function form_save() { - if ((isset($_POST["save_component_input"])) && (isset($_POST["save_component_graph"]))) { - graph_save(); - input_save(); - return "graphs.php?action=graph_edit&local_graph_id=" . $_POST["local_graph_id"]; - }elseif (isset($_POST["save_component_graph"])) { - graph_save(); - return "graphs.php?action=graph_edit&local_graph_id=" . $_POST["local_graph_id"]; - }elseif (isset($_POST["save_component_input"])) { - input_save(); - return "graphs.php?action=item&local_graph_id=" . $_POST["local_graph_id"]; - }elseif (isset($_POST["save_component_graph_diff"])) { - graph_diff_save(); - return "graphs.php?action=graph_edit&local_graph_id=" . $_POST["local_graph_id"]; - }elseif (isset($_POST["save_component_item"])) { - item_save(); + include_once ("include/utility_functions.php"); + + if (isset($_POST["save_component_graph"])) { + $save["id"] = $_POST["local_graph_id"]; + $save["graph_template_id"] = $_POST["graph_template_id"]; - if (read_config_option("full_view_graph") == "") { - return "graphs.php?action=item&local_graph_id=" . $_POST["local_graph_id"]; - }else{ - return "graphs.php?action=graph_edit&local_graph_id=" . $_POST["local_graph_id"]; + $local_graph_id = sql_save($save, "graph_local"); + unset($save); + + $save["id"] = $_POST["graph_template_graph_id"]; + $save["local_graph_template_graph_id"] = $_POST["local_graph_template_graph_id"]; + $save["local_graph_id"] = $local_graph_id; + $save["graph_template_id"] = $_POST["graph_template_id"]; + $save["image_format_id"] = form_input_validate($_POST["image_format_id"], "image_format_id", "", true, 3); + $save["title"] = form_input_validate($_POST["title"], "title", "", false, 3); + $save["height"] = form_input_validate($_POST["height"], "height", "^[0-9]+$", false, 3); + $save["width"] = form_input_validate($_POST["width"], "width", "^[0-9]+$", false, 3); + $save["upper_limit"] = form_input_validate($_POST["upper_limit"], "upper_limit", "^[0-9]+$", false, 3); + $save["lower_limit"] = form_input_validate($_POST["lower_limit"], "lower_limit", "^[0-9]+$", false, 3); + $save["vertical_label"] = form_input_validate($_POST["vertical_label"], "vertical_label", "", true, 3); + $save["auto_scale"] = form_input_validate($_POST["auto_scale"], "auto_scale", "", true, 3); + $save["auto_scale_opts"] = form_input_validate($_POST["auto_scale_opts"], "auto_scale_opts", "", true, 3); + $save["auto_scale_log"] = form_input_validate($_POST["auto_scale_log"], "auto_scale_log", "", true, 3); + $save["auto_scale_rigid"] = form_input_validate($_POST["auto_scale_rigid"], "auto_scale_rigid", "", true, 3); + $save["auto_padding"] = form_input_validate($_POST["auto_padding"], "auto_padding", "", true, 3); + $save["base_value"] = form_input_validate($_POST["base_value"], "base_value", "^[0-9]+$", false, 3); + $save["export"] = form_input_validate($_POST["export"], "export", "", true, 3); + $save["unit_value"] = form_input_validate($_POST["unit_value"], "unit_value", "", true, 3); + $save["unit_exponent_value"] = form_input_validate($_POST["unit_exponent_value"], "unit_exponent_value", "^[0-9]+$", false, 3); + + if (!is_error_message()) { + $graph_templates_graph_id = sql_save($save, "graph_templates_graph"); + + if ($graph_templates_graph_id) { + raise_message(1); + + /* if template information chanegd, update all nessesary template information */ + if ($_POST["graph_template_id"] != $_POST["_graph_template_id"]) { + /* check to see if the number of graph items differs, if it does; we need user input */ + if ((!empty($_POST["graph_template_id"])) && (sizeof(db_fetch_assoc("select id from graph_templates_item where local_graph_id=$local_graph_id")) != sizeof(db_fetch_assoc("select id from graph_templates_item where local_graph_id=0 and graph_template_id=" . $_POST["graph_template_id"])))) { + /* set the template back, since the user may choose not to go through with the change + at this point */ + db_execute("update graph_local set graph_template_id=" . $_POST["_graph_template_id"] . " where id=$local_graph_id"); + db_execute("update graph_templates_graph set graph_template_id=" . $_POST["_graph_template_id"] . " where local_graph_id=$local_graph_id"); + + header("Location: graphs.php?action=graph_diff&local_graph_id=$local_graph_id&graph_template_id=" . $_POST["graph_template_id"]); + exit; + } + + change_graph_template($local_graph_id, $_POST["graph_template_id"], true); + } + }else{ + raise_message(2); + } } } + + if (isset($_POST["save_component_input"])) { + /* first; get the current graph template id */ + $graph_template_id = db_fetch_cell("select graph_template_id from graph_local where id=" . $_POST["local_graph_id"]); + + /* get all inputs that go along with this graph template */ + $input_list = db_fetch_assoc("select id,column_name from graph_template_input where graph_template_id=$graph_template_id"); + + if (sizeof($input_list) > 0) { + foreach ($input_list as $input) { + /* we need to find out which graph items will be affected by saving this particular item */ + $item_list = db_fetch_assoc("select + graph_templates_item.id + from graph_template_input_defs,graph_templates_item + where graph_template_input_defs.graph_template_item_id=graph_templates_item.local_graph_template_item_id + and graph_templates_item.local_graph_id=" . $_POST["local_graph_id"] . " + and graph_template_input_defs.graph_template_input_id=" . $input["id"]); + + /* loop through each item affected and update column data */ + if (sizeof($item_list) > 0) { + foreach ($item_list as $item) { + db_execute("update graph_templates_item set " . $input["column_name"] . "='" . $_POST{$column_name . "_" . $input["id"]} . "' where id=" . $item["id"]); + } + } + } + } + } + + if (isset($_POST["save_component_graph_diff"])) { + if ($_POST["type"] == "1") { + $intrusive = true; + }elseif ($_POST["type"] == "2") { + $intrusive = false; + } + + change_graph_template($_POST["local_graph_id"], $_POST["graph_template_id"], $intrusive); + } + + if (isset($_POST["save_component_item"])) { + $save["id"] = $_POST["graph_template_item_id"]; + $save["graph_template_id"] = $_POST["graph_template_id"]; + $save["local_graph_id"] = $_POST["local_graph_id"]; + $save["task_item_id"] = form_input_validate($_POST["task_item_id"], "task_item_id", "", true, 3); + $save["color_id"] = form_input_validate($_POST["color_id"], "color_id", "", true, 3); + $save["graph_type_id"] = form_input_validate($_POST["graph_type_id"], "graph_type_id", "", true, 3); + $save["cdef_id"] = form_input_validate($_POST["cdef_id"], "cdef_id", "", true, 3); + $save["consolidation_function_id"] = form_input_validate($_POST["consolidation_function_id"], "consolidation_function_id", "", true, 3); + $save["text_format"] = form_input_validate($_POST["text_format"], "text_format", "", true, 3); + $save["value"] = form_input_validate($_POST["value"], "value", "", true, 3); + $save["hard_return"] = form_input_validate($_POST["hard_return"], "hard_return", "", true, 3); + $save["gprint_id"] = form_input_validate($_POST["gprint_id"], "gprint_id", "", true, 3); + $save["sequence"] = $_POST["sequence"]; + + if (!is_error_message()) { + $graph_template_item_id = sql_save($save, "graph_templates_item"); + + if ($graph_template_item_id) { + raise_message(1); + }else{ + raise_message(2); + } + } + + if (is_error_message()) { + header ("Location: graphs.php?action=item_edit&graph_template_item_id=" . (empty($graph_template_item_id) ? $_POST["graph_template_item_id"] : $graph_template_item_id) . "&local_graph_id=" . $_POST["local_graph_id"]); + exit; + }elseif (read_config_option("full_view_graph") == "") { + header ("Location: graphs.php?action=item&local_graph_id=" . $_POST["local_graph_id"]); + exit; + }elseif (read_config_option("full_view_graph") == "on") { + header ("Location: graphs.php?action=graph_edit&local_graph_id=" . $_POST["local_graph_id"]); + exit; + } + } + + if ((is_error_message()) || (empty($_POST["local_graph_id"])) || (isset($_POST["save_component_input"])) || (isset($_POST["save_component_graph_diff"]))) { + header ("Location: graphs.php?action=graph_edit&local_graph_id=" . (empty($local_graph_id) ? $_POST["local_graph_id"] : $local_graph_id)); + }else{ + header ("Location: graphs.php"); + } } /* ----------------------- @@ -329,16 +442,7 @@ function item() { form_hidden_box("save_component_input","1",""); if ((read_config_option("full_view_graph") == "") && (sizeof($input_item_list) > 0)) { - start_box("", "98%", $colors["header"], "3", "center", ""); - ?> - - - - - - - - - - - - - - 0) { - foreach ($input_list as $input) { - /* we need to find out which graph items will be affected by saving this particular item */ - $item_list = db_fetch_assoc("select - graph_templates_item.id - from graph_template_input_defs,graph_templates_item - where graph_template_input_defs.graph_template_item_id=graph_templates_item.local_graph_template_item_id - and graph_templates_item.local_graph_id=" . $_POST["local_graph_id"] . " - and graph_template_input_defs.graph_template_input_id=" . $input["id"]); - - /* get some variables */ - $column_name = $input["column_name"]; - $column_value = $_POST{$column_name . "_" . $input["id"]}; - - /* loop through each item affected and update column data */ - if (sizeof($item_list) > 0) { - foreach ($item_list as $item) { - db_execute("update graph_templates_item set $column_name='$column_value' where id=" . $item["id"]); - } - } - } - } + form_save_button( $_SERVER["HTTP_REFERER"]); } /* ------------------------------------ graph - Graphs ------------------------------------ */ -function graph_save() { - include_once ("include/utility_functions.php"); - - if ($_POST["lower_limit"] == "") { $_POST["lower_limit"] = 0; } - if ($_POST["upper_limit"] == "") { $_POST["upper_limit"] = 0; } - if ($_POST["unit_exponent_value"] == "") { $_POST["unit_exponent_value"] = 0; } - - $save["id"] = $_POST["local_graph_id"]; - $save["graph_template_id"] = $_POST["graph_template_id"]; - - $local_graph_id = sql_save($save, "graph_local"); - unset($save); - - $save["id"] = $_POST["graph_template_graph_id"]; - $save["local_graph_template_graph_id"] = $_POST["local_graph_template_graph_id"]; - $save["local_graph_id"] = $local_graph_id; - $save["graph_template_id"] = $_POST["graph_template_id"]; - $save["image_format_id"] = $_POST["image_format_id"]; - $save["title"] = $_POST["title"]; - $save["height"] = $_POST["height"]; - $save["width"] = $_POST["width"]; - $save["upper_limit"] = $_POST["upper_limit"]; - $save["lower_limit"] = $_POST["lower_limit"]; - $save["vertical_label"] = $_POST["vertical_label"]; - $save["auto_scale"] = $_POST["auto_scale"]; - $save["auto_scale_opts"] = $_POST["auto_scale_opts"]; - $save["auto_scale_log"] = $_POST["auto_scale_log"]; - $save["auto_scale_rigid"] = $_POST["auto_scale_rigid"]; - $save["auto_padding"] = $_POST["auto_padding"]; - $save["base_value"] = $_POST["base_value"]; - $save["export"] = $_POST["export"]; - $save["unit_value"] = $_POST["unit_value"]; - $save["unit_exponent_value"] = $_POST["unit_exponent_value"]; - - sql_save($save, "graph_templates_graph"); - - /* if template information chanegd, update all nessesary template information */ - if ($_POST["graph_template_id"] != $_POST["_graph_template_id"]) { - /* check to see if the number of graph items differs, if it does; we need user input */ - if ((!empty($_POST["graph_template_id"])) && (sizeof(db_fetch_assoc("select id from graph_templates_item where local_graph_id=$local_graph_id")) != sizeof(db_fetch_assoc("select id from graph_templates_item where local_graph_id=0 and graph_template_id=" . $_POST["graph_template_id"])))) { - /* set the template back, since the user may choose not to go through with the change - at this point */ - db_execute("update graph_local set graph_template_id=" . $_POST["_graph_template_id"] . " where id=$local_graph_id"); - db_execute("update graph_templates_graph set graph_template_id=" . $_POST["_graph_template_id"] . " where local_graph_id=$local_graph_id"); - - header("Location: graphs.php?action=graph_diff&local_graph_id=$local_graph_id&graph_template_id=" . $_POST["graph_template_id"]); - exit; - } - - change_graph_template($local_graph_id, $_POST["graph_template_id"], true); - } - - /* so we get redirected to the correct page, not '&local_graph_id=0' */ - $_POST["local_graph_id"] = $local_graph_id; -} - -function graph_diff_save() { - include_once ("include/utility_functions.php"); - - if ($_POST["type"] == "1") { - $intrusive = true; - }elseif ($_POST["type"] == "2") { - $intrusive = false; - } - - change_graph_template($_POST["local_graph_id"], $_POST["graph_template_id"], $intrusive); -} - function graph_diff() { global $colors; include("include/config_arrays.php"); @@ -760,19 +734,14 @@ function graph_diff() {
- - - - -
- -
+ "> "> - - - - - - - - \n"; @@ -428,7 +430,7 @@ function host_new_graphs($host_id, $host_template_id, $selected_graphs_array) { if (sizeof($fields) > 0) { foreach ($fields as $field) { - print " + print " " . $field["name"] . " -> " . $field["field_name"] . "
When these graphs are created, the following data input field will be filled with data from @@ -499,7 +501,7 @@ function host_new_graphs($host_id, $host_template_id, $selected_graphs_array) { entry here might might 20 graphs... so we can't automatically fill in the values */ if ((!empty($snmp_query_id)) && ($snmp_queries["suggested_values"][0]["graph"][0][$field_name])) { - print ""; + print ""; print "" . $struct_graph[$field_name]["title"] . ""; print "Using Suggested Values (see XML file)"; print "\n"; @@ -528,7 +530,7 @@ function host_new_graphs($host_id, $host_template_id, $selected_graphs_array) { $field_name = $item["column_name"]; - form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],0); + print ""; print " " . $graph_input["name"] . ""; @@ -560,7 +562,7 @@ function host_new_graphs($host_id, $host_template_id, $selected_graphs_array) { values */ if ((!empty($snmp_query_id)) && (isset($snmp_queries["suggested_values"][0]{"ds_" . $data_template["data_source_name"]}[0][$field_name]))) { - print ""; + print ""; print "" . $struct_data_source[$field_name]["title"] . ""; print "Using Suggested Values (see XML file)"; print "\n"; @@ -582,16 +584,17 @@ function host_new_graphs($host_id, $host_template_id, $selected_graphs_array) { if (sizeof($data_template_items) > 0) { foreach ($data_template_items as $data_template_item) { reset($struct_data_source_item); - $row_counter = 0; + $drew_items = false; while (list($field_name, $field_array) = each($struct_data_source_item)) { if ($data_template_item{"t_" . $field_name} == "on") { if ($drew_items == false) { - print "Data Source Item - " . $data_template_item["data_source_name"] . " - [Template: " . $data_template["data_template_name"] . "]"; + //print "Data Source Item - " . $data_template_item["data_source_name"] . " - [Template: " . $data_template["data_template_name"] . "]"; } + $row_counter = 1; draw_templated_row($field_array, "di_" . $snmp_query_id . "_" . $graph_template_id . "_" . $data_template["data_template_id"] . "_" . $data_template_item["id"] . "_" . $field_name, $data_template_item[$field_name]); - $row_counter = 0; $drew_items = true; + $drew_items = true; } } } @@ -608,16 +611,7 @@ function host_new_graphs($host_id, $host_template_id, $selected_graphs_array) { form_hidden_box("save_component_new_graphs","1",""); print "\n"; - start_box("", "98%", $colors["header"], "3", "center", ""); - ?> - - - - - - - - - - - - - - - - - - - - - - - - - - - - Round Robin Archives", "98%", $colors["header"], "3", "center", "rra.php?action=edit"); print ""; diff --git a/tree.php b/tree.php index e4fd31d04..fe3b17627 100644 --- a/tree.php +++ b/tree.php @@ -30,9 +30,8 @@ include_once ('include/functions.php'); switch ($_REQUEST["action"]) { case 'save': - $redirect_location = form_save(); + form_save(); - header ("Location: $redirect_location"); exit; break; case 'item_movedown': item_movedown(); @@ -82,12 +81,60 @@ switch ($_REQUEST["action"]) { -------------------------- */ function form_save() { + include_once("include/tree_functions.php"); + if (isset($_POST["save_component_tree"])) { - tree_save(); - return "tree.php"; + $save["id"] = $_POST["id"]; + $save["name"] = form_input_validate($_POST["name"], "name", "", false, 3); + + if (!is_error_message()) { + $tree_id = sql_save($save, "graph_tree"); + + if ($tree_id) { + raise_message(1); + }else{ + raise_message(2); + } + } + + if (is_error_message()) { + header ("Location: tree.php?action=edit&id=" . (empty($tree_id) ? $_POST["id"] : $tree_id)); + }else{ + header ("Location: tree.php"); + } }elseif (isset($_POST["save_component_tree_item"])) { - item_save(); - return "tree.php?action=edit&id=" . $_POST["graph_tree_id"]; + if (empty($_POST["id"])) { + /* new/save - generate new order key */ + $order_key = get_next_tree_id(db_fetch_cell("select order_key from graph_tree_items where id=" . $_POST["parent_item_id"]),"graph_tree_items","order_key"); + }else{ + /* edit/save - use old order_key */ + $order_key = db_fetch_cell("select order_key from graph_tree_items where id=" . $_POST["id"]); + } + + $save["id"] = $_POST["id"]; + $save["graph_tree_id"] = $_POST["graph_tree_id"]; + $save["title"] = form_input_validate($_POST["title"], "title", "", true, 3); + $save["order_key"] = $order_key; + $save["local_graph_id"] = form_input_validate($_POST["local_graph_id"], "local_graph_id", "", true, 3); + $save["rra_id"] = form_input_validate($_POST["rra_id"], "rra_id", "", true, 3); + + if (!is_error_message()) { + $tree_item_id = sql_save($save, "graph_tree_items"); + + if ($tree_item_id) { + raise_message(1); + + reparent_branch($_POST["parent_item_id"], $_POST["id"]); + }else{ + raise_message(2); + } + } + + if (is_error_message()) { + header ("Location: tree.php?action=item_edit&tree_item_id=" . (empty($tree_item_id) ? $_POST["id"] : $tree_item_id) . "&tree_id=" . $_POST["graph_tree_id"]); + }else{ + header ("Location: tree.php?action=edit&id=" . $_POST["graph_tree_id"]); + } } } @@ -167,16 +214,7 @@ function item_edit() { form_hidden_id("graph_tree_id",$_GET["tree_id"]); form_hidden_box("save_component_tree_item","1",""); - start_box("", "98%", $colors["header"], "3", "center", ""); - ?> - - - - - - - 0) { branch_down($order_key, 'graph_tree_items', 'order_key', ''); } } -function item_save() { - include_once("include/tree_functions.php"); - - if (empty($_POST["id"])) { - /* new/save - generate new order key */ - $order_key = get_next_tree_id(db_fetch_cell("select order_key from graph_tree_items where id=" . $_POST["parent_item_id"]),"graph_tree_items","order_key"); - }else{ - /* edit/save - use old order_key */ - $order_key = db_fetch_cell("select order_key from graph_tree_items where id=" . $_POST["id"]); - } - - $save["id"] = $_POST["id"]; - $save["graph_tree_id"] = $_POST["graph_tree_id"]; - $save["title"] = $_POST["title"]; - $save["order_key"] = $order_key; - $save["local_graph_id"] = $_POST["local_graph_id"]; - $save["rra_id"] = $_POST["rra_id"]; - - if (sql_save($save, "graph_tree_items")) { - raise_message(1); - - reparent_branch($_POST["parent_item_id"], $_POST["id"]); - }else{ - raise_message(2); - header("Location: " . $_SERVER["HTTP_REFERER"]); - exit; - } -} - function item_remove() { include_once("include/tree_functions.php"); @@ -244,22 +253,7 @@ function item_remove() { Tree Functions --------------------- */ -function tree_save() { - $save["id"] = $_POST["id"]; - $save["name"] = $_POST["name"]; - - if (sql_save($save, "graph_tree")) { - raise_message(1); - }else{ - raise_message(2); - header("Location: " . $_SERVER["HTTP_REFERER"]); - exit; - } -} - function tree_remove() { - global $config; - if ((read_config_option("remove_verification") == "on") && ($_GET["confirm"] != "yes")) { include ('include/top_header.php'); form_confirm("Are You Sure?", "Are you sure you want to delete the tree '" . db_fetch_cell("select name from graph_tree where id=" . $_GET["id"]) . "'?", getenv("HTTP_REFERER"), "tree.php?action=remove&id=" . $_GET["id"]); @@ -275,7 +269,7 @@ function tree_remove() { function tree_edit() { include_once("include/tree_view_functions.php"); - global $colors, $cdef_item_types; + global $colors; start_box("Trees [edit]", "98%", $colors["header"], "3", "center", ""); @@ -306,16 +300,7 @@ function tree_edit() { form_hidden_box("save_component_tree","1",""); - start_box("", "98%", $colors["header"], "3", "center", ""); - ?> - - - - - - - User Management [edit]", "98%", $colors["header"], "3", "center", ""); + start_box("User Management $header_label", "98%", $colors["header"], "3", "center", ""); draw_user_form_select(); end_box(); } - if ($graph_policy == "1") { - $graph_policy_text = "Select the graphs you want to DENY this user from."; - } elseif ($graph_policy == "2") { - $graph_policy_text = "Select the graphs you want ALLOW this user to view."; - } + $header_label = "Graph Permissions [policy: " . (($graph_policy == "1") ? "ALLOW" : "DENY") . "]"; - start_box($graph_policy_text, "98%", $colors["header"], "3", "center", ""); + start_box($header_label, "98%", $colors["header"], "3", "center", ""); $graphs = db_fetch_assoc("select user_auth_graph.user_id, graph_templates_graph.local_graph_id, graph_templates_graph.title from graph_templates_graph - left join user_auth_graph on (graph_templates_graph.local_graph_id=user_auth_graph.local_graph_id and user_auth_graph.user_id=" . $_GET["id"] . ") + left join user_auth_graph on (graph_templates_graph.local_graph_id=user_auth_graph.local_graph_id and user_auth_graph.user_id=" . (empty($_GET["id"]) ? "0" : $_GET["id"]) . ") where graph_templates_graph.local_graph_id > 0 order by graph_templates_graph.title"); - $rows = sizeof($graphs); ?>
@@ -181,27 +219,26 @@ function graph_perms_edit() {
- 0) { - foreach ($graphs as $graph) { - if ($graph["user_id"] == "") { - $old_value = ""; - }else{ - $old_value = "on"; - } - - $column1 = floor(($rows / 2) + ($rows % 2)); - - if ($i == $column1) { - print ""; - } - - form_base_checkbox("graph" . $graph["id"], $old_value, $graph["title"], "", $_GET["id"], true); - $i++; - } - } - ?> + 0) { + foreach ($graphs as $graph) { + if ($graph["user_id"] == "") { + $old_value = ""; + }else{ + $old_value = "on"; + } + + $column1 = floor((sizeof($graphs) / 2) + (sizeof($graphs) % 2)); + + if ($i == $column1) { + print ""; + } + + form_base_checkbox("graph" . $graph["local_graph_id"], $old_value, $graph["title"], "", $_GET["id"], true); + $i++; + } + } + ?>
@@ -215,16 +252,7 @@ function graph_perms_edit() { form_hidden_box("save_component_graph_perms","1",""); if (read_config_option("full_view_user_admin") == "") { - start_box("", "98%", $colors["header"], "3", "center", ""); - ?> - - - - - -
- User Management [edit]", "98%", $colors["header"], "3", "center", ""); + start_box("User Management $header_label", "98%", $colors["header"], "3", "center", ""); draw_user_form_select(); end_box(); } @@ -253,7 +283,7 @@ function graph_config_edit() { ?> "> - + Graph Settings [] \n"; } @@ -299,62 +331,14 @@ function graph_config_edit() { form_hidden_id("user_id",$_GET["id"]); form_hidden_box("save_component_graph_config","1",""); - start_box("", "98%", $colors["header"], "3", "center", ""); - ?> - - - - - - - '" . db_fetch_cell("select username from user where id=" . $_GET["id"]) . "'?", getenv("HTTP_REFERER"), "user_admin.php?action=user_remove&id=" . $_GET["id"]); @@ -373,21 +357,22 @@ function user_remove() { } function user_edit() { - global $colors, $config; + global $colors; if (isset($_GET["id"])) { $user = db_fetch_row("select * from user where id=" . $_GET["id"]); + $header_label = "[edit: " . $user["username"] . "]"; }else{ - unset($user); + $header_label = "[new]"; } if (read_config_option("full_view_user_admin") == "") { - start_box("User Management [edit]", "98%", $colors["header"], "3", "center", ""); + start_box("User Management $header_label", "98%", $colors["header"], "3", "center", ""); draw_user_form_select(); end_box(); } - start_box("User Configuration", "98%", $colors["header"], "3", "center", ""); + start_box("User Management $header_label", "98%", $colors["header"], "3", "center", ""); ?>
@@ -396,7 +381,7 @@ function user_edit() { form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],0); ?> User Name
- + The login name for this user. @@ -404,7 +389,7 @@ function user_edit() { Full Name
- + A more descriptive name for this user, that can include spaces or special characters. @@ -412,18 +397,18 @@ function user_edit() { Password
- + Enter the password for this user twice. Remember that passwords are case sensitive!
- + Account Options
- + Set any user account-specific options here. Graph Options
- + Set any graph-specific options here. Realm Permissions", "98%", $colors["header"], "3", "center", ""); $realms = db_fetch_assoc("select user_auth_realm.user_id, user_realm.id, user_realm.name from user_realm - left join user_auth_realm on (user_realm.id=user_auth_realm.realm_id and user_auth_realm.user_id=" . $_GET["id"] . ") + left join user_auth_realm on (user_realm.id=user_auth_realm.realm_id and user_auth_realm.user_id=" . (empty($_GET["id"]) ? "0" : $_GET["id"]) . ") order by user_realm.name"); ?> @@ -494,28 +479,27 @@ function user_edit() {
- 0) { - foreach ($realms as $realm) { - if ($realm["user_id"] == "") { - $old_value = ""; - }else{ - $old_value = "on"; - } - - $column1 = floor((sizeof($realms) / 2) + (sizeof($realms) % 2)); - - if ($i == $column1) { - print ""; - } - - form_base_checkbox("section" . $realm["id"], $old_value, $realm["name"], "", $_GET["id"], true); - - $i++; - } - } - ?> + 0) { + foreach ($realms as $realm) { + if ($realm["user_id"] == "") { + $old_value = ""; + }else{ + $old_value = "on"; + } + + $column1 = floor((sizeof($realms) / 2) + (sizeof($realms) % 2)); + + if ($i == $column1) { + print ""; + } + + form_base_checkbox("section" . $realm["id"], $old_value, $realm["name"], "", $_GET["id"], true); + + $i++; + } + } + ?>
@@ -529,22 +513,13 @@ function user_edit() { form_hidden_box("save_component_user","1",""); if (read_config_option("full_view_user_admin") == "") { - start_box("", "98%", $colors["header"], "3", "center", ""); - ?> - - - - - -
-