Ejemplo n.º 1
0
function thold_user_auth_threshold($rra)
{
    $current_user = db_fetch_row("select policy_graphs,policy_hosts,policy_graph_templates from user_auth where id=" . $_SESSION["sess_user_id"]);
    $sql_where = 'WHERE ' . get_graph_permissions_sql($current_user['policy_graphs'], $current_user['policy_hosts'], $current_user['policy_graph_templates']);
    $graphs = db_fetch_assoc('SELECT DISTINCT graph_templates_graph.local_graph_id
		FROM data_template_rrd
		LEFT JOIN graph_templates_item ON graph_templates_item.task_item_id = data_template_rrd.id
		LEFT JOIN graph_local ON (graph_local.id=graph_templates_item.local_graph_id)
		LEFT JOIN host ON graph_local.host_id = host.id
		LEFT JOIN graph_templates_graph ON graph_templates_graph.local_graph_id = graph_local.id
		LEFT JOIN graph_templates ON (graph_templates.id=graph_templates_graph.graph_template_id)
		LEFT JOIN user_auth_perms on ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=1 and user_auth_perms.user_id=' . $_SESSION['sess_user_id'] . ') OR (host.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=' . $_SESSION['sess_user_id'] . ') OR (graph_templates.id=user_auth_perms.item_id and user_auth_perms.type=4 and user_auth_perms.user_id=' . $_SESSION['sess_user_id'] . "))\r\n\t\t{$sql_where}\r\n\t\tAND data_template_rrd.local_data_id = {$rra}");
    if (!empty($graphs)) {
        return true;
    }
    return false;
}
Ejemplo n.º 2
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.º 3
0
function is_graph_allowed($local_graph_id)
{
    $current_user = db_fetch_row("select policy_graphs,policy_hosts,policy_graph_templates from user_auth where id=" . $_SESSION["sess_user_id"]);
    /* get policy information for the sql where clause */
    $sql_where = get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]);
    $graphs = db_fetch_assoc("select\n\t\tgraph_templates_graph.local_graph_id\n\t\tfrom (graph_templates_graph,graph_local)\n\t\tleft join host on (host.id=graph_local.host_id)\n\t\tleft join graph_templates on (graph_templates.id=graph_local.graph_template_id)\n\t\tleft join user_auth_perms on ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=1 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (host.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_templates.id=user_auth_perms.item_id and user_auth_perms.type=4 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . "))\n\t\twhere graph_templates_graph.local_graph_id=graph_local.id\n\t\t" . (empty($sql_where) ? "" : "and {$sql_where}") . "\n\t\tand graph_templates_graph.local_graph_id={$local_graph_id}\n\t\tgroup by graph_templates_graph.local_graph_id");
    if (sizeof($graphs) > 0) {
        return true;
    } else {
        return false;
    }
}
Ejemplo n.º 4
0
function get_graph_tree_content($tree_id, $leaf_id, $device_group_data) {
	global $current_user, $colors, $config, $graphs_per_page;

	include(CACTI_BASE_PATH . "/include/global_arrays.php");
	require(CACTI_BASE_PATH . "/include/graph_tree/graph_tree_arrays.php");
	include_once(CACTI_BASE_PATH . "/lib/data_query.php");
	include_once(CACTI_BASE_PATH . "/lib/tree.php");
	include_once(CACTI_BASE_PATH . "/lib/html_utility.php");
	include_once(CACTI_BASE_PATH . "/lib/graph/graph_view_form.php");
	define("MAX_DISPLAY_PAGES", 21);

	if (empty($tree_id)) { return; }

	$sql_where       = "";
	$sql_join        = "";
	$title           = "";
	$title_delimeter = "";
	$search_key      = "";

	$leaf      = db_fetch_row("SELECT order_key, title, device_id, device_grouping_type
					FROM graph_tree_items
					WHERE id=$leaf_id");

	$leaf_type = get_tree_item_type($leaf_id);

	/* get the "starting leaf" if the user clicked on a specific branch */
	if (!empty($leaf_id)) {
		$search_key = substr($leaf["order_key"], 0, (tree_tier($leaf["order_key"]) * CHARS_PER_TIER));
	}

	/* graph permissions */
	if (read_config_option("auth_method") != 0) {
		/* get policy information for the sql where clause */
		$sql_where = get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_devices"], $current_user["policy_graph_templates"]);
		$sql_where = (empty($sql_where) ? "" : "AND $sql_where");
		$sql_join = "
			LEFT JOIN device ON (device.id=graph_local.device_id)
			LEFT JOIN graph_templates ON (graph_templates.id=graph_local.graph_template_id)
			LEFT JOIN user_auth_perms ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id AND user_auth_perms.type=1 AND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (device.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_templates.id=user_auth_perms.item_id AND user_auth_perms.type=4 AND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . "))";
	}

	/* get information for the headers */
	if (!empty($tree_id)) { $tree_name = db_fetch_cell("SELECT name FROM graph_tree WHERE id=$tree_id"); }
	if (!empty($leaf_id)) { $leaf_name = $leaf["title"]; }
	if (!empty($leaf_id)) { $device_name = db_fetch_cell("SELECT device.description FROM (graph_tree_items,device) WHERE graph_tree_items.device_id=device.id AND graph_tree_items.id=$leaf_id"); }

	$device_group_data_array = $device_group_data;

	if ($device_group_data_array[0] == "gt") {
		$device_group_data_name = "Graph Template: " . db_fetch_cell("select name from graph_templates where id=" . $device_group_data_array[1]);
		$graph_template_id = $device_group_data_array[1];
	}elseif ($device_group_data_array[0] == "dq") {
		$device_group_data_name = "Graph Template: " . (empty($device_group_data_array[1]) ? "Non Query Based" : db_fetch_cell("select name from snmp_query where id=" . $device_group_data_array[1]));
		$data_query_id = $device_group_data_array[1];
	}elseif ($device_group_data_array[0] == "dqi") {
		$device_group_data_name = "Graph Template: " . (empty($device_group_data_array[1]) ? "Non Query Based" : db_fetch_cell("select name from snmp_query where id=" . $device_group_data_array[1])) . "-> " . (empty($device_group_data_array[2]) ? "Template Based" : get_formatted_data_query_index($leaf["device_id"], $device_group_data_array[1], $device_group_data_array[2]));
		$data_query_id = $device_group_data_array[1];
		$data_query_index = $device_group_data_array[2];
	}

	if (!empty($tree_name)) { $title .= $title_delimeter . "<strong>Tree:</strong> $tree_name"; $title_delimeter = "-> "; }
	if (!empty($leaf_name)) { $title .= $title_delimeter . "<strong.Leaf:</strong> $leaf_name"; $title_delimeter = "-> "; }
	if (!empty($device_name)) { $title .= $title_delimeter . "<strong>Host:</strong> $device_name"; $title_delimeter = "-> "; }
	if (!empty($device_group_data_name)) { $title .= $title_delimeter . " $device_group_data_name"; $title_delimeter = "-> "; }

	/* ================= input validation ================= */
	input_validate_input_number(get_request_var_request("graphs"));
	input_validate_input_number(get_request_var_request("page"));
	/* ==================================================== */

	/* if the user pushed the 'clear' button */
	if (isset($_REQUEST["clear_filter"])) {
		kill_session_var("sess_graph_view_graphs");
		kill_session_var("sess_graph_view_filter");
		kill_session_var("sess_graph_view_page");

		unset($_REQUEST["graphs"]);
		unset($_REQUEST["filter"]);
		unset($_REQUEST["page"]);

		$changed = true;
	}else{
		/* if any of the settings changed, reset the page number */
		$changed = 0;
		$changed += check_changed("graphs",          "sess_graph_view_graphs");
		$changed += check_changed("filter",          "sess_graph_view_filter");
		$changed += check_changed("action",          "sess_graph_view_action");
	}

	if (isset($_SESSION["sess_graph_view_tree_id"])) {
		if ($_SESSION["sess_graph_view_tree_id"] != $tree_id) {
			$changed += 1;
		}
	}
	$_SESSION["sess_graph_view_tree_id"] = $tree_id;

	if (isset($_SESSION["sess_graph_view_leaf_id"])) {
		if ($_SESSION["sess_graph_view_leaf_id"] != $leaf_id) {
			$changed += 1;
		}
	}
	$_SESSION["sess_graph_view_leaf_id"] = $leaf_id;

	if (isset($_SESSION["sess_graph_view_device_group_data"])) {
		if ($_SESSION["sess_graph_view_device_group_data"] != $device_group_data) {
			$changed += 1;
		}
	}
	$_SESSION["sess_graph_view_device_group_data"] = $device_group_data;

	if ($changed) {
		$_REQUEST["page"] = 1;
	}

	load_current_session_value("page",   "sess_graph_view_page",   "1");
	load_current_session_value("graphs", "sess_graph_view_graphs", read_graph_config_option("treeview_graphs_per_page"));
	load_current_session_value("filter", "sess_graph_view_filter", "");
	load_current_session_value("thumbnails", "sess_graph_view_thumbnails", (read_graph_config_option("thumbnail_section_tree_2") == CHECKED ? "true":""));

	$graph_list = array();

	if (($leaf_type == "header") || (empty($leaf_id))) {
		if (strlen(get_request_var_request("filter"))) {
			$sql_where = "AND (title_cache LIKE '%" . $_REQUEST["filter"] . "%' OR graph_templates_graph.title LIKE '%" . $_REQUEST["filter"] . "%')";
		}

		$graph_list = db_fetch_assoc("SELECT
			graph_tree_items.id,
			graph_tree_items.title,
			graph_tree_items.local_graph_id,
			graph_tree_items.rra_id,
			graph_tree_items.order_key,
			graph_templates_graph.height,
			graph_templates_graph.title_cache as title_cache,
			graph_templates_graph.image_format_id
			FROM (graph_tree_items,graph_local)
			LEFT JOIN graph_templates_graph ON (graph_tree_items.local_graph_id=graph_templates_graph.local_graph_id AND graph_tree_items.local_graph_id>0)
			$sql_join
			WHERE graph_tree_items.graph_tree_id=$tree_id
			AND graph_local.id=graph_templates_graph.local_graph_id
			AND graph_tree_items.order_key like '$search_key" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', (MAX_TREE_DEPTH * CHARS_PER_TIER) - (strlen($search_key) + CHARS_PER_TIER)) . "'
			AND graph_tree_items.local_graph_id>0
			$sql_where
			GROUP BY graph_tree_items.id
			ORDER BY graph_tree_items.order_key");
	}elseif ($leaf_type == "device") {
		/* graph template grouping */
		if ($leaf["device_grouping_type"] == TREE_DEVICE_GROUPING_GRAPH_TEMPLATE) {
			$graph_templates = db_fetch_assoc("SELECT
				graph_templates.id,
				graph_templates.name
				FROM (graph_local,graph_templates,graph_templates_graph)
				WHERE graph_local.id=graph_templates_graph.local_graph_id
				AND graph_templates_graph.graph_template_id=graph_templates.id
				AND graph_local.device_id=" . $leaf["device_id"] . "
				" . (empty($graph_template_id) ? "" : "AND graph_templates.id=$graph_template_id") . "
				GROUP BY graph_templates.id
				ORDER BY graph_templates.name");

			/* for graphs without a template */
			array_push($graph_templates, array(
				"id" => "0",
				"name" => "(No Graph Template)"
				));

			if (sizeof($graph_templates) > 0) {
				foreach ($graph_templates as $graph_template) {
					if (strlen(get_request_var_request("filter"))) {
						$sql_where = "AND (title_cache LIKE '%" . $_REQUEST["filter"] . "%')";
					}

					$graphs = db_fetch_assoc("SELECT
						graph_templates_graph.title_cache,
						graph_templates_graph.local_graph_id,
						graph_templates_graph.height,
						graph_templates_graph.image_format_id
						FROM (graph_local,graph_templates_graph)
						$sql_join
						WHERE graph_local.id=graph_templates_graph.local_graph_id
						AND graph_local.graph_template_id=" . $graph_template["id"] . "
						AND graph_local.device_id=" . $leaf["device_id"] . "
						$sql_where
						ORDER BY graph_templates_graph.title_cache");

					/* let's sort the graphs naturally */
					if (sizeof($graphs)) {
						usort($graphs, 'naturally_sort_graphs');

						foreach ($graphs as $graph) {
							$graph["graph_template_name"] = $graph_template["name"];
							array_push($graph_list, $graph);
						}
					}
				}
			}
			/* data query index grouping */
		}elseif ($leaf["device_grouping_type"] == TREE_DEVICE_GROUPING_DATA_QUERY_INDEX) {
			$data_queries = db_fetch_assoc("SELECT
				snmp_query.id,
				snmp_query.name
				FROM (graph_local,snmp_query)
				WHERE graph_local.snmp_query_id=snmp_query.id
				AND graph_local.device_id=" . $leaf["device_id"] . "
				" . (!isset($data_query_id) ? "" : "and snmp_query.id=$data_query_id") . "
				GROUP BY snmp_query.id
				ORDER BY snmp_query.name");

			/* for graphs without a data query */
			if (empty($data_query_id)) {
				array_push($data_queries, array(
					"id" => "0",
					"name" => "Non Query Based"
					));
			}

			if (sizeof($data_queries) > 0) {
				foreach ($data_queries as $data_query) {
					/* fetch a list of field names that are sorted by the preferred sort field */
					$sort_field_data = get_formatted_data_query_indexes($leaf["device_id"], $data_query["id"]);

					if (strlen(get_request_var_request("filter"))) {
						$sql_where = "AND (title_cache LIKE '%" . $_REQUEST["filter"] . "%')";
					}

					/* grab a list of all graphs for this device/data query combination */
					$graphs = db_fetch_assoc("SELECT
						graph_templates_graph.title_cache,
						graph_templates_graph.local_graph_id,
						graph_templates_graph.height,
						graph_templates_graph.image_format_id,
						graph_local.snmp_index
						FROM (graph_local, graph_templates_graph)
						$sql_join
						WHERE graph_local.id=graph_templates_graph.local_graph_id
						AND graph_local.snmp_query_id=" . $data_query["id"] . "
						AND graph_local.device_id=" . $leaf["device_id"] . "
						" . (empty($data_query_index) ? "" : "and graph_local.snmp_index='$data_query_index'") . "
						$sql_where
						GROUP BY graph_templates_graph.local_graph_id
						ORDER BY graph_templates_graph.title_cache");

					/* re-key the results on data query index */
					if (sizeof($graphs)) {
						/* let's sort the graphs naturally */
						usort($graphs, 'naturally_sort_graphs');

						foreach ($graphs as $graph) {
							$snmp_index_to_graph{$graph["snmp_index"]} = array(
								"local_graph_id"	=> $graph["local_graph_id"],
								"title_cache"		=> $graph["title_cache"],
								"image_format_id"	=> $graph["image_format_id"],
							);
							$graphs_height[$graph["local_graph_id"]] = $graph["height"];
						}
					}

					/* using the sorted data as they key; grab each snmp index from the master list */
					while (list($snmp_index, $sort_field_value) = each($sort_field_data)) {
						/* render each graph for the current data query index */
						if (isset($snmp_index_to_graph[$snmp_index])) {
							#while (list($local_graph_id, $graph_title) = each($snmp_index_to_graph[$snmp_index])) {
							foreach ($snmp_index_to_graph as $graph) {
								/* reformat the array so it's compatable with the html_graph* area functions */
								array_push($graph_list, array(
									"data_query_name"   => $data_query["name"],
									"sort_field_value" 	=> $sort_field_value,
									"local_graph_id"    => $graph["local_graph_id"],
									"title_cache"       => $graph["title_cache"],
									"image_format_id"   => $graph["image_format_id"],
									"height"            => $graphs_height[$graph["local_graph_id"]]
								));
							}
						}
					}
				}
			}
		}
	}

	$total_rows = sizeof($graph_list);

	if (read_graph_config_option("timespan_sel") == CHECKED) {
		graph_view_timespan_selector();
	}

	graph_view_search_filter();

	?>
	<script type='text/javascript'>
	<!--
	function pageChange(page) {
		strURL = '?action=ajax_tree_graphs&page=' + page;
		$.get("graph_view.php" + strURL, function (data) {
			$("#graphs").html(data);
		});
	}
	-->
	</script>
	<?php

	print "<table cellpadding='0' cellspacing='0' style='width:100%;border:1px solid #BEBEBE;'>\n";
	/* generate page list */
	if ($total_rows > get_request_var_request("graphs")) {
		$url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, $_REQUEST["graphs"], $total_rows, "pageChange");

		$nav = "\t\t\t<tr class='rowHeader'>
				<td colspan='11'>
					<table width='100%' cellspacing='0' cellpadding='0' border='0'>
						<tr>
							<td align='left' style='width:100px;' class='textHeaderDark'>";
		if ($_REQUEST["page"] > 1) { $nav .= "<strong><a class='linkOverDark' href='#' onClick='pageChange(" . ($_REQUEST["page"]-1) . ")'>&lt;&lt;&nbsp;" . __("Previous") . "</a></strong>"; }
		$nav .= "</td>\n
							<td align='center' class='textHeaderDark'>
								" . __("Showing Graphs") . " " . ((get_request_var_request("graphs")*(get_request_var_request("page")-1))+1) . " " . __("to") . " " . ((($total_rows < read_graph_config_option("treeview_graphs_per_page")) || ($total_rows < (get_request_var_request("graphs")*get_request_var_request("page")))) ? $total_rows : (get_request_var_request("graphs")*get_request_var_request("page"))) . " " . __("of") . " $total_rows [$url_page_select]
							</td>\n
							<td align='right' style='width:100px;' class='textHeaderDark'>";
		if (($_REQUEST["page"] * $_REQUEST["graphs"]) < $total_rows) { $nav .= "<strong><a class='linkOverDark' href='#' onClick='pageChange(" . ($_REQUEST["page"]+1) . ")'>". __("Next") . " &gt;&gt;</a></strong>"; }
		$nav .= "</td>\n
						</tr>
					</table>
				</td>
			</tr>\n";
	}else{
		$nav = "<tr class='rowHeader'>
				<td colspan='11'>
					<table width='100%' cellspacing='0' cellpadding='0' border='0'>
						<tr>
							<td align='center' class='textHeaderDark'>
								" . __("Showing All Graphs") . (strlen(get_request_var_request("filter")) ? " [ " . __("Filter") . " '" . get_request_var_request("filter") . "' ". __("Applied") . " ]" : "") . "
							</td>
						</tr>
					</table>
				</td>
			</tr>\n";
	}

	print $nav;

	/* start graph display */
	print "\t\t\t<tr class='rowSubHeaderAlt'><td width='390' colspan='10' class='textHeaderLight'>$title</td></tr>";

	$i = $_REQUEST["graphs"] * ($_REQUEST["page"] - 1);
	$last_graph = $i + $_REQUEST["graphs"];

	$new_graph_list = array();
	while ($i < $total_rows && $i < $last_graph) {
		$new_graph_list[] = $graph_list[$i];
		$i++;
	}

	if (get_request_var_request("thumbnails") == "true") {
		html_graph_thumbnail_area($new_graph_list, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end());
	}else{
		html_graph_area($new_graph_list, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end());
	}

	print $nav;

	print "</table>\n";
}
Ejemplo n.º 5
0
function grow_right_pane_tree($tree_id, $leaf_id, $host_group_data) {
	global $current_user, $colors, $config;

	include($config["include_path"] . "/config_arrays.php");
	include_once($config["library_path"] . "/data_query.php");
	include_once($config["library_path"] . "/tree.php");
	include_once($config["library_path"] . "/html_utility.php");

	if (empty($tree_id)) { return; }

	$sql_where = "";
	$sql_join = "";
	$title = "";
	$title_delimeter = "";
	$search_key = "";

	$leaf = db_fetch_row("select order_key,title,host_id,host_grouping_type from graph_tree_items where id=$leaf_id");
	$leaf_type = get_tree_item_type($leaf_id);

	/* get the "starting leaf" if the user clicked on a specific branch */
	if (!empty($leaf_id)) {
		$search_key = substr($leaf["order_key"], 0, (tree_tier($leaf["order_key"]) * CHARS_PER_TIER));
	}

	/* graph permissions */
	if (read_config_option("global_auth") == "on") {
		/* get policy information for the sql where clause */
		$sql_where = get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]);
		$sql_where = (empty($sql_where) ? "" : "and $sql_where");
		$sql_join = "
			left join host on (host.id=graph_local.host_id)
			left join graph_templates on (graph_templates.id=graph_local.graph_template_id)
			left join user_auth_perms on ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=1 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (host.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_templates.id=user_auth_perms.item_id and user_auth_perms.type=4 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . "))";
	}

	/* get information for the headers */
	if (!empty($tree_id)) { $tree_name = db_fetch_cell("select name from graph_tree where id=$tree_id"); }
	if (!empty($leaf_id)) { $leaf_name = $leaf["title"]; }
	if (!empty($leaf_id)) { $host_name = db_fetch_cell("select host.description from (graph_tree_items,host) where graph_tree_items.host_id=host.id and graph_tree_items.id=$leaf_id"); }

	$host_group_data_array = explode(":", $host_group_data);

	if ($host_group_data_array[0] == "graph_template") {
		$host_group_data_name = "<strong>Graph Template:</strong> " . db_fetch_cell("select name from graph_templates where id=" . $host_group_data_array[1]);
		$graph_template_id = $host_group_data_array[1];
	}elseif ($host_group_data_array[0] == "data_query") {
		$host_group_data_name = "<strong>Data Query:</strong> " . (empty($host_group_data_array[1]) ? "(Non Indexed)" : db_fetch_cell("select name from snmp_query where id=" . $host_group_data_array[1]));
		$data_query_id = $host_group_data_array[1];
	}elseif ($host_group_data_array[0] == "data_query_index") {
		$host_group_data_name = "<strong>Data Query:</strong> " . (empty($host_group_data_array[1]) ? "(Non Indexed) " : db_fetch_cell("select name from snmp_query where id=" . $host_group_data_array[1])) . "-> " . (empty($host_group_data_array[2]) ? "Unknown Index" : get_formatted_data_query_index($leaf["host_id"], $host_group_data_array[1], $host_group_data_array[2]));
		$data_query_id = $host_group_data_array[1];
		$data_query_index = $host_group_data_array[2];
	}

	if (!empty($tree_name)) { $title .= $title_delimeter . "<strong>Tree:</strong> $tree_name"; $title_delimeter = "-> "; }
	if (!empty($leaf_name)) { $title .= $title_delimeter . "<strong>Leaf:</strong> $leaf_name"; $title_delimeter = "-> "; }
	if (!empty($host_name)) { $title .= $title_delimeter . "<strong>Host:</strong> $host_name"; $title_delimeter = "-> "; }
	if (!empty($host_group_data_name)) { $title .= $title_delimeter . " $host_group_data_name"; $title_delimeter = "-> "; }

	print "<table width='98%' align='center' cellpadding='3'>";

	/* include time span selector */
	if (read_graph_config_option("timespan_sel") == "on") {
		html_graph_start_box(3, false);
		include("./include/html/inc_timespan_selector.php");
		html_graph_end_box();
		print "<br>";
	}

	/* start graph display */
	html_graph_start_box(3, false);
	print "<tr bgcolor='#" . $colors["header_panel"] . "'><td width='390' colspan='3' class='textHeaderDark'>$title</td></tr>";

	if (($leaf_type == "header") || (empty($leaf_id))) {
		$heirarchy = db_fetch_assoc("select
			graph_tree_items.id,
			graph_tree_items.title,
			graph_tree_items.local_graph_id,
			graph_tree_items.rra_id,
			graph_tree_items.order_key,
			graph_templates_graph.title_cache as title_cache
			from (graph_tree_items,graph_local)
			left join graph_templates_graph on (graph_tree_items.local_graph_id=graph_templates_graph.local_graph_id and graph_tree_items.local_graph_id>0)
			$sql_join
			where graph_tree_items.graph_tree_id=$tree_id
			and graph_local.id=graph_templates_graph.local_graph_id
			and graph_tree_items.order_key like '$search_key" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', (MAX_TREE_DEPTH * CHARS_PER_TIER) - (strlen($search_key) + CHARS_PER_TIER)) . "'
			and graph_tree_items.local_graph_id>0
			$sql_where
			group by graph_tree_items.id
			order by graph_tree_items.order_key");

		if (read_graph_config_option("thumbnail_section_tree_2") == "on") {
			html_graph_thumbnail_area($heirarchy, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end());
		}else{
			html_graph_area($heirarchy, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end());
		}
	}elseif ($leaf_type == "host") {
		/* graph template grouping */
		if ($leaf["host_grouping_type"] == HOST_GROUPING_GRAPH_TEMPLATE) {
			$graph_templates = db_fetch_assoc("select
				graph_templates.id,
				graph_templates.name
				from (graph_local,graph_templates,graph_templates_graph)
				where graph_local.id=graph_templates_graph.local_graph_id
				and graph_templates_graph.graph_template_id=graph_templates.id
				and graph_local.host_id=" . $leaf["host_id"] . "
				" . (empty($graph_template_id) ? "" : "and graph_templates.id=$graph_template_id") . "
				group by graph_templates.id
				order by graph_templates.name");

			/* for graphs without a template */
			array_push($graph_templates, array(
				"id" => "0",
				"name" => "(No Graph Template)"
				));

			if (sizeof($graph_templates) > 0) {
			foreach ($graph_templates as $graph_template) {
				$graphs = db_fetch_assoc("select
					graph_templates_graph.title_cache,
					graph_templates_graph.local_graph_id
					from (graph_local,graph_templates_graph)
					$sql_join
					where graph_local.id=graph_templates_graph.local_graph_id
					and graph_local.graph_template_id=" . $graph_template["id"] . "
					and graph_local.host_id=" . $leaf["host_id"] . "
					$sql_where
					order by graph_templates_graph.title_cache");

				if (read_graph_config_option("thumbnail_section_tree_2") == "on") {
					html_graph_thumbnail_area($graphs, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end(), "<tr bgcolor='#a9b7cb'><td colspan='3' class='textHeaderDark'><strong>Graph Template:</strong> " . $graph_template["name"] . "</td></tr>");
				}else{
					html_graph_area($graphs, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end(), "<tr bgcolor='#a9b7cb'><td colspan='3' class='textHeaderDark'><strong>Graph Template:</strong> " . $graph_template["name"] . "</td></tr>");
				}
			}
			}
		/* data query index grouping */
		}elseif ($leaf["host_grouping_type"] == HOST_GROUPING_DATA_QUERY_INDEX) {
			$data_queries = db_fetch_assoc("select
				snmp_query.id,
				snmp_query.name
				from (graph_local,snmp_query)
				where graph_local.snmp_query_id=snmp_query.id
				and graph_local.host_id=" . $leaf["host_id"] . "
				" . (!isset($data_query_id) ? "" : "and snmp_query.id=$data_query_id") . "
				group by snmp_query.id
				order by snmp_query.name");

			/* for graphs without a data query */
			if (empty($data_query_id)) {
				array_push($data_queries, array(
					"id" => "0",
					"name" => "(Non Indexed)"
					));
			}

			if (sizeof($data_queries) > 0) {
			foreach ($data_queries as $data_query) {
				/* fetch a list of field names that are sorted by the preferred sort field */
				$sort_field_data = get_formatted_data_query_indexes($leaf["host_id"], $data_query["id"]);

				/* grab a list of all graphs for this host/data query combination */
				$graphs = db_fetch_assoc("select
					graph_templates_graph.title_cache,
					graph_templates_graph.local_graph_id,
					graph_local.snmp_index
					from (graph_local,graph_templates_graph)
					$sql_join
					where graph_local.id=graph_templates_graph.local_graph_id
					and graph_local.snmp_query_id=" . $data_query["id"] . "
					and graph_local.host_id=" . $leaf["host_id"] . "
					" . (empty($data_query_index) ? "" : "and graph_local.snmp_index='$data_query_index'") . "
					$sql_where
					group by graph_templates_graph.local_graph_id
					order by graph_templates_graph.title_cache");

				/* re-key the results on data query index */
				if (sizeof($graphs) > 0) {
					print "<tr bgcolor='#a9b7cb'><td colspan='3' class='textHeaderDark'><strong>Data Query:</strong> " . $data_query["name"] . "</td></tr>";

					foreach ($graphs as $graph) {
						$snmp_index_to_graph{$graph["snmp_index"]}{$graph["local_graph_id"]} = $graph["title_cache"];
					}
				}

				/* using the sorted data as they key; grab each snmp index from the master list */
				while (list($snmp_index, $sort_field_value) = each($sort_field_data)) {
					/* render each graph for the current data query index */
					if (isset($snmp_index_to_graph[$snmp_index])) {
						$graph_list = array();

						while (list($local_graph_id, $graph_title) = each($snmp_index_to_graph[$snmp_index])) {
							/* reformat the array so it's compatable with the html_graph* area functions */
							array_push($graph_list, array("local_graph_id" => $local_graph_id, "title_cache" => $graph_title));
						}

						if (read_graph_config_option("thumbnail_section_tree_2") == "on") {
							html_graph_thumbnail_area($graph_list, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end(), "<tr bgcolor='#a9b7cb'><td colspan='3' class='textHeaderDark'>$sort_field_value</td></tr>");
						}else{
							html_graph_area($graph_list, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end(), "<tr bgcolor='#a9b7cb'><td colspan='3' class='textHeaderDark'>$sort_field_value</td></tr>");
						}
					}
				}
			}
			}
		}
	}

	print "</table>";
}
Ejemplo n.º 6
0
function export_tree_graphs_and_graph_html($path, $tree_id)
{
    global $colors, $config;
    include_once $config["library_path"] . "/tree.php";
    include_once $config["library_path"] . "/data_query.php";
    /* start the count of graphs */
    $total_graphs_created = 0;
    $exported_files = array();
    $cacti_export_path = read_config_option("path_html_export");
    /* auth check for hosts on the trees */
    $current_user = db_fetch_row("SELECT * FROM user_auth WHERE id=" . read_config_option("export_user_id"));
    if (!export_is_tree_allowed($tree_id)) {
        return 0;
    }
    $sql_join = "LEFT JOIN graph_local ON (graph_templates_graph.local_graph_id=graph_local.id)\n\t\tLEFT JOIN graph_templates ON (graph_templates.id=graph_local.graph_template_id)\n\t\tLEFT JOIN host ON (host.id=graph_local.host_id)\n\t\tLEFT JOIN user_auth_perms ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=1 AND user_auth_perms.user_id=" . $current_user["id"] . ") OR (host.id=user_auth_perms.item_id AND user_auth_perms.type=3 AND user_auth_perms.user_id=" . $current_user["id"] . ") OR (graph_templates.id=user_auth_perms.item_id AND user_auth_perms.type=4 AND user_auth_perms.user_id=" . $current_user["id"] . "))";
    $sql_where = get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]);
    $sql_where = empty($sql_where) ? "" : "AND {$sql_where}";
    $graphs = array();
    if ($tree_id == 0) {
        $hosts = db_fetch_assoc("SELECT DISTINCT host_id FROM graph_tree_items");
    } else {
        $hosts = db_fetch_assoc("SELECT DISTINCT host_id FROM graph_tree_items WHERE graph_tree_id=" . $tree_id);
    }
    /* get a list of host graphs first */
    if (sizeof($hosts)) {
        foreach ($hosts as $host) {
            $hosts_sql = "SELECT DISTINCT\n\t\t\tgraph_templates_graph.id,\n\t\t\tgraph_templates_graph.local_graph_id,\n\t\t\tgraph_templates_graph.height,\n\t\t\tgraph_templates_graph.width,\n\t\t\tgraph_templates_graph.title_cache,\n\t\t\tgraph_templates.name,\n\t\t\tgraph_local.host_id\n\t\t\tFROM (graph_tree_items, graph_templates_graph)\n\t\t\t{$sql_join}\n\t\t\tWHERE ((graph_templates_graph.local_graph_id<>0)\n\t\t\t{$sql_where}\n\t\t\tAND (graph_local.host_id=" . $host["host_id"] . ")\n\t\t\tAND (graph_templates_graph.export='on'))\n\t\t\tORDER BY graph_templates_graph.title_cache";
            $host_graphs = db_fetch_assoc($hosts_sql);
            if (sizeof($host_graphs)) {
                if (sizeof($graphs)) {
                    $graphs = array_merge($host_graphs, $graphs);
                } else {
                    $graphs = $host_graphs;
                }
            }
        }
    }
    /* now get the list of graphs placed within the tree */
    if ($tree_id == 0) {
        $sql_where = "WHERE graph_templates_graph.local_graph_id!=0\n\t\t\t{$sql_where}\n\t\t\tAND graph_templates_graph.export='on'";
    } else {
        $sql_where = "WHERE graph_tree_items.graph_tree_id =" . $tree_id . "\n\t\t\t{$sql_where}\n\t\t\tAND graph_templates_graph.local_graph_id!=0\n\t\t\tAND graph_templates_graph.export='on'";
    }
    $non_host_sql = "SELECT\n\t\tgraph_templates_graph.id,\n\t\tgraph_templates_graph.local_graph_id,\n\t\tgraph_templates_graph.height,\n\t\tgraph_templates_graph.width,\n\t\tgraph_templates_graph.title_cache,\n\t\tgraph_templates.name,\n\t\tgraph_local.host_id,\n\t\tgraph_tree_items.id AS gtid\n\t\tFROM (graph_tree_items, graph_templates_graph)\n\t\t{$sql_join}\n\t\t{$sql_where}\n\t\tAND graph_tree_items.local_graph_id = graph_templates_graph.local_graph_id\n\t\tAND graph_templates_graph.export='on'\n\t\tORDER BY graph_templates_graph.title_cache";
    $non_host_graphs = db_fetch_assoc($non_host_sql);
    if (sizeof($non_host_graphs)) {
        if (sizeof($graphs)) {
            $graphs = array_merge($non_host_graphs, $graphs);
        } else {
            $graphs = $non_host_graphs;
        }
    }
    /* open a pipe to rrdtool for writing */
    $rrdtool_pipe = rrd_init();
    /* for each graph... */
    $i = 0;
    if (sizeof($graphs) > 0) {
        foreach ($graphs as $graph) {
            $rras = get_associated_rras($graph["local_graph_id"]);
            /* settings for preview graphs */
            $graph_data_array["graph_height"] = read_config_option("export_default_height");
            $graph_data_array["graph_width"] = read_config_option("export_default_width");
            $graph_data_array["graph_nolegend"] = true;
            $graph_data_array["export"] = true;
            if (read_config_option("export_tree_isolation") == "on") {
                $graph_data_array["export_filename"] = "/" . $path . "/graphs/thumb_" . $graph["local_graph_id"] . ".png";
                $export_filename = $cacti_export_path . "/" . $path . "/graphs/thumb_" . $graph["local_graph_id"] . ".png";
            } else {
                $graph_data_array["export_filename"] = "/graphs/thumb_" . $graph["local_graph_id"] . ".png";
                $export_filename = $cacti_export_path . "/graphs/thumb_" . $graph["local_graph_id"] . ".png";
            }
            if (!array_search($export_filename, $exported_files)) {
                /* add the graph to the exported list */
                array_push($exported_files, $export_filename);
                export_log("Creating Graph '" . $cacti_export_path . $graph_data_array["export_filename"] . "'");
                /* generate the graph */
                rrdtool_function_graph($graph["local_graph_id"], 0, $graph_data_array, $rrdtool_pipe);
                $total_graphs_created++;
                /* generate html files for each graph */
                if (read_config_option("export_tree_isolation") == "on") {
                    export_log("Creating File  '" . $cacti_export_path . "/" . $path . "/graph_" . $graph["local_graph_id"] . ".html'");
                    $fp_graph_index = fopen($cacti_export_path . "/" . $path . "/graph_" . $graph["local_graph_id"] . ".html", "w");
                } else {
                    export_log("Creating File  '" . $cacti_export_path . "/graph_" . $graph["local_graph_id"] . ".html'");
                    $fp_graph_index = fopen($cacti_export_path . "/graph_" . $graph["local_graph_id"] . ".html", "w");
                }
                fwrite($fp_graph_index, HTML_HEADER_TREE);
                /* write the code for the tree at the left */
                draw_html_left_tree($fp_graph_index, $tree_id);
                fwrite($fp_graph_index, HTML_GRAPH_HEADER_ONE_TREE);
                fwrite($fp_graph_index, "<strong>Graph - " . $graph["title_cache"] . "</strong></td></tr>");
                fwrite($fp_graph_index, HTML_GRAPH_HEADER_TWO_TREE);
                fwrite($fp_graph_index, "<td>");
                /* reset vars for actual graph image creation */
                reset($rras);
                unset($graph_data_array);
                /* generate graphs for each rra */
                foreach ($rras as $rra) {
                    $graph_data_array["export"] = true;
                    if (read_config_option("export_tree_isolation") == "on") {
                        $graph_data_array["export_filename"] = "/" . $path . "/graphs/graph_" . $graph["local_graph_id"] . "_" . $rra["id"] . ".png";
                    } else {
                        $graph_data_array["export_filename"] = "/graphs/graph_" . $graph["local_graph_id"] . "_" . $rra["id"] . ".png";
                    }
                    export_log("Creating Graph '" . $cacti_export_path . $graph_data_array["export_filename"] . "'");
                    rrdtool_function_graph($graph["local_graph_id"], $rra["id"], $graph_data_array, $rrdtool_pipe);
                    $total_graphs_created++;
                    /* write image related html */
                    if (read_config_option("export_tree_isolation") == "off") {
                        fwrite($fp_graph_index, "<div align=center><img src='graphs/graph_" . $graph["local_graph_id"] . "_" . $rra["id"] . ".png' border=0></div>\n\n\t\t\t\t\t\t<div align=center><strong>" . $rra["name"] . "</strong></div><br>");
                    } else {
                        fwrite($fp_graph_index, "<div align=center><img src='" . "graphs/graph_" . $graph["local_graph_id"] . "_" . $rra["id"] . ".png' border=0></div>\n\n\t\t\t\t\t\t<div align=center><strong>" . $rra["name"] . "</strong></div><br>");
                    }
                }
                fwrite($fp_graph_index, "</td></tr></table></td></tr></table>");
                fwrite($fp_graph_index, HTML_FOOTER_TREE);
                fclose($fp_graph_index);
            }
        }
    }
    /* close the rrdtool pipe */
    rrd_close($rrdtool_pipe);
    return $total_graphs_created;
}
Ejemplo n.º 7
0
function grow_right_pane_tree($tree_id, $leaf_id, $host_group_data) {
	global $current_user, $colors, $config, $graphs_per_page, $graph_timeshifts;

	include($config["include_path"] . "/global_arrays.php");
	include_once($config["library_path"] . "/data_query.php");
	include_once($config["library_path"] . "/tree.php");
	include_once($config["library_path"] . "/html_utility.php");

	define("MAX_DISPLAY_PAGES", 21);

	if (empty($tree_id)) { return; }

	$sql_where       = "";
	$sql_join        = "";
	$title           = "";
	$title_delimeter = "";
	$search_key      = "";

	$leaf      = db_fetch_row("SELECT order_key, title, host_id, host_grouping_type
					FROM graph_tree_items
					WHERE id=$leaf_id");

	$leaf_type = get_tree_item_type($leaf_id);

	/* get the "starting leaf" if the user clicked on a specific branch */
	if (!empty($leaf_id)) {
		$search_key = substr($leaf["order_key"], 0, (tree_tier($leaf["order_key"]) * CHARS_PER_TIER));
	}

	/* graph permissions */
	if (read_config_option("auth_method") != 0) {
		/* get policy information for the sql where clause */
		$sql_where = get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]);
		$sql_where = (empty($sql_where) ? "" : "AND $sql_where");
		$sql_join = "
			LEFT JOIN host ON (host.id=graph_local.host_id)
			LEFT JOIN graph_templates ON (graph_templates.id=graph_local.graph_template_id)
			LEFT JOIN user_auth_perms ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id AND user_auth_perms.type=1 AND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (host.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_templates.id=user_auth_perms.item_id AND user_auth_perms.type=4 AND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . "))";
	}

	/* get information for the headers */
	if (!empty($tree_id)) { $tree_name = db_fetch_cell("SELECT name FROM graph_tree WHERE id=$tree_id"); }
	if (!empty($leaf_id)) { $leaf_name = $leaf["title"]; }
	if (!empty($leaf_id)) { $host_name = db_fetch_cell("SELECT host.description FROM (graph_tree_items,host) WHERE graph_tree_items.host_id=host.id AND graph_tree_items.id=$leaf_id"); }

	$host_group_data_array = explode(":", $host_group_data);

	if ($host_group_data_array[0] == "graph_template") {
		$host_group_data_name = "<strong>Graph Template:</strong> " . db_fetch_cell("select name from graph_templates where id=" . $host_group_data_array[1]);
		$graph_template_id = $host_group_data_array[1];
	}elseif ($host_group_data_array[0] == "data_query") {
		$host_group_data_name = "<strong>Graph Template:</strong> " . (empty($host_group_data_array[1]) ? "Non Query Based" : db_fetch_cell("select name from snmp_query where id=" . $host_group_data_array[1]));
		$data_query_id = $host_group_data_array[1];
	}elseif ($host_group_data_array[0] == "data_query_index") {
		$host_group_data_name = "<strong>Graph Template:</strong> " . (empty($host_group_data_array[1]) ? "Non Query Based" : db_fetch_cell("select name from snmp_query where id=" . $host_group_data_array[1])) . "-> " . (empty($host_group_data_array[2]) ? "Template Based" : get_formatted_data_query_index($leaf["host_id"], $host_group_data_array[1], $host_group_data_array[2]));
		$data_query_id = $host_group_data_array[1];
		$data_query_index = $host_group_data_array[2];
	}

	if (!empty($tree_name)) { $title .= $title_delimeter . "<strong>Tree:</strong> $tree_name"; $title_delimeter = "-> "; }
	if (!empty($leaf_name)) { $title .= $title_delimeter . "<strong>Leaf:</strong> $leaf_name"; $title_delimeter = "-> "; }
	if (!empty($host_name)) { $title .= $title_delimeter . "<strong>Host:</strong> $host_name"; $title_delimeter = "-> "; }
	if (!empty($host_group_data_name)) { $title .= $title_delimeter . " $host_group_data_name"; $title_delimeter = "-> "; }
	if (isset($_REQUEST["tree_id"])) {
		$nodeid = "tree_" . get_request_var_request("tree_id");
	}

	if (isset($_REQUEST["leaf_id"])) {
		$nodeid .= "_leaf_" . get_request_var_request("leaf_id");
	}

	if (isset($_REQUEST["host_group_data"])) {
		$type_id = explode(":", get_request_var_request("host_group_data"));

		if ($type_id[0] == "graph_template") {
			$nodeid .= "_hgd_gt_" . $type_id[1];
		}elseif ($type_id[0] == "data_query") {
			$nodeid .= "_hgd_dq_" . $type_id[1];
		}else{
			$nodeid .= "_hgd_dqi" . $type_id[1] . "_" . $type_id[2];
		}
	}

	print "<script type=\"text/javascript\">\n";
	print "<!--\n";
	print "myNode = findObj(\"$nodeid\")\n";
	print "myNode.forceOpeningOfAncestorFolders();\n";
	print "highlightObjLink(myNode)\n";
	print "//-->\n";
	print "</script>";

	print "<table width='100%' align='center' cellpadding='3'>";

	/* ================= input validation ================= */
	input_validate_input_number(get_request_var_post("graphs"));
	input_validate_input_number(get_request_var_post("page"));
	/* ==================================================== */

	/* clean up search string */
	if (isset($_REQUEST["filter"])) {
		$_REQUEST["filter"] = sanitize_search_string(get_request_var_post("filter"));
	}

	/* clean up search string */
	if (isset($_REQUEST["thumbnails"])) {
		$_REQUEST["thumbnails"] = sanitize_search_string(get_request_var_post("thumbnails"));
	}

	/* if the user pushed the 'clear' button */
	if (isset($_POST["clear_x"])) {
		kill_session_var("sess_graph_view_graphs");
		kill_session_var("sess_graph_view_filter");
		kill_session_var("sess_graph_view_thumbnails");
		kill_session_var("sess_graph_view_page");

		unset($_POST["graphs"]);
		unset($_REQUEST["graphs"]);
		unset($_POST["filter"]);
		unset($_REQUEST["filter"]);
		unset($_REQUEST["page"]);
		unset($_POST["thumbnails"]);
		unset($_REQUEST["thumbnails"]);

		$changed = true;
	}else{
		/* if any of the settings changed, reset the page number */
		$changed = 0;
		$changed += check_changed("graphs", "sess_graph_view_graphs");
		$changed += check_changed("filter", "sess_graph_view_filter");
		$changed += check_changed("action", "sess_graph_view_action");
	}

	if (isset($_SESSION["sess_graph_view_tree_id"])) {
		if ($_SESSION["sess_graph_view_tree_id"] != $tree_id) {
			$changed += 1;
		}
	}
	$_SESSION["sess_graph_view_tree_id"] = $tree_id;

	if (isset($_SESSION["sess_graph_view_leaf_id"])) {
		if ($_SESSION["sess_graph_view_leaf_id"] != $leaf_id) {
			$changed += 1;
		}
	}
	$_SESSION["sess_graph_view_leaf_id"] = $leaf_id;

	if (isset($_SESSION["sess_graph_view_host_group_data"])) {
		if ($_SESSION["sess_graph_view_host_group_data"] != $host_group_data) {
			$changed += 1;
		}
	}
	$_SESSION["sess_graph_view_host_group_data"] = $host_group_data;

	if ($changed) {
		$_REQUEST["page"] = 1;
	}

	load_current_session_value("page",   "sess_graph_view_page",   "1");
	load_current_session_value("graphs", "sess_graph_view_graphs", read_graph_config_option("treeview_graphs_per_page"));
	load_current_session_value("filter", "sess_graph_view_filter", "");

	if (isset($_SESSION["sess_graph_view_thumbnails"])) {
		if ($_SESSION["sess_graph_view_thumbnails"] == "on") {
			if (isset($_POST["filter"])) {
				if (!isset($_POST["thumbnails"])) {
					$_SESSION["sess_graph_view_thumbnails"] = 'off';
				}
			}
		}else{
			if (isset($_POST["thumbnails"])) {
				$_SESSION["sess_graph_view_thumbnails"] = 'on';
			}
		}
	}else{
		$_SESSION["sess_graph_view_thumbnails"] = read_graph_config_option("thumbnail_section_tree_2");
		if ($_SESSION["sess_graph_view_thumbnails"] == '') {
			$_SESSION["sess_graph_view_thumbnails"] = 'off';
		}else{
			$_SESSION["sess_graph_view_thumbnails"] = 'on';
		}
	}

	html_graph_start_box(1, false);

	/* include time span selector */
	if (read_graph_config_option("timespan_sel") == "on") {

		?>
			<script type='text/javascript'>
			// Initialize the calendar
			calendar=null;

			// This function displays the calendar associated to the input field 'id'
			function showCalendar(id) {
				var el = document.getElementById(id);
				if (calendar != null) {
					// we already have some calendar created
					calendar.hide();  // so we hide it first.
				} else {
					// first-time call, create the calendar.
					var cal = new Calendar(true, null, selected, closeHandler);
					cal.weekNumbers = false;  // Do not display the week number
					cal.showsTime = true;     // Display the time
					cal.time24 = true;        // Hours have a 24 hours format
					cal.showsOtherMonths = false;    // Just the current month is displayed
					calendar = cal;                  // remember it in the global var
					cal.setRange(1900, 2070);        // min/max year allowed.
					cal.create();
				}

				calendar.setDateFormat('%Y-%m-%d %H:%M');    // set the specified date format
				calendar.parseDate(el.value);                // try to parse the text in field
				calendar.sel = el;                           // inform it what input field we use

				// Display the calendar below the input field
				calendar.showAtElement(el, "Br");        // show the calendar

				return false;
			}

			// This function update the date in the input field when selected
			function selected(cal, date) {
				cal.sel.value = date;      // just update the date in the input field.
			}

			// This function gets called when the end-user clicks on the 'Close' button.
			// It just hides the calendar without destroying it.
			function closeHandler(cal) {
				cal.hide();                        // hide the calendar
				calendar = null;
			}
		</script>
		<script type="text/javascript">
		<!--

			function applyTimespanFilterChange(objForm) {
				strURL = '?predefined_timespan=' + objForm.predefined_timespan.value;
				strURL = strURL + '&predefined_timeshift=' + objForm.predefined_timeshift.value;
				document.location = strURL;
			}

		-->
		</script>
			<tr bgcolor="<?php print $colors["panel"];?>" class="noprint">
				<form name="form_timespan_selector" method="post">
				<td class="noprint">
					<table width="100%" cellpadding="0" cellspacing="0">
						<tr>
							<td nowrap style='white-space: nowrap;' width='55'>
								&nbsp;<strong>Presets:</strong>&nbsp;
							</td>
							<td nowrap style='white-space: nowrap;' width='130'>
								<select name='predefined_timespan' onChange="applyTimespanFilterChange(document.form_timespan_selector)">
									<?php
									if ($_SESSION["custom"]) {
										$graph_timespans[GT_CUSTOM] = "Custom";
										$start_val = 0;
										$end_val = sizeof($graph_timespans);
									} else {
										if (isset($graph_timespans[GT_CUSTOM])) {
											asort($graph_timespans);
											array_shift($graph_timespans);
										}
										$start_val = 1;
										$end_val = sizeof($graph_timespans)+1;
									}

									if (sizeof($graph_timespans) > 0) {
										for ($value=$start_val; $value < $end_val; $value++) {
											print "<option value='$value'"; if ($_SESSION["sess_current_timespan"] == $value) { print " selected"; } print ">" . title_trim($graph_timespans[$value], 40) . "</option>\n";
										}
									}
									?>
								</select>
							</td>
							<td nowrap style='white-space: nowrap;' width='30'>
								&nbsp;<strong>From:</strong>&nbsp;
							</td>
							<td width='150' nowrap style='white-space: nowrap;'>
								<input type='text' name='date1' id='date1' title='Graph Begin Timestamp' size='14' value='<?php print (isset($_SESSION["sess_current_date1"]) ? $_SESSION["sess_current_date1"] : "");?>'>
								&nbsp;<input style='padding-bottom: 4px;' type='image' src='images/calendar.gif' alt='Start date selector' title='Start date selector' border='0' align='absmiddle' onclick="return showCalendar('date1');">&nbsp;
							</td>
							<td nowrap style='white-space: nowrap;' width='20'>
								&nbsp;<strong>To:</strong>&nbsp;
							</td>
							<td width='150' nowrap style='white-space: nowrap;'>
								<input type='text' name='date2' id='date2' title='Graph End Timestamp' size='14' value='<?php print (isset($_SESSION["sess_current_date2"]) ? $_SESSION["sess_current_date2"] : "");?>'>
								&nbsp;<input style='padding-bottom: 4px;' type='image' src='images/calendar.gif' alt='End date selector' title='End date selector' border='0' align='absmiddle' onclick="return showCalendar('date2');">
							</td>
							<td width='130' nowrap style='white-space: nowrap;'>
								&nbsp;&nbsp;<input style='padding-bottom: 4px;' type='image' name='move_left' src='images/move_left.gif' alt='Left' border='0' align='absmiddle' title='Shift Left'>
								<select name='predefined_timeshift' title='Define Shifting Interval' onChange="applyTimespanFilterChange(document.form_timespan_selector)">
									<?php
									$start_val = 1;
									$end_val = sizeof($graph_timeshifts)+1;
									if (sizeof($graph_timeshifts) > 0) {
										for ($shift_value=$start_val; $shift_value < $end_val; $shift_value++) {
											print "<option value='$shift_value'"; if ($_SESSION["sess_current_timeshift"] == $shift_value) { print " selected"; } print ">" . title_trim($graph_timeshifts[$shift_value], 40) . "</option>\n";
										}
									}
									?>
								</select>
								<input style='padding-bottom: 4px;' type='image' name='move_right' src='images/move_right.gif' alt='Right' border='0' align='absmiddle' title='Shift Right'>
							</td>
							<td nowrap style='white-space: nowrap;'>
								&nbsp;&nbsp;<input type='image' name='button_refresh' src='images/button_refresh.gif' alt='Refresh selected time span' border='0' align='absmiddle' value='refresh'>
								<input type='image' name='button_clear' src='images/button_clear.gif' alt='Return to the default time span' border='0' align='absmiddle'>
							</td>
						</tr>
					</table>
				</td>
				</form>
			</tr>
		<?php

	}

	?>
	<tr class="noprint" bgcolor="#e5e5e5">
		<form name="form_graph_view" method="post">
			<td class="noprint">
				<table cellspacing="0" cellpadding="0">
					<tr>
						<td width="55" nowrap="" style="white-space: nowrap;">
							<strong>&nbsp;Search:</strong>&nbsp;
						</td>
						<td width="130" nowrap="" style="white-space: nowrap;">
							<input size='30' width='100' name='filter' value='<?php print clean_html_output(get_request_var_request("filter"));?>'>
						</td>
						<td nowrap style='white-space:nowrap;' width="110">
							&nbsp;<strong>Graphs per Page:</strong>&nbsp;
						</td>
						<td width="1">
							<select name="graphs" id="graphs" onChange="submit()">
								<?php
								if (sizeof($graphs_per_page) > 0) {
								foreach ($graphs_per_page as $key => $value) {
									print "<option value='" . $key . "'"; if (get_request_var_request("graphs") == $key) { print " selected"; } print ">" . $value . "</option>\n";
								}
								}
								?>
							</select>
						</td>
						<td width="40">
							<label for="thumbnails"><strong>&nbsp;Thumbnails:&nbsp;<strong></label>
						</td>
						<td>
							<input type="checkbox" name="thumbnails" onClick="submit()" <?php print (($_SESSION['sess_graph_view_thumbnails'] == "on") ? "checked":"");?>>
						</td>
						<td style='white-space:nowrap;' nowrap>
							&nbsp;<input type="image" src="images/button_go.gif" alt="Go" border="0" align="absmiddle">
							<input type="image" src="images/button_clear.gif" name="clear" alt="Clear" border="0" align="absmiddle">
						</td>
					</tr>
				</table>
			</td>
		</form>
	</tr>
	<?php
	html_graph_end_box(FALSE);
	html_graph_start_box(3, TRUE);

	$graph_list = array();

	if (($leaf_type == "header") || (empty($leaf_id))) {
		if (strlen(get_request_var_request("filter"))) {
			$sql_where = (empty($sql_where) ? "" : "AND (title_cache LIKE '%" . get_request_var_request("filter") . "%' OR graph_templates_graph.title LIKE '%" . get_request_var_request("filter") . "%')");
		}

		$graph_list = db_fetch_assoc("SELECT
			graph_tree_items.id,
			graph_tree_items.title,
			graph_tree_items.local_graph_id,
			graph_tree_items.rra_id,
			graph_tree_items.order_key,
			graph_templates_graph.title_cache as title_cache
			FROM (graph_tree_items,graph_local)
			LEFT JOIN graph_templates_graph ON (graph_tree_items.local_graph_id=graph_templates_graph.local_graph_id AND graph_tree_items.local_graph_id>0)
			$sql_join
			WHERE graph_tree_items.graph_tree_id=$tree_id
			AND graph_local.id=graph_templates_graph.local_graph_id
			AND graph_tree_items.order_key like '$search_key" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', (MAX_TREE_DEPTH * CHARS_PER_TIER) - (strlen($search_key) + CHARS_PER_TIER)) . "'
			AND graph_tree_items.local_graph_id>0
			$sql_where
			GROUP BY graph_tree_items.id
			ORDER BY graph_tree_items.order_key");
	}elseif ($leaf_type == "host") {
		/* graph template grouping */
		if ($leaf["host_grouping_type"] == HOST_GROUPING_GRAPH_TEMPLATE) {
			$graph_templates = db_fetch_assoc("SELECT
				graph_templates.id,
				graph_templates.name
				FROM (graph_local,graph_templates,graph_templates_graph)
				WHERE graph_local.id=graph_templates_graph.local_graph_id
				AND graph_templates_graph.graph_template_id=graph_templates.id
				AND graph_local.host_id=" . $leaf["host_id"] . "
				" . (empty($graph_template_id) ? "" : "AND graph_templates.id=$graph_template_id") . "
				GROUP BY graph_templates.id
				ORDER BY graph_templates.name");

			/* for graphs without a template */
			array_push($graph_templates, array(
				"id" => "0",
				"name" => "(No Graph Template)"
				));

			if (sizeof($graph_templates) > 0) {
			foreach ($graph_templates as $graph_template) {
				if (strlen(get_request_var_request("filter"))) {
					$sql_where = (empty($sql_where) ? "" : "AND (title_cache LIKE '%" . get_request_var_request("filter") . "%')");
				}

				$graphs = db_fetch_assoc("SELECT
					graph_templates_graph.title_cache,
					graph_templates_graph.local_graph_id
					FROM (graph_local,graph_templates_graph)
					$sql_join
					WHERE graph_local.id=graph_templates_graph.local_graph_id
					AND graph_local.graph_template_id=" . $graph_template["id"] . "
					AND graph_local.host_id=" . $leaf["host_id"] . "
					$sql_where
					ORDER BY graph_templates_graph.title_cache");

				/* let's sort the graphs naturally */
				usort($graphs, 'naturally_sort_graphs');

				if (sizeof($graphs)) {
				foreach ($graphs as $graph) {
					$graph["graph_template_name"] = $graph_template["name"];
					array_push($graph_list, $graph);
				}
				}
			}
			}
		/* data query index grouping */
		}elseif ($leaf["host_grouping_type"] == HOST_GROUPING_DATA_QUERY_INDEX) {
			$data_queries = db_fetch_assoc("SELECT
				snmp_query.id,
				snmp_query.name
				FROM (graph_local,snmp_query)
				WHERE graph_local.snmp_query_id=snmp_query.id
				AND graph_local.host_id=" . $leaf["host_id"] . "
				" . (!isset($data_query_id) ? "" : "and snmp_query.id=$data_query_id") . "
				GROUP BY snmp_query.id
				ORDER BY snmp_query.name");

			/* for graphs without a data query */
			if (empty($data_query_id)) {
				array_push($data_queries, array(
					"id" => "0",
					"name" => "Non Query Based"
					));
			}

			if (sizeof($data_queries) > 0) {
			foreach ($data_queries as $data_query) {
				/* fetch a list of field names that are sorted by the preferred sort field */
				$sort_field_data = get_formatted_data_query_indexes($leaf["host_id"], $data_query["id"]);

				if (strlen(get_request_var_request("filter"))) {
					$sql_where = (empty($sql_where) ? "" : "AND (title_cache LIKE '%" . get_request_var_request("filter") . "%')");
				}

				/* grab a list of all graphs for this host/data query combination */
				$graphs = db_fetch_assoc("SELECT
					graph_templates_graph.title_cache,
					graph_templates_graph.local_graph_id,
					graph_local.snmp_index
					FROM (graph_local, graph_templates_graph)
					$sql_join
					WHERE graph_local.id=graph_templates_graph.local_graph_id
					AND graph_local.snmp_query_id=" . $data_query["id"] . "
					AND graph_local.host_id=" . $leaf["host_id"] . "
					" . (empty($data_query_index) ? "" : "and graph_local.snmp_index='$data_query_index'") . "
					$sql_where
					GROUP BY graph_templates_graph.local_graph_id
					ORDER BY graph_templates_graph.title_cache");

				/* re-key the results on data query index */
				if (sizeof($graphs) > 0) {
					/* let's sort the graphs naturally */
					usort($graphs, 'naturally_sort_graphs');

					foreach ($graphs as $graph) {
						$snmp_index_to_graph{$graph["snmp_index"]}{$graph["local_graph_id"]} = $graph["title_cache"];
					}
				}

				/* using the sorted data as they key; grab each snmp index from the master list */
				while (list($snmp_index, $sort_field_value) = each($sort_field_data)) {
					/* render each graph for the current data query index */
					if (isset($snmp_index_to_graph[$snmp_index])) {
						while (list($local_graph_id, $graph_title) = each($snmp_index_to_graph[$snmp_index])) {
							/* reformat the array so it's compatable with the html_graph* area functions */
							array_push($graph_list, array("data_query_name" => $data_query["name"], "sort_field_value" => $sort_field_value, "local_graph_id" => $local_graph_id, "title_cache" => $graph_title));
						}
					}
				}
			}
			}
		}
	}

	$total_rows = sizeof($graph_list);

	/* generate page list */
	if ($total_rows > get_request_var_request("graphs")) {
		$url_page_select = get_page_list(get_request_var_request("page"), MAX_DISPLAY_PAGES, get_request_var_request("graphs"), $total_rows, "graph_view.php?action=tree&tree_id=" . $tree_id . "&leaf_id=" . $leaf_id . (isset($_REQUEST["host_group_data"]) ? "&host_group_data=" . get_request_var_request("host_group_data") : ""));

		$nav = "<tr bgcolor='#" . $colors["header"] . "'>
				<td colspan='11'>
					<table width='100%' cellspacing='0' cellpadding='0' border='0'>
						<tr>
							<td align='left' class='textHeaderDark'>
								<strong>&lt;&lt; "; if (get_request_var_request("page") > 1) { $nav .= "<a class='linkOverDark' href='graph_view.php?action=tree&tree_id=" . $tree_id . "&leaf_id=" . $leaf_id  . (isset($_REQUEST["host_group_data"]) ? "&host_group_data=" . get_request_var_request("host_group_data") : "") . "&page=" . (get_request_var_request("page")-1) . "'>"; } $nav .= "Previous"; if (get_request_var_request("page") > 1) { $nav .= "</a>"; } $nav .= "</strong>
							</td>\n
							<td align='center' class='textHeaderDark'>
								Showing Graphs " . ((get_request_var_request("graphs")*(get_request_var_request("page")-1))+1) . " to " . ((($total_rows < read_graph_config_option("treeview_graphs_per_page")) || ($total_rows < (get_request_var_request("graphs")*get_request_var_request("page")))) ? $total_rows : (get_request_var_request("graphs")*get_request_var_request("page"))) . " of $total_rows [$url_page_select]
							</td>\n
							<td align='right' class='textHeaderDark'>
								<strong>"; if ((get_request_var_request("page") * get_request_var_request("graphs")) < $total_rows) { $nav .= "<a class='linkOverDark' href='graph_view.php?action=tree&tree_id=" . $tree_id . "&leaf_id=" . $leaf_id  . (isset($_REQUEST["host_group_data"]) ? "&host_group_data=" . get_request_var_request("host_group_data") : "") . "&page=" . (get_request_var_request("page")+1) . "'>"; } $nav .= "Next"; if ((get_request_var_request("page") * get_request_var_request("graphs")) < $total_rows) { $nav .= "</a>"; } $nav .= " &gt;&gt;</strong>
							</td>\n
						</tr>
					</table>
				</td>
			</tr>\n";
	}else{
		$nav = "<tr bgcolor='#" . $colors["header"] . "'>
				<td colspan='11'>
					<table width='100%' cellspacing='0' cellpadding='0' border='0'>
						<tr>
							<td align='center' class='textHeaderDark'>
								Showing All Graphs" . (strlen(get_request_var_request("filter")) ? " [ Filter '" . clean_html_output(get_request_var_request("filter")) . "' Applied ]" : "") . "
							</td>
						</tr>
					</table>
				</td>
			</tr>\n";
	}

	print $nav;

	/* start graph display */
	print "<tr bgcolor='#" . $colors["header_panel"] . "'><td width='390' colspan='10' class='textHeaderDark'>$title</td></tr>";

	$i = get_request_var_request("graphs") * (get_request_var_request("page") - 1);
	$last_graph = $i + get_request_var_request("graphs");

	$new_graph_list = array();
	while ($i < $total_rows && $i < $last_graph) {
		$new_graph_list[] = $graph_list[$i];
		$i++;
	}

	if ($_SESSION["sess_graph_view_thumbnails"] == "on") {
		html_graph_thumbnail_area($new_graph_list, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end());
	}else{
		html_graph_area($new_graph_list, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end());
	}

	print $nav;

	print "</table>";
}
Ejemplo n.º 8
0
function tholds($header_label)
{
    global $colors, $thold_bgcolors, $item_rows, $config;
    $thold_actions = array(1 => 'Associate', 2 => 'Disassociate');
    thold_request_validation();
    $statefilter = '';
    if (isset($_REQUEST['state'])) {
        if ($_REQUEST['state'] == '-1') {
            $statefilter = '';
        } else {
            if ($_REQUEST['state'] == '0') {
                $statefilter = "thold_data.thold_enabled='off'";
            }
            if ($_REQUEST['state'] == '2') {
                $statefilter = "thold_data.thold_enabled='on'";
            }
            if ($_REQUEST['state'] == '1') {
                $statefilter = 'thold_data.thold_alert!=0 OR thold_data.bl_alert>0';
            }
            if ($_REQUEST['state'] == '3') {
                $statefilter = '(thold_data.thold_alert!=0 AND thold_data.thold_fail_count >= thold_data.thold_fail_trigger) OR (thold_data.bl_alert>0 AND thold_data.bl_fail_count >= thold_data.bl_fail_trigger)';
            }
        }
    }
    $alert_num_rows = read_config_option('alert_num_rows');
    if ($alert_num_rows < 1 || $alert_num_rows > 5000) {
        db_execute("REPLACE INTO settings VALUES ('alert_num_rows', 30)");
        /* pull it again so it updates the cache */
        $alert_num_rows = read_config_option('alert_num_rows', true);
    }
    $sql_where = "WHERE template_enabled='off'";
    $sort = $_REQUEST['sort_column'];
    $limit = ' LIMIT ' . $alert_num_rows * ($_REQUEST['page'] - 1) . ",{$alert_num_rows}";
    if (!empty($_REQUEST['template']) && $_REQUEST['template'] != 'ALL') {
        $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . "thold_data.data_template = " . $_REQUEST['template'];
    }
    if (strlen($_REQUEST['filter'])) {
        $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . "thold_data.name LIKE '%" . $_REQUEST['filter'] . "%'";
    }
    if ($statefilter != '') {
        $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . "{$statefilter}";
    }
    if ($_REQUEST["associated"] == 'true') {
        $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . "(notify_warning=" . get_request_var_request('id') . " OR notify_alert=" . get_request_var_request('id') . ")";
    }
    $current_user = db_fetch_row('SELECT * FROM user_auth WHERE id=' . $_SESSION['sess_user_id']);
    $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . get_graph_permissions_sql($current_user['policy_graphs'], $current_user['policy_hosts'], $current_user['policy_graph_templates']);
    $sql = "SELECT * FROM thold_data\n\t\tLEFT JOIN user_auth_perms \n\t\tON ((thold_data.graph_id=user_auth_perms.item_id \n\t\tAND user_auth_perms.type=1 \n\t\tAND user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . ") \n\t\tOR (thold_data.host_id=user_auth_perms.item_id \n\t\tAND user_auth_perms.type=3 \n\t\tAND user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . ") \n\t\tOR (thold_data.graph_template=user_auth_perms.item_id \n\t\tAND user_auth_perms.type=4 \n\t\tAND user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . "))\n\t\t{$sql_where}\n\t\tORDER BY {$sort} " . $_REQUEST['sort_direction'] . $limit;
    $result = db_fetch_assoc($sql);
    $data_templates = db_fetch_assoc("SELECT DISTINCT data_template.id, data_template.name\n\t\tFROM data_template\n\t\tINNER JOIN thold_data ON (thold_data.data_template = data_template.id)\n\t\tORDER BY data_template.name");
    ?>
	<script type="text/javascript">
	<!--
	function applyTHoldFilterChange(objForm) {
		strURL = '?action=edit&tab=tholds&id=<?php 
    print get_request_var_request('id');
    ?>
'
		strURL = strURL + '&associated=' + objForm.associated.checked;
		strURL = strURL + '&state=' + objForm.state.value;
		strURL = strURL + '&rows=' + objForm.rows.value;
		strURL = strURL + '&template=' + objForm.template.value;
		strURL = strURL + '&filter=' + objForm.filter.value;
		document.location = strURL;
	}

	function clearTHoldFilterChange(objForm) {
		strURL = '?action=edit&tab=tholds&id=<?php 
    print get_request_var_request('id');
    ?>
&clearf=true'
		document.location = strURL;
	}

	-->
	</script>
	<?php 
    html_start_box('<strong>Associated Thresholds</strong> ' . htmlspecialchars($header_label), '100%', $colors['header'], '3', 'center', '');
    ?>
	<tr bgcolor='#<?php 
    print $colors["panel"];
    ?>
' class='noprint'>
		<td class='noprint'>
			<form name="listthold" method="get" action="notify_lists.php">
			<table cellpadding='0' cellspacing='0'>
				<tr class='noprint'>
					<td width='1'>
						&nbsp;Template:&nbsp;
					</td>
					<td width='1'>
						<select name='template' onChange='applyTHoldFilterChange(document.listthold)'>
							<option value='ALL'>Any</option>
							<?php 
    foreach ($data_templates as $row) {
        echo "<option value='" . $row['id'] . "'" . (isset($_REQUEST['template']) && $row['id'] == $_REQUEST['template'] ? ' selected' : '') . '>' . $row['name'] . '</option>';
    }
    ?>
						</select>
					</td>
					<td nowrap style='white-space: nowrap;' width="20">
						&nbsp;Search:&nbsp;
					</td>
					<td width="1">
						<input type="text" name="filter" size="20" value="<?php 
    print htmlspecialchars(get_request_var_request("filter"));
    ?>
" onChange="applyTHoldFilterChange(document.listthold)">
					</td>
					<td width='1'>
						&nbsp;State:&nbsp;
					</td>
					<td width='1'>
						<select name='state' onChange='applyTHoldFilterChange(document.listthold)'>
							<option value='-1'<?php 
    if ($_REQUEST["state"] == "-1") {
        ?>
 selected<?php 
    }
    ?>
>All</option>
							<option value='1'<?php 
    if ($_REQUEST["state"] == "1") {
        ?>
 selected<?php 
    }
    ?>
>Breached</option>
							<option value='3'<?php 
    if ($_REQUEST["state"] == "3") {
        ?>
 selected<?php 
    }
    ?>
>Triggered</option>
							<option value='2'<?php 
    if ($_REQUEST["state"] == "2") {
        ?>
 selected<?php 
    }
    ?>
>Enabled</option>
							<option value='0'<?php 
    if ($_REQUEST["state"] == "0") {
        ?>
 selected<?php 
    }
    ?>
>Disabled</option>
						</select>
					</td>
					<td nowrap style='white-space: nowrap;' width="50">
						&nbsp;Rows:&nbsp;
					</td>
					<td width="1">
						<select name="rows" onChange="applyTHoldFilterChange(document.listthold)">
							<option value="-1"<?php 
    if (get_request_var_request("rows") == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Default</option>
							<?php 
    if (sizeof($item_rows) > 0) {
        foreach ($item_rows as $key => $value) {
            print "<option value='" . $key . "'";
            if (get_request_var_request("rows") == $key) {
                print " selected";
            }
            print ">" . htmlspecialchars($value) . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td>
						<input type='checkbox' name='associated' id='associated' onChange='applyTHoldFilterChange(document.listthold)' <?php 
    print $_REQUEST['associated'] == 'true' || $_REQUEST['associated'] == 'on' ? 'checked' : '';
    ?>
>
					</td>
					<td>
						<label for='associated'>Associated</label>
					</td>
					<td nowrap>
						&nbsp;<input type="button" value="Go" onClick='applyTHoldFilterChange(document.listthold)' title="Set/Refresh Filters">
					</td>
					<td nowrap>
						<input type="button" name="clearf" value="Clear" onClick='clearTHoldFilterChange(document.listthold)' title="Clear Filters">
					</td>
				</tr>
			</table>
			<input type='hidden' name='page' value='1'>
			<input type='hidden' name='action' value='edit'>
			<input type='hidden' name='tab' value='tholds'>
			<input type='hidden' name='id' value='<?php 
    print get_request_var_request('id');
    ?>
'>
			</form>
		</td>
	</tr>
	<?php 
    html_end_box();
    $total_rows = count(db_fetch_assoc("SELECT thold_data.id \n\t\tFROM thold_data\n\t\tLEFT JOIN user_auth_perms \n\t\tON ((thold_data.graph_id=user_auth_perms.item_id \n\t\tAND user_auth_perms.type=1 \n\t\tAND user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . ") \n\t\tOR (thold_data.host_id=user_auth_perms.item_id \n\t\tAND user_auth_perms.type=3 \n\t\tAND user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . ") \n\t\tOR (thold_data.graph_template=user_auth_perms.item_id \n\t\tAND user_auth_perms.type=4 \n\t\tAND user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . "))\n\t\t{$sql_where}"));
    $url_page_select = get_page_list($_REQUEST['page'], MAX_DISPLAY_PAGES, $alert_num_rows, $total_rows, 'notify_lists.php?action=edit&tab=tholds');
    /* print checkbox form for validation */
    print "<form name='chk' method='post' action='notify_lists.php'>\n";
    html_start_box('', '100%', $colors['header'], '4', 'center', '');
    if ($total_rows) {
        $nav = "<tr bgcolor='#" . $colors['header'] . "'>\n\t\t\t\t<td colspan='8'>\n\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td align='left' class='textHeaderDark'>\n\t\t\t\t\t\t\t\t<strong>&lt;&lt; ";
        if ($_REQUEST["page"] > 1) {
            $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("notify_lists.php?page=" . ($_REQUEST["page"] - 1)) . "'>";
        }
        $nav .= "Previous";
        if ($_REQUEST["page"] > 1) {
            $nav .= "</a>";
        }
        $nav .= "</strong>\n\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\n\t\t\t\t\t\t\t\tShowing Rows " . ($alert_num_rows * ($_REQUEST["page"] - 1) + 1) . " to " . ($total_rows < $alert_num_rows || $total_rows < $alert_num_rows * $_REQUEST["page"] ? $total_rows : $alert_num_rows * $_REQUEST["page"]) . " of {$total_rows} [{$url_page_select}]\n\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t\t<td align='right' class='textHeaderDark'>\n\t\t\t\t\t\t\t\t<strong>";
        if ($_REQUEST["page"] * $alert_num_rows < $total_rows) {
            $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("notify_lists.php?page=" . ($_REQUEST["page"] + 1)) . "'>";
        }
        $nav .= "Next";
        if ($_REQUEST["page"] * $alert_num_rows < $total_rows) {
            $nav .= "</a>";
        }
        $nav .= " &gt;&gt;</strong>\n\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t</tr>\n";
    } else {
        $nav = "<tr bgcolor='#" . $colors['header'] . "'>\n\t\t\t\t<td colspan='8'>\n\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\n\t\t\t\t\t\t\t\tNo Rows Found\n\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t</tr>\n";
    }
    print $nav;
    $display_text = array('name' => array('Name', 'ASC'), 'id' => array('ID', 'ASC'), 'nosort1' => array('Warning Lists', 'ASC'), 'nosort2' => array('Alert Lists', 'ASC'), 'thold_type' => array('Type', 'ASC'), 'thold_alert' => array('Triggered', 'ASC'), 'thold_enabled' => array('Enabled', 'ASC'));
    html_header_sort_checkbox($display_text, $_REQUEST['sort_column'], $_REQUEST['sort_direction'], false);
    $c = 0;
    $i = 0;
    $types = array('High/Low', 'Baseline Deviation', 'Time Based');
    if (count($result)) {
        foreach ($result as $row) {
            $c++;
            $alertstat = 'no';
            $bgcolor = 'green';
            if ($row['thold_type'] != 1) {
                if ($row['thold_alert'] != 0) {
                    $alertstat = 'yes';
                }
            } else {
                if ($row['bl_alert'] == 1) {
                    $alertstat = 'baseline-LOW';
                } elseif ($row['bl_alert'] == 2) {
                    $alertstat = 'baseline-HIGH';
                }
            }
            /* show alert stats first */
            $alert_stat = '';
            $list = db_fetch_cell("SELECT count(*) FROM plugin_thold_threshold_contact WHERE thold_id=" . $row["id"]);
            if ($list > 0) {
                $alert_stat = "<span style='font-weight:bold;color:green;'>Select Users</span>";
            }
            if (strlen($row["notify_extra"])) {
                $alert_stat .= (strlen($alert_stat) ? ", " : "") . "<span style='font-weight:bold;color:purple;'>Specific Emails</span>";
            }
            if (!empty($row["notify_alert"])) {
                if (get_request_var_request('id') == $row["notify_alert"]) {
                    $alert_stat .= (strlen($alert_stat) ? ", " : "") . "<span style='font-weight:bold;color:green;'>Current List</span>";
                } else {
                    $alert_list = db_fetch_cell("SELECT name FROM plugin_notification_lists WHERE id=" . $row["notify_alert"]);
                    $alert_stat .= (strlen($alert_stat) ? ", " : "") . "<span style='font-weight:bold;color:red;'>" . $alert_list . "</span>";
                }
            }
            if (!strlen($alert_stat)) {
                $alert_stat = "<span style='font-weight:bold;color:blue;'>Log Only</span>";
            }
            /* show warning stats first */
            $warn_stat = '';
            if (strlen($row["notify_warning_extra"])) {
                $warn_stat .= (strlen($warn_stat) ? ", " : "") . "<span style='font-weight:bold;color:purple;'>Specific Emails</span>";
            }
            if (!empty($row["notify_warning"])) {
                if (get_request_var_request('id') == $row["notify_warning"]) {
                    $warn_stat .= (strlen($warn_stat) ? ", " : "") . "<span style='font-weight:bold;color:green;'>Current List</span>";
                } else {
                    $warn_list = db_fetch_cell("SELECT name FROM plugin_notification_lists WHERE id=" . $row["notify_warning"]);
                    $warn_stat .= (strlen($warn_stat) ? ", " : "") . "<span style='font-weight:bold;color:red;'>" . $warn_list . "</span>";
                }
            }
            if (!strlen($warn_stat) && ($row["thold_type"] == 0 && $row["thold_warning_hi"] == '' && $row["thold_warning_low"] == '' || $row["thold_type"] == 2 && $row["time_warning_hi"] == '' && $row["time_warning_low"] == '')) {
                $warn_stat = "<span style='font-weight:bold;color:red;'>None</span>";
            } elseif (!strlen($warn_stat)) {
                $warn_stat = "<span style='font-weight:bold;color:blue;'>Log Only</span>";
            }
            if ($row['name'] != '') {
                $name = $row['name'];
            } else {
                $name = $row['name_cache'] . " [" . $row['data_source_name'] . "]";
            }
            form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $row["id"]);
            $i++;
            form_selectable_cell(strlen(get_request_var_request("filter")) ? preg_replace("/(" . preg_quote(get_request_var_request("filter")) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", htmlspecialchars($name)) : htmlspecialchars($name), $row['id']);
            form_selectable_cell($row['id'], $row["id"]);
            form_selectable_cell($warn_stat, $row["id"]);
            form_selectable_cell($alert_stat, $row["id"]);
            form_selectable_cell($types[$row['thold_type']], $row["id"]);
            form_selectable_cell($alertstat, $row["id"]);
            form_selectable_cell($row['thold_enabled'] == 'off' ? "Disabled" : "Enabled", $row["id"]);
            form_checkbox_cell($row['name'], $row['id']);
            form_end_row();
        }
        print $nav;
    } else {
        form_alternate_row_color($colors['alternate'], $colors['light'], 0);
        print '<td colspan="8"><i>No Thresholds</i></td></tr>';
    }
    html_end_box(false);
    form_hidden_box("action", "edit", "");
    form_hidden_box("tab", "tholds", "");
    form_hidden_box("id", get_request_var_request("id"), "");
    form_hidden_box("save_tholds", "1", "");
    draw_actions_dropdown($thold_actions);
    print "</form>\n";
}
Ejemplo n.º 9
0
function is_graph_allowed($local_graph_id)
{
    $current_user = db_fetch_row("select policy_graphs,policy_hosts,policy_graph_templates from user_auth where id=" . $_SESSION["sess_user_id"]);
    /* get policy information for the sql where clause */
    /* modify for multi user start */
    if ($_SESSION["permission"] <= ACCESS_ADMINISTRATOR && strstr($_SERVER["HTTP_REFERER"], $_SERVER["SERVER_NAME"]) && check_graph($local_graph_id)) {
        $graphs = TRUE;
    } else {
        $sql_where = get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]);
        $graphs = db_fetch_assoc("select\r\n\t\tgraph_templates_graph.local_graph_id\r\n\t\tfrom (graph_templates_graph,graph_local)\r\n\t\tleft join host on (host.id=graph_local.host_id)\r\n\t\tleft join graph_templates on (graph_templates.id=graph_local.graph_template_id)\r\n\t\tleft join user_auth_perms on ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=1 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (host.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_templates.id=user_auth_perms.item_id and user_auth_perms.type=4 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . "))\r\n\t\twhere graph_templates_graph.local_graph_id=graph_local.id\r\n\t\t" . (empty($sql_where) ? "" : "and {$sql_where}") . "\r\n\t\tand graph_templates_graph.local_graph_id={$local_graph_id}\r\n\t\tgroup by graph_templates_graph.local_graph_id");
    }
    /* modify for multi user end */
    if (sizeof($graphs) > 0) {
        return true;
    } else {
        return false;
    }
}
Ejemplo n.º 10
0
function grow_right_pane_tree($tree_id, $leaf_id, $host_group_data)
{
    global $current_user, $config, $graphs_per_page, $graph_timeshifts;
    include $config['include_path'] . '/global_arrays.php';
    include_once $config['library_path'] . '/data_query.php';
    include_once $config['library_path'] . '/tree.php';
    include_once $config['library_path'] . '/html_utility.php';
    if (empty($tree_id)) {
        return;
    }
    if (empty($leaf_id)) {
        $leaf_id = 0;
    }
    $sql_where = '';
    $sql_join = '';
    $title = '';
    $title_delimeter = '';
    $search_key = '';
    $leaf = db_fetch_row("SELECT order_key, title, host_id, host_grouping_type\n\t\tFROM graph_tree_items\n\t\tWHERE id={$leaf_id}");
    $leaf_type = get_tree_item_type($leaf_id);
    /* get the "starting leaf" if the user clicked on a specific branch */
    if (!empty($leaf_id)) {
        $search_key = substr($leaf['order_key'], 0, tree_tier($leaf['order_key']) * CHARS_PER_TIER);
    }
    /* graph permissions */
    if (read_config_option('auth_method') != 0) {
        /* get policy information for the sql where clause */
        $sql_where = get_graph_permissions_sql($current_user['policy_graphs'], $current_user['policy_hosts'], $current_user['policy_graph_templates']);
        $sql_where = empty($sql_where) ? '' : "AND {$sql_where}";
        $sql_join = "\n\t\t\tLEFT JOIN host ON (host.id=graph_local.host_id)\n\t\t\tLEFT JOIN graph_templates ON (graph_templates.id=graph_local.graph_template_id)\n\t\t\tLEFT JOIN user_auth_perms ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id AND user_auth_perms.type=1 AND user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . ") OR (host.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . ") OR (graph_templates.id=user_auth_perms.item_id AND user_auth_perms.type=4 AND user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . '))';
    }
    /* get information for the headers */
    if (!empty($tree_id)) {
        $tree_name = db_fetch_cell("SELECT name FROM graph_tree WHERE id={$tree_id}");
    }
    if (!empty($leaf_id)) {
        $leaf_name = $leaf['title'];
    }
    if (!empty($leaf_id)) {
        $host_name = db_fetch_cell("SELECT host.description FROM (graph_tree_items,host) WHERE graph_tree_items.host_id=host.id AND graph_tree_items.id={$leaf_id}");
    }
    $host_group_data_array = explode(':', $host_group_data);
    if ($host_group_data_array[0] == 'graph_template') {
        $host_group_data_name = '<strong>Graph Template:</strong> ' . db_fetch_cell('select name from graph_templates where id=' . $host_group_data_array[1]);
        $graph_template_id = $host_group_data_array[1];
    } elseif ($host_group_data_array[0] == 'data_query') {
        $host_group_data_name = '<strong>Graph Template:</strong> ' . (empty($host_group_data_array[1]) ? 'Non Query Based' : db_fetch_cell('select name from snmp_query where id=' . $host_group_data_array[1]));
        $data_query_id = $host_group_data_array[1];
    } elseif ($host_group_data_array[0] == 'data_query_index') {
        $host_group_data_name = '<strong>Graph Template:</strong> ' . (empty($host_group_data_array[1]) ? 'Non Query Based' : db_fetch_cell('select name from snmp_query where id=' . $host_group_data_array[1])) . '-> ' . (empty($host_group_data_array[2]) ? 'Template Based' : get_formatted_data_query_index($leaf['host_id'], $host_group_data_array[1], $host_group_data_array[2]));
        $data_query_id = $host_group_data_array[1];
        $data_query_index = $host_group_data_array[2];
    }
    if (!empty($tree_name)) {
        $title .= $title_delimeter . '<strong>Tree:</strong>' . htmlspecialchars($tree_name, ENT_QUOTES);
        $title_delimeter = '-> ';
    }
    if (!empty($leaf_name)) {
        $title .= $title_delimeter . '<strong>Leaf:</strong>' . htmlspecialchars($leaf_name, ENT_QUOTES);
        $title_delimeter = '-> ';
    }
    if (!empty($host_name)) {
        $title .= $title_delimeter . '<strong>Host:</strong>' . htmlspecialchars($host_name, ENT_QUOTES);
        $title_delimeter = '-> ';
    }
    if (!empty($host_group_data_name)) {
        $title .= $title_delimeter . " {$host_group_data_name}";
        $title_delimeter = '-> ';
    }
    validate_tree_vars($tree_id, $leaf_id, $host_group_data);
    html_start_box('<strong>Graph Filters</strong>' . (strlen(get_request_var_request('filter')) ? " [ Filter '" . htmlspecialchars(get_request_var_request('filter')) . "' Applied ]" : ''), '100%', "", '2', 'center', '');
    /* include time span selector */
    if (read_graph_config_option('timespan_sel') == 'on') {
        ?>
		<tr class='even noprint'>
			<td class='noprint'>
			<form style='margin:0px;padding:0px;' name='form_timespan_selector' method='post' action='graph_view.php'>
				<table cellpadding='1' cellspacing='0'>
					<tr>
						<td width='55'>
							Presets:
						</td>
						<td>
							<select id='predefined_timespan' name='predefined_timespan' onChange='spanTime()'>
								<?php 
        if (isset($_SESSION['custom'])) {
            $graph_timespans[GT_CUSTOM] = 'Custom';
            $start_val = 0;
            $end_val = sizeof($graph_timespans);
        } else {
            if (isset($graph_timespans[GT_CUSTOM])) {
                asort($graph_timespans);
                array_shift($graph_timespans);
            }
            $start_val = 1;
            $end_val = sizeof($graph_timespans) + 1;
        }
        if (sizeof($graph_timespans) > 0) {
            for ($value = $start_val; $value < $end_val; $value++) {
                print "<option value='{$value}'";
                if ($_SESSION['sess_current_timespan'] == $value) {
                    print ' selected';
                }
                print '>' . title_trim($graph_timespans[$value], 40) . "</option>\n";
            }
        }
        ?>
							</select>
						</td>
						<td>
							From:
						</td>
						<td>
							<input type='text' name='date1' id='date1' title='Graph Begin Timestamp' size='15' value='<?php 
        print isset($_SESSION['sess_current_date1']) ? $_SESSION['sess_current_date1'] : '';
        ?>
'>
						</td>
						<td>
							<input type='image' src='images/calendar.gif' align='absmiddle' alt='Start date selector' title='Start date selector' onclick="return showCalendar('date1');">
						</td>
						<td>
							To:
						</td>
						<td>
							<input type='text' name='date2' id='date2' title='Graph End Timestamp' size='15' value='<?php 
        print isset($_SESSION['sess_current_date2']) ? $_SESSION['sess_current_date2'] : '';
        ?>
'>
						</td>
						<td>
							<input type='image' src='images/calendar.gif' align='absmiddle' alt='End date selector' title='End date selector' onclick="return showCalendar('date2');">
						</td>
						<td>
							<img style='padding-bottom:0px;cursor:pointer;' border='0' src='images/move_left.gif' align='absmiddle' alt='' title='Shift Left' onClick='timeshiftFilterLeft()'/>
						</td>
						<td>
							<select id='predefined_timeshift' name='predefined_timeshift' title='Define Shifting Interval'>
								<?php 
        $start_val = 1;
        $end_val = sizeof($graph_timeshifts) + 1;
        if (sizeof($graph_timeshifts) > 0) {
            for ($shift_value = $start_val; $shift_value < $end_val; $shift_value++) {
                print "<option value='{$shift_value}'";
                if ($_SESSION['sess_current_timeshift'] == $shift_value) {
                    print ' selected';
                }
                print '>' . title_trim($graph_timeshifts[$shift_value], 40) . "</option>\n";
            }
        }
        ?>
							</select>
						</td>
						<td>
							<img style='padding-bottom:0px;cursor:pointer;' name='move_right' src='images/move_right.gif' align='absmiddle' alt='' title='Shift Right' onClick='timeshiftFilterRight()'/>
						</td>
						<td>
							<input type='button' name='button_refresh_x' value='Refresh' title='Refresh selected time span' onClick='refreshTimespanFilter()'>
						</td>
						<td>
							<input type='button' name='button_clear_x' value='Clear' title='Return to the default time span' onClick='clearTimespanFilter()'>
						</td>
					</tr>
				</table>
			</form>
			</td>
		</tr>
		<?php 
    }
    ?>
	<tr class='noprint' bgcolor='#e5e5e5'>
		<td class='noprint'>
		<form style='margin:0px;padding:0px;' name='form_graph_view' method='post' onSubmit='changeFilter();return false'>
			<table cellspacing='0' cellpadding='1'>
				<tr>
					<td width='55'>
						Search:
					</td>
					<td width='130'>
						<input id='filter' size='30' name='filter' value='<?php 
    print htmlspecialchars(get_request_var_request('filter'));
    ?>
'>
					</td>
					<td>
						Graphs:
					</td>
					<td width='1'>
						<select name='graphs' id='graphs' onChange='changeFilter()'>
							<option value='-1'<?php 
    if (get_request_var_request('graphs') == '-1') {
        ?>
 selected<?php 
    }
    ?>
>Default</option>
							<?php 
    if (sizeof($graphs_per_page) > 0) {
        foreach ($graphs_per_page as $key => $value) {
            print "<option value='" . $key . "'";
            if (get_request_var_request('graphs') == $key) {
                print ' selected';
            }
            print '>' . $value . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td>
						Columns:
					</td>
					<td width='1'>
						<select name='columns' id='columns' onChange='changeFilter()' <?php 
    print get_request_var_request('thumbnails') == 'false' ? 'disabled' : '';
    ?>
>
							<?php 
    if (get_request_var_request('thumbnails') == 'false') {
        ?>
							<option value='<?php 
        print get_request_var_request('columns');
        ?>
' selected>N/A</option>
							<?php 
    } else {
        ?>
							<option value='-1' <?php 
        print get_request_var_request('columns') == '-1' ? ' selected' : '';
        ?>
>Default</option>
							<option value='1' <?php 
        print get_request_var_request('columns') == '1' ? ' selected' : '';
        ?>
>1 Column</option>
							<option value='2' <?php 
        print get_request_var_request('columns') == '2' ? ' selected' : '';
        ?>
>2 Columns</option>
							<option value='3' <?php 
        print get_request_var_request('columns') == '3' ? ' selected' : '';
        ?>
>3 Columns</option>
							<option value='4' <?php 
        print get_request_var_request('columns') == '4' ? ' selected' : '';
        ?>
>4 Columns</option>
							<option value='5' <?php 
        print get_request_var_request('columns') == '5' ? ' selected' : '';
        ?>
>5 Columns</option>
							<?php 
    }
    ?>
						</select>
					</td>
					<td width='40'>
						<label for='thumbnails'>Thumbnails:</label>
					</td>
					<td>
						<input id='thumbnails' type='checkbox' name='thumbnails' onClick='changeFilter()' <?php 
    print $_REQUEST['thumbnails'] == 'true' ? 'checked' : '';
    ?>
>
					</td>
					<td>
						<input type='button' value='Go' title='Set/Refresh Filter' onClick='changeFilter()'>
					</td>
					<td>
						<input type='button' value='Clear' title='Clear Filters' onClick='clearFilter()'>
					</td>
				</tr>
			</table>
		</form>
		</td>
	</tr>
	<script type='text/javascript'>
	function changeFilter() {
		$.get('graph_view.php?action=tree_content&tree_id=<?php 
    print $_REQUEST['tree_id'];
    ?>
&leaf_id=<?php 
    print $_REQUEST['leaf_id'];
    ?>
&host_group_data=<?php 
    print $_REQUEST['host_group_data'];
    ?>
&graphs='+$('#graphs').val()+'&filter='+$('#filter').val()+'&thumbnails='+$('#thumbnails').is(':checked')+'&columns='+$('#columns').val()+'&nodeid='+'<?php 
    print $_REQUEST['nodeid'];
    ?>
', function(data) {
			$('#main').html(data);
		});
	}

	function clearFilter() {
		$.get('graph_view.php?action=tree_content&tree_id=<?php 
    print $_REQUEST['tree_id'];
    ?>
&leaf_id=<?php 
    print $_REQUEST['leaf_id'];
    ?>
&host_group_data=<?php 
    print $_REQUEST['host_group_data'];
    ?>
&clear_x=1&nodeid='+'<?php 
    print $_REQUEST['nodeid'];
    ?>
', function(data) {
			$('#main').html(data);
		});
	}

	function spanTime() {
		$.get('graph_view.php?action=tree_content&tree_id=<?php 
    print $_REQUEST['tree_id'];
    ?>
&leaf_id=<?php 
    print $_REQUEST['leaf_id'];
    ?>
&host_group_data=<?php 
    print $_REQUEST['host_group_data'];
    ?>
&nodeid='+'<?php 
    print $_REQUEST['nodeid'];
    ?>
&predefined_timespan='+$('#predefined_timespan').val()+'&predefined_timeshift='+$('#predefined_timeshift').val(), function(data) {
			$('#main').html(data);
		});
	}

	function clearTimespanFilter() {
		var json = { button_clear_x: 1, date1: $('#date1').val(), date2: $('#date2').val(), predefined_timespan: $('#predefined_timespan').val(), predefined_timeshift: $('#predefined_timeshift').val() };
		var url  = 'graph_view.php?action=tree_content&tree_id=<?php 
    print $_REQUEST['tree_id'];
    ?>
&leaf_id=<?php 
    print $_REQUEST['leaf_id'];
    ?>
&host_group_data=<?php 
    print $_REQUEST['host_group_data'];
    ?>
&nodeid=<?php 
    print $_REQUEST['nodeid'];
    ?>
';
		$.post(url, json).done(function(data) {
			$('#main').html(data);
		});
	}

	function refreshTimespanFilter() {
		var json = { button_refresh_x: 1, date1: $('#date1').val(), date2: $('#date2').val(), predefined_timespan: $('#predefined_timespan').val(), predefined_timeshift: $('#predefined_timeshift').val() };
		var url  = 'graph_view.php?action=tree_content&tree_id=<?php 
    print $_REQUEST['tree_id'];
    ?>
&leaf_id=<?php 
    print $_REQUEST['leaf_id'];
    ?>
&host_group_data=<?php 
    print $_REQUEST['host_group_data'];
    ?>
&nodeid=<?php 
    print $_REQUEST['nodeid'];
    ?>
';
		$.post(url, json).done(function(data) {
			$('#main').html(data);
		});
	}

	function timeshiftFilterLeft() {
		var json = { move_left_x: 1, move_left_y: 1, date1: $('#date1').val(), date2: $('#date2').val(), predefined_timespan: $('#predefined_timespan').val(), predefined_timeshift: $('#predefined_timeshift').val() };
		var url  = 'graph_view.php?action=tree_content&tree_id=<?php 
    print $_REQUEST['tree_id'];
    ?>
&leaf_id=<?php 
    print $_REQUEST['leaf_id'];
    ?>
&host_group_data=<?php 
    print $_REQUEST['host_group_data'];
    ?>
&nodeid=<?php 
    print $_REQUEST['nodeid'];
    ?>
';
		$.post(url, json).done(function(data) {
			$('#main').html(data);
		});
	}

	function timeshiftFilterRight() {
		var json = { move_right_x: 1, move_right_y: 1, date1: $('#date1').val(), date2: $('#date2').val(), predefined_timespan: $('#predefined_timespan').val(), predefined_timeshift: $('#predefined_timeshift').val() };
		var url  = 'graph_view.php?action=tree_content&tree_id=<?php 
    print $_REQUEST['tree_id'];
    ?>
&leaf_id=<?php 
    print $_REQUEST['leaf_id'];
    ?>
&host_group_data=<?php 
    print $_REQUEST['host_group_data'];
    ?>
&nodeid=<?php 
    print $_REQUEST['nodeid'];
    ?>
';
		$.post(url, json).done(function(data) {
			$('#main').html(data);
		});
	}

	</script>
	<?php 
    html_end_box();
    api_plugin_hook_function('graph_tree_page_buttons', array('treeid' => $tree_id, 'leafid' => $leaf_id, 'mode' => 'tree', 'timespan' => $_SESSION['sess_current_timespan'], 'starttime' => get_current_graph_start(), 'endtime' => get_current_graph_end()));
    html_start_box('', '100%', "", '3', 'center', '');
    $graph_list = array();
    /* if the number of rows is -1, set it to the default */
    if ($_REQUEST['graphs'] == -1) {
        $_REQUEST['graphs'] = read_graph_config_option('treeview_graphs_per_page');
    }
    if ($leaf_type == 'header' || empty($leaf_id)) {
        if (strlen(get_request_var_request('filter'))) {
            $sql_where = empty($sql_where) ? '' : "AND (title_cache LIKE '%" . get_request_var_request('filter') . "%' OR graph_templates_graph.title LIKE '%" . get_request_var_request('filter') . "%')";
        }
        $graph_list = db_fetch_assoc("SELECT\n\t\t\tgraph_tree_items.id,\n\t\t\tgraph_tree_items.title,\n\t\t\tgraph_tree_items.local_graph_id,\n\t\t\tgraph_tree_items.rra_id,\n\t\t\tgraph_tree_items.order_key,\n\t\t\tgraph_templates_graph.height,\n\t\t\tgraph_templates_graph.width,\n\t\t\tgraph_templates_graph.title_cache as title_cache\n\t\t\tFROM (graph_tree_items,graph_local)\n\t\t\tLEFT JOIN graph_templates_graph ON (graph_tree_items.local_graph_id=graph_templates_graph.local_graph_id AND graph_tree_items.local_graph_id>0)\n\t\t\t{$sql_join}\n\t\t\tWHERE graph_tree_items.graph_tree_id={$tree_id}\n\t\t\tAND graph_local.id=graph_templates_graph.local_graph_id\n\t\t\tAND graph_tree_items.order_key like '{$search_key}" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', MAX_TREE_DEPTH * CHARS_PER_TIER - (strlen($search_key) + CHARS_PER_TIER)) . "'\n\t\t\tAND graph_tree_items.local_graph_id>0\n\t\t\t{$sql_where}\n\t\t\tGROUP BY graph_tree_items.id\n\t\t\tORDER BY graph_tree_items.order_key");
    } elseif ($leaf_type == 'host') {
        /* graph template grouping */
        if ($leaf['host_grouping_type'] == HOST_GROUPING_GRAPH_TEMPLATE) {
            $graph_templates = db_fetch_assoc("SELECT\n\t\t\t\tgraph_templates.id,\n\t\t\t\tgraph_templates.name\n\t\t\t\tFROM (graph_local,graph_templates,graph_templates_graph)\n\t\t\t\tWHERE graph_local.id=graph_templates_graph.local_graph_id\n\t\t\t\tAND graph_templates_graph.graph_template_id=graph_templates.id\n\t\t\t\tAND graph_local.host_id=" . $leaf['host_id'] . "\n\t\t\t\t" . (empty($graph_template_id) ? "" : "AND graph_templates.id={$graph_template_id}") . "\n\t\t\t\tGROUP BY graph_templates.id\n\t\t\t\tORDER BY graph_templates.name");
            /* for graphs without a template */
            array_push($graph_templates, array('id' => '0', 'name' => '(No Graph Template)'));
            if (sizeof($graph_templates) > 0) {
                foreach ($graph_templates as $graph_template) {
                    if (strlen(get_request_var_request('filter'))) {
                        $sql_where = empty($sql_where) ? '' : "AND (title_cache LIKE '%" . get_request_var_request('filter') . "%')";
                    }
                    $graphs = db_fetch_assoc("SELECT\n\t\t\t\t\tgraph_templates_graph.title_cache,\n\t\t\t\t\tgraph_templates_graph.local_graph_id,\n\t\t\t\t\tgraph_templates_graph.height,\n\t\t\t\t\tgraph_templates_graph.width\n\t\t\t\t\tFROM (graph_local,graph_templates_graph)\n\t\t\t\t\t{$sql_join}\n\t\t\t\t\tWHERE graph_local.id=graph_templates_graph.local_graph_id\n\t\t\t\t\tAND graph_local.graph_template_id=" . $graph_template['id'] . "\n\t\t\t\t\tAND graph_local.host_id=" . $leaf['host_id'] . "\n\t\t\t\t\t{$sql_where}\n\t\t\t\t\tORDER BY graph_templates_graph.title_cache");
                    /* let's sort the graphs naturally */
                    usort($graphs, 'naturally_sort_graphs');
                    if (sizeof($graphs)) {
                        foreach ($graphs as $graph) {
                            $graph['graph_template_name'] = $graph_template['name'];
                            array_push($graph_list, $graph);
                        }
                    }
                }
            }
            /* data query index grouping */
        } elseif ($leaf['host_grouping_type'] == HOST_GROUPING_DATA_QUERY_INDEX) {
            $data_queries = db_fetch_assoc("SELECT\n\t\t\t\tsnmp_query.id,\n\t\t\t\tsnmp_query.name\n\t\t\t\tFROM (graph_local,snmp_query)\n\t\t\t\tWHERE graph_local.snmp_query_id=snmp_query.id\n\t\t\t\tAND graph_local.host_id=" . $leaf['host_id'] . "\n\t\t\t\t" . (!isset($data_query_id) ? '' : "and snmp_query.id={$data_query_id}") . "\n\t\t\t\tGROUP BY snmp_query.id\n\t\t\t\tORDER BY snmp_query.name");
            /* for graphs without a data query */
            if (empty($data_query_id)) {
                array_push($data_queries, array('id' => '0', 'name' => 'Non Query Based'));
            }
            if (sizeof($data_queries) > 0) {
                foreach ($data_queries as $data_query) {
                    /* fetch a list of field names that are sorted by the preferred sort field */
                    $sort_field_data = get_formatted_data_query_indexes($leaf['host_id'], $data_query['id']);
                    if (strlen(get_request_var_request('filter'))) {
                        $sql_where = empty($sql_where) ? '' : "AND (title_cache LIKE '%" . get_request_var_request('filter') . "%')";
                    }
                    /* grab a list of all graphs for this host/data query combination */
                    $graphs = db_fetch_assoc("SELECT\n\t\t\t\t\tgraph_templates_graph.title_cache,\n\t\t\t\t\tgraph_templates_graph.local_graph_id,\n\t\t\t\t\tgraph_templates_graph.height,\n\t\t\t\t\tgraph_templates_graph.width,\n\t\t\t\t\tgraph_local.snmp_index\n\t\t\t\t\tFROM (graph_local, graph_templates_graph)\n\t\t\t\t\t{$sql_join}\n\t\t\t\t\tWHERE graph_local.id=graph_templates_graph.local_graph_id\n\t\t\t\t\tAND graph_local.snmp_query_id=" . $data_query['id'] . "\n\t\t\t\t\tAND graph_local.host_id=" . $leaf['host_id'] . "\n\t\t\t\t\t" . (empty($data_query_index) ? '' : "and graph_local.snmp_index='{$data_query_index}'") . "\n\t\t\t\t\t{$sql_where}\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");
                    /* re-key the results on data query index */
                    $snmp_index_to_graph = array();
                    if (sizeof($graphs) > 0) {
                        /* let's sort the graphs naturally */
                        usort($graphs, 'naturally_sort_graphs');
                        foreach ($graphs as $graph) {
                            $snmp_index_to_graph[$graph['snmp_index']][$graph['local_graph_id']] = $graph['title_cache'];
                            $graphs_height[$graph['local_graph_id']] = $graph['height'];
                            $graphs_width[$graph['local_graph_id']] = $graph['width'];
                        }
                    }
                    /* using the sorted data as they key; grab each snmp index from the master list */
                    while (list($snmp_index, $sort_field_value) = each($sort_field_data)) {
                        /* render each graph for the current data query index */
                        if (isset($snmp_index_to_graph[$snmp_index])) {
                            while (list($local_graph_id, $graph_title) = each($snmp_index_to_graph[$snmp_index])) {
                                /* reformat the array so it's compatable with the html_graph* area functions */
                                array_push($graph_list, array('data_query_name' => $data_query['name'], 'sort_field_value' => $sort_field_value, 'local_graph_id' => $local_graph_id, 'title_cache' => $graph_title, 'height' => $graphs_height[$graph['local_graph_id']], 'width' => $graphs_width[$graph['local_graph_id']]));
                            }
                        }
                    }
                }
            }
        }
    }
    $total_rows = sizeof($graph_list);
    /* generate page list */
    if ($total_rows > get_request_var_request('graphs')) {
        $url_page_select = get_page_list(get_request_var_request('page'), MAX_DISPLAY_PAGES, get_request_var_request('graphs'), $total_rows, "graph_view.php?action=tree_content&tree_id={$tree_id}&leaf_id={$leaf_id}&nodeid=" . get_request_var_request('nodeid') . '&host_group_data=' . get_request_var_request('host_group_data'), 'page', 'main');
        $nav = "<tr class='tableHeader'>\n\t\t\t\t<td colspan='11'>\n\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td align='left' class='textHeaderDark' style='width:5%;'>\n\t\t\t\t\t\t\t\t" . (get_request_var_request('page') > 1 ? "<strong>&lt;&lt;<span style='cursor:pointer;' class='linkOverDark' onClick='pageBack()'>Previous</span></strong>" : '') . "\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td align='center' class='textHeaderDark' style='width:90%;'>\n\t\t\t\t\t\t\t\tShowing Graphs " . (get_request_var_request('graphs') * (get_request_var_request('page') - 1) + 1) . ' to ' . ($total_rows < get_request_var_request('graphs') || $total_rows < get_request_var_request('graphs') * get_request_var_request('page') ? $total_rows : get_request_var_request('graphs') * get_request_var_request('page')) . " of {$total_rows} [{$url_page_select}]\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td align='right' class='textHeaderDark' style='width:5%;'>\n\t\t\t\t\t\t\t\t" . (get_request_var_request('page') * get_request_var_request('graphs') < $total_rows ? "<strong><span style='cursor:pointer;' class='linkOverDark' onClick='pageForward()'>Next</span>&gt;&gt;</strong>" : "") . "\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t</tr>\n";
    } else {
        $nav = "<tr class='tableHeader'>\n\t\t\t\t<td colspan='11'>\n\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\n\t\t\t\t\t\t\t\tShowing All Graphs\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t</tr>\n";
    }
    ?>
	<script type='text/javascript'>
	function pageForward() {
		var url = 'graph_view.php?action=tree_content&tree_id=<?php 
    print $_REQUEST['tree_id'];
    ?>
&leaf_id=<?php 
    print $_REQUEST['leaf_id'];
    ?>
&host_group_data=<?php 
    print get_request_var_request('host_group_data');
    ?>
&nodeid=<?php 
    print $_REQUEST['nodeid'];
    ?>
&page=<?php 
    print get_request_var_request('page') + 1;
    ?>
';
		$.get(url, function(data) {
			$('#main').html(data);
		});
	}
	function pageBack() {
		var url = 'graph_view.php?action=tree_content&tree_id=<?php 
    print $_REQUEST['tree_id'];
    ?>
&leaf_id=<?php 
    print $_REQUEST['leaf_id'];
    ?>
&host_group_data=<?php 
    print get_request_var_request('host_group_data');
    ?>
&nodeid=<?php 
    print $_REQUEST['nodeid'];
    ?>
&page=<?php 
    print get_request_var_request('page') - 1;
    ?>
';
		$.get(url, function(data) {
			$('#main').html(data);
		});
	}
	</script>
	<?php 
    if (!empty($leaf_id)) {
        api_plugin_hook_function('tree_after', $host_name . ',' . get_request_var("leaf_id"));
    }
    api_plugin_hook_function('tree_view_page_end');
    print $nav;
    /* start graph display */
    print "<tr bgcolor='#00438c'><td width='390' colspan='11' class='textHeaderDark'>{$title}</td></tr>";
    $i = get_request_var_request('graphs') * (get_request_var_request('page') - 1);
    $last_graph = $i + get_request_var_request('graphs');
    $new_graph_list = array();
    while ($i < $total_rows && $i < $last_graph) {
        $new_graph_list[] = $graph_list[$i];
        $i++;
    }
    if ($_REQUEST['thumbnails'] == 'true') {
        html_graph_thumbnail_area($new_graph_list, '', 'view_type=tree&graph_start=' . get_current_graph_start() . '&graph_end=' . get_current_graph_end(), '', get_request_var_request('columns'));
    } else {
        html_graph_area($new_graph_list, '', 'view_type=tree&graph_start=' . get_current_graph_start() . '&graph_end=' . get_current_graph_end(), '', 1);
    }
    if (!empty($leaf_id)) {
        api_plugin_hook_function('tree_after', $host_name . ',' . get_request_var_request('leaf_id'));
    }
    api_plugin_hook_function('tree_view_page_end');
    print $nav;
    html_end_box();
}
Ejemplo n.º 11
0
/**
 * expand a tree for including into report
 * @param array $report		- parameters for this report mail report
 * @param int $item			- current graph item
 * @param int $output		- type of output
 * @param bool $format_ok	- use css styling
 * @param bool $nested		- nested tree?
 * @return string			- html
 */
function reports_expand_tree($report, $item, $output, $format_ok, $nested = false)
{
    global $colors, $config, $alignment;
    include $config["include_path"] . "/global_arrays.php";
    include_once $config["library_path"] . "/data_query.php";
    include_once $config["library_path"] . "/tree.php";
    include_once $config["library_path"] . "/html_tree.php";
    include_once $config["library_path"] . "/html_utility.php";
    $tree_id = $item["tree_id"];
    $leaf_id = $item["branch_id"];
    $time = time();
    # get config option for first-day-of-the-week
    $first_weekdayid = read_graph_config_option("first_weekdayid");
    /* check if we have enough data */
    if (isset($_SESSION["sess_current_user"])) {
        $current_user = db_fetch_row("SELECT * FROM user_auth WHERE id=" . $_SESSION["sess_user_id"]);
    } else {
        $current_user = db_fetch_row("SELECT * FROM user_auth WHERE id=" . $report["user_id"]);
    }
    /*todo*/
    $host_group_data = "";
    $timespan = array();
    # get start/end time-since-epoch for actual time (now()) and given current-session-timespan
    get_timespan($timespan, $time, $item["timespan"], $first_weekdayid);
    if (empty($tree_id)) {
        return;
    }
    $sql_where = "";
    $sql_join = "";
    $title = "";
    $title_delimeter = "";
    $search_key = "";
    $outstr = "";
    $leaf = db_fetch_row("SELECT order_key, title, host_id, host_grouping_type FROM graph_tree_items WHERE id={$leaf_id}");
    $leaf_type = get_tree_item_type($leaf_id);
    /* get the "starting leaf" if the user clicked on a specific branch */
    if (!empty($leaf_id)) {
        $search_key = substr($leaf["order_key"], 0, tree_tier($leaf["order_key"]) * CHARS_PER_TIER);
    }
    /* graph permissions */
    if (read_config_option("auth_method") != 0) {
        /* get policy information for the sql where clause */
        $sql_where = get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]);
        $sql_where = empty($sql_where) ? "" : "AND {$sql_where}";
        $sql_join = "\n\t\t\tLEFT JOIN host ON (host.id=graph_local.host_id)\n\t\t\tLEFT JOIN graph_templates ON (graph_templates.id=graph_local.graph_template_id)\n\t\t\tLEFT JOIN user_auth_perms ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id AND user_auth_perms.type=1 AND user_auth_perms.user_id=" . $current_user["id"] . ") OR (host.id=user_auth_perms.item_id AND user_auth_perms.type=3 and user_auth_perms.user_id=" . $current_user["id"] . ") OR (graph_templates.id=user_auth_perms.item_id AND user_auth_perms.type=4 AND user_auth_perms.user_id=" . $current_user["id"] . "))";
    }
    /* get information for the headers */
    if (!empty($tree_id)) {
        $tree_name = db_fetch_cell("SELECT name FROM graph_tree WHERE id={$tree_id}");
    }
    if (!empty($leaf_id)) {
        $leaf_name = $leaf["title"];
    }
    if (!empty($leaf_id)) {
        $host_name = db_fetch_cell("SELECT host.description FROM (graph_tree_items,host) WHERE graph_tree_items.host_id=host.id AND graph_tree_items.id={$leaf_id}");
    }
    $host_group_data_array = explode(":", $host_group_data);
    if ($host_group_data_array[0] == "graph_template") {
        $host_group_data_name = "<strong>Graph Template:</strong> " . db_fetch_cell("SELECT name FROM graph_templates WHERE id=" . $host_group_data_array[1]) . "</td></tr>";
        $graph_template_id = $host_group_data_array[1];
    } elseif ($host_group_data_array[0] == "data_query") {
        $host_group_data_name = "<strong>Graph Template:</strong> " . (empty($host_group_data_array[1]) ? "Non Query Based" : db_fetch_cell("SELECT name FROM snmp_query WHERE id=" . $host_group_data_array[1])) . "</td></tr>";
        $data_query_id = $host_group_data_array[1];
    } elseif ($host_group_data_array[0] == "data_query_index") {
        $host_group_data_name = "<strong>Graph Template:</strong> " . (empty($host_group_data_array[1]) ? "Non Query Based" : db_fetch_cell("SELECT name FROM snmp_query WHERE id=" . $host_group_data_array[1])) . "-> " . (empty($host_group_data_array[2]) ? "Template Based" : get_formatted_data_query_index($leaf["host_id"], $host_group_data_array[1], $host_group_data_array[2])) . "</td></tr>";
        $data_query_id = $host_group_data_array[1];
        $data_query_index = $host_group_data_array[2];
    }
    if (!empty($tree_name) && empty($leaf_name) && empty($host_name) && !$nested) {
        $title .= $title_delimeter . "<strong>Tree:</strong> {$tree_name}";
        $title_delimeter = "-> ";
    } elseif (!empty($leaf_name)) {
        $title .= $title_delimeter . "<strong>Leaf:</strong> {$leaf_name}";
        $title_delimeter = "-> ";
    } elseif (!empty($host_name)) {
        $title .= $title_delimeter . "<strong>Host:</strong> {$host_name}";
        $title_delimeter = "-> ";
    } elseif (!empty($host_group_data_name)) {
        $title .= $title_delimeter . " {$host_group_data_name}";
        $title_delimeter = "-> ";
    }
    if (isset($_REQUEST["tree_id"])) {
        $nodeid = "tree_" . $_REQUEST["tree_id"];
    }
    if (isset($_REQUEST["leaf_id"])) {
        $nodeid .= "_leaf" . $_REQUEST["leaf_id"];
    }
    /* start graph display */
    if (strlen($title)) {
        $outstr .= "\t\t<tr class='text_row'>\n";
        if ($format_ok) {
            $outstr .= "\t\t\t<td class='text' align='" . $alignment[$item["align"]] . "'>\n";
        } else {
            $outstr .= "\t\t\t<td class='text' align='" . $alignment[$item["align"]] . "' style='font-size: " . $item["font_size"] . "pt;'>\n";
        }
        $outstr .= "\t\t\t\t{$title}\n";
        $outstr .= "\t\t\t</td>\n";
        $outstr .= "\t\t</tr>\n";
    }
    if (strlen($item["graph_name_regexp"])) {
        $sql_where .= " AND title_cache REGEXP '" . $item["graph_name_regexp"] . "'";
    }
    if ($leaf_type == "header" || empty($leaf_id)) {
        $heirarchy = db_fetch_assoc("SELECT\n\t\t\tgraph_tree_items.local_graph_id\n\t\t\tFROM (graph_tree_items,graph_local)\n\t\t\tLEFT JOIN graph_templates_graph ON (graph_tree_items.local_graph_id=graph_templates_graph.local_graph_id AND graph_tree_items.local_graph_id>0)\n\t\t\t{$sql_join}\n\t\t\tWHERE graph_tree_items.graph_tree_id={$tree_id}\n\t\t\tAND graph_local.id=graph_templates_graph.local_graph_id\n\t\t\tAND graph_tree_items.order_key like '{$search_key}" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', MAX_TREE_DEPTH * CHARS_PER_TIER - (strlen($search_key) + CHARS_PER_TIER)) . "'\n\t\t\tAND graph_tree_items.local_graph_id>0\n\t\t\t{$sql_where}\n\t\t\tGROUP BY graph_tree_items.id\n\t\t\tORDER BY graph_tree_items.order_key");
        $outstr .= reports_graph_area($heirarchy, $report, $item, $timespan, $output, $format_ok);
    } elseif ($leaf_type == "host") {
        /* graph template grouping */
        if ($leaf["host_grouping_type"] == HOST_GROUPING_GRAPH_TEMPLATE) {
            $graph_templates = db_fetch_assoc("SELECT\n\t\t\t\tgraph_templates.id,\n\t\t\t\tgraph_templates.name\n\t\t\t\tFROM (graph_local,graph_templates,graph_templates_graph)\n\t\t\t\tWHERE graph_local.id=graph_templates_graph.local_graph_id\n\t\t\t\tAND graph_templates_graph.graph_template_id=graph_templates.id\n\t\t\t\tAND graph_local.host_id=" . $leaf["host_id"] . "\n\t\t\t\t" . (empty($graph_template_id) ? "" : "AND graph_templates.id={$graph_template_id}") . "\n\t\t\t\tGROUP BY graph_templates.id\n\t\t\t\tORDER BY graph_templates.name");
            /* for graphs without a template */
            array_push($graph_templates, array("id" => "0", "name" => "(No Graph Template)"));
            $outgraphs = array();
            if (sizeof($graph_templates) > 0) {
                foreach ($graph_templates as $graph_template) {
                    $graphs = db_fetch_assoc("SELECT\n\t\t\t\t\t\tgraph_templates_graph.title_cache,\n\t\t\t\t\t\tgraph_templates_graph.local_graph_id\n\t\t\t\t\t\tFROM (graph_local,graph_templates_graph)\n\t\t\t\t\t\t{$sql_join}\n\t\t\t\t\t\tWHERE graph_local.id=graph_templates_graph.local_graph_id\n\t\t\t\t\t\tAND graph_local.graph_template_id=" . $graph_template["id"] . "\n\t\t\t\t\t\tAND graph_local.host_id=" . $leaf["host_id"] . "\n\t\t\t\t\t\t{$sql_where}\n\t\t\t\t\t\tORDER BY graph_templates_graph.title_cache");
                    $outgraphs = array_merge($outgraphs, $graphs);
                }
                if (sizeof($outgraphs) > 0) {
                    /* let's sort the graphs naturally */
                    usort($outgraphs, 'necturally_sort_graphs');
                    $outstr .= reports_graph_area($outgraphs, $report, $item, $timespan, $output, $format_ok);
                }
            }
            /* data query index grouping */
        } elseif ($leaf["host_grouping_type"] == HOST_GROUPING_DATA_QUERY_INDEX) {
            $data_queries = db_fetch_assoc("SELECT\n\t\t\t\tsnmp_query.id,\n\t\t\t\tsnmp_query.name\n\t\t\t\tFROM (graph_local,snmp_query)\n\t\t\t\tWHERE graph_local.snmp_query_id=snmp_query.id\n\t\t\t\tAND graph_local.host_id=" . $leaf["host_id"] . "\n\t\t\t\t" . (!isset($data_query_id) ? "" : "AND snmp_query.id={$data_query_id}") . "\n\t\t\t\tGROUP BY snmp_query.id\n\t\t\t\tORDER BY snmp_query.name");
            /* for graphs without a data query */
            if (empty($data_query_id)) {
                array_push($data_queries, array("id" => "0", "name" => "Non Query Based"));
            }
            if (sizeof($data_queries) > 0) {
                foreach ($data_queries as $data_query) {
                    /* fetch a list of field names that are sorted by the preferred sort field */
                    $sort_field_data = get_formatted_data_query_indexes($leaf["host_id"], $data_query["id"]);
                    /* grab a list of all graphs for this host/data query combination */
                    $graphs = db_fetch_assoc("SELECT\n\t\t\t\t\tgraph_templates_graph.title_cache,\n\t\t\t\t\tgraph_templates_graph.local_graph_id,\n\t\t\t\t\tgraph_local.snmp_index\n\t\t\t\t\tFROM (graph_local,graph_templates_graph)\n\t\t\t\t\t{$sql_join}\n\t\t\t\t\tWHERE graph_local.id=graph_templates_graph.local_graph_id\n\t\t\t\t\tAND graph_local.snmp_query_id=" . $data_query["id"] . "\n\t\t\t\t\tAND graph_local.host_id=" . $leaf["host_id"] . "\n\t\t\t\t\t" . (empty($data_query_index) ? "" : "AND graph_local.snmp_index='{$data_query_index}'") . "\n\t\t\t\t\t{$sql_where}\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");
                    /* re-key the results on data query index */
                    if (sizeof($graphs) > 0) {
                        $outstr .= "\t\t<tr class='text_row'>\n";
                        if ($format_ok) {
                            $outstr .= "\t\t\t<td class='text' align='" . $alignment[$item["align"]] . "'><strong>Data Query:</strong> " . $data_query["name"] . "\n";
                            $outstr .= "\t\t\t</td>\n";
                            $outstr .= "\t\t</tr>\n";
                        } else {
                            $outstr .= "\t\t\t<td class='text' align='" . $alignment[$item["align"]] . "' style='font-size: " . $item["font_size"] . "pt;'><strong>Data Query:</strong> " . $data_query["name"] . "\n";
                            $outstr .= "\t\t\t</td>\n";
                            $outstr .= "\t\t</tr>\n";
                        }
                        /* let's sort the graphs naturally */
                        usort($graphs, 'necturally_sort_graphs');
                        foreach ($graphs as $graph) {
                            $snmp_index_to_graph[$graph["snmp_index"]][$graph["local_graph_id"]] = $graph["title_cache"];
                        }
                    }
                    /* using the sorted data as they key; grab each snmp index from the master list */
                    $graph_list = array();
                    while (list($snmp_index, $sort_field_value) = each($sort_field_data)) {
                        /* render each graph for the current data query index */
                        if (isset($snmp_index_to_graph[$snmp_index])) {
                            while (list($local_graph_id, $graph_title) = each($snmp_index_to_graph[$snmp_index])) {
                                /* reformat the array so it's compatable with the html_graph* area functions */
                                array_push($graph_list, array("local_graph_id" => $local_graph_id, "title_cache" => $graph_title));
                            }
                        }
                    }
                    if (sizeof($graph_list)) {
                        $outstr .= reports_graph_area($graph_list, $report, $item, $timespan, $output, $format_ok);
                    }
                }
            }
        }
    }
    return $outstr;
}
Ejemplo n.º 12
0
function create_dhtml_tree_export($tree_id) {
	/* record start time */
	list($micro,$seconds) = split(" ", microtime());
	$start = $seconds + $micro;
	$search_key = "";

	$dhtml_tree = array();
	$dhtml_tree[0] = $start;
	$dhtml_tree[1] = read_graph_config_option("expand_hosts");
	$dhtml_tree[2] = "foldersTree = gFld(\"\", \"\")\n";
	$i = 2;

	$tree_list = get_graph_tree_array_export();

	/* auth check for hosts on the trees */
	$current_user = db_fetch_row("SELECT * FROM user_auth WHERE id=" . read_config_option("export_user_id"));

	$sql_join  = "LEFT JOIN user_auth_perms ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=1 AND user_auth_perms.user_id=" . $current_user["id"] . ") OR (host.id=user_auth_perms.item_id AND user_auth_perms.type=3 AND user_auth_perms.user_id=" . $current_user["id"] . ") OR (graph_templates.id=user_auth_perms.item_id AND user_auth_perms.type=4 AND user_auth_perms.user_id=" . $current_user["id"] . "))";
//	$sql_join  = "LEFT JOIN user_auth_perms ON (host.id=user_auth_perms.item_id AND user_auth_perms.type=3 AND user_auth_perms.user_id=" . $current_user["id"] . ")";
	$sql_where = get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]);
	$sql_where = (empty($sql_where) ? "" : "AND $sql_where");

	if (sizeof($tree_list) > 0) {
	foreach ($tree_list as $tree) {
		$i++;

		$heir_sql = "SELECT
				graph_tree_items.id,
				graph_tree_items.title,
				graph_tree_items.order_key,
				graph_tree_items.host_id,
				graph_tree_items.host_grouping_type,
				host.description as hostname
				FROM graph_tree_items
				LEFT JOIN host ON (host.id=graph_tree_items.host_id)
				LEFT JOIN graph_templates ON (graph_templates_graph.graph_template_id=graph_templates.id)
				$sql_join
				WHERE graph_tree_items.graph_tree_id=" . $tree["id"] . "
				$sql_where
				AND graph_tree_items.local_graph_id = 0
				ORDER BY graph_tree_items.order_key";

		$heirarchy = db_fetch_assoc($heir_sql);

		$dhtml_tree_id = 0;

		if (sizeof($heirarchy) > 0) {
		foreach ($heirarchy as $leaf) {
			if ($dhtml_tree_id <> $tree["id"]) {
				$dhtml_tree[$i] = "ou0 = insFld(foldersTree, gFld(\"" . get_tree_name($tree["id"]) . "\", \"" . clean_up_export_name(get_tree_name($tree["id"])) . "_leaf.html\"))\n";
			}
			$dhtml_tree_id = $tree["id"];

			$i++;
			$tier = tree_tier($leaf["order_key"]);

			if ($leaf["host_id"] > 0) {  //It's a host
				$dhtml_tree[$i] = "ou" . ($tier) . " = insFld(ou" . ($tier-1) . ", gFld(\"<strong>Host:</strong> " . htmlentities($leaf["hostname"], ENT_QUOTES) . "\", \"" . clean_up_export_name($leaf["hostname"] . "_" . $leaf["id"]) . ".html\"))\n";

				if (read_config_option("export_tree_expand_hosts") == "on") {
					if ($leaf["host_grouping_type"] == HOST_GROUPING_GRAPH_TEMPLATE) {
						$graph_templates = db_fetch_assoc("SELECT
							graph_templates.id,
							graph_templates.name,
							graph_templates_graph.local_graph_id,
							graph_templates_graph.title_cache
							FROM (graph_local,graph_templates,graph_templates_graph)
							WHERE graph_local.id=graph_templates_graph.local_graph_id
							AND graph_templates_graph.graph_template_id=graph_templates.id
							AND graph_local.host_id=" . $leaf["host_id"] . "
							GROUP BY graph_templates.id
							ORDER BY graph_templates.name");

					 	if (sizeof($graph_templates) > 0) {
							foreach ($graph_templates as $graph_template) {
								$i++;
								$dhtml_tree[$i] = "ou" . ($tier+1) . " = insFld(ou" . ($tier) . ", gFld(\" " . $graph_template["name"] . "\", \"" . clean_up_export_name($leaf["hostname"] . "_gt_" . $leaf["id"]) . "_" . $graph_template["id"] . ".html\"))\n";
							}
						}
					}else if ($leaf["host_grouping_type"] == HOST_GROUPING_DATA_QUERY_INDEX) {
						$data_queries = db_fetch_assoc("SELECT
							snmp_query.id,
							snmp_query.name
							FROM (graph_local,snmp_query)
							WHERE graph_local.snmp_query_id=snmp_query.id
							AND graph_local.host_id=" . $leaf["host_id"] . "
							GROUP BY snmp_query.id
							ORDER BY snmp_query.name");

						array_push($data_queries, array(
							"id" => "0",
							"name" => "Graph Template Based"
							));

						if (sizeof($data_queries) > 0) {
						foreach ($data_queries as $data_query) {
							$i++;

							$dhtml_tree[$i] = "ou" . ($tier+1) . " = insFld(ou" . ($tier) . ", gFld(\" " . $data_query["name"] . "\", \"" . clean_up_export_name($leaf["hostname"] . "_dq_" . $leaf["title"] . "_" . $leaf["id"]) . "_" . $data_query["id"] . ".html\"))\n";

							/* fetch a list of field names that are sorted by the preferred sort field */
							$sort_field_data = get_formatted_data_query_indexes($leaf["host_id"], $data_query["id"]);

							if ($data_query["id"] > 0) {
								while (list($snmp_index, $sort_field_value) = each($sort_field_data)) {
									$i++;
									$dhtml_tree[$i] = "ou" . ($tier+2) . " = insFld(ou" . ($tier+1) . ", gFld(\" " . $sort_field_value . "\", \"" . clean_up_export_name($leaf["hostname"] . "_dqi_" . $leaf["title"] . "_" . $leaf["id"]) . "_" . $data_query["id"] . "_" . $snmp_index . ".html\"))\n";
								}
							}
						}
						}
					}
				}
			}else {
				$dhtml_tree[$i] = "ou" . ($tier) . " = insFld(ou" . ($tier-1) . ", gFld(\"" . htmlentities($leaf["title"], ENT_QUOTES) . "\", \"" . clean_up_export_name(get_tree_name($tree["id"]) . "_" . $leaf["title"] . "_" . $leaf["id"]) . "_leaf.html\"))\n";
			}
		}
		}
	}
	}

	return $dhtml_tree;
}
Ejemplo n.º 13
0
function list_tholds()
{
    global $colors, $thold_bgcolors, $config, $hostid;
    $thold_actions = array(1 => 'Delete', 2 => 'Disable', 3 => 'Enable', 4 => 'Reapply Suggested Names');
    thold_request_validation();
    $statefilter = '';
    if (isset($_REQUEST['state'])) {
        if ($_REQUEST['state'] == '-1') {
            $statefilter = '';
        } else {
            if ($_REQUEST['state'] == '0') {
                $statefilter = "thold_data.thold_enabled='off'";
            }
            if ($_REQUEST['state'] == '2') {
                $statefilter = "thold_data.thold_enabled='on'";
            }
            if ($_REQUEST['state'] == '1') {
                $statefilter = '(thold_data.thold_alert!=0 OR thold_data.bl_alert>0)';
            }
            if ($_REQUEST['state'] == '3') {
                $statefilter = '((thold_data.thold_alert!=0 AND thold_data.thold_fail_count >= thold_data.thold_fail_trigger) OR (thold_data.bl_alert>0 AND thold_data.bl_fail_count >= thold_data.bl_fail_trigger))';
            }
        }
    }
    $alert_num_rows = read_config_option('alert_num_rows');
    if ($alert_num_rows < 1 || $alert_num_rows > 999) {
        db_execute("REPLACE INTO settings VALUES ('alert_num_rows', 30)");
        /* pull it again so it updates the cache */
        $alert_num_rows = read_config_option('alert_num_rows', true);
    }
    include $config['include_path'] . '/top_header.php';
    $sql_where = '';
    $sort = $_REQUEST['sort_column'];
    $limit = ' LIMIT ' . $alert_num_rows * ($_REQUEST['page'] - 1) . ",{$alert_num_rows}";
    if (!empty($_REQUEST['hostid']) && $_REQUEST['hostid'] != 'ALL') {
        $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . "thold_data.host_id = " . $_REQUEST['hostid'];
    }
    if (!empty($_REQUEST['template']) && $_REQUEST['template'] != 'ALL') {
        $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . "thold_data.data_template = " . $_REQUEST['template'];
    }
    if ($statefilter != '') {
        $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . "{$statefilter}";
    }
    /* modify for multi user start */
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        $sql = "\r\n            SELECT thold_data.* FROM thold_data\r\n                INNER JOIN user_auth_perms ON thold_data.host_id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'\r\n            {$sql_where}\r\n            ORDER BY {$sort} " . $_REQUEST['sort_direction'] . $limit;
    } else {
        $current_user = db_fetch_row('SELECT * FROM user_auth WHERE id=' . $_SESSION['sess_user_id']);
        $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . get_graph_permissions_sql($current_user['policy_graphs'], $current_user['policy_hosts'], $current_user['policy_graph_templates']);
        $sql = "SELECT * FROM thold_data\r\n\t\tLEFT JOIN user_auth_perms on ((thold_data.graph_id=user_auth_perms.item_id and user_auth_perms.type=1 and user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . ") OR (thold_data.host_id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . ") OR (thold_data.graph_template=user_auth_perms.item_id and user_auth_perms.type=4 and user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . "))\r\n\t\t{$sql_where}\r\n\t\tORDER BY {$sort} " . $_REQUEST['sort_direction'] . $limit;
    }
    /* modify for multi user end */
    $result = db_fetch_assoc($sql);
    /* modify for multi user start */
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        $hostresult = db_fetch_assoc("\r\n            SELECT host.id, host.description, host.hostname FROM host \r\n                INNER JOIN thold_data ON host.id = thold_data.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'");
        $data_templates = db_fetch_assoc("\r\n            SELECT DISTINCT data_template.id, data_template.name FROM data_template\r\n                INNER JOIN thold_data ON thold_data.data_template = data_template.id\r\n                INNER JOIN host ON thold_data.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'\r\n            ORDER BY data_template.name");
    } else {
        $sql_where_hid = 'WHERE ' . get_graph_permissions_sql($current_user['policy_graphs'], $current_user['policy_hosts'], $current_user['policy_graph_templates']);
        $hostresult = db_fetch_assoc("SELECT DISTINCT host.id, host.description, host.hostname\r\n\t\tFROM host\r\n\t\tINNER JOIN thold_data ON (host.id = thold_data.host_id)\r\n\t\tLEFT JOIN user_auth_perms on (thold_data.host_id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . ")\r\n\t\t{$sql_where_hid}\r\n\t\tORDER BY description");
        $data_templates = db_fetch_assoc("SELECT DISTINCT data_template.id, data_template.name\r\n\t\tFROM data_template\r\n\t\tINNER JOIN thold_data ON (thold_data.data_template = data_template.id)\r\n\t\tORDER BY data_template.name");
    }
    /* modify for multi user end */
    ?>
	<script type="text/javascript">
	<!--
	function applyTHoldFilterChange(objForm) {
		strURL = '?hostid=' + objForm.hostid.value;
		strURL = strURL + '&state=' + objForm.state.value;
		strURL = strURL + '&template=' + objForm.template.value;
		document.location = strURL;
	}
	-->
	</script>
	<?php 
    /* modify for multi user start */
    if (check_resource_count(RESOURCE_THOLD) == TRUE) {
        html_start_box('<strong>Threshold Management</strong>', '100%', $colors['header'], '3', 'center', 'thold_add.php');
    } else {
        html_start_box('<strong>Threshold Management</strong>', '100%', $colors['header'], '3', 'center', '');
    }
    /* modify for multi user end */
    ?>
	<tr bgcolor='#<?php 
    print $colors["panel"];
    ?>
' class='noprint'>
		<td class='noprint'>
			<form name='listthold' action='listthold.php' method='post'>
			<table cellpadding='0' cellspacing='0'>
				<tr class='noprint'>
					<td width='1'>
						&nbsp;Host:&nbsp;
					</td>
					<td width='1'>
						<select name='hostid' onChange='applyTHoldFilterChange(document.listthold)'>
							<option value='ALL'>Any</option>
							<?php 
    foreach ($hostresult as $row) {
        echo "<option value='" . $row['id'] . "'" . (isset($_REQUEST['hostid']) && $row['id'] == $_REQUEST['hostid'] ? ' selected' : '') . '>' . $row['description'] . ' - (' . $row['hostname'] . ')' . '</option>';
    }
    ?>
						</select>
					</td>
					<td width='1'>
						&nbsp;Template:&nbsp;
					</td>
					<td width='1'>
						<select name='template' onChange='applyTHoldFilterChange(document.listthold)'>
							<option value='ALL'>Any</option>
							<?php 
    foreach ($data_templates as $row) {
        echo "<option value='" . $row['id'] . "'" . (isset($_REQUEST['template']) && $row['id'] == $_REQUEST['template'] ? ' selected' : '') . '>' . $row['name'] . '</option>';
    }
    ?>
						</select>
					</td>
					<td width='1'>
						&nbsp;State:&nbsp;
					</td>
					<td width='1'>
						<select name='state' onChange='applyTHoldFilterChange(document.listthold)'>
							<option value='-1'<?php 
    if ($_REQUEST["state"] == "-1") {
        ?>
 selected<?php 
    }
    ?>
>All</option>
							<option value='1'<?php 
    if ($_REQUEST["state"] == "1") {
        ?>
 selected<?php 
    }
    ?>
>Breached</option>
							<option value='3'<?php 
    if ($_REQUEST["state"] == "3") {
        ?>
 selected<?php 
    }
    ?>
>Triggered</option>
							<option value='2'<?php 
    if ($_REQUEST["state"] == "2") {
        ?>
 selected<?php 
    }
    ?>
>Enabled</option>
							<option value='0'<?php 
    if ($_REQUEST["state"] == "0") {
        ?>
 selected<?php 
    }
    ?>
>Disabled</option>
						</select>
					</td>
					<td nowrap style='white-space: nowrap;'>
						&nbsp;<input type='submit' name='clear' value='Clear' title='Return to Defaults'>
					</td>
				</tr>
			</table>
			<input type='hidden' name='search' value='search'>
			</form>
		</td>
	</tr>
	<?php 
    html_end_box();
    define('MAX_DISPLAY_PAGES', 21);
    /* modify for multi user start */
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        $total_rows = db_fetch_cell("\r\n            SELECT COUNT(thold_data.id) FROM thold_data\r\n                INNER JOIN user_auth_perms ON thold_data.host_id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'\r\n            {$sql_where}");
    } else {
        $total_rows = count(db_fetch_assoc("SELECT thold_data.id\r\n\t\tFROM thold_data\r\n\t\tLEFT JOIN user_auth_perms\r\n\t\tON ((thold_data.graph_id=user_auth_perms.item_id\r\n\t\tAND user_auth_perms.type=1\r\n\t\tAND user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . ")\r\n\t\tOR (thold_data.host_id=user_auth_perms.item_id\r\n\t\tAND user_auth_perms.type=3\r\n\t\tAND user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . ")\r\n\t\tOR (thold_data.graph_template=user_auth_perms.item_id\r\n\t\tAND user_auth_perms.type=4\r\n\t\tAND user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . "))\r\n\t\t{$sql_where}"));
    }
    /* modify for multi user end */
    $url_page_select = get_page_list($_REQUEST['page'], MAX_DISPLAY_PAGES, $alert_num_rows, $total_rows, 'listthold.php?');
    /* print checkbox form for validation */
    print "<form name='chk' method='post' action='listthold.php'>\n";
    html_start_box('', '100%', $colors['header'], '4', 'center', '');
    if ($total_rows) {
        $nav = "<tr bgcolor='#" . $colors['header'] . "'>\r\n\t\t\t\t<td colspan='12'>\r\n\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<td align='left' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\t<strong>&lt;&lt; ";
        if ($_REQUEST["page"] > 1) {
            $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("listthold.php?page=" . ($_REQUEST["page"] - 1)) . "'>";
        }
        $nav .= "Previous";
        if ($_REQUEST["page"] > 1) {
            $nav .= "</a>";
        }
        $nav .= "</strong>\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\tShowing Rows " . ($alert_num_rows * ($_REQUEST["page"] - 1) + 1) . " to " . ($total_rows < $alert_num_rows || $total_rows < $alert_num_rows * $_REQUEST["page"] ? $total_rows : $alert_num_rows * $_REQUEST["page"]) . " of {$total_rows} [{$url_page_select}]\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t\t<td align='right' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\t<strong>";
        if ($_REQUEST["page"] * $alert_num_rows < $total_rows) {
            $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("listthold.php?page=" . ($_REQUEST["page"] + 1)) . "'>";
        }
        $nav .= "Next";
        if ($_REQUEST["page"] * $alert_num_rows < $total_rows) {
            $nav .= "</a>";
        }
        $nav .= " &gt;&gt;</strong>\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t</table>\r\n\t\t\t\t</td>\r\n\t\t\t</tr>\n";
    } else {
        $nav = "<tr bgcolor='#" . $colors['header'] . "'>\r\n\t\t\t\t<td colspan='12'>\r\n\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\tNo Rows Found\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t</table>\r\n\t\t\t\t</td>\r\n\t\t\t</tr>\n";
    }
    print $nav;
    $display_text = array('name' => array('Name', 'ASC'), 'thold_type' => array('Type', 'ASC'), 'thold_hi' => array('High', 'ASC'), 'thold_low' => array('Low', 'ASC'), 'nosort3' => array('Trigger', ''), 'nosort4' => array('Duration', ''), 'repeat_alert' => array('Repeat', 'ASC'), 'lastread' => array('Current', 'ASC'), 'thold_alert' => array('Triggered', 'ASC'), 'thold_enabled' => array('Enabled', 'ASC'));
    html_header_sort_checkbox($display_text, $_REQUEST['sort_column'], $_REQUEST['sort_direction'], false);
    $timearray = array(1 => '5 Minutes', 2 => '10 Minutes', 3 => '15 Minutes', 4 => '20 Minutes', 6 => '30 Minutes', 8 => '45 Minutes', 12 => 'Hour', 24 => '2 Hours', 36 => '3 Hours', 48 => '4 Hours', 72 => '6 Hours', 96 => '8 Hours', 144 => '12 Hours', 288 => '1 Day', 576 => '2 Days', 2016 => '1 Week', 4032 => '2 Weeks', 8640 => '1 Month');
    $c = 0;
    $i = 0;
    $types = array('High/Low', 'Baseline Deviation', 'Time Based');
    if (count($result)) {
        foreach ($result as $row) {
            $c++;
            $grapharr = db_fetch_row('SELECT DISTINCT graph_templates_item.local_graph_id
						FROM graph_templates_item, data_template_rrd
						WHERE (data_template_rrd.local_data_id=' . $row['rra_id'] . ' AND data_template_rrd.id=graph_templates_item.task_item_id)');
            $graph_id = $grapharr['local_graph_id'];
            $alertstat = 'no';
            $bgcolor = 'green';
            if ($row['thold_type'] == 0) {
                if ($row['thold_alert'] != 0) {
                    $alertstat = 'yes';
                    if ($row['thold_fail_count'] >= $row['thold_fail_trigger']) {
                        $bgcolor = 'red';
                    } elseif ($row['thold_warning_fail_count'] >= $row['thold_warning_fail_trigger']) {
                        $bgcolor = 'warning';
                    } else {
                        $bgcolor = 'yellow';
                    }
                }
            } elseif ($row['thold_type'] == 2) {
                if ($row['thold_alert'] != 0) {
                    $alertstat = 'yes';
                    if ($row['thold_fail_count'] >= $row['time_fail_trigger']) {
                        $bgcolor = 'red';
                    } elseif ($row['thold_warning_fail_count'] >= $row['time_warning_fail_trigger']) {
                        $bgcolor = 'warning';
                    } else {
                        $bgcolor = 'yellow';
                    }
                }
            } else {
                if ($row['bl_alert'] == 1) {
                    $alertstat = 'baseline-LOW';
                    $bgcolor = $row['bl_fail_count'] >= $row['bl_fail_trigger'] ? 'orange' : 'yellow';
                } elseif ($row['bl_alert'] == 2) {
                    $alertstat = 'baseline-HIGH';
                    $bgcolor = $row['bl_fail_count'] >= $row['bl_fail_trigger'] ? 'orange' : 'yellow';
                }
            }
            if ($row['thold_enabled'] == 'off') {
                form_alternate_row_color($thold_bgcolors['grey'], $thold_bgcolors['grey'], $i, 'line' . $row["id"]);
                $i++;
            } else {
                form_alternate_row_color($thold_bgcolors[$bgcolor], $thold_bgcolors[$bgcolor], $i, 'line' . $row["id"]);
                $i++;
            }
            form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars("thold.php?rra=" . $row['rra_id'] . "&view_rrd=" . $row['data_id']) . "'>" . ($row['name'] != '' ? $row['name'] : $row['name_cache'] . " [" . $row['data_source_name'] . ']') . '</a>', $row['id']);
            form_selectable_cell($types[$row['thold_type']], $row["id"]);
            switch ($row['thold_type']) {
                case 0:
                    form_selectable_cell(thold_format_number($row['thold_hi']), $row["id"]);
                    form_selectable_cell(thold_format_number($row['thold_low']), $row["id"]);
                    form_selectable_cell("<i>" . plugin_thold_duration_convert($row['rra_id'], $row['thold_fail_trigger'], 'alert') . "</i>", $row["id"]);
                    form_selectable_cell("", $row["id"]);
                    break;
                case 1:
                    form_selectable_cell(thold_format_number($row['thold_hi']), $row["id"]);
                    form_selectable_cell(thold_format_number($row['thold_low']), $row["id"]);
                    form_selectable_cell("<i>" . plugin_thold_duration_convert($row['rra_id'], $row['bl_fail_trigger'], 'alert') . "</i>", $row["id"]);
                    form_selectable_cell($timearray[$row['bl_ref_time_range'] / 300], $row["id"]);
                    break;
                case 2:
                    form_selectable_cell(thold_format_number($row['time_hi']), $row["id"]);
                    form_selectable_cell(thold_format_number($row['time_low']), $row["id"]);
                    form_selectable_cell("<i>" . $row['time_fail_trigger'] . " Triggers</i>", $row["id"]);
                    form_selectable_cell(plugin_thold_duration_convert($row['rra_id'], $row['time_fail_length'], 'time'), $row["id"]);
                    break;
                default:
                    form_selectable_cell("", $row["id"]);
                    form_selectable_cell("", $row["id"]);
                    form_selectable_cell("", $row["id"]);
                    form_selectable_cell("", $row["id"]);
            }
            form_selectable_cell($row['repeat_alert'] == '' ? '' : plugin_thold_duration_convert($row['rra_id'], $row['repeat_alert'], 'repeat'), $row["id"]);
            form_selectable_cell(thold_format_number($row['lastread']), $row["id"]);
            form_selectable_cell($alertstat, $row["id"]);
            form_selectable_cell($row['thold_enabled'] == 'off' ? "Disabled" : "Enabled", $row["id"]);
            form_checkbox_cell($row['name'], $row['id']);
            form_end_row();
        }
    } else {
        form_alternate_row_color($colors['alternate'], $colors['light'], 0);
        print '<td colspan=12><center>No Thresholds</center></td></tr>';
    }
    print $nav;
    html_end_box(false);
    thold_legend();
    draw_actions_dropdown($thold_actions);
    if (isset($hostid) && $hostid != '') {
        print "<input type=hidden name=hostid value={$hostid}>";
    }
    print "</form>\n";
    include_once $config['include_path'] . '/bottom_footer.php';
}
Ejemplo n.º 14
0
function grow_right_pane_tree($tree_id, $leaf_id, $host_group_data)
{
    global $current_user, $colors, $config, $graphs_per_page, $graph_timeshifts;
    include $config["include_path"] . "/global_arrays.php";
    include_once $config["library_path"] . "/data_query.php";
    include_once $config["library_path"] . "/tree.php";
    include_once $config["library_path"] . "/html_utility.php";
    define("MAX_DISPLAY_PAGES", 21);
    if (empty($tree_id)) {
        return;
    }
    $sql_where = "";
    $sql_join = "";
    $title = "";
    $title_delimeter = "";
    $search_key = "";
    $leaf = db_fetch_row("SELECT order_key, title, host_id, host_grouping_type\r\n\t\t\t\t\tFROM graph_tree_items\r\n\t\t\t\t\tWHERE id={$leaf_id}");
    $leaf_type = get_tree_item_type($leaf_id);
    /* get the "starting leaf" if the user clicked on a specific branch */
    if (!empty($leaf_id)) {
        $search_key = substr($leaf["order_key"], 0, tree_tier($leaf["order_key"]) * CHARS_PER_TIER);
    }
    /* graph permissions */
    if (read_config_option("auth_method") != 0) {
        /* get policy information for the sql where clause */
        $sql_where = get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]);
        $sql_where = empty($sql_where) ? "" : "AND {$sql_where}";
        /* modify for multi user start */
        if ($_SESSION["permission"] <= ACCESS_ADMINISTRATOR && $tree_id == $_SESSION["public_tree_id"]) {
            $sql_join = "\r\n                LEFT JOIN (SELECT local_graph_id ,COUNT(local_graph_id) AS count FROM graph_tree_items WHERE local_graph_id != '0' GROUP BY local_graph_id) AS gti ON graph_tree_items.local_graph_id = gti.local_graph_id \r\n                LEFT JOIN host ON (host.id=graph_local.host_id)\r\n                LEFT JOIN graph_templates ON (graph_templates.id=graph_local.graph_template_id)\r\n                LEFT JOIN user_auth_perms ON (graph_templates_graph.local_graph_id=user_auth_perms.item_id AND user_auth_perms.type=1)";
            $sql_order = "gti.count DESC";
        } else {
            $sql_join = "\r\n\t\t\tLEFT JOIN host ON (host.id=graph_local.host_id)\r\n\t\t\tLEFT JOIN graph_templates ON (graph_templates.id=graph_local.graph_template_id)\r\n\t\t\tLEFT JOIN user_auth_perms ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id AND user_auth_perms.type=1 AND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (host.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_templates.id=user_auth_perms.item_id AND user_auth_perms.type=4 AND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . "))";
            $sql_order = "graph_tree_items.order_key";
        }
        /* modify for multi user end */
    }
    /* get information for the headers */
    if (!empty($tree_id)) {
        $tree_name = db_fetch_cell("SELECT name FROM graph_tree WHERE id={$tree_id}");
    }
    if (!empty($leaf_id)) {
        $leaf_name = $leaf["title"];
    }
    if (!empty($leaf_id)) {
        $host_name = db_fetch_cell("SELECT host.description FROM (graph_tree_items,host) WHERE graph_tree_items.host_id=host.id AND graph_tree_items.id={$leaf_id}");
    }
    $host_group_data_array = explode(":", $host_group_data);
    if ($host_group_data_array[0] == "graph_template") {
        $host_group_data_name = "<strong>Graph Template:</strong> " . db_fetch_cell("select name from graph_templates where id=" . $host_group_data_array[1]);
        $graph_template_id = $host_group_data_array[1];
    } elseif ($host_group_data_array[0] == "data_query") {
        $host_group_data_name = "<strong>Graph Template:</strong> " . (empty($host_group_data_array[1]) ? "Non Query Based" : db_fetch_cell("select name from snmp_query where id=" . $host_group_data_array[1]));
        $data_query_id = $host_group_data_array[1];
    } elseif ($host_group_data_array[0] == "data_query_index") {
        $host_group_data_name = "<strong>Graph Template:</strong> " . (empty($host_group_data_array[1]) ? "Non Query Based" : db_fetch_cell("select name from snmp_query where id=" . $host_group_data_array[1])) . "-> " . (empty($host_group_data_array[2]) ? "Template Based" : get_formatted_data_query_index($leaf["host_id"], $host_group_data_array[1], $host_group_data_array[2]));
        $data_query_id = $host_group_data_array[1];
        $data_query_index = $host_group_data_array[2];
    }
    if (!empty($tree_name)) {
        $title .= $title_delimeter . "<strong>Tree:</strong>" . htmlspecialchars($tree_name);
        $title_delimeter = "-> ";
    }
    if (!empty($leaf_name)) {
        $title .= $title_delimeter . "<strong>Leaf:</strong>" . htmlspecialchars($leaf_name);
        $title_delimeter = "-> ";
    }
    if (!empty($host_name)) {
        $title .= $title_delimeter . "<strong>Host:</strong>" . htmlspecialchars($host_name);
        $title_delimeter = "-> ";
    }
    if (!empty($host_group_data_name)) {
        $title .= $title_delimeter . " {$host_group_data_name}";
        $title_delimeter = "-> ";
    }
    if (isset($_REQUEST["tree_id"])) {
        $nodeid = "tree_" . get_request_var_request("tree_id");
    }
    if (isset($_REQUEST["leaf_id"])) {
        $nodeid .= "_leaf_" . get_request_var_request("leaf_id");
    }
    if (isset($_REQUEST["host_group_data"])) {
        $type_id = explode(":", get_request_var_request("host_group_data"));
        if ($type_id[0] == "graph_template") {
            $nodeid .= "_hgd_gt_" . $type_id[1];
        } elseif ($type_id[0] == "data_query") {
            $nodeid .= "_hgd_dq_" . $type_id[1];
        } else {
            $nodeid .= "_hgd_dqi" . $type_id[1] . "_" . $type_id[2];
        }
    }
    print "<script type=\"text/javascript\">\n";
    print "<!--\n";
    print "myNode = findObj(\"{$nodeid}\")\n";
    print "myNode.forceOpeningOfAncestorFolders();\n";
    print "highlightObjLink(myNode)\n";
    print "//-->\n";
    print "</script>";
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_post("graphs"));
    input_validate_input_number(get_request_var_post("page"));
    /* ==================================================== */
    /* clean up search string */
    if (isset($_REQUEST["filter"])) {
        $_REQUEST["filter"] = sanitize_search_string(get_request_var_post("filter"));
    }
    /* clean up search string */
    if (isset($_REQUEST["thumbnails"])) {
        $_REQUEST["thumbnails"] = sanitize_search_string(get_request_var_post("thumbnails"));
    }
    /* if the user pushed the 'clear' button */
    if (isset($_POST["clear_x"])) {
        kill_session_var("sess_graph_view_graphs");
        kill_session_var("sess_graph_view_filter");
        kill_session_var("sess_graph_view_thumbnails");
        kill_session_var("sess_graph_view_page");
        unset($_POST["graphs"]);
        unset($_REQUEST["graphs"]);
        unset($_POST["filter"]);
        unset($_REQUEST["filter"]);
        unset($_REQUEST["page"]);
        unset($_POST["thumbnails"]);
        unset($_REQUEST["thumbnails"]);
        $changed = true;
    } else {
        /* if any of the settings changed, reset the page number */
        $changed = 0;
        $changed += check_changed("graphs", "sess_graph_view_graphs");
        $changed += check_changed("filter", "sess_graph_view_filter");
        $changed += check_changed("action", "sess_graph_view_action");
    }
    if (isset($_SESSION["sess_graph_view_tree_id"])) {
        if ($_SESSION["sess_graph_view_tree_id"] != $tree_id) {
            $changed += 1;
        }
    }
    $_SESSION["sess_graph_view_tree_id"] = $tree_id;
    if (isset($_SESSION["sess_graph_view_leaf_id"])) {
        if ($_SESSION["sess_graph_view_leaf_id"] != $leaf_id) {
            $changed += 1;
        }
    }
    $_SESSION["sess_graph_view_leaf_id"] = $leaf_id;
    if (isset($_SESSION["sess_graph_view_host_group_data"])) {
        if ($_SESSION["sess_graph_view_host_group_data"] != $host_group_data) {
            $changed += 1;
        }
    }
    $_SESSION["sess_graph_view_host_group_data"] = $host_group_data;
    if ($changed) {
        $_REQUEST["page"] = 1;
    }
    load_current_session_value("page", "sess_graph_view_page", "1");
    load_current_session_value("graphs", "sess_graph_view_graphs", read_graph_config_option("treeview_graphs_per_page"));
    load_current_session_value("filter", "sess_graph_view_filter", "");
    if (isset($_SESSION["sess_graph_view_thumbnails"])) {
        if ($_SESSION["sess_graph_view_thumbnails"] == "on") {
            if (isset($_POST["filter"])) {
                if (!isset($_POST["thumbnails"])) {
                    $_SESSION["sess_graph_view_thumbnails"] = 'off';
                }
            }
        } else {
            if (isset($_POST["thumbnails"])) {
                $_SESSION["sess_graph_view_thumbnails"] = 'on';
            }
        }
    } else {
        $_SESSION["sess_graph_view_thumbnails"] = read_graph_config_option("thumbnail_section_tree_2");
        if ($_SESSION["sess_graph_view_thumbnails"] == '') {
            $_SESSION["sess_graph_view_thumbnails"] = 'off';
        } else {
            $_SESSION["sess_graph_view_thumbnails"] = 'on';
        }
    }
    html_start_box("<strong>Graph Filters</strong>", "100%", $colors["header"], "3", "center", "");
    /* include time span selector */
    if (read_graph_config_option("timespan_sel") == "on") {
        ?>
		<tr bgcolor="#<?php 
        print $colors["panel"];
        ?>
" class="noprint">
			<td class="noprint">
			<form style="margin:0px;padding:0px;" name="form_timespan_selector" method="post" action="graph_view.php">
				<table cellpadding="0" cellspacing="0">
					<tr>
						<td nowrap style='white-space: nowrap;'>
							&nbsp;<strong>Presets:</strong>&nbsp;
						</td>
						<td nowrap style='white-space: nowrap;'>
							<select name='predefined_timespan' onChange="applyTimespanFilterChange(document.form_timespan_selector)">
								<?php 
        if (isset($_SESSION["custom"])) {
            $graph_timespans[GT_CUSTOM] = "Custom";
            $start_val = 0;
            $end_val = sizeof($graph_timespans);
        } else {
            if (isset($graph_timespans[GT_CUSTOM])) {
                asort($graph_timespans);
                array_shift($graph_timespans);
            }
            $start_val = 1;
            $end_val = sizeof($graph_timespans) + 1;
        }
        if (sizeof($graph_timespans) > 0) {
            for ($value = $start_val; $value < $end_val; $value++) {
                print "<option value='{$value}'";
                if ($_SESSION["sess_current_timespan"] == $value) {
                    print " selected";
                }
                print ">" . title_trim($graph_timespans[$value], 40) . "</option>\n";
            }
        }
        ?>
							</select>
						</td>
						<td nowrap style='white-space: nowrap;'>
							&nbsp;<strong>From:</strong>&nbsp;
						</td>
						<td nowrap style='white-space: nowrap;'>
							<input type='text' name='date1' id='date1' title='Graph Begin Timestamp' size='15' value='<?php 
        print isset($_SESSION["sess_current_date1"]) ? $_SESSION["sess_current_date1"] : "";
        ?>
'>
						</td>
						<td nowrap style='white-space: nowrap;'>
							&nbsp;<input type='image' src='images/calendar.gif' align='middle' alt='Start date selector' title='Start date selector' onclick="return showCalendar('date1');">
						</td>
						<td nowrap style='white-space: nowrap;'>
							&nbsp;<strong>To:</strong>&nbsp;
						</td>
						<td nowrap style='white-space: nowrap;'>
							<input type='text' name='date2' id='date2' title='Graph End Timestamp' size='15' value='<?php 
        print isset($_SESSION["sess_current_date2"]) ? $_SESSION["sess_current_date2"] : "";
        ?>
'>
						</td>
						<td nowrap style='white-space: nowrap;'>
							&nbsp;<input type='image' src='images/calendar.gif' align='middle' alt='End date selector' title='End date selector' onclick="return showCalendar('date2');">
						</td>
						<td nowrap style='white-space: nowrap;'>
							&nbsp;<input type='image' name='move_left' src='images/move_left.gif' align='middle' alt='Left' title='Shift Left'>
						</td>
						<td nowrap style='white-space: nowrap;'>
							&nbsp;<select name='predefined_timeshift' title='Define Shifting Interval' onChange="applyTimespanFilterChange(document.form_timespan_selector)">
								<?php 
        $start_val = 1;
        $end_val = sizeof($graph_timeshifts) + 1;
        if (sizeof($graph_timeshifts) > 0) {
            for ($shift_value = $start_val; $shift_value < $end_val; $shift_value++) {
                print "<option value='{$shift_value}'";
                if ($_SESSION["sess_current_timeshift"] == $shift_value) {
                    print " selected";
                }
                print ">" . title_trim($graph_timeshifts[$shift_value], 40) . "</option>\n";
            }
        }
        ?>
							</select>
						</td>
						<td nowrap style='white-space: nowrap;'>
							&nbsp;<input type='image' name='move_right' src='images/move_right.gif' align='middle' alt='Right' title='Shift Right'>
						</td>
						<td nowrap style='white-space: nowrap;'>
							&nbsp;<input type='submit' name='button_refresh_x' value='Refresh' title='Refresh selected time span'>
						</td>
						<td nowrap style='white-space: nowrap;'>
							<input type='submit' name='button_clear_x' value='Clear' title='Return to the default time span'>
						</td>
					</tr>
				</table>
			</form>
			</td>
		</tr>
		<?php 
    }
    ?>
	<tr class="noprint" bgcolor="#e5e5e5">
		<td class="noprint">
		<form style="margin:0px;padding:0px;" name="form_graph_view" method="post">
			<table cellspacing="0" cellpadding="0">
				<tr>
					<td width="55" nowrap="" style="white-space: nowrap;">
						<strong>&nbsp;Search:</strong>&nbsp;
					</td>
					<td width="130" nowrap="" style="white-space: nowrap;">
						<input size='30' name='filter' value='<?php 
    print htmlspecialchars(get_request_var_request("filter"));
    ?>
