Ejemplo n.º 1
0
function mikrotik_view_graphs()
{
    global $current_user, $colors, $config;
    if (file_exists("./lib/timespan_settings.php")) {
        include "./lib/timespan_settings.php";
    } else {
        include "./include/html/inc_timespan_settings.php";
    }
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var("rra_id"));
    input_validate_input_number(get_request_var("host"));
    input_validate_input_number(get_request_var("cols"));
    input_validate_input_regex(get_request_var_request('graph_list'), "^([\\,0-9]+)\$");
    input_validate_input_regex(get_request_var_request('graph_add'), "^([\\,0-9]+)\$");
    input_validate_input_regex(get_request_var_request('graph_remove'), "^([\\,0-9]+)\$");
    /* ==================================================== */
    define("ROWS_PER_PAGE", read_graph_config_option("preview_graphs_per_page"));
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request("graph_template_id"));
    input_validate_input_number(get_request_var_request("page"));
    /* ==================================================== */
    /* clean up search string */
    if (isset($_REQUEST["filter"])) {
        $_REQUEST["filter"] = sanitize_search_string(get_request_var_request("filter"));
    }
    /* clean up styl string */
    if (isset($_REQUEST["style"])) {
        $_REQUEST["style"] = sanitize_search_string(get_request_var_request("style"));
    }
    /* clean up styl string */
    if (isset($_REQUEST["thumb"])) {
        $_REQUEST["thumb"] = sanitize_search_string(get_request_var_request("thumb"));
    }
    $sql_or = "";
    $sql_where = "";
    $sql_join = "";
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST["reset"])) {
        kill_session_var("sess_mikrotik_graph_current_page");
        kill_session_var("sess_mikrotik_graph_filter");
        kill_session_var("sess_mikrotik_graph_host");
        kill_session_var("sess_mikrotik_graph_cols");
        kill_session_var("sess_mikrotik_graph_thumb");
        kill_session_var("sess_mikrotik_graph_add");
        kill_session_var("sess_mikrotik_graph_style");
        kill_session_var("sess_mikrotik_graph_graph_template");
    } elseif (isset($_REQUEST["clear"])) {
        kill_session_var("sess_mikrotik_graph_current_page");
        kill_session_var("sess_mikrotik_graph_filter");
        kill_session_var("sess_mikrotik_graph_host");
        kill_session_var("sess_mikrotik_graph_cols");
        kill_session_var("sess_mikrotik_graph_thumb");
        kill_session_var("sess_mikrotik_graph_add");
        kill_session_var("sess_mikrotik_graph_style");
        kill_session_var("sess_mikrotik_graph_graph_template");
        unset($_REQUEST["page"]);
        unset($_REQUEST["filter"]);
        unset($_REQUEST["host"]);
        unset($_REQUEST["cols"]);
        unset($_REQUEST["thumb"]);
        unset($_REQUEST["graph_template_id"]);
        unset($_REQUEST["graph_list"]);
        unset($_REQUEST["graph_add"]);
        unset($_REQUEST["style"]);
        unset($_REQUEST["graph_remove"]);
    } else {
        /* if any of the settings changed, reset the page number */
        $changed = false;
        $changed += mikrotik_check_changed("fitler", "sess_mikrotik_graph_filter");
        $changed += mikrotik_check_changed("host", "sess_mikrotik_graph_host");
        $changed += mikrotik_check_changed("style", "sess_mikrotik_graph_style");
        $changed += mikrotik_check_changed("graph_add", "sess_mikrotik_graph_add");
        $changed += mikrotik_check_changed("graph_template_id", "sess_mikrotik_graph_graph_template");
        if ($changed) {
            $_REQUEST["page"] = "1";
            $_REQUEST["style"] = "";
            $_REQUEST["graph_add"] = "";
        }
    }
    load_current_session_value("graph_template_id", "sess_mikrotik_graph_graph_template", "0");
    load_current_session_value("host", "sess_mikrotik_graph_host", "0");
    load_current_session_value("cols", "sess_mikrotik_graph_cols", "2");
    load_current_session_value("thumb", "sess_mikrotik_graph_thumb", "true");
    load_current_session_value("graph_add", "sess_mikrotik_graph_add", "");
    load_current_session_value("style", "sess_mikrotik_graph_style", "");
    load_current_session_value("filter", "sess_mikrotik_graph_filter", "");
    load_current_session_value("page", "sess_mikrotik_graph_current_page", "1");
    if ($_REQUEST["graph_add"] != "") {
        $_REQUEST["style"] = "selective";
    }
    /* graph permissions */
    if (read_config_option("auth_method") != 0) {
        $sql_where = "WHERE " . get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]);
        $sql_join = "LEFT JOIN host ON (host.id=graph_local.host_id)\n\t\t\tLEFT JOIN graph_templates\n\t\t\tON (graph_templates.id=graph_local.graph_template_id)\n\t\t\tLEFT JOIN user_auth_perms\n\t\t\tON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id\n\t\t\tAND user_auth_perms.type=1\n\t\t\tAND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ")\n\t\t\tOR (host.id=user_auth_perms.item_id AND user_auth_perms.type=3 AND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ")\n\t\t\tOR (graph_templates.id=user_auth_perms.item_id AND user_auth_perms.type=4 AND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . "))";
    } else {
        $sql_where = "";
        $sql_join = "";
    }
    /* the user select a bunch of graphs of the 'list' view and wants them dsplayed here */
    if (isset($_REQUEST["style"])) {
        if ($_REQUEST["style"] == "selective") {
            /* process selected graphs */
            if (!empty($_REQUEST["graph_list"])) {
                foreach (explode(",", $_REQUEST["graph_list"]) as $item) {
                    $graph_list[$item] = 1;
                }
            } else {
                $graph_list = array();
            }
            if (!empty($_REQUEST["graph_add"])) {
                foreach (explode(",", $_REQUEST["graph_add"]) as $item) {
                    $graph_list[$item] = 1;
                }
            }
            /* remove items */
            if (!empty($_REQUEST["graph_remove"])) {
                foreach (explode(",", $_REQUEST["graph_remove"]) as $item) {
                    unset($graph_list[$item]);
                }
            }
            $i = 0;
            foreach ($graph_list as $item => $value) {
                $graph_array[$i] = $item;
                $i++;
            }
            if (isset($graph_array) && sizeof($graph_array) > 0) {
                /* build sql string including each graph the user checked */
                $sql_or = "AND " . array_to_sql_or($graph_array, "graph_templates_graph.local_graph_id");
                /* clear the filter vars so they don't affect our results */
                $_REQUEST["filter"] = "";
                $set_rra_id = empty($rra_id) ? read_graph_config_option("default_rra_id") : $_REQUEST["rra_id"];
            }
        }
    }
    $sql_base = "FROM (graph_templates_graph,graph_local)\n\t\t{$sql_join}\n\t\t{$sql_where}\n\t\t" . (empty($sql_where) ? "WHERE" : "AND") . "   graph_templates_graph.local_graph_id > 0\n\t\tAND graph_templates_graph.local_graph_id=graph_local.id\n\t\t" . (strlen($_REQUEST["filter"]) ? "AND graph_templates_graph.title_cache like '%%" . $_REQUEST["filter"] . "%%'" : "") . "\n\t\t" . (empty($_REQUEST["graph_template_id"]) ? "" : " and graph_local.graph_template_id=" . $_REQUEST["graph_template_id"]) . "\n\t\t" . (empty($_REQUEST["host"]) ? "" : " and graph_local.host_id=" . $_REQUEST["host"]) . "\n\t\t{$sql_or}";
    $total_rows = count(db_fetch_assoc("SELECT\n\t\tgraph_templates_graph.local_graph_id\n\t\t{$sql_base}"));
    /* reset the page if you have changed some settings */
    if (ROWS_PER_PAGE * ($_REQUEST["page"] - 1) >= $total_rows) {
        $_REQUEST["page"] = "1";
    }
    $graphs = db_fetch_assoc("SELECT\n\t\tgraph_templates_graph.local_graph_id,\n\t\tgraph_templates_graph.title_cache\n\t\t{$sql_base}\n\t\tGROUP BY graph_templates_graph.local_graph_id\n\t\tORDER BY graph_templates_graph.title_cache\n\t\tLIMIT " . ROWS_PER_PAGE * ($_REQUEST["page"] - 1) . "," . ROWS_PER_PAGE);
    ?>
	<script type="text/javascript">
	<!--
	function applyGraphWReset(objForm) {
		strURL = '?action=graphs&reset=1&graph_template_id=' + objForm.graph_template_id.value;
		strURL = strURL + '&host=' + objForm.host.value;
		strURL = strURL + '&cols=' + objForm.cols.value;
		strURL = strURL + '&thumb=' + objForm.thumb.checked;
		strURL = strURL + '&filter=' + objForm.filter.value;
		document.location = strURL;
	}
	function applyGraphWOReset(objForm) {
		strURL = '?action=graphs&graph_template_id=' + objForm.graph_template_id.value;
		strURL = strURL + '&host=' + objForm.host.value;
		strURL = strURL + '&cols=' + objForm.cols.value;
		strURL = strURL + '&thumb=' + objForm.thumb.checked;
		strURL = strURL + '&filter=' + objForm.filter.value;
		document.location = strURL;
	}
	-->
	</script>
	<?php 
    html_start_box("<strong>Host MIB Graphs" . ($_REQUEST["style"] == "selective" ? " (Custom Selective Filter)" : "") . "</strong>", "100%", $colors["header"], "1", "center", "");
    mikrotik_graph_view_filter();
    /* include time span selector */
    if (read_graph_config_option("timespan_sel") == "on") {
        mikrotik_timespan_selector();
    }
    html_end_box();
    /* do some fancy navigation url construction so we don't have to try and rebuild the url string */
    if (ereg("page=[0-9]+", basename($_SERVER["QUERY_STRING"]))) {
        $nav_url = str_replace("page=" . $_REQUEST["page"], "page=<PAGE>", basename($_SERVER["PHP_SELF"]) . "?" . $_SERVER["QUERY_STRING"]);
    } else {
        $nav_url = basename($_SERVER["PHP_SELF"]) . "?" . $_SERVER["QUERY_STRING"] . "&page=<PAGE>";
    }
    $nav_url = ereg_replace("((\\?|&)filter=[a-zA-Z0-9]*)", "", $nav_url);
    html_start_box("", "100%", $colors["header"], "3", "center", "");
    mikrotik_nav_bar($_REQUEST["page"], ROWS_PER_PAGE, $total_rows, $nav_url);
    mikrotik_graph_area($graphs, "", "graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end(), "", $_REQUEST["cols"], $_REQUEST["thumb"]);
    if ($total_rows) {
        mikrotik_nav_bar($_REQUEST["page"], ROWS_PER_PAGE, $total_rows, $nav_url);
    }
    html_end_box();
}
Ejemplo n.º 2
0
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 */
                $data_template_datas = db_fetch_assoc("select id from data_template_data where " . array_to_sql_or($selected_items, "data_template_id") . " and local_data_id=0");
                if (sizeof($data_template_datas) > 0) {
                    foreach ($data_template_datas as $data_template_data) {
                        db_execute("delete from data_template_data_rra where data_template_data_id=" . $data_template_data["id"]);
                    }
                }
                db_execute("delete from data_template_data where " . array_to_sql_or($selected_items, "data_template_id") . " and local_data_id=0");
                db_execute("delete from data_template_rrd where " . array_to_sql_or($selected_items, "data_template_id") . " and local_data_id=0");
                db_execute("delete from snmp_query_graph_rrd where " . array_to_sql_or($selected_items, "data_template_id"));
                db_execute("delete from snmp_query_graph_rrd_sv where " . array_to_sql_or($selected_items, "data_template_id"));
                db_execute("delete from data_template where " . array_to_sql_or($selected_items, "id"));
                /* "undo" any graph that is currently using this template */
                db_execute("update data_template_data set local_data_template_data_id=0,data_template_id=0 where " . array_to_sql_or($selected_items, "data_template_id"));
                db_execute("update data_template_rrd set local_data_template_rrd_id=0,data_template_id=0 where " . array_to_sql_or($selected_items, "data_template_id"));
                db_execute("update data_local set data_template_id=0 where " . array_to_sql_or($selected_items, "data_template_id"));
            } elseif ($_POST["drp_action"] == "2") {
                /* duplicate */
                for ($i = 0; $i < count($selected_items); $i++) {
                    duplicate_data_source(0, $selected_items[$i], $_POST["title_format"]);
                }
            }
        }
        header("Location: data_templates.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(db_fetch_cell("select name from data_template where id=" . $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_templates.php' method='post'>\n";
    if (isset($ds_array) && sizeof($ds_array)) {
        if ($_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 Data Template(s) will be deleted.  Any data sources attached\n\t\t\t\t\t\tto these templates will become individual Data Source(s) and all Templating benefits will be removed.</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()'>&nbsp;<input type='submit' value='Continue' title='Delete Data Template(s)'>";
        } elseif ($_POST["drp_action"] == "2") {
            /* 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 Template(s) will be duplicated. You can\n\t\t\t\t\t\toptionally 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", "<template_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()'>&nbsp;<input type='submit' value='Continue' title='Duplicate Data Template(s)'>";
        }
    } else {
        print "<tr><td class='even'><span class='textError'>You must select at least one data template.</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";
}
Ejemplo n.º 3
0
function form_actions() {
	global $colors, $graph_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 */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */

				if (!isset($_POST["delete_type"])) { $_POST["delete_type"] = 1; }

				switch ($_POST["delete_type"]) {
					case '2': /* delete all data sources referenced by this graph */
						$data_sources = db_fetch_assoc("SELECT " .
								"data_template_data.local_data_id " .
							"FROM " .
								"(data_template_rrd, " .
								"data_template_data, " .
								"graph_templates_item) " .
							"WHERE " .
								"graph_templates_item.task_item_id=data_template_rrd.id " .
								"AND data_template_rrd.local_data_id=data_template_data.local_data_id " .
								"AND graph_templates_item.local_graph_id=" . $selected_items[$i] . " " .
								"AND data_template_data.local_data_id > 0");

						if (sizeof($data_sources) > 0) {
							foreach ($data_sources as $data_source) {
								api_data_source_remove($data_source["local_data_id"]);
							}
						}

						break;
				}

				api_graph_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("graph_template_id"));
				/* ==================================================== */

				change_graph_template($selected_items[$i], $_POST["graph_template_id"], true);
			}
		}elseif ($_POST["drp_action"] == "3") { /* duplicate */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */

				duplicate_graph($selected_items[$i], 0, $_POST["title_format"]);
			}
		}elseif ($_POST["drp_action"] == "4") { /* graph -> graph template */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */

				graph_to_graph_template($selected_items[$i], $_POST["title_format"]);
			}
		}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_GRAPH, $_POST["tree_item_id"], "", $selected_items[$i], read_graph_config_option("default_rra_id"), 0, 0, 0, false);
			}
		}elseif ($_POST["drp_action"] == "5") { /* 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 graph_local set host_id=" . $_POST["host_id"] . " where id=" . $selected_items[$i]);
				update_graph_title_cache($selected_items[$i]);
			}
		}elseif ($_POST["drp_action"] == "6") { /* reapply suggested naming */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */

				api_reapply_suggested_graph_title($selected_items[$i]);
				update_graph_title_cache($selected_items[$i]);
			}
		}elseif ($_POST["drp_action"] == "7") { /* resize graphs */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */

				api_resize_graphs($selected_items[$i], $_POST["graph_width"], $_POST["graph_height"]);
			}
		}

		header("Location: graphs.php");
		exit;
	}

	/* setup some variables */
	$graph_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]);
			/* ==================================================== */

			$graph_list .= "<li>" . get_graph_title($matches[1]) . "<br>";
			$graph_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>" . $graph_actions{$_POST["drp_action"]} . "</strong>", "60%", $colors["header_panel"], "3", "center", "");

	print "<form action='graphs.php' method='post'>\n";

	if ($_POST["drp_action"] == "1") { /* delete */
		$graphs = array();

		/* find out which (if any) data sources are being used by this graph, so we can tell the user */
		if (isset($graph_array)) {
			$data_sources = db_fetch_assoc("select
				data_template_data.local_data_id,
				data_template_data.name_cache
				from (data_template_rrd,data_template_data,graph_templates_item)
				where graph_templates_item.task_item_id=data_template_rrd.id
				and data_template_rrd.local_data_id=data_template_data.local_data_id
				and " . array_to_sql_or($graph_array, "graph_templates_item.local_graph_id") . "
				and data_template_data.local_data_id > 0
				group by data_template_data.local_data_id
				order by data_template_data.name_cache");
		}

		print "	<tr>
				<td class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
					<p>Are you sure you want to delete the following graphs?</p>
					<p>$graph_list</p>
					";
					if (sizeof($data_sources) > 0) {
						print "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td class='textArea'><p class='textArea'>The following data sources are in use by these graphs:</p>\n";

						foreach ($data_sources as $data_source) {
							print "<strong>" . $data_source["name_cache"] . "</strong><br>\n";
						}

						print "<br>";
						form_radio_button("delete_type", "1", "1", "Leave the data sources untouched.", "1"); print "<br>";
						form_radio_button("delete_type", "1", "2", "Delete all <strong>data sources</strong> referenced by these graphs.", "1"); print "<br>";
						print "</td></tr>";
					}
				print "
				</td>
			</tr>\n
			";
	}elseif ($_POST["drp_action"] == "2") { /* change graph template */
		print "	<tr>
				<td class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
					<p>Choose a graph template and click save to change the graph template for
					the following graphs. Be aware that all warnings will be suppressed during the
					conversion, so graph data loss is possible.</p>
					<p>$graph_list</p>
					<p><strong>New Graph Template:</strong><br>"; form_dropdown("graph_template_id",db_fetch_assoc("select graph_templates.id,graph_templates.name from graph_templates order by name"),"name","id","","","0"); print "</p>
				</td>
			</tr>\n
			";
	}elseif ($_POST["drp_action"] == "3") { /* duplicate */
		print "	<tr>
				<td class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
					<p>When you click save, the following graphs will be duplicated. You can
					optionally change the title format for the new graphs.</p>
					<p>$graph_list</p>
					<p><strong>Title Format:</strong><br>"; form_text_box("title_format", "<graph_title> (1)", "", "255", "30", "text"); print "</p>
				</td>
			</tr>\n
			";
	}elseif ($_POST["drp_action"] == "4") { /* graph -> graph template */
		print "	<tr>
				<td class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
					<p>When you click save, the following graphs will be converted into graph templates.
					You can optionally change the title format for the new graph templates.</p>
					<p>$graph_list</p>
					<p><strong>Title Format:</strong><br>"; form_text_box("title_format", "<graph_title> Template", "", "255", "30", "text"); print "</p>
				</td>
			</tr>\n
			";
	}elseif (ereg("^tr_([0-9]+)$", $_POST["drp_action"], $matches)) { /* place on tree */
		print "	<tr>
				<td class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
					<p>When you click save, the following graphs will be placed under the branch selected
					below.</p>
					<p>$graph_list</p>
					<p><strong>Destination Branch:</strong><br>"; grow_dropdown_tree($matches[1], "tree_item_id", "0"); print "</p>
				</td>
			</tr>\n
			<input type='hidden' name='tree_id' value='" . $matches[1] . "'>\n
			";
	}elseif ($_POST["drp_action"] == "5") { /* change host */
		print "	<tr>
				<td class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
					<p>Choose a new host for these graphs:</p>
					<p>$graph_list</p>
					<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>
				</td>
			</tr>\n
			";
	}elseif ($_POST["drp_action"] == "6") { /* reapply suggested naming to host */
		print "	<tr>
				<td class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
					<p>When you click save, the following graphs will have thier suggested naming convensions
					recalculated and applies to the graphs.</p>
					<p>$graph_list</p>
				</td>
			</tr>\n
			";
	}elseif ($_POST["drp_action"] == "7") { /* reapply suggested naming to host */
		print "	<tr>
				<td class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
					<p>When you click save, the following graphs will be resized per your specifications.</p>
					<p>$graph_list</p>
					<p><strong>Graph Height:</strong><br>"; form_text_box("graph_height", "", "", "255", "30", "text"); print "</p>
					<p><strong>Graph Width:</strong><br>"; form_text_box("graph_width", "", "", "255", "30", "text"); print "</p>
				</td>
			</tr>\n
			";
	}

	if (!isset($graph_array)) {
		print "<tr><td bgcolor='#" . $colors["form_alternate1"]. "'><span class='textError'>You must select at least one graph.</span></td></tr>\n";
		$save_html = "";
	}else{
		$save_html = "<input type='image' src='images/button_yes.gif' alt='Save' align='absmiddle'>";
	}

	print "	<tr>
			<td align='right' bgcolor='#eaeaea'>
				<input type='hidden' name='action' value='actions'>
				<input type='hidden' name='selected_items' value='" . (isset($graph_array) ? serialize($graph_array) : '') . "'>
				<input type='hidden' name='drp_action' value='" . $_POST["drp_action"] . "'>
				<a href='graphs.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");
}
Ejemplo n.º 4
0
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");
}
Ejemplo n.º 5
0
function form_actions()
{
    global $host_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 */
            db_execute('DELETE FROM host_template WHERE ' . array_to_sql_or($selected_items, 'id'));
            db_execute('DELETE FROM host_template_snmp_query WHERE ' . array_to_sql_or($selected_items, 'host_template_id'));
            db_execute('DELETE FROM host_template_graph WHERE ' . array_to_sql_or($selected_items, 'host_template_id'));
            /* "undo" any device that is currently using this template */
            db_execute('UPDATE host SET host_template_id=0 WHERE ' . array_to_sql_or($selected_items, 'host_template_id'));
        } elseif ($_POST['drp_action'] == '2') {
            /* duplicate */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                duplicate_host_template($selected_items[$i], $_POST['title_format']);
            }
        }
        header('Location: host_templates.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 name FROM host_template WHERE id = ?'), array($matches[1])) . '<br>';
            $host_array[$i] = $matches[1];
            $i++;
        }
    }
    top_header();
    html_start_box('<strong>' . $host_actions[$_POST['drp_action']] . '</strong>', '60%', '', '3', 'center', '');
    print "<form action='host_templates.php' autocomplete='off' method='post'>\n";
    if (isset($host_array) && sizeof($host_array)) {
        if ($_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>Are you sure you want to delete the following Device Template(s)? All Devices currently associated\n\t\t\t\t\t\twith these Device Template(s) will lose that assocation.</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</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Delete Device Template(s)'>";
        } elseif ($_POST['drp_action'] == '2') {
            /* 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 Device Template(s) will be duplicated. You can\n\t\t\t\t\t\toptionally change the title format for the new Device Template(s).</p>\n\t\t\t\t\t\t<p><ul>{$host_list}</ul></p>\n\t\t\t\t\t\t<p><strong>Title Format:</strong><br>";
            form_text_box('title_format', '<template_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()'>&nbsp;<input type='submit' value='Continue' title='Duplicate Device Template(s)'>";
        }
    } else {
        print "<tr><td class='even'><span class='textError'>You must select at least one host template.</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($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();
}
Ejemplo n.º 6
0
function form_actions()
{
    /* modify for multi user start */
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        $rows = db_fetch_assoc("\r\n            SELECT graph_local.id FROM graph_local \r\n                INNER JOIN host ON graph_local.host_id = host.id\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) {
            $graphs[] = $row["id"];
        }
    }
    /* modify for multi user end */
    global $colors, $graph_actions;
    /* 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], $graphs)) {
                    access_denied();
                }
            }
        }
        /* modify for multi user end */
        if ($_POST["drp_action"] == "1") {
            /* delete */
            if (!isset($_POST["delete_type"])) {
                $_POST["delete_type"] = 1;
            }
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
            }
            switch ($_POST["delete_type"]) {
                case '2':
                    /* delete all data sources referenced by this graph */
                    $data_sources = array_rekey(db_fetch_assoc("SELECT data_template_data.local_data_id\r\n\t\t\t\t\t\tFROM (data_template_rrd, data_template_data, graph_templates_item)\r\n\t\t\t\t\t\tWHERE graph_templates_item.task_item_id=data_template_rrd.id\r\n\t\t\t\t\t\tAND data_template_rrd.local_data_id=data_template_data.local_data_id\r\n\t\t\t\t\t\tAND " . array_to_sql_or($selected_items, "graph_templates_item.local_graph_id") . "\r\n\t\t\t\t\t\tAND data_template_data.local_data_id > 0"), "local_data_id", "local_data_id");
                    if (sizeof($data_sources)) {
                        api_data_source_remove_multi($data_sources);
                        api_plugin_hook_function('data_source_remove', $data_sources);
                    }
                    break;
            }
            api_graph_remove_multi($selected_items);
            api_plugin_hook_function('graphs_remove', $selected_items);
        } elseif ($_POST["drp_action"] == "2") {
            /* change graph template */
            input_validate_input_number(get_request_var_post("graph_template_id"));
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                change_graph_template($selected_items[$i], $_POST["graph_template_id"], true);
            }
        } elseif ($_POST["drp_action"] == "3") {
            /* duplicate */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                duplicate_graph($selected_items[$i], 0, $_POST["title_format"]);
            }
        } elseif ($_POST["drp_action"] == "4") {
            /* graph -> graph template */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                graph_to_graph_template($selected_items[$i], $_POST["title_format"]);
            }
        } elseif (preg_match("/^tr_([0-9]+)\$/", $_POST["drp_action"], $matches)) {
            /* place on tree */
            input_validate_input_number(get_request_var_post("tree_id"));
            input_validate_input_number(get_request_var_post("tree_item_id"));
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                api_tree_item_save(0, $_POST["tree_id"], TREE_ITEM_TYPE_GRAPH, $_POST["tree_item_id"], "", $selected_items[$i], read_graph_config_option("default_rra_id"), 0, 0, 0, false);
            }
        } elseif ($_POST["drp_action"] == "5") {
            /* change host */
            input_validate_input_number(get_request_var_post("host_id"));
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute("update graph_local set host_id=" . $_POST["host_id"] . " where id=" . $selected_items[$i]);
                update_graph_title_cache($selected_items[$i]);
            }
        } elseif ($_POST["drp_action"] == "6") {
            /* reapply suggested naming */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                api_reapply_suggested_graph_title($selected_items[$i]);
                update_graph_title_cache($selected_items[$i]);
            }
        } elseif ($_POST["drp_action"] == "7") {
            /* resize graphs */
            input_validate_input_number(get_request_var_post("graph_width"));
            input_validate_input_number(get_request_var_post("graph_height"));
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                api_resize_graphs($selected_items[$i], $_POST["graph_width"], $_POST["graph_height"]);
            }
        } else {
            api_plugin_hook_function('graphs_action_execute', $_POST['drp_action']);
        }
        header("Location: graphs.php");
        exit;
    }
    /* setup some variables */
    $graph_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]);
            /* ==================================================== */
            /* modify for multi user start */
            if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
                if (!in_array($matches[1], $graphs)) {
                    access_denied();
                }
            }
            /* modify for multi user end */
            $graph_list .= "<li>" . get_graph_title($matches[1]) . "</li>";
            $graph_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>" . $graph_actions[$_POST["drp_action"]] . "</strong>", "60%", $colors["header_panel"], "3", "center", "");
    print "<form action='graphs.php' method='post'>\n";
    if (isset($graph_array) && sizeof($graph_array)) {
        if ($_POST["drp_action"] == "1") {
            /* delete */
            $graphs = array();
            /* find out which (if any) data sources are being used by this graph, so we can tell the user */
            if (isset($graph_array) && sizeof($graph_array)) {
                $data_sources = db_fetch_assoc("select\r\n\t\t\t\t\tdata_template_data.local_data_id,\r\n\t\t\t\t\tdata_template_data.name_cache\r\n\t\t\t\t\tfrom (data_template_rrd,data_template_data,graph_templates_item)\r\n\t\t\t\t\twhere graph_templates_item.task_item_id=data_template_rrd.id\r\n\t\t\t\t\tand data_template_rrd.local_data_id=data_template_data.local_data_id\r\n\t\t\t\t\tand " . array_to_sql_or($graph_array, "graph_templates_item.local_graph_id") . "\r\n\t\t\t\t\tand data_template_data.local_data_id > 0\r\n\t\t\t\t\tgroup by data_template_data.local_data_id\r\n\t\t\t\t\torder by data_template_data.name_cache");
            }
            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 Graph(s) will be deleted.  Please note, Data Source(s) should be deleted only if they are only used by these Graph(s)\r\n\t\t\t\t\t\tand not others.</p>\r\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>";
            if (isset($data_sources) && sizeof($data_sources)) {
                print "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td class='textArea'><p class='textArea'>The following Data Source(s) are in use by these Graph(s):</p>\n";
                print "<ul>";
                foreach ($data_sources as $data_source) {
                    print "<li><strong>" . $data_source["name_cache"] . "</strong></li>\n";
                }
                print "</ul>";
                print "<br>";
                form_radio_button("delete_type", "1", "1", "Leave the Data Source(s) untouched.", "1");
                print "<br>";
                form_radio_button("delete_type", "1", "2", "Delete all <strong>Data Source(s)</strong> referenced by these Graph(s).", "1");
                print "<br>";
                print "</td></tr>";
            }
            print "\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()'>&nbsp;<input type='submit' value='Continue' title='Delete Graph(s)'>";
        } elseif ($_POST["drp_action"] == "2") {
            /* change graph template */
            /* modify for multi user start */
            $sql_where = "";
            if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
                $sql_where = "WHERE graph_templates.name NOT LIKE '%@system'";
            }
            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>Choose a Graph Template and click \"Continue\" to change the Graph Template for\r\n\t\t\t\t\t\tthe following Graph(s). Be aware that all warnings will be suppressed during the\r\n\t\t\t\t\t\tconversion, so Graph data loss is possible.</p>\r\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\r\n\t\t\t\t\t\t<p><strong>New Graph Template:</strong><br>";
            form_dropdown("graph_template_id", db_fetch_assoc("select graph_templates.id,graph_templates.name from graph_templates {$sql_where} order by name"), "name", "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";
            /* modify for multi user end */
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Change Graph Template'>";
        } elseif ($_POST["drp_action"] == "3") {
            /* duplicate */
            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 Graph(s) will be duplicated. You can\r\n\t\t\t\t\t\toptionally change the title format for the new Graph(s).</p>\r\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\r\n\t\t\t\t\t\t<p><strong>Title Format:</strong><br>";
            form_text_box("title_format", "<graph_title> (1)", "", "255", "30", "text");
            print "</p>\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()'>&nbsp;<input type='submit' value='Continue' title='Duplicate Graph(s)'>";
        } elseif ($_POST["drp_action"] == "4") {
            /* graph -> graph template */
            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 Graph(s) will be converted into Graph Template(s).\r\n\t\t\t\t\t\tYou can optionally change the title format for the new Graph Template(s).</p>\r\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\r\n\t\t\t\t\t\t<p><strong>Title Format:</strong><br>";
            form_text_box("title_format", "<graph_title> Template", "", "255", "30", "text");
            print "</p>\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()'>&nbsp;<input type='submit' value='Continue' title='Convert to Graph Template'>";
        } 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 Graph(s) will be placed under the Tree Branch selected below.</p>\r\n\t\t\t\t\t\t<p><ul>{$graph_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()'>&nbsp;<input type='submit' value='Continue' title='Place Graph(s) on Tree'>";
        } elseif ($_POST["drp_action"] == "5") {
            /* change host */
            /* modify for multi user start */
            if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
                $sql_join = "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'";
            }
            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>Choose a new Device for these Graph(s) and click \"Continue\"</p>\r\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\r\n\t\t\t\t\t\t<p><strong>New Host:</strong><br>";
            form_dropdown("host_id", db_fetch_assoc("select host.id,CONCAT_WS('',host.description,' (',host.hostname,')') as name from host order by description,hostname"), "name", "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";
            /* modify for multi user end */
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Change Graph(s) Associated Device'>";
        } elseif ($_POST["drp_action"] == "6") {
            /* reapply suggested naming to host */
            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 Graph(s) will have thier suggested naming convensions\r\n\t\t\t\t\t\trecalculated and applied to the Graph(s).</p>\r\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\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()'>&nbsp;<input type='submit' value='Continue' title='Reapply Suggested Naming to Graph(s)'>";
        } elseif ($_POST["drp_action"] == "7") {
            /* resize graphs */
            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 Graph(s) will be resized per your specifications.</p>\r\n\t\t\t\t\t\t<p><ul>{$graph_list}</ul></p>\r\n\t\t\t\t\t\t<p><strong>Graph Height:</strong><br>";
            form_text_box("graph_height", "", "", "255", "30", "text");
            print "</p>\r\n\t\t\t\t\t\t<p><strong>Graph Width:</strong><br>";
            form_text_box("graph_width", "", "", "255", "30", "text");
            print "</p>\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()'>&nbsp;<input type='submit' value='Continue' title='Resize Selected Graph(s)'>";
        } else {
            $save['drp_action'] = $_POST['drp_action'];
            $save['graph_list'] = $graph_list;
            $save['graph_array'] = isset($graph_array) ? $graph_array : array();
            api_plugin_hook_function('graphs_action_prepare', $save);
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue'>";
        }
    } else {
        print "<tr><td bgcolor='#" . $colors["form_alternate1"] . "'><span class='textError'>You must select at least one graph.</span></td></tr>\n";
        $save_html = "<input type='button' value='Return' onClick='window.history.back()'>";
    }
    print "\t<tr>\r\n\t\t\t<td 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($graph_array) ? serialize($graph_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";
}
Ejemplo n.º 7
0
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";
}
Ejemplo n.º 8
0
function export_colors() {
	if (isset($_REQUEST["selectedColors"]) && strlen($_REQUEST["selectedColors"])) {
		$selected_items = explode(",", $_REQUEST["selectedColors"]);
		if (is_array($selected_items)) {
		foreach($selected_items as $color_hex) {
			/* clean up color_id string */
			$color_hex = sanitize_search_string($color_hex);

			$color_hexes[] = $color_hex;
		}
		}
	}else{
		$message = "<i>You need to select the colors that you want for export before you may export them</i>\n";
		$_SESSION['sess_message_color_ref_int'] = array('message' => "<font size=-2>$message</font>", 'type' => 'info');
		raise_message('color_ref_int');

		header("Location: color.php");
		exit;
	}

	$colors = db_fetch_assoc("SELECT * FROM colors WHERE " . array_to_sql_or($color_hexes, "hex"));

	$xport_array = array();
	array_push($xport_array, '"id","hex"');

	if (sizeof($colors)) {
		foreach($colors as $color) {
			array_push($xport_array,'"' . $color['id'] . '","' . $color['hex'] . '"');
		}
	}

	header("Content-type: application/csv");
	header("Content-Disposition: attachment; filename=cacti_colors_xport.csv");

	if (sizeof($xport_array)) {
	foreach($xport_array as $xport_line) {
		print $xport_line . "\n";
	}
	}
}
Ejemplo n.º 9
0
function data_source_form_actions() {
	global $colors;
	require(CACTI_BASE_PATH . "/include/data_source/data_source_arrays.php");

	/* if we are to save this form, instead of display it */
	if (isset($_POST["selected_items"])) {
		$selected_items = unserialize(stripslashes($_POST["selected_items"]));

		if (get_request_var_post("drp_action") === DS_ACTION_DELETE) { /* delete */
			if (!isset($_POST["delete_type"])) { $_POST["delete_type"] = 1; }

			switch (get_request_var_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
						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");

					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 (get_request_var_post("drp_action") === DS_ACTION_CHANGE_TEMPLATE) { /* 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], get_request_var_post("data_template_id"));
			}
		}elseif (get_request_var_post("drp_action") === DS_ACTION_CHANGE_HOST) { /* change device */
			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("device_id"));
				/* ==================================================== */

				db_execute("update data_local set device_id=" . $_POST["device_id"] . " where id=" . $selected_items[$i]);
				push_out_device(get_request_var_post("device_id"), $selected_items[$i]);
				update_data_source_title_cache($selected_items[$i]);
			}
		}elseif (get_request_var_post("drp_action") === DS_ACTION_DUPLICATE) { /* 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, get_request_var_post("title_format"));
			}
		}elseif (get_request_var_post("drp_action") === DS_ACTION_CONVERT_TO_TEMPLATE) { /* 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], get_request_var_post("title_format"));
			}
		}elseif (get_request_var_post("drp_action") === DS_ACTION_ENABLE) { /* data source enable */
			for ($i=0;($i<count($selected_items));$i++) {
				api_data_source_enable($selected_items[$i]);
			}
		}elseif (get_request_var_post("drp_action") === DS_ACTION_DISABLE) { /* data source disable */
			for ($i=0;($i<count($selected_items));$i++) {
				api_data_source_disable($selected_items[$i]);
			}
		}elseif (get_request_var_post("drp_action") === DS_ACTION_REAPPLY_SUGGESTED_NAMES) { /* 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]);
			}
		}

		header("Location: data_sources.php");
		exit;
	}

	/* setup some variables */
	$ds_list = ""; $i = 0; $ds_array = array();

	/* 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>" . get_data_source_title($matches[1]) . "<br>";
			$ds_array[$i++] = $matches[1];
		}
	}

	$ds_actions[ACTION_NONE] = __("None");

	include_once(CACTI_BASE_PATH . "/include/top_header.php");

	html_start_box("<strong>" . $ds_actions{get_request_var_post("drp_action")} . "</strong>", "60", $colors["header_panel"], "3", "center", "");

	print "<form action='data_sources.php' method='post'>\n";

	if (sizeof($ds_array)) {
		if (get_request_var_post("drp_action") === ACTION_NONE) { /* NONE */
			print "	<tr>
						<td class='textArea'>
							<p>" . __("You did not select a valid action. Please select 'Return' to return to the previous menu.") . "</p>
						</td>
					</tr>\n";
		}elseif (get_request_var_post("drp_action") === DS_ACTION_DELETE) { /* 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 "	<tr>
					<td class='textArea'>
						<p>" . __("Are you sure you want to delete the following data sources?") . "</p>
						<p><ul>$ds_list</ul></p>
						";
						if (sizeof($graphs) > 0) {
							form_alternate_row_color();

							print "<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 "
					</td>
				</tr>\n
				";
		}elseif (get_request_var_post("drp_action") === DS_ACTION_CHANGE_TEMPLATE) { /* change graph template */
			print "	<tr>
					<td class='textArea'>
						<p>" . __("Choose a data template and click save to change the data template for the following data souces. Be aware that all warnings will be suppressed during the conversion, so graph data loss is possible.") . "</p>
						<p><ul>$ds_list</ul></p>
						<p><strong>". __("New Data Source 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>
					</td>
				</tr>\n
				";
		}elseif (get_request_var_post("drp_action") === DS_ACTION_CHANGE_HOST) { /* change device */
			print "	<tr>
					<td class='textArea'>
						<p>" . __("Choose a new device for these data sources.") . "</p>
						<p><ul>$ds_list</ul></p>
						<p><strong>" . __("New Host:") . "</strong><br>"; form_dropdown("device_id",db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from device order by description,hostname"),"name","id","","","0"); print "</p>
					</td>
				</tr>\n
				";
		}elseif (get_request_var_post("drp_action") === DS_ACTION_DUPLICATE) { /* duplicate */
			print "	<tr>
					<td class='textArea'>
						<p>" . __("When you click save, the following data sources will be duplicated. You can optionally change the title format for the new data sources.") . "</p>
						<p><ul>$ds_list</ul></p>
						<p><strong>" . __("Title Format:") . "</strong><br>"; form_text_box("title_format", "<ds_title> (1)", "", "255", "30", "text"); print "</p>
					</td>
				</tr>\n
				";
		}elseif (get_request_var_post("drp_action") === DS_ACTION_CONVERT_TO_TEMPLATE) { /* data source -> data template */
			print "	<tr>
					<td class='textArea'>
						<p>" . __("When you click save, the following data sources will be converted into data templates.  You can optionally change the title format for the new data templates.") . "</p>
						<p><ul>$ds_list</ul></p>
						<p><strong>" . __("Title Format:") . "</strong><br>"; form_text_box("title_format", "<ds_title> Template", "", "255", "30", "text"); print "</p>
					</td>
				</tr>\n
				";
		}elseif (get_request_var_post("drp_action") === DS_ACTION_ENABLE) { /* data source enable */
			print "	<tr>
					<td class='textArea'>
						<p>" . __("When you click yes, the following data sources will be enabled.") . "</p>
						<p><ul>$ds_list</ul></p>
					</td>
				</tr>\n
				";
		}elseif (get_request_var_post("drp_action") === DS_ACTION_DISABLE) { /* data source disable */
			print "	<tr>
					<td class='textArea'>
						<p>" . __("When you click yes, the following data sources will be disabled.") . "</p>
						<p><ul>$ds_list</ul></p>
					</td>
				</tr>\n
				";
		}elseif (get_request_var_post("drp_action") === DS_ACTION_REAPPLY_SUGGESTED_NAMES) { /* reapply suggested data source naming */
			print "	<tr>
					<td class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
						<p>" . __("When you click yes, the following data sources will will have their suggested naming conventions recalculated.") . "</p>
						<p><ul>$ds_list</ul></p>
					</td>
				</tr>\n
				";
			}
	} else {
		print "	<tr>
				<td class='textArea'>
					<p>" . __("You must first select a Data Source.  Please select 'Return' to return to the previous menu.") . "</p>
				</td>
			</tr>\n";
	}

	if (!sizeof($ds_array) || get_request_var_post("drp_action") === ACTION_NONE) {
		form_return_button_alt();
	}else{
		form_yesno_button_alt(serialize($ds_array), get_request_var_post("drp_action"));
	}

	html_end_box();

	include_once(CACTI_BASE_PATH . "/include/bottom_footer.php");
}
Ejemplo n.º 10
0
function cleanup_ds_and_graphs()
{
    global $config;
    include_once $config['library_path'] . '/rrd.php';
    include_once $config['library_path'] . '/utility.php';
    include_once $config['library_path'] . '/api_graph.php';
    include_once $config['library_path'] . '/api_data_source.php';
    include_once $config['library_path'] . '/functions.php';
    $remove_ldis = array();
    $remove_lgis = array();
    cacti_log('RRDClean now cleans up all data sources and graphs', true, 'MAINT');
    //fetch all local_data_id's which have appropriate data-sources
    $rrds = db_fetch_assoc("SELECT local_data_id, name_cache, data_source_path \n\t\tFROM data_template_data \n\t\tWHERE name_cache > ''");
    //filter those whose rrd files doesn't exist
    foreach ($rrds as $item) {
        $ldi = $item['local_data_id'];
        $name = $item['name_cache'];
        $ds_pth = $item['data_source_path'];
        $real_pth = str_replace('<path_rra>', $config['rra_path'], $ds_pth);
        if (!file_exists($real_pth)) {
            if (!in_array($ldi, $remove_ldis)) {
                $remove_ldis[] = $ldi;
                cacti_log("RRD file is missing for data source name: {$name} (local_data_id={$ldi})", true, 'MAINT');
            }
        }
    }
    if (empty($remove_ldis)) {
        cacti_log('No missing rrd files found', true, 'MAINT');
        return 0;
    }
    cacti_log('Processing Graphs', true, 'MAINT');
    //fetch all local_graph_id's according to filtered rrds
    $lgis = db_fetch_assoc('SELECT DISTINCT gl.id
		FROM graph_local AS gl
		INNER JOIN graph_templates_item AS gti
		ON gl.id=gti.local_graph_id
		INNER JOIN data_template_rrd AS dtr
		ON dtr.id=gti.task_item_id
		INNER JOIN data_local AS dl
		ON dtr.local_data_id=dl.id
		WHERE (' . array_to_sql_or($remove_ldis, 'local_data_id') . ')');
    foreach ($lgis as $item) {
        $remove_lgis[] = $item['id'];
        cacti_log('RRD file missing for local_graph_id=' . $item['id'], true, 'MAINT');
    }
    if (!empty($remove_lgis)) {
        cacti_log('removing graphs', true, 'MAINT');
        api_graph_remove_multi($remove_lgis);
    }
    cacti_log('removing data sources', true, 'MAINT');
    api_data_source_remove_multi($remove_ldis);
    cacti_log('removed graphs:' . count($remove_lgis) . ' removed data-sources:' . count($remove_ldis), true, 'MAINT');
}
Ejemplo n.º 11
0
function form_actions()
{
    global $colors, $actions, $assoc_actions;
    /* if we are to save this form, instead of display it */
    if (isset($_POST["selected_items"])) {
        if (isset($_POST["save_list"])) {
            $selected_items = unserialize(stripslashes($_POST["selected_items"]));
            if ($_POST["drp_action"] == "1") {
                /* delete */
                db_execute("DELETE FROM plugin_notification_lists WHERE " . array_to_sql_or($selected_items, "id"));
                db_execute("UPDATE host SET thold_send_email=0 WHERE thold_send_email=2 AND " . array_to_sql_or($selected_items, "thold_host_email"));
                db_execute("UPDATE host SET thold_send_email=1 WHERE thold_send_email=3 AND " . array_to_sql_or($selected_items, "thold_host_email"));
                db_execute("UPDATE host SET thold_host_email=0 WHERE " . array_to_sql_or($selected_items, "thold_host_email"));
                db_execute("UPDATE host SET thold_send_sms=0 WHERE thold_send_sms=2 AND " . array_to_sql_or($selected_items, "thold_host_phone"));
                db_execute("UPDATE host SET thold_send_sms=1 WHERE thold_send_sms=3 AND " . array_to_sql_or($selected_items, "thold_host_phone"));
                db_execute("UPDATE host SET thold_host_phone=0 WHERE " . array_to_sql_or($selected_items, "thold_host_phone"));
            } elseif ($_POST["drp_action"] == "2") {
                /* duplicate */
                for ($i = 0; $i < count($selected_items); $i++) {
                    /* ================= input validation ================= */
                    input_validate_input_number($selected_items[$i]);
                    /* ==================================================== */
                }
            }
            header("Location: notify_lists.php");
            exit;
        } elseif (isset($_POST["save_associate"])) {
            $selected_items = unserialize(stripslashes($_POST["selected_items"]));
            input_validate_input_number(get_request_var_request('notification_action'));
            if ($_POST["drp_action"] == "1") {
                /* associate */
                for ($i = 0; $i < count($selected_items); $i++) {
                    /* ================= input validation ================= */
                    input_validate_input_number($selected_items[$i]);
                    /* ==================================================== */
                    /* set the notification list */
                    db_execute("UPDATE host SET thold_host_email=" . get_request_var_request("id") . " WHERE id=" . $selected_items[$i]);
                    /* set the global/list election */
                    db_execute("UPDATE host SET thold_send_email=" . get_request_var_request("notification_action") . " WHERE id=" . $selected_items[$i]);
                    db_execute("UPDATE host SET thold_host_phone=" . get_request_var_request("id") . " WHERE id=" . $selected_items[$i]);
                    /* set the global/list election */
                    db_execute("UPDATE host SET thold_send_sms=" . get_request_var_request("notification_action") . " WHERE id=" . $selected_items[$i]);
                }
            } elseif ($_POST["drp_action"] == "2") {
                /* disassociate */
                for ($i = 0; $i < count($selected_items); $i++) {
                    /* ================= input validation ================= */
                    input_validate_input_number($selected_items[$i]);
                    /* ==================================================== */
                    /* set the notification list */
                    db_execute("UPDATE host SET thold_host_email=0 WHERE id=" . $selected_items[$i]);
                    /* set the global/list election */
                    db_execute("UPDATE host SET thold_send_email=" . get_request_var_request("notification_action") . " WHERE id=" . $selected_items[$i]);
                    /* set the notification list */
                    db_execute("UPDATE host SET thold_host_phone=0 WHERE id=" . $selected_items[$i]);
                    /* set the global/list election */
                    db_execute("UPDATE host SET thold_send_sms=" . get_request_var_request("notification_action") . " WHERE id=" . $selected_items[$i]);
                }
            }
            header("Location: notify_lists.php?action=edit&tab=hosts&id=" . get_request_var_request("id"));
            exit;
        } elseif (isset($_POST["save_templates"])) {
            $selected_items = unserialize(stripslashes($_POST["selected_items"]));
            input_validate_input_number(get_request_var_request('notification_action'));
            if ($_POST["drp_action"] == "1") {
                /* associate */
                for ($i = 0; $i < count($selected_items); $i++) {
                    /* ================= input validation ================= */
                    input_validate_input_number($selected_items[$i]);
                    /* ==================================================== */
                    if ($_POST["notification_warning_action"] > 0) {
                        /* clear other settings */
                        if ($_POST["notification_warning_action"] == 1) {
                            /* set the notification list */
                            db_execute("UPDATE thold_template SET notify_warning=" . get_request_var_request("id") . " WHERE id=" . $selected_items[$i]);
                            /* clear other items */
                            db_execute("UPDATE thold_template SET notify_warning_extra='' WHERE id=" . $selected_items[$i]);
                            db_execute("UPDATE thold_template SET warning_phones_extra='' WHERE id=" . $selected_items[$i]);
                        } else {
                            /* set the notification list */
                            db_execute("UPDATE thold_template SET notify_warning=" . get_request_var_request("id") . " WHERE id=" . $selected_items[$i]);
                        }
                    }
                    if ($_POST["notification_alert_action"] > 0) {
                        /* clear other settings */
                        if ($_POST["notification_alert_action"] == 1) {
                            /* set the notification list */
                            db_execute("UPDATE thold_template SET notify_alert=" . get_request_var_request("id") . " WHERE id=" . $selected_items[$i]);
                            /* clear other items */
                            db_execute("UPDATE thold_template SET notify_extra='' WHERE id=" . $selected_items[$i]);
                            db_execute("UPDATE thold_template SET alert_phones_extra='' WHERE id=" . $selected_items[$i]);
                            db_execute("DELETE FROM plugin_thold_template_contact WHERE template_id=" . $selected_items[$i]);
                        } else {
                            /* set the notification list */
                            db_execute("UPDATE thold_template SET notify_alert=" . get_request_var_request("id") . " WHERE id=" . $selected_items[$i]);
                        }
                    }
                }
            } elseif ($_POST["drp_action"] == "2") {
                /* disassociate */
                for ($i = 0; $i < count($selected_items); $i++) {
                    /* ================= input validation ================= */
                    input_validate_input_number($selected_items[$i]);
                    /* ==================================================== */
                    if ($_POST["notification_warning_action"] > 0) {
                        /* set the notification list */
                        db_execute("UPDATE thold_template SET notify_warning=0 WHERE id=" . $selected_items[$i] . " AND notify_warning=" . get_request_var_request('id'));
                    }
                    if ($_POST["notification_alert_action"] > 0) {
                        /* set the notification list */
                        db_execute("UPDATE thold_template SET notify_alert=0 WHERE id=" . $selected_items[$i] . " AND notify_alert=" . get_request_var_request('id'));
                    }
                }
            }
            header("Location: notify_lists.php?action=edit&tab=templates&id=" . get_request_var_request("id"));
            exit;
        } elseif (isset($_POST["save_tholds"])) {
            $selected_items = unserialize(stripslashes($_POST["selected_items"]));
            input_validate_input_number(get_request_var_request('notification_action'));
            if ($_POST["drp_action"] == "1") {
                /* associate */
                for ($i = 0; $i < count($selected_items); $i++) {
                    /* ================= input validation ================= */
                    input_validate_input_number($selected_items[$i]);
                    /* ==================================================== */
                    if ($_POST["notification_warning_action"] > 0) {
                        /* clear other settings */
                        if ($_POST["notification_warning_action"] == 1) {
                            /* set the notification list */
                            db_execute("UPDATE thold_data SET notify_warning=" . get_request_var_request("id") . " WHERE id=" . $selected_items[$i]);
                            /* clear other items */
                            db_execute("UPDATE thold_data SET notify_warning_extra='' WHERE id=" . $selected_items[$i]);
                            db_execute("UPDATE thold_data SET warning_phones_extra='' WHERE id=" . $selected_items[$i]);
                        } else {
                            /* set the notification list */
                            db_execute("UPDATE thold_data SET notify_warning=" . get_request_var_request("id") . " WHERE id=" . $selected_items[$i]);
                        }
                    }
                    if ($_POST["notification_alert_action"] > 0) {
                        /* clear other settings */
                        if ($_POST["notification_alert_action"] == 1) {
                            /* set the notification list */
                            db_execute("UPDATE thold_data SET notify_alert=" . get_request_var_request("id") . " WHERE id=" . $selected_items[$i]);
                            /* clear other items */
                            db_execute("UPDATE thold_data SET notify_extra='' WHERE id=" . $selected_items[$i]);
                            db_execute("UPDATE thold_data SET alert_phones_extra='' WHERE id=" . $selected_items[$i]);
                            db_execute("DELETE FROM plugin_thold_threshold_contact WHERE thold_id=" . $selected_items[$i]);
                        } else {
                            /* set the notification list */
                            db_execute("UPDATE thold_data SET notify_alert=" . get_request_var_request("id") . " WHERE id=" . $selected_items[$i]);
                        }
                    }
                }
            } elseif ($_POST["drp_action"] == "2") {
                /* disassociate */
                for ($i = 0; $i < count($selected_items); $i++) {
                    /* ================= input validation ================= */
                    input_validate_input_number($selected_items[$i]);
                    /* ==================================================== */
                    if ($_POST["notification_warning_action"] > 0) {
                        /* set the notification list */
                        db_execute("UPDATE thold_data SET notify_warning=0 WHERE id=" . $selected_items[$i] . " AND notify_warning=" . get_request_var_request('id'));
                    }
                    if ($_POST["notification_alert_action"] > 0) {
                        /* set the notification list */
                        db_execute("UPDATE thold_data SET notify_alert=0 WHERE id=" . $selected_items[$i] . " AND notify_alert=" . get_request_var_request('id'));
                    }
                }
            }
            header("Location: notify_lists.php?action=edit&tab=tholds&id=" . get_request_var_request("id"));
            exit;
        }
    }
    /* setup some variables */
    $list = "";
    $array = array();
    $list_name = "";
    if (isset($_POST["id"])) {
        $list_name = db_fetch_cell("SELECT name FROM plugin_notification_lists WHERE id=" . $_POST["id"]);
    }
    if (isset($_POST["save_list"])) {
        /* loop through each of the notification lists 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]);
                /* ==================================================== */
                $list .= "<li><b>" . db_fetch_cell("SELECT name FROM plugin_notification_lists WHERE id=" . $matches[1]) . "</b></li>";
                $array[] = $matches[1];
            }
        }
        include_once "./include/top_header.php";
        html_start_box("<strong>" . $actions[$_POST["drp_action"]] . " {$list_name}</strong>", "60%", $colors["header_panel"], "3", "center", "");
        print "<form action='notify_lists.php' method='post'>\n";
        if (sizeof($array)) {
            if ($_POST["drp_action"] == "1") {
                /* delete */
                print "\t<tr>\n\t\t\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t\t\t<p>When you click \"Continue\", the following Notification Lists(s) will be Deleted.  Any Hosts(s) or Threshold(s) associated with the List(s) will be reverted to the default.</p>\n\t\t\t\t\t\t\t<ul>{$list}</ul>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>\n";
                $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Delete Notification List(s)'>";
            } elseif ($_POST["drp_action"] == "2") {
                /* duplicate */
                print "\t<tr>\n\t\t\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t\t\t<p>When you click \"Continue\", the following Notification List(s) will be duplicated.</p>\n\t\t\t\t\t\t\t<ul>{$list}</ul>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>\n";
                $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Duplicate Notification List(s)'>";
            }
        } else {
            print "<tr><td bgcolor='#" . $colors["form_alternate1"] . "'><span class='textError'>You must select at least one Notification List.</span></td></tr>\n";
            $save_html = "<input type='button' value='Return' onClick='window.history.back()'>";
        }
        print "\t<tr>\n\t\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='save_list' value='1'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($array) ? serialize($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";
        html_end_box();
        include_once "./include/bottom_footer.php";
    } elseif (isset($_POST["save_templates"])) {
        /* loop through each of the notification lists 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]);
                /* ==================================================== */
                $list .= "<li><b>" . db_fetch_cell("SELECT name FROM thold_template WHERE id=" . $matches[1]) . "</b></li>";
                $array[] = $matches[1];
            }
        }
        include_once "./include/top_header.php";
        html_start_box("<strong>" . $assoc_actions[$_POST["drp_action"]] . " Threshold Template(s)</strong>", "60%", $colors["header_panel"], "3", "center", "");
        print "<form action='notify_lists.php' method='post'>\n";
        if (sizeof($array)) {
            if ($_POST["drp_action"] == "1") {
                /* associate */
                print "\t<tr>\n\t\t\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t\t\t<p>When you click \"Continue\", the Notification List '<b>" . $list_name . "</b>' will be associated with the Threshold Template(s) below.</p>\n\t\t\t\t\t\t\t<ul>{$list}</ul>\n\t\t\t\t\t\t\t<p><b>Warning Membership:</b><br>";
                form_dropdown("notification_warning_action", array(0 => "No Change", 1 => "Notification List Only", 2 => "Notification List, Retain Other Settings"), "", "", 1, "", "");
                print "</p>\n\t\t\t\t\t\t\t<p><b>Alert Membership:</b><br>";
                form_dropdown("notification_alert_action", array(0 => "No Change", 1 => "Notification List Only", 2 => "Notification List, Retain Other Settings"), "", "", 1, "", "");
                print "</p>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>\n";
                $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Associate Notification List(s)'>";
            } elseif ($_POST["drp_action"] == "2") {
                /* disassociate */
                print "\t<tr>\n\t\t\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t\t\t<p>When you click \"Continue\", the Notification List '<b>" . $list_name . "</b>' will be disassociated from the Thresholds Template(s) below.</p>\n\t\t\t\t\t\t\t<ul>{$list}</ul>\n\t\t\t\t\t\t\t<p><b>Warning Membership:</b><br>";
                form_dropdown("notification_warning_action", array(0 => "No Change", 1 => "Remove List"), "", "", 1, "", "");
                print "</p>\n\t\t\t\t\t\t\t<p><b>Alert Membership:</b><br>";
                form_dropdown("notification_alert_action", array(0 => "No Change", 1 => "Remove List"), "", "", 1, "", "");
                print "</p>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>\n";
                $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Disassociate Notification List(s)'>";
            }
        } else {
            print "<tr><td bgcolor='#" . $colors["form_alternate1"] . "'><span class='textError'>You must select at least one Threshold Template.</span></td></tr>\n";
            $save_html = "<input type='button' value='Return' onClick='window.history.back()'>";
        }
        print "\t<tr>\n\t\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='id' value='" . get_request_var_request('id') . "'>\n\t\t\t\t<input type='hidden' name='save_templates' value='1'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($array) ? serialize($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";
        html_end_box();
        include_once "./include/bottom_footer.php";
    } elseif (isset($_POST["save_tholds"])) {
        /* loop through each of the notification lists 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]);
                /* ==================================================== */
                $list .= "<li><b>" . db_fetch_cell("SELECT name FROM thold_data WHERE id=" . $matches[1]) . "</b></li>";
                $array[] = $matches[1];
            }
        }
        include_once "./include/top_header.php";
        html_start_box("<strong>" . $assoc_actions[$_POST["drp_action"]] . " Threshold(s)</strong>", "60%", $colors["header_panel"], "3", "center", "");
        print "<form action='notify_lists.php' method='post'>\n";
        if (sizeof($array)) {
            if ($_POST["drp_action"] == "1") {
                /* associate */
                print "\t<tr>\n\t\t\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t\t\t<p>When you click \"Continue\", the Notification List '<b>" . $list_name . "</b>' will be associated with the Threshold(s) below.</p>\n\t\t\t\t\t\t\t<ul>{$list}</ul>\n\t\t\t\t\t\t\t<p><b>Warning Membership:</b><br>";
                form_dropdown("notification_warning_action", array(0 => "No Change", 1 => "Notification List Only", 2 => "Notification List, Retain Other Settings"), "", "", 1, "", "");
                print "</p>\n\t\t\t\t\t\t\t<p><b>Alert Membership:</b><br>";
                form_dropdown("notification_alert_action", array(0 => "No Change", 1 => "Notification List Only", 2 => "Notification List, Retain Other Settings"), "", "", 1, "", "");
                print "</p>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>\n";
                $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Associate Notification List(s)'>";
            } elseif ($_POST["drp_action"] == "2") {
                /* disassociate */
                print "\t<tr>\n\t\t\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t\t\t<p>When you click \"Continue\", the Notification List '<b>" . $list_name . "</b>' will be disassociated from the Thresholds(s) below.</p>\n\t\t\t\t\t\t\t<ul>{$list}</ul>\n\t\t\t\t\t\t\t<p><b>Warning Membership:</b><br>";
                form_dropdown("notification_warning_action", array(0 => "No Change", 1 => "Remove List"), "", "", 1, "", "");
                print "</p>\n\t\t\t\t\t\t\t<p><b>Alert Membership:</b><br>";
                form_dropdown("notification_alert_action", array(0 => "No Change", 1 => "Remove List"), "", "", 1, "", "");
                print "</p>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>\n";
                $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Disassociate Notification List(s)'>";
            }
        } else {
            print "<tr><td bgcolor='#" . $colors["form_alternate1"] . "'><span class='textError'>You must select at least one Threshold.</span></td></tr>\n";
            $save_html = "<input type='button' value='Return' onClick='window.history.back()'>";
        }
        print "\t<tr>\n\t\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='id' value='" . get_request_var_request('id') . "'>\n\t\t\t\t<input type='hidden' name='save_tholds' value='1'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($array) ? serialize($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";
        html_end_box();
        include_once "./include/bottom_footer.php";
    } else {
        /* loop through each of the notification lists 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]);
                /* ==================================================== */
                $list .= "<li><b>" . db_fetch_cell("SELECT description FROM host WHERE id=" . $matches[1]) . "</b></li>";
                $array[] = $matches[1];
            }
        }
        include_once "./include/top_header.php";
        html_start_box("<strong>" . $assoc_actions[$_POST["drp_action"]] . " Host(s)</strong>", "60%", $colors["header_panel"], "3", "center", "");
        print "<form action='notify_lists.php' method='post'>\n";
        if (sizeof($array)) {
            if ($_POST["drp_action"] == "1") {
                /* associate */
                print "\t<tr>\n\t\t\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t\t\t<p>When you click \"Continue\", the Notification List '<b>" . $list_name . "</b>' will be associated with the Host(s) below.</p>\n\t\t\t\t\t\t\t<ul>{$list}</ul>\n\t\t\t\t\t\t\t<p><b>Resulting Membership:<br>";
                form_dropdown("notification_action", array(2 => "Notification List Only", 3 => "Notification and Global Lists"), "", "", 2, "", "");
                print "</p>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>\n";
                $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Associate Notification List(s)'>";
            } elseif ($_POST["drp_action"] == "2") {
                /* disassociate */
                print "\t<tr>\n\t\t\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t\t\t<p>When you click \"Continue\", the Notification List '<b>" . $list_name . "</b>' will be disassociated from the Host(s) below.</p>\n\t\t\t\t\t\t\t<ul>{$list}</ul>\n\t\t\t\t\t\t\t<p><b>Resulting Membership:</b><br>";
                form_dropdown("notification_action", array(1 => "Global List", 0 => "Disabled"), "", "", 1, "", "");
                print "</p>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>\n";
                $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Disassociate Notification List(s)'>";
            }
        } else {
            print "<tr><td bgcolor='#" . $colors["form_alternate1"] . "'><span class='textError'>You must select at least one Host.</span></td></tr>\n";
            $save_html = "<input type='button' value='Return' onClick='window.history.back()'>";
        }
        print "\t<tr>\n\t\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='id' value='" . get_request_var_request('id') . "'>\n\t\t\t\t<input type='hidden' name='save_associate' value='1'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($array) ? serialize($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";
        html_end_box();
        include_once "./include/bottom_footer.php";
    }
}
Ejemplo n.º 12
0
function form_actions()
{
    global $actions, $assoc_actions;
    /* ================= input validation ================= */
    get_filter_request_var('drp_action');
    /* ==================================================== */
    /* if we are to save this form, instead of display it */
    if (isset_request_var('selected_items')) {
        if (isset_request_var('save_list')) {
            $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
            if ($selected_items != false) {
                if (get_request_var('drp_action') == '1') {
                    /* delete */
                    db_execute('DELETE FROM plugin_notification_lists WHERE ' . array_to_sql_or($selected_items, 'id'));
                    db_execute('UPDATE host SET thold_send_email=0 WHERE thold_send_email=2 AND ' . array_to_sql_or($selected_items, 'thold_host_email'));
                    db_execute('UPDATE host SET thold_send_email=1 WHERE thold_send_email=3 AND ' . array_to_sql_or($selected_items, 'thold_host_email'));
                    db_execute('UPDATE host SET thold_host_email=0 WHERE ' . array_to_sql_or($selected_items, 'thold_host_email'));
                } elseif (get_request_var('drp_action') == '2') {
                    /* duplicate */
                    // To Do
                }
            }
            header('Location: notify_lists.php?header=false');
            exit;
        } elseif (isset_request_var('save_associate')) {
            $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
            if ($selected_items != false) {
                get_filter_request_var('notification_action');
                if (get_request_var('drp_action') == '1') {
                    /* associate */
                    for ($i = 0; $i < count($selected_items); $i++) {
                        /* set the notification list */
                        db_execute('UPDATE host SET thold_host_email=' . get_request_var('id') . ' WHERE id=' . $selected_items[$i]);
                        /* set the global/list election */
                        db_execute('UPDATE host SET thold_send_email=' . get_request_var('notification_action') . ' WHERE id=' . $selected_items[$i]);
                    }
                } elseif (get_request_var('drp_action') == '2') {
                    /* disassociate */
                    for ($i = 0; $i < count($selected_items); $i++) {
                        /* set the notification list */
                        db_execute('UPDATE host SET thold_host_email=0 WHERE id=' . $selected_items[$i]);
                        /* set the global/list election */
                        db_execute('UPDATE host SET thold_send_email=' . get_request_var('notification_action') . ' WHERE id=' . $selected_items[$i]);
                    }
                }
            }
            header('Location: notify_lists.php?header=false&action=edit&tab=hosts&id=' . get_request_var('id'));
            exit;
        } elseif (isset_request_var('save_templates')) {
            $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
            if ($selected_items != false) {
                get_filter_request_var('notification_action');
                if (get_request_var('drp_action') == '1') {
                    /* associate */
                    for ($i = 0; $i < count($selected_items); $i++) {
                        if (get_request_var('notification_warning_action') > 0) {
                            /* clear other settings */
                            if (get_request_var('notification_warning_action') == 1) {
                                /* set the notification list */
                                db_execute('UPDATE thold_template SET notify_warning=' . get_request_var('id') . ' WHERE id=' . $selected_items[$i]);
                                /* clear other items */
                                db_execute("UPDATE thold_template SET notify_warning_extra='' WHERE id=" . $selected_items[$i]);
                            } else {
                                /* set the notification list */
                                db_execute('UPDATE thold_template SET notify_warning=' . get_request_var('id') . ' WHERE id=' . $selected_items[$i]);
                            }
                        }
                        if (get_request_var('notification_alert_action') > 0) {
                            /* clear other settings */
                            if (get_request_var('notification_alert_action') == 1) {
                                /* set the notification list */
                                db_execute('UPDATE thold_template SET notify_alert=' . get_request_var('id') . ' WHERE id=' . $selected_items[$i]);
                                /* clear other items */
                                db_execute("UPDATE thold_template SET notify_extra='' WHERE id=" . $selected_items[$i]);
                                db_execute('DELETE FROM plugin_thold_template_contact WHERE template_id=' . $selected_items[$i]);
                            } else {
                                /* set the notification list */
                                db_execute('UPDATE thold_template SET notify_alert=' . get_request_var('id') . ' WHERE id=' . $selected_items[$i]);
                            }
                        }
                    }
                } elseif (get_request_var('drp_action') == '2') {
                    /* disassociate */
                    for ($i = 0; $i < count($selected_items); $i++) {
                        if (get_request_var('notification_warning_action') > 0) {
                            /* set the notification list */
                            db_execute('UPDATE thold_template SET notify_warning=0 WHERE id=' . $selected_items[$i] . ' AND notify_warning=' . get_request_var('id'));
                        }
                        if (get_request_var('notification_alert_action') > 0) {
                            /* set the notification list */
                            db_execute('UPDATE thold_template SET notify_alert=0 WHERE id=' . $selected_items[$i] . ' AND notify_alert=' . get_request_var('id'));
                        }
                    }
                }
            }
            header('Location: notify_lists.php?header=false&action=edit&tab=templates&id=' . get_request_var('id'));
            exit;
        } elseif (isset_request_var('save_tholds')) {
            $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
            if ($selected_items != false) {
                get_filter_request_var('notification_action');
                if (get_request_var('drp_action') == '1') {
                    /* associate */
                    for ($i = 0; $i < count($selected_items); $i++) {
                        if (get_request_var('notification_warning_action') > 0) {
                            /* clear other settings */
                            if (get_request_var('notification_warning_action') == 1) {
                                /* set the notification list */
                                db_execute('UPDATE thold_data SET notify_warning=' . get_request_var('id') . ' WHERE id=' . $selected_items[$i]);
                                /* clear other items */
                                db_execute("UPDATE thold_data SET notify_warning_extra='' WHERE id=" . $selected_items[$i]);
                            } else {
                                /* set the notification list */
                                db_execute('UPDATE thold_data SET notify_warning=' . get_request_var('id') . ' WHERE id=' . $selected_items[$i]);
                            }
                        }
                        if (get_request_var('notification_alert_action') > 0) {
                            /* clear other settings */
                            if (get_request_var('notification_alert_action') == 1) {
                                /* set the notification list */
                                db_execute('UPDATE thold_data SET notify_alert=' . get_request_var('id') . ' WHERE id=' . $selected_items[$i]);
                                /* clear other items */
                                db_execute("UPDATE thold_data SET notify_extra='' WHERE id=" . $selected_items[$i]);
                                db_execute('DELETE FROM plugin_thold_threshold_contact WHERE thold_id=' . $selected_items[$i]);
                            } else {
                                /* set the notification list */
                                db_execute('UPDATE thold_data SET notify_alert=' . get_request_var('id') . ' WHERE id=' . $selected_items[$i]);
                            }
                        }
                    }
                } elseif (get_request_var('drp_action') == '2') {
                    /* disassociate */
                    for ($i = 0; $i < count($selected_items); $i++) {
                        if (get_request_var('notification_warning_action') > 0) {
                            /* set the notification list */
                            db_execute('UPDATE thold_data SET notify_warning=0 WHERE id=' . $selected_items[$i] . ' AND notify_warning=' . get_request_var('id'));
                        }
                        if (get_request_var('notification_alert_action') > 0) {
                            /* set the notification list */
                            db_execute('UPDATE thold_data SET notify_alert=0 WHERE id=' . $selected_items[$i] . ' AND notify_alert=' . get_request_var('id'));
                        }
                    }
                }
            }
            header('Location: notify_lists.php?header=false&action=edit&tab=tholds&id=' . get_request_var('id'));
            exit;
        }
    }
    /* setup some variables */
    $list = '';
    $array = array();
    $list_name = '';
    if (isset_request_var('id')) {
        $list_name = db_fetch_cell('SELECT name FROM plugin_notification_lists WHERE id=' . get_filter_request_var('id'));
    }
    if (isset_request_var('save_list')) {
        /* loop through each of the notification lists 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]);
                /* ==================================================== */
                $list .= '<li><b>' . db_fetch_cell('SELECT name FROM plugin_notification_lists WHERE id=' . $matches[1]) . '</b></li>';
                $array[] = $matches[1];
            }
        }
        top_header();
        form_start('notify_lists.php');
        html_start_box($actions[get_request_var('drp_action')] . " {$list_name}", '60%', '', '3', 'center', '');
        print "<form action='notify_lists.php' method='post'>\n";
        if (sizeof($array)) {
            if (get_request_var('drp_action') == '1') {
                /* delete */
                print "<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>" . __('Click \'Continue\' to Delete Notification Lists(s).  Any Device(s) or Threshold(s) associated with the List(s) will be reverted to the default.') . "</p>\n\t\t\t\t\t\t<ul>{$list}</ul>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
                $save_html = "<input type='button' value='" . __('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' value='" . __('Continue') . "' title='" . __('Delete Notification List(s)') . "'>";
            } elseif (get_request_var('drp_action') == '2') {
                /* duplicate */
                print "<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>" . __('Click \'Continue\' to Duplicate the following Notification List(s).') . "</p>\n\t\t\t\t\t\t<ul>{$list}</ul>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
                $save_html = "<input type='button' value='" . __('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' value='" . __('Continue') . "' title='" . __('Duplicate Notification List(s)') . "'>";
            }
        } else {
            print "<tr><td class='even'><span class='textError'>" . __('You must select at least one Notification List.') . "</span></td></tr>\n";
            $save_html = "<input type='button' value='" . __('Return') . "' onClick='cactiReturnTo()'>";
        }
        print "<tr>\n\t\t\t\t<td class='saveRow'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='save_list' value='1'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($array) ? serialize($array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . get_request_var('drp_action') . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n";
        html_end_box();
        form_end();
        bottom_footer();
    } elseif (isset_request_var('save_templates')) {
        /* loop through each of the notification lists 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]);
                /* ==================================================== */
                $list .= '<li><b>' . db_fetch_cell('SELECT name FROM thold_template WHERE id=' . $matches[1]) . '</b></li>';
                $array[] = $matches[1];
            }
        }
        top_header();
        form_start('notify_lists.php');
        html_start_box(__('%s Threshold Template(s)', $assoc_actions[get_request_var('drp_action')]), '60%', '', '3', 'center', '');
        if (sizeof($array)) {
            if (get_request_var('drp_action') == '1') {
                /* associate */
                print "<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>" . __('Click \'Continue\' to Association the Notification List \'<b>%s</b>\' with the Threshold Template(s) below.', $list_name) . "</p>\n\t\t\t\t\t\t<ul>{$list}</ul>\n\t\t\t\t\t\t<p><b>" . __('Warning Membership:') . "</b><br>";
                form_dropdown('notification_warning_action', array(0 => __('No Change'), 1 => __('Notification List Only'), 2 => __('Notification List, Retain Other Settings')), '', '', 1, '', '');
                print "</p>\n\t\t\t\t\t\t<p><b>" . __('Alert Membership:') . "</b><br>";
                form_dropdown('notification_alert_action', array(0 => __('No Change'), 1 => __('Notification List Only'), 2 => __('Notification List, Retain Other Settings')), '', '', 1, '', '');
                print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
                $save_html = "<input type='button' value='" . __('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' value='" . __('Continue') . "' title='" . __('Associate Notification List(s)') . "'>";
            } elseif (get_request_var('drp_action') == '2') {
                /* disassociate */
                print "<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>" . __('Click \'Continue\' to Disassociate the Notification List \'<b>%s</b>\' from the Thresholds Template(s) below.', $list_name) . "</p>\n\t\t\t\t\t\t<ul>{$list}</ul>\n\t\t\t\t\t\t<p><b>" . __('Warning Membership:') . "</b><br>";
                form_dropdown('notification_warning_action', array(0 => __('No Change'), 1 => __('Remove List')), '', '', 1, '', '');
                print "</p>\n\t\t\t\t\t\t<p><b>" . __('Alert Membership:') . "</b><br>";
                form_dropdown('notification_alert_action', array(0 => __('No Change'), 1 => __('Remove List')), '', '', 1, '', '');
                print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
                $save_html = "<input type='button' value='" . __('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' value='" . __('Continue') . "' title='" . __('Disassociate Notification List(s)') . "'>";
            }
        } else {
            print "<tr><td class='even'><span class='textError'>" . __('You must select at least one Threshold Template.') . "</span></td></tr>\n";
            $save_html = "<input type='button' value='" . __('Return') . "' onClick='cactiReturnTo()'>";
        }
        print "\t<tr>\n\t\t\t\t<td class='saveRow'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='id' value='" . get_request_var('id') . "'>\n\t\t\t\t<input type='hidden' name='save_templates' value='1'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($array) ? serialize($array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . get_request_var('drp_action') . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n";
        html_end_box();
        form_end();
        bottom_footer();
    } elseif (isset_request_var('save_tholds')) {
        /* loop through each of the notification lists 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]);
                /* ==================================================== */
                $list .= '<li><b>' . db_fetch_cell('SELECT name FROM thold_data WHERE id=' . $matches[1]) . '</b></li>';
                $array[] = $matches[1];
            }
        }
        top_header();
        form_start('notify_lists.php');
        html_start_box(__('%s Threshold(s)', $assoc_actions[get_request_var('drp_action')]), '60%', '', '3', 'center', '');
        if (sizeof($array)) {
            if (get_request_var('drp_action') == '1') {
                /* associate */
                print "<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>" . __('Click \'Continue\' to Associate the Notification List \'<b>%s</b>\' with the Threshold(s) below.', $list_name) . "</p>\n\t\t\t\t\t\t<ul>{$list}</ul>\n\t\t\t\t\t\t<p><b>" . __('Warning Membership:') . "</b><br>";
                form_dropdown('notification_warning_action', array(0 => __('No Change'), 1 => __('Notification List Only'), 2 => __('Notification List, Retain Other Settings')), '', '', 1, '', '');
                print "</p>\n\t\t\t\t\t\t<p><b>" . __('Alert Membership:') . "</b><br>";
                form_dropdown('notification_alert_action', array(0 => __('No Change'), 1 => __('Notification List Only'), 2 => __('Notification List, Retain Other Settings')), '', '', 1, '', '');
                print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
                $save_html = "<input type='button' value='" . __('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' value='" . __('Continue') . "' title='" . __('Associate Notification List(s)') . "'>";
            } elseif (get_request_var('drp_action') == '2') {
                /* disassociate */
                print "<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>" . __('Click \'Continue\' to Disassociate the Notification List \'<b>%s</b>\' from the Thresholds(s) below.', $list_name) . "</p>\n\t\t\t\t\t\t<ul>{$list}</ul>\n\t\t\t\t\t\t<p><b>" . __('Warning Membership:') . "</b><br>";
                form_dropdown('notification_warning_action', array(0 => __('No Change'), 1 => __('Remove List')), '', '', 1, '', '');
                print "</p>\n\t\t\t\t\t\t<p><b>" . __('Alert Membership:') . "</b><br>";
                form_dropdown('notification_alert_action', array(0 => __('No Change'), 1 => __('Remove List')), '', '', 1, '', '');
                print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
                $save_html = "<input type='button' value='" . __('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' value='" . __('Continue') . "' title='" . __('Disassociate Notification List(s)') . "'>";
            }
        } else {
            print "<tr><td class='even'><span class='textError'>" . __('You must select at least one Threshold.') . "</span></td></tr>\n";
            $save_html = "<input type='button' value='" . __('Return') . "' onClick='cactiReturnTo()'>";
        }
        print "\t<tr>\n\t\t\t\t<td class='saveRow'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='id' value='" . get_request_var('id') . "'>\n\t\t\t\t<input type='hidden' name='save_tholds' value='1'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($array) ? serialize($array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . get_request_var('drp_action') . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n";
        html_end_box();
        form_end();
        bottom_footer();
    } else {
        /* loop through each of the notification lists 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]);
                /* ==================================================== */
                $list .= '<li>' . db_fetch_cell('SELECT description FROM host WHERE id=' . $matches[1]) . '</li>';
                $array[] = $matches[1];
            }
        }
        top_header();
        form_start('notify_lists.php');
        html_start_box($assoc_actions[get_request_var('drp_action')] . ' Device(s)', '60%', '', '3', 'center', '');
        if (sizeof($array)) {
            if (get_request_var('drp_action') == '1') {
                /* associate */
                print "<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>" . __('Click \'Continue\' to Associate the Notification List \'<b>%s</b>\' with the Device(s) below.', $list_name) . "</p>\n\t\t\t\t\t\t<ul>{$list}</ul>\n\t\t\t\t\t\t<p><b>" . __('Resulting Membership:') . "<br>";
                form_dropdown('notification_action', array(2 => __('Notification List Only'), 3 => __('Notification and Global Lists')), '', '', 2, '', '');
                print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
                $save_html = "<input type='button' value='" . __('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' value='" . __('Continue') . "' title='" . __('Associate Notification List(s)') . "'>";
            } elseif (get_request_var('drp_action') == '2') {
                /* disassociate */
                print "<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>" . __('Click \'Continue\' to Disassociate the Notification List \'<b>%s</b>\' from the Device(s) below.', $list_name) . "</p>\n\t\t\t\t\t\t<ul>{$list}</ul>\n\t\t\t\t\t\t<p><b>" . __('Resulting Membership:') . "</b><br>";
                form_dropdown('notification_action', array(1 => __('Global List'), 0 => __('Disabled')), '', '', 1, '', '');
                print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
                $save_html = "<input type='button' value='" . __('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' value='" . __('Continue') . "' title='" . __('Disassociate Notification List(s)') . "'>";
            }
        } 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='cactiReturnTo()'>";
        }
        print "<tr>\n\t\t\t\t<td class='saveRow'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='id' value='" . get_request_var('id') . "'>\n\t\t\t\t<input type='hidden' name='save_associate' value='1'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($array) ? serialize($array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . get_request_var('drp_action') . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n";
        html_end_box();
        form_end();
        bottom_footer();
    }
}
Ejemplo n.º 13
0
function form_actions()
{
    global $colors, $host_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 */
            db_execute("delete from host_template where " . array_to_sql_or($selected_items, "id"));
            db_execute("delete from host_template_snmp_query where " . array_to_sql_or($selected_items, "host_template_id"));
            db_execute("delete from host_template_graph where " . array_to_sql_or($selected_items, "host_template_id"));
            /* "undo" any device that is currently using this template */
            db_execute("update host set host_template_id=0 where " . array_to_sql_or($selected_items, "host_template_id"));
        } elseif ($_POST["drp_action"] == "2") {
            /* duplicate */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                duplicate_host_template($selected_items[$i], $_POST["title_format"]);
            }
        }
        header("Location: host_templates.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>" . db_fetch_cell("select name from host_template where id=" . $matches[1]) . "<br>";
            $host_array[$i] = $matches[1];
            $i++;
        }
    }
    include_once "./include/top_header.php";
    html_start_box("<strong>" . $host_actions[$_POST["drp_action"]] . "</strong>", "60%", $colors["header_panel"], "3", "center", "");
    print "<form action='host_templates.php' autocomplete='off' method='post'>\n";
    if (isset($host_array) && sizeof($host_array)) {
        if ($_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>Are you sure you want to delete the following Host Template(s)? All Devices currently associated\r\n\t\t\t\t\t\twith these Host Template(s) will lose that assocation.</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</tr>\n\r\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Delete Host Template(s)'>";
        } elseif ($_POST["drp_action"] == "2") {
            /* duplicate */
            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 Host Template(s) will be duplicated. You can\r\n\t\t\t\t\t\toptionally change the title format for the new Host Template(s).</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>Title Format:</strong><br>";
            form_text_box("title_format", "<template_title> (1)", "", "255", "30", "text");
            print "</p>\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()'>&nbsp;<input type='submit' value='Continue' title='Duplicate Host Template(s)'>";
        }
    } else {
        print "<tr><td bgcolor='#" . $colors["form_alternate1"] . "'><span class='textError'>You must select at least one host template.</span></td></tr>\n";
        $save_html = "<input type='button' value='Return' onClick='window.history.back()'>";
    }
    print "\t<tr>\r\n\t\t\t<td 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";
}
Ejemplo n.º 14
0
function mikrotik_view_graphs()
{
    global $current_user, $colors, $config, $host_template_hashes, $graph_template_hashes;
    include './lib/timespan_settings.php';
    include './lib/html_graph.php';
    html_graph_validate_preview_request_vars();
    /* include graph view filter selector */
    html_start_box('<strong>Graph Preview Filters</strong>' . (isset($_REQUEST['style']) && strlen($_REQUEST['style']) ? ' [ Custom Graph List Applied - Filtering from List ]' : ''), '100%', '', '3', 'center', '');
    html_graph_preview_filter('mikrotik.php', 'graphs', 'ht.hash IN ("' . implode('","', $host_template_hashes) . '")', 'gt.hash IN ("' . implode('","', $graph_template_hashes) . '")');
    html_end_box();
    /* the user select a bunch of graphs of the 'list' view and wants them displayed here */
    $sql_or = '';
    if (isset($_REQUEST['style'])) {
        if (get_request_var_request('style') == 'selective') {
            /* process selected graphs */
            if (!empty($_REQUEST['graph_list'])) {
                foreach (explode(',', $_REQUEST['graph_list']) as $item) {
                    $graph_list[$item] = 1;
                }
            } else {
                $graph_list = array();
            }
            if (!empty($_REQUEST['graph_add'])) {
                foreach (explode(',', $_REQUEST['graph_add']) as $item) {
                    $graph_list[$item] = 1;
                }
            }
            /* remove items */
            if (!empty($_REQUEST['graph_remove'])) {
                foreach (explode(',', $_REQUEST['graph_remove']) as $item) {
                    unset($graph_list[$item]);
                }
            }
            $i = 0;
            foreach ($graph_list as $item => $value) {
                $graph_array[$i] = $item;
                $i++;
            }
            if (isset($graph_array) && sizeof($graph_array) > 0) {
                /* build sql string including each graph the user checked */
                $sql_or = array_to_sql_or($graph_array, 'gtg.local_graph_id');
                $set_rra_id = empty($rra_id) ? read_graph_config_option('default_rra_id') : get_request_var_request('rra_id');
            }
        }
    }
    $total_graphs = 0;
    // Filter sql_where
    $sql_where = strlen($_REQUEST['filter']) ? "gtg.title_cache LIKE '%" . get_request_var_request('filter') . "%'" : '';
    $sql_where .= (strlen($sql_or) && strlen($sql_where) ? ' AND ' : '') . $sql_or;
    // Host Id sql_where
    if ($_REQUEST['host_id'] > 0) {
        $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.host_id=' . $_REQUEST['host_id'];
    } else {
        $host_ids = mikrotik_host_ids_from_hashes($host_template_hashes);
        if (sizeof($host_ids)) {
            $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.host_id IN (' . implode(',', $host_ids) . ')';
        } else {
            $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' 1=0';
        }
    }
    // Graph Template Id sql_where
    if ($_REQUEST['graph_template_id'] > 0) {
        $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.graph_template_id=' . $_REQUEST['graph_template_id'];
    } else {
        $graph_template_ids = mikrotik_graph_templates_from_hashes($graph_template_hashes);
        if (sizeof($graph_template_ids)) {
            $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.graph_template_id IN (' . implode(',', $graph_template_ids) . ')';
        } else {
            $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' 1=0';
        }
    }
    $limit = $_REQUEST['graphs'] * ($_REQUEST['page'] - 1) . ',' . $_REQUEST['graphs'];
    $order = 'gtg.title_cache';
    $graphs = get_allowed_graphs($sql_where, $order, $limit, $total_graphs);
    /* do some fancy navigation url construction so we don't have to try and rebuild the url string */
    if (preg_match('/page=[0-9]+/', basename($_SERVER['QUERY_STRING']))) {
        $nav_url = str_replace('&page=' . get_request_var_request('page'), '', get_browser_query_string());
    } else {
        $nav_url = get_browser_query_string() . '&host_id=' . get_request_var_request('host_id');
    }
    $nav_url = preg_replace('/((\\?|&)host_id=[0-9]+|(\\?|&)filter=[a-zA-Z0-9]*)/', '', $nav_url);
    html_start_box('', '100%', '', '3', 'center', '');
    $nav = html_nav_bar($nav_url, MAX_DISPLAY_PAGES, get_request_var_request('page'), get_request_var_request('graphs'), $total_graphs, get_request_var_request('columns'), 'Graphs', 'page', 'main');
    print $nav;
    if (get_request_var_request('thumbnails') == 'true') {
        html_graph_thumbnail_area($graphs, '', 'graph_start=' . get_current_graph_start() . '&graph_end=' . get_current_graph_end(), '', get_request_var_request('columns'));
    } else {
        html_graph_area($graphs, '', 'graph_start=' . get_current_graph_start() . '&graph_end=' . get_current_graph_end(), '', get_request_var_request('columns'));
    }
    if ($total_graphs > 0) {
        print $nav;
    }
    html_end_box();
    bottom_footer();
}
Ejemplo n.º 15
0
function form_actions()
{
    global $colors, $graph_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 */
            for ($i = 0; $i < count($selected_items); $i++) {
                if (!isset($_POST["delete_type"])) {
                    $_POST["delete_type"] = 1;
                }
                switch ($_POST["delete_type"]) {
                    case '2':
                        /* delete all data sources referenced by this graph */
                        $data_sources = db_fetch_assoc("select distinct\n\t\t\t\t\t\t\tdata_source.id\n\t\t\t\t\t\t\tfrom data_source_item,data_source,graph_item\n\t\t\t\t\t\t\twhere graph_item.data_source_item_id=data_source_item.id\n\t\t\t\t\t\t\tand data_source_item.data_source_id=data_source.id\n\t\t\t\t\t\t\tand " . array_to_sql_or($selected_items, "graph_item.graph_id") . "\n\t\t\t\t\t\t\torder by data_source.name_cache");
                        if (sizeof($data_sources) > 0) {
                            foreach ($data_sources as $data_source) {
                                api_data_source_remove($data_source["id"]);
                            }
                        }
                        break;
                }
                api_graph_remove($selected_items[$i]);
            }
        } elseif ($_POST["drp_action"] == "2") {
            /* change graph template */
            for ($i = 0; $i < count($selected_items); $i++) {
                change_graph_template($selected_items[$i], $_POST["graph_template_id"], true);
            }
        } elseif ($_POST["drp_action"] == "3") {
            /* duplicate */
            for ($i = 0; $i < count($selected_items); $i++) {
                duplicate_graph($selected_items[$i], 0, $_POST["title_format"]);
            }
        } elseif ($_POST["drp_action"] == "4") {
            /* graph -> graph template */
            for ($i = 0; $i < count($selected_items); $i++) {
                graph_to_graph_template($selected_items[$i], $_POST["title_format"]);
            }
        } elseif (ereg("^tr_([0-9]+)\$", $_POST["drp_action"], $matches)) {
            /* place on tree */
            for ($i = 0; $i < count($selected_items); $i++) {
                api_tree_item_save(0, $_POST["tree_id"], TREE_ITEM_TYPE_GRAPH, $_POST["tree_item_id"], "", $selected_items[$i], read_graph_config_option("default_rra_id"), 0, 0, 0, false);
            }
        } elseif ($_POST["drp_action"] == "5") {
            /* change host */
            for ($i = 0; $i < count($selected_items); $i++) {
                db_execute("update graph set host_id = " . $_POST["host_id"] . " where id = " . $selected_items[$i]);
                api_graph_title_cache_update($selected_items[$i]);
            }
        } elseif ($_POST["drp_action"] == "6") {
            /* reapply suggested naming */
            for ($i = 0; $i < count($selected_items); $i++) {
                api_reapply_suggested_graph_title($selected_items[$i]);
                api_graph_title_cache_update($selected_items[$i]);
            }
        } elseif ($_POST["drp_action"] == "7") {
            /* resize graphs */
            for ($i = 0; $i < count($selected_items); $i++) {
                api_graph_resize($selected_items[$i], $_POST["graph_width"], $_POST["graph_height"]);
            }
        }
        header("Location: graphs.php");
        exit;
    }
    /* setup some variables */
    $graph_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)) {
            $graph_list .= "<li>" . db_fetch_cell("select title_cache from graph where id = " . $matches[1]) . "<br>";
            $graph_array[$i] = $matches[1];
        }
        $i++;
    }
    require_once CACTI_BASE_PATH . "/include/top_header.php";
    html_start_box("<strong>" . $graph_actions[$_POST["drp_action"]] . "</strong>", "60%", $colors["header_panel_background"], "3", "center", "");
    print "<form action='graphs.php' method='post'>\n";
    if ($_POST["drp_action"] == "1") {
        /* delete */
        $graphs = array();
        /* find out which (if any) data sources are being used by this graph, so we can tell the user */
        if (isset($graph_array)) {
            $data_sources = db_fetch_assoc("select distinct\n\t\t\t\tdata_source.id,\n\t\t\t\tdata_source.name_cache\n\t\t\t\tfrom data_source_item,data_source,graph_item\n\t\t\t\twhere graph_item.data_source_item_id=data_source_item.id\n\t\t\t\tand data_source_item.data_source_id=data_source.id\n\t\t\t\tand " . array_to_sql_or($graph_array, "graph_item.graph_id") . "\n\t\t\t\torder by data_source.name_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 graphs?") . "</p>\n\t\t\t\t\t<p>{$graph_list}</p>\n\t\t\t\t\t";
        if (sizeof($data_sources) > 0) {
            print "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td class='textArea'><p class='textArea'>" . _("The following data sources are in use by these graphs:") . "</p>\n";
            foreach ($data_sources as $data_source) {
                print "<strong>" . $data_source["name_cache"] . "</strong><br>\n";
            }
            print "<br>";
            form_radio_button("delete_type", "1", "1", _("Leave the data sources untouched."), "1");
            print "<br>";
            form_radio_button("delete_type", "1", "2", _("Delete all <strong>data sources</strong> referenced by these graphs."), "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 graph template and click save to change the graph template for\n\t\t\t\t\tthe following graphs. 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>{$graph_list}</p>\n\t\t\t\t\t<p><strong>" . _("New Graph Template:") . "</strong><br>";
        form_dropdown("graph_template_id", db_fetch_assoc("select graph_templates.id,graph_templates.name from graph_templates"), "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") {
        /* 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 graphs will be duplicated. You can\n\t\t\t\t\toptionally change the title format for the new graphs.") . "</p>\n\t\t\t\t\t<p>{$graph_list}</p>\n\t\t\t\t\t<p><strong>" . _("Title Format:") . "</strong><br>";
        form_text_box("title_format", "<graph_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"] == "4") {
        /* graph -> graph 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 graphs will be converted into graph templates.\n\t\t\t\t\tYou can optionally change the title format for the new graph templates.") . "</p>\n\t\t\t\t\t<p>{$graph_list}</p>\n\t\t\t\t\t<p><strong>" . _("Title Format:") . "</strong><br>";
        form_text_box("title_format", "<graph_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"] == "5") {
        /* change device */
        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 graphs:") . "</p>\n\t\t\t\t\t<p>{$graph_list}</p>\n\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</td>\n\t\t\t</tr>\n\n\t\t\t";
    } elseif ($_POST["drp_action"] == "6") {
        /* reapply suggested naming to host */
        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 graphs will have thier suggested naming convensions\n\t\t\t\t\trecalculated and applies to the graphs.") . "</p>\n\t\t\t\t\t<p>{$graph_list}</p>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t";
    } elseif ($_POST["drp_action"] == "7") {
        /* reapply suggested naming to host */
        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 graphs will be resized per your specifications.</p>\n\t\t\t\t\t<p>{$graph_list}</p>\n\t\t\t\t\t<p><strong>Graph Height:</strong><br>";
        form_text_box("graph_height", "", "", "255", "30", "text");
        print "</p>\n\t\t\t\t\t<p><strong>Graph Width:</strong><br>";
        form_text_box("graph_width", "", "", "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"] == "8") {
        /* place on tree */
        $trees = db_fetch_assoc("select id,name from graph_tree order by name");
        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 graphs will be placed under the branch selected\n\t\t\t\t\tbelow.") . "</p>\n\t\t\t\t\t<p>{$graph_list}</p>\n\t\t\t\t\t<p><strong>" . _("Destination Branch:") . "</strong><br>";
        html_tree_dropdown_draw($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($graph_array)) {
        print "<tr><td bgcolor='#" . $colors["form_alternate1"] . "'><span class='textError'>" . _("You must select at least one graph.") . "</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 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($graph_array) ? serialize($graph_array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST["drp_action"] . "'>\n\t\t\t\t<a href='graphs.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";
}
Ejemplo n.º 16
0
function form_actions() {
	global $colors, $cdef_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 */
			db_execute("delete from cdef where " . array_to_sql_or($selected_items, "id"));
			db_execute("delete from cdef_items where " . array_to_sql_or($selected_items, "cdef_id"));

		}elseif ($_POST["drp_action"] == "2") { /* duplicate */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */

				duplicate_cdef($selected_items[$i], $_POST["title_format"]);
			}
		}

		header("Location: cdef.php");
		exit;
	}

	/* setup some variables */
	$cdef_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]);
			/* ==================================================== */

			$cdef_list .= "<li>" . db_fetch_cell("select name from cdef where id=" . $matches[1]) . "<br>";
			$cdef_array[$i] = $matches[1];
		}

		$i++;
	}

	include_once("./include/top_header.php");

	html_start_box("<strong>" . $cdef_actions{$_POST["drp_action"]} . "</strong>", "60%", $colors["header_panel"], "3", "center", "");

	print "<form action='cdef.php' method='post'>\n";

	if ($_POST["drp_action"] == "1") { /* delete */
		print "	<tr>
				<td class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
					<p>Are you sure you want to delete the following CDEFs?</p>
					<p>$cdef_list</p>
				</td>
			</tr>\n
			";
	}elseif ($_POST["drp_action"] == "2") { /* duplicate */
		print "	<tr>
				<td class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
					<p>When you click save, the following CDEFs will be duplicated. You can
					optionally change the title format for the new CDEFs.</p>
					<p>$cdef_list</p>
					<p><strong>Title Format:</strong><br>"; form_text_box("title_format", "<cdef_title> (1)", "", "255", "30", "text"); print "</p>
				</td>
			</tr>\n
			";
	}

	if (!isset($cdef_array)) {
		print "<tr><td bgcolor='#" . $colors["form_alternate1"]. "'><span class='textError'>You must select at least one CDEF.</span></td></tr>\n";
		$save_html = "";
	}else{
		$save_html = "<input type='image' src='images/button_yes.gif' alt='Save' align='absmiddle'>";
	}

	print "	<tr>
			<td align='right' bgcolor='#eaeaea'>
				<input type='hidden' name='action' value='actions'>
				<input type='hidden' name='selected_items' value='" . (isset($cdef_array) ? serialize($cdef_array) : '') . "'>
				<input type='hidden' name='drp_action' value='" . $_POST["drp_action"] . "'>
				<a href='cdef.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");
}
Ejemplo n.º 17
0
function form_actions() {
	global $colors, $poller_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 (get_request_var_post("drp_action") === "1") { /* delete */
			/* do a referential integrity check */
			if (sizeof($selected_items)) {
			foreach($selected_items as $poller_id) {
				/* ================= input validation ================= */
				input_validate_input_number($poller_id);
				/* ==================================================== */

				if (sizeof(db_fetch_assoc("SELECT * FROM device WHERE poller_id=$poller_id LIMIT 1")) || $poller_id == 1) {
					$bad_ids[] = $poller_id;
				}else{
					$poller_ids[] = $poller_id;
				}
			}
			}

			if (isset($bad_ids)) {
				$message = "";
				foreach($bad_ids as $poller_id) {
					$message .= (strlen($message) ? "<br>":"") . "<i>" . sprintf(__("Poller '%s' is in use or is the system poller and can not be removed"), $poller_id) . "</i>\n";
				}

				$_SESSION['sess_message_poller_ref_int'] = array('message' => "<font size=-2>$message</font>", 'type' => 'info');

				raise_message('poller_ref_int');
			}

			if (isset($poller_ids)) {
				db_execute("delete from poller where " . array_to_sql_or($poller_ids, "id"));
				db_execute("update poller_item set poller_id=0 where " . array_to_sql_or($poller_ids, "poller_id"));
				db_execute("update device set poller_id=0 where " . array_to_sql_or($poller_ids, "poller_id"));
			}
		}elseif (get_request_var_post("drp_action") === "2") { /* disable */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */

				db_execute("update poller set disabled='on' where " . array_to_sql_or($selected_items, "id"));
			}
		}

		header("Location: pollers.php");
		exit;
	}

	/* setup some variables */
	$poller_list = ""; $i = 0; $poller_array = array();

	/* loop through each of the pollers 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]);
			/* ==================================================== */

			$poller_list .= "<li>" . db_fetch_cell("select description from poller where id=" . $matches[1]) . "<br>";
			$poller_array[$i] = $matches[1];
		}

		$i++;
	}

	include_once(CACTI_BASE_PATH . "/include/top_header.php");

	html_start_box("<strong>" . $poller_actions{get_request_var_post("drp_action")} . "</strong>", "60", $colors["header_panel"], "3", "center", "");

	print "<form action='pollers.php' method='post'>\n";

	if (sizeof($poller_array)) {
		if (get_request_var_post("drp_action") === ACTION_NONE) { /* NONE */
			print "	<tr>
						<td class='textArea'>
							<p>" . __("You did not select a valid action. Please select 'Return' to return to the previous menu.") . "</p>
						</td>
					</tr>\n";
		}elseif (get_request_var_post("drp_action") === "1") { /* delete */
			print "	<tr>
					<td class='textArea'>
						<p>". __("Are you sure you want to delete the following pollers? All devices currently attached this these pollers will be reassigned to the default poller.") . "</p>
						<p><ul>$poller_list</ul></p>
					</td>
				</tr>\n
				";
		}elseif (get_request_var_post("drp_action") === "2") { /* disable */
			print "	<tr>
					<td class='textArea'>
						<p>" . __("Are you sure you want to disable the following pollers? All devices currently attached to these pollers will no longer have their graphs updated.") . "</p>
						<p><ul>$poller_list</ul></p>
					</td>
				</tr>\n
				";
		}
	} else {
		print "	<tr>
				<td class='textArea'>
					<p>" . __("You must first select a Poller.  Please select 'Return' to return to the previous menu.") . "</p>
				</td>
			</tr>\n";
	}

	if (!sizeof($poller_array) || get_request_var_post("drp_action") === ACTION_NONE) {
		form_return_button_alt();
	}else{
		form_yesno_button_alt(serialize($poller_array), get_request_var_post("drp_action"));
	}

	html_end_box();

	include_once(CACTI_BASE_PATH . "/include/bottom_footer.php");
}
Ejemplo n.º 18
0
             }
         }
         /* remove items */
         if (!empty($_REQUEST['graph_remove'])) {
             foreach (explode(',', $_REQUEST['graph_remove']) as $item) {
                 unset($graph_list[$item]);
             }
         }
         $i = 0;
         foreach ($graph_list as $item => $value) {
             $graph_array[$i] = $item;
             $i++;
         }
         if (isset($graph_array) && sizeof($graph_array) > 0) {
             /* build sql string including each graph the user checked */
             $sql_or = 'AND ' . array_to_sql_or($graph_array, 'graph_templates_graph.local_graph_id');
             $set_rra_id = empty($rra_id) ? read_graph_config_option('default_rra_id') : get_request_var_request('rra_id');
         }
     }
 }
 $sql_base = "FROM (graph_templates_graph,graph_local)\n\t\t{$sql_join}\n\t\t{$sql_where}\n\t\t" . (empty($sql_where) ? 'WHERE' : 'AND') . "   graph_templates_graph.local_graph_id > 0\n\t\tAND graph_templates_graph.local_graph_id=graph_local.id\n\t\tAND graph_templates_graph.title_cache like '%%" . get_request_var_request('filter') . "%%'\n\t\t" . (empty($_REQUEST['host_id']) ? '' : ' and graph_local.host_id=' . get_request_var_request('host_id')) . "\n\t\t" . (empty($_REQUEST['graph_template_id']) ? '' : ' and graph_local.graph_template_id=' . get_request_var_request('graph_template_id')) . "\n\t\t{$sql_or}";
 $total_rows = count(db_fetch_assoc('SELECT ' . 'graph_templates_graph.local_graph_id ' . $sql_base));
 $graphs = db_fetch_assoc('SELECT ' . 'graph_templates_graph.local_graph_id, ' . 'graph_templates_graph.height, ' . 'graph_templates_graph.width, ' . 'graph_templates_graph.title_cache ' . $sql_base . ' ' . 'GROUP BY graph_templates_graph.local_graph_id ' . 'ORDER BY graph_templates_graph.title_cache ' . 'limit ' . $_REQUEST['rows'] * ($_REQUEST['page'] - 1) . ',' . $_REQUEST['rows']);
 /* do some fancy navigation url construction so we don't have to try and rebuild the url string */
 if (preg_match('/page=[0-9]+/', basename($_SERVER['QUERY_STRING']))) {
     $nav_url = str_replace('&page=' . get_request_var_request('page'), '', get_browser_query_string());
 } else {
     $nav_url = get_browser_query_string() . '&host_id=' . get_request_var_request('host_id');
 }
 $nav_url = preg_replace('/((\\?|&)host_id=[0-9]+|(\\?|&)filter=[a-zA-Z0-9]*)/', '', $nav_url);
 html_start_box('', '100%', "", '3', 'center', '');
