function api_device_save($id, $host_template_id, $description, $hostname, $snmp_community, $snmp_version, $snmp_username, $snmp_password, $snmp_port, $snmp_timeout, $disabled) { /* fetch some cache variables */ if (empty($id)) { $_host_template_id = 0; } else { $_host_template_id = db_fetch_cell("select host_template_id from host where id={$id}"); } $save["id"] = $id; $save["host_template_id"] = form_input_validate($host_template_id, "host_template_id", "^[0-9]+\$", false, 3); $save["description"] = form_input_validate($description, "description", "", false, 3); $save["hostname"] = form_input_validate($hostname, "hostname", "", false, 3); $save["snmp_community"] = form_input_validate($snmp_community, "snmp_community", "", true, 3); $save["snmp_version"] = form_input_validate($snmp_version, "snmp_version", "", true, 3); $save["snmp_username"] = form_input_validate($snmp_username, "snmp_username", "", true, 3); $save["snmp_password"] = form_input_validate($snmp_password, "snmp_password", "", true, 3); $save["snmp_port"] = form_input_validate($snmp_port, "snmp_port", "^[0-9]+\$", false, 3); $save["snmp_timeout"] = form_input_validate($snmp_timeout, "snmp_timeout", "^[0-9]+\$", false, 3); $save["disabled"] = form_input_validate($disabled, "disabled", "", true, 3); $host_id = 0; if (!is_error_message()) { $host_id = sql_save($save, "host"); if ($host_id) { raise_message(1); /* push out relavant fields to data sources using this host */ push_out_host($host_id, 0); /* the host substitution cache is now stale; purge it */ kill_session_var("sess_host_cache_array"); /* update title cache for graph and data source */ update_data_source_title_cache_from_host($host_id); update_graph_title_cache_from_host($host_id); } else { raise_message(2); } /* if the user changes the host template, add each snmp query associated with it */ if ($host_template_id != $_host_template_id && !empty($host_template_id)) { $snmp_queries = db_fetch_assoc("select snmp_query_id from host_template_snmp_query where host_template_id={$host_template_id}"); if (sizeof($snmp_queries) > 0) { foreach ($snmp_queries as $snmp_query) { db_execute("replace into host_snmp_query (host_id,snmp_query_id,reindex_method) values ({$host_id}," . $snmp_query["snmp_query_id"] . "," . DATA_QUERY_AUTOINDEX_BACKWARDS_UPTIME . ")"); /* recache snmp data */ run_data_query($host_id, $snmp_query["snmp_query_id"]); } } $graph_templates = db_fetch_assoc("select graph_template_id from host_template_graph where host_template_id={$host_template_id}"); if (sizeof($graph_templates) > 0) { foreach ($graph_templates as $graph_template) { db_execute("replace into host_graph (host_id,graph_template_id) values ({$host_id}," . $graph_template["graph_template_id"] . ")"); } } } } return $host_id; }
function api_device_save($id, $host_template_id, $description, $hostname, $snmp_community, $snmp_version, $snmp_username, $snmp_password, $snmp_port, $snmp_timeout, $disabled, $availability_method, $ping_method, $ping_port, $ping_timeout, $ping_retries, $notes, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context) { /* fetch some cache variables */ if (empty($id)) { $_host_template_id = 0; }else{ $_host_template_id = db_fetch_cell("select host_template_id from host where id=$id"); } $save["id"] = $id; $save["host_template_id"] = form_input_validate($host_template_id, "host_template_id", "^[0-9]+$", false, 3); $save["description"] = form_input_validate($description, "description", "", false, 3); $save["hostname"] = form_input_validate($hostname, "hostname", "", false, 3); $save["notes"] = form_input_validate($notes, "notes", "", true, 3); $save["snmp_version"] = form_input_validate($snmp_version, "snmp_version", "", true, 3); $save["snmp_community"] = form_input_validate($snmp_community, "snmp_community", "", true, 3); $save["snmp_username"] = form_input_validate($snmp_username, "snmp_username", "", true, 3); $save["snmp_password"] = form_input_validate($snmp_password, "snmp_password", "", true, 3); $save["snmp_auth_protocol"] = form_input_validate($snmp_auth_protocol, "snmp_auth_protocol", "", true, 3); $save["snmp_priv_passphrase"] = form_input_validate($snmp_priv_passphrase, "snmp_priv_passphrase", "", true, 3); $save["snmp_priv_protocol"] = form_input_validate($snmp_priv_protocol, "snmp_priv_protocol", "", true, 3); $save["snmp_context"] = form_input_validate($snmp_context, "snmp_context", "", true, 3); $save["snmp_port"] = form_input_validate($snmp_port, "snmp_port", "^[0-9]+$", false, 3); $save["snmp_timeout"] = form_input_validate($snmp_timeout, "snmp_timeout", "^[0-9]+$", false, 3); $save["disabled"] = form_input_validate($disabled, "disabled", "", true, 3); $save["availability_method"] = form_input_validate($availability_method, "availability_method", "^[0-9]+$", false, 3); $save["ping_method"] = form_input_validate($ping_method, "ping_method", "^[0-9]+$", false, 3); $save["ping_port"] = form_input_validate($ping_port, "ping_port", "^[0-9]+$", true, 3); $save["ping_timeout"] = form_input_validate($ping_timeout, "ping_timeout", "^[0-9]+$", true, 3); $save["ping_retries"] = form_input_validate($ping_retries, "ping_retries", "^[0-9]+$", true, 3); $host_id = 0; if (!is_error_message()) { $host_id = sql_save($save, "host"); if ($host_id) { raise_message(1); /* push out relavant fields to data sources using this host */ push_out_host($host_id, 0); /* the host substitution cache is now stale; purge it */ kill_session_var("sess_host_cache_array"); /* update title cache for graph and data source */ update_data_source_title_cache_from_host($host_id); update_graph_title_cache_from_host($host_id); }else{ raise_message(2); } /* if the user changes the host template, add each snmp query associated with it */ if (($host_template_id != $_host_template_id) && (!empty($host_template_id))) { $snmp_queries = db_fetch_assoc("select snmp_query_id from host_template_snmp_query where host_template_id=$host_template_id"); if (sizeof($snmp_queries) > 0) { foreach ($snmp_queries as $snmp_query) { db_replace("host_snmp_query",array("host_id"=>$host_id,"snmp_query_id"=>$snmp_query["snmp_query_id"],"reindex_method"=>DATA_QUERY_AUTOINDEX_BACKWARDS_UPTIME),array("host_id","snmp_query_id"),true); /* recache snmp data */ run_data_query($host_id, $snmp_query["snmp_query_id"]); } } $graph_templates = db_fetch_assoc("select graph_template_id from host_template_graph where host_template_id=$host_template_id"); if (sizeof($graph_templates) > 0) { foreach ($graph_templates as $graph_template) { db_replace("host_graph",array("host_id"=>$host_id,"graph_template_id"=>$graph_template["graph_template_id"]),array("host_id","graph_template_id"),true); } } } } return $host_id; }
function form_actions() { global $colors, $device_actions, $fields_host_edit; /* if we are to save this form, instead of display it */ if (isset($_POST["selected_items"])) { $selected_items = unserialize(stripslashes($_POST["selected_items"])); if ($_POST["drp_action"] == "2") { /* Enable Selected Devices */ for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); /* ==================================================== */ db_execute("update host set disabled='' where id='" . $selected_items[$i] . "'"); /* update poller cache */ $data_sources = db_fetch_assoc("select id from data_local where host_id='" . $selected_items[$i] . "'"); if (sizeof($data_sources) > 0) { foreach ($data_sources as $data_source) { update_poller_cache($data_source["id"], false); } } } } elseif ($_POST["drp_action"] == "3") { /* Disable Selected Devices */ for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); /* ==================================================== */ db_execute("update host set disabled='on' where id='" . $selected_items[$i] . "'"); /* update poller cache */ db_execute("delete from poller_item where host_id='" . $selected_items[$i] . "'"); db_execute("delete from poller_reindex where host_id='" . $selected_items[$i] . "'"); } } elseif ($_POST["drp_action"] == "4") { /* change snmp options */ for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); /* ==================================================== */ reset($fields_host_edit); while (list($field_name, $field_array) = each($fields_host_edit)) { if (isset($_POST["t_{$field_name}"])) { db_execute("update host set {$field_name} = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'"); } } push_out_host($selected_items[$i]); } } elseif ($_POST["drp_action"] == "5") { /* Clear Statisitics for Selected Devices */ for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); /* ==================================================== */ db_execute("update host set min_time = '9.99999', max_time = '0', cur_time = '0',\tavg_time = '0',\n\t\t\t\t\t\ttotal_polls = '0', failed_polls = '0',\tavailability = '100.00'\n\t\t\t\t\t\twhere id = '" . $selected_items[$i] . "'"); } } elseif ($_POST["drp_action"] == "6") { /* change availability options */ for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); /* ==================================================== */ reset($fields_host_edit); while (list($field_name, $field_array) = each($fields_host_edit)) { if (isset($_POST["t_{$field_name}"])) { db_execute("update host set {$field_name} = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'"); } } push_out_host($selected_items[$i]); } } elseif ($_POST["drp_action"] == "1") { /* delete */ if (!isset($_POST["delete_type"])) { $_POST["delete_type"] = 2; } $data_sources_to_act_on = array(); $graphs_to_act_on = array(); $devices_to_act_on = array(); for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); /* ==================================================== */ $data_sources = db_fetch_assoc("select\n\t\t\t\t\tdata_local.id as local_data_id\n\t\t\t\t\tfrom data_local\n\t\t\t\t\twhere " . array_to_sql_or($selected_items, "data_local.host_id")); if (sizeof($data_sources) > 0) { foreach ($data_sources as $data_source) { $data_sources_to_act_on[] = $data_source["local_data_id"]; } } if ($_POST["delete_type"] == 2) { $graphs = db_fetch_assoc("select\n\t\t\t\t\t\tgraph_local.id as local_graph_id\n\t\t\t\t\t\tfrom graph_local\n\t\t\t\t\t\twhere " . array_to_sql_or($selected_items, "graph_local.host_id")); if (sizeof($graphs) > 0) { foreach ($graphs as $graph) { $graphs_to_act_on[] = $graph["local_graph_id"]; } } } $devices_to_act_on[] = $selected_items[$i]; } switch ($_POST["delete_type"]) { case '1': /* leave graphs and data_sources in place, but disable the data sources */ api_data_source_disable_multi($data_sources_to_act_on); break; case '2': /* delete graphs/data sources tied to this device */ api_data_source_remove_multi($data_sources_to_act_on); api_graph_remove_multi($graphs_to_act_on); break; } api_device_remove_multi($devices_to_act_on); } elseif (ereg("^tr_([0-9]+)\$", $_POST["drp_action"], $matches)) { /* place on tree */ for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); input_validate_input_number(get_request_var_post("tree_id")); input_validate_input_number(get_request_var_post("tree_item_id")); /* ==================================================== */ api_tree_item_save(0, $_POST["tree_id"], TREE_ITEM_TYPE_HOST, $_POST["tree_item_id"], "", 0, read_graph_config_option("default_rra_id"), $selected_items[$i], 1, 1, false); } } header("Location: host.php"); exit; } /* setup some variables */ $host_list = ""; $i = 0; /* loop through each of the host templates selected on the previous page and get more info about them */ while (list($var, $val) = each($_POST)) { if (ereg("^chk_([0-9]+)\$", $var, $matches)) { /* ================= input validation ================= */ input_validate_input_number($matches[1]); /* ==================================================== */ $host_list .= "<li>" . db_fetch_cell("select description from host where id=" . $matches[1]) . "<br>"; $host_array[$i] = $matches[1]; } $i++; } include_once "./include/top_header.php"; /* add a list of tree names to the actions dropdown */ add_tree_names_to_actions_array(); html_start_box("<strong>" . $device_actions[$_POST["drp_action"]] . "</strong>", "60%", $colors["header_panel"], "3", "center", ""); print "<form action='host.php' method='post'>\n"; if ($_POST["drp_action"] == "2") { /* Enable Devices */ print "\t<tr>\n\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>To enable the following devices, press the \"yes\" button below.</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t</td>\n\t\t\t\t</tr>"; } elseif ($_POST["drp_action"] == "3") { /* Disable Devices */ print "\t<tr>\n\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>To disable the following devices, press the \"yes\" button below.</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t</td>\n\t\t\t\t</tr>"; } elseif ($_POST["drp_action"] == "4") { /* change snmp options */ print "\t<tr>\n\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>To change SNMP parameters for the following devices, check the box next to the fields\n\t\t\t\t\tyou want to update, fill in the new value, and click \"yes\".</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t</td>\n\t\t\t\t</tr>"; $form_array = array(); while (list($field_name, $field_array) = each($fields_host_edit)) { if (ereg("^snmp_", $field_name) || $field_name == "max_oids") { $form_array += array($field_name => $fields_host_edit[$field_name]); $form_array[$field_name]["value"] = ""; $form_array[$field_name]["description"] = ""; $form_array[$field_name]["form_id"] = 0; $form_array[$field_name]["sub_checkbox"] = array("name" => "t_" . $field_name, "friendly_name" => "Update this Field", "value" => ""); } } draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => $form_array)); } elseif ($_POST["drp_action"] == "6") { /* change availability options */ print "\t<tr>\n\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>To change SNMP parameters for the following devices, check the box next to the fields\n\t\t\t\t\tyou want to update, fill in the new value, and click \"yes\".</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t</td>\n\t\t\t\t</tr>"; $form_array = array(); while (list($field_name, $field_array) = each($fields_host_edit)) { if (ereg("(availability_method|ping_method|ping_port)", $field_name)) { $form_array += array($field_name => $fields_host_edit[$field_name]); $form_array[$field_name]["value"] = ""; $form_array[$field_name]["description"] = ""; $form_array[$field_name]["form_id"] = 0; $form_array[$field_name]["sub_checkbox"] = array("name" => "t_" . $field_name, "friendly_name" => "Update this Field", "value" => ""); } } draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => $form_array)); } elseif ($_POST["drp_action"] == "5") { /* Clear Statisitics for Selected Devices */ print "\t<tr>\n\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>To clear the counters for the following devices, press the \"yes\" button below.</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t</td>\n\t\t\t\t</tr>"; } elseif ($_POST["drp_action"] == "1") { /* delete */ print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>Are you sure you want to delete the following devices?</p>\n\t\t\t\t\t<p>{$host_list}</p>"; form_radio_button("delete_type", "2", "1", "Leave all graphs and data sources untouched. Data sources will be disabled however.", "1"); print "<br>"; form_radio_button("delete_type", "2", "2", "Delete all associated <strong>graphs</strong> and <strong>data sources</strong>.", "1"); print "<br>"; print "</td></tr>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t"; } elseif (ereg("^tr_([0-9]+)\$", $_POST["drp_action"], $matches)) { /* place on tree */ print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>When you click save, the following hosts will be placed under the branch selected\n\t\t\t\t\tbelow.</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t\t<p><strong>Destination Branch:</strong><br>"; grow_dropdown_tree($matches[1], "tree_item_id", "0"); print "</p>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t<input type='hidden' name='tree_id' value='" . $matches[1] . "'>\n\n\t\t\t"; } if (!isset($host_array)) { print "<tr><td bgcolor='#" . $colors["form_alternate1"] . "'><span class='textError'>You must select at least one device.</span></td></tr>\n"; $save_html = ""; } else { $save_html = "<input type='image' src='images/button_yes.gif' alt='Save' align='absmiddle'>"; } print "\t<tr>\n\t\t\t<td colspan='2' align='right' bgcolor='#eaeaea'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($host_array) ? serialize($host_array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST["drp_action"] . "'>\n\t\t\t\t<a href='host.php'><img src='images/button_no.gif' alt='Cancel' align='absmiddle' border='0'></a>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n\t\t"; html_end_box(); include_once "./include/bottom_footer.php"; }
function push_out_host($host_id, $local_data_id = 0, $data_template_id = 0) { /* ok here's the deal: first we need to find every data source that uses this host. then we go through each of those data sources, finding each one using a data input method with "special fields". if we find one, fill it will the data here from this host */ if (!empty($data_template_id)) { $hosts = db_fetch_assoc("select host_id from data_local where data_template_id=$data_template_id group by host_id"); if (sizeof($hosts) > 0) { foreach ($hosts as $host) { push_out_host($host["host_id"]); } } } if (empty($host_id)) { return 0; } /* get all information about this host so we can write it to the data source */ $host = db_fetch_row("select * from host where id=$host_id"); $data_sources = db_fetch_assoc("select data_template_data.id, data_template_data.data_input_id, data_template_data.local_data_id, data_template_data.local_data_template_data_id from data_local,data_template_data where " . (empty($local_data_id) ? "data_local.host_id=$host_id" : "data_local.id=$local_data_id") . " and data_local.id=data_template_data.local_data_id and data_template_data.data_input_id>0"); /* loop through each matching data source */ if (sizeof($data_sources) > 0) { foreach ($data_sources as $data_source) { /* get field information from the data template */ if (!isset($template_fields{$data_source["local_data_template_data_id"]})) { $template_fields{$data_source["local_data_template_data_id"]} = db_fetch_assoc("select data_input_data.value, data_input_data.t_value, data_input_fields.id, data_input_fields.type_code from data_input_fields left join data_input_data on (data_input_fields.id=data_input_data.data_input_field_id and data_input_data.data_template_data_id=" . $data_source["local_data_template_data_id"] . ") where data_input_fields.data_input_id=" . $data_source["data_input_id"] . " and (data_input_data.t_value='' or data_input_data.t_value is null) and data_input_fields.input_output='in'"); } reset($template_fields{$data_source["local_data_template_data_id"]}); /* loop through each field contained in the data template and push out a host value if: - the field is a valid "host field" - the value of the field is empty - the field is set to 'templated' */ if (sizeof($template_fields{$data_source["local_data_template_data_id"]})) { foreach ($template_fields{$data_source["local_data_template_data_id"]} as $template_field) { if ((eregi('^' . VALID_HOST_FIELDS . '$', $template_field["type_code"])) && ($template_field["value"] == "") && ($template_field["t_value"] == "")) { db_execute("replace into data_input_data (data_input_field_id,data_template_data_id,value) values (" . $template_field["id"] . "," . $data_source["id"] . ",'" . $host{$template_field["type_code"]} . "')"); } } } /* make sure to update the poller cache as well */ update_poller_cache($data_source["local_data_id"], false); } } }
function form_actions() { global $ds_actions; /* ================= input validation ================= */ input_validate_input_regex(get_request_var_post('drp_action'), "^([a-zA-Z0-9_]+)\$"); /* ==================================================== */ /* if we are to save this form, instead of display it */ if (isset($_POST["selected_items"])) { $selected_items = sanitize_unserialize_selected_items($_POST['selected_items']); if ($selected_items != false) { if ($_POST["drp_action"] == "1") { /* delete */ if (!isset($_POST["delete_type"])) { $_POST["delete_type"] = 1; } switch ($_POST["delete_type"]) { case '2': /* delete all graph items tied to this data source */ $data_template_rrds = array_rekey(db_fetch_assoc("select id from data_template_rrd where " . array_to_sql_or($selected_items, "local_data_id")), "id", "id"); /* loop through each data source item */ if (sizeof($data_template_rrds) > 0) { db_execute("delete from graph_templates_item where task_item_id IN (" . implode(",", $data_template_rrds) . ") and local_graph_id > 0"); } api_plugin_hook_function('graph_items_remove', $data_template_rrds); break; case '3': /* delete all graphs tied to this data source */ $graphs = array_rekey(db_fetch_assoc("select\n\t\t\t\t\t\t\tgraph_templates_graph.local_graph_id\n\t\t\t\t\t\t\tfrom (data_template_rrd,graph_templates_item,graph_templates_graph)\n\t\t\t\t\t\t\twhere graph_templates_item.task_item_id=data_template_rrd.id\n\t\t\t\t\t\t\tand graph_templates_item.local_graph_id=graph_templates_graph.local_graph_id\n\t\t\t\t\t\t\tand " . array_to_sql_or($selected_items, "data_template_rrd.local_data_id") . "\n\t\t\t\t\t\t\tand graph_templates_graph.local_graph_id > 0\n\t\t\t\t\t\t\tgroup by graph_templates_graph.local_graph_id"), "local_graph_id", "local_graph_id"); if (sizeof($graphs) > 0) { api_graph_remove_multi($graphs); } api_plugin_hook_function('graphs_remove', $graphs); break; } api_data_source_remove_multi($selected_items); api_plugin_hook_function('data_source_remove', $selected_items); } elseif ($_POST["drp_action"] == "2") { /* change graph template */ input_validate_input_number(get_request_var_post("data_template_id")); for ($i = 0; $i < count($selected_items); $i++) { change_data_template($selected_items[$i], $_POST["data_template_id"]); } } elseif ($_POST["drp_action"] == "3") { /* change host */ input_validate_input_number(get_request_var_post("host_id")); for ($i = 0; $i < count($selected_items); $i++) { db_execute("update data_local set host_id=" . $_POST["host_id"] . " where id=" . $selected_items[$i]); push_out_host($_POST["host_id"], $selected_items[$i]); update_data_source_title_cache($selected_items[$i]); } } elseif ($_POST["drp_action"] == "4") { /* duplicate */ for ($i = 0; $i < count($selected_items); $i++) { duplicate_data_source($selected_items[$i], 0, $_POST["title_format"]); } } elseif ($_POST["drp_action"] == "5") { /* data source -> data template */ for ($i = 0; $i < count($selected_items); $i++) { data_source_to_data_template($selected_items[$i], $_POST["title_format"]); } } elseif ($_POST["drp_action"] == "6") { /* data source enable */ for ($i = 0; $i < count($selected_items); $i++) { api_data_source_enable($selected_items[$i]); } } elseif ($_POST["drp_action"] == "7") { /* data source disable */ for ($i = 0; $i < count($selected_items); $i++) { api_data_source_disable($selected_items[$i]); } } elseif ($_POST["drp_action"] == "8") { /* reapply suggested data source naming */ for ($i = 0; $i < count($selected_items); $i++) { api_reapply_suggested_data_source_title($selected_items[$i]); update_data_source_title_cache($selected_items[$i]); } } else { api_plugin_hook_function('data_source_action_execute', $_POST['drp_action']); } api_plugin_hook_function('data_source_action_bottom', array($_POST['drp_action'], $selected_items)); } header("Location: data_sources.php"); exit; } /* setup some variables */ $ds_list = ""; $i = 0; /* loop through each of the graphs selected on the previous page and get more info about them */ while (list($var, $val) = each($_POST)) { if (preg_match("/^chk_([0-9]+)\$/", $var, $matches)) { /* ================= input validation ================= */ input_validate_input_number($matches[1]); /* ==================================================== */ $ds_list .= "<li>" . htmlspecialchars(get_data_source_title($matches[1])) . "</li>"; $ds_array[$i] = $matches[1]; $i++; } } include_once "./include/top_header.php"; html_start_box("<strong>" . $ds_actions[$_POST["drp_action"]] . "</strong>", "60%", "", "3", "center", ""); print "<form action='data_sources.php' method='post'>\n"; if (isset($ds_array) && sizeof($ds_array)) { if ($_POST["drp_action"] == "1") { /* delete */ $graphs = array(); /* find out which (if any) graphs are using this data source, so we can tell the user */ if (isset($ds_array)) { $graphs = db_fetch_assoc("select\n\t\t\t\t\tgraph_templates_graph.local_graph_id,\n\t\t\t\t\tgraph_templates_graph.title_cache\n\t\t\t\t\tfrom (data_template_rrd,graph_templates_item,graph_templates_graph)\n\t\t\t\t\twhere graph_templates_item.task_item_id=data_template_rrd.id\n\t\t\t\t\tand graph_templates_item.local_graph_id=graph_templates_graph.local_graph_id\n\t\t\t\t\tand " . array_to_sql_or($ds_array, "data_template_rrd.local_data_id") . "\n\t\t\t\t\tand graph_templates_graph.local_graph_id > 0\n\t\t\t\t\tgroup by graph_templates_graph.local_graph_id\n\t\t\t\t\torder by graph_templates_graph.title_cache"); } print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Data Source(s) will be deleted.</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>"; if (sizeof($graphs) > 0) { print "<tr><td class='textArea'><p class='textArea'>The following graphs are using these data sources:</p>\n"; print "<ul>"; foreach ($graphs as $graph) { print "<li><strong>" . $graph["title_cache"] . "</strong></li>\n"; } print "</ul>"; print "<br>"; form_radio_button("delete_type", "3", "1", "Leave the Graph(s) untouched.", "1"); print "<br>"; form_radio_button("delete_type", "3", "2", "Delete all <strong>Graph Item(s)</strong> that reference these Data Source(s).", "1"); print "<br>"; form_radio_button("delete_type", "3", "3", "Delete all <strong>Graph(s)</strong> that reference these Data Source(s).", "1"); print "<br>"; print "</td></tr>"; } print "\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t"; $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Delete Data Source(s)'>"; } elseif ($_POST["drp_action"] == "2") { /* change graph template */ print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>Choose a Data Template and click \"Continue\" to change the Data Template for\n\t\t\t\t\t\tthe following Data Source(s). Be aware that all warnings will be suppressed during the\n\t\t\t\t\t\tconversion, so graph data loss is possible.</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t\t<p><strong>New Data Template:</strong><br>"; form_dropdown("data_template_id", db_fetch_assoc("select data_template.id,data_template.name from data_template order by data_template.name"), "name", "id", "", "", "0"); print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t"; $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Change Graph Template for Data Source(s)'>"; } elseif ($_POST["drp_action"] == "3") { /* change host */ print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>Choose a new Device for these Data Source(s) and click \"Continue\"</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t\t<p><strong>New Host:</strong><br>"; form_dropdown("host_id", db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"), "name", "id", "", "", "0"); print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t"; $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Change Device'>"; } elseif ($_POST["drp_action"] == "4") { /* duplicate */ print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Data Source(s) will be duplicated. You can\n\t\t\t\t\t\toptionally change the title format for the new Data Source(s).</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t\t<p><strong>Title Format:</strong><br>"; form_text_box("title_format", "<ds_title> (1)", "", "255", "30", "text"); print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t"; $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Duplicate Data Source(s)'>"; } elseif ($_POST["drp_action"] == "5") { /* data source -> data template */ print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Data Source(s) will be converted into Data Template(s).\n\t\t\t\t\t\tYou can optionally change the title format for the new Data Template(s).</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t\t<p><strong>Title Format:</strong><br>"; form_text_box("title_format", "<ds_title> Template", "", "255", "30", "text"); print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t"; $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Convert Data Source(s) to Data Template(s)'>"; } elseif ($_POST["drp_action"] == "6") { /* data source enable */ print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Data Source(s) will be enabled.</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t"; $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Enable Data Source(s)'>"; } elseif ($_POST["drp_action"] == "7") { /* data source disable */ print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Data Source(s) will be disabled.</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t"; $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Disable Data Source(s)'>"; } elseif ($_POST["drp_action"] == "8") { /* reapply suggested data source naming */ print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Data Source(s) will will have there suggested naming convention\n\t\t\t\t\t\trecalculated.</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t"; $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Reapply Suggested Naming to Data Source(s)'>"; } else { $save['drp_action'] = $_POST['drp_action']; $save['ds_list'] = $ds_list; $save['ds_array'] = isset($ds_array) ? $ds_array : array(); api_plugin_hook_function('data_source_action_prepare', $save); $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue'>"; } } else { print "<tr><td class='even'><span class='textError'>You must select at least one data source.</span></td></tr>\n"; $save_html = "<input type='button' value='Return' onClick='window.history.back()'>"; } print "\t<tr>\n\t\t\t<td align='right' class='saveRow'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($ds_array) ? serialize($ds_array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST["drp_action"] . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n\t\t"; html_end_box(); include_once "./include/bottom_footer.php"; }
function form_actions() { global $ds_actions; /* ================= input validation ================= */ input_validate_input_regex(get_request_var_post('drp_action'), '^([a-zA-Z0-9_]+)$'); /* ==================================================== */ /* if we are to save this form, instead of display it */ if (isset($_POST['selected_items'])) { $selected_items = unserialize(stripslashes($_POST['selected_items'])); if ($_POST['drp_action'] == '1') { /* delete */ if (!isset($_POST['delete_type'])) { $_POST['delete_type'] = 1; } switch ($_POST['delete_type']) { case '2': /* delete all graph items tied to this data source */ $data_template_rrds = array_rekey(db_fetch_assoc('SELECT id FROM data_template_rrd WHERE ' . array_to_sql_or($selected_items, 'local_data_id')), 'id', 'id'); /* loop through each data source item */ if (sizeof($data_template_rrds) > 0) { db_execute('DELETE FROM graph_templates_item WHERE task_item_id IN (' . implode(',', $data_template_rrds) . ') and local_graph_id > 0'); } api_plugin_hook_function('graph_items_remove', $data_template_rrds); break; case '3': /* delete all graphs tied to this data source */ $graphs = array_rekey(db_fetch_assoc('SELECT graph_templates_graph.local_graph_id FROM (data_template_rrd,graph_templates_item,graph_templates_graph) WHERE graph_templates_item.task_item_id=data_template_rrd.id AND graph_templates_item.local_graph_id=graph_templates_graph.local_graph_id AND ' . array_to_sql_or($selected_items, 'data_template_rrd.local_data_id') . ' AND graph_templates_graph.local_graph_id > 0 GROUP BY graph_templates_graph.local_graph_id'), 'local_graph_id', 'local_graph_id'); if (sizeof($graphs) > 0) { api_graph_remove_multi($graphs); } api_plugin_hook_function('graphs_remove', $graphs); break; } for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); /* ==================================================== */ } api_data_source_remove_multi($selected_items); api_plugin_hook_function('data_source_remove', $selected_items); } elseif ($_POST['drp_action'] == '2') { /* change graph template */ for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); input_validate_input_number(get_request_var_post('data_template_id')); /* ==================================================== */ change_data_template($selected_items[$i], $_POST['data_template_id']); } } elseif ($_POST['drp_action'] == '3') { /* change host */ for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); input_validate_input_number(get_request_var_post('host_id')); /* ==================================================== */ db_execute_prepared('UPDATE data_local SET host_id = ? WHERE id = ?', array($_POST['host_id'], $selected_items[$i])); push_out_host($_POST['host_id'], $selected_items[$i]); update_data_source_title_cache($selected_items[$i]); } } elseif ($_POST['drp_action'] == '4') { /* duplicate */ for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); /* ==================================================== */ duplicate_data_source($selected_items[$i], 0, $_POST['title_format']); } } elseif ($_POST['drp_action'] == '5') { /* data source -> data template */ for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); /* ==================================================== */ data_source_to_data_template($selected_items[$i], $_POST['title_format']); } } elseif ($_POST['drp_action'] == '6') { /* data source enable */ for ($i = 0; $i < count($selected_items); $i++) { api_data_source_enable($selected_items[$i]); } } elseif ($_POST['drp_action'] == '7') { /* data source disable */ for ($i = 0; $i < count($selected_items); $i++) { api_data_source_disable($selected_items[$i]); } } elseif ($_POST['drp_action'] == '8') { /* reapply suggested data source naming */ for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); /* ==================================================== */ api_reapply_suggested_data_source_title($selected_items[$i]); update_data_source_title_cache($selected_items[$i]); } } else { api_plugin_hook_function('data_source_action_execute', $_POST['drp_action']); } /* update snmpcache */ snmpagent_data_source_action_bottom(array($_POST['drp_action'], $selected_items)); api_plugin_hook_function('data_source_action_bottom', array($_POST['drp_action'], $selected_items)); header('Location: data_sources.php'); exit; } /* setup some variables */ $ds_list = ''; $i = 0; /* loop through each of the graphs selected on the previous page and get more info about them */ while (list($var, $val) = each($_POST)) { if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) { /* ================= input validation ================= */ input_validate_input_number($matches[1]); /* ==================================================== */ $ds_list .= '<li>' . htmlspecialchars(get_data_source_title($matches[1])) . '<br>'; $ds_array[$i] = $matches[1]; $i++; } } top_header(); html_start_box('<strong>' . $ds_actions[$_POST['drp_action']] . '</strong>', '60%', '', '3', 'center', ''); print "<form action='data_sources.php' method='post'>\n"; if (isset($ds_array) && sizeof($ds_array)) { if ($_POST['drp_action'] == '1') { /* delete */ $graphs = array(); /* find out which (if any) graphs are using this data source, so we can tell the user */ if (isset($ds_array)) { $graphs = db_fetch_assoc('SELECT graph_templates_graph.local_graph_id, graph_templates_graph.title_cache FROM (data_template_rrd,graph_templates_item,graph_templates_graph) WHERE graph_templates_item.task_item_id=data_template_rrd.id AND graph_templates_item.local_graph_id=graph_templates_graph.local_graph_id AND ' . array_to_sql_or($ds_array, 'data_template_rrd.local_data_id') . ' AND graph_templates_graph.local_graph_id > 0 GROUP BY graph_templates_graph.local_graph_id ORDER BY graph_templates_graph.title_cache'); } print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Data Source(s) will be deleted.</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>"; if (sizeof($graphs) > 0) { print "<tr><td class='textArea'><p class='textArea'>The following graphs are using these data sources:</p>\n"; print '<ul>'; foreach ($graphs as $graph) { print '<li><strong>' . $graph['title_cache'] . "</strong></li>\n"; } print '</ul>'; print '<br>'; form_radio_button('delete_type', '3', '1', 'Leave the Graph(s) untouched.', '1'); print '<br>'; form_radio_button('delete_type', '3', '2', 'Delete all <strong>Graph Item(s)</strong> that reference these Data Source(s).', '1'); print '<br>'; form_radio_button('delete_type', '3', '3', 'Delete all <strong>Graph(s)</strong> that reference these Data Source(s).', '1'); print '<br>'; print '</td></tr>'; } print "\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t"; $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Delete Data Source(s)'>"; } elseif ($_POST['drp_action'] == '2') { /* change graph template */ print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>Choose a Data Template and click \"Continue\" to change the Data Template for\n\t\t\t\t\t\tthe following Data Source(s). Be aware that all warnings will be suppressed during the\n\t\t\t\t\t\tconversion, so graph data loss is possible.</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t\t<p><strong>New Data Template:</strong><br>"; form_dropdown('data_template_id', db_fetch_assoc('SELECT data_template.id,data_template.name FROM data_template ORDER BY data_template.name'), 'name', 'id', '', '', '0'); print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t"; $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Change Graph Template for Data Source(s)'>"; } elseif ($_POST['drp_action'] == '3') { /* change host */ print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>Choose a new Device for these Data Source(s) and click \"Continue\"</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t\t<p><strong>New Device:</strong><br>"; form_dropdown('host_id', db_fetch_assoc("SELECT id, CONCAT_WS('',description,' (',hostname,')') AS name FROM host ORDER BY description, hostname"), 'name', 'id', '', '', '0'); print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t"; $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Change Device'>"; } elseif ($_POST['drp_action'] == '4') { /* duplicate */ print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Data Source(s) will be duplicated. You can\n\t\t\t\t\t\toptionally change the title format for the new Data Source(s).</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t\t<p><strong>Title Format:</strong><br>"; form_text_box('title_format', '<ds_title> (1)', '', '255', '30', 'text'); print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t"; $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Duplicate Data Source(s)'>"; } elseif ($_POST['drp_action'] == '5') { /* data source -> data template */ print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Data Source(s) will be converted into Data Template(s).\n\t\t\t\t\t\tYou can optionally change the title format for the new Data Template(s).</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t\t<p><strong>Title Format:</strong><br>"; form_text_box('title_format', '<ds_title> Template', '', '255', '30', 'text'); print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t"; $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Convert Data Source(s) to Data Template(s)'>"; } elseif ($_POST['drp_action'] == '6') { /* data source enable */ print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Data Source(s) will be enabled.</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t"; $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Enable Data Source(s)'>"; } elseif ($_POST['drp_action'] == '7') { /* data source disable */ print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Data Source(s) will be disabled.</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t"; $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Disable Data Source(s)'>"; } elseif ($_POST['drp_action'] == '8') { /* reapply suggested data source naming */ print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Data Source(s) will will have there suggested naming convention\n\t\t\t\t\t\trecalculated.</p>\n\t\t\t\t\t\t<p><ul>{$ds_list}</ul></p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t"; $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Reapply Suggested Naming to Data Source(s)'>"; } else { $save['drp_action'] = $_POST['drp_action']; $save['ds_list'] = $ds_list; $save['ds_array'] = isset($ds_array) ? $ds_array : array(); api_plugin_hook_function('data_source_action_prepare', $save); $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue'>"; } } else { print "<tr><td class='even'><span class='textError'>You must select at least one data source.</span></td></tr>\n"; $save_html = "<input type='button' value='Return' onClick='window.history.back()'>"; } print "\t<tr>\n\t\t\t<td align='right' class='saveRow'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($ds_array) ? serialize($ds_array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST['drp_action'] . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n\t\t"; html_end_box(); bottom_footer(); }
function host_new_graphs_save() { $selected_graphs_array = unserialize(stripslashes($_POST['selected_graphs_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: snmp_query_id, 2: graph_template_id, 3: field_name */ if (empty($matches[1])) { /* this is a new graph from template field */ $values['cg'][$matches[2]]['graph_template'][$matches[3]] = $val; } else { /* this is a data query field */ $values['sg'][$matches[1]][$matches[2]]['graph_template'][$matches[3]] = $val; } } elseif (preg_match('/^gi_(\\d+)_(\\d+)_(\\d+)_(\\w+)/', $var, $matches)) { /* 1: snmp_query_id, 2: graph_template_id, 3: graph_template_input_id, 4:field_name */ /* ================= input validation ================= */ input_validate_input_number($matches[3]); /* ==================================================== */ /* we need to find out which graph items will be affected by saving this particular item */ $item_list = db_fetch_assoc_prepared('SELECT graph_template_item_id FROM graph_template_input_defs WHERE graph_template_input_id = ?', array($matches[3])); /* loop through each item affected and update column data */ if (sizeof($item_list) > 0) { foreach ($item_list as $item) { if (empty($matches[1])) { /* this is a new graph from template field */ $values['cg'][$matches[2]]['graph_template_item'][$item['graph_template_item_id']][$matches[4]] = $val; } else { /* this is a data query field */ $values['sg'][$matches[1]][$matches[2]]['graph_template_item'][$item['graph_template_item_id']][$matches[4]] = $val; } } } } elseif (preg_match('/^d_(\\d+)_(\\d+)_(\\d+)_(\\w+)/', $var, $matches)) { /* 1: snmp_query_id, 2: graph_template_id, 3: data_template_id, 4:field_name */ if (empty($matches[1])) { /* this is a new graph from template field */ $values['cg'][$matches[2]]['data_template'][$matches[3]][$matches[4]] = $val; } else { /* this is a data query field */ $values['sg'][$matches[1]][$matches[2]]['data_template'][$matches[3]][$matches[4]] = $val; } } elseif (preg_match('/^c_(\\d+)_(\\d+)_(\\d+)_(\\d+)/', $var, $matches)) { /* 1: snmp_query_id, 2: graph_template_id, 3: data_template_id, 4:data_input_field_id */ if (empty($matches[1])) { /* this is a new graph from template field */ $values['cg'][$matches[2]]['custom_data'][$matches[3]][$matches[4]] = $val; } else { /* this is a data query field */ $values['sg'][$matches[1]][$matches[2]]['custom_data'][$matches[3]][$matches[4]] = $val; } } elseif (preg_match('/^di_(\\d+)_(\\d+)_(\\d+)_(\\d+)_(\\w+)/', $var, $matches)) { /* 1: snmp_query_id, 2: graph_template_id, 3: data_template_id, 4:local_data_template_rrd_id, 5:field_name */ if (empty($matches[1])) { /* this is a new graph from template field */ $values['cg'][$matches[2]]['data_template_item'][$matches[4]][$matches[5]] = $val; } else { /* this is a data query field */ $values['sg'][$matches[1]][$matches[2]]['data_template_item'][$matches[4]][$matches[5]] = $val; } } } debug_log_clear('new_graphs'); while (list($form_type, $form_array) = each($selected_graphs_array)) { $current_form_type = $form_type; while (list($form_id1, $form_array2) = each($form_array)) { /* enumerate information from the arrays stored in post variables */ if ($form_type == 'cg') { $graph_template_id = $form_id1; } elseif ($form_type == 'sg') { while (list($form_id2, $form_array3) = each($form_array2)) { $snmp_index_array = $form_array3; $snmp_query_array['snmp_query_id'] = $form_id1; $snmp_query_array['snmp_index_on'] = get_best_data_query_index_type($_POST['host_id'], $form_id1); $snmp_query_array['snmp_query_graph_id'] = $form_id2; } $graph_template_id = db_fetch_cell_prepared('SELECT graph_template_id FROM snmp_query_graph WHERE id = ?', array($snmp_query_array['snmp_query_graph_id'])); } if ($current_form_type == 'cg') { $return_array = create_complete_graph_from_template($graph_template_id, $_POST['host_id'], '', $values['cg']); debug_log_insert('new_graphs', 'Created graph: ' . get_graph_title($return_array['local_graph_id'])); /* lastly push host-specific information to our data sources */ if (sizeof($return_array['local_data_id'])) { # we expect at least one data source associated foreach ($return_array['local_data_id'] as $item) { push_out_host($_POST['host_id'], $item); } } else { debug_log_insert('new_graphs', 'ERROR: no Data Source associated. Check Template'); } } elseif ($current_form_type == 'sg') { while (list($snmp_index, $true) = each($snmp_index_array)) { $snmp_query_array['snmp_index'] = decode_data_query_index($snmp_index, $snmp_query_array['snmp_query_id'], $_POST['host_id']); $return_array = create_complete_graph_from_template($graph_template_id, $_POST['host_id'], $snmp_query_array, $values['sg'][$snmp_query_array['snmp_query_id']]); debug_log_insert('new_graphs', 'Created graph: ' . get_graph_title($return_array['local_graph_id'])); /* lastly push host-specific information to our data sources */ if (sizeof($return_array['local_data_id'])) { # we expect at least one data source associated foreach ($return_array['local_data_id'] as $item) { push_out_host($_POST['host_id'], $item); } } else { debug_log_insert('new_graphs', 'ERROR: no Data Source associated. Check Template'); } } } } } }
function form_actions() { global $device_actions, $fields_host_edit; /* ================= input validation ================= */ input_validate_input_regex(get_request_var_post('drp_action'), '^([a-zA-Z0-9_]+)$'); /* ==================================================== */ /* if we are to save this form, instead of display it */ if (isset($_POST['selected_items'])) { $selected_items = unserialize(stripslashes($_POST['selected_items'])); if ($_POST['drp_action'] == '2') { /* Enable Selected Devices */ for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); /* ==================================================== */ db_execute_prepared("UPDATE host SET disabled = '' WHERE id = ?", array($selected_items[$i])); /* update poller cache */ $data_sources = db_fetch_assoc_prepared('SELECT id FROM data_local WHERE host_id = ?', array($selected_items[$i])); $poller_items = $local_data_ids = array(); if (sizeof($data_sources) > 0) { foreach ($data_sources as $data_source) { $local_data_ids[] = $data_source['id']; $poller_items = array_merge($poller_items, update_poller_cache($data_source['id'])); } } if (sizeof($local_data_ids)) { poller_update_poller_cache_from_buffer($local_data_ids, $poller_items); } } } elseif ($_POST['drp_action'] == '3') { /* Disable Selected Devices */ for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); /* ==================================================== */ db_execute_prepared("UPDATE host SET disabled='on' WHERE id = ?", array($selected_items[$i])); /* update poller cache */ db_execute_prepared('DELETE FROM poller_item WHERE host_id = ?', array($selected_items[$i])); db_execute_prepared('DELETE FROM poller_reindex WHERE host_id = ?', array($selected_items[$i])); } } elseif ($_POST['drp_action'] == '4') { /* change snmp options */ for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); /* ==================================================== */ reset($fields_host_edit); while (list($field_name, $field_array) = each($fields_host_edit)) { if (isset($_POST["t_{$field_name}"])) { db_execute_prepared("UPDATE host SET {$field_name} = ? WHERE id = ?", array($_POST[$field_name], $selected_items[$i])); } } push_out_host($selected_items[$i]); } } elseif ($_POST['drp_action'] == '5') { /* Clear Statisitics for Selected Devices */ for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); /* ==================================================== */ db_execute_prepared("UPDATE host SET min_time = '9.99999', max_time = '0', cur_time = '0', avg_time = '0',\n\t\t\t\t\t\ttotal_polls = '0', failed_polls = '0',\tavailability = '100.00'\n\t\t\t\t\t\twhere id = ?", array($selected_items[$i])); } } elseif ($_POST['drp_action'] == '6') { /* change availability options */ for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); /* ==================================================== */ reset($fields_host_edit); while (list($field_name, $field_array) = each($fields_host_edit)) { if (isset($_POST["t_{$field_name}"])) { db_execute_prepared("UPDATE host SET {$field_name} = ? WHERE id = ?", array($_POST[$field_name], $selected_items[$i])); } } push_out_host($selected_items[$i]); } } elseif ($_POST['drp_action'] == '1') { /* delete */ if (!isset($_POST['delete_type'])) { $_POST['delete_type'] = 2; } $data_sources_to_act_on = array(); $graphs_to_act_on = array(); $devices_to_act_on = array(); for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); /* ==================================================== */ $data_sources = db_fetch_assoc('SELECT data_local.id AS local_data_id FROM data_local WHERE ' . array_to_sql_or($selected_items, 'data_local.host_id')); if (sizeof($data_sources) > 0) { foreach ($data_sources as $data_source) { $data_sources_to_act_on[] = $data_source['local_data_id']; } } if ($_POST['delete_type'] == 2) { $graphs = db_fetch_assoc('SELECT graph_local.id AS local_graph_id FROM graph_local WHERE ' . array_to_sql_or($selected_items, 'graph_local.host_id')); if (sizeof($graphs) > 0) { foreach ($graphs as $graph) { $graphs_to_act_on[] = $graph['local_graph_id']; } } } $devices_to_act_on[] = $selected_items[$i]; } switch ($_POST['delete_type']) { case '1': /* leave graphs and data_sources in place, but disable the data sources */ api_data_source_disable_multi($data_sources_to_act_on); api_plugin_hook_function('data_source_remove', $data_sources_to_act_on); break; case '2': /* delete graphs/data sources tied to this device */ api_data_source_remove_multi($data_sources_to_act_on); api_graph_remove_multi($graphs_to_act_on); api_plugin_hook_function('graphs_remove', $graphs_to_act_on); break; } api_device_remove_multi($devices_to_act_on); api_plugin_hook_function('device_remove', $devices_to_act_on); } elseif (preg_match('/^tr_([0-9]+)$/', $_POST['drp_action'], $matches)) { /* place on tree */ for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); input_validate_input_number(get_request_var_post('tree_id')); input_validate_input_number(get_request_var_post('tree_item_id')); /* ==================================================== */ api_tree_item_save(0, $_POST['tree_id'], TREE_ITEM_TYPE_HOST, $_POST['tree_item_id'], '', 0, read_graph_config_option('default_rra_id'), $selected_items[$i], 1, 1, false); } } else { api_plugin_hook_function('device_action_execute', $_POST['drp_action']); } /* update snmpcache */ snmpagent_device_action_bottom(array($_POST['drp_action'], $selected_items)); api_plugin_hook_function('device_action_bottom', array($_POST['drp_action'], $selected_items)); header('Location: host.php'); exit; } /* setup some variables */ $host_list = ''; $i = 0; /* loop through each of the host templates selected on the previous page and get more info about them */ while (list($var, $val) = each($_POST)) { if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) { /* ================= input validation ================= */ input_validate_input_number($matches[1]); /* ==================================================== */ $host_list .= '<li>' . htmlspecialchars(db_fetch_cell_prepared('SELECT description FROM host WHERE id = ?', array($matches[1]))) . '<br>'; $host_array[$i] = $matches[1]; $i++; } } top_header(); /* add a list of tree names to the actions dropdown */ add_tree_names_to_actions_array(); html_start_box('<strong>' . $device_actions[get_request_var_post('drp_action')] . '</strong>', '60%', '', '3', 'center', ''); print "<form action='host.php' autocomplete='off' method='post'>\n"; if (isset($host_array) && sizeof($host_array)) { if ($_POST['drp_action'] == '2') { /* Enable Devices */ print "\t<tr>\n\t\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t\t<p>To enable the following Device(s), click \"Continue\".</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . "</ul></p>\n\t\t\t\t\t</td>\n\t\t\t\t\t</tr>"; $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Enable Device(s)'>"; } elseif ($_POST['drp_action'] == '3') { /* Disable Devices */ print "\t<tr>\n\t\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t\t<p>To disable the following Device(s), click \"Continue\".</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p> </td> </tr>'; $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Disable Device(s)'>"; } elseif ($_POST['drp_action'] == '4') { /* change snmp options */ print "\t<tr>\n\t\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t\t<p>To change SNMP parameters for the following Device(s), check the box next to the fields\n\t\t\t\t\t\tyou want to update, fill in the new value, and click \"Continue\".</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p> </td> </tr>'; $form_array = array(); while (list($field_name, $field_array) = each($fields_host_edit)) { if (preg_match('/^snmp_/', $field_name) || $field_name == 'max_oids') { $form_array += array($field_name => $fields_host_edit[$field_name]); $form_array[$field_name]['value'] = ''; $form_array[$field_name]['description'] = ''; $form_array[$field_name]['form_id'] = 0; $form_array[$field_name]['sub_checkbox'] = array('name' => 't_' . $field_name, 'friendly_name' => 'Update this Field', 'value' => ''); } } draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => $form_array)); $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Change Device(s) SNMP Options'>"; } elseif ($_POST['drp_action'] == '6') { /* change availability options */ print "\t<tr>\n\t\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t\t<p>To change Availability parameters for the following Device(s), check the box next to the fields\n\t\t\t\t\t\tyou want to update, fill in the new value, and click \"Continue\".</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p> </td> </tr>'; $form_array = array(); while (list($field_name, $field_array) = each($fields_host_edit)) { if (preg_match('/(availability_method|ping_method|ping_port)/', $field_name)) { $form_array += array($field_name => $fields_host_edit[$field_name]); $form_array[$field_name]['value'] = ''; $form_array[$field_name]['description'] = ''; $form_array[$field_name]['form_id'] = 0; $form_array[$field_name]['sub_checkbox'] = array('name' => 't_' . $field_name, 'friendly_name' => 'Update this Field', 'value' => ''); } } draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => $form_array)); $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Change Device(s) Availability Options'>"; } elseif ($_POST['drp_action'] == '5') { /* Clear Statisitics for Selected Devices */ print "\t<tr>\n\t\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t\t<p>To clear the counters for the following Device(s), press the \"Continue\" button below.</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p> </td> </tr>'; $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Clear Statistics on Device(s)'>"; } elseif ($_POST['drp_action'] == '1') { /* delete */ print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\" the following Device(s) will be deleted.</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p>'; form_radio_button('delete_type', '2', '1', 'Leave all Graph(s) and Data Source(s) untouched. Data Source(s) will be disabled however.', '1'); print '<br>'; form_radio_button('delete_type', '2', '2', 'Delete all associated <strong>Graph(s)</strong> and <strong>Data Source(s)</strong>.', '1'); print '<br>'; print "</td></tr>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t"; $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Delete Device(s)'>"; } elseif (preg_match('/^tr_([0-9]+)$/', $_POST['drp_action'], $matches)) { /* place on tree */ print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Device(s) will be placed under the branch selected\n\t\t\t\t\t\tbelow.</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p> <p><strong>Destination Branch:</strong><br>'; grow_dropdown_tree($matches[1], '0', 'tree_item_id', '0'); print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t<input type='hidden' name='tree_id' value='" . $matches[1] . "'>\n\n\t\t\t\t"; $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Place Device(s) on Tree'>"; } else { $save['drp_action'] = $_POST['drp_action']; $save['host_list'] = $host_list; $save['host_array'] = isset($host_array) ? $host_array : array(); api_plugin_hook_function('device_action_prepare', $save); $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue'>"; } } else { print "<tr><td class='even'><span class='textError'>You must select at least one device.</span></td></tr>\n"; $save_html = "<input type='button' value='Return' onClick='window.history.back()'>"; } print "\t<tr>\n\t\t\t<td colspan='2' align='right' class='saveRow'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($host_array) ? serialize($host_array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST['drp_action'] . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n\t\t"; html_end_box(); bottom_footer(); }
function form_save() { if (isset($_POST['save_component_template'])) { /* ================= input validation ================= */ input_validate_input_number(get_request_var_post('data_input_id')); input_validate_input_number(get_request_var_post('data_template_id')); /* ==================================================== */ /* save: data_template */ $save1['id'] = $_POST['data_template_id']; $save1['hash'] = get_hash_data_template($_POST['data_template_id']); $save1['name'] = form_input_validate($_POST['template_name'], 'template_name', '', false, 3); /* save: data_template_data */ $save2['id'] = $_POST['data_template_data_id']; $save2['local_data_template_data_id'] = 0; $save2['local_data_id'] = 0; $save2['data_input_id'] = form_input_validate($_POST['data_input_id'], 'data_input_id', '', true, 3); $save2['t_name'] = form_input_validate(isset($_POST['t_name']) ? $_POST['t_name'] : '', 't_name', '', true, 3); $save2['name'] = form_input_validate($_POST['name'], 'name', '', isset($_POST['t_name']) ? true : false, 3); $save2['t_active'] = form_input_validate(isset($_POST['t_active']) ? $_POST['t_active'] : '', 't_active', '', true, 3); $save2['active'] = form_input_validate(isset($_POST['active']) ? $_POST['active'] : '', 'active', '', true, 3); $save2['t_rrd_step'] = form_input_validate(isset($_POST['t_rrd_step']) ? $_POST['t_rrd_step'] : '', 't_rrd_step', '', true, 3); $save2['rrd_step'] = form_input_validate($_POST['rrd_step'], 'rrd_step', '^[0-9]+$', isset($_POST['t_rrd_step']) ? true : false, 3); $save2['t_rra_id'] = form_input_validate(isset($_POST['t_rra_id']) ? $_POST['t_rra_id'] : '', 't_rra_id', '', true, 3); /* save: data_template_rrd */ $save3['id'] = $_POST['data_template_rrd_id']; $save3['hash'] = get_hash_data_template($_POST['data_template_rrd_id'], 'data_template_item'); $save3['local_data_template_rrd_id'] = 0; $save3['local_data_id'] = 0; $save3['t_rrd_maximum'] = form_input_validate(isset($_POST['t_rrd_maximum']) ? $_POST['t_rrd_maximum'] : '', 't_rrd_maximum', '', true, 3); $save3['rrd_maximum'] = form_input_validate($_POST['rrd_maximum'], 'rrd_maximum', '^(-?([0-9]+(\\.[0-9]*)?|[0-9]*\\.[0-9]+)([eE][+\\-]?[0-9]+)?)|U$', isset($_POST['t_rrd_maximum']) ? true : false, 3); $save3['t_rrd_minimum'] = form_input_validate(isset($_POST['t_rrd_minimum']) ? $_POST['t_rrd_minimum'] : '', 't_rrd_minimum', '', true, 3); $save3['rrd_minimum'] = form_input_validate($_POST['rrd_minimum'], 'rrd_minimum', '^(-?([0-9]+(\\.[0-9]*)?|[0-9]*\\.[0-9]+)([eE][+\\-]?[0-9]+)?)|U$', isset($_POST['t_rrd_minimum']) ? true : false, 3); $save3['t_rrd_heartbeat'] = form_input_validate(isset($_POST['t_rrd_heartbeat']) ? $_POST['t_rrd_heartbeat'] : '', 't_rrd_heartbeat', '', true, 3); $save3['rrd_heartbeat'] = form_input_validate($_POST['rrd_heartbeat'], 'rrd_heartbeat', '^[0-9]+$', isset($_POST['t_rrd_heartbeat']) ? true : false, 3); $save3['t_data_source_type_id'] = form_input_validate(isset($_POST['t_data_source_type_id']) ? $_POST['t_data_source_type_id'] : '', 't_data_source_type_id', '', true, 3); $save3['data_source_type_id'] = form_input_validate($_POST['data_source_type_id'], 'data_source_type_id', '', true, 3); $save3['t_data_source_name'] = form_input_validate(isset($_POST['t_data_source_name']) ? $_POST['t_data_source_name'] : '', 't_data_source_name', '', true, 3); $save3['data_source_name'] = form_input_validate($_POST['data_source_name'], 'data_source_name', '^[a-zA-Z0-9_]{1,19}$', isset($_POST['t_data_source_name']) ? true : false, 3); $save3['t_data_input_field_id'] = form_input_validate(isset($_POST['t_data_input_field_id']) ? $_POST['t_data_input_field_id'] : '', 't_data_input_field_id', '', true, 3); $save3['data_input_field_id'] = form_input_validate(isset($_POST['data_input_field_id']) ? $_POST['data_input_field_id'] : '0', 'data_input_field_id', '', true, 3); /* ok, first pull out all 'input' values so we know how much to save */ $input_fields = db_fetch_assoc_prepared("SELECT\n\t\t\tid,\n\t\t\tinput_output,\n\t\t\tregexp_match,\n\t\t\tallow_nulls,\n\t\t\ttype_code,\n\t\t\tdata_name\n\t\t\tFROM data_input_fields\n\t\t\tWHERE data_input_id = ?\n\t\t\tAND input_output = 'in'", array($_POST['data_input_id'])); /* pass 1 for validation */ if (sizeof($input_fields) > 0) { foreach ($input_fields as $input_field) { $form_value = 'value_' . $input_field['data_name']; if (isset($_POST[$form_value]) && $input_field['type_code'] == '') { if (isset($_POST['t_' . $form_value]) && $_POST['t_' . $form_value] == 'on') { $not_required = true; } else { if ($input_field['allow_nulls'] == 'on') { $not_required = true; } else { $not_required = false; } } form_input_validate($_POST[$form_value], 'value_' . $input_field['data_name'], $input_field['regexp_match'], $not_required, 3); } } } if (!is_error_message()) { $data_template_id = sql_save($save1, 'data_template'); if ($data_template_id) { raise_message(1); } else { raise_message(2); } } if (!is_error_message()) { $save2['data_template_id'] = $data_template_id; $data_template_data_id = sql_save($save2, 'data_template_data'); if ($data_template_data_id) { raise_message(1); } else { raise_message(2); } } /* update actual host template information for live hosts */ if (!is_error_message() && $save2['id'] > 0) { db_execute_prepared('UPDATE data_template_data set data_input_id = ? WHERE data_template_id = ?', array($_POST['data_input_id'], $_POST['data_template_id'])); } if (!is_error_message()) { $save3['data_template_id'] = $data_template_id; $data_template_rrd_id = sql_save($save3, 'data_template_rrd'); if ($data_template_rrd_id) { raise_message(1); } else { raise_message(2); } } if (!is_error_message()) { /* save entries in 'selected rras' field */ db_execute_prepared('DELETE FROM data_template_data_rra WHERE data_template_data_id = ?', array($data_template_data_id)); if (isset($_POST['rra_id'])) { for ($i = 0; $i < count($_POST['rra_id']); $i++) { /* ================= input validation ================= */ input_validate_input_number($_POST['rra_id'][$i]); /* ==================================================== */ db_execute_prepared('INSERT INTO data_template_data_rra (rra_id, data_template_data_id) VALUES (?, ?)', array($_POST['rra_id'][$i], $data_template_data_id)); } } if (!empty($_POST['data_template_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); db_execute_prepared('DELETE FROM data_input_data WHERE data_template_data_id = ?', array($data_template_data_id)); reset($input_fields); if (sizeof($input_fields) > 0) { foreach ($input_fields as $input_field) { $form_value = 'value_' . $input_field['data_name']; if (isset($_POST[$form_value])) { /* save the data into the 'host_template_data' table */ if (isset($_POST['t_value_' . $input_field['data_name']])) { $template_this_item = 'on'; } else { $template_this_item = ''; } if (!empty($form_value) || !empty($_POST['t_value_' . $input_field['data_name']])) { db_execute_prepared('INSERT INTO data_input_data (data_input_field_id, data_template_data_id, t_value, value) values (?, ?, ?, ?)', array($input_field['id'], $data_template_data_id, $template_this_item, trim($_POST[$form_value]))); } } } } /* push out all "custom data" for this data source template */ push_out_data_source_custom_data($data_template_id); push_out_host(0, 0, $data_template_id); } } header('Location: data_templates.php?action=template_edit&id=' . (empty($data_template_id) ? $_POST['data_template_id'] : $data_template_id) . (empty($_POST['current_rrd']) ? '' : '&view_rrd=' . ($_POST['current_rrd'] ? $_POST['current_rrd'] : $data_template_rrd_id))); } }
function form_save() { if (isset($_POST["save_component_template"])) { /* save: data_template */ $save1["id"] = $_POST["data_template_id"]; $save1["hash"] = get_hash_data_template($_POST["data_template_id"]); $save1["name"] = form_input_validate($_POST["template_name"], "template_name", "", false, 3); /* save: data_template_data */ $save2["id"] = $_POST["data_template_data_id"]; $save2["local_data_template_data_id"] = 0; $save2["local_data_id"] = 0; $save2["data_input_id"] = form_input_validate($_POST["data_input_id"], "data_input_id", "", true, 3); $save2["t_name"] = form_input_validate((isset($_POST["t_name"]) ? $_POST["t_name"] : ""), "t_name", "", true, 3); $save2["name"] = form_input_validate($_POST["name"], "name", "", false, 3); $save2["t_active"] = form_input_validate((isset($_POST["t_active"]) ? $_POST["t_active"] : ""), "t_active", "", true, 3); $save2["active"] = form_input_validate((isset($_POST["active"]) ? $_POST["active"] : ""), "active", "", true, 3); $save2["t_rrd_step"] = form_input_validate((isset($_POST["t_rrd_step"]) ? $_POST["t_rrd_step"] : ""), "t_rrd_step", "", true, 3); $save2["rrd_step"] = form_input_validate($_POST["rrd_step"], "rrd_step", "^[0-9]+$", false, 3); $save2["t_rra_id"] = form_input_validate((isset($_POST["t_rra_id"]) ? $_POST["t_rra_id"] : ""), "t_rra_id", "", true, 3); /* save: data_template_rrd */ $save3["id"] = $_POST["data_template_rrd_id"]; $save3["hash"] = get_hash_data_template($_POST["data_template_rrd_id"], "data_template_item"); $save3["local_data_template_rrd_id"] = 0; $save3["local_data_id"] = 0; $save3["t_rrd_maximum"] = form_input_validate((isset($_POST["t_rrd_maximum"]) ? $_POST["t_rrd_maximum"] : ""), "t_rrd_maximum", "", true, 3); $save3["rrd_maximum"] = form_input_validate($_POST["rrd_maximum"], "rrd_maximum", "^-?[0-9]+$", false, 3); $save3["t_rrd_minimum"] = form_input_validate((isset($_POST["t_rrd_minimum"]) ? $_POST["t_rrd_minimum"] : ""), "t_rrd_minimum", "", true, 3); $save3["rrd_minimum"] = form_input_validate($_POST["rrd_minimum"], "rrd_minimum", "^-?[0-9]+$", false, 3); $save3["t_rrd_heartbeat"] = form_input_validate((isset($_POST["t_rrd_heartbeat"]) ? $_POST["t_rrd_heartbeat"] : ""), "t_rrd_heartbeat", "", true, 3); $save3["rrd_heartbeat"] = form_input_validate($_POST["rrd_heartbeat"], "rrd_heartbeat", "^[0-9]+$", false, 3); $save3["t_data_source_type_id"] = form_input_validate((isset($_POST["t_data_source_type_id"]) ? $_POST["t_data_source_type_id"] : ""), "t_data_source_type_id", "", true, 3); $save3["data_source_type_id"] = form_input_validate($_POST["data_source_type_id"], "data_source_type_id", "", true, 3); $save3["t_data_source_name"] = form_input_validate((isset($_POST["t_data_source_name"]) ? $_POST["t_data_source_name"] : ""), "t_data_source_name", "", true, 3); $save3["data_source_name"] = form_input_validate($_POST["data_source_name"], "data_source_name", "^[a-zA-Z0-9_]{1,19}$", false, 3); $save3["t_data_input_field_id"] = form_input_validate((isset($_POST["t_data_input_field_id"]) ? $_POST["t_data_input_field_id"] : ""), "t_data_input_field_id", "", true, 3); $save3["data_input_field_id"] = form_input_validate((isset($_POST["data_input_field_id"]) ? $_POST["data_input_field_id"] : "0"), "data_input_field_id", "", true, 3); if (!is_error_message()) { $data_template_id = sql_save($save1, "data_template"); if ($data_template_id) { raise_message(1); }else{ raise_message(2); } } if (!is_error_message()) { $save2["data_template_id"] = $data_template_id; $data_template_data_id = sql_save($save2, "data_template_data"); if ($data_template_data_id) { raise_message(1); }else{ raise_message(2); } } /* update actual host template information for live hosts */ if (!is_error_message()) { db_execute("update data_template_data set data_input_id = '" . $_POST["data_input_id"] . "' where data_template_id = " . $_POST["data_template_id"] . ";"); } if (!is_error_message()) { $save3["data_template_id"] = $data_template_id; $data_template_rrd_id = sql_save($save3, "data_template_rrd"); if ($data_template_rrd_id) { raise_message(1); }else{ raise_message(2); } } if (!is_error_message()) { /* save entries in 'selected rras' field */ db_execute("delete from data_template_data_rra where data_template_data_id=$data_template_data_id"); if (isset($_POST["rra_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)"); } } if (!empty($_POST["data_template_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) { $form_value = "value_" . $input_field["data_name"]; if (isset($_POST[$form_value])) { /* save the data into the 'host_template_data' table */ if (isset($_POST{"t_value_" . $input_field["data_name"]})) { $template_this_item = "on"; }else{ $template_this_item = ""; } if ((!empty($form_value)) || (!empty($_POST{"t_value_" . $input_field["data_name"]}))) { 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,'$template_this_item','" . $_POST[$form_value] . "')"); } } } } /* push out all "custom data" for this data source template */ push_out_data_source_custom_data($data_template_id); push_out_host(0, 0, $data_template_id); } } if ((is_error_message()) || (empty($_POST["data_template_id"]))) { header("Location: data_templates.php?action=template_edit&id=" . (empty($data_template_id) ? $_POST["data_template_id"] : $data_template_id) . (empty($_POST["current_rrd"]) ? "" : "&view_rrd=" . ($_POST["current_rrd"] ? $_POST["current_rrd"] : $data_template_rrd_id))); }else{ header("Location: data_templates.php"); } } }
function api_device_save($id, $host_template_id, $description, $hostname, $snmp_community, $snmp_version, $snmp_username, $snmp_password, $snmp_port, $snmp_timeout, $disabled, $availability_method, $ping_method, $ping_port, $ping_timeout, $ping_retries, $notes, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $max_oids, $device_threads) { global $config; include_once $config["base_path"] . "/lib/utility.php"; include_once $config["base_path"] . "/lib/variables.php"; include_once $config["base_path"] . "/lib/data_query.php"; /* fetch some cache variables */ if (empty($id)) { $_host_template_id = 0; } else { $_host_template_id = db_fetch_cell("select host_template_id from host where id={$id}"); } $save["id"] = $id; $save["host_template_id"] = form_input_validate($host_template_id, "host_template_id", "^[0-9]+\$", false, 3); $save["description"] = form_input_validate($description, "description", "", false, 3); $save["hostname"] = form_input_validate(trim($hostname), "hostname", "", false, 3); $save["notes"] = form_input_validate($notes, "notes", "", true, 3); $save["snmp_version"] = form_input_validate($snmp_version, "snmp_version", "", true, 3); $save["snmp_community"] = form_input_validate($snmp_community, "snmp_community", "", true, 3); if ($save["snmp_version"] == 3) { $save["snmp_username"] = form_input_validate($snmp_username, "snmp_username", "", true, 3); $save["snmp_password"] = form_input_validate($snmp_password, "snmp_password", "", true, 3); $save["snmp_auth_protocol"] = form_input_validate($snmp_auth_protocol, "snmp_auth_protocol", "", true, 3); $save["snmp_priv_passphrase"] = form_input_validate($snmp_priv_passphrase, "snmp_priv_passphrase", "", true, 3); $save["snmp_priv_protocol"] = form_input_validate($snmp_priv_protocol, "snmp_priv_protocol", "", true, 3); $save["snmp_context"] = form_input_validate($snmp_context, "snmp_context", "", true, 3); } else { $save["snmp_username"] = ""; $save["snmp_password"] = ""; } $save["snmp_port"] = form_input_validate($snmp_port, "snmp_port", "^[0-9]+\$", false, 3); $save["snmp_timeout"] = form_input_validate($snmp_timeout, "snmp_timeout", "^[0-9]+\$", false, 3); $save["disabled"] = form_input_validate($disabled, "disabled", "", true, 3); $save["availability_method"] = form_input_validate($availability_method, "availability_method", "^[0-9]+\$", false, 3); $save["ping_method"] = form_input_validate($ping_method, "ping_method", "^[0-9]+\$", false, 3); $save["ping_port"] = form_input_validate($ping_port, "ping_port", "^[0-9]+\$", true, 3); $save["ping_timeout"] = form_input_validate($ping_timeout, "ping_timeout", "^[0-9]+\$", true, 3); $save["ping_retries"] = form_input_validate($ping_retries, "ping_retries", "^[0-9]+\$", true, 3); $save["max_oids"] = form_input_validate($max_oids, "max_oids", "^[0-9]+\$", true, 3); $save["device_threads"] = form_input_validate($device_threads, "device_threads", "^[0-9]+\$", true, 3); $save = api_plugin_hook_function('api_device_save', $save); $host_id = 0; if (!is_error_message()) { $host_id = sql_save($save, "host"); if ($host_id) { raise_message(1); /* push out relavant fields to data sources using this host */ push_out_host($host_id, 0); /* the host substitution cache is now stale; purge it */ kill_session_var("sess_host_cache_array"); /* update title cache for graph and data source */ update_data_source_title_cache_from_host($host_id); update_graph_title_cache_from_host($host_id); } else { raise_message(2); } /* if the user changes the host template, add each snmp query associated with it */ if ($host_template_id != $_host_template_id && !empty($host_template_id)) { $snmp_queries = db_fetch_assoc("select snmp_query_id from host_template_snmp_query where host_template_id={$host_template_id}"); if (sizeof($snmp_queries) > 0) { foreach ($snmp_queries as $snmp_query) { db_execute("replace into host_snmp_query (host_id,snmp_query_id,reindex_method) values ({$host_id}," . $snmp_query["snmp_query_id"] . "," . read_config_option("reindex_method") . ")"); /* recache snmp data */ run_data_query($host_id, $snmp_query["snmp_query_id"]); } } $graph_templates = db_fetch_assoc("select graph_template_id from host_template_graph where host_template_id={$host_template_id}"); if (sizeof($graph_templates) > 0) { foreach ($graph_templates as $graph_template) { db_execute("replace into host_graph (host_id,graph_template_id) values ({$host_id}," . $graph_template["graph_template_id"] . ")"); api_plugin_hook_function('add_graph_template_to_host', array("host_id" => $host_id, "graph_template_id" => $graph_template["graph_template_id"])); } } } } # now that we have the id of the new host, we may plugin postprocessing code $save["id"] = $host_id; api_plugin_hook_function('api_device_new', $save); return $host_id; }
function form_actions() { /* modify for multi user start */ if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) { $rows = db_fetch_assoc("\r\n SELECT host.id FROM host\r\n INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'"); foreach ($rows as $row) { $hosts[] = $row["id"]; } } /* modify for multi user end */ global $colors, $device_actions, $fields_host_edit; /* if we are to save this form, instead of display it */ if (isset($_POST["selected_items"])) { $selected_items = unserialize(stripslashes($_POST["selected_items"])); /* modify for multi user start */ if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) { for ($i = 0; $i < count($selected_items); $i++) { if (!in_array($selected_items[$i], $hosts)) { access_denied(); } } } /* modify for multi user end */ if ($_POST["drp_action"] == "2") { /* Enable Selected Devices */ for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); /* ==================================================== */ /* modify for multi user start */ if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) { if (db_fetch_cell("SELECT id FROM host WHERE id = '" . $selected_items[$i] . "' AND disabled = 'ps'")) { continue; } } /* modify for multi user end */ db_execute("update host set disabled='' where id='" . $selected_items[$i] . "'"); /* update poller cache */ $data_sources = db_fetch_assoc("select id from data_local where host_id='" . $selected_items[$i] . "'"); $poller_items = array(); if (sizeof($data_sources) > 0) { foreach ($data_sources as $data_source) { $local_data_ids[] = $data_source["id"]; $poller_items = array_merge($poller_items, update_poller_cache($data_source["id"])); } } poller_update_poller_cache_from_buffer($local_data_ids, $poller_items); } } elseif ($_POST["drp_action"] == "3") { /* Disable Selected Devices */ for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); /* ==================================================== */ /* modify for multi user start */ if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) { if (db_fetch_cell("SELECT id FROM host WHERE id = '" . $selected_items[$i] . "' AND disabled = 'ps'")) { continue; } } /* modify for multi user end */ db_execute("update host set disabled='on' where id='" . $selected_items[$i] . "'"); /* update poller cache */ db_execute("delete from poller_item where host_id='" . $selected_items[$i] . "'"); db_execute("delete from poller_reindex where host_id='" . $selected_items[$i] . "'"); } } elseif ($_POST["drp_action"] == "4") { /* change snmp options */ for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); /* ==================================================== */ reset($fields_host_edit); while (list($field_name, $field_array) = each($fields_host_edit)) { if (isset($_POST["t_{$field_name}"])) { db_execute("update host set {$field_name} = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'"); } } push_out_host($selected_items[$i]); } } elseif ($_POST["drp_action"] == "5") { /* Clear Statisitics for Selected Devices */ for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); /* ==================================================== */ db_execute("update host set min_time = '9.99999', max_time = '0', cur_time = '0',\tavg_time = '0',\r\n\t\t\t\t\t\ttotal_polls = '0', failed_polls = '0',\tavailability = '100.00'\r\n\t\t\t\t\t\twhere id = '" . $selected_items[$i] . "'"); } } elseif ($_POST["drp_action"] == "6") { /* change availability options */ for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); /* ==================================================== */ reset($fields_host_edit); while (list($field_name, $field_array) = each($fields_host_edit)) { if (isset($_POST["t_{$field_name}"])) { db_execute("update host set {$field_name} = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'"); } } push_out_host($selected_items[$i]); } } elseif ($_POST["drp_action"] == "1") { /* delete */ if (!isset($_POST["delete_type"])) { $_POST["delete_type"] = 2; } $data_sources_to_act_on = array(); $graphs_to_act_on = array(); $devices_to_act_on = array(); for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); /* ==================================================== */ $data_sources = db_fetch_assoc("select\r\n\t\t\t\t\tdata_local.id as local_data_id\r\n\t\t\t\t\tfrom data_local\r\n\t\t\t\t\twhere " . array_to_sql_or($selected_items, "data_local.host_id")); if (sizeof($data_sources) > 0) { foreach ($data_sources as $data_source) { $data_sources_to_act_on[] = $data_source["local_data_id"]; } } if ($_POST["delete_type"] == 2) { $graphs = db_fetch_assoc("select\r\n\t\t\t\t\t\tgraph_local.id as local_graph_id\r\n\t\t\t\t\t\tfrom graph_local\r\n\t\t\t\t\t\twhere " . array_to_sql_or($selected_items, "graph_local.host_id")); if (sizeof($graphs) > 0) { foreach ($graphs as $graph) { $graphs_to_act_on[] = $graph["local_graph_id"]; } } } $devices_to_act_on[] = $selected_items[$i]; } switch ($_POST["delete_type"]) { case '1': /* leave graphs and data_sources in place, but disable the data sources */ api_data_source_disable_multi($data_sources_to_act_on); api_plugin_hook_function('data_source_remove', $data_sources_to_act_on); break; case '2': /* delete graphs/data sources tied to this device */ api_data_source_remove_multi($data_sources_to_act_on); api_graph_remove_multi($graphs_to_act_on); api_plugin_hook_function('graphs_remove', $graphs_to_act_on); break; } api_device_remove_multi($devices_to_act_on); /* modify for multi user start */ if ($_SESSION["permission"] <= ACCESS_ADMINISTRATOR) { foreach ($devices_to_act_on as $device_id) { db_execute("DELETE FROM user_auth_perms WHERE type = 3 AND user_id = '" . $_SESSION["sess_user_id"] . "' AND item_id = '{$device_id}'"); } } /* modify for multi user end */ api_plugin_hook_function('device_remove', $devices_to_act_on); } elseif (preg_match("/^tr_([0-9]+)\$/", $_POST["drp_action"], $matches)) { /* place on tree */ /* modify for multi user start */ if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) { input_validate_input_number(get_request_var_post("tree_id")); if ($_POST["tree_id"] != $_SESSION["public_tree_id"]) { access_denied(); } } /* modify for multi user end */ for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); input_validate_input_number(get_request_var_post("tree_id")); input_validate_input_number(get_request_var_post("tree_item_id")); /* ==================================================== */ api_tree_item_save(0, $_POST["tree_id"], TREE_ITEM_TYPE_HOST, $_POST["tree_item_id"], "", 0, read_graph_config_option("default_rra_id"), $selected_items[$i], 1, 1, false); } /* modify for multi user start */ if (isset($_SESSION['dhtml_tree'])) { unset($_SESSION['dhtml_tree']); } /* modify for multi user end */ } else { api_plugin_hook_function('device_action_execute', $_POST['drp_action']); } header("Location: host.php"); exit; } /* setup some variables */ $host_list = ""; $i = 0; /* loop through each of the host templates selected on the previous page and get more info about them */ while (list($var, $val) = each($_POST)) { if (preg_match("/^chk_([0-9]+)\$/", $var, $matches)) { /* ================= input validation ================= */ input_validate_input_number($matches[1]); /* ==================================================== */ /* modify for multi user start */ if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) { if (!in_array($matches[1], $hosts)) { access_denied(); } } /* modify for multi user start */ $host_list .= "<li>" . htmlspecialchars(db_fetch_cell("select description from host where id=" . $matches[1])) . "<br>"; $host_array[$i] = $matches[1]; $i++; } } include_once "./include/top_header.php"; /* add a list of tree names to the actions dropdown */ add_tree_names_to_actions_array(); html_start_box("<strong>" . $device_actions[get_request_var_post("drp_action")] . "</strong>", "60%", $colors["header_panel"], "3", "center", ""); print "<form action='host.php' autocomplete='off' method='post'>\n"; if (isset($host_array) && sizeof($host_array)) { if ($_POST["drp_action"] == "2") { /* Enable Devices */ print "\t<tr>\r\n\t\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>To enable the following Device(s), click \"Continue\".</p>\r\n\t\t\t\t\t\t<p><ul>" . $host_list . "</ul></p>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t\t</tr>"; $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Enable Device(s)'>"; } elseif ($_POST["drp_action"] == "3") { /* Disable Devices */ print "\t<tr>\r\n\t\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>To disable the following Device(s), click \"Continue\".</p>\r\n\t\t\t\t\t\t<p><ul>" . $host_list . "</ul></p>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t\t</tr>"; $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Disable Device(s)'>"; } elseif ($_POST["drp_action"] == "4") { /* change snmp options */ print "\t<tr>\r\n\t\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>To change SNMP parameters for the following Device(s), check the box next to the fields\r\n\t\t\t\t\t\tyou want to update, fill in the new value, and click \"Continue\".</p>\r\n\t\t\t\t\t\t<p><ul>" . $host_list . "</ul></p>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t\t</tr>"; $form_array = array(); while (list($field_name, $field_array) = each($fields_host_edit)) { if (preg_match("/^snmp_/", $field_name) || $field_name == "max_oids") { $form_array += array($field_name => $fields_host_edit[$field_name]); $form_array[$field_name]["value"] = ""; $form_array[$field_name]["description"] = ""; $form_array[$field_name]["form_id"] = 0; $form_array[$field_name]["sub_checkbox"] = array("name" => "t_" . $field_name, "friendly_name" => "Update this Field", "value" => ""); } } /* modify for multi user start */ if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) { $form_array["snmp_timeout"]["method"] = "hidden"; $form_array["max_oids"]["method"] = "hidden"; } /* modify for multi user end */ draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => $form_array)); $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Change Device(s) SNMP Options'>"; } elseif ($_POST["drp_action"] == "6") { /* change availability options */ print "\t<tr>\r\n\t\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>To change Availability parameters for the following Device(s), check the box next to the fields\r\n\t\t\t\t\t\tyou want to update, fill in the new value, and click \"Continue\".</p>\r\n\t\t\t\t\t\t<p><ul>" . $host_list . "</ul></p>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t\t</tr>"; $form_array = array(); while (list($field_name, $field_array) = each($fields_host_edit)) { if (preg_match("/(availability_method|ping_method|ping_port)/", $field_name)) { $form_array += array($field_name => $fields_host_edit[$field_name]); $form_array[$field_name]["value"] = ""; $form_array[$field_name]["description"] = ""; $form_array[$field_name]["form_id"] = 0; $form_array[$field_name]["sub_checkbox"] = array("name" => "t_" . $field_name, "friendly_name" => "Update this Field", "value" => ""); } } draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => $form_array)); $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Change Device(s) Availability Options'>"; } elseif ($_POST["drp_action"] == "5") { /* Clear Statisitics for Selected Devices */ print "\t<tr>\r\n\t\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>To clear the counters for the following Device(s), press the \"Continue\" button below.</p>\r\n\t\t\t\t\t\t<p><ul>" . $host_list . "</ul></p>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t\t</tr>"; $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Clear Statistics on Device(s)'>"; } elseif ($_POST["drp_action"] == "1") { /* delete */ print "\t<tr>\r\n\t\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>When you click \"Continue\" the following Device(s) will be deleted.</p>\r\n\t\t\t\t\t\t<p><ul>" . $host_list . "</ul></p>"; /* modify for multi user start */ if ($_SESSION["permission"] == ACCESS_ADMINISTRATOR) { form_radio_button("delete_type", "2", "1", "Leave all Graph(s) and Data Source(s) untouched. Data Source(s) will be disabled however.", "1"); print "<br>"; } /* modify for multi user end */ form_radio_button("delete_type", "2", "2", "Delete all associated <strong>Graph(s)</strong> and <strong>Data Source(s)</strong>.", "1"); print "<br>"; print "</td></tr>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t</tr>\n\r\n\t\t\t\t"; $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Delete Device(s)'>"; } elseif (preg_match("/^tr_([0-9]+)\$/", $_POST["drp_action"], $matches)) { /* place on tree */ print "\t<tr>\r\n\t\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Device(s) will be placed under the branch selected\r\n\t\t\t\t\t\tbelow.</p>\r\n\t\t\t\t\t\t<p><ul>" . $host_list . "</ul></p>\r\n\t\t\t\t\t\t<p><strong>Destination Branch:</strong><br>"; grow_dropdown_tree($matches[1], "tree_item_id", "0"); print "</p>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t</tr>\n\r\n\t\t\t\t<input type='hidden' name='tree_id' value='" . $matches[1] . "'>\n\r\n\t\t\t\t"; $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Place Device(s) on Tree'>"; } else { $save['drp_action'] = $_POST['drp_action']; $save['host_list'] = $host_list; $save['host_array'] = isset($host_array) ? $host_array : array(); api_plugin_hook_function('device_action_prepare', $save); $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue'>"; } } else { print "<tr><td bgcolor='#" . $colors["form_alternate1"] . "'><span class='textError'>You must select at least one device.</span></td></tr>\n"; $save_html = "<input type='button' value='Return' onClick='window.history.back()'>"; } print "\t<tr>\r\n\t\t\t<td colspan='2' align='right' bgcolor='#eaeaea'>\r\n\t\t\t\t<input type='hidden' name='action' value='actions'>\r\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($host_array) ? serialize($host_array) : '') . "'>\r\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST["drp_action"] . "'>\r\n\t\t\t\t{$save_html}\r\n\t\t\t</td>\r\n\t\t</tr>\r\n\t\t"; html_end_box(); include_once "./include/bottom_footer.php"; }
function form_actions() { global $colors, $device_actions, $fields_host_edit; /* if we are to save this form, instead of display it */ if (isset($_POST["selected_items"])) { $selected_items = unserialize(stripslashes($_POST["selected_items"])); if ($_POST["drp_action"] == "2") { /* Enable Selected Devices */ for ($i = 0; $i < count($selected_items); $i++) { db_execute("update host set disabled='' where id='" . $selected_items[$i] . "'"); /* update poller cache */ $data_sources = db_fetch_assoc("select id from data_local where host_id='" . $selected_items[$i] . "'"); if (sizeof($data_sources) > 0) { foreach ($data_sources as $data_source) { update_poller_cache($data_source["id"], false); } } } } elseif ($_POST["drp_action"] == "3") { /* Disable Selected Devices */ for ($i = 0; $i < count($selected_items); $i++) { db_execute("update host set disabled='on' where id='" . $selected_items[$i] . "'"); /* update poller cache */ db_execute("delete from poller_item where host_id='" . $selected_items[$i] . "'"); db_execute("delete from poller_reindex where host_id='" . $selected_items[$i] . "'"); } } elseif ($_POST["drp_action"] == "4") { /* change snmp options */ for ($i = 0; $i < count($selected_items); $i++) { reset($fields_host_edit); while (list($field_name, $field_array) = each($fields_host_edit)) { if (isset($_POST["t_{$field_name}"])) { db_execute("update host set {$field_name} = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'"); } } push_out_host($selected_items[$i]); } } elseif ($_POST["drp_action"] == "6") { /* change poller */ for ($i = 0; $i < count($selected_items); $i++) { reset($fields_host_edit); while (list($field_name, $field_array) = each($fields_host_edit)) { if (isset($_POST["t_{$field_name}"])) { db_execute("update host set {$field_name} = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'"); } } push_out_host($selected_items[$i]); } } elseif ($_POST["drp_action"] == "7") { /* change availability options */ for ($i = 0; $i < count($selected_items); $i++) { reset($fields_host_edit); while (list($field_name, $field_array) = each($fields_host_edit)) { if (isset($_POST["t_{$field_name}"])) { db_execute("update host set {$field_name} = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'"); } } push_out_host($selected_items[$i]); } } elseif ($_POST["drp_action"] == "5") { /* Clear Statisitics for Selected Devices */ for ($i = 0; $i < count($selected_items); $i++) { db_execute("update host set min_time = '9.99999', max_time = '0', cur_time = '0',\tavg_time = '0',\n\t\t\t\t\t\ttotal_polls = '0', failed_polls = '0',\tavailability = '100.00'\n\t\t\t\t\t\twhere id = '" . $selected_items[$i] . "'"); } } elseif ($_POST["drp_action"] == "1") { /* delete */ for ($i = 0; $i < count($selected_items); $i++) { if (!isset($_POST["delete_type"])) { $_POST["delete_type"] = 2; } switch ($_POST["delete_type"]) { case '1': /* leave graphs and data_sources in place, but disable the data sources */ $data_sources = db_fetch_assoc("select id from data_source where " . array_to_sql_or($selected_items, "host_id")); if (sizeof($data_sources) > 0) { foreach ($data_sources as $data_source) { api_data_source_disable($data_source["id"]); } } break; case '2': /* delete graphs/data sources tied to this device */ $data_sources = db_fetch_assoc("select id from data_source where " . array_to_sql_or($selected_items, "host_id")); if (sizeof($data_sources) > 0) { foreach ($data_sources as $data_source) { api_data_source_remove($data_source["id"]); } } $graphs = db_fetch_assoc("select id from graph where " . array_to_sql_or($selected_items, "host_id")); if (sizeof($graphs) > 0) { foreach ($graphs as $graph) { api_graph_remove($graph["id"]); } } break; } api_device_remove($selected_items[$i]); } } header("Location: devices.php"); exit; } /* setup some variables */ $host_list = ""; $i = 0; /* loop through each of the host templates selected on the previous page and get more info about them */ while (list($var, $val) = each($_POST)) { if (ereg("^chk_([0-9]+)\$", $var, $matches)) { $host_list .= "<li>" . db_fetch_cell("select description from host where id=" . $matches[1]) . "<br>"; $host_array[$i] = $matches[1]; } $i++; } require_once CACTI_BASE_PATH . "/include/top_header.php"; html_start_box("<strong>" . $device_actions[$_POST["drp_action"]] . "</strong>", "60%", $colors["header_panel_background"], "3", "center", ""); print "<form action='devices.php' method='post'>\n"; if ($_POST["drp_action"] == "2") { /* Enable Devices */ print "\t<tr>\n\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>" . _("To enable the following devices, press the \"yes\" button below.") . "</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t</td>\n\t\t\t\t</tr>"; } elseif ($_POST["drp_action"] == "3") { /* Disable Devices */ print "\t<tr>\n\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>" . _("To disable the following devices, press the \"yes\" button below.") . "</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t</td>\n\t\t\t\t</tr>"; } elseif ($_POST["drp_action"] == "4") { /* change snmp options */ print "\t<tr>\n\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>" . _("To change SNMP parameters for the following devices, check the box next to the fields\n\t\t\t\t\tyou want to update, fill in the new value, and click Save.") . "</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t</td>\n\t\t\t\t</tr>"; $form_array = array(); while (list($field_name, $field_array) = each($fields_host_edit)) { if (ereg("^snmp_", $field_name) || ereg("^snmpv3_", $field_name)) { $form_array += array($field_name => $fields_host_edit[$field_name]); $form_array[$field_name]["value"] = ""; $form_array[$field_name]["description"] = ""; $form_array[$field_name]["form_id"] = 0; $form_array[$field_name]["sub_checkbox"] = array("name" => "t_" . $field_name, "friendly_name" => _("Update this Field"), "value" => ""); } } draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => $form_array)); } elseif ($_POST["drp_action"] == "6") { /* change poller */ print "\t<tr>\n\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>" . _("To change the poller that will, by default handle the processing for the selected host(s)\n\t\t\t\t\tsimply select the host from the list, toggle the checkbox and select yes.") . "</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t</td>\n\t\t\t\t</tr>"; $form_array = array(); while (list($field_name, $field_array) = each($fields_host_edit)) { if (ereg("^poller_", $field_name)) { $form_array += array($field_name => $fields_host_edit[$field_name]); $form_array[$field_name]["value"] = ""; $form_array[$field_name]["description"] = ""; $form_array[$field_name]["form_id"] = 0; $form_array[$field_name]["sub_checkbox"] = array("name" => "t_" . $field_name, "friendly_name" => _("Update this Field"), "value" => ""); } } draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => $form_array)); } elseif ($_POST["drp_action"] == "7") { /* change availability options */ print "\t<tr>\n\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>" . _("To change the availability detection for your hosts will use by default\n\t\t\t\t\tsimply select the host from the list, make the changes you require and select yes.") . "</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t</td>\n\t\t\t\t</tr>"; $form_array = array(); while (list($field_name, $field_array) = each($fields_host_edit)) { if (ereg("^availability_", $field_name) || ereg("^ping_", $field_name)) { $form_array += array($field_name => $fields_host_edit[$field_name]); $form_array[$field_name]["value"] = ""; $form_array[$field_name]["description"] = ""; $form_array[$field_name]["form_id"] = 0; $form_array[$field_name]["sub_checkbox"] = array("name" => "t_" . $field_name, "friendly_name" => _("Update this Field"), "value" => ""); } } draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => $form_array)); } elseif ($_POST["drp_action"] == "5") { /* Clear Statisitics for Selected Devices */ print "\t<tr>\n\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>" . _("To clear the counters for the following devices, press the \"yes\" button below.") . "</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t</td>\n\t\t\t\t</tr>"; } elseif ($_POST["drp_action"] == "1") { /* delete */ print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>" . _("Are you sure you want to delete the following devices?") . "</p>\n\t\t\t\t\t<p>{$host_list}</p>"; form_radio_button("delete_type", "2", "1", _("Leave all graphs and data sources untouched. Data sources will be disabled however."), "1"); print "<br>"; form_radio_button("delete_type", "2", "2", _("Delete all associated <strong>graphs</strong> and <strong>data sources</strong>."), "1"); print "<br>"; print "</td></tr>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t"; } if (!isset($host_array)) { print "<tr><td bgcolor='#" . $colors["form_alternate1"] . "'><span class='textError'>" . _("You must select at least one device.") . "</span></td></tr>\n"; $save_html = ""; } else { $save_html = "<input type='image' src='" . html_get_theme_images_path("button_yes.gif") . "' alt='" . _("Save") . "' align='absmiddle'>"; } print "\t<tr>\n\t\t\t<td colspan='2' align='right' bgcolor='#" . $colors["buttonbar_background"] . "'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($host_array) ? serialize($host_array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST["drp_action"] . "'>\n\t\t\t\t<a href='devices.php'><img src='" . html_get_theme_images_path("button_no.gif") . "' alt='" . _("Cancel") . "' align='absmiddle' border='0'></a>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n\t\t"; html_end_box(); require_once CACTI_BASE_PATH . "/include/bottom_footer.php"; }
function form_actions() { global $colors, $device_actions, $fields_host_edit; /* if we are to save this form, instead of display it */ if (isset($_POST["selected_items"])) { $selected_items = unserialize(stripslashes($_POST["selected_items"])); if ($_POST["drp_action"] == "2") { /* Enable Selected Devices */ for ($i=0;($i<count($selected_items));$i++) { db_execute("update host set disabled='' where id='" . $selected_items[$i] . "'"); /* update poller cache */ $data_sources = db_fetch_assoc("select id from data_local where host_id='" . $selected_items[$i] . "'"); if (sizeof($data_sources) > 0) { foreach ($data_sources as $data_source) { update_poller_cache($data_source["id"], false); } } } }elseif ($_POST["drp_action"] == "3") { /* Disable Selected Devices */ for ($i=0;($i<count($selected_items));$i++) { db_execute("update host set disabled='on' where id='" . $selected_items[$i] . "'"); /* update poller cache */ db_execute("delete from poller_item where host_id='" . $selected_items[$i] . "'"); db_execute("delete from poller_reindex where host_id='" . $selected_items[$i] . "'"); } }elseif ($_POST["drp_action"] == "4") { /* change snmp options */ for ($i=0;($i<count($selected_items));$i++) { reset($fields_host_edit); while (list($field_name, $field_array) = each($fields_host_edit)) { if (isset($_POST["t_$field_name"])) { db_execute("update host set $field_name = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'"); } } push_out_host($selected_items[$i]); } }elseif ($_POST["drp_action"] == "5") { /* Clear Statisitics for Selected Devices */ for ($i=0;($i<count($selected_items));$i++) { db_execute("update host set min_time = '9.99999', max_time = '0', cur_time = '0', avg_time = '0', total_polls = '0', failed_polls = '0', availability = '100.00' where id = '" . $selected_items[$i] . "'"); } }elseif ($_POST["drp_action"] == "1") { /* delete */ for ($i=0; $i<count($selected_items); $i++) { if (!isset($_POST["delete_type"])) { $_POST["delete_type"] = 2; } switch ($_POST["delete_type"]) { case '2': /* delete graphs/data sources tied to this device */ $data_sources = db_fetch_assoc("select data_local.id as local_data_id from data_local where " . array_to_sql_or($selected_items, "data_local.host_id")); if (sizeof($data_sources) > 0) { foreach ($data_sources as $data_source) { api_data_source_remove($data_source["local_data_id"]); } } $graphs = db_fetch_assoc("select graph_local.id as local_graph_id from graph_local where " . array_to_sql_or($selected_items, "graph_local.host_id")); if (sizeof($graphs) > 0) { foreach ($graphs as $graph) { api_graph_remove($graph["local_graph_id"]); } } break; } api_device_remove($selected_items[$i]); } } header("Location: host.php"); exit; } /* setup some variables */ $host_list = ""; $i = 0; /* loop through each of the host templates selected on the previous page and get more info about them */ while (list($var,$val) = each($_POST)) { if (ereg("^chk_([0-9]+)$", $var, $matches)) { $host_list .= "<li>" . db_fetch_cell("select description from host where id=" . $matches[1]) . "<br>"; $host_array[$i] = $matches[1]; } $i++; } include_once("./include/top_header.php"); html_start_box("<strong>" . $device_actions{$_POST["drp_action"]} . "</strong>", "60%", $colors["header_panel"], "3", "center", ""); print "<form action='host.php' method='post'>\n"; if ($_POST["drp_action"] == "2") { /* Enable Devices */ print " <tr> <td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'> <p>To enable the following devices, press the \"yes\" button below.</p> <p>$host_list</p> </td> </tr>"; }elseif ($_POST["drp_action"] == "3") { /* Disable Devices */ print " <tr> <td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'> <p>To disable the following devices, press the \"yes\" button below.</p> <p>$host_list</p> </td> </tr>"; }elseif ($_POST["drp_action"] == "4") { /* change snmp options */ print " <tr> <td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'> <p>To change SNMP parameters for the following devices, check the box next to the fields you want to update, fill in the new value, and click Save.</p> <p>$host_list</p> </td> </tr>"; $form_array = array(); while (list($field_name, $field_array) = each($fields_host_edit)) { if (ereg("^snmp_", $field_name)) { $form_array += array($field_name => $fields_host_edit[$field_name]); $form_array[$field_name]["value"] = ""; $form_array[$field_name]["description"] = ""; $form_array[$field_name]["form_id"] = 0; $form_array[$field_name]["sub_checkbox"] = array( "name" => "t_" . $field_name, "friendly_name" => "Update this Field", "value" => "" ); } } draw_edit_form( array( "config" => array("no_form_tag" => true), "fields" => $form_array ) ); }elseif ($_POST["drp_action"] == "5") { /* Clear Statisitics for Selected Devices */ print " <tr> <td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'> <p>To clear the counters for the following devices, press the \"yes\" button below.</p> <p>$host_list</p> </td> </tr>"; }elseif ($_POST["drp_action"] == "1") { /* delete */ print " <tr> <td class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'> <p>Are you sure you want to delete the following devices?</p> <p>$host_list</p>"; form_radio_button("delete_type", "2", "1", "Leave all graphs and data sources untouched.", "1"); print "<br>"; form_radio_button("delete_type", "2", "2", "Delete all associated <strong>graphs</strong> and <strong>data sources</strong>.", "1"); print "<br>"; print "</td></tr> </td> </tr>\n "; } if (!isset($host_array)) { print "<tr><td bgcolor='#" . $colors["form_alternate1"]. "'><span class='textError'>You must select at least one device.</span></td></tr>\n"; $save_html = ""; }else{ $save_html = "<input type='image' src='images/button_yes.gif' alt='Save' align='absmiddle'>"; } print " <tr> <td colspan='2' align='right' bgcolor='#eaeaea'> <input type='hidden' name='action' value='actions'> <input type='hidden' name='selected_items' value='" . (isset($host_array) ? serialize($host_array) : '') . "'> <input type='hidden' name='drp_action' value='" . $_POST["drp_action"] . "'> <a href='host.php'><img src='images/button_no.gif' alt='Cancel' align='absmiddle' border='0'></a> $save_html </td> </tr> "; html_end_box(); include_once("./include/bottom_footer.php"); }
function host_new_graphs_save() { $selected_graphs_array = unserialize(stripslashes($_POST["selected_graphs_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: snmp_query_id, 2: graph_template_id, 3: field_name */ if (empty($matches[1])) { /* this is a new graph from template field */ $values["cg"][$matches[2]]["graph_template"][$matches[3]] = $val; } else { /* this is a data query field */ $values["sg"][$matches[1]][$matches[2]]["graph_template"][$matches[3]] = $val; } } elseif (preg_match("/^gi_(\\d+)_(\\d+)_(\\d+)_(\\w+)/", $var, $matches)) { /* 1: snmp_query_id, 2: graph_template_id, 3: graph_template_input_id, 4:field_name */ /* ================= input validation ================= */ input_validate_input_number($matches[3]); /* ==================================================== */ /* we need to find out which graph items will be affected by saving this particular item */ $item_list = db_fetch_assoc("select\n\t\t\t\tgraph_template_item_id\n\t\t\t\tfrom graph_template_input_defs\n\t\t\t\twhere graph_template_input_id=" . $matches[3]); /* loop through each item affected and update column data */ if (sizeof($item_list) > 0) { foreach ($item_list as $item) { if (empty($matches[1])) { /* this is a new graph from template field */ $values["cg"][$matches[2]]["graph_template_item"][$item["graph_template_item_id"]][$matches[4]] = $val; } else { /* this is a data query field */ $values["sg"][$matches[1]][$matches[2]]["graph_template_item"][$item["graph_template_item_id"]][$matches[4]] = $val; } } } } elseif (preg_match("/^d_(\\d+)_(\\d+)_(\\d+)_(\\w+)/", $var, $matches)) { /* 1: snmp_query_id, 2: graph_template_id, 3: data_template_id, 4:field_name */ if (empty($matches[1])) { /* this is a new graph from template field */ $values["cg"][$matches[2]]["data_template"][$matches[3]][$matches[4]] = $val; } else { /* this is a data query field */ $values["sg"][$matches[1]][$matches[2]]["data_template"][$matches[3]][$matches[4]] = $val; } } elseif (preg_match("/^c_(\\d+)_(\\d+)_(\\d+)_(\\d+)/", $var, $matches)) { /* 1: snmp_query_id, 2: graph_template_id, 3: data_template_id, 4:data_input_field_id */ if (empty($matches[1])) { /* this is a new graph from template field */ $values["cg"][$matches[2]]["custom_data"][$matches[3]][$matches[4]] = $val; } else { /* this is a data query field */ $values["sg"][$matches[1]][$matches[2]]["custom_data"][$matches[3]][$matches[4]] = $val; } } elseif (preg_match("/^di_(\\d+)_(\\d+)_(\\d+)_(\\d+)_(\\w+)/", $var, $matches)) { /* 1: snmp_query_id, 2: graph_template_id, 3: data_template_id, 4:local_data_template_rrd_id, 5:field_name */ if (empty($matches[1])) { /* this is a new graph from template field */ $values["cg"][$matches[2]]["data_template_item"][$matches[4]][$matches[5]] = $val; } else { /* this is a data query field */ $values["sg"][$matches[1]][$matches[2]]["data_template_item"][$matches[4]][$matches[5]] = $val; } } } debug_log_clear("new_graphs"); while (list($form_type, $form_array) = each($selected_graphs_array)) { $current_form_type = $form_type; while (list($form_id1, $form_array2) = each($form_array)) { /* enumerate information from the arrays stored in post variables */ if ($form_type == "cg") { $graph_template_id = $form_id1; } elseif ($form_type == "sg") { while (list($form_id2, $form_array3) = each($form_array2)) { $snmp_index_array = $form_array3; $snmp_query_array["snmp_query_id"] = $form_id1; $snmp_query_array["snmp_index_on"] = get_best_data_query_index_type($_POST["host_id"], $form_id1); $snmp_query_array["snmp_query_graph_id"] = $form_id2; } $graph_template_id = db_fetch_cell("select graph_template_id from snmp_query_graph where id=" . $snmp_query_array["snmp_query_graph_id"]); } if ($current_form_type == "cg") { $return_array = create_complete_graph_from_template($graph_template_id, $_POST["host_id"], "", $values["cg"]); debug_log_insert("new_graphs", "Created graph: " . get_graph_title($return_array["local_graph_id"])); /* lastly push host-specific information to our data sources */ if (sizeof($return_array["local_data_id"])) { # we expect at least one data source associated foreach ($return_array["local_data_id"] as $item) { push_out_host($_POST["host_id"], $item); } } else { debug_log_insert("new_graphs", "ERROR: no Data Source associated. Check Template"); } } elseif ($current_form_type == "sg") { while (list($snmp_index, $true) = each($snmp_index_array)) { $snmp_query_array["snmp_index"] = decode_data_query_index($snmp_index, $snmp_query_array["snmp_query_id"], $_POST["host_id"]); $return_array = create_complete_graph_from_template($graph_template_id, $_POST["host_id"], $snmp_query_array, $values["sg"][$snmp_query_array["snmp_query_id"]]); debug_log_insert("new_graphs", "Created graph: " . get_graph_title($return_array["local_graph_id"])); /* lastly push host-specific information to our data sources */ if (sizeof($return_array["local_data_id"])) { # we expect at least one data source associated foreach ($return_array["local_data_id"] as $item) { push_out_host($_POST["host_id"], $item); } } else { debug_log_insert("new_graphs", "ERROR: no Data Source associated. Check Template"); } } } } } }
function form_actions() { global $colors, $ds_actions; /* if we are to save this form, instead of display it */ if (isset($_POST["selected_items"])) { $selected_items = unserialize(stripslashes($_POST["selected_items"])); if ($_POST["drp_action"] == "1") { /* delete */ if (!isset($_POST["delete_type"])) { $_POST["delete_type"] = 1; } switch ($_POST["delete_type"]) { case '2': /* delete all graph items tied to this data source */ $data_template_rrds = db_fetch_assoc("select id from data_template_rrd where " . array_to_sql_or($selected_items, "local_data_id")); /* loop through each data source item */ if (sizeof($data_template_rrds) > 0) { foreach ($data_template_rrds as $item) { db_execute("delete from graph_templates_item where task_item_id=" . $item["id"] . " and local_graph_id > 0"); } } break; case '3': /* delete all graphs tied to this data source */ $graphs = db_fetch_assoc("select\n\t\t\t\t\t\tgraph_templates_graph.local_graph_id\n\t\t\t\t\t\tfrom (data_template_rrd,graph_templates_item,graph_templates_graph)\n\t\t\t\t\t\twhere graph_templates_item.task_item_id=data_template_rrd.id\n\t\t\t\t\t\tand graph_templates_item.local_graph_id=graph_templates_graph.local_graph_id\n\t\t\t\t\t\tand " . array_to_sql_or($selected_items, "data_template_rrd.local_data_id") . "\n\t\t\t\t\t\tand graph_templates_graph.local_graph_id > 0\n\t\t\t\t\t\tgroup by graph_templates_graph.local_graph_id"); if (sizeof($graphs) > 0) { foreach ($graphs as $graph) { api_graph_remove($graph["local_graph_id"]); } } break; } for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); /* ==================================================== */ api_data_source_remove($selected_items[$i]); } } elseif ($_POST["drp_action"] == "2") { /* change graph template */ for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); input_validate_input_number(get_request_var_post("data_template_id")); /* ==================================================== */ change_data_template($selected_items[$i], $_POST["data_template_id"]); } } elseif ($_POST["drp_action"] == "3") { /* change host */ for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); input_validate_input_number(get_request_var_post("host_id")); /* ==================================================== */ db_execute("update data_local set host_id=" . $_POST["host_id"] . " where id=" . $selected_items[$i]); push_out_host($_POST["host_id"], $selected_items[$i]); update_data_source_title_cache($selected_items[$i]); } } elseif ($_POST["drp_action"] == "4") { /* duplicate */ for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); /* ==================================================== */ duplicate_data_source($selected_items[$i], 0, $_POST["title_format"]); } } elseif ($_POST["drp_action"] == "5") { /* data source -> data template */ for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); /* ==================================================== */ data_source_to_data_template($selected_items[$i], $_POST["title_format"]); } } elseif ($_POST["drp_action"] == "6") { /* data source enable */ for ($i = 0; $i < count($selected_items); $i++) { api_data_source_enable($selected_items[$i]); } } elseif ($_POST["drp_action"] == "7") { /* data source disable */ for ($i = 0; $i < count($selected_items); $i++) { api_data_source_disable($selected_items[$i]); } } header("Location: data_sources.php"); exit; } /* setup some variables */ $ds_list = ""; $i = 0; /* loop through each of the graphs selected on the previous page and get more info about them */ while (list($var, $val) = each($_POST)) { if (ereg("^chk_([0-9]+)\$", $var, $matches)) { /* ================= input validation ================= */ input_validate_input_number($matches[1]); /* ==================================================== */ $ds_list .= "<li>" . get_data_source_title($matches[1]) . "<br>"; $ds_array[$i] = $matches[1]; } $i++; } include_once "./include/top_header.php"; html_start_box("<strong>" . $ds_actions[$_POST["drp_action"]] . "</strong>", "60%", $colors["header_panel"], "3", "center", ""); print "<form action='data_sources.php' method='post'>\n"; if ($_POST["drp_action"] == "1") { /* delete */ $graphs = array(); /* find out which (if any) graphs are using this data source, so we can tell the user */ if (isset($ds_array)) { $graphs = db_fetch_assoc("select\n\t\t\t\tgraph_templates_graph.local_graph_id,\n\t\t\t\tgraph_templates_graph.title_cache\n\t\t\t\tfrom (data_template_rrd,graph_templates_item,graph_templates_graph)\n\t\t\t\twhere graph_templates_item.task_item_id=data_template_rrd.id\n\t\t\t\tand graph_templates_item.local_graph_id=graph_templates_graph.local_graph_id\n\t\t\t\tand " . array_to_sql_or($ds_array, "data_template_rrd.local_data_id") . "\n\t\t\t\tand graph_templates_graph.local_graph_id > 0\n\t\t\t\tgroup by graph_templates_graph.local_graph_id\n\t\t\t\torder by graph_templates_graph.title_cache"); } print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>Are you sure you want to delete the following data sources?</p>\n\t\t\t\t\t<p>{$ds_list}</p>\n\t\t\t\t\t"; if (sizeof($graphs) > 0) { print "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td class='textArea'><p class='textArea'>The following graphs are using these data sources:</p>\n"; foreach ($graphs as $graph) { print "<strong>" . $graph["title_cache"] . "</strong><br>\n"; } print "<br>"; form_radio_button("delete_type", "3", "1", "Leave the graphs untouched.", "1"); print "<br>"; form_radio_button("delete_type", "3", "2", "Delete all <strong>graph items</strong> that reference these data sources.", "1"); print "<br>"; form_radio_button("delete_type", "3", "3", "Delete all <strong>graphs</strong> that reference these data sources.", "1"); print "<br>"; print "</td></tr>"; } print "\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t"; } elseif ($_POST["drp_action"] == "2") { /* change graph template */ print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>Choose a data template and click save to change the data template for\n\t\t\t\t\tthe following data souces. Be aware that all warnings will be suppressed during the\n\t\t\t\t\tconversion, so graph data loss is possible.</p>\n\t\t\t\t\t<p>{$ds_list}</p>\n\t\t\t\t\t<p><strong>New Data Template:</strong><br>"; form_dropdown("data_template_id", db_fetch_assoc("select data_template.id,data_template.name from data_template order by data_template.name"), "name", "id", "", "", "0"); print "</p>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t"; } elseif ($_POST["drp_action"] == "3") { /* change host */ print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>Choose a new host for these data sources:</p>\n\t\t\t\t\t<p>{$ds_list}</p>\n\t\t\t\t\t<p><strong>New Host:</strong><br>"; form_dropdown("host_id", db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"), "name", "id", "", "", "0"); print "</p>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t"; } elseif ($_POST["drp_action"] == "4") { /* duplicate */ print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>When you click save, the following data sources will be duplicated. You can\n\t\t\t\t\toptionally change the title format for the new data sources.</p>\n\t\t\t\t\t<p>{$ds_list}</p>\n\t\t\t\t\t<p><strong>Title Format:</strong><br>"; form_text_box("title_format", "<ds_title> (1)", "", "255", "30", "text"); print "</p>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t"; } elseif ($_POST["drp_action"] == "5") { /* data source -> data template */ print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>When you click save, the following data sources will be converted into data templates.\n\t\t\t\t\tYou can optionally change the title format for the new data templates.</p>\n\t\t\t\t\t<p>{$ds_list}</p>\n\t\t\t\t\t<p><strong>Title Format:</strong><br>"; form_text_box("title_format", "<ds_title> Template", "", "255", "30", "text"); print "</p>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t"; } elseif ($_POST["drp_action"] == "6") { /* data source enable */ print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>When you click yes, the following data sources will be enabled.</p>\n\t\t\t\t\t<p>{$ds_list}</p>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t"; } elseif ($_POST["drp_action"] == "7") { /* data source disable */ print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>When you click yes, the following data sources will be disabled.</p>\n\t\t\t\t\t<p>{$ds_list}</p>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t"; } if (!isset($ds_array)) { print "<tr><td bgcolor='#" . $colors["form_alternate1"] . "'><span class='textError'>You must select at least one data source.</span></td></tr>\n"; $save_html = ""; } else { $save_html = "<input type='image' src='images/button_yes.gif' alt='Save' align='absmiddle'>"; } print "\t<tr>\n\t\t\t<td align='right' bgcolor='#eaeaea'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($ds_array) ? serialize($ds_array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST["drp_action"] . "'>\n\t\t\t\t<a href='data_sources.php'><img src='images/button_no.gif' alt='Cancel' align='absmiddle' border='0'></a>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n\t\t"; html_end_box(); include_once "./include/bottom_footer.php"; }
SET title=\"$graphTitle\" WHERE local_graph_id=" . $returnArray["local_graph_id"]); update_graph_title_cache($returnArray["local_graph_id"]); } $dataSourceId = db_fetch_cell("SELECT DISTINCT data_template_rrd.local_data_id FROM graph_templates_item, data_template_rrd WHERE graph_templates_item.local_graph_id = " . $returnArray["local_graph_id"] . " AND graph_templates_item.task_item_id = data_template_rrd.id"); echo "Graph Added - graph-id: (" . $returnArray["local_graph_id"] . ") - data-source-id: ($dataSourceId)\n"; } push_out_host($hostId,0); }else{ echo "ERROR: Could not find snmp-field " . $dsGraph["snmpField"] . " (" . $dsGraph["snmpValue"] . ") for host-id " . $hostId . " (" . $hosts[$hostId]["hostname"] . ")\n"; echo "Try --host-id=" . $hostId . " --list-snmp-fields\n"; exit(1); } }else{ echo "ERROR: Graph Types must be either 'cg' or 'ds'\n"; exit(1); } exit(0); }else{ display_help(); exit(1); }
function form_save() { global $cnn_id; if (isset($_POST["save_component_template"])) { /* ================= input validation ================= */ input_validate_input_number(get_request_var_post("data_input_id")); input_validate_input_number(get_request_var_post("data_template_id")); input_validate_input_number(get_request_var_post("data_template_data_id")); input_validate_input_number(get_request_var_post("data_template_rrd_id")); /* ==================================================== */ /* save: data_template */ $save1["id"] = $_POST["data_template_id"]; $save1["hash"] = get_hash_data_template($_POST["data_template_id"]); $save1["name"] = form_input_validate($_POST["template_name"], "template_name", "", false, 3); /* save: data_template_data */ $save2["id"] = $_POST["data_template_data_id"]; $save2["local_data_template_data_id"] = 0; $save2["local_data_id"] = 0; $save2["data_input_id"] = form_input_validate($_POST["data_input_id"], "data_input_id", "^[0-9]+\$", true, 3); $save2["t_name"] = form_input_validate(isset($_POST["t_name"]) ? $_POST["t_name"] : "", "t_name", "", true, 3); $save2["name"] = form_input_validate($_POST["name"], "name", "", isset($_POST["t_name"]) ? true : false, 3); $save2["t_active"] = form_input_validate(isset($_POST["t_active"]) ? $_POST["t_active"] : "", "t_active", "", true, 3); $save2["active"] = form_input_validate(isset($_POST["active"]) ? $_POST["active"] : "", "active", "", true, 3); $save2["t_rrd_step"] = form_input_validate(isset($_POST["t_rrd_step"]) ? $_POST["t_rrd_step"] : "", "t_rrd_step", "", true, 3); $save2["rrd_step"] = form_input_validate($_POST["rrd_step"], "rrd_step", "^[0-9]+\$", isset($_POST["t_rrd_step"]) ? true : false, 3); $save2["t_rra_id"] = form_input_validate(isset($_POST["t_rra_id"]) ? $_POST["t_rra_id"] : "", "t_rra_id", "", true, 3); /* save: data_template_rrd */ $save3["id"] = $_POST["data_template_rrd_id"]; $save3["hash"] = get_hash_data_template($_POST["data_template_rrd_id"], "data_template_item"); $save3["local_data_template_rrd_id"] = 0; $save3["local_data_id"] = 0; $save3["t_rrd_maximum"] = form_input_validate(isset($_POST["t_rrd_maximum"]) ? $_POST["t_rrd_maximum"] : "", "t_rrd_maximum", "", true, 3); $save3["rrd_maximum"] = form_input_validate($_POST["rrd_maximum"], "rrd_maximum", "^(-?([0-9]+(\\.[0-9]*)?|[0-9]*\\.[0-9]+)([eE][+\\-]?[0-9]+)?)|U\$", isset($_POST["t_rrd_maximum"]) ? true : false, 3); $save3["t_rrd_minimum"] = form_input_validate(isset($_POST["t_rrd_minimum"]) ? $_POST["t_rrd_minimum"] : "", "t_rrd_minimum", "", true, 3); $save3["rrd_minimum"] = form_input_validate($_POST["rrd_minimum"], "rrd_minimum", "^(-?([0-9]+(\\.[0-9]*)?|[0-9]*\\.[0-9]+)([eE][+\\-]?[0-9]+)?)|U\$", isset($_POST["t_rrd_minimum"]) ? true : false, 3); $save3["t_rrd_heartbeat"] = form_input_validate(isset($_POST["t_rrd_heartbeat"]) ? $_POST["t_rrd_heartbeat"] : "", "t_rrd_heartbeat", "", true, 3); $save3["rrd_heartbeat"] = form_input_validate($_POST["rrd_heartbeat"], "rrd_heartbeat", "^[0-9]+\$", isset($_POST["t_rrd_heartbeat"]) ? true : false, 3); $save3["t_data_source_type_id"] = form_input_validate(isset($_POST["t_data_source_type_id"]) ? $_POST["t_data_source_type_id"] : "", "t_data_source_type_id", "", true, 3); $save3["data_source_type_id"] = form_input_validate($_POST["data_source_type_id"], "data_source_type_id", "^[0-9]+\$", true, 3); $save3["t_data_source_name"] = form_input_validate(isset($_POST["t_data_source_name"]) ? $_POST["t_data_source_name"] : "", "t_data_source_name", "", true, 3); $save3["data_source_name"] = form_input_validate($_POST["data_source_name"], "data_source_name", "^[a-zA-Z0-9_]{1,19}\$", isset($_POST["t_data_source_name"]) ? true : false, 3); $save3["t_data_input_field_id"] = form_input_validate(isset($_POST["t_data_input_field_id"]) ? $_POST["t_data_input_field_id"] : "", "t_data_input_field_id", "", true, 3); $save3["data_input_field_id"] = form_input_validate(isset($_POST["data_input_field_id"]) ? $_POST["data_input_field_id"] : "0", "data_input_field_id", "^[0-9]+\$", true, 3); /* ok, first pull out all 'input' values so we know how much to save */ $input_fields = db_fetch_assoc("select\n\t\t\tid,\n\t\t\tinput_output,\n\t\t\tregexp_match,\n\t\t\tallow_nulls,\n\t\t\ttype_code,\n\t\t\tdata_name\n\t\t\tfrom data_input_fields\n\t\t\twhere data_input_id=" . $_POST["data_input_id"] . "\n\t\t\tand input_output='in'"); /* pass 1 for validation */ if (sizeof($input_fields) > 0) { foreach ($input_fields as $input_field) { $form_value = "value_" . $input_field["data_name"]; if (isset($_POST[$form_value]) && $input_field["type_code"] == "") { if (isset($_POST["t_" . $form_value]) && $_POST["t_" . $form_value] == "on") { $not_required = true; } else { if ($input_field["allow_nulls"] == "on") { $not_required = true; } else { $not_required = false; } } form_input_validate($_POST[$form_value], "value_" . $input_field["data_name"], $input_field["regexp_match"], $not_required, 3); } } } if (!is_error_message()) { $data_template_id = sql_save($save1, "data_template"); if ($data_template_id) { raise_message(1); } else { raise_message(2); } } if (!is_error_message()) { $save2["data_template_id"] = $data_template_id; $data_template_data_id = sql_save($save2, "data_template_data"); if ($data_template_data_id) { raise_message(1); } else { raise_message(2); } } /* update actual host template information for live hosts */ if (!is_error_message() && $save2["id"] > 0) { db_execute("update data_template_data set data_input_id = " . $_POST["data_input_id"] . " where data_template_id = " . $_POST["data_template_id"] . ";"); } if (!is_error_message()) { $save3["data_template_id"] = $data_template_id; $data_template_rrd_id = sql_save($save3, "data_template_rrd"); if ($data_template_rrd_id) { raise_message(1); } else { raise_message(2); } } if (!is_error_message()) { /* save entries in 'selected rras' field */ db_execute("delete from data_template_data_rra where data_template_data_id={$data_template_data_id}"); if (isset($_POST["rra_id"])) { for ($i = 0; $i < count($_POST["rra_id"]); $i++) { /* ================= input validation ================= */ input_validate_input_number($_POST["rra_id"][$i]); /* ==================================================== */ db_execute("insert into data_template_data_rra (rra_id,data_template_data_id)\n\t\t\t\t\t\tvalues (" . $_POST["rra_id"][$i] . ",{$data_template_data_id})"); } } if (!empty($_POST["data_template_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); db_execute("delete from data_input_data where data_template_data_id={$data_template_data_id}"); reset($input_fields); if (sizeof($input_fields) > 0) { foreach ($input_fields as $input_field) { $form_value = "value_" . $input_field["data_name"]; if (isset($_POST[$form_value])) { /* save the data into the 'host_template_data' table */ if (isset($_POST["t_value_" . $input_field["data_name"]])) { $template_this_item = "on"; } else { $template_this_item = ""; } if (!empty($form_value) || !empty($_POST["t_value_" . $input_field["data_name"]])) { db_execute("insert into data_input_data (data_input_field_id,data_template_data_id,t_value,value)\n\t\t\t\t\t\t\t\tvalues (" . $input_field["id"] . ",{$data_template_data_id}," . $cnn_id->qstr($template_this_item) . "," . $cnn_id->qstr(trim($_POST[$form_value])) . ")"); } } } } /* push out all "custom data" for this data source template */ push_out_data_source_custom_data($data_template_id); push_out_host(0, 0, $data_template_id); } } header("Location: data_templates.php?action=template_edit&id=" . (empty($data_template_id) ? $_POST["data_template_id"] : $data_template_id) . (empty($_POST["current_rrd"]) ? "" : "&view_rrd=" . ($_POST["current_rrd"] ? $_POST["current_rrd"] : $data_template_rrd_id))); } }
function create_cg_graph($args) { $hostId = $args["hostId"]; $description = $args["description"]; $templateId = $args["GraphTemplateId"]; $values["cg"] = array(); // Not doing anything with this for now if (!isset($hostId) || !isset($description) || !isset($templateId)) { echo "ERROR: create_cg_graph: Missing required arguments\n"; exit(1); } $existsAlready = db_fetch_cell("SELECT id \n FROM graph_local \n WHERE graph_template_id={$templateId} \n AND host_id={$hostId}"); if (isset($existsAlready) && $existsAlready > 0) { debug("{$description}: Graph already exists: ({$existsAlready})"); return 0; } else { $returnArray = create_complete_graph_from_template($templateId, $hostId, "", $values["cg"]); echo "{$description}: Added Graph id: " . $returnArray["local_graph_id"] . "\n"; push_out_host($hostId, 0); return 1; } }
update_data_source_title_cache($dataSourceId); } /* modify for multi user end */ echo "NOTE: Not Adding Graph - this graph already exists - graph-id: ({$existsAlready}) - data-source-id: ({$dataSourceId})\n"; continue; } $empty = array(); /* Suggested Values are not been implemented */ $returnArray = create_complete_graph_from_template($templateId, $hostId, $snmp_query_array, $empty); if ($graphTitle != "") { db_execute("UPDATE graph_templates_graph\r\n\t\t\t\t\t\tSET title=\"{$graphTitle}\"\r\n\t\t\t\t\t\tWHERE local_graph_id=" . $returnArray["local_graph_id"]); update_graph_title_cache($returnArray["local_graph_id"]); } $dataSourceId = db_fetch_cell("SELECT\r\n\t\t\t\t\tdata_template_rrd.local_data_id\r\n\t\t\t\t\tFROM graph_templates_item, data_template_rrd\r\n\t\t\t\t\tWHERE graph_templates_item.local_graph_id = " . $returnArray["local_graph_id"] . "\r\n\t\t\t\t\tAND graph_templates_item.task_item_id = data_template_rrd.id\r\n\t\t\t\t\tLIMIT 1"); foreach ($returnArray["local_data_id"] as $item) { push_out_host($hostId, $item); if (strlen($dataSourceId)) { $dataSourceId .= ", " . $item; } else { $dataSourceId = $item; } } echo "Graph Added - graph-id: (" . $returnArray["local_graph_id"] . ") - data-source-ids: ({$dataSourceId})\n"; } } else { echo "ERROR: Could not find snmp-field " . $dsGraph["snmpField"] . " (" . $dsGraph["snmpValue"] . ") for host-id " . $hostId . " (" . $hosts[$hostId]["hostname"] . ")\n"; echo "Try --host-id=" . $hostId . " --list-snmp-fields\n"; exit(1); } } else { echo "ERROR: Graph Types must be either 'cg' or 'ds'\n";
function api_device_save($id, $host_template_id, $description, $hostname, $snmp_community, $snmp_version, $snmp_username, $snmp_password, $snmp_port, $snmp_timeout, $disabled, $availability_method, $ping_method, $ping_port, $ping_timeout, $ping_retries, $notes, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $max_oids, $device_threads) { global $config; include_once $config['base_path'] . '/lib/utility.php'; include_once $config['base_path'] . '/lib/variables.php'; include_once $config['base_path'] . '/lib/data_query.php'; /* fetch some cache variables */ if (empty($id)) { $_host_template_id = 0; } else { $_host_template_id = db_fetch_cell_prepared('SELECT host_template_id FROM host WHERE id=?', array($id)); } $save['id'] = form_input_validate($id, 'id', '^[0-9]+$', false, 3); $save['host_template_id'] = form_input_validate($host_template_id, 'host_template_id', '^[0-9]+$', false, 3); $save['description'] = form_input_validate($description, 'description', '', false, 3); $save['hostname'] = form_input_validate(trim($hostname), 'hostname', '', false, 3); $save['notes'] = form_input_validate($notes, 'notes', '', true, 3); $save['snmp_version'] = form_input_validate($snmp_version, 'snmp_version', '', true, 3); $save['snmp_community'] = form_input_validate($snmp_community, 'snmp_community', '', true, 3); if ($save['snmp_version'] == 3) { $save['snmp_username'] = form_input_validate($snmp_username, 'snmp_username', '', true, 3); $save['snmp_password'] = form_input_validate($snmp_password, 'snmp_password', '', true, 3); $save['snmp_auth_protocol'] = form_input_validate($snmp_auth_protocol, 'snmp_auth_protocol', "^\\[None\\]|MD5|SHA\$", true, 3); $save['snmp_priv_passphrase'] = form_input_validate($snmp_priv_passphrase, 'snmp_priv_passphrase', '', true, 3); $save['snmp_priv_protocol'] = form_input_validate($snmp_priv_protocol, 'snmp_priv_protocol', "^\\[None\\]|DES|AES128\$", true, 3); $save['snmp_context'] = form_input_validate($snmp_context, 'snmp_context', '', true, 3); } else { $save['snmp_username'] = ''; $save['snmp_password'] = ''; $save['snmp_auth_protocol'] = ''; $save['snmp_priv_passphrase'] = ''; $save['snmp_priv_protocol'] = ''; $save['snmp_context'] = ''; } $save['snmp_port'] = form_input_validate($snmp_port, 'snmp_port', '^[0-9]+$', false, 3); $save['snmp_timeout'] = form_input_validate($snmp_timeout, 'snmp_timeout', '^[0-9]+$', false, 3); /* disabled = 'on' => regexp '^on$' * not disabled = '' => no regexp, but allow nulls */ $save['disabled'] = form_input_validate($disabled, 'disabled', '^on$', true, 3); $save['availability_method'] = form_input_validate($availability_method, 'availability_method', '^[0-9]+$', false, 3); $save['ping_method'] = form_input_validate($ping_method, 'ping_method', '^[0-9]+$', false, 3); $save['ping_port'] = form_input_validate($ping_port, 'ping_port', '^[0-9]+$', true, 3); $save['ping_timeout'] = form_input_validate($ping_timeout, 'ping_timeout', '^[0-9]+$', true, 3); $save['ping_retries'] = form_input_validate($ping_retries, 'ping_retries', '^[0-9]+$', true, 3); $save['max_oids'] = form_input_validate($max_oids, 'max_oids', '^[0-9]+$', true, 3); $save['device_threads'] = form_input_validate($device_threads, 'device_threads', '^[0-9]+$', true, 3); $save = api_plugin_hook_function('api_device_save', $save); $host_id = 0; if (!is_error_message()) { $host_id = sql_save($save, 'host'); if ($host_id) { raise_message(1); /* push out relavant fields to data sources using this host */ push_out_host($host_id, 0); /* the host substitution cache is now stale; purge it */ kill_session_var('sess_host_cache_array'); /* update title cache for graph and data source */ update_data_source_title_cache_from_host($host_id); update_graph_title_cache_from_host($host_id); } else { raise_message(2); } /* if the user changes the host template, add each snmp query associated with it */ if ($host_template_id != $_host_template_id && !empty($host_template_id)) { $snmp_queries = db_fetch_assoc_prepared('SELECT snmp_query_id FROM host_template_snmp_query WHERE host_template_id = ?', array($host_template_id)); if (sizeof($snmp_queries) > 0) { foreach ($snmp_queries as $snmp_query) { db_execute_prepared('REPLACE INTO host_snmp_query (host_id, snmp_query_id, reindex_method) VALUES (?, ?, ?)', array($host_id, $snmp_query['snmp_query_id'], read_config_option('reindex_method'))); /* recache snmp data */ run_data_query($host_id, $snmp_query['snmp_query_id']); } } $graph_templates = db_fetch_assoc_prepared('SELECT graph_template_id FROM host_template_graph WHERE host_template_id = ?', array($host_template_id)); if (sizeof($graph_templates) > 0) { foreach ($graph_templates as $graph_template) { db_execute_prepared('REPLACE INTO host_graph (host_id, graph_template_id) VALUES (?, ?)', array($host_id, $graph_template['graph_template_id'])); api_plugin_hook_function('add_graph_template_to_host', array('host_id' => $host_id, 'graph_template_id' => $graph_template['graph_template_id'])); } } } } # now that we have the id of the new host, we may plugin postprocessing code $save['id'] = $host_id; snmpagent_api_device_new($save); api_plugin_hook_function('api_device_new', $save); return $host_id; }