'>
					</td>
					<td nowrap style='white-space:nowrap;' width="110">
						&nbsp;<strong>Graphs per Page:</strong>&nbsp;
					</td>
					<td width="1">
						<select name="graphs" id="graphs" onChange="submit()">
							<?php 
    if (sizeof($graphs_per_page) > 0) {
        foreach ($graphs_per_page as $key => $value) {
            print "<option value='" . $key . "'";
            if (get_request_var_request("graphs") == $key) {
                print " selected";
            }
            print ">" . $value . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td width="40">
						<label for="thumbnails"><strong>&nbsp;Thumbnails:&nbsp;</strong></label>
					</td>
					<td>
						<input type="checkbox" name="thumbnails" onClick="submit()" <?php 
    print $_SESSION['sess_graph_view_thumbnails'] == "on" ? "checked" : "";
    ?>
>
					</td>
					<td style='white-space:nowrap;' nowrap>
						&nbsp;<input type="submit" value="Go" title="Set/Refresh Filter">
						<input type="submit" name="clear_x" value="Clear" title="Clear Filters">
					</td>
				</tr>
			</table>
		</form>
		</td>
	</tr>
	<?php 
    html_end_box();
    api_plugin_hook_function('graph_tree_page_buttons', array('treeid' => $tree_id, 'leafid' => $leaf_id, 'mode' => 'tree', 'timespan' => $_SESSION["sess_current_timespan"], 'starttime' => get_current_graph_start(), 'endtime' => get_current_graph_end()));
    html_start_box("", "100%", $colors["header"], "3", "center", "");
    $graph_list = array();
    if ($leaf_type == "header" || empty($leaf_id)) {
        if (strlen(get_request_var_request("filter"))) {
            $sql_where = empty($sql_where) ? "" : "AND (title_cache LIKE '%" . get_request_var_request("filter") . "%' OR graph_templates_graph.title LIKE '%" . get_request_var_request("filter") . "%')";
        }
        /* modify for multi user start */
        $graph_list = db_fetch_assoc("SELECT\r\n\t\t\tgraph_tree_items.id,\r\n\t\t\tgraph_tree_items.title,\r\n\t\t\tgraph_tree_items.local_graph_id,\r\n\t\t\tgraph_tree_items.rra_id,\r\n\t\t\tgraph_tree_items.order_key,\r\n\t\t\tgraph_templates_graph.height,\r\n\t\t\tgraph_templates_graph.title_cache as title_cache\r\n\t\t\tFROM (graph_tree_items,graph_local)\r\n\t\t\tLEFT JOIN graph_templates_graph ON (graph_tree_items.local_graph_id=graph_templates_graph.local_graph_id AND graph_tree_items.local_graph_id>0)\r\n\t\t\t{$sql_join}\r\n\t\t\tWHERE graph_tree_items.graph_tree_id={$tree_id}\r\n\t\t\tAND graph_local.id=graph_templates_graph.local_graph_id\r\n\t\t\tAND graph_tree_items.order_key like '{$search_key}" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', MAX_TREE_DEPTH * CHARS_PER_TIER - (strlen($search_key) + CHARS_PER_TIER)) . "'\r\n\t\t\tAND graph_tree_items.local_graph_id>0\r\n\t\t\t{$sql_where}\r\n\t\t\tGROUP BY graph_tree_items.id\r\n\t\t\tORDER BY {$sql_order}");
        /* modify for multi user end */
    } elseif ($leaf_type == "host") {
        /* graph template grouping */
        if ($leaf["host_grouping_type"] == HOST_GROUPING_GRAPH_TEMPLATE) {
            $graph_templates = db_fetch_assoc("SELECT\r\n\t\t\t\tgraph_templates.id,\r\n\t\t\t\tgraph_templates.name\r\n\t\t\t\tFROM (graph_local,graph_templates,graph_templates_graph)\r\n\t\t\t\tWHERE graph_local.id=graph_templates_graph.local_graph_id\r\n\t\t\t\tAND graph_templates_graph.graph_template_id=graph_templates.id\r\n\t\t\t\tAND graph_local.host_id=" . $leaf["host_id"] . "\r\n\t\t\t\t" . (empty($graph_template_id) ? "" : "AND graph_templates.id={$graph_template_id}") . "\r\n\t\t\t\tGROUP BY graph_templates.id\r\n\t\t\t\tORDER BY graph_templates.name");
            /* for graphs without a template */
            array_push($graph_templates, array("id" => "0", "name" => "(No Graph Template)"));
            if (sizeof($graph_templates) > 0) {
                foreach ($graph_templates as $graph_template) {
                    if (strlen(get_request_var_request("filter"))) {
                        $sql_where = empty($sql_where) ? "" : "AND (title_cache LIKE '%" . get_request_var_request("filter") . "%')";
                    }
                    $graphs = db_fetch_assoc("SELECT DISTINCT\r\n\t\t\t\t\tgraph_templates_graph.title_cache,\r\n\t\t\t\t\tgraph_templates_graph.local_graph_id,\r\n\t\t\t\t\tgraph_templates_graph.height\r\n\t\t\t\t\tFROM (graph_local,graph_templates_graph)\r\n\t\t\t\t\t{$sql_join}\r\n\t\t\t\t\tWHERE graph_local.id=graph_templates_graph.local_graph_id\r\n\t\t\t\t\tAND graph_local.graph_template_id=" . $graph_template["id"] . "\r\n\t\t\t\t\tAND graph_local.host_id=" . $leaf["host_id"] . "\r\n\t\t\t\t\t{$sql_where}\r\n\t\t\t\t\tORDER BY graph_templates_graph.title_cache");
                    /* let's sort the graphs naturally */
                    usort($graphs, 'naturally_sort_graphs');
                    if (sizeof($graphs)) {
                        foreach ($graphs as $graph) {
                            $graph["graph_template_name"] = $graph_template["name"];
                            array_push($graph_list, $graph);
                        }
                    }
                }
            }
            /* data query index grouping */
        } elseif ($leaf["host_grouping_type"] == HOST_GROUPING_DATA_QUERY_INDEX) {
            $data_queries = db_fetch_assoc("SELECT\r\n\t\t\t\tsnmp_query.id,\r\n\t\t\t\tsnmp_query.name\r\n\t\t\t\tFROM (graph_local,snmp_query)\r\n\t\t\t\tWHERE graph_local.snmp_query_id=snmp_query.id\r\n\t\t\t\tAND graph_local.host_id=" . $leaf["host_id"] . "\r\n\t\t\t\t" . (!isset($data_query_id) ? "" : "and snmp_query.id={$data_query_id}") . "\r\n\t\t\t\tGROUP BY snmp_query.id\r\n\t\t\t\tORDER BY snmp_query.name");
            /* for graphs without a data query */
            if (empty($data_query_id)) {
                array_push($data_queries, array("id" => "0", "name" => "Non Query Based"));
            }
            if (sizeof($data_queries) > 0) {
                foreach ($data_queries as $data_query) {
                    /* fetch a list of field names that are sorted by the preferred sort field */
                    $sort_field_data = get_formatted_data_query_indexes($leaf["host_id"], $data_query["id"]);
                    if (strlen(get_request_var_request("filter"))) {
                        $sql_where = empty($sql_where) ? "" : "AND (title_cache LIKE '%" . get_request_var_request("filter") . "%')";
                    }
                    /* grab a list of all graphs for this host/data query combination */
                    $graphs = db_fetch_assoc("SELECT\r\n\t\t\t\t\tgraph_templates_graph.title_cache,\r\n\t\t\t\t\tgraph_templates_graph.local_graph_id,\r\n\t\t\t\t\tgraph_templates_graph.height,\r\n\t\t\t\t\tgraph_local.snmp_index\r\n\t\t\t\t\tFROM (graph_local, graph_templates_graph)\r\n\t\t\t\t\t{$sql_join}\r\n\t\t\t\t\tWHERE graph_local.id=graph_templates_graph.local_graph_id\r\n\t\t\t\t\tAND graph_local.snmp_query_id=" . $data_query["id"] . "\r\n\t\t\t\t\tAND graph_local.host_id=" . $leaf["host_id"] . "\r\n\t\t\t\t\t" . (empty($data_query_index) ? "" : "and graph_local.snmp_index='{$data_query_index}'") . "\r\n\t\t\t\t\t{$sql_where}\r\n\t\t\t\t\tGROUP BY graph_templates_graph.local_graph_id\r\n\t\t\t\t\tORDER BY graph_templates_graph.title_cache");
                    /* re-key the results on data query index */
                    if (sizeof($graphs) > 0) {
                        /* let's sort the graphs naturally */
                        usort($graphs, 'naturally_sort_graphs');
                        foreach ($graphs as $graph) {
                            $snmp_index_to_graph[$graph["snmp_index"]][$graph["local_graph_id"]] = $graph["title_cache"];
                            $graphs_height[$graph["local_graph_id"]] = $graph["height"];
                        }
                    }
                    /* using the sorted data as they key; grab each snmp index from the master list */
                    while (list($snmp_index, $sort_field_value) = each($sort_field_data)) {
                        /* render each graph for the current data query index */
                        if (isset($snmp_index_to_graph[$snmp_index])) {
                            while (list($local_graph_id, $graph_title) = each($snmp_index_to_graph[$snmp_index])) {
                                /* reformat the array so it's compatable with the html_graph* area functions */
                                array_push($graph_list, array("data_query_name" => $data_query["name"], "sort_field_value" => $sort_field_value, "local_graph_id" => $local_graph_id, "title_cache" => $graph_title, "height" => $graphs_height[$graph["local_graph_id"]]));
                            }
                        }
                    }
                }
            }
        }
    }
    $total_rows = sizeof($graph_list);
    /* generate page list */
    if ($total_rows > get_request_var_request("graphs")) {
        $url_page_select = get_page_list(get_request_var_request("page"), MAX_DISPLAY_PAGES, get_request_var_request("graphs"), $total_rows, "graph_view.php?action=tree&tree_id=" . $tree_id . "&leaf_id=" . $leaf_id . (isset($_REQUEST["host_group_data"]) ? "&host_group_data=" . get_request_var_request("host_group_data") : ""));
        $nav = "<tr bgcolor='#" . $colors["header"] . "'>\r\n\t\t\t\t<td colspan='11'>\r\n\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<td align='left' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\t<strong>&lt;&lt; ";
        if (get_request_var_request("page") > 1) {
            $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("graph_view.php?action=tree&tree_id=" . $tree_id . "&leaf_id=" . $leaf_id . (isset($_REQUEST["host_group_data"]) ? "&host_group_data=" . get_request_var_request("host_group_data") : "") . "&page=" . (get_request_var_request("page") - 1)) . "'>";
        }
        $nav .= "Previous";
        if (get_request_var_request("page") > 1) {
            $nav .= "</a>";
        }
        $nav .= "</strong>\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\tShowing Graphs " . (get_request_var_request("graphs") * (get_request_var_request("page") - 1) + 1) . " to " . ($total_rows < read_graph_config_option("treeview_graphs_per_page") || $total_rows < get_request_var_request("graphs") * get_request_var_request("page") ? $total_rows : get_request_var_request("graphs") * get_request_var_request("page")) . " of {$total_rows} [{$url_page_select}]\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t\t<td align='right' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\t<strong>";
        if (get_request_var_request("page") * get_request_var_request("graphs") < $total_rows) {
            $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("graph_view.php?action=tree&tree_id=" . $tree_id . "&leaf_id=" . $leaf_id . (isset($_REQUEST["host_group_data"]) ? "&host_group_data=" . get_request_var_request("host_group_data") : "") . "&page=" . (get_request_var_request("page") + 1)) . "'>";
        }
        $nav .= "Next";
        if (get_request_var_request("page") * get_request_var_request("graphs") < $total_rows) {
            $nav .= "</a>";
        }
        $nav .= " &gt;&gt;</strong>\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t</table>\r\n\t\t\t\t</td>\r\n\t\t\t</tr>\n";
    } else {
        $nav = "<tr bgcolor='#" . $colors["header"] . "'>\r\n\t\t\t\t<td colspan='11'>\r\n\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\tShowing All Graphs" . (strlen(get_request_var_request("filter")) ? " [ Filter '" . htmlspecialchars(get_request_var_request("filter")) . "' Applied ]" : "") . "\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t</table>\r\n\t\t\t\t</td>\r\n\t\t\t</tr>\n";
    }
    print $nav;
    /* start graph display */
    print "<tr bgcolor='#" . $colors["header_panel"] . "'><td width='390' colspan='11' class='textHeaderDark'>{$title}</td></tr>";
    $i = get_request_var_request("graphs") * (get_request_var_request("page") - 1);
    $last_graph = $i + get_request_var_request("graphs");
    $new_graph_list = array();
    while ($i < $total_rows && $i < $last_graph) {
        $new_graph_list[] = $graph_list[$i];
        $i++;
    }
    if ($_SESSION["sess_graph_view_thumbnails"] == "on") {
        html_graph_thumbnail_area($new_graph_list, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end());
    } else {
        html_graph_area($new_graph_list, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end());
    }
    if (!empty($leaf_id)) {
        api_plugin_hook_function('tree_after', $host_name . ',' . get_request_var("leaf_id"));
    }
    api_plugin_hook_function('tree_view_page_end');
    print $nav;
    html_end_box();
}
Ejemplo n.º 15
0
function get_graph_preview_content () {
	global $colors;
	require_once(CACTI_BASE_PATH . "/include/auth/auth_constants.php");

	/* Make sure nothing is cached */
	header("Cache-Control: must-revalidate");
	header("Cache-Control: post-check=0, pre-check=0", false);
	header("Pragma: no-cache");
	header("Expires: ". gmdate("D, d M Y H:i:s", mktime(date("H"), date("i"), date("s"), date("m")-1, date("d"), date("Y")))." GMT");
	header("Last-Modified: ". gmdate("D, d M Y H:i:s")." GMT");

	$current_user = db_fetch_row("SELECT * FROM user_auth WHERE id=" . $_SESSION["sess_user_id"]);

	define("MAX_DISPLAY_PAGES", 21);

	/* ================= input validation ================= */
	input_validate_input_number(get_request_var("graphs"));
	input_validate_input_number(get_request_var_request("device_id"));
	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 search string */
	if (isset($_REQUEST["thumbnails"])) {
		$_REQUEST["thumbnails"] = sanitize_search_string(get_request_var_request("thumbnails"));
	}

	$sql_or = ""; $sql_where = ""; $sql_join = "";

	if ((read_config_option("auth_method") != 0) && (empty($current_user["show_preview"]))) {
		print "<strong><font size='+1' color='FF0000'>" . __("YOU DO NOT HAVE RIGHTS FOR PREVIEW VIEW") . "</font></strong>"; exit;
	}

	/* if the user pushed the 'clear' button */
	if (isset($_REQUEST["clear_filter"])) {
		kill_session_var("sess_graph_view_current_page");
		kill_session_var("sess_graph_view_filter");
		kill_session_var("sess_graph_view_graph_template");
		kill_session_var("sess_graph_view_device");
		kill_session_var("sess_graph_view_graphs");
		kill_session_var("sess_graph_view_thumbnails");
		kill_session_var("sess_graph_view_list_graph_list");
		kill_session_var("sess_graph_view_list_graph_add");
		kill_session_var("sess_graph_view_list_graph_remove");

		unset($_REQUEST["page"]);
		unset($_REQUEST["filter"]);
		unset($_REQUEST["device_id"]);
		unset($_REQUEST["graphs"]);
		unset($_REQUEST["thumbnails"]);
		unset($_REQUEST["graph_template_id"]);
		unset($_REQUEST["graph_list"]);
		unset($_REQUEST["graph_add"]);
		unset($_REQUEST["graph_remove"]);
	}

	/* save selected graphs into url, for backward compatibility */
	if (!empty($_REQUEST["graph_list"])) {
		foreach (explode(",",get_request_var_request("graph_list")) as $item) {
			$graph_list[$item] = 1;
		}
	}else{
		$graph_list = array();
	}

	load_current_session_value("device_id", "sess_graph_view_device", "0");
	load_current_session_value("graph_template_id", "sess_graph_view_graph_template", "0");
	load_current_session_value("filter", "sess_graph_view_filter", "");
	load_current_session_value("page", "sess_graph_view_current_page", "1");
	load_current_session_value("thumbnails", "sess_graph_view_thumbnails", CHECKED);
	load_current_session_value("graphs", "sess_graph_view_graphs", read_graph_config_option("preview_graphs_per_page"));
	load_current_session_value("graph_list", "sess_graph_view_list_graph_list", "");
	load_current_session_value("graph_add", "sess_graph_view_list_graph_add", "");
	load_current_session_value("graph_remove", "sess_graph_view_list_graph_remove", "");

	/* graph permissions */
	if (read_config_option("auth_method") != 0) {
		$sql_where = "where " . get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_devices"], $current_user["policy_graph_templates"]);

		$sql_join = "left join device on (device.id=graph_local.device_id)
			left join graph_templates on (graph_templates.id=graph_local.graph_template_id)
			left join user_auth_perms on ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=" . PERM_GRAPHS . " and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (device.id=user_auth_perms.item_id and user_auth_perms.type=" . PERM_DEVICES . " and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_templates.id=user_auth_perms.item_id and user_auth_perms.type=" . PERM_GRAPH_TEMPLATES . " 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["list"])) {
		if (is_array(get_request_var_request("graph_list"))) {
			$graph_list = $_REQUEST["graph_list"];
		}

		if (!empty($_REQUEST["graph_add"])) {
			foreach (explode(",",get_request_var_request("graph_add")) as $item) {
				$graph_list[$item] = 1;
			}
		}
		/* remove items */
		if (!empty($_REQUEST["graph_remove"])) {
			foreach (explode(",",get_request_var_request("graph_remove")) as $item) {
				unset($graph_list[$item]);
			}
		}
		$_SESSION["sess_graph_view_list_graph_list"] = $graph_list;

		$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["device_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
		AND graph_templates_graph.local_graph_id=graph_local.id
		AND graph_templates_graph.title_cache like '%%" . get_request_var_request("filter") . "%%'
		" . (empty($_REQUEST["device_id"]) ? "" : " and graph_local.device_id=" . $_REQUEST["device_id"]) . "
		" . (empty($_REQUEST["graph_template_id"]) ? "" : " and graph_local.graph_template_id=" . $_REQUEST["graph_template_id"]) . "
		$sql_or";

	$total_rows = count(db_fetch_assoc("SELECT
		graph_templates_graph.local_graph_id
		$sql_base"));

	/* reset the page if you have changed some settings */
	if ($_REQUEST["graphs"] * ($_REQUEST["page"]-1) >= $total_rows) {
		$_REQUEST["page"] = "1";
	}

	$graphs = db_fetch_assoc("SELECT
		graph_templates_graph.local_graph_id,
		graph_templates_graph.title_cache,
		graph_templates_graph.image_format_id
		$sql_base
		GROUP BY graph_templates_graph.local_graph_id
		ORDER BY graph_templates_graph.title_cache
		LIMIT " . (get_request_var_request("graphs")*(get_request_var_request("page")-1)) . "," . get_request_var_request("graphs"));

	/* include graph view filter selector */
	graph_view_filter_table("preview");

	/* include time span selector */
	if (read_graph_config_option("timespan_sel") == CHECKED) {
		graph_view_timespan_selector("preview");
	}

	?>
	<script type='text/javascript'>
	<!--
	function pageChange(page) {
		strURL = '?action=ajax_preview&page=' + page;
		$.get("graph_view.php" + strURL, function (data) {
			$("#graph_content").html(data);
		});
	}
	//-->
	</script>
	<?php

	html_start_box("", "100", $colors["header"], "0", "center", "");

	print "<table cellpadding='0' cellspacing='0' style='width:100%;border:1px solid #BEBEBE;'>\n";
	/* generate page list */

	if ($total_rows > get_request_var_request("graphs")) {
		$url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, $_REQUEST["graphs"], $total_rows, "pageChange");

		$nav = "\t\t\t<tr class='rowHeader'>
				<td colspan='11'>
					<table width='100%' cellspacing='0' cellpadding='0' border='0'>
						<tr>
							<td align='left' style='width:100px;' class='textHeaderDark'>";
		if ($_REQUEST["page"] > 1) { $nav .= "<strong><a class='linkOverDark' href='#' onClick='pageChange(" . ($_REQUEST["page"]-1) . ")'>&lt;&lt;&nbsp;" . __("Previous") . "</a></strong>"; }
		$nav .= "</td>\n
							<td align='center' class='textHeaderDark'>
								" . __("Showing Graphs") . ((get_request_var_request("graphs")*(get_request_var_request("page")-1))+1) . " " . __("to") . " " . ((($total_rows < get_request_var_request("graphs")) || ($total_rows < (get_request_var_request("graphs")*get_request_var_request("page")))) ? $total_rows : (get_request_var_request("graphs")*get_request_var_request("page"))) . " " . __("of") . " $total_rows [$url_page_select]
							</td>\n
							<td align='right' style='width:100px;' class='textHeaderDark'>";
		if (($_REQUEST["page"] * $_REQUEST["graphs"]) < $total_rows) { $nav .= "<strong><a class='linkOverDark' href='#' onClick='pageChange(" . ($_REQUEST["page"]+1) . ")'>" . __("Next") . "&gt;&gt;</a></strong>"; }
		$nav .= "</td>\n
						</tr>
					</table>
				</td>
			</tr>\n";
	}else{
		$nav = "<tr class='rowHeader'>
				<td colspan='11'>
					<table width='100%' cellspacing='0' cellpadding='0' border='0'>
						<tr>
							<td align='center' class='textHeaderDark'>
								" . __("Showing All Graphs") . (strlen(get_request_var_request("filter")) ? " [ " . __("Filter") . " '" . get_request_var_request("filter") . "' " . __("Applied") . " ]" : "") . "
							</td>
						</tr>
					</table>
				</td>
			</tr>\n";
	}

	print $nav;

	if (read_graph_config_option("thumbnail_section_preview") == CHECKED) {
		html_graph_thumbnail_area($graphs, "","graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end());
	}else{
		html_graph_area($graphs, "", "graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end());
	}

	print $nav;

	html_graph_end_box();
}
Ejemplo n.º 16
0
function thold_show_log()
{
    global $config, $colors, $item_rows;
    $thold_log = array('Alarm' => 'F21924', 'Warning' => 'FB4A14', 'Re-Trigger' => 'FF7A30', 'Alert Trigger' => 'FAFD9E', 'Warn Trigger' => 'FAFD9E', 'Restoral' => 'CCFFCC', 'Restore' => 'CDCFC4', 'Alarm2Warn' => 'FACD6E');
    $thold_status = array('0' => 'Restore', '1' => 'Alert Trigger', '2' => 'Re-Trigger', '3' => 'Warning', '4' => 'Alarm', '5' => 'Restoral', '6' => 'Warn Trigger', '7' => 'Alarm-Warn');
    $types = array('High/Low', 'Baseline Deviation', 'Time Based');
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request("threshold_id"));
    input_validate_input_number(get_request_var_request("host_id"));
    input_validate_input_number(get_request_var_request("page"));
    input_validate_input_number(get_request_var_request("status"));
    input_validate_input_number(get_request_var_request("rows"));
    /* ==================================================== */
    /* clean up search string */
    if (isset($_REQUEST["filter"])) {
        $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter"));
    }
    /* clean up sort_column */
    if (isset($_REQUEST["sort_column"])) {
        $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column"));
    }
    /* clean up search string */
    if (isset($_REQUEST["sort_direction"])) {
        $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction"));
    }
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST["clear"])) {
        kill_session_var("sess_thold_log_current_page");
        kill_session_var("sess_thold_log_filter");
        kill_session_var("sess_thold_log_threshold_id");
        kill_session_var("sess_thold_log_host_id");
        kill_session_var("sess_thold_log_status");
        kill_session_var("sess_thold_log_rows");
        kill_session_var("sess_thold_log_sort_column");
        kill_session_var("sess_thold_log_sort_direction");
        unset($_REQUEST["page"]);
        unset($_REQUEST["filter"]);
        unset($_REQUEST["host_id"]);
        unset($_REQUEST["threshold_id"]);
        unset($_REQUEST["status"]);
        unset($_REQUEST["rows"]);
        unset($_REQUEST["sort_column"]);
        unset($_REQUEST["sort_direction"]);
    } else {
        /* if any of the settings changed, reset the page number */
        $changed = 0;
        $changed += thold_request_check_changed('filter', 'sess_thold_log_filter');
        $changed += thold_request_check_changed('threshold_id', 'sess_thold_log_threshold_id');
        $changed += thold_request_check_changed('host_id', 'sess_thold_log_host_id');
        $changed += thold_request_check_changed('status', 'sess_thold_log_status');
        $changed += thold_request_check_changed('rows', 'sess_thold_log_rows');
        $changed += thold_request_check_changed('sort_column', 'sess_thold_log_sort_column');
        $changed += thold_request_check_changed('sort_direction', 'sess_thold_log_sort_direction');
        if ($changed) {
            $_REQUEST['page'] = '1';
        }
    }
    /* remember these search fields in session vars so we don't have to keep passing them around */
    load_current_session_value("page", "sess_thold_log_current_page", "1");
    load_current_session_value("filter", "sess_thold_log_filter", "");
    load_current_session_value("threshold_id", "sess_thold_log_threshold_id", "-1");
    load_current_session_value("host_id", "sess_thold_log_host_id", "-1");
    load_current_session_value("status", "sess_thold_log_status", "-1");
    load_current_session_value("rows", "sess_thold_log_rows", read_config_option("num_rows_device"));
    load_current_session_value("sort_column", "sess_thold_log_sort_column", "time");
    load_current_session_value("sort_direction", "sess_thold_log_sort_direction", "DESC");
    /* if the number of rows is -1, set it to the default */
    if ($_REQUEST["rows"] == -1) {
        $_REQUEST["rows"] = read_config_option("num_rows_device");
    }
    ?>
	<script type="text/javascript">
	<!--
	function filterChange(objForm) {
		strURL = '?tab=log&status=' + objForm.status.value;
		strURL = strURL + '&threshold_id=' + objForm.threshold_id.value;
		strURL = strURL + '&host_id=' + objForm.host_id.value;
		strURL = strURL + '&rows=' + objForm.rows.value;
		strURL = strURL + '&filter=' + objForm.filter.value;
		document.location = strURL;
	}
	-->
	</script>
	<?php 
    html_start_box("<strong>Threshold Log</strong> [last 30 days]", "100%", $colors["header"], "3", "center", "");
    form_thold_log_filter();
    html_end_box();
    $sql_where = '';
    if ($_REQUEST["host_id"] == "-1") {
        /* Show all items */
    } elseif ($_REQUEST["host_id"] == "0") {
        $sql_where .= (strlen($sql_where) ? " AND" : "WHERE") . " host.id IS NULL";
    } elseif (!empty($_REQUEST["host_id"])) {
        $sql_where .= (strlen($sql_where) ? " AND" : "WHERE") . " plugin_thold_log.host_id=" . $_REQUEST["host_id"];
    }
    if ($_REQUEST["threshold_id"] == "-1") {
        /* Show all items */
    } elseif ($_REQUEST["threshold_id"] == "0") {
        $sql_where .= (strlen($sql_where) ? " AND" : "WHERE") . " thold_data.id IS NULL";
    } elseif (!empty($_REQUEST["threshold_id"])) {
        $sql_where .= (strlen($sql_where) ? " AND" : "WHERE") . " plugin_thold_log.threshold_id=" . $_REQUEST["threshold_id"];
    }
    if ($_REQUEST["status"] == "-1") {
        /* Show all items */
    } else {
        $sql_where .= (strlen($sql_where) ? " AND" : "WHERE") . " plugin_thold_log.status=" . $_REQUEST["status"];
    }
    if (strlen($_REQUEST["filter"])) {
        $sql_where .= (strlen($sql_where) ? " AND" : "WHERE") . " plugin_thold_log.description LIKE '%" . $_REQUEST["filter"] . "%'";
    }
    html_start_box("", "100%", $colors["header"], "3", "center", "");
    $sortby = $_REQUEST["sort_column"];
    $current_user = db_fetch_row('SELECT * FROM user_auth WHERE id=' . $_SESSION['sess_user_id']);
    $sql_where .= ' AND ' . get_graph_permissions_sql($current_user['policy_graphs'], $current_user['policy_hosts'], $current_user['policy_graph_templates']);
    $total_rows = db_fetch_cell("SELECT\r\n\t\tCOUNT(*)\r\n\t\tFROM plugin_thold_log\r\n\t\tLEFT JOIN host ON plugin_thold_log.host_id=host.id\r\n\t\tLEFT JOIN thold_data ON plugin_thold_log.threshold_id=thold_data.id\r\n\t\tLEFT JOIN graph_templates_graph AS gtg ON plugin_thold_log.graph_id=gtg.local_graph_id\r\n\t\tLEFT JOIN user_auth_perms\r\n\t\tON (host.id=user_auth_perms.item_id\r\n\t\tAND user_auth_perms.type=3\r\n\t\tAND user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . ")\r\n\t\t{$sql_where}");
    $sql_query = "SELECT plugin_thold_log.*, host.description AS hdescription, thold_data.name AS name, gtg.title_cache\r\n\t\tFROM plugin_thold_log\r\n\t\tLEFT JOIN host ON plugin_thold_log.host_id=host.id\r\n\t\tLEFT JOIN thold_data ON plugin_thold_log.threshold_id=thold_data.id\r\n\t\tLEFT JOIN graph_templates_graph AS gtg ON plugin_thold_log.graph_id=gtg.local_graph_id\r\n\t\tLEFT JOIN user_auth_perms\r\n\t\tON (host.id=user_auth_perms.item_id\r\n\t\tAND user_auth_perms.type=3\r\n\t\tAND user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . ")\r\n\t\t{$sql_where}\r\n\t\tORDER BY " . $sortby . " " . $_REQUEST["sort_direction"] . "\r\n\t\tLIMIT " . $_REQUEST["rows"] * ($_REQUEST["page"] - 1) . "," . $_REQUEST["rows"];
    //print $sql_query;
    $logs = db_fetch_assoc($sql_query);
    /* generate page list */
    $url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, $_REQUEST["rows"], $total_rows, "thold_graph.php?tab=log");
    if ($total_rows) {
        $nav = "<tr bgcolor='#" . $colors["header"] . "'>\r\n\t\t\t\t<td colspan='11'>\r\n\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<td align='left' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\t<strong>&lt;&lt; ";
        if ($_REQUEST["page"] > 1) {
            $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("thold_graph.php?tab=log&page=" . ($_REQUEST["page"] - 1)) . "'>";
        }
        $nav .= "Previous";
        if ($_REQUEST["page"] > 1) {
            $nav .= "</a>";
        }
        $nav .= "</strong>\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\tShowing Rows " . ($_REQUEST["rows"] * ($_REQUEST["page"] - 1) + 1) . " to " . ($total_rows < read_config_option("num_rows_device") || $total_rows < $_REQUEST["rows"] * $_REQUEST["page"] ? $total_rows : $_REQUEST["rows"] * $_REQUEST["page"]) . " of {$total_rows} [{$url_page_select}]\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t\t<td align='right' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\t<strong>";
        if ($_REQUEST["page"] * $_REQUEST["rows"] < $total_rows) {
            $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("thold_graph.php?tab=log&page=" . ($_REQUEST["page"] + 1)) . "'>";
        }
        $nav .= "Next";
        if ($_REQUEST["page"] * $_REQUEST["rows"] < $total_rows) {
            $nav .= "</a>";
        }
        $nav .= " &gt;&gt;</strong>\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t</table>\r\n\t\t\t\t</td>\r\n\t\t\t</tr>\n";
    } else {
        $nav = "<tr bgcolor='#" . $colors["header"] . "'>\r\n\t\t\t\t<td colspan='11'>\r\n\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\tNo Rows Found\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t</table>\r\n\t\t\t\t</td>\r\n\t\t\t</tr>\n";
    }
    print $nav;
    $display_text = array("hdescription" => array("<br>Host", "ASC"), "name" => array("<br>Threshold", "ASC"), "time" => array("<br>Time", "ASC"), "threshold_value" => array("Alarm<br>Value", "ASC"), "current" => array("Current<br>Value", "ASC"), "status" => array("<br>Status", "DESC"), "type" => array("<br>Type", "DESC"), "description" => array("<br>Event Description", "ASC"));
    html_header_sort($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"]);
    $i = 0;
    if (sizeof($logs)) {
        foreach ($logs as $l) {
            ?>
			<tr style='background-color:#<?php 
            print $thold_log[$thold_status[$l['status']]];
            ?>
'>
			<td style='white-space:nowrap;'><?php 
            print $l["hdescription"];
            ?>
</td>
			<td style='white-space:nowrap;'><?php 
            print $l["name"];
            ?>
</td>
			<td style='white-space:nowrap;'><?php 
            print date("Y-m-d H:i:s", $l["time"]);
            ?>
</td>
			<td><?php 
            print $l["threshold_value"] != '' ? thold_format_number($l["threshold_value"]) : 'N/A';
            ?>
</td>
			<td><?php 
            print $l["current"] != '' ? thold_format_number($l["current"]) : 'N/A';
            ?>
</td>
			<td nowrap style='white-space:nowrap;'><?php 
            print $thold_status[$l["status"]];
            ?>
</td>
			<td nowrap style='white-space:nowrap;'><?php 
            print $types[$l["type"]];
            ?>
</td>
			<td style='white-space:nowrap;'><?php 
            print strlen($l["description"]) ? $l["description"] : "Restoral Event";
            ?>
</td>
			<?php 
            form_end_row();
        }
    } else {
        print "<tr><td><em>No Threshold Logs Found</em></td></tr>";
    }
    /* put the nav bar on the bottom as well */
    print $nav;
    html_end_box(false);
    log_legend();
    //thold_display_rusage();
}
Ejemplo n.º 17
0
function is_graph_allowed($local_graph_id) {
	require_once(CACTI_BASE_PATH . "/include/auth/auth_constants.php");

	$current_user = db_fetch_row("select policy_graphs,policy_devices,policy_graph_templates from user_auth where id=" . $_SESSION["sess_user_id"]);

	/* get policy information for the sql where clause */
	$sql_where = get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_devices"], $current_user["policy_graph_templates"]);

	$graphs = db_fetch_assoc("select
		graph_templates_graph.local_graph_id
		from (graph_templates_graph,graph_local)
		left join device on (device.id=graph_local.device_id)
		left join graph_templates on (graph_templates.id=graph_local.graph_template_id)
		left join user_auth_perms on ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=" . PERM_GRAPHS . " and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (device.id=user_auth_perms.item_id and user_auth_perms.type=" . PERM_DEVICES . " and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_templates.id=user_auth_perms.item_id and user_auth_perms.type=" . PERM_GRAPH_TEMPLATES . " and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . "))
		where graph_templates_graph.local_graph_id=graph_local.id
		" . (empty($sql_where) ? "" : "and $sql_where") . "
		and graph_templates_graph.local_graph_id=$local_graph_id
		group by graph_templates_graph.local_graph_id");

	if (sizeof($graphs) > 0) {
		return true;
	}else{
		return false;
	}
}
Ejemplo n.º 18
0
function thold_add_select_host()
{
    global $colors, $config, $host, $graph, $ds;
    /* get policy information for the sql where clause */
    $current_user = db_fetch_row("SELECT * FROM user_auth WHERE id=" . $_SESSION["sess_user_id"]);
    $sql_where = get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]);
    $hosts = db_fetch_assoc("SELECT DISTINCT host.id, CONCAT_WS('',host.description,' (',host.hostname,')') AS name\r\n\t\tFROM (graph_templates_graph, host)\r\n\t\tLEFT JOIN graph_local ON (graph_local.host_id=host.id)\r\n\t\tLEFT JOIN graph_templates ON (graph_templates.id=graph_local.graph_template_id)\r\n\t\tLEFT JOIN user_auth_perms ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id AND user_auth_perms.type=1 AND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (host.id=user_auth_perms.item_id AND user_auth_perms.type=3 AND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_templates.id=user_auth_perms.item_id AND user_auth_perms.type=4 AND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . "))\r\n\t\tWHERE graph_templates_graph.local_graph_id=graph_local.id\r\n\t\t" . (empty($sql_where) ? "" : "AND {$sql_where}") . "\r\n\t\tORDER BY name");
    include $config['include_path'] . '/top_header.php';
    html_start_box('<strong>Threshold Creation Wizard</strong>', '50%', $colors['header'], '3', 'center', '');
    echo '<tr><td><form action="thold_add.php" method="post" name="tholdform">';
    if ($host == '') {
        print '<center><h3>Please select a Host</h3></center>';
    } else {
        if ($graph == '') {
            print '<center><h3>Please select a Graph</h3></center>';
        } else {
            if ($ds == '') {
                print '<center><h3>Please select a Data Source</h3></center>';
            } else {
                print '<center><h3>Please press "Create" to activate your Threshold</h3></center>';
            }
        }
    }
    /* display the host dropdown */
    ?>
	<center><table>
		<tr>
			<td width='70' style='white-space:nowrap;'>
				&nbsp;<b>Host:</b>
			</td>
			<td style='width:1;'>
				<select name=hostid onChange="applyTholdFilterChange(document.tholdform, 'host')">
					<option value=""></option><?php 
    foreach ($hosts as $row) {
        echo "<option value='" . $row['id'] . "'" . ($row['id'] == $host ? ' selected' : '') . '>' . $row['name'] . '</option>';
    }
    ?>
				</select>
			</td>
		</tr><?php 
    if ($host != '') {
        $graphs = db_fetch_assoc("SELECT\r\n\t\t\t\t\tgraph_templates_graph.id,\r\n\t\t\t\t\tgraph_templates_graph.local_graph_id,\r\n\t\t\t\t\tgraph_templates_graph.title_cache\r\n\t\t\t\t\tFROM (graph_templates_graph,graph_local)\r\n\t\t\t\t\tLEFT JOIN host ON (host.id=graph_local.host_id)\r\n\t\t\t\t\tLEFT JOIN graph_templates ON (graph_templates.id=graph_local.graph_template_id)\r\n\t\t\t\t\tLEFT JOIN user_auth_perms ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=1 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (host.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_templates.id=user_auth_perms.item_id and user_auth_perms.type=4 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . "))\r\n\t\t\t\t\tWHERE graph_templates_graph.local_graph_id=graph_local.id\r\n\t\t\t\t\tAND graph_templates.id IS NOT NULL\r\n\t\t\t\t\t" . (empty($sql_where) ? "" : "AND {$sql_where}") . "\r\n\t\t\t\t\tAND host.id = {$host}\r\n\t\t\t\t\tORDER BY title_cache");
        /* display the graphs dropdown */
        ?>
		<tr>
			<td width='70' style='white-space:nowrap;'>
				&nbsp;<b>Graph:</b>
			</td>
			<td>
				<select name=graphid onChange="applyTholdFilterChange(document.tholdform, 'graph')">
					<option value=""></option><?php 
        foreach ($graphs as $row) {
            echo "<option value='" . $row['local_graph_id'] . "'" . ($row['local_graph_id'] == $graph ? ' selected' : '') . '>' . $row['title_cache'] . '</option>';
        }
        ?>
				</select>
			</td>
		</tr><?php 
    } else {
        ?>
		<tr>
			<td>
				<input type=hidden name=graphid value="">
			</td>
		</tr><?php 
    }
    if ($graph != '') {
        $dt_sql = 'SELECT DISTINCT dtr.local_data_id
				FROM data_template_rrd AS dtr
				LEFT JOIN graph_templates_item AS gti
				ON gti.task_item_id=dtr.id
				LEFT JOIN graph_local AS gl
				ON gl.id=gti.local_graph_id
				WHERE gl.id = ' . $graph;
        $dt = db_fetch_cell($dt_sql);
        $dss = db_fetch_assoc('SELECT DISTINCT id, data_source_name
				FROM data_template_rrd
				WHERE local_data_id IN (' . $dt_sql . ') ORDER BY data_source_name');
        /* show the data source options */
        ?>
		<tr>
			<td width='70' style='white-space:nowrap;'>
				&nbsp;<b>Data Source:</b>
			</td>
			<td>
				<input type=hidden name=dt value="<?php 
        print $dt;
        ?>
">
				<select name=dsid onChange="applyTholdFilterChange(document.tholdform, 'ds')">
					<option value=""></option><?php 
        foreach ($dss as $row) {
            echo "<option value='" . $row['id'] . "'" . ($row['id'] == $ds ? ' selected' : '') . '>' . $row['data_source_name'] . '</option>';
        }
        ?>
				</select>
			</td>
		</tr><?php 
    } else {
        ?>
		<tr>
			<td>
				<input type=hidden name=dsid value="">
			</td>
		</tr><?php 
    }
    if ($ds != '') {
        echo '<tr><td colspan=2><input type=hidden name=save value="save"><br><center><input type="submit" value="Create" title="Create Threshold"></center></td></tr>';
    } else {
        echo '<tr><td colspan=2><br><br><br></td></tr>';
    }
    echo '</table></form></td></tr>';
    html_end_box();
    if ($graph != '') {
        print "<br><center><img id=graphi name=graphi src='../../graph_image.php?local_graph_id={$graph}&rra_id=0'><center><br><br>";
    }
}
Ejemplo n.º 19
0
function grow_right_pane_tree($tree_id, $leaf_id, $host_group_data) {
	global $current_user, $colors;

	require_once(CACTI_BASE_PATH . "/lib/data_query/data_query_info.php");
	require_once(CACTI_BASE_PATH . "/lib/graph_tree/graph_tree_utility.php");

	if (empty($tree_id)) { return; }

	$sql_where = "";
	$sql_join = "";
	$title = "";
	$title_delimiter = "";
	$search_key = "";

	$leaf = db_fetch_row("select order_key,title,host_id,host_grouping_type from graph_tree_items where id=$leaf_id");
	$leaf_type = get_tree_item_type($leaf_id);

	/* get the "starting leaf" if the user clicked on a specific branch */
	if (!empty($leaf_id)) {
		$search_key = substr($leaf["order_key"], 0, (api_graph_tree_item_depth_get($leaf["order_key"]) * CHARS_PER_TIER));
	}

	/* graph permissions */
	if (read_config_option("auth_method") != "0") {
		/* get policy information for the sql where clause */
		$sql_where = get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]);
		$sql_where = (empty($sql_where) ? "" : "and $sql_where");
		$sql_join = "
			left join host on (host.id=graph.host_id)
			left join graph_template on (graph_template.id=graph.graph_template_id)
			left join user_auth_perms on ((graph.id=user_auth_perms.item_id and user_auth_perms.type=1 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (host.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_template.id=user_auth_perms.item_id and user_auth_perms.type=4 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . "))";
	}

	/* get information for the headers */
	if (!empty($tree_id)) { $tree_name = db_fetch_cell("select name from graph_tree where id=$tree_id"); }
	if (!empty($leaf_id)) { $leaf_name = $leaf["title"]; }
	if (!empty($leaf_id)) { $host_name = db_fetch_cell("select host.description from (graph_tree_items,host) where graph_tree_items.host_id=host.id and graph_tree_items.id=$leaf_id"); }

	$host_group_data_array = explode(":", $host_group_data);

	if ($host_group_data_array[0] == "graph_template") {
		$host_group_data_name = "<strong>" . _("Graph Template:") . "</strong> " . db_fetch_cell("select template_name from graph_template where id=" . $host_group_data_array[1]);
		$graph_template_id = $host_group_data_array[1];
	}elseif ($host_group_data_array[0] == "data_query") {
		$host_group_data_name = "<strong>" . _("Data Query:") . "</strong> " . (empty($host_group_data_array[1]) ? _("(Non Indexed)") : db_fetch_cell("select name from snmp_query where id=" . $host_group_data_array[1]));
		$data_query_id = $host_group_data_array[1];
	}elseif ($host_group_data_array[0] == "data_query_index") {
		$host_group_data_name = "<strong>" . _("Data Query:") . "</strong> " . (empty($host_group_data_array[1]) ? _("(Non Indexed)") : db_fetch_cell("select name from snmp_query where id=" . $host_group_data_array[1])) . "-> " . (empty($host_group_data_array[2]) ? "Unknown Index" : get_formatted_data_query_index($leaf["host_id"], $host_group_data_array[1], $host_group_data_array[2]));
		$data_query_id = $host_group_data_array[1];
		$data_query_index = $host_group_data_array[2];
	}

	if (!empty($tree_name)) { $title .= $title_delimiter . "<strong>" . _("Tree:") . "</strong> $tree_name"; $title_delimiter = "-> "; }
	if (!empty($leaf_name)) { $title .= $title_delimiter . "<strong>" . _("Leaf:") . "</strong> $leaf_name"; $title_delimiter = "-> "; }
	if (!empty($host_name)) { $title .= $title_delimiter . "<strong>" . _("Device:") . "</strong> $host_name"; $title_delimiter = "-> "; }
	if (!empty($host_group_data_name)) { $title .= $title_delimiter . " $host_group_data_name"; $title_delimiter = "-> "; }

	print "<table width='98%' align='center' cellpadding='3'>";

	/* include time span selector */
	if (read_graph_config_option("timespan_sel") == "on") {
		html_graph_start_box(3, false);
		require(CACTI_BASE_PATH . "/include/html/inc_timespan_selector.php");
		html_graph_end_box();
		print "<br>";
	}

	/* start graph display */
	html_graph_start_box(3, false);
	print "<tr bgcolor='#" . $colors["header_panel_background"] . "'><td width='390' colspan='3' class='textHeaderDark'>$title</td></tr>";

	if (($leaf_type == "header") || (empty($leaf_id))) {
		$heirarchy = db_fetch_assoc("select
			graph_tree_items.id,
			graph_tree_items.title,
			graph_tree_items.local_graph_id,
			graph_tree_items.rra_id,
			graph_tree_items.order_key,
			graph.title_cache
			from (graph_tree_items,graph)
			left join graph on (graph_tree_items.local_graph_id=graph.id)
			$sql_join
			where graph_tree_items.graph_tree_id=$tree_id
			and graph_tree_items.order_key like '$search_key" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', (MAX_TREE_DEPTH * CHARS_PER_TIER) - (strlen($search_key) + CHARS_PER_TIER)) . "'
			and graph_tree_items.local_graph_id>0
			$sql_where
			group by graph_tree_items.id
			order by graph_tree_items.order_key");

		if (read_graph_config_option("thumbnail_section_tree_2") == "on") {
			html_graph_thumbnail_area($heirarchy, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end());
		}else{
			html_graph_area($heirarchy, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end());
		}
	}elseif ($leaf_type == "host") {
		/* graph template grouping */
		if ($leaf["host_grouping_type"] == HOST_GROUPING_GRAPH_TEMPLATE) {
			$graph_templates = db_fetch_assoc("select
				graph_template.id,
				graph_template.template_name
				from graph,graph_template
				where graph.graph_template_id=graph_template.id
				and graph.host_id=" . $leaf["host_id"] . "
				" . (empty($graph_template_id) ? "" : "and graph_template.id=$graph_template_id") . "
				group by graph_template.id
				order by graph_template.template_name");

			/* for graphs without a template */
			array_push($graph_templates, array(
				"id" => "0",
				"template_name" => _("(No Graph Template)")
				));

			if (sizeof($graph_templates) > 0) {
				foreach ($graph_templates as $item) {
					$graphs = db_fetch_assoc("select
						graph.title_cache,
						graph.id as graph_id
						from graph
						$sql_join
						where graph.graph_template_id=" . $item["id"] . "
						and graph.host_id=" . $leaf["host_id"] . "
						$sql_where
						order by graph.title_cache");

					if (read_graph_config_option("thumbnail_section_tree_2") == "on") {
						html_graph_thumbnail_area($graphs, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end(), "<tr bgcolor='#" . $colors["graph_type_background"] . "'><td colspan='3' class='textHeaderDark'><strong>" . _("Graph Template:") . "</strong> " . $item["template_name"] . "</td></tr>");
					}else{
						html_graph_area($graphs, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end(), "<tr bgcolor='#" . $colors["graph_type_background"] . "'><td colspan='3' class='textHeaderDark'><strong>" . _("Graph Template:") . "</strong> " . $item["template_name"] . "</td></tr>");
					}
				}
			}
		/* data query index grouping */
		}elseif ($leaf["host_grouping_type"] == HOST_GROUPING_DATA_QUERY_INDEX) {
			$data_sources = db_fetch_assoc("select
				graph.id as graph_id,
				graph.title_cache as graph_title,
				data_source.data_input_type,
				data_source.id as data_source_id
				from graph,graph_item,data_source_item,data_source
				where graph.id=graph_item.graph_id
				and graph_item.data_source_item_id=data_source_item.id
				and data_source_item.data_source_id=data_source.id
				and graph.host_id = " . $leaf["host_id"] . "");

			$index_list = array();

			if (sizeof($data_sources) > 0) {
				foreach ($data_sources as $item) {
					if ($item["data_input_type"] == DATA_INPUT_TYPE_DATA_QUERY) {
						$field_list = array_rekey(db_fetch_assoc("select name,value from data_source_field where data_source_id = ". $item["data_source_id"] . " and (name = 'data_query_id' or name = 'data_query_index' or name = 'data_query_field_name' or name = 'data_query_field_value')"), "name", "value");

						if ((isset($field_list["data_query_id"])) && (isset($field_list["data_query_index"]))) {
							if ( !(((isset($data_query_id)) && ($data_query_id != $field_list["data_query_id"])) || ((isset($data_query_index)) && ($data_query_index != $field_list["data_query_index"]))) ) {
								$index_list{$field_list["data_query_id"]}{$field_list["data_query_index"]}{$item["graph_id"]} = $item["graph_title"];
							}
						}
					}else{
						$index_list[0][0]{$item["graph_id"]} = $item["graph_title"];
					}
				}
			}

			while (list($data_query_id, $graph_list) = each($index_list)) {
				if (empty($data_query_id)) {
					print "<tr bgcolor='#" . $colors["graph_type_background"] . "'><td colspan='3' class='textHeaderDark'><strong>" . _("(Non Indexed)") . "</strong></td></tr>";

					$index_graph_list = array();

					while (list($graph_id, $graph_title) = each($graph_list[0])) {
						/* reformat the array so it's compatable with the html_graph* area functions */
						array_push($index_graph_list, array("graph_id" => $graph_id, "title_cache" => $graph_title));
					}

					if (read_graph_config_option("thumbnail_section_tree_2") == "on") {
						html_graph_thumbnail_area($index_graph_list, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end(), "");
					}else{
						html_graph_area($index_graph_list, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end(), "");
					}
				}else{
					/* fetch a list of field names that are sorted by the preferred sort field */
					$sort_field_data = get_formatted_data_query_indexes($leaf["host_id"], $data_query_id);

					/* re-key the results on data query index */
					if (sizeof($graph_list) > 0) {
						print "<tr bgcolor='#" . $colors["graph_type_background"] . "'><td colspan='3' class='textHeaderDark'><strong>" . _("Data Query:") . "</strong> " . db_fetch_cell("select name from snmp_query where id = $data_query_id") . "</td></tr>";
					}

					/* using the sorted data as they key; grab each snmp index from the master list */
					while (list($data_query_index, $sort_field_value) = each($sort_field_data)) {
						/* render each graph for the current data query index */
						if (isset($graph_list[$data_query_index])) {
							$index_graph_list = array();

							while (list($graph_id, $graph_title) = each($graph_list[$data_query_index])) {
								/* reformat the array so it's compatable with the html_graph* area functions */
								array_push($index_graph_list, array("graph_id" => $graph_id, "title_cache" => $graph_title));
							}

							if (read_graph_config_option("thumbnail_section_tree_2") == "on") {
								html_graph_thumbnail_area($index_graph_list, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end(), "<tr bgcolor='#" . $colors["graph_type_background"] . "'><td colspan='3' class='textHeaderDark'>$sort_field_value</td></tr>");
							}else{
								html_graph_area($index_graph_list, "", "view_type=tree&graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end(), "<tr bgcolor='#" . $colors["graph_type_background"] . "'><td colspan='3' class='textHeaderDark'>$sort_field_value</td></tr>");
							}
						}
					}
				}
			}
		}
	}

	print "</table>";
}
Ejemplo n.º 20
0
	</tr>
	<?php 
        html_end_box();
        /* if the number of rows is -1, set it to the default */
        if ($_REQUEST['rows'] == -1) {
            $_REQUEST['rows'] = read_graph_config_option('list_graphs_per_page');
        }
        /* create filter for sql */
        $sql_filter = '';
        $sql_filter .= empty($_REQUEST['filter']) ? '' : " graph_templates_graph.title_cache like '%" . get_request_var_request('filter') . "%'";
        $sql_filter .= empty($_REQUEST['host_id']) ? '' : (empty($sql_filter) ? '' : ' and') . ' graph_local.host_id=' . get_request_var_request('host_id');
        $sql_filter .= empty($_REQUEST['graph_template_id']) ? '' : (empty($sql_filter) ? '' : ' and') . ' graph_local.graph_template_id=' . get_request_var_request('graph_template_id');
        /* graph permissions */
        if (read_config_option('auth_method') != 0) {
            /* get policy information for the sql where clause */
            $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)
			left join graph_templates on (graph_templates.id=graph_local.graph_template_id)
			left join user_auth_perms on ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=1 and user_auth_perms.user_id=' . $_SESSION['sess_user_id'] . ') OR (host.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=' . $_SESSION['sess_user_id'] . ') OR (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 = '';
        }
        $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 '%" . $_REQUEST['filter'] . "%'\n\t\t" . (empty($_REQUEST['host_id']) ? '' : ' and graph_local.host_id=' . $_REQUEST['host_id']) . '
		' . (empty($_REQUEST['graph_template_id']) ? '' : ' and graph_local.graph_template_id=' . $_REQUEST['graph_template_id']);
        $total_rows = count(db_fetch_assoc("select\n\t\tgraph_templates_graph.local_graph_id\n\t\t{$sql_base}"));
        $graphs = db_fetch_assoc("select\n\t\tgraph_templates_graph.local_graph_id,\n\t\thost.description,\n\t\tgraph_templates.name AS template_name,\n\t\tgraph_templates_graph.title_cache,\n\t\tgraph_templates_graph.height,\n\t\tgraph_templates_graph.width\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 " . $_REQUEST['rows'] * ($_REQUEST['page'] - 1) . ',' . $_REQUEST['rows']);
        ?>

	<form name='chk' id='chk' action='graph_view.php' method='get' onSubmit='form_graph(document.chk,document.chk)'>
Ejemplo n.º 21
0
function mactrack_view_graphs() {
	global $current_user, $colors, $config;

	/* ================= input validation ================= */
	input_validate_input_number(get_request_var("rra_id"));
	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"));
	}

	$sql_or = ""; $sql_where = ""; $sql_join = "";

	/* if the user pushed the 'clear' button */
	if (isset($_REQUEST["clear_x"])) {
		kill_session_var("sess_graph_view_current_page");
		kill_session_var("sess_graph_view_filter");
		kill_session_var("sess_graph_view_graph_template");

		unset($_REQUEST["page"]);
		unset($_REQUEST["filter"]);
		unset($_REQUEST["graph_template_id"]);
		unset($_REQUEST["graph_list"]);
		unset($_REQUEST["graph_add"]);
		unset($_REQUEST["graph_remove"]);
	}

	/* reset the page counter to '1' if a search in initiated */
	if (isset($_REQUEST["filter"])) {
		$_REQUEST["page"] = "1";
	}

	load_current_session_value("graph_template_id", "sess_graph_view_graph_template", "0");
	load_current_session_value("filter", "sess_graph_view_filter", "");
	load_current_session_value("page", "sess_graph_view_current_page", "1");

	/* 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)
			LEFT JOIN graph_templates
			ON (graph_templates.id=graph_local.graph_template_id)
			LEFT JOIN user_auth_perms
			ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id
			AND user_auth_perms.type=1
			AND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ")
			OR (host.id=user_auth_perms.item_id AND user_auth_perms.type=3 AND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ")
			OR (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)
		$sql_join
		$sql_where
		" . (empty($sql_where) ? "WHERE" : "AND") . "   graph_templates_graph.local_graph_id > 0
		AND graph_templates_graph.local_graph_id=graph_local.id
		" . (strlen($_REQUEST["filter"]) ? "AND graph_templates_graph.title_cache like '%%" . $_REQUEST["filter"] . "%%'":"") . "
		" . (empty($_REQUEST["graph_template_id"]) ? "" : " and graph_local.graph_template_id=" . $_REQUEST["graph_template_id"]) . "
		$sql_or";

	$total_rows = count(db_fetch_assoc("SELECT
		graph_templates_graph.local_graph_id
		$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
		graph_templates_graph.local_graph_id,
		graph_templates_graph.title_cache
		$sql_base
		GROUP BY graph_templates_graph.local_graph_id
		ORDER BY graph_templates_graph.title_cache
		LIMIT " . (ROWS_PER_PAGE*($_REQUEST["page"]-1)) . "," . ROWS_PER_PAGE);

	?>
	<script type="text/javascript">
	<!--
	function applyGraphPreviewFilterChange(objForm) {
		strURL = '?report=graphs&graph_template_id=' + objForm.graph_template_id.value;
		strURL = strURL + '&filter=' + objForm.filter.value;
		document.location = strURL;
	}
	-->
	</script>
	<?php

	/* include graph view filter selector */
	display_output_messages();
	mactrack_tabs();
	html_start_box("<strong>Network Device Graphs</strong>", "100%", $colors["header"], "1", "center", "");
	mactrack_graph_view_filter();

	/* include time span selector */
	if (read_graph_config_option("timespan_sel") == "on") {
		mactrack_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", "");
	mactrack_nav_bar($_REQUEST["page"], ROWS_PER_PAGE, $total_rows, $nav_url);
	if (read_graph_config_option("thumbnail_section_preview") == "on") {
		html_graph_thumbnail_area($graphs, "","graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end());
	}else{
		html_graph_area($graphs, "", "graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end());
	}

	if ($total_rows) {
		mactrack_nav_bar($_REQUEST["page"], ROWS_PER_PAGE, $total_rows, $nav_url);
	}
	html_end_box();
}
Ejemplo n.º 22
0
		</td>
		</form>
	</tr>
	<?php
	html_graph_end_box();

	/* create filter for sql */
	$sql_filter = "";
	$sql_filter .= (empty($_REQUEST["filter"]) ? "" : " graph_templates_graph.title_cache like '%" . $_REQUEST["filter"] . "%'");
	$sql_filter .= (empty($_REQUEST["host_id"]) ? "" : (empty($sql_filter) ? "" : " and") . " graph_local.host_id=" . $_REQUEST["host_id"]);
	$sql_filter .= (empty($_REQUEST["graph_template_id"]) ? "" : (empty($sql_filter) ? "" : " and") . " graph_local.graph_template_id=" . $_REQUEST["graph_template_id"]);

	/* graph permissions */
	if (read_config_option("auth_method") != 0) {
		/* get policy information for the sql where clause */
		$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)
			left join graph_templates on (graph_templates.id=graph_local.graph_template_id)
			left join user_auth_perms on ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=1 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (host.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (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 = "";
	}

	$sql_base = "from (graph_templates_graph,graph_local)
		$sql_join
		$sql_where
		" . (empty($sql_where) ? "where" : "and") . " graph_templates_graph.local_graph_id > 0
		and graph_templates_graph.local_graph_id=graph_local.id
		and graph_templates_graph.title_cache like '%" . $_REQUEST["filter"] . "%'
Ejemplo n.º 23
0
function is_graph_allowed($graph_id) {
	$current_user = db_fetch_row("select policy_graphs,policy_hosts,policy_graph_templates from user_auth where id=" . $_SESSION["sess_user_id"]);

	/* get policy information for the sql where clause */
	$sql_where = get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]);

	$graphs = db_fetch_assoc("select distinct
		graph.id
		from graph
		left join host on (host.id=graph.host_id)
		left join graph_template on (graph_template.id=graph.graph_template_id)
		left join user_auth_perms on ((graph.id=user_auth_perms.item_id and user_auth_perms.type=1 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (host.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_template.id=user_auth_perms.item_id and user_auth_perms.type=4 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . "))
		where graph.id = $graph_id");

	if (sizeof($graphs) > 0) {
		return true;
	}else{
		return false;
	}
}
Ejemplo n.º 24
0
function graph() {
	global $colors, $graph_actions, $item_rows;

	/* ================= input validation ================= */
	input_validate_input_number(get_request_var_request("host_id"));
	input_validate_input_number(get_request_var_request("graph_rows"));
	input_validate_input_number(get_request_var_request("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("filter"));
	}

	/* clean up sort_column string */
	if (isset($_REQUEST["sort_column"])) {
		$_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column"));
	}

	/* clean up sort_direction string */
	if (isset($_REQUEST["sort_direction"])) {
		$_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction"));
	}

	/* if the user pushed the 'clear' button */
	if (isset($_REQUEST["clear_x"])) {
		kill_session_var("sess_graph_current_page");
		kill_session_var("sess_graph_filter");
		kill_session_var("sess_graph_sort_column");
		kill_session_var("sess_graph_sort_direction");
		kill_session_var("sess_graph_host_id");
		kill_session_var("sess_graph_rows");
		kill_session_var("sess_graph_template_id");

		unset($_REQUEST["page"]);
		unset($_REQUEST["filter"]);
		unset($_REQUEST["sort_column"]);
		unset($_REQUEST["sort_direction"]);
		unset($_REQUEST["host_id"]);
		unset($_REQUEST["graph_rows"]);
		unset($_REQUEST["template_id"]);
	}

	/* remember these search fields in session vars so we don't have to keep passing them around */
	load_current_session_value("page", "sess_graph_current_page", "1");
	load_current_session_value("filter", "sess_graph_filter", "");
	load_current_session_value("sort_column", "sess_graph_sort_column", "title_cache");
	load_current_session_value("sort_direction", "sess_graph_sort_direction", "ASC");
	load_current_session_value("host_id", "sess_graph_host_id", "-1");
	load_current_session_value("graph_rows", "sess_graph_rows", read_config_option("num_rows_graph"));
	load_current_session_value("template_id", "sess_graph_template_id", "-1");

	/* if the number of rows is -1, set it to the default */
	if (get_request_var_request("graph_rows") == -1) {
		$_REQUEST["graph_rows"] = read_config_option("num_rows_graph");
	}

	?>
	<script type="text/javascript">
	<!--

	function applyGraphsFilterChange(objForm) {
		strURL = '?host_id=' + objForm.host_id.value;
		strURL = strURL + '&graph_rows=' + objForm.graph_rows.value;
		strURL = strURL + '&filter=' + objForm.filter.value;
		strURL = strURL + '&template_id=' + objForm.template_id.value;
		document.location = strURL;
	}

	-->
	</script>
	<?php

	html_start_box("<strong>Graph Management</strong>", "100%", $colors["header"], "3", "center", "graphs.php?action=graph_edit&host_id=" . get_request_var_request("host_id"));

	?>
	<tr bgcolor="<?php print $colors["panel"];?>">
		<form name="form_graph_id">
		<td>
			<table cellpadding="1" cellspacing="0">
				<tr>
					<td width="50">
						Host:&nbsp;
					</td>
					<td width="1">
						<select name="host_id" onChange="applyGraphsFilterChange(document.form_graph_id)">
							<option value="-1"<?php if (get_request_var_request("host_id") == "-1") {?> selected<?php }?>>Any</option>
							<option value="0"<?php if (get_request_var_request("host_id") == "0") {?> selected<?php }?>>None</option>
							<?php
							if (read_config_option("auth_method") != 0) {
								/* get policy information for the sql where clause */
								$current_user = db_fetch_row("select * from user_auth where id=" . $_SESSION["sess_user_id"]);
								$sql_where = get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]);

								$hosts = db_fetch_assoc("SELECT DISTINCT host.id, CONCAT_WS('',host.description,' (',host.hostname,')') as name
									FROM (graph_templates_graph,host)
									LEFT JOIN graph_local ON (graph_local.host_id=host.id)
									LEFT JOIN graph_templates ON (graph_templates.id=graph_local.graph_template_id)
									LEFT JOIN user_auth_perms ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=1 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (host.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_templates.id=user_auth_perms.item_id and user_auth_perms.type=4 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . "))
									WHERE graph_templates_graph.local_graph_id=graph_local.id
									" . (empty($sql_where) ? "" : "and $sql_where") . "
									ORDER BY name");
							}else{
								$hosts = db_fetch_assoc("SELECT DISTINCT host.id, CONCAT_WS('',host.description,' (',host.hostname,')') as name
									FROM host
									ORDER BY name");
							}

							if (sizeof($hosts) > 0) {
							foreach ($hosts as $host) {
								print "<option value=' " . $host["id"] . "'"; if (get_request_var_request("host_id") == $host["id"]) { print " selected"; } print ">" . title_trim($host["name"], 40) . "</option>\n";
							}
							}
							?>
						</select>
					</td>
					<td width="70">
						&nbsp;Template:&nbsp;
					</td>
					<td width="1">
						<select name="template_id" onChange="applyGraphsFilterChange(document.form_graph_id)">
							<option value="-1"<?php if (get_request_var_request("template_id") == "-1") {?> selected<?php }?>>Any</option>
							<option value="0"<?php if (get_request_var_request("template_id") == "0") {?> selected<?php }?>>None</option>
							<?php
							if (read_config_option("auth_method") != 0) {
								$templates = db_fetch_assoc("SELECT DISTINCT graph_templates.id, graph_templates.name
									FROM (graph_templates_graph,graph_local)
									LEFT JOIN host ON (host.id=graph_local.host_id)
									LEFT JOIN graph_templates ON (graph_templates.id=graph_local.graph_template_id)
									LEFT JOIN user_auth_perms ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=1 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (host.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_templates.id=user_auth_perms.item_id and user_auth_perms.type=4 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . "))
									WHERE graph_templates_graph.local_graph_id=graph_local.id
									AND graph_templates.id IS NOT NULL
									" . (empty($sql_where) ? "" : "AND $sql_where") . "
									ORDER BY name");
							}else{
								$templates = db_fetch_assoc("SELECT DISTINCT graph_templates.id, graph_templates.name
									FROM graph_templates
									ORDER BY name");
							}

							if (sizeof($templates) > 0) {
							foreach ($templates as $template) {
								print "<option value=' " . $template["id"] . "'"; if (get_request_var_request("template_id") == $template["id"]) { print " selected"; } print ">" . title_trim($template["name"], 40) . "</option>\n";
							}
							}
							?>
						</select>
					</td>
					<td width="120" nowrap style='white-space: nowrap;'>
						&nbsp;<input type="image" src="images/button_go.gif" alt="Go" border="0" align="absmiddle">
						<input type="image" src="images/button_clear.gif" name="clear" alt="Clear" border="0" align="absmiddle">
					</td>
				</tr>
			</table>
			<table cellpadding="1" cellspacing="0">
				<tr>
					<td width="50">
						&nbsp;Search:&nbsp;
					</td>
					<td>
						<input type="text" name="filter" size="40" value="<?php print get_request_var_request("filter");?>">
					</td>
					<td nowrap style='white-space: nowrap;' width="50">
						Rows per Page:&nbsp;
					</td>
					<td width="1">
						<select name="graph_rows" onChange="applyGraphsFilterChange(document.form_graph_id)">
							<option value="-1"<?php if (get_request_var_request("graph_rows") == "-1") {?> selected<?php }?>>Default</option>
							<?php
							if (sizeof($item_rows) > 0) {
							foreach ($item_rows as $key => $value) {
								print "<option value='" . $key . "'"; if (get_request_var_request("graph_rows") == $key) { print " selected"; } print ">" . $value . "</option>\n";
							}
							}
							?>
						</select>
					</td>
				</tr>
			</table>
		</td>
		<input type='hidden' name='page' value='1'>
		</form>
	</tr>
	<?php

	html_end_box();

	/* form the 'where' clause for our main sql query */
	if (strlen(get_request_var_request("filter"))) {
		$sql_where = "AND (graph_templates_graph.title_cache like '%%" . get_request_var_request("filter") . "%%'" .
			" OR graph_templates.name like '%%" . get_request_var_request("filter") . "%%')";
	}else{
		$sql_where = "";
	}

	if (get_request_var_request("host_id") == "-1") {
		/* Show all items */
	}elseif (get_request_var_request("host_id") == "0") {
		$sql_where .= " AND graph_local.host_id=0";
	}elseif (!empty($_REQUEST["host_id"])) {
		$sql_where .= " AND graph_local.host_id=" . get_request_var_request("host_id");
	}

	if (get_request_var_request("template_id") == "-1") {
		/* Show all items */
	}elseif (get_request_var_request("template_id") == "0") {
		$sql_where .= " AND graph_templates_graph.graph_template_id=0";
	}elseif (!empty($_REQUEST["template_id"])) {
		$sql_where .= " AND graph_templates_graph.graph_template_id=" . get_request_var_request("template_id");
	}

	html_start_box("", "100%", $colors["header"], "3", "center", "");

	$total_rows = db_fetch_cell("SELECT
		COUNT(graph_templates_graph.id)
		FROM (graph_local,graph_templates_graph)
		LEFT JOIN graph_templates ON (graph_local.graph_template_id=graph_templates.id)
		WHERE graph_local.id=graph_templates_graph.local_graph_id
		$sql_where");

	$graph_list = db_fetch_assoc("SELECT
		graph_templates_graph.id,
		graph_templates_graph.local_graph_id,
		graph_templates_graph.height,
		graph_templates_graph.width,
		graph_templates_graph.title_cache,
		graph_templates.name,
		graph_local.host_id
		FROM (graph_local,graph_templates_graph)
		LEFT JOIN graph_templates ON (graph_local.graph_template_id=graph_templates.id)
		WHERE graph_local.id=graph_templates_graph.local_graph_id
		$sql_where
		ORDER BY " . $_REQUEST["sort_column"] . " " . get_request_var_request("sort_direction") .
		" LIMIT " . (get_request_var_request("graph_rows")*(get_request_var_request("page")-1)) . "," . get_request_var_request("graph_rows"));

	/* generate page list */
	$url_page_select = get_page_list(get_request_var_request("page"), MAX_DISPLAY_PAGES, get_request_var_request("graph_rows"), $total_rows, "graphs.php?filter=" . get_request_var_request("filter") . "&host_id=" . get_request_var_request("host_id"));

	$nav = "<tr bgcolor='#" . $colors["header"] . "'>
			<td colspan='5'>
				<table width='100%' cellspacing='0' cellpadding='0' border='0'>
					<tr>
						<td align='left' class='textHeaderDark'>
							<strong>&lt;&lt; "; if (get_request_var_request("page") > 1) { $nav .= "<a class='linkOverDark' href='graphs.php?filter=" . get_request_var_request("filter") . "&host_id=" . get_request_var_request("host_id") . "&page=" . (get_request_var_request("page")-1) . "'>"; } $nav .= "Previous"; if (get_request_var_request("page") > 1) { $nav .= "</a>"; } $nav .= "</strong>
						</td>\n
						<td align='center' class='textHeaderDark'>
							Showing Rows " . ((get_request_var_request("graph_rows")*(get_request_var_request("page")-1))+1) . " to " . ((($total_rows < get_request_var_request("graph_rows")) || ($total_rows < (get_request_var_request("graph_rows")*get_request_var_request("page")))) ? $total_rows : (get_request_var_request("graph_rows")*get_request_var_request("page"))) . " of $total_rows [$url_page_select]
						</td>\n
						<td align='right' class='textHeaderDark'>
							<strong>"; if ((get_request_var_request("page") * get_request_var_request("graph_rows")) < $total_rows) { $nav .= "<a class='linkOverDark' href='graphs.php?filter=" . get_request_var_request("filter") . "&host_id=" . get_request_var_request("host_id") . "&page=" . (get_request_var_request("page")+1) . "'>"; } $nav .= "Next"; if ((get_request_var_request("page") * get_request_var_request("graph_rows")) < $total_rows) { $nav .= "</a>"; } $nav .= " &gt;&gt;</strong>
						</td>\n
					</tr>
				</table>
			</td>
		</tr>\n";

	print $nav;

	$display_text = array(
		"title_cache" => array("Graph Title", "ASC"),
		"local_graph_id" => array("ID", "ASC"),
		"name" => array("Template Name", "ASC"),
		"height" => array("Size", "ASC"));

	html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction"));

	$i = 0;
	if (sizeof($graph_list) > 0) {
		foreach ($graph_list as $graph) {
			$template_name = ((empty($graph["name"])) ? "<em>None</em>" : $graph["name"]);
			form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $graph["local_graph_id"]); $i++;
			form_selectable_cell("<a class='linkEditMain' href='graphs.php?action=graph_edit&id=" . $graph["local_graph_id"] . "' title='" . htmlspecialchars($graph["title_cache"]) . "'>" . ((get_request_var_request("filter") != "") ? eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", title_trim($graph["title_cache"], read_config_option("max_title_graph"))) : title_trim($graph["title_cache"], read_config_option("max_title_graph"))) . "</a>", $graph["local_graph_id"]);
			form_selectable_cell($graph["local_graph_id"], $graph["local_graph_id"]);
			form_selectable_cell(((get_request_var_request("filter") != "") ? eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $template_name) : $template_name) . "</a>", $graph["local_graph_id"]);
			form_selectable_cell($graph["height"] . "x" . $graph["width"], $graph["local_graph_id"]);
			form_checkbox_cell($graph["title_cache"], $graph["local_graph_id"]);
			form_end_row();
		}

		/* put the nav bar on the bottom as well */
		print $nav;
	}else{
		print "<tr><td><em>No Graphs Found</em></td></tr>";
	}

	html_end_box(false);

	/* add a list of tree names to the actions dropdown */
	add_tree_names_to_actions_array();

	/* draw the dropdown containing a list of available actions for this form */
	draw_actions_dropdown($graph_actions);

	print "</form>\n";
}
Ejemplo n.º 25
0
function graph()
{
    global $colors, $graph_actions, $item_rows;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request("host_id"));
    input_validate_input_number(get_request_var_request("graph_rows"));
    input_validate_input_number(get_request_var_request("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("filter"));
    }
    /* clean up sort_column string */
    if (isset($_REQUEST["sort_column"])) {
        $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column"));
    }
    /* clean up sort_direction string */
    if (isset($_REQUEST["sort_direction"])) {
        $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction"));
    }
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST["clear_x"])) {
        kill_session_var("sess_graph_current_page");
        kill_session_var("sess_graph_filter");
        kill_session_var("sess_graph_sort_column");
        kill_session_var("sess_graph_sort_direction");
        kill_session_var("sess_graph_host_id");
        kill_session_var("sess_graph_rows");
        kill_session_var("sess_graph_template_id");
        unset($_REQUEST["page"]);
        unset($_REQUEST["filter"]);
        unset($_REQUEST["sort_column"]);
        unset($_REQUEST["sort_direction"]);
        unset($_REQUEST["host_id"]);
        unset($_REQUEST["graph_rows"]);
        unset($_REQUEST["template_id"]);
    }
    /* remember these search fields in session vars so we don't have to keep passing them around */
    load_current_session_value("page", "sess_graph_current_page", "1");
    load_current_session_value("filter", "sess_graph_filter", "");
    load_current_session_value("sort_column", "sess_graph_sort_column", "title_cache");
    load_current_session_value("sort_direction", "sess_graph_sort_direction", "ASC");
    load_current_session_value("host_id", "sess_graph_host_id", "-1");
    load_current_session_value("graph_rows", "sess_graph_rows", read_config_option("num_rows_graph"));
    load_current_session_value("template_id", "sess_graph_template_id", "-1");
    /* if the number of rows is -1, set it to the default */
    if (get_request_var_request("graph_rows") == -1) {
        $_REQUEST["graph_rows"] = read_config_option("num_rows_graph");
    }
    ?>
	<script type="text/javascript">
	<!--

	function applyGraphsFilterChange(objForm) {
		strURL = '?host_id=' + objForm.host_id.value;
		strURL = strURL + '&graph_rows=' + objForm.graph_rows.value;
		strURL = strURL + '&filter=' + objForm.filter.value;
		strURL = strURL + '&template_id=' + objForm.template_id.value;
		document.location = strURL;
	}

	-->
	</script>
	<?php 
    html_start_box("<strong>Graph Management</strong>", "100%", "", "3", "center", "graphs.php?action=graph_edit&host_id=" . htmlspecialchars(get_request_var_request("host_id")));
    ?>
	<tr class='even noprint'>
		<td>
			<form name="form_graph_id" action="graphs.php">
			<table cellpadding="2" cellspacing="0">
				<tr>
					<td width="50">
						Host:
					</td>
					<td width="1">
						<select name="host_id" onChange="applyGraphsFilterChange(document.form_graph_id)">
							<option value="-1"<?php 
    if (get_request_var_request("host_id") == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Any</option>
							<option value="0"<?php 
    if (get_request_var_request("host_id") == "0") {
        ?>
 selected<?php 
    }
    ?>
>None</option>
							<?php 
    if (read_config_option("auth_method") != 0) {
        /* get policy information for the sql where clause */
        $current_user = db_fetch_row("select * from user_auth where id=" . $_SESSION["sess_user_id"]);
        $sql_where = get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]);
        $hosts = db_fetch_assoc("SELECT DISTINCT host.id, CONCAT_WS('',host.description,' (',host.hostname,')') as name\n\t\t\t\t\t\t\t\t\tFROM (graph_templates_graph,host)\n\t\t\t\t\t\t\t\t\tLEFT JOIN graph_local ON (graph_local.host_id=host.id)\n\t\t\t\t\t\t\t\t\tLEFT JOIN graph_templates ON (graph_templates.id=graph_local.graph_template_id)\n\t\t\t\t\t\t\t\t\tLEFT JOIN user_auth_perms ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=1 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (host.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_templates.id=user_auth_perms.item_id and user_auth_perms.type=4 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . "))\n\t\t\t\t\t\t\t\t\tWHERE graph_templates_graph.local_graph_id=graph_local.id\n\t\t\t\t\t\t\t\t\t" . (empty($sql_where) ? "" : "and {$sql_where}") . "\n\t\t\t\t\t\t\t\t\tORDER BY name");
    } else {
        $hosts = db_fetch_assoc("SELECT DISTINCT host.id, CONCAT_WS('',host.description,' (',host.hostname,')') as name\n\t\t\t\t\t\t\t\t\tFROM host\n\t\t\t\t\t\t\t\t\tORDER BY name");
    }
    if (sizeof($hosts) > 0) {
        foreach ($hosts as $host) {
            print "<option value='" . $host["id"] . "'";
            if (get_request_var_request("host_id") == $host["id"]) {
                print " selected";
            }
            print ">" . title_trim(htmlspecialchars($host["name"]), 40) . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td width="70">
						Template:
					</td>
					<td width="1">
						<select name="template_id" onChange="applyGraphsFilterChange(document.form_graph_id)">
							<option value="-1"<?php 
    if (get_request_var_request("template_id") == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Any</option>
							<option value="0"<?php 
    if (get_request_var_request("template_id") == "0") {
        ?>
 selected<?php 
    }
    ?>
>None</option>
							<?php 
    if (read_config_option("auth_method") != 0) {
        $templates = db_fetch_assoc("SELECT DISTINCT graph_templates.id, graph_templates.name\n\t\t\t\t\t\t\t\t\tFROM (graph_templates_graph,graph_local)\n\t\t\t\t\t\t\t\t\tLEFT JOIN host ON (host.id=graph_local.host_id)\n\t\t\t\t\t\t\t\t\tLEFT JOIN graph_templates ON (graph_templates.id=graph_local.graph_template_id)\n\t\t\t\t\t\t\t\t\tLEFT JOIN user_auth_perms ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=1 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (host.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_templates.id=user_auth_perms.item_id and user_auth_perms.type=4 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . "))\n\t\t\t\t\t\t\t\t\tWHERE graph_templates_graph.local_graph_id=graph_local.id\n\t\t\t\t\t\t\t\t\tAND graph_templates.id IS NOT NULL\n\t\t\t\t\t\t\t\t\t" . (empty($sql_where) ? "" : "AND {$sql_where}") . "\n\t\t\t\t\t\t\t\t\tORDER BY name");
    } else {
        $templates = db_fetch_assoc("SELECT DISTINCT graph_templates.id, graph_templates.name\n\t\t\t\t\t\t\t\t\tFROM graph_templates\n\t\t\t\t\t\t\t\t\tORDER BY name");
    }
    if (sizeof($templates) > 0) {
        foreach ($templates as $template) {
            print "<option value='" . $template["id"] . "'";
            if (get_request_var_request("template_id") == $template["id"]) {
                print " selected";
            }
            print ">" . title_trim(htmlspecialchars($template["name"]), 40) . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td>
						<input type="submit" value="Go" title="Set/Refresh Filters">
					</td>
					<td>
						<input type="submit" name="clear_x" value="Clear" title="Clear Filters">
					</td>
				</tr>
				<tr>
					<td width="50">
						Search:
					</td>
					<td>
						<input type="text" name="filter" size="40" value="<?php 
    print htmlspecialchars(get_request_var_request("filter"));
    ?>
">
					</td>
					<td style='white-space: nowrap;'>
						Rows per Page:
					</td>
					<td width="1">
						<select name="graph_rows" onChange="applyGraphsFilterChange(document.form_graph_id)">
							<option value="-1"<?php 
    if (get_request_var_request("graph_rows") == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Default</option>
							<?php 
    if (sizeof($item_rows) > 0) {
        foreach ($item_rows as $key => $value) {
            print "<option value='" . $key . "'";
            if (get_request_var_request("graph_rows") == $key) {
                print " selected";
            }
            print ">" . htmlspecialchars($value) . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
				</tr>
			</table>
			<input type='hidden' name='page' value='1'>
			</form>
		</td>
	</tr>
	<?php 
    html_end_box();
    /* form the 'where' clause for our main sql query */
    if (strlen(get_request_var_request("filter"))) {
        $sql_where = " AND (graph_templates_graph.title_cache like '%%" . get_request_var_request("filter") . "%%'" . " OR graph_templates.name like '%%" . get_request_var_request("filter") . "%%')";
    } else {
        $sql_where = "";
    }
    if (get_request_var_request("host_id") == "-1") {
        /* Show all items */
    } elseif (get_request_var_request("host_id") == "0") {
        $sql_where .= " AND graph_local.host_id=0";
    } elseif (!empty($_REQUEST["host_id"])) {
        $sql_where .= " AND graph_local.host_id=" . get_request_var_request("host_id");
    }
    if (get_request_var_request("template_id") == "-1") {
        /* Show all items */
    } elseif (get_request_var_request("template_id") == "0") {
        $sql_where .= " AND graph_templates_graph.graph_template_id=0";
    } elseif (!empty($_REQUEST["template_id"])) {
        $sql_where .= " AND graph_templates_graph.graph_template_id=" . get_request_var_request("template_id");
    }
    /* allow plugins to modify sql_where */
    $sql_where .= api_plugin_hook_function('graphs_sql_where', $sql_where);
    /* print checkbox form for validation */
    print "<form name='chk' method='post' action='graphs.php'>\n";
    html_start_box("", "100%", "", "3", "center", "");
    $total_rows = db_fetch_cell("SELECT\n\t\tCOUNT(graph_templates_graph.id)\n\t\tFROM (graph_local,graph_templates_graph)\n\t\tLEFT JOIN graph_templates ON (graph_local.graph_template_id=graph_templates.id)\n\t\tWHERE graph_local.id=graph_templates_graph.local_graph_id\n\t\t{$sql_where}");
    $graph_list = db_fetch_assoc("SELECT\n\t\tgraph_templates_graph.id,\n\t\tgraph_templates_graph.local_graph_id,\n\t\tgraph_templates_graph.height,\n\t\tgraph_templates_graph.width,\n\t\tgraph_templates_graph.title_cache,\n\t\tgraph_templates.name,\n\t\tgraph_local.host_id\n\t\tFROM (graph_local,graph_templates_graph)\n\t\tLEFT JOIN graph_templates ON (graph_local.graph_template_id=graph_templates.id)\n\t\tWHERE graph_local.id=graph_templates_graph.local_graph_id\n\t\t{$sql_where}\n\t\tORDER BY " . $_REQUEST["sort_column"] . " " . get_request_var_request("sort_direction") . " LIMIT " . get_request_var_request("graph_rows") * (get_request_var_request("page") - 1) . "," . get_request_var_request("graph_rows"));
    $nav = html_nav_bar("graphs.php?filter=" . get_request_var_request("filter") . "&host_id=" . get_request_var_request("host_id"), MAX_DISPLAY_PAGES, get_request_var_request("page"), get_request_var_request("graph_rows"), $total_rows, 5);
    print $nav;
    $display_text = array("title_cache" => array("Graph Title", "ASC"), "local_graph_id" => array("ID", "ASC"), "name" => array("Template Name", "ASC"), "height" => array("Size", "ASC"));
    html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction"), false);
    $i = 0;
    if (sizeof($graph_list) > 0) {
        foreach ($graph_list as $graph) {
            /* we're escaping strings here, so no need to escape them on form_selectable_cell */
            $template_name = empty($graph["name"]) ? "<em>None</em>" : htmlspecialchars($graph["name"]);
            form_alternate_row('line' . $graph["local_graph_id"], true);
            form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars("graphs.php?action=graph_edit&id=" . $graph["local_graph_id"]) . "' title='" . htmlspecialchars($graph["title_cache"], ENT_QUOTES) . "'>" . (get_request_var_request("filter") != "" ? preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", title_trim(htmlspecialchars($graph["title_cache"]), read_config_option("max_title_graph"))) : title_trim(htmlspecialchars($graph["title_cache"]), read_config_option("max_title_graph"))) . "</a>", $graph["local_graph_id"]);
            form_selectable_cell($graph["local_graph_id"], $graph["local_graph_id"]);
            form_selectable_cell(get_request_var_request("filter") != "" ? preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $template_name) : $template_name, $graph["local_graph_id"]);
            form_selectable_cell($graph["height"] . "x" . $graph["width"], $graph["local_graph_id"]);
            form_checkbox_cell($graph["title_cache"], $graph["local_graph_id"]);
            form_end_row();
        }
        /* put the nav bar on the bottom as well */
        print $nav;
    } else {
        print "<tr><td><em>No Graphs Found</em></td></tr>";
    }
    html_end_box(false);
    /* add a list of tree names to the actions dropdown */
    add_tree_names_to_actions_array();
    /* draw the dropdown containing a list of available actions for this form */
    draw_actions_dropdown($graph_actions);
    print "</form>\n";
}