Ejemplo n.º 19
0
function form_actions()
{
    global $colors, $graph_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 */
            db_execute("delete from graph_templates where " . array_to_sql_or($selected_items, "id"));
            $graph_template_input = db_fetch_assoc("select id from graph_template_input where " . array_to_sql_or($selected_items, "graph_template_id"));
            if (sizeof($graph_template_input) > 0) {
                foreach ($graph_template_input as $item) {
                    db_execute("delete from graph_template_input_defs where graph_template_input_id=" . $item["id"]);
                }
            }
            db_execute("delete from graph_template_input where " . array_to_sql_or($selected_items, "graph_template_id"));
            db_execute("delete from graph_templates_graph where " . array_to_sql_or($selected_items, "graph_template_id") . " and local_graph_id=0");
            db_execute("delete from graph_templates_item where " . array_to_sql_or($selected_items, "graph_template_id") . " and local_graph_id=0");
            db_execute("delete from host_template_graph where " . array_to_sql_or($selected_items, "graph_template_id"));
            /* "undo" any graph that is currently using this template */
            db_execute("update graph_templates_graph set local_graph_template_graph_id=0,graph_template_id=0 where " . array_to_sql_or($selected_items, "graph_template_id"));
            db_execute("update graph_templates_item set local_graph_template_item_id=0,graph_template_id=0 where " . array_to_sql_or($selected_items, "graph_template_id"));
            db_execute("update graph_local set graph_template_id=0 where " . array_to_sql_or($selected_items, "graph_template_id"));
        } elseif ($_POST["drp_action"] == "2") {
            /* duplicate */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                duplicate_graph(0, $selected_items[$i], $_POST["title_format"]);
            }
        }
        header("Location: graph_templates.php");
        exit;
    }
    /* setup some variables */
    $graph_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]);
            /* ==================================================== */
            $graph_list .= "<li>" . db_fetch_cell("select name from graph_templates where id=" . $matches[1]) . "<br>";
            $graph_array[$i] = $matches[1];
        }
        $i++;
    }
    include_once "./include/top_header.php";
    html_start_box("<strong>" . $graph_actions[$_POST["drp_action"]] . "</strong>", "60%", $colors["header_panel"], "3", "center", "");
    print "<form action='graph_templates.php' method='post'>\n";
    if ($_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 graph templates? Any graphs attached\n\t\t\t\t\tto these templates will become individual graphs.</p>\n\t\t\t\t\t<p>{$graph_list}</p>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t";
    } elseif ($_POST["drp_action"] == "2") {
        /* 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 graph templates will be duplicated. You can\n\t\t\t\t\toptionally change the title format for the new graph templates.</p>\n\t\t\t\t\t<p>{$graph_list}</p>\n\t\t\t\t\t<p><strong>Title Format:</strong><br>";
        form_text_box("title_format", "<template_title> (1)", "", "255", "30", "text");
        print "</p>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t";
    }
    if (!isset($graph_array)) {
        print "<tr><td bgcolor='#" . $colors["form_alternate1"] . "'><span class='textError'>You must select at least one graph template.</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($graph_array) ? serialize($graph_array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST["drp_action"] . "'>\n\t\t\t\t<a href='graph_templates.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";
}
Ejemplo n.º 20
0
function form_actions()
{
    global $colors, $user_actions, $fields_user_edit;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_post('drp_action'));
    /* ==================================================== */
    /* 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'] = 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 ================= */
                $selected_items[$i] = sanitize_search_string($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.snmp_index') . "\n\t\t\t\t\tAND snmp_query_id='" . mikrotik_data_query_by_hash('ce63249e6cc3d52bc69659a3f32194fe') . "'");
                if (sizeof($data_sources) > 0) {
                    foreach ($data_sources as $data_source) {
                        $data_sources_to_act_on[] = $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.snmp_index') . "\n\t\t\t\t\tAND snmp_query_id='" . mikrotik_data_query_by_hash('ce63249e6cc3d52bc69659a3f32194fe') . "'");
                if (sizeof($graphs) > 0) {
                    foreach ($graphs as $graph) {
                        $graphs_to_act_on[] = $graph['local_graph_id'];
                    }
                }
                $devices_to_act_on[] = $selected_items[$i];
            }
            api_data_source_remove_multi($data_sources_to_act_on);
            api_graph_remove_multi($graphs_to_act_on);
            db_execute("DELETE FROM plugin_mikrotik_users WHERE name IN ('" . implode("','", $devices_to_act_on) . "')");
        }
        header('Location: mikrotik_users.php&header=false');
        exit;
    }
    /* setup some variables */
    $user_list = '';
    /* loop through each of the user templates selected on the previous page and get more info about them */
    while (list($var, $val) = each($_POST)) {
        if (preg_match('/^chk_([A-Z0-9]+)$/', $var, $matches)) {
            /* ================= input validation ================= */
            $matches[1] = sanitize_search_string($matches[1]);
            /* ==================================================== */
            $user_list .= '<li>' . $matches[1] . '</li>';
            $user_array[] = $matches[1];
        }
    }
    top_header();
    html_start_box('<strong>' . $user_actions[$_POST['drp_action']] . '</strong>', '60%', '', '3', 'center', '');
    print "<form action='mikrotik_users.php' autocomplete='off' method='post'>\n";
    if (isset($user_array) && sizeof($user_array)) {
        if ($_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 Users(s) and their Graph(s) will be deleted.</p>\n\t\t\t\t\t\t<ul>" . $user_list . "</ul>";
            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='cactiReturnTo()'>&nbsp;<input type='submit' value='Continue' title='Delete Device(s)'>";
        }
    } else {
        print "<tr><td><span class='textError'>You must select at least one User.</span></td></tr>\n";
        $save_html = "<input type='button' value='Return' onClick='cactiReturnTo()'>";
    }
    print "<tr class='saveRow'>\n\t\t<td colspan='2' align='right' bgcolor='#eaeaea'>\n\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t<input type='hidden' name='selected_items' value='" . (isset($user_array) ? serialize($user_array) : '') . "'>\n\t\t\t<input type='hidden' name='drp_action' value='" . $_POST["drp_action"] . "'>\n\t\t\t{$save_html}\n\t\t</td>\n\t</tr>\n";
    html_end_box();
    bottom_footer();
}
Ejemplo n.º 21
0
			/* remove items */
			if (! empty($_REQUEST["graph_remove"])) {
				foreach (explode(",",$_REQUEST["graph_remove"]) as $item) {
					unset($graph_list[$item]);
				}
			}

			$i = 0;
			foreach ($graph_list as $item => $value) {
				$graph_array[$i] = $item;
				$i++;
			}

			if ((isset($graph_array)) && (sizeof($graph_array) > 0)) {
				/* build sql string including each graph the user checked */
				$sql_or = "AND " . array_to_sql_or($graph_array, "graph_templates_graph.local_graph_id");

				/* clear the filter vars so they don't affect our results */
				$_REQUEST["filter"]  = "";
				$_REQUEST["host_id"] = "0";

				/* Fix to avoid error in 'preview' after selection in 'list' : Notice: Undefined index: rra_id in C:\apache2\htdocs\cacti\graph_view.php on line 142 */
				$set_rra_id = empty($rra_id) ? read_graph_config_option("default_rra_id") : $_REQUEST["rra_id"];
			}
		}
	}

	$sql_base = "FROM (graph_templates_graph,graph_local)
		$sql_join
		$sql_where
		" . (empty($sql_where) ? "WHERE" : "AND") . "   graph_templates_graph.local_graph_id > 0
