YOU DO NOT HAVE RIGHTS FOR TREE VIEW"; exit; } /* if cacti's builtin authentication is turned on then make sure to take graph permissions into account here. if a user does not have rights to a particular graph; do not show it. they will get an access denied message if they try and view the graph directly. */ $access_denied = false; $tree_parameters = array(); if ((!isset($_GET["tree_id"])) && (isset($_SESSION['dhtml_tree']))) { unset($_SESSION["dhtml_tree"]); } if (isset($_GET["tree_id"])) { $_SESSION["sess_graph_view_last_tree"] = get_browser_query_string(); } $tree_dropdown_html = draw_tree_dropdown((isset($_GET["tree_id"]) ? $_GET["tree_id"] : "0")); /* don't even print the table if there is not >1 tree */ if ((!empty($tree_dropdown_html)) && (read_graph_config_option("default_tree_view_mode") == "1")) { print " $tree_dropdown_html
\n"; } if (isset($_SESSION["sess_view_tree_id"])) { if (read_config_option("auth_method") != 0) { /* take tree permissions into account here, if the user does not have permission give an "access denied" message */ $access_denied = !(is_tree_allowed($_SESSION["sess_view_tree_id"])); if ($access_denied == true) { print "ACCESS DENIED"; exit; } } if (read_graph_config_option("default_tree_view_mode") == "1") { grow_graph_tree($_SESSION["sess_view_tree_id"], (!empty($start_branch) ? $start_branch : 0), isset($_SESSION["sess_user_id"]) ? $_SESSION["sess_user_id"] : 0, $tree_parameters); }elseif (read_graph_config_option("default_tree_view_mode") == "2") { grow_right_pane_tree((isset($_GET["tree_id"]) ? $_GET["tree_id"] : 0), (isset($_GET["leaf_id"]) ? $_GET["leaf_id"] : 0), (isset($_GET["host_group_data"]) ? urldecode($_GET["host_group_data"]) : 0)); } } break; case 'preview': define("ROWS_PER_PAGE", read_graph_config_option("preview_graphs_per_page")); /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("host_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")); } $sql_or = ""; $sql_where = ""; $sql_join = ""; if ((read_config_option("auth_method") != 0) && (empty($current_user["show_preview"]))) { print "YOU DO NOT HAVE RIGHTS FOR PREVIEW VIEW"; exit; } /* 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"); kill_session_var("sess_graph_view_host"); unset($_REQUEST["page"]); unset($_REQUEST["filter"]); unset($_REQUEST["host_id"]); 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("host_id", "sess_graph_view_host", "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"); /* 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 (get_request_var_request("style") == "selective") { /* process selected graphs */ if (! empty($_REQUEST["graph_list"])) { foreach (explode(",",$_REQUEST["graph_list"]) as $item) { $graph_list[$item] = 1; } }else{ $graph_list = array(); } if (! empty($_REQUEST["graph_add"])) { foreach (explode(",",$_REQUEST["graph_add"]) as $item) { $graph_list[$item] = 1; } } /* remove items */ if (! empty($_REQUEST["graph_remove"])) { foreach (explode(",",$_REQUEST["graph_remove"]) as $item) { unset($graph_list[$item]); } } $i = 0; foreach ($graph_list as $item => $value) { $graph_array[$i] = $item; $i++; } if ((isset($graph_array)) && (sizeof($graph_array) > 0)) { /* build sql string including each graph the user checked */ $sql_or = "AND " . array_to_sql_or($graph_array, "graph_templates_graph.local_graph_id"); /* clear the filter vars so they don't affect our results */ $_REQUEST["filter"] = ""; $_REQUEST["host_id"] = "0"; $set_rra_id = empty($rra_id) ? read_graph_config_option("default_rra_id") : get_request_var_request("rra_id"); } } } $sql_base = "FROM (graph_templates_graph,graph_local) $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["host_id"]) ? "" : " and graph_local.host_id=" . get_request_var_request("host_id")) . " " . (empty($_REQUEST["graph_template_id"]) ? "" : " and graph_local.graph_template_id=" . get_request_var_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 * (get_request_var_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*(get_request_var_request("page")-1)) . "," . ROWS_PER_PAGE); /* include graph view filter selector */ html_start_box("Graph Filters", "100%", $colors["header"], "3", "center", ""); ?> " class="noprint">
 Host:   Template:   Search:  ">  
" class="noprint">
 Presets:   From:      To:         
