function form_save() { if (isset($_POST["save_component_item"])) { /* cache all post field values */ init_post_field_cache(); /* step #1: field validation */ $form_graph_item["id"] = $_POST["graph_template_item_id"]; $form_graph_item["graph_template_id"] = $_POST["graph_template_id"]; $form_graph_item["data_template_item_id"] = $_POST["data_template_item_id"]; $form_graph_item["color"] = $_POST["color"]; $form_graph_item["graph_item_type"] = $_POST["graph_item_type"]; $form_graph_item["consolidation_function"] = $_POST["consolidation_function"]; $form_graph_item["cdef"] = $_POST["cdef"]; $form_graph_item["gprint_format"] = $_POST["gprint_format"]; $form_graph_item["legend_value"] = $_POST["legend_value"]; $form_graph_item["legend_format"] = $_POST["legend_format"]; $form_graph_item["hard_return"] = html_boolean(isset($_POST["hard_return"]) ? $_POST["hard_return"] : ""); field_register_error(api_graph_item_fields_validate($form_graph_item, "|field|")); /* step #2: field save */ if (!is_error_message()) { $graph_template_item_id = api_graph_template_item_save($_POST["graph_template_item_id"], $form_graph_item); } if (is_error_message()) { header("Location: graph_templates_items.php?action=edit" . (empty($graph_template_item_id) ? "" : "&id=" . $graph_template_item_id) . "&graph_template_id=" . $_POST["graph_template_id"]); } else { header("Location: graph_templates.php?action=edit&id=" . $_POST["graph_template_id"]); } } }
function form_save() { if ($_POST["action_post"] == "script_field_edit") { /* cache all post field values */ init_post_field_cache(); $form_script_field["data_input_id"] = $_POST["script_id"]; $form_script_field["name"] = $_POST["name"]; $form_script_field["data_name"] = $_POST["data_name"]; $form_script_field["input_output"] = ($_POST["field_type"] == SCRIPT_FIELD_TYPE_INPUT ? "in" : "out"); if ($_POST["field_type"] == SCRIPT_FIELD_TYPE_INPUT) { $form_script_field["field_input_type"] = $_POST["field_input_type"]; if ($_POST["field_input_type"] == SCRIPT_FIELD_INPUT_CUSTOM) { $form_script_field["field_input_value"] = $_POST["field_input_value_custom"]; }else if ($_POST["field_input_type"] == SCRIPT_FIELD_INPUT_DEVICE) { $form_script_field["field_input_value"] = $_POST["field_input_value_device"]; } $form_script_field["regexp_match"] = $_POST["regexp_match"]; $form_script_field["allow_empty"] = html_boolean(isset($_POST["allow_empty"]) ? $_POST["allow_empty"] : ""); }else if ($_POST["field_type"] == SCRIPT_FIELD_TYPE_OUTPUT) { $form_script_field["update_rrd"] = html_boolean(isset($_POST["update_rrd"]) ? $_POST["update_rrd"] : ""); } /* obtain a list of visible script field fields on the form */ $visible_fields = api_script_field_visible_field_list($_POST["field_type"]); /* all non-visible fields on the form should be discarded */ foreach ($visible_fields as $field_name) { $v_form_script_field[$field_name] = $form_script_field[$field_name]; } field_register_error(api_script_field_field_validate($v_form_script_field, "|field|")); /* if the validation passes, save the row to the database */ if (!is_error_message()) { $script_field_id = api_script_field_save($_POST["id"], $form_script_field); } if (is_error_message()) { header("Location: scripts_fields.php?action=edit&script_id=" . $_POST["script_id"] . "&id=" . (empty($script_field_id) ? $_POST["id"] : $script_field_id) . (!empty($_POST["field_type"]) ? "&field_type=" . $_POST["field_type"] : "")); }else{ header("Location: scripts.php?action=edit&id=" . $_POST["script_id"]); } /* submit button on the actions area page */ }else if ($_POST["action_post"] == "box-1") { $selected_rows = explode(":", $_POST["box-1-action-area-selected-rows"]); if ($_POST["box-1-action-area-type"] == "remove") { foreach ($selected_rows as $script_field_id) { api_script_field_remove($script_field_id); } } header("Location: scripts.php?action=edit&id=" . $_POST["script_id"]); } }
function form_save() { if ($_POST["action_post"] == "graph_tree_item_edit") { /* cache all post field values */ init_post_field_cache(); $form_graph_tree_item["graph_tree_id"] = $_POST["graph_tree_id"]; $form_graph_tree_item["device_grouping_type"] = $_POST["device_grouping_type"]; $form_graph_tree_item["parent_item_id"] = $_POST["parent_item_id"]; $form_graph_tree_item["sort_children_type"] = $_POST["sort_children_type"]; $form_graph_tree_item["item_type"] = $_POST["item_type"]; $form_graph_tree_item["propagate_changes"] = html_boolean(isset($_POST["propagate_changes"]) ? $_POST["propagate_changes"] : ""); if ($_POST["item_type"] == TREE_ITEM_TYPE_HEADER) { $form_graph_tree_item["item_value"] = $_POST["item_value_title"]; } else { if ($_POST["item_type"] == TREE_ITEM_TYPE_GRAPH) { $form_graph_tree_item["item_value"] = $_POST["item_value_graph"]; } else { if ($_POST["item_type"] == TREE_ITEM_TYPE_HOST) { $form_graph_tree_item["item_value"] = $_POST["item_value_device"]; } } } /* obtain a list of visible graph tree item fields on the form */ $visible_fields = api_graph_tree_item_visible_field_list($_POST["item_type"]); /* all non-visible fields on the form should be discarded */ foreach ($visible_fields as $field_name) { $v_form_graph_tree_item[$field_name] = $form_graph_tree_item[$field_name]; } /* validate graph tree item preset fields */ field_register_error(api_graph_tree_item_fields_validate($v_form_graph_tree_item, "|field|")); /* the header title textbox goes by a different name on the form */ if (field_error_isset("item_value") && $_POST["item_type"] == TREE_ITEM_TYPE_HEADER) { field_register_error("item_value_title"); } if (!is_error_message()) { $graph_tree_item_id = api_graph_tree_item_save($_POST["id"], $form_graph_tree_item); } if (is_error_message()) { header("Location: graph_trees_items.php?action=edit&tree_id=" . $_POST["graph_tree_id"] . (empty($graph_tree_item_id) ? "" : "&id={$graph_tree_item_id}")); } else { header("Location: graph_trees.php?action=edit&id=" . $_POST["graph_tree_id"]); } /* submit button on the actions area page */ } else { if ($_POST["action_post"] == "box-1") { $selected_rows = explode(":", $_POST["box-1-action-area-selected-rows"]); if ($_POST["box-1-action-area-type"] == "remove") { foreach ($selected_rows as $graph_tree_item_id) { api_graph_tree_item_remove($graph_tree_item_id); } } header("Location: graph_trees.php?action=edit&id=" . $_POST["graph_tree_id"]); } } }
function form_save() { if ($_POST["action_post"] == "script_edit") { /* cache all post field values */ init_post_field_cache(); $form_script["name"] = $_POST["name"]; $form_script["input_string"] = $_POST["input_string"]; $form_script["type_id"] = $_POST["type_id"]; field_register_error(api_script_field_validate($form_script, "|field|")); /* if the validation passes, save the row to the database */ if (!is_error_message()) { $script_id = api_script_save($_POST["id"], $form_script); } if ((is_error_message()) || (empty($_POST["id"]))) { header("Location: scripts.php?action=edit&id=" . (empty($script_id) ? $_POST["id"] : $script_id)); }else{ header("Location: scripts.php"); } /* submit button on the actions area page */ }else if ($_POST["action_post"] == "box-1") { $selected_rows = explode(":", $_POST["box-1-action-area-selected-rows"]); if ($_POST["box-1-action-area-type"] == "remove") { foreach ($selected_rows as $script_id) { api_script_remove($script_id); } }else if ($_POST["box-1-action-area-type"] == "duplicate") { // yet yet coded } header("Location: scripts.php"); /* 'filter' area at the bottom of the box */ }else if ($_POST["action_post"] == "script_list") { $get_string = ""; /* the 'clear' button wasn't pressed, so we should filter */ if (!isset($_POST["box-1-action-clear-button"])) { if (trim($_POST["box-1-search_filter"]) != "") { $get_string = ($get_string == "" ? "?" : "&") . "search_filter=" . urlencode($_POST["box-1-search_filter"]); } } header("Location: scripts.php$get_string"); } }
function form_save() { if ($_POST["action_post"] == "graph_tree_edit") { /* cache all post field values */ init_post_field_cache(); $form_graph_tree["name"] = $_POST["name"]; $form_graph_tree["sort_type"] = $_POST["sort_type"]; /* validate graph tree preset fields */ field_register_error(api_graph_tree_fields_validate($form_graph_tree, "|field|")); if (!is_error_message()) { $graph_tree_id = api_graph_tree_save($_POST["id"], $form_graph_tree); } if (is_error_message()) { header("Location: graph_trees.php?action=edit" . (empty($graph_tree_id) ? "" : "&id={$graph_tree_id}")); } else { header("Location: graph_trees.php"); } /* submit button on the actions area page */ } else { if ($_POST["action_post"] == "box-1") { $selected_rows = explode(":", $_POST["box-1-action-area-selected-rows"]); if ($_POST["box-1-action-area-type"] == "remove") { foreach ($selected_rows as $graph_tree_id) { api_graph_tree_remove($graph_tree_id); } } else { if ($_POST["box-1-action-area-type"] == "duplicate") { // yet yet coded } } header("Location: graph_trees.php"); /* 'filter' area at the bottom of the box */ } else { if ($_POST["action_post"] == "graph_tree_list") { $get_string = ""; /* the 'clear' button wasn't pressed, so we should filter */ if (!isset($_POST["box-1-action-clear-button"])) { if (trim($_POST["box-1-search_filter"]) != "") { $get_string = ($get_string == "" ? "?" : "&") . "search_filter=" . urlencode($_POST["box-1-search_filter"]); } } header("Location: graph_trees.php{$get_string}"); } } } }
function form_save() { if ($_POST["action_post"] == "gprint_preset_edit") { /* cache all post field values */ init_post_field_cache(); $form_gprint["name"] = $_POST["name"]; $form_gprint["gprint_text"] = $_POST["gprint_text"]; /* validate base gprint preset fields */ field_register_error(api_data_preset_gprint_field_validate($form_gprint, "|field|")); if (!is_error_message()) { $preset_gprint_id = api_data_preset_gprint_save($_POST["preset_gprint_id"], $form_gprint); if (empty($preset_gprint_id)) { raise_message(2); } } if (is_error_message()) { header("Location: presets_gprint.php?action=edit" . (empty($preset_gprint_id) ? "" : "&id=$preset_gprint_id")); }else{ header("Location: presets.php?action=view_gprint"); } }else if (isset($_POST["box-1-action-area-button"])) { $selected_rows = explode(":", $_POST["box-1-action-area-selected-rows"]); if ($_POST["box-1-action-area-type"] == "remove") { foreach ($selected_rows as $preset_gprint_id) { api_data_preset_gprint_remove($preset_gprint_id); } } header("Location: presets.php?action=view_gprint"); } }
function form_save() { if ($_POST["action_post"] == "package_new") { header("Location: packages.php?action=edit"); }else if ($_POST["action_post"] == "package_edit") { /* the "Add" associated graph template button was pressed */ if (isset($_POST["assoc_graph_template_add_y"])) { api_package_package_template_add($_POST["package_id"], $_POST["assoc_graph_template_id"]); header("Location: packages.php?action=edit&id=" . $_POST["package_id"]); exit; } /* cache all post field values */ init_post_field_cache(); /* step #2: field validation */ $form_package["id"] = $_POST["package_id"]; $form_package["name"] = $_POST["name"]; $form_package["description"] = $_POST["description"]; $form_package["description_install"] = $_POST["description_install"]; $form_package["category"] = ($_POST["category"] == "new" ? $_POST["category_txt"] : api_data_preset_package_category_get($_POST["category_drp"])); $form_package["subcategory"] = ($_POST["subcategory"] == "new" ? $_POST["subcategory_txt"] : api_data_preset_package_subcategory_get($_POST["subcategory_drp"])); $form_package["vendor"] = ($_POST["vendor"] == "new" ? $_POST["vendor_txt"] : api_data_preset_package_vendor_get($_POST["vendor_drp"])); $form_package["model"] = $_POST["model"]; /* the author field values may either come from the form or from the database */ if ($_POST["author_type"] == "new") { $form_package["author_name"] = $_POST["author_name"]; $form_package["author_email"] = $_POST["author_email"]; $form_package["author_user_repository"] = $_POST["author_user_repository"]; $form_package["author_user_forum"] = $_POST["author_user_forum"]; }else if ($_POST["author_type"] == "existing") { $package_author = api_package_author_get($_POST["author_type_drp"]); $form_package["author_name"] = $package_author["name"]; $form_package["author_email"] = $package_author["email"]; $form_package["author_user_repository"] = $package_author["user_repository"]; $form_package["author_user_forum"] = $package_author["user_forum"]; } field_register_error(api_package_field_validate($form_package, "|field|")); /* the custom category textbox goes by a different name on the form */ if (field_error_isset("category")) { field_register_error("category_txt"); } /* the custom subcategory textbox goes by a different name on the form */ if (field_error_isset("subcategory")) { field_register_error("subcategory_txt"); } /* step #3: field save */ $package_id = false; if (is_error_message()) { log_save("User input validation error for package [ID#" . $_POST["package_id"] . "]", SEV_DEBUG); }else{ $package_id = api_package_save($_POST["package_id"], $form_package); if ($package_id === false) { log_save("Save error for package [ID#" . $_POST["package_id"] . "]", SEV_ERROR); } } if (($package_id === false) || (empty($_POST["package_id"]))) { header("Location: packages.php?action=edit" . (empty($_POST["package_id"]) ? "" : "&id=" . $_POST["package_id"])); }else{ header("Location: packages.php"); } }else if ($_POST["action_post"] == "package_edit_metadata") { /* cache all post field values */ init_post_field_cache(); /* step #2: field validation */ $form_package_metadata["id"] = $_POST["package_metadata_id"]; $form_package_metadata["package_id"] = $_POST["package_id"]; $form_package_metadata["type"] = $_POST["type"]; $form_package_metadata["name"] = $_POST["name"]; $form_package_metadata["description"] = $_POST["description"]; if ($_POST["type"] == PACKAGE_METADATA_TYPE_SCREENSHOT) { /* make sure there is a valid file that was uploaded via an HTTP POST */ if ((isset($_FILES["payload_upl"])) && (is_uploaded_file($_FILES["payload_upl"]["tmp_name"]))) { $fp = fopen($_FILES["payload_upl"]["tmp_name"], "r"); $raw_data = fread($fp, $_FILES["payload_upl"]["size"]); fclose($fp); $form_package_metadata["mime_type"] = $_FILES["payload_upl"]["type"]; $form_package_metadata["payload"] = $raw_data; } }else if ($_POST["type"] == PACKAGE_METADATA_TYPE_SCRIPT) { $form_package_metadata["description_install"] = $_POST["description_install"]; $form_package_metadata["required"] = html_boolean(isset($_POST["required"]) ? $_POST["required"] : ""); $form_package_metadata["mime_type"] = "text/plain"; $form_package_metadata["payload"] = $_POST["payload_txt"]; } field_register_error(api_package_field_validate($form_package_metadata, "|field|")); /* step #3: field save */ $package_metadata_id = false; if (is_error_message()) { log_save("User input validation error for package metadata [ID#" . $_POST["package_metadata_id"] . "], package [ID#" . $_POST["package_id"] . "]", SEV_DEBUG); }else{ $package_metadata_id = api_package_metadata_save($_POST["package_metadata_id"], $form_package_metadata); if ($package_metadata_id === false) { log_save("Save error for package metadata [ID#" . $_POST["package_metadata_id"] . "], package [ID#" . $_POST["package_id"] . "]", SEV_ERROR); } } if ($package_metadata_id === false) { header("Location: packages.php?action=edit_metadata&package_id=" . $_POST["package_id"] . (empty($_POST["package_metadata_id"]) ? "" : "&id=" . $_POST["package_metadata_id"])); }else{ /* the cache will not be purged in time unless to do it here */ kill_post_field_cache(); header("Location: packages.php?action=edit&id=" . $_POST["package_id"]); } }else if ($_POST["action_post"] == "package_import") { /* first, see if there is any XML in the textbox */ if (trim($_POST["import_package_text"] != "")) { $xml_data = $_POST["import_package_text"]; /* next, check if the user uploaded a file */ }else if ((isset($_FILES["import_package_file"])) && (is_uploaded_file($_FILES["import_package_file"]["tmp_name"]))) { $fp = fopen($_FILES["import_package_file"]["tmp_name"], "r"); $xml_data = fread($fp, $_FILES["import_package_file"]["size"]); fclose($fp); } package_import($xml_data); } }
function host_new_graphs_save() { $validation_array = array(); $selected_graphs_array = unserialize(stripslashes($_POST["selected_graphs_array"])); $map_id_to_index_array = unserialize(stripslashes($_POST["map_id_to_index_array"])); /* form an array that contains all of the data on the previous form */ while (list($var, $val) = each($_POST)) { if (preg_match("/^g_(\\d+)_(\\d+)_(\\w+)/", $var, $matches)) { /* 1: data_query_id, 2: graph_template_id, 3: field_name */ foreach ($map_id_to_index_array[empty($matches[1]) ? "gt" : "dq"][empty($matches[1]) ? $matches[2] : $matches[1]] as $uniq_id) { $selected_graphs_array[$uniq_id]["graph_template"][$matches[3]] = $val; } $validation_array["graph_template"][$matches[3]][$var] = $val; } elseif (preg_match("/^gi_(\\d+)_(\\d+)_(\\d+)_(\\w+)/", $var, $matches)) { /* 1: data_query_id, 2: graph_template_id, 3: graph_template_input_id, 4: field_name */ foreach ($map_id_to_index_array[empty($matches[1]) ? "gt" : "dq"][empty($matches[1]) ? $matches[2] : $matches[1]] as $uniq_id) { $selected_graphs_array[$uniq_id]["graph_template_item"][$matches[2]][$matches[3]] = $val; } $validation_array["graph_template_item"][$matches[4]][$var] = $val; } elseif (preg_match("/^d_(\\d+)_(\\d+)_(\\d+)_(\\w+)/", $var, $matches)) { /* 1: data_query_id, 2: graph_template_id, 3: data_template_id, 4: field_name */ foreach ($map_id_to_index_array[empty($matches[1]) ? "gt" : "dq"][empty($matches[1]) ? $matches[2] : $matches[1]] as $uniq_id) { $selected_graphs_array[$uniq_id]["data_template"][$matches[3]][$matches[4]] = $val; } $validation_array["data_template"][$matches[4]][$var] = $val; } elseif (preg_match("/^c_(\\d+)_(\\d+)_(\\d+)_(\\d+)/", $var, $matches)) { /* 1: data_query_id, 2: graph_template_id, 3: data_template_id, 4: data_input_field_name */ foreach ($map_id_to_index_array[empty($matches[1]) ? "gt" : "dq"][empty($matches[1]) ? $matches[2] : $matches[1]] as $uniq_id) { $selected_graphs_array[$uniq_id]["custom_data"][$matches[3]][$matches[4]] = $val; } $validation_array["custom_data"][$matches[4]][$var] = $val; } elseif (preg_match("/^di_(\\d+)_(\\d+)_(\\d+)_(\\d+)_(\\w+)/", $var, $matches)) { /* 1: data_query_id, 2: graph_template_id, 3: data_template_id, 4: data_template_item_id, 5: field_name */ foreach ($map_id_to_index_array[empty($matches[1]) ? "gt" : "dq"][empty($matches[1]) ? $matches[2] : $matches[1]] as $uniq_id) { $selected_graphs_array[$uniq_id]["data_template_item"][$matches[3]][$matches[4]][$matches[5]] = $val; } $validation_array["data_template_item"][$matches[5]][$var] = $val; } } /* first pass: form validation */ while (list($type, $type_array) = each($validation_array)) { while (list($field_name, $field_array) = each($type_array)) { while (list($form_field_name, $value) = each($field_array)) { $_v_arr = array($field_name => $value); if ($type == "data_template") { $_sv_arr = array(); field_register_error(api_data_source_fields_validate($_v_arr, $_sv_arr, $form_field_name, "")); } else { if ($type == "custom_data") { field_register_error(api_data_source_input_fields_validate($_v_arr, $form_field_name)); } else { if ($type == "data_template_item") { $_v_arr["id"] = 0; field_register_error(api_data_source_item_fields_validate($_v_arr, $form_field_name)); } else { if ($type == "graph_template") { $_sv_arr = array(); field_register_error(api_graph_fields_validate($_v_arr, $_sv_arr, $form_field_name, "")); } else { if ($type == "graph_template_item") { field_register_error(api_graph_item_fields_validate($_v_arr, $form_field_name)); } } } } } } } } /* form validation failed: redirect back */ if (is_error_message()) { /* cache all post field values */ init_post_field_cache(); host_new_graphs($selected_graphs_array, $map_id_to_index_array); /* form validation passed: save the data on the form */ } else { debug_log_clear("new_graphs"); foreach ($selected_graphs_array as $uniq_id => $skel) { if (isset($skel["custom_data"]["all_dq"])) { $is_data_query_graph = true; $data_query_id = isset($skel["custom_data"]["all_dq"]["data_query_id"]) ? $skel["custom_data"]["all_dq"]["data_query_id"] : 0; /* decode the data query index into its literal form */ $data_query_index = decode_data_query_index(isset($skel["custom_data"]["all_dq"]["data_query_index"]) ? $skel["custom_data"]["all_dq"]["data_query_index"] : 0, get_data_query_indexes($data_query_id, $_POST["host_id"])); } else { $is_data_query_graph = false; $data_query_id = 0; $data_query_index = ""; } $create_info = generate_complete_graph($skel["graph_template_id"], $_POST["host_id"], $data_query_id, $data_query_index); /* set the appropriate 'custom_data' keys */ if ($is_data_query_graph == true) { /* pick the data query field name to index on */ $data_query_field_name = get_best_data_query_index_type($_POST["host_id"], $data_query_id); /* get a list of all data templates associated with this graph template that are of type DATA_INPUT_TYPE_DATA_QUERY */ $dq_data_templates = get_data_templates_from_graph_template($skel["graph_template_id"], DATA_INPUT_TYPE_DATA_QUERY); if (sizeof($dq_data_templates) > 0) { foreach ($dq_data_templates as $data_template) { $skel["custom_data"][$data_template["id"]]["data_query_id"] = $data_query_id; $skel["custom_data"][$data_template["id"]]["data_query_index"] = $data_query_index; $skel["custom_data"][$data_template["id"]]["data_query_field_name"] = $data_query_field_name; $skel["custom_data"][$data_template["id"]]["data_query_field_value"] = get_data_query_row_value($data_query_id, $_POST["host_id"], $data_query_field_name, $data_query_index); } } } /* update user specified data: data source-specific fields */ foreach (array_keys($create_info["data_source"]) as $data_template_id) { if (isset($skel["data_template"][$data_template_id])) { if (!api_data_source_save($create_info["data_source"][$data_template_id], $skel["data_template"][$data_template_id])) { log_save("Problems updating new data source [ID#" . $create_info["data_source"][$data_template_id] . "], data template [ID#{$data_template_id}] from user data", SEV_ERROR); } } if (isset($skel["data_template_item"][$data_template_id])) { foreach ($skel["data_template_item"][$data_template_id] as $data_source_item_id => $data_template_item_array) { if (!api_data_source_item_save($data_source_item_id, $data_template_item_array)) { log_save("Problems updating new data source [item] [ID#" . $create_info["data_source"][$data_template_id] . "], data template [ID#{$data_template_id}] from user data", SEV_ERROR); } } } if (isset($skel["custom_data"][$data_template_id])) { if (!api_data_source_fields_save($create_info["data_source"][$data_template_id], $skel["custom_data"][$data_template_id])) { log_save("Problems updating new data source (fields) [ID#" . $create_info["data_source"][$data_template_id] . "], data template [ID#{$data_template_id}] from user data", SEV_ERROR); } } /* update the title cache */ api_data_source_title_cache_update($create_info["data_source"][$data_template_id]); /* update poller cache */ update_poller_cache($create_info["data_source"][$data_template_id]); } /* update user specified data: graph-specific fields */ foreach (array_keys($create_info["graph"]) as $graph_template_id) { if (isset($skel["graph_template"][$graph_template_id])) { if (!api_graph_save($create_info["graph"][$graph_template_id], $skel["graph_template"][$graph_template_id])) { log_save("Problems updating new graph [ID#" . $create_info["graph"][$graph_template_id] . "], graph template [ID#{$graph_template_id}] from user data", SEV_ERROR); } } if (isset($skel["graph_template_item"][$graph_template_id])) { foreach ($skel["graph_template_item"][$graph_template_id] as $graph_template_item_input_id => $value) { if (!api_graph_template_item_input_propagate($graph_template_item_input_id, $value)) { log_save("Problems updating new graph [item] [ID#" . $create_info["graph"][$graph_template_id] . "], graph template [ID#{$graph_template_id}] from user data", SEV_ERROR); } } } /* update the title cache */ api_graph_title_cache_update($create_info["graph"][$graph_template_id]); } debug_log_insert("new_graphs", _("Created graph: ") . api_graph_title_get($create_info["graph"][$skel["graph_template_id"]])); } /* lastly push host-specific information to our data sources */ //push_out_host($_POST["host_id"], 0); } }
function form_save() { if ($_POST["action_post"] == "data_template_edit") { $data_input_fields = array(); $data_template_item_fields = array(); $suggested_value_fields = array(); $rra_item_fields = array(); /* cache all post field values */ init_post_field_cache(); reset($_POST); /* step #1: field parsing */ while (list($name, $value) = each($_POST)) { if (substr($name, 0, 4) == "dsi|") { $matches = explode("|", $name); $data_template_item_fields[$matches[2]][$matches[1]] = $value; } else { if (substr($name, 0, 4) == "dif_") { $field_name = substr($name, 4); $data_input_fields[$field_name]["value"] = $value; if (isset($_POST["t_dif_{$field_name}"])) { $data_input_fields[$field_name]["t_value"] = html_boolean($_POST["t_dif_{$field_name}"]); } else { $data_input_fields[$field_name]["t_value"] = "0"; } } else { if (substr($name, 0, 3) == "sv|") { $matches = explode("|", $name); $suggested_value_fields[$matches[1]][] = array("id" => $matches[2], "value" => $value); } else { if (substr($name, 0, 5) == "rrai|") { $matches = explode("|", $name); $rra_item_fields[$matches[2]][$matches[1]] = $value; } } } } } /* step #2: field validation */ $form_data_template["template_name"] = $_POST["template_name"]; $form_data_source["data_input_type"] = $_POST["data_input_type"]; $form_data_source["t_name"] = html_boolean(isset($_POST["t_name"]) ? $_POST["t_name"] : ""); $form_data_source["active"] = html_boolean(isset($_POST["active"]) ? $_POST["active"] : ""); $form_data_source["t_active"] = html_boolean(isset($_POST["t_active"]) ? $_POST["t_active"] : ""); $form_data_source["polling_interval"] = isset($_POST["polling_interval"]) ? $_POST["polling_interval"] : ""; $form_data_source["t_polling_interval"] = html_boolean(isset($_POST["t_polling_interval"]) ? $_POST["t_polling_interval"] : ""); field_register_error(api_data_source_fields_validate($form_data_source, $suggested_value_fields, "|field|", "sv||field|||id|")); field_register_error(api_data_source_input_fields_validate($data_input_fields, "|field|")); field_register_error(api_data_template_fields_validate($form_data_template, "|field|")); foreach ($data_template_item_fields as $data_template_item_id => $fields) { $form_data_source_item[$data_template_item_id]["t_rrd_maximum"] = html_boolean(isset($fields["t_rrd_maximum"]) ? $fields["t_rrd_maximum"] : ""); $form_data_source_item[$data_template_item_id]["rrd_maximum"] = isset($fields["rrd_maximum"]) ? $fields["rrd_maximum"] : ""; $form_data_source_item[$data_template_item_id]["t_rrd_minimum"] = html_boolean(isset($fields["t_rrd_minimum"]) ? $fields["t_rrd_minimum"] : ""); $form_data_source_item[$data_template_item_id]["rrd_minimum"] = isset($fields["rrd_minimum"]) ? $fields["rrd_minimum"] : ""; $form_data_source_item[$data_template_item_id]["t_rrd_heartbeat"] = html_boolean(isset($fields["t_rrd_heartbeat"]) ? $fields["t_rrd_heartbeat"] : ""); $form_data_source_item[$data_template_item_id]["rrd_heartbeat"] = isset($fields["rrd_heartbeat"]) ? $fields["rrd_heartbeat"] : ""; $form_data_source_item[$data_template_item_id]["t_data_source_type"] = html_boolean(isset($fields["t_data_source_type"]) ? $fields["t_data_source_type"] : ""); $form_data_source_item[$data_template_item_id]["data_source_type"] = $fields["data_source_type"]; $form_data_source_item[$data_template_item_id]["data_source_name"] = $fields["data_source_name"]; $form_data_source_item[$data_template_item_id]["field_input_value"] = isset($fields["field_input_value"]) ? $fields["field_input_value"] : ""; api_data_source_item_fields_validate($form_data_source_item[$data_template_item_id], "dsi||field|||id|"); } /* step #3: field save */ if (!is_error_message()) { $data_template_id = api_data_template_save($_POST["data_template_id"], $form_data_template + $form_data_source); if ($data_template_id) { /* copy down the selected rra preset into the data template if a preset is selected */ api_data_template_rra_item_clear($data_template_id); api_data_template_preset_rra_item_copy($data_template_id, $_POST["preset_rra_id"]); /* save suggested values (for the 'name' field) */ api_data_template_suggested_values_save($data_template_id, $suggested_value_fields); /* save custom data input data */ api_data_template_input_fields_save($data_template_id, $data_input_fields); /* save each data template item on the form */ foreach (array_keys($data_template_item_fields) as $data_template_item_id) { $form_data_source_item[$data_template_item_id]["data_template_id"] = $data_template_id; $data_template_item_id = api_data_template_item_save($data_template_item_id, $form_data_source_item[$data_template_item_id]); if (!$data_template_item_id) { raise_message(2); } } } else { raise_message(2); } } if (is_error_message()) { if (isset($_POST["redirect_item_add"])) { $action = "item_add"; } else { $action = "edit"; } header("Location: data_templates.php?action={$action}" . (empty($data_template_id) ? "&id=" . $_POST["data_template_id"] : "&id={$data_template_id}") . (isset($_POST["data_input_type"]) ? "&data_input_type=" . $_POST["data_input_type"] : "") . (isset($_POST["dif_script_id"]) ? "&script_id=" . $_POST["dif_script_id"] : "") . (isset($_POST["dif_data_query_id"]) ? "&data_query_id=" . $_POST["dif_data_query_id"] : "")); } else { raise_message(1); header("Location: data_templates.php"); } /* submit button on the actions area page */ } else { if ($_POST["action_post"] == "box-1") { $selected_rows = explode(":", $_POST["box-1-action-area-selected-rows"]); if ($_POST["box-1-action-area-type"] == "remove") { foreach ($selected_rows as $data_template_id) { api_data_template_remove($data_template_id); } } else { if ($_POST["box-1-action-area-type"] == "duplicate") { // yet yet coded } } header("Location: data_templates.php"); /* 'filter' area at the bottom of the box */ } else { if ($_POST["action_post"] == "data_template_list") { $get_string = ""; /* the 'clear' button wasn't pressed, so we should filter */ if (!isset($_POST["box-1-action-clear-button"])) { if (trim($_POST["box-1-search_filter"]) != "") { $get_string = ($get_string == "" ? "?" : "&") . "search_filter=" . urlencode($_POST["box-1-search_filter"]); } } header("Location: data_templates.php{$get_string}"); } } } }
function form_save() { if ($_POST["action_post"] == "graph_edit") { /* fetch some cache variables */ if (empty($_POST["id"])) { $_graph_template_id = 0; } else { $_graph_template_id = db_fetch_cell("select graph_template_id from graph where id=" . $_POST["id"]); } /* cache all post field values */ init_post_field_cache(); $form_graph_fields = array(); $form_graph_item_fields = array(); /* parse out form values that we care about */ reset($_POST); while (list($name, $value) = each($_POST)) { if (substr($name, 0, 2) == "g|") { $matches = explode("|", $name); $form_graph_fields[$matches[1]] = $value; } else { if (substr($name, 0, 4) == "gip|") { $matches = explode("|", $name); $form_graph_item_fields[$matches[2]] = $value; } } } /* make a list of fields to save */ while (list($_field_name, $_field_value) = each($form_graph_fields)) { /* make sure that we know about this field */ if (isset($fields_graph[$_field_name])) { $save_graph[$_field_name] = $_field_value; } } /* add any unchecked checkbox fields */ $form_graph_fields += field_register_html_checkboxes(api_graph_form_list(), "g||field|"); $form_graph_fields["host_id"] = $_POST["host_id"]; $form_graph_fields["graph_template_id"] = $_POST["graph_template_id"]; /* step #2: field validation */ $suggested_value_fields = array(); /* placeholder */ field_register_error(api_graph_fields_validate($form_graph_fields, $suggested_value_fields, "g||field|", "")); /* step #3: field save */ if (is_error_message()) { log_save("User input validation error for graph [ID#" . $_POST["id"] . "]", SEV_DEBUG); } else { /* save graph data */ if (!api_graph_save($_POST["id"], $form_graph_fields)) { log_save("Save error for graph [ID#" . $_POST["id"] . "]", SEV_ERROR); } /* save graph item data for templated graphs */ if (!empty($_graph_template_id)) { if (sizeof($form_graph_item_fields) > 0) { foreach ($form_graph_item_fields as $graph_template_item_input_id => $value) { if (!api_graph_template_item_input_propagate($graph_template_item_input_id, $value)) { log_save("Save error when propagating graph item input [ID#{$graph_template_item_input_id}] to graph [ID#" . $_POST["id"] . "]", SEV_ERROR); } } } } } if (is_error_message() || $_POST["graph_template_id"] != $_graph_template_id) { header("Location: graphs.php?action=edit&id=" . $_POST["id"] . (!isset($_POST["host_id"]) ? "" : "&host_id=" . $_POST["host_id"]) . (!isset($_POST["graph_template_id"]) ? "" : "&graph_template_id=" . $_POST["graph_template_id"])); } else { header("Location: graphs.php"); } /* submit button on the actions area page */ } else { if ($_POST["action_post"] == "box-1") { $selected_rows = explode(":", $_POST["box-1-action-area-selected-rows"]); if ($_POST["box-1-action-area-type"] == "search") { $get_string = ""; if ($_POST["box-1-search_device"] != "-1") { $get_string .= ($get_string == "" ? "?" : "&") . "search_device=" . urlencode($_POST["box-1-search_device"]); } if (trim($_POST["box-1-search_filter"]) != "") { $get_string .= ($get_string == "" ? "?" : "&") . "search_filter=" . urlencode($_POST["box-1-search_filter"]); } header("Location: graphs.php{$get_string}"); } else { if ($_POST["box-1-action-area-type"] == "remove") { foreach ($selected_rows as $graph_id) { api_graph_remove($graph_id); } } else { if ($_POST["box-1-action-area-type"] == "duplicate") { // not yet coded } else { if ($_POST["box-1-action-area-type"] == "change_graph_template") { // note yet coded } else { if ($_POST["box-1-action-area-type"] == "change_host") { foreach ($selected_rows as $graph_id) { api_graph_host_update($graph_id, $_POST["box-1-change_device"]); } } else { if ($_POST["box-1-action-area-type"] == "convert_graph_template") { // note yet coded } else { if ($_POST["box-1-action-area-type"] == "place_tree") { // note yet coded } } } } } } } header("Location: graphs.php"); /* 'filter' area at the bottom of the box */ } else { if ($_POST["action_post"] == "graph_list") { $get_string = ""; /* the 'clear' button wasn't pressed, so we should filter */ if (!isset($_POST["box-1-action-clear-button"])) { if (trim($_POST["box-1-search_filter"]) != "") { $get_string = ($get_string == "" ? "?" : "&") . "search_filter=" . urlencode($_POST["box-1-search_filter"]); } } header("Location: graphs.php{$get_string}"); } } } }
function form_save() { if (isset($_POST["save_data_query_x"])) { /* cache all post field values */ init_post_field_cache(); /* step #2: field validation */ $form_data_query["id"] = $_POST["data_query_id"]; $form_data_query["input_type"] = $_POST["input_type"]; $form_data_query["name"] = $_POST["name"]; $form_data_query["index_order_type"] = $_POST["index_order_type"]; $form_data_query["index_title_format"] = $_POST["index_title_format"]; /* these fields are only displayed when editing a data query field */ if (!empty($_POST["data_query_id"])) { $form_data_query["index_order"] = $_POST["index_order"]; $form_data_query["index_field_id"] = $_POST["index_field_id"]; } if ($form_data_query["input_type"] == DATA_QUERY_INPUT_TYPE_SNMP_QUERY) { $form_data_query["snmp_oid_num_rows"] = $_POST["snmp_oid_num_rows"]; } if ($form_data_query["input_type"] == DATA_QUERY_INPUT_TYPE_SCRIPT_QUERY || $form_data_query["input_type"] == DATA_QUERY_INPUT_TYPE_PHP_SCRIPT_SERVER_QUERY) { $form_data_query["script_path"] = $_POST["script_path"]; } if ($form_data_query["input_type"] == DATA_QUERY_INPUT_TYPE_PHP_SCRIPT_SERVER_QUERY) { $form_data_query["script_server_function"] = $_POST["script_server_function"]; } field_register_error(validate_data_query_fields($form_data_query, "|field|")); /* step #3: field save */ $data_query_id = false; if (is_error_message()) { log_save("User input validation error for data query [ID#" . $_POST["data_query_id"] . "]", SEV_DEBUG); } else { $data_query_id = api_data_query_save($_POST["data_query_id"], $form_data_query); if ($data_query_id === false) { log_save("Save error for data query [ID#" . $_POST["data_query_id"] . "]", SEV_ERROR); } } if ($data_query_id === false) { header("Location: data_queries.php?action=edit" . (empty($_POST["data_query_id"]) ? "" : "&id=" . $_POST["data_query_id"])); } else { if (empty($_POST["data_query_id"])) { header("Location: data_queries.php?action=edit&id={$data_query_id}"); } else { header("Location: data_queries.php"); } } } else { if (isset($_POST["save_data_query_field_x"])) { /* cache all post field values */ init_post_field_cache(); /* step #2: field validation */ $form_data_query["id"] = $_POST["data_query_field_id"]; $form_data_query["data_query_id"] = $_POST["data_query_id"]; $form_data_query["type"] = $_POST["field_type"]; $form_data_query["name"] = $_POST["name"]; $form_data_query["name_desc"] = $_POST["name_desc"]; $form_data_query["source"] = $_POST["source"]; /* determine the correct values for the method type/value fields */ if (isset($_POST["method_group"])) { /* value */ if ($_POST["method_group"] == DATA_QUERY_FIELD_METHOD_GROUP_VALUE) { $form_data_query["method_type"] = $_POST["method_type_v"]; if ($_POST["method_type_v"] == DATA_QUERY_FIELD_METHOD_VALUE_PARSE) { $form_data_query["method_value"] = $_POST["method_value_v_parse"]; } /* snmp oid */ } else { if ($_POST["method_group"] == DATA_QUERY_FIELD_METHOD_GROUP_OID) { $form_data_query["method_type"] = $_POST["method_type_s"]; if ($_POST["method_type_s"] == DATA_QUERY_FIELD_METHOD_OID_OCTET) { $form_data_query["method_value"] = $_POST["method_value_s_octet"]; } else { if ($_POST["method_type_s"] == DATA_QUERY_FIELD_METHOD_OID_PARSE) { $form_data_query["method_value"] = $_POST["method_value_s_parse"]; } } } } } field_register_error(validate_data_query_field_fields($form_data_query, "|field|")); /* since the 'method_value' field name is abstracted above, we need to pass any input field errors * on to the correct form field */ if (isset($_SESSION["sess_error_fields"]["method_value"]) && $_POST["method_group"] == DATA_QUERY_FIELD_METHOD_GROUP_VALUE && $_POST["method_type_v"] == DATA_QUERY_FIELD_METHOD_VALUE_PARSE) { $_SESSION["sess_error_fields"]["method_value_v_parse"] = 1; } else { if (isset($_SESSION["sess_error_fields"]["method_value"]) && $_POST["method_group"] == DATA_QUERY_FIELD_METHOD_GROUP_OID && $_POST["method_type_s"] == DATA_QUERY_FIELD_METHOD_OID_OCTET) { $_SESSION["sess_error_fields"]["method_value_s_octet"] = 1; } else { if (isset($_SESSION["sess_error_fields"]["method_value"]) && $_POST["method_group"] == DATA_QUERY_FIELD_METHOD_GROUP_OID && $_POST["method_type_s"] == DATA_QUERY_FIELD_METHOD_OID_PARSE) { $_SESSION["sess_error_fields"]["method_value_s_parse"] = 1; } } } /* step #3: field save */ $data_query_field_id = false; if (is_error_message()) { log_save("User input validation error for data query field [ID#" . $_POST["data_query_field_id"] . "], data query [ID#" . $_POST["data_query_id"] . "]", SEV_DEBUG); } else { $data_query_field_id = api_data_query_field_save($_POST["data_query_field_id"], $form_data_query); if ($data_query_field_id === false) { log_save("Save error for data query field [ID#" . $_POST["data_query_field_id"] . "], data query [ID#" . $_POST["data_query_id"] . "]", SEV_ERROR); } } if ($data_query_field_id === false) { header("Location: data_queries.php?action=field_edit" . (empty($_POST["data_query_field_id"]) ? "" : "&id=" . $_POST["data_query_field_id"]) . "&data_query_id=" . $_POST["data_query_id"]); } else { header("Location: data_queries.php?action=edit&id=" . $_POST["data_query_id"]); } } else { if (isset($_POST["box-1-action-area-button"])) { $selected_rows = explode(":", $_POST["box-1-action-area-selected-rows"]); if ($_POST["box-1-action-area-type"] == "remove") { foreach ($selected_rows as $data_query_id) { api_data_query_remove($data_query_id); } } header("Location: data_queries.php"); } } } }
function form_post() { if ($_POST["action_post"] == "device_edit") { /* the "Add" assigned package button was pressed */ if (isset($_POST["assoc_package_add_y"])) { api_device_package_add($_POST["id"], $_POST["assoc_package_id"]); header("Location: devices.php?action=edit&id=" . $_POST["id"]); exit; } /* cache all post field values */ init_post_field_cache(); /* field validation */ $form_device["id"] = $_POST["id"]; $form_device["description"] = $_POST["description"]; $form_device["hostname"] = $_POST["hostname"]; $form_device["host_template_id"] = $_POST["host_template_id"]; $form_device["poller_id"] = $_POST["poller_id"]; $form_device["disabled"] = html_boolean(isset($_POST["disabled"]) ? $_POST["disabled"] : ""); $form_device["snmp_version"] = $_POST["snmp_version"]; $form_device["snmp_community"] = $_POST["snmp_community"]; $form_device["snmp_port"] = $_POST["snmp_port"]; $form_device["snmp_timeout"] = $_POST["snmp_timeout"]; $form_device["snmpv3_auth_username"] = $_POST["snmpv3_auth_username"]; $form_device["snmpv3_auth_password"] = $_POST["snmpv3_auth_password"]; $form_device["snmpv3_auth_protocol"] = $_POST["snmpv3_auth_protocol"]; $form_device["snmpv3_priv_passphrase"] = $_POST["snmpv3_priv_passphrase"]; $form_device["snmpv3_priv_protocol"] = $_POST["snmpv3_priv_protocol"]; field_register_error(api_device_field_validate($form_device, "|field|")); /* field save */ $device_id = false; if (is_error_message()) { log_save("User input validation error for device [ID#" . $_POST["id"] . "]", SEV_DEBUG); } else { $device_id = api_device_save($_POST["id"], $form_device); if ($device_id === false) { log_save("Save error for device [ID#" . $_POST["id"] . "]", SEV_ERROR); } } if ($device_id === false || empty($_POST["id"])) { header("Location: devices.php?action=edit" . (empty($_POST["id"]) ? "" : "&id=" . $_POST["id"])); } else { header("Location: devices.php"); } /* submit button on the actions area page */ } else { if ($_POST["action_post"] == "box-1") { $selected_rows = explode(":", $_POST["box-1-action-area-selected-rows"]); if ($_POST["box-1-action-area-type"] == "search") { $get_string = ""; if ($_POST["box-1-search_device_template"] != "-1") { $get_string .= ($get_string == "" ? "?" : "&") . "search_device_template=" . urlencode($_POST["box-1-search_device_template"]); } if ($_POST["box-1-search_status"] != "-1") { $get_string .= ($get_string == "" ? "?" : "&") . "search_status=" . urlencode($_POST["box-1-search_status"]); } if (trim($_POST["box-1-search_filter"]) != "") { $get_string .= ($get_string == "" ? "?" : "&") . "search_filter=" . urlencode($_POST["box-1-search_filter"]); } header("Location: devices.php{$get_string}"); exit; } else { if ($_POST["box-1-action-area-type"] == "remove") { foreach ($selected_rows as $host_id) { api_device_remove($host_id, $_POST["box-1-remove_type"] == "2" ? true : false); } } else { if ($_POST["box-1-action-area-type"] == "enable") { foreach ($selected_rows as $host_id) { api_device_enable($host_id); } } else { if ($_POST["box-1-action-area-type"] == "disable") { foreach ($selected_rows as $host_id) { api_device_disable($host_id); } } else { if ($_POST["box-1-action-area-type"] == "clear_stats") { foreach ($selected_rows as $host_id) { api_device_statistics_clear($host_id); } } else { if ($_POST["box-1-action-area-type"] == "change_snmp_opts") { // not yet implemented } else { if ($_POST["box-1-action-area-type"] == "change_avail_opts") { // not yet implemented } else { if ($_POST["box-1-action-area-type"] == "change_poller") { // not yet implemented } } } } } } } } header("Location: devices.php"); /* 'filter' area at the bottom of the box */ } else { if ($_POST["action_post"] == "device_list") { $get_string = ""; /* the 'clear' button wasn't pressed, so we should filter */ if (!isset($_POST["box-1-action-clear-button"])) { if (trim($_POST["box-1-search_filter"]) != "") { $get_string = ($get_string == "" ? "?" : "&") . "search_filter=" . urlencode($_POST["box-1-search_filter"]); } } header("Location: devices.php{$get_string}"); } } } }
function form_save() { if ($_POST["action_post"] == "rra_preset_edit") { $rra_item_fields = array(); /* cache all post field values */ init_post_field_cache(); /* parse form fields into manageable arrays */ foreach ($_POST as $name => $value) { if (substr($name, 0, 5) == "rrai|") { $matches = explode("|", $name); $rra_item_fields{$matches[2]}{$matches[1]} = $value; } } $form_rra["name"] = $_POST["name"]; /* validate base rra preset fields */ field_register_error(api_data_preset_rra_field_validate($form_rra, "|field|")); foreach ($rra_item_fields as $rra_item_id => $fields) { /* obtain a list of visible rra item fields on the form */ $visible_fields = api_data_preset_rra_item_visible_field_list($fields["consolidation_function"]); /* all non-visible fields on the form should be discarded */ foreach ($visible_fields as $field_name) { $form_rra_item[$rra_item_id][$field_name] = $fields[$field_name]; } /* validate rra item preset fields */ field_register_error(api_data_preset_rra_item_field_validate($form_rra_item[$rra_item_id], "rrai||field||$rra_item_id")); } if (!is_error_message()) { $preset_rra_id = api_data_preset_rra_save($_POST["preset_rra_id"], $form_rra); if ($preset_rra_id) { /* save each rra item on the form */ foreach (array_keys($rra_item_fields) as $rra_item_id) { $form_rra_item[$rra_item_id]["preset_rra_id"] = $_POST["preset_rra_id"]; $preset_rra_item_id = api_data_preset_rra_item_save($rra_item_id, $form_rra_item[$rra_item_id]); if (!$preset_rra_item_id) { raise_message(2); } } }else{ raise_message(2); } } if ((is_error_message()) || (empty($_POST["preset_rra_id"]))) { header("Location: presets_rra.php?action=edit" . (empty($preset_rra_id) ? "" : "&id=$preset_rra_id")); }else{ header("Location: presets.php?action=view_rra"); } }else if (isset($_POST["box-1-action-area-button"])) { $selected_rows = explode(":", $_POST["box-1-action-area-selected-rows"]); if ($_POST["box-1-action-area-type"] == "remove") { foreach ($selected_rows as $preset_rra_id) { api_data_preset_rra_remove($preset_rra_id); } } header("Location: presets.php?action=view_rra"); } }
function form_save() { if ($_POST["action_post"] == "graph_template_edit") { $suggested_value_fields = array(); /* cache all post field values */ init_post_field_cache(); reset($_POST); /* step #1: field parsing */ while (list($name, $value) = each($_POST)) { if (substr($name, 0, 3) == "sv|") { $matches = explode("|", $name); $suggested_value_fields[$matches[1]][] = array("id" => $matches[2], "value" => $value); } } /* step #2: field validation */ $form_graph_template["template_name"] = $_POST["template_name"]; $form_graph["t_title"] = html_boolean(isset($_POST["t_title"]) ? $_POST["t_title"] : ""); $form_graph["vertical_label"] = $_POST["vertical_label"]; $form_graph["t_vertical_label"] = html_boolean(isset($_POST["t_vertical_label"]) ? $_POST["t_vertical_label"] : ""); $form_graph["image_format"] = $_POST["image_format"]; $form_graph["t_image_format"] = html_boolean(isset($_POST["t_image_format"]) ? $_POST["t_image_format"] : ""); $form_graph["export"] = html_boolean(isset($_POST["export"]) ? $_POST["export"] : ""); $form_graph["t_export"] = html_boolean(isset($_POST["t_export"]) ? $_POST["t_export"] : ""); $form_graph["force_rules_legend"] = html_boolean(isset($_POST["force_rules_legend"]) ? $_POST["force_rules_legend"] : ""); $form_graph["t_force_rules_legend"] = html_boolean(isset($_POST["t_force_rules_legend"]) ? $_POST["t_force_rules_legend"] : ""); $form_graph["height"] = $_POST["height"]; $form_graph["t_height"] = html_boolean(isset($_POST["t_height"]) ? $_POST["t_height"] : ""); $form_graph["width"] = $_POST["width"]; $form_graph["t_width"] = html_boolean(isset($_POST["t_width"]) ? $_POST["t_width"] : ""); $form_graph["x_grid"] = $_POST["x_grid"]; $form_graph["t_x_grid"] = html_boolean(isset($_POST["t_x_grid"]) ? $_POST["t_x_grid"] : ""); $form_graph["y_grid"] = $_POST["y_grid"]; $form_graph["t_y_grid"] = html_boolean(isset($_POST["t_y_grid"]) ? $_POST["t_y_grid"] : ""); $form_graph["y_grid_alt"] = html_boolean(isset($_POST["y_grid_alt"]) ? $_POST["y_grid_alt"] : ""); $form_graph["t_y_grid_alt"] = html_boolean(isset($_POST["t_y_grid_alt"]) ? $_POST["t_y_grid_alt"] : ""); $form_graph["no_minor"] = html_boolean(isset($_POST["no_minor"]) ? $_POST["no_minor"] : ""); $form_graph["t_no_minor"] = html_boolean(isset($_POST["t_no_minor"]) ? $_POST["t_no_minor"] : ""); $form_graph["auto_scale"] = html_boolean(isset($_POST["auto_scale"]) ? $_POST["auto_scale"] : ""); $form_graph["t_auto_scale"] = html_boolean(isset($_POST["t_auto_scale"]) ? $_POST["t_auto_scale"] : ""); $form_graph["auto_scale_opts"] = $_POST["auto_scale_opts"]; $form_graph["t_auto_scale_opts"] = html_boolean(isset($_POST["t_auto_scale_opts"]) ? $_POST["t_auto_scale_opts"] : ""); $form_graph["auto_scale_log"] = html_boolean(isset($_POST["auto_scale_log"]) ? $_POST["auto_scale_log"] : ""); $form_graph["t_auto_scale_log"] = html_boolean(isset($_POST["t_auto_scale_log"]) ? $_POST["t_auto_scale_log"] : ""); $form_graph["auto_scale_rigid"] = html_boolean(isset($_POST["auto_scale_rigid"]) ? $_POST["auto_scale_rigid"] : ""); $form_graph["t_auto_scale_rigid"] = html_boolean(isset($_POST["t_auto_scale_rigid"]) ? $_POST["t_auto_scale_rigid"] : ""); $form_graph["auto_padding"] = html_boolean(isset($_POST["auto_padding"]) ? $_POST["auto_padding"] : ""); $form_graph["t_auto_padding"] = html_boolean(isset($_POST["t_auto_padding"]) ? $_POST["t_auto_padding"] : ""); $form_graph["upper_limit"] = $_POST["upper_limit"]; $form_graph["t_upper_limit"] = html_boolean(isset($_POST["t_upper_limit"]) ? $_POST["t_upper_limit"] : ""); $form_graph["lower_limit"] = $_POST["lower_limit"]; $form_graph["t_lower_limit"] = html_boolean(isset($_POST["t_lower_limit"]) ? $_POST["t_lower_limit"] : ""); $form_graph["base_value"] = $_POST["base_value"]; $form_graph["t_base_value"] = html_boolean(isset($_POST["t_base_value"]) ? $_POST["t_base_value"] : ""); $form_graph["unit_value"] = $_POST["unit_value"]; $form_graph["t_unit_value"] = html_boolean(isset($_POST["t_unit_value"]) ? $_POST["t_unit_value"] : ""); $form_graph["unit_length"] = $_POST["unit_length"]; $form_graph["t_unit_length"] = html_boolean(isset($_POST["t_unit_length"]) ? $_POST["t_unit_length"] : ""); $form_graph["unit_exponent_value"] = $_POST["unit_exponent_value"]; $form_graph["t_unit_exponent_value"] = html_boolean(isset($_POST["t_unit_exponent_value"]) ? $_POST["t_unit_exponent_value"] : ""); field_register_error(api_graph_template_fields_validate($form_graph_template, "|field|")); field_register_error(api_graph_fields_validate($form_graph, $suggested_value_fields, "|field|", "sv||field|||id|")); /* step #3: field save */ if (!is_error_message()) { $graph_template_id = api_graph_template_save($_POST["graph_template_id"], $form_graph_template + $form_graph); if ($graph_template_id) { api_graph_template_suggested_values_save($graph_template_id, $suggested_value_fields); } } if (is_error_message() || empty($graph_template_id) || empty($_POST["graph_template_id"])) { if (isset($_POST["redirect_sv_add"])) { $action = "sv_add"; } else { $action = "edit"; } header("Location: graph_templates.php?action={$action}" . (empty($graph_template_id) ? "" : "&id={$graph_template_id}")); } /* submit button on the actions area page */ } else { if ($_POST["action_post"] == "box-1") { $selected_rows = explode(":", $_POST["box-1-action-area-selected-rows"]); if ($_POST["box-1-action-area-type"] == "remove") { foreach ($selected_rows as $graph_template_id) { api_graph_template_remove($graph_template_id); } } else { if ($_POST["box-1-action-area-type"] == "duplicate") { // yet yet coded } } header("Location: graph_templates.php"); /* 'filter' area at the bottom of the box */ } else { if ($_POST["action_post"] == "graph_template_list") { $get_string = ""; /* the 'clear' button wasn't pressed, so we should filter */ if (!isset($_POST["box-1-action-clear-button"])) { if (trim($_POST["box-1-search_filter"]) != "") { $get_string = ($get_string == "" ? "?" : "&") . "search_filter=" . urlencode($_POST["box-1-search_filter"]); } } header("Location: graph_templates.php{$get_string}"); } } } }
function form_post() { if ($_POST["action_post"] == "data_source_add") { if (!empty($_POST["data_template_id"])) { $data_source_id = copy_data_template_to_data_source($_POST["data_template_id"], $_POST["host_id"]); if ($data_source_id) { api_data_source_title_cache_update($data_source_id); } else { log_save("Error pushing data template [ID#" . $_POST["data_template_id"] . "] down to a data source.", SEV_ERROR); } } header("Location: data_sources.php?action=edit" . (empty($data_source_id) ? "" : "&id={$data_source_id}") . (!isset($_POST["host_id"]) ? "" : "&host_id=" . $_POST["host_id"]) . (!isset($_POST["data_template_id"]) ? "" : "&data_template_id=" . $_POST["data_template_id"])); } else { if ($_POST["action_post"] == "data_source_edit") { /* fetch some cache variables */ if (empty($_POST["data_source_id"])) { $_data_template_id = 0; } else { $_data_template_id = db_fetch_cell("select data_template_id from data_source where id = " . $_POST["data_source_id"]); } /* cache all post field values */ init_post_field_cache(); $data_source_fields = array(); $data_source_item_fields = array(); $data_input_fields = array(); $rra_item_fields = array(); /* parse out form values that we care about (data source / data source item fields) */ reset($_POST); while (list($name, $value) = each($_POST)) { if (substr($name, 0, 4) == "dsi|") { $matches = explode("|", $name); $data_source_item_fields[$matches[2]][$matches[1]] = $value; } else { if (substr($name, 0, 4) == "dif_") { $data_input_fields[substr($name, 4)] = $value; } else { if (substr($name, 0, 3) == "ds|") { $matches = explode("|", $name); $data_source_fields[$matches[1]] = $value; } else { if (substr($name, 0, 5) == "rrai|") { $matches = explode("|", $name); $rra_item_fields[$matches[2]][$matches[1]] = $value; } } } } } /* add any unchecked checkbox fields */ $data_source_fields += field_register_html_checkboxes(api_data_source_form_list(), "ds||field|"); /* step #2: field validation */ $suggested_value_fields = array(); /* placeholder */ field_register_error(api_data_source_fields_validate($data_source_fields, $suggested_value_fields, "ds||field|", "")); field_register_error(api_data_source_input_fields_validate($data_input_fields, "dif_|field|")); foreach ($data_source_item_fields as $data_source_item_id => $data_source_item) { field_register_error(api_data_source_item_fields_validate($data_source_item, "dsi||field||{$data_source_item_id}")); } /* step #3: field save */ if (is_error_message()) { log_save("User input validation error for data source [ID#" . $_POST["data_source_id"] . "]", SEV_DEBUG); } else { /* save data source data */ $data_source_id = api_data_source_save($_POST["data_source_id"], $data_source_fields); if ($data_source_id) { /* treat this as a regular form with rra presets if there is no template selected */ if (empty($_data_template_id)) { if (isset($_POST["preset_rra_id"])) { /* copy down the selected rra preset into the data template if a preset is selected */ api_data_source_rra_item_clear($data_source_id); /* copy down associated rra items from the preset */ api_data_source_preset_rra_item_copy($data_source_id, $_POST["preset_rra_id"]); } /* rra items for templated forms ALWAYS come from the template */ } else { /* ONLY copy down rra items from the template if the data source is new */ if (empty($_POST["data_source_id"])) { if (!api_data_source_data_template_rra_item_copy($data_source_id, $_POST["data_template_id"])) { log_save("Copy error for data template [ID#" . $_POST["data_template_id"] . "], data source [ID#" . $data_source_id . "]", SEV_ERROR); } } } /* save data source input fields */ if (!api_data_source_fields_save($data_source_id, $data_input_fields)) { log_save("Save error for data input fields, data source [ID#" . $data_source_id . "]", SEV_ERROR); } /* save data source item data */ foreach ($data_source_item_fields as $data_source_item_id => $data_source_item) { /* required fields */ $data_source_item["data_source_id"] = $data_source_id; if (!api_data_source_item_save($data_source_item_id, $data_source_item)) { log_save("Save error for data source item [ID#" . $data_source_item_id . "], data source [ID#" . $data_source_id . "]", SEV_ERROR); } } } else { log_save("Save error for data source [ID#" . $_POST["data_source_id"] . "]", SEV_ERROR); } } if (is_error_message() || $_POST["data_template_id"] != $_data_template_id) { if (isset($_POST["redirect_item_add"])) { $action = "item_add"; } else { $action = "edit"; } header("Location: data_sources.php?action={$action}" . (empty($_POST["data_source_id"]) ? "" : "&id=" . $_POST["data_source_id"]) . (!isset($_POST["host_id"]) ? "" : "&host_id=" . $_POST["host_id"]) . (!isset($_POST["data_template_id"]) ? "" : "&data_template_id=" . $_POST["data_template_id"]) . (isset($_POST["data_input_type"]) ? "&data_input_type=" . $_POST["data_input_type"] : "") . (isset($_POST["dif_script_id"]) ? "&script_id=" . $_POST["dif_script_id"] : "") . (isset($_POST["dif_data_query_id"]) ? "&data_query_id=" . $_POST["dif_data_query_id"] : "")); } else { header("Location: data_sources.php"); } /* submit button on the actions area page */ } else { if ($_POST["action_post"] == "box-1") { $selected_rows = explode(":", $_POST["box-1-action-area-selected-rows"]); if ($_POST["box-1-action-area-type"] == "search") { $get_string = ""; if ($_POST["box-1-search_device"] != "-1") { $get_string .= ($get_string == "" ? "?" : "&") . "search_device=" . urlencode($_POST["box-1-search_device"]); } if (trim($_POST["box-1-search_filter"]) != "") { $get_string .= ($get_string == "" ? "?" : "&") . "search_filter=" . urlencode($_POST["box-1-search_filter"]); } header("Location: data_sources.php{$get_string}"); exit; } else { if ($_POST["box-1-action-area-type"] == "remove") { foreach ($selected_rows as $data_source_id) { api_data_source_remove($data_source_id); } } else { if ($_POST["box-1-action-area-type"] == "duplicate") { // not yet coded } else { if ($_POST["box-1-action-area-type"] == "enable") { foreach ($selected_rows as $data_source_id) { api_data_source_enable($data_source_id); } } else { if ($_POST["box-1-action-area-type"] == "disable") { foreach ($selected_rows as $data_source_id) { api_data_source_disable($data_source_id); } } else { if ($_POST["box-1-action-area-type"] == "change_data_template") { // note yet coded } else { if ($_POST["box-1-action-area-type"] == "change_host") { foreach ($selected_rows as $data_source_id) { api_data_source_host_update($data_source_id, $_POST["box-1-change_device"]); } } else { if ($_POST["box-1-action-area-type"] == "convert_data_template") { // note yet coded } } } } } } } } header("Location: data_sources.php"); /* 'filter' area at the bottom of the box */ } else { if ($_POST["action_post"] == "data_source_list") { $get_string = ""; /* the 'clear' button wasn't pressed, so we should filter */ if (!isset($_POST["box-1-action-clear-button"])) { if (trim($_POST["box-1-search_filter"]) != "") { $get_string = ($get_string == "" ? "?" : "&") . "search_filter=" . urlencode($_POST["box-1-search_filter"]); } } header("Location: data_sources.php{$get_string}"); } } } } }
$_GET = array_map('stripslashes_deep', $_GET); $_COOKIE = array_map('stripslashes_deep', $_COOKIE); } /* make sure to start only only Cacti session at a time */ if (!isset($_SESSION["cacti_cwd"])) { $_SESSION["cacti_cwd"] = CACTI_BASE_PATH; } else { if ($_SESSION["cacti_cwd"] != CACTI_BASE_PATH) { session_unset(); session_destroy(); } } /* this code handles dropdown boxes that automatically redirect the user upon select while * retaining all current form values */ if (isset($_REQUEST["cacti_js_dropdown_redirect"])) { init_post_field_cache(); header("Location: " . $_REQUEST["cacti_js_dropdown_redirect"]); exit; } } /* Variable includes -- note that the includes must fall below the session_start() call * for now because they rely on read_config_option() */ require CACTI_BASE_PATH . "/include/global_arrays.php"; require CACTI_BASE_PATH . "/include/global_settings.php"; require CACTI_BASE_PATH . "/include/global_form.php"; /* emulate 'register_globals' = 'off' if turned on */ if ((bool) ini_get("register_globals")) { $not_unset = array("_GET", "_POST", "_COOKIE", "_SERVER", "_SESSION", "_ENV", "_FILES", "database_type", "database_default", "database_hostname", "database_username", "database_password", "config", "colors"); /* Not only will array_merge give a warning if a parameter is not an array, it will * actually fail. So we check if HTTP_SESSION_VARS has been initialised. */ if (!isset($_SESSION)) {