Ejemplo n.º 22
0
function form_mactrack_snmp_actions()
{
    global $config, $mactrack_snmp_actions;
    /* ================= input validation ================= */
    get_filter_request_var('drp_action');
    /* ==================================================== */
    /* if we are to save this form, instead of display it */
    if (isset_request_var('selected_items')) {
        $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
        if ($selected_items != false) {
            if (get_nfilter_request_var('drp_action') == '1') {
                /* delete */
                db_execute('DELETE FROM mac_track_snmp WHERE ' . array_to_sql_or($selected_items, 'id'));
                db_execute('DELETE FROM mac_track_snmp_items WHERE ' . str_replace('id', 'snmp_id', array_to_sql_or($selected_items, 'id')));
            } elseif (get_nfilter_request_var('drp_action') == '2') {
                /* duplicate */
                for ($i = 0; $i < count($selected_items); $i++) {
                    duplicate_mactrack($selected_items[$i], get_nfilter_request_var('name_format'));
                }
            }
            header('Location: mactrack_snmp.php?header=false');
            exit;
        }
    }
    /* setup some variables */
    $snmp_groups = '';
    $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]);
            /* ==================================================== */
            $snmp_groups .= '<li>' . db_fetch_cell_prepared('SELECT name FROM mac_track_snmp WHERE id = ?', array($matches[1])) . '</li>';
            $mactrack_array[$i] = $matches[1];
            $i++;
        }
    }
    general_header();
    display_output_messages();
    ?>
	<script type='text/javascript'>
	function goTo(strURL) {
		loadPageNoHeader(strURL);
	}
	</script>
	<?php 
    form_start('mactrack_snmp.php', 'mactrack');
    html_start_box($mactrack_snmp_actions[get_nfilter_request_var('drp_action')], '60%', '', '3', 'center', '');
    if (!isset($mactrack_array)) {
        print "<tr><td class='even'><span class='textError'>" . __('You must select at least one SNMP Option.') . "</span></td></tr>\n";
        $save_html = "";
    } else {
        $save_html = "<input type='submit' value='" . __('Yes') . "' name='save'>";
        if (get_nfilter_request_var("drp_action") == '1') {
            /* delete */
            print "<tr>\n\t\t\t\t<td class='textArea'>\n\t\t\t\t\t<p>" . __('Are you sure you want to delete the following SNMP Options?') . "</p>\n\t\t\t\t\t<p><ul>{$snmp_groups}</ul></p>\n\t\t\t\t</td>\n\t\t\t</tr>";
        } elseif (get_nfilter_request_var("drp_action") == '2') {
            /* duplicate */
            print "<tr>\n\t\t\t\t<td class='textArea'>\n\t\t\t\t\t<p>" . __('When you click save, the following SNMP Options will be duplicated. You can optionally change the title format for the new SNMP Options.') . "</p>\n\t\t\t\t\t<p><ul>{$snmp_groups}</ul></p>\n\t\t\t\t\t<p>" . __('Name Format:') . "<br>";
            form_text_box('name_format', '<name> (1)', '', '255', '30', 'text');
            print "</p>\n\t\t\t\t</td>\n\t\t\t</tr>";
        }
    }
    print "\t<tr>\n\t\t<td align='right' class='saveRow'>\n\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t<input type='hidden' name='selected_items' value='" . (isset($mactrack_array) ? serialize($mactrack_array) : '') . "'>\n\t\t\t<input type='hidden' name='drp_action' value='" . get_nfilter_request_var("drp_action") . "'>\n\t\t\t<input type='button' onClick='goTo(\"" . "mactrack_snmp.php" . "\")' value='" . ($save_html == '' ? 'Return' : 'No') . "' name='cancel'>\n\t\t\t{$save_html}\n\t\t</td>\n\t</tr>";
    html_end_box();
    bottom_footer();
}
Ejemplo n.º 23
0
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";
}
Ejemplo n.º 24
0
function form_actions() {
	global $colors, $graph_template_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 (get_request_var_post("drp_action") === "1") { /* delete */
			/* do a referential integrity check */
			if (sizeof($selected_items)) {
				foreach($selected_items as $template_id) {
					/* ================= input validation ================= */
					input_validate_input_number($template_id);
					/* ==================================================== */

					if (sizeof(db_fetch_assoc("SELECT * FROM graph_templates_graph WHERE graph_template_id=$template_id AND local_graph_id > 0 LIMIT 1"))) {
						$bad_ids[] = $template_id;
					}else{
						$template_ids[] = $template_id;
					}
				}
			}

			if (isset($bad_ids)) {
				$message = "";
				foreach($bad_ids as $template_id) {
					$message .= (strlen($message) ? "<br>":"") . "<i>Graph Template " . $template_id . " is in use and can not be removed</i>\n";
				}

				$_SESSION['sess_message_gt_ref_int'] = array('message' => "<font size=-2>$message</font>", 'type' => 'info');

				raise_message('gt_ref_int');
			}

			if (isset($template_ids)) {
				db_execute("delete from graph_templates where " . array_to_sql_or($template_ids, "id"));

				$graph_template_input = db_fetch_assoc("select id from graph_template_input where " . array_to_sql_or($template_ids, "graph_template_id"));

				if (sizeof($graph_template_input) > 0) {
					foreach ($graph_template_input as $item) {
						db_execute("delete from graph_template_input_defs where graph_template_input_id=" . $item["id"]);
					}
				}

				db_execute("delete from graph_template_input where " . array_to_sql_or($template_ids, "graph_template_id"));
				db_execute("delete from graph_templates_graph where " . array_to_sql_or($template_ids, "graph_template_id") . " and local_graph_id=0");
				db_execute("delete from graph_templates_item where " . array_to_sql_or($template_ids, "graph_template_id") . " and local_graph_id=0");
				db_execute("delete from device_template_graph where " . array_to_sql_or($template_ids, "graph_template_id"));

				/* "undo" any graph that is currently using this template */
				db_execute("update graph_templates_graph set local_graph_template_graph_id=0,graph_template_id=0 where " . array_to_sql_or($template_ids, "graph_template_id"));
				db_execute("update graph_templates_item set local_graph_template_item_id=0,graph_template_id=0 where " . array_to_sql_or($template_ids, "graph_template_id"));
				db_execute("update graph_local set graph_template_id=0 where " . array_to_sql_or($template_ids, "graph_template_id"));
			}
		}elseif (get_request_var_post("drp_action") === "2") { /* duplicate */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */

				duplicate_graph(0, $selected_items[$i], get_request_var_post("title_format"));
			}
		}

		header("Location: graph_templates.php");
		exit;
	}

	/* setup some variables */
	$graph_list = ""; $i = 0; $graph_array = array();

	/* 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]);
			/* ==================================================== */

			$graph_list .= "<li>" . db_fetch_cell("select name from graph_templates where id=" . $matches[1]) . "<br>";
			$graph_array[$i] = $matches[1];
		}

		$i++;
	}

	include_once(CACTI_BASE_PATH . "/include/top_header.php");

	html_start_box("<strong>" . $graph_template_actions{get_request_var_post("drp_action")} . "</strong>", "60", $colors["header_panel"], "3", "center", "");

	print "<form action='graph_templates.php' method='post'>\n";

	if (sizeof($graph_array)) {
		if (get_request_var_post("drp_action") === ACTION_NONE) { /* NONE */
			print "	<tr>
						<td class='textArea'>
							<p>" . __("You did not select a valid action. Please select 'Return' to return to the previous menu.") . "</p>
						</td>
					</tr>\n";
		}elseif (get_request_var_post("drp_action") === "1") { /* delete */
			print "	<tr>
					<td class='textArea'>
						<p>" . __("Are you sure you want to delete the following graph templates? Any graphs attached to these templates will become individual graphs.") . "</p>
						<p>$graph_list</p>
					</td>
				</tr>\n
				";
		}elseif (get_request_var_post("drp_action") === "2") { /* duplicate */
			print "	<tr>
					<td class='textArea'>
						<p>" . __("When you click save, the following graph templates will be duplicated. You can optionally change the title format for the new graph templates.") . "</p>
						<p>$graph_list</p>
						<p><strong>" . __("Title Format:") . "</strong><br>"; form_text_box("title_format", "<template_title> (1)", "", "255", "30", "text"); print "</p>
					</td>
				</tr>\n
				";
		}
	} else {
		print "	<tr>
				<td class='textArea'>
					<p>" . __("You must first select a Graph Template.  Please select 'Return' to return to the previous menu.") . "</p>
				</td>
			</tr>\n";
	}

	if (!sizeof($graph_array) || get_request_var_post("drp_action") === ACTION_NONE) {
		form_return_button_alt();
	}else{
		form_yesno_button_alt(serialize($graph_array), get_request_var_post("drp_action"));
	}

	html_end_box();

	include_once(CACTI_BASE_PATH . "/include/bottom_footer.php");
}
Ejemplo n.º 25
0
Archivo: host.php Proyecto: MrWnn/cacti
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()'>&nbsp;<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()'>&nbsp;<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()'>&nbsp;<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()'>&nbsp;<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()'>&nbsp;<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()'>&nbsp;<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()'>&nbsp;<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()'>&nbsp;<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();
}
Ejemplo n.º 26
0
function resolve_dependencies($type, $id, $dep_array)
{
    /* make sure we define our variables */
    if (!isset($dep_array[$type])) {
        $dep_array[$type] = array();
    }
    switch ($type) {
        case 'graph_template':
            /* dep: data template */
            $graph_template_items = db_fetch_assoc("select\n\t\t\tdata_template_rrd.data_template_id\n\t\t\tfrom (graph_templates_item,data_template_rrd)\n\t\t\twhere graph_templates_item.task_item_id=data_template_rrd.id\n\t\t\tand graph_templates_item.graph_template_id={$id}\n\t\t\tand graph_templates_item.local_graph_id=0\n\t\t\tand graph_templates_item.task_item_id > 0\n\t\t\tgroup by data_template_rrd.data_template_id");
            if (sizeof($graph_template_items) > 0) {
                foreach ($graph_template_items as $item) {
                    if (!isset($dep_array["data_template"][$item["data_template_id"]])) {
                        $dep_array = resolve_dependencies("data_template", $item["data_template_id"], $dep_array);
                    }
                }
            }
            /* dep: cdef */
            $cdef_items = db_fetch_assoc("select cdef_id from graph_templates_item where graph_template_id={$id} and local_graph_id=0 and cdef_id > 0 group by cdef_id");
            $recursive = true;
            /* in the first turn, search all inherited cdef items related to all cdef's known on highest recursion level */
            $search_cdef_items = $cdef_items;
            if (sizeof($cdef_items) > 0) {
                while ($recursive) {
                    /* are there any inherited cdef's within those referenced by any graph item? 
                     * search for all cdef_items of type = 5 (inherited cdef) 
                     * but fetch only those related to already given cdef's */
                    $sql = "SELECT value as cdef_id " . "FROM cdef_items " . "WHERE type = 5 " . "AND " . array_to_sql_or($search_cdef_items, "cdef_id");
                    $inherited_cdef_items = db_fetch_assoc($sql);
                    /* in case we found any */
                    if (sizeof($inherited_cdef_items) > 0) {
                        /* join all cdef's found 
                         * ATTENTION!
                         * sequence of parameters matters! 
                         * we must place the newly found inherited items first
                         * reason is, that during import, the leafes have to be tackled first,
                         * that is, the inherited items must be placed first so that they are "resolved" (decoded)
                         * first during re-import */
                        $cdef_items = array_merge_recursive($inherited_cdef_items, $cdef_items);
                        /* for the next turn, search only new cdef's */
                        $search_cdef_items = $inherited_cdef_items;
                    } else {
                        /* else stop recursion */
                        $recursive = false;
                    }
                }
                foreach ($cdef_items as $item) {
                    if (!isset($dep_array["cdef"][$item["cdef_id"]])) {
                        $dep_array = resolve_dependencies("cdef", $item["cdef_id"], $dep_array);
                    }
                }
            }
            /* dep: gprint preset */
            $graph_template_items = db_fetch_assoc("select gprint_id from graph_templates_item where graph_template_id={$id} and local_graph_id=0 and gprint_id > 0 group by gprint_id");
            if (sizeof($graph_template_items) > 0) {
                foreach ($graph_template_items as $item) {
                    if (!isset($dep_array["gprint_preset"][$item["gprint_id"]])) {
                        $dep_array = resolve_dependencies("gprint_preset", $item["gprint_id"], $dep_array);
                    }
                }
            }
            break;
        case 'data_template':
            /* dep: data input method */
            $item = db_fetch_row("select data_input_id from data_template_data where data_template_id={$id} and local_data_id=0 and data_input_id > 0");
            if (!empty($item) && !isset($dep_array["data_input_method"][$item["data_input_id"]])) {
                $dep_array = resolve_dependencies("data_input_method", $item["data_input_id"], $dep_array);
            }
            /* dep: round robin archive */
            $rras = db_fetch_assoc("select rra_id from data_template_data_rra where data_template_data_id=" . db_fetch_cell("select id from data_template_data where data_template_id={$id} and local_data_id = 0"));
            if (sizeof($rras) > 0) {
                foreach ($rras as $item) {
                    if (!isset($dep_array["round_robin_archive"][$item["rra_id"]])) {
                        $dep_array = resolve_dependencies("round_robin_archive", $item["rra_id"], $dep_array);
                    }
                }
            }
            break;
        case 'data_query':
            /* dep: data input method */
            $item = db_fetch_row("select data_input_id from snmp_query where id={$id} and data_input_id > 0");
            if (!empty($item) && !isset($dep_array["data_input_method"][$item["data_input_id"]])) {
                $dep_array = resolve_dependencies("data_input_method", $item["data_input_id"], $dep_array);
            }
            /* dep: graph template */
            $snmp_query_graph = db_fetch_assoc("select graph_template_id from snmp_query_graph where snmp_query_id={$id} and graph_template_id > 0 group by graph_template_id");
            if (sizeof($snmp_query_graph) > 0) {
                foreach ($snmp_query_graph as $item) {
                    if (!isset($dep_array["graph_template"][$item["graph_template_id"]])) {
                        $dep_array = resolve_dependencies("graph_template", $item["graph_template_id"], $dep_array);
                    }
                }
            }
            break;
        case 'host_template':
            /* dep: graph template */
            $host_template_graph = db_fetch_assoc("select graph_template_id from host_template_graph where host_template_id={$id} and graph_template_id > 0 group by graph_template_id");
            if (sizeof($host_template_graph) > 0) {
                foreach ($host_template_graph as $item) {
                    if (!isset($dep_array["graph_template"][$item["graph_template_id"]])) {
                        $dep_array = resolve_dependencies("graph_template", $item["graph_template_id"], $dep_array);
                    }
                }
            }
            /* dep: data query */
            $host_template_snmp_query = db_fetch_assoc("select snmp_query_id from host_template_snmp_query where host_template_id={$id} and snmp_query_id > 0 group by snmp_query_id");
            if (sizeof($host_template_snmp_query) > 0) {
                foreach ($host_template_snmp_query as $item) {
                    if (!isset($dep_array["data_query"][$item["snmp_query_id"]])) {
                        $dep_array = resolve_dependencies("data_query", $item["snmp_query_id"], $dep_array);
                    }
                }
            }
            break;
    }
    /* update the dependency array */
    $dep_array[$type][$id] = $id;
    return $dep_array;
}
Ejemplo n.º 27
0
function get_ordered_index_type_list($host_id, $data_query_id, $data_query_index_array = array()) {
	$raw_xml = get_data_query_array($data_query_id);

	/* invalid xml check */
	if ((!is_array($raw_xml)) || (sizeof($raw_xml) == 0)) {
		return array();
	}

	$xml_outputs = array();

	/* create an SQL string that contains each index in this snmp_index_id */
	$sql_or = array_to_sql_or($data_query_index_array, "snmp_index");

	/* check for nonunique query parameter, set value */
	if (isset($raw_xml["index_type"])) {
		if ($raw_xml["index_type"] == "nonunique") {
			$nonunique = 1;
		}else{
			$nonunique = 0;
		}
	} else {
		$nonunique = 0;
	}

	/* list each of the input fields for this snmp query */
	while (list($field_name, $field_array) = each($raw_xml["fields"])) {
		if ($field_array["direction"] == "input") {
			/* create a list of all values for this index */
			if (sizeof($data_query_index_array) == 0) {
				$field_values = db_fetch_assoc("select field_value from host_snmp_cache where host_id=$host_id and snmp_query_id=$data_query_id and field_name='$field_name'");
			}else{
				$field_values = db_fetch_assoc("select field_value from host_snmp_cache where host_id=$host_id and snmp_query_id=$data_query_id and field_name='$field_name' and $sql_or");
			}

			/* aggregate the above list so there is no duplicates */
			$aggregate_field_values = array_rekey($field_values, "field_value", "field_value");

			/* fields that contain duplicate or empty values are not suitable to index off of */
			if (!((sizeof($aggregate_field_values) < sizeof($field_values)) || (in_array("", $aggregate_field_values) == true) || (sizeof($aggregate_field_values) == 0)) || ($nonunique)) {
				array_push($xml_outputs, $field_name);
			}
		}
	}

	$return_array = array();

	/* the xml file contains an ordered list of "indexable" fields */
	if (isset($raw_xml["index_order"])) {
		$index_order_array = explode(":", $raw_xml["index_order"]);

		for ($i=0; $i<count($index_order_array); $i++) {
			if (in_array($index_order_array[$i], $xml_outputs)) {
				$return_array[] = $index_order_array[$i];
			}
		}
	/* the xml file does not contain a field list, ignore the order */
	}else{
		for ($i=0; $i<count($xml_outputs); $i++) {
			$return_array[] = $xml_outputs[$i];
		}
	}

	return $return_array;
}
Ejemplo n.º 28
0
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()'>&nbsp;<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()'>&nbsp;<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()'>&nbsp;<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()'>&nbsp;<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()'>&nbsp;<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()'>&nbsp;<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()'>&nbsp;<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()'>&nbsp;<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()'>&nbsp;<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";
}
Ejemplo n.º 29
0
/** push_out_graph_input - pushes out the value of a graph input to a single child item. this function
	differs from other push_out_* functions in that it does not push out the value of this element to
	all attached children. instead, it obtains the current value of the graph input based on other
	graph items and pushes out the "active" value
   @param int $graph_template_input_id 	- the id of the graph input to push out values for
   @param int $graph_template_item_id 	- the id the graph template item to push out
   @param array $session_members 		- when looking for the "active" value of the graph input, ignore these graph
	template items. typically you want to ignore all items that were just selected and have yet to be
	saved to the database. this is because these items most likely contain incorrect data */