", basename($_SERVER["PHP_SELF"]) . "?" . $_SERVER["QUERY_STRING"]); }else{ $nav_url = basename($_SERVER["PHP_SELF"]) . "?" . $_SERVER["QUERY_STRING"] . "&page=&host_id=" . get_request_var_request("host_id"); } $nav_url = ereg_replace("((\?|&)host_id=[0-9]+|(\?|&)filter=[a-zA-Z0-9]*)", "", $nav_url); html_start_box("", "100%", $colors["header"], "1", "center", ""); html_nav_bar($colors["header"], read_graph_config_option("num_columns"), get_request_var_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()); } html_nav_bar($colors["header"], read_graph_config_option("num_columns"), get_request_var_request("page"), ROWS_PER_PAGE, $total_rows, $nav_url); html_end_box(); break; case 'list': if ((read_config_option("auth_method") != 0) && (empty($current_user["show_list"]))) { print "YOU DO NOT HAVE RIGHTS FOR LIST VIEW"; exit; } /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("host_id")); input_validate_input_number(get_request_var_request("graph_template_id")); 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_request("filter")); } /* reset the graph list on a new viewing */ if (!isset($_REQUEST["page"])) { $_REQUEST["graph_list"] = ""; $_REQUEST["page"] = 1; } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { kill_session_var("sess_graph_view_list_current_page"); kill_session_var("sess_graph_view_list_filter"); kill_session_var("sess_graph_view_list_host"); kill_session_var("sess_graph_view_list_graph_template"); kill_session_var("sess_graph_view_list_rows"); kill_session_var("sess_graph_view_list_graph_list"); unset($_REQUEST["page"]); unset($_REQUEST["rows"]); unset($_REQUEST["filter"]); unset($_REQUEST["host_id"]); unset($_REQUEST["graph_template_id"]); unset($_REQUEST["graph_list"]); unset($_REQUEST["graph_add"]); unset($_REQUEST["graph_remove"]); }else{ /* if any of the settings changed, reset the page number */ $changed = false; $changed += check_changed("host_id", "sess_graphs_view_list_host"); $changed += check_changed("rows", "sess_graphs_view_list_rows"); $changed += check_changed("graph_template_id", "sess_graphs_view_list_graph_template"); $changed += check_changed("filter", "sess_graphs_view_list_filter"); if ($changed) $_REQUEST["page"] = 1; } load_current_session_value("host_id", "sess_graph_view_list_host", "0"); load_current_session_value("graph_template_id", "sess_graph_view_list_graph_template", "0"); load_current_session_value("filter", "sess_graph_view_list_filter", ""); load_current_session_value("page", "sess_graph_view_list_current_page", "1"); load_current_session_value("rows", "sess_graph_view_list_rows", "-1"); load_current_session_value("graph_list", "sess_graph_view_list_graph_list", ""); /* save selected graphs into url */ 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]); } } /* update the revised graph list session variable */ $_REQUEST["graph_list"] = implode(",", array_keys($graph_list)); load_current_session_value("graph_list", "sess_graph_view_list_graph_list", ""); // debugging //echo "GraphList:" . (strlen($_REQUEST["graph_list"]) ? $_REQUEST["graph_list"]:"-") . ", GraphRemove:" . (isset($_REQUEST["graph_remove"]) && strlen($_REQUEST["graph_remove"]) ? $_REQUEST["graph_remove"]:"-") . ", GraphAdd:" . (isset($_REQUEST["graph_add"]) && strlen($_REQUEST["graph_add"]) ? $_REQUEST["graph_add"]:"-"); $nav_url = "graph_view.php?action=list&page="; /* display graph view filter selector */ html_start_box("Graph Filters", "100%", $colors["header"], "3", "center", ""); ?> ">
 Host:   Template:   Graphs per Page:   Search:  ">  
0 and graph_templates_graph.local_graph_id=graph_local.id and graph_templates_graph.title_cache like '%" . $_REQUEST["filter"] . "%' " . (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 graph_templates_graph.local_graph_id $sql_base")); $graphs = db_fetch_assoc("select graph_templates_graph.local_graph_id, graph_templates_graph.title_cache, graph_templates_graph.height, graph_templates_graph.width $sql_base group by graph_templates_graph.local_graph_id order by graph_templates_graph.title_cache limit " . ($_REQUEST["rows"]*($_REQUEST["page"]-1)) . "," . $_REQUEST["rows"]); ?>
<< " . (get_request_var_request("page") > 1 ? "":"") . "Previous" . (get_request_var_request("page") > 1 ? "":"") . " Showing Rows " . (($_REQUEST["rows"]*(get_request_var_request("page")-1))+1) . " to " . ((($total_rows < $_REQUEST["rows"]) || ($total_rows < ($_REQUEST["rows"]*get_request_var_request("page")))) ? $total_rows : ($_REQUEST["rows"]*get_request_var_request("page"))) . " of " . $total_rows . " " . ((get_request_var_request("page") * $_REQUEST["rows"]) < $total_rows ? "":"") . "Next" . ((get_request_var_request("page") * $_REQUEST["rows"]) < $total_rows ? "":"") . " >>
"; html_start_box("", "100%", $colors["header"], "1", "center", ""); print $nav; html_header_checkbox(array("Graph Title", "Graph Size")); $i = 0; if (sizeof($graphs)) { foreach ($graphs as $graph) { form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $graph["local_graph_id"]); $i++; form_selectable_cell("" . $graph["title_cache"] . "", $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(); } } print $nav; html_end_box(); ?>