function push_out_graph_input($graph_template_input_id, $graph_template_item_id, $session_members) {
	$graph_input = db_fetch_row("select graph_template_id,column_name from graph_template_input where id=$graph_template_input_id");
	$graph_input_items = db_fetch_assoc("select graph_template_item_id from graph_template_input_defs where graph_template_input_id=$graph_template_input_id");

	$i = 0;
	if (sizeof($graph_input_items) > 0) {
	foreach ($graph_input_items as $item) {
		$include_items[$i] = $item["graph_template_item_id"];
		$i++;
	}
	}

	/* we always want to make sure to stay within the same graph item input, so make a list of each
	item included in this input to be included in the sql query */
	if (isset($include_items)) {
		$sql_include_items = "and " . array_to_sql_or($include_items, "local_graph_template_item_id");
	}else{
		$sql_include_items = "and 0=1";
	}

	if (sizeof($session_members) == 0) {
		$values_to_apply = db_fetch_assoc("select local_graph_id," . $graph_input["column_name"] . " from graph_templates_item where graph_template_id=" . $graph_input["graph_template_id"] . " $sql_include_items and local_graph_id>0 group by local_graph_id");
	}else{
		$i = 0;
		while (list($item_id, $item_id) = each($session_members)) {
			$new_session_members[$i] = $item_id;
			$i++;
		}

		$values_to_apply = db_fetch_assoc("select local_graph_id," . $graph_input["column_name"] . " from graph_templates_item where graph_template_id=" . $graph_input["graph_template_id"] . " and local_graph_id>0 and !(" . array_to_sql_or($new_session_members, "local_graph_template_item_id") . ") $sql_include_items group by local_graph_id");
	}

	if (sizeof($values_to_apply) > 0) {
	foreach ($values_to_apply as $value) {
		/* this is just an extra check that i threw in to prevent users' graphs from getting really messed up */
		if (!(($graph_input["column_name"] == "task_item_id") && (empty($value{$graph_input["column_name"]})))) {
			db_execute("update graph_templates_item set " . $graph_input["column_name"] . "='" . addslashes($value{$graph_input["column_name"]}) . "' where local_graph_id=" . $value["local_graph_id"] . " and local_graph_template_item_id=$graph_template_item_id");
		}
	}
	}
}
Ejemplo n.º 30
0
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()'>&nbsp;<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()'>&nbsp;<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()'>&nbsp;<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()'>&nbsp;<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()'>&nbsp;<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()'>&nbsp;<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()'>&nbsp;<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()'>&nbsp;<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";
}