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"] . "))"; if ($current_user["policy_hosts"] == "1") { $sql_where = "AND !(user_auth_perms.user_id IS NOT NULL AND graph_tree_items.host_id>0)"; } elseif ($current_user["policy_hosts"] == "2") { $sql_where = "AND !(user_auth_perms.user_id IS NULL AND graph_tree_items.host_id>0)"; } if (sizeof($tree_list) > 0) { foreach ($tree_list as $tree) { if (read_config_option("export_tree_isolation") == "on" && $tree_id == $tree["id"] || read_config_option("export_tree_isolation") == "off") { $i++; $hier_sql = "SELECT DISTINCT\n\t\t\t\t\tgraph_tree_items.id,\n\t\t\t\t\tgraph_tree_items.title,\n\t\t\t\t\tgraph_tree_items.order_key,\n\t\t\t\t\tgraph_tree_items.host_id,\n\t\t\t\t\tgraph_tree_items.host_grouping_type,\n\t\t\t\t\thost.description as hostname\n\t\t\t\t\tFROM (graph_tree_items, graph_templates_graph)\n\t\t\t\t\tLEFT JOIN host ON (host.id=graph_tree_items.host_id)\n\t\t\t\t\tLEFT JOIN graph_templates ON (graph_templates_graph.graph_template_id=graph_templates.id)\n\t\t\t\t\t{$sql_join}\n\t\t\t\t\tWHERE graph_tree_items.graph_tree_id=" . $tree["id"] . "\n\t\t\t\t\t{$sql_where}\n\t\t\t\t\tAND graph_tree_items.local_graph_id = 0\n\t\t\t\t\tORDER BY graph_tree_items.order_key"; $hierarchy = db_fetch_assoc($hier_sql); $dhtml_tree_id = 0; if (sizeof($hierarchy) > 0) { foreach ($hierarchy 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> " . $leaf["hostname"] . "\", \"" . 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\n\t\t\t\t\t\t\t\t\tgraph_templates.id,\n\t\t\t\t\t\t\t\t\tgraph_templates.name,\n\t\t\t\t\t\t\t\t\tgraph_templates_graph.local_graph_id,\n\t\t\t\t\t\t\t\t\tgraph_templates_graph.title_cache\n\t\t\t\t\t\t\t\t\tFROM (graph_local,graph_templates,graph_templates_graph)\n\t\t\t\t\t\t\t\t\tWHERE graph_local.id=graph_templates_graph.local_graph_id\n\t\t\t\t\t\t\t\t\tAND graph_templates_graph.graph_template_id=graph_templates.id\n\t\t\t\t\t\t\t\t\tAND graph_local.host_id=" . $leaf["host_id"] . "\n\t\t\t\t\t\t\t\t\tAND graph_templates_graph.export='on'\n\t\t\t\t\t\t\t\t\tGROUP BY graph_templates.id\n\t\t\t\t\t\t\t\t\tORDER 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\n\t\t\t\t\t\t\t\t\tsnmp_query.id,\n\t\t\t\t\t\t\t\t\tsnmp_query.name\n\t\t\t\t\t\t\t\t\tFROM (graph_local,snmp_query)\n\t\t\t\t\t\t\t\t\tWHERE graph_local.snmp_query_id=snmp_query.id\n\t\t\t\t\t\t\t\t\tAND graph_local.host_id=" . $leaf["host_id"] . "\n\t\t\t\t\t\t\t\t\tGROUP BY snmp_query.id\n\t\t\t\t\t\t\t\t\tORDER 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(\"" . $leaf["title"] . "\", \"" . clean_up_export_name(get_tree_name($tree["id"]) . "_" . $leaf["title"] . "_" . $leaf["id"]) . "_leaf.html\"))\n"; } } } else { 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"; $i++; } } } } } return $dhtml_tree; }
<?php $no_http_headers = true; include "../include/global.php"; include "../lib/tree.php"; $trees = db_fetch_assoc("select id from graph_tree"); if (sizeof($trees) > 0) { foreach ($trees as $tree) { $tree_items = db_fetch_assoc("select \n\t\t\tgraph_tree_items.id,\n\t\t\tgraph_tree_items.order_key\n\t\t\tfrom graph_tree_items\n\t\t\twhere graph_tree_items.graph_tree_id='" . $tree["id"] . "'\n\t\t\torder by graph_tree_items.order_key"); if (sizeof($tree_items) > 0) { $_tier = 0; foreach ($tree_items as $tree_item) { $tier = tree_tier($tree_item["order_key"], 2); /* back off */ if ($tier < $_tier) { for ($i = $_tier; $i > $tier; $i--) { print "reset ctr = {$i}\n"; $tier_counter[$i] = 0; } } /* we key tier==0 off of '1' and tier>0 off of '0' */ if (!isset($tier_counter[$tier])) { $tier_counter[$tier] = 1; } else { $tier_counter[$tier]++; } $search_key = preg_replace("/0+\$/", "", $tree_item["order_key"]); if (strlen($search_key) % 2 != 0) { $search_key .= "0"; } $new_search_key = "";
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>"; }
function create_dhtml_tree_export($tree_id) { /* record start time */ list($micro, $seconds) = explode(" ", microtime()); $start = $seconds + $micro; $search_key = ""; $dhtml_tree = array(); $dhtml_tree[0] = $start; $dhtml_tree[1] = read_graph_config_option("expand_hosts"); $i = 1; $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"] . "))"; if ($current_user["policy_hosts"] == "1") { $sql_where = "AND !(user_auth_perms.user_id IS NOT NULL AND graph_tree_items.host_id>0)"; } elseif ($current_user["policy_hosts"] == "2") { $sql_where = "AND !(user_auth_perms.user_id IS NULL AND graph_tree_items.host_id>0)"; } if (sizeof($tree_list) > 0) { foreach ($tree_list as $tree) { if (read_config_option("export_tree_isolation") == "on" && $tree_id == $tree["id"] || read_config_option("export_tree_isolation") == "off") { $hier_sql = "SELECT DISTINCT\n\t\t\t\t\tgraph_tree_items.id,\n\t\t\t\t\tgraph_tree_items.title,\n\t\t\t\t\tgraph_tree_items.order_key,\n\t\t\t\t\tgraph_tree_items.host_id,\n\t\t\t\t\tgraph_tree_items.host_grouping_type,\n\t\t\t\t\thost.description as hostname\n\t\t\t\t\tFROM (graph_tree_items, graph_templates_graph)\n\t\t\t\t\tLEFT JOIN host ON (host.id=graph_tree_items.host_id)\n\t\t\t\t\tLEFT JOIN graph_templates ON (graph_templates_graph.graph_template_id=graph_templates.id)\n\t\t\t\t\t{$sql_join}\n\t\t\t\t\tWHERE graph_tree_items.graph_tree_id=" . $tree["id"] . "\n\t\t\t\t\t{$sql_where}\n\t\t\t\t\tAND graph_tree_items.local_graph_id = 0\n\t\t\t\t\tORDER BY graph_tree_items.order_key"; $hierarchy = db_fetch_assoc($hier_sql); $dhtml_tree_id = 0; if (sizeof($hierarchy) > 0) { $last_tier = 1; $openli = false; $lasthost = false; $opentree = false; foreach ($hierarchy as $leaf) { if ($dhtml_tree_id != $tree["id"]) { if ($opentree) { $i++; $dhtml_tree[$i] = "\t\t\t</ul>\n\t\t</li>\n\t</ul>\n"; } $i++; $clean_id = clean_up_export_name(get_tree_name($tree["id"]) . "_" . $tree['id']); $dhtml_tree[$i] = "\t<ul>\n\t\t<li id='{$clean_id}'><a href='" . $clean_id . ".html'>" . get_tree_name($tree["id"]) . "</a>\n\t\t\t<ul>\n"; $opentree = true; } $dhtml_tree_id = $tree["id"]; $tier = tree_tier($leaf["order_key"]); if ($leaf["host_id"] > 0) { //It's a host if ($tier > $last_tier) { $i++; $dhtml_tree[$i] = "\t\t\t<ul>\n"; } elseif ($tier < $last_tier) { if (!$lasthost) { $i++; $dhtml_tree[$i] = "\t\t\t\t</li>\n"; } for ($x = $tier; $x < $last_tier; $x++) { $i++; $dhtml_tree[$i] = "\t\t\t</ul>\n\t\t\t\t</li>\n"; $openli = false; } } elseif ($openli && !$lasthost) { $i++; $dhtml_tree[$i] = "\t\t\t\t</li>\n"; $openli = false; } $last_tier = $tier; $lasthost = true; $i++; $clean_id = clean_up_export_name($leaf["hostname"] . "_" . $leaf["id"]); $dhtml_tree[$i] = "\t\t\t\t<li id='{$clean_id}' data-jstree='{ \"icon\" : \"./server.png\" }'><a href=\"" . $clean_id . ".html\">Host: " . htmlspecialchars($leaf["hostname"]) . "</a>\n"; if (read_config_option("export_tree_expand_hosts") == "on") { $i++; $dhtml_tree[$i] = "\t\t\t\t\t<ul>\n"; if ($leaf["host_grouping_type"] == HOST_GROUPING_GRAPH_TEMPLATE) { $graph_templates = db_fetch_assoc("SELECT\n\t\t\t\t\t\t\t\t\tgraph_templates.id,\n\t\t\t\t\t\t\t\t\tgraph_templates.name,\n\t\t\t\t\t\t\t\t\tgraph_templates_graph.local_graph_id,\n\t\t\t\t\t\t\t\t\tgraph_templates_graph.title_cache\n\t\t\t\t\t\t\t\t\tFROM (graph_local,graph_templates,graph_templates_graph)\n\t\t\t\t\t\t\t\t\tWHERE graph_local.id=graph_templates_graph.local_graph_id\n\t\t\t\t\t\t\t\t\tAND graph_templates_graph.graph_template_id=graph_templates.id\n\t\t\t\t\t\t\t\t\tAND graph_local.host_id=" . $leaf["host_id"] . "\n\t\t\t\t\t\t\t\t\tAND graph_templates_graph.export='on'\n\t\t\t\t\t\t\t\t\tGROUP BY graph_templates.id\n\t\t\t\t\t\t\t\t\tORDER BY graph_templates.name"); if (sizeof($graph_templates) > 0) { foreach ($graph_templates as $graph_template) { $i++; $clean_id = clean_up_export_name($leaf["hostname"] . "_gt_" . $leaf["id"] . "_" . $graph_template["id"]); $dhtml_tree[$i] = "\t\t\t\t\t\t<li id='" . $clean_id . "' data-jstree='{ \"icon\" : \"./server_chart.png\" }'><a href=\"" . $clean_id . ".html\">" . htmlspecialchars($graph_template["name"]) . "</a></li>\n"; } } } else { if ($leaf["host_grouping_type"] == HOST_GROUPING_DATA_QUERY_INDEX) { $data_queries = db_fetch_assoc("SELECT\n\t\t\t\t\t\t\t\t\tsnmp_query.id,\n\t\t\t\t\t\t\t\t\tsnmp_query.name\n\t\t\t\t\t\t\t\t\tFROM (graph_local,snmp_query)\n\t\t\t\t\t\t\t\t\tWHERE graph_local.snmp_query_id=snmp_query.id\n\t\t\t\t\t\t\t\t\tAND graph_local.host_id=" . $leaf["host_id"] . "\n\t\t\t\t\t\t\t\t\tGROUP BY snmp_query.id\n\t\t\t\t\t\t\t\t\tORDER BY snmp_query.name"); array_push($data_queries, array("id" => "0", "name" => "Non Query Based")); if (sizeof($data_queries) > 0) { foreach ($data_queries as $data_query) { $i++; $clean_id = clean_up_export_name($leaf["hostname"] . "_dq_" . $leaf["title"] . "_" . $leaf["id"] . "_" . $data_query["id"]); if ($data_query['name'] != 'Non Query Based') { $dhtml_tree[$i] = "\t\t\t\t\t\t<li id='" . $clean_id . "' data-jstree='{ \"icon\" : \"./server_dataquery.png\" }'><a href=\"" . $clean_id . ".html\">" . htmlspecialchars($data_query["name"]) . "</a>\n"; } else { $dhtml_tree[$i] = "\t\t\t\t\t\t<li id='" . $clean_id . "' data-jstree='{ \"icon\" : \"./server_chart.png\" }'><a href=\"" . $clean_id . ".html\">" . htmlspecialchars($data_query["name"]) . "</a>\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) { $i++; $dhtml_tree[$i] = "\t\t\t\t\t\t\t<ul>\n"; while (list($snmp_index, $sort_field_value) = each($sort_field_data)) { $i++; $clean_id = clean_up_export_name($leaf["hostname"] . "_dqi_" . $leaf["id"] . "_" . $data_query["id"] . "_" . $snmp_index); $dhtml_tree[$i] = "\t\t\t\t\t\t\t\t<li id='" . $clean_id . "' data-jstree='{ \"icon\" : \"./server_chart_curve.png\" }'><a href=\"" . $clean_id . ".html\">" . htmlspecialchars($sort_field_value) . "</a></li>\n"; } $i++; $dhtml_tree[$i] = "\t\t\t\t\t\t\t</ul>\n"; } $i++; $dhtml_tree[$i] = "\t\t\t\t\t\t</li>\n"; } } } } $i++; $dhtml_tree[$i] = "\t\t\t\t\t</ul>\n"; } $i++; $dhtml_tree[$i] = "\t\t\t\t</li>\n"; } else { //It's not a host if ($tier > $last_tier) { $i++; $dhtml_tree[$i] = "\t\t\t<ul>\n"; } elseif ($tier < $last_tier) { if (!$lasthost) { $i++; $dhtml_tree[$i] = "</li>\n"; } for ($x = $tier; $x < $last_tier; $x++) { $i++; $dhtml_tree[$i] = "\t\t\t\t</ul>\n\t\t\t\t</li>\n"; $openli = false; } } elseif ($openli && !$lasthost) { $i++; $dhtml_tree[$i] = "</li>\n"; $openli = false; } $last_tier = $tier; $i++; $clean_id = clean_up_export_name(get_tree_name($tree["id"]) . "_" . $leaf["title"] . "_" . $leaf["id"]); $dhtml_tree[$i] = "\t\t\t\t<li id=\"" . $clean_id . "\"><a href=\"" . $clean_id . ".html\">" . htmlspecialchars($leaf["title"]) . "</a>\n"; $openli = true; $lasthost = false; } } for ($x = $last_tier; $x > 1; $x--) { $i++; $dhtml_tree[$i] = "\t\t\t\t\t</ul>\n\t\t\t\t</li>\n"; } $i++; $dhtml_tree[$i] = "\t\t\t</ul>\n\t\t</li>\n\t</ul>\n"; } else { if ($dhtml_tree_id != $tree["id"]) { $i++; $clean_id = clean_up_export_name(get_tree_name($tree["id"]) . "_" . $tree['id']); $dhtml_tree[$i] = "\t<ul>\n\t\t<li id=\"" . $clean_id . "\"><a href=\"" . $clean_id . ".html\">" . get_tree_name($tree["id"]) . "</a></li>\n\t</ul>"; } } } } } return $dhtml_tree; }
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;'> <strong>Presets:</strong> </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;'> <strong>From:</strong> </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;'> <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;'> <strong>To:</strong> </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;'> <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;'> <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;'> <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;'> <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;'> <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> Search:</strong> </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"> <strong>Graphs per Page:</strong> </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> Thumbnails: </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> <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><< "; 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 .= " >></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(); }
function upgrade_to_0_8_6() { include "../lib/data_query.php"; include "../lib/tree.php"; include "../lib/import.php"; include "../lib/poller.php"; db_install_execute("0.8.6", "DROP TABLE `snmp_query_field`;"); db_install_execute("0.8.6", "DROP TABLE `data_input_data_cache`;"); db_install_execute("0.8.6", "DROP TABLE `data_input_data_fcache`;"); /* distributed poller support */ db_install_execute("0.8.6", "CREATE TABLE `poller` (`id` smallint(5) unsigned NOT NULL auto_increment, `hostname` varchar(250) NOT NULL default '', `ip_address` int(11) unsigned NOT NULL default '0', `last_update` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (`id`)) TYPE=MyISAM;"); db_install_execute("0.8.6", "CREATE TABLE `poller_command` (`poller_id` smallint(5) unsigned NOT NULL default '0', `time` datetime NOT NULL default '0000-00-00 00:00:00', `action` tinyint(3) unsigned NOT NULL default '0', `command` varchar(200) NOT NULL default '', PRIMARY KEY (`poller_id`,`action`,`command`)) TYPE=MyISAM;"); db_install_execute("0.8.6", "CREATE TABLE `poller_item` (`local_data_id` mediumint(8) unsigned NOT NULL default '0', `poller_id` smallint(5) unsigned NOT NULL default '0', `host_id` mediumint(8) NOT NULL default '0', `action` tinyint(2) unsigned NOT NULL default '1', `hostname` varchar(250) NOT NULL default '', `snmp_community` varchar(100) NOT NULL default '', `snmp_version` tinyint(1) unsigned NOT NULL default '0', `snmp_username` varchar(50) NOT NULL default '', `snmp_password` varchar(50) NOT NULL default '', `snmp_port` mediumint(5) unsigned NOT NULL default '161', `snmp_timeout` mediumint(8) unsigned NOT NULL default '0', `rrd_name` varchar(19) NOT NULL default '', `rrd_path` varchar(255) NOT NULL default '', `rrd_num` tinyint(2) unsigned NOT NULL default '0', `arg1` varchar(255) default NULL, `arg2` varchar(255) default NULL, `arg3` varchar(255) default NULL, PRIMARY KEY (`local_data_id`,`rrd_name`), KEY `local_data_id` (`local_data_id`), KEY `host_id` (`host_id`)) TYPE=MyISAM;"); db_install_execute("0.8.6", "CREATE TABLE `poller_output` (`local_data_id` mediumint(8) unsigned NOT NULL default '0', `rrd_name` varchar(19) NOT NULL default '', `time` datetime NOT NULL default '0000-00-00 00:00:00', `output` text NOT NULL, PRIMARY KEY (`local_data_id`,`rrd_name`,`time`)) TYPE=MyISAM;"); db_install_execute("0.8.6", "CREATE TABLE `poller_reindex` (`host_id` mediumint(8) unsigned NOT NULL default '0', `data_query_id` mediumint(8) unsigned NOT NULL default '0', `action` tinyint(3) unsigned NOT NULL default '0', `op` char(1) NOT NULL default '', `assert_value` varchar(100) NOT NULL default '', `arg1` varchar(100) NOT NULL default '', PRIMARY KEY (`host_id`,`data_query_id`,`arg1`)) TYPE=MyISAM;"); db_install_execute("0.8.6", "CREATE TABLE `poller_time` (`id` mediumint(8) unsigned NOT NULL auto_increment, `poller_id` smallint(5) unsigned NOT NULL default '0', `start_time` datetime NOT NULL default '0000-00-00 00:00:00', `end_time` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (`id`)) TYPE=MyISAM;"); db_install_execute("0.8.6", "ALTER TABLE `graph_tree_items` ADD `host_grouping_type` TINYINT( 3 ) UNSIGNED DEFAULT '1' NOT NULL, ADD `sort_children_type` TINYINT( 3 ) UNSIGNED DEFAULT '1' NOT NULL;"); db_install_execute("0.8.6", "ALTER TABLE `host_snmp_query` ADD `sort_field` VARCHAR( 50 ) NOT NULL, ADD `title_format` VARCHAR( 50 ) NOT NULL, ADD `reindex_method` TINYINT( 3 ) UNSIGNED DEFAULT '1' NOT NULL;"); db_install_execute("0.8.6", "ALTER TABLE `graph_tree` CHANGE `user_id` `sort_type` TINYINT( 3 ) UNSIGNED DEFAULT '1' NOT NULL;"); db_install_execute("0.8.6", "ALTER TABLE `graph_tree_items` CHANGE `order_key` `order_key` VARCHAR( 100 ) DEFAULT '0' NOT NULL;"); db_install_execute("0.8.6", "ALTER TABLE `host` ADD `status_event_count` mediumint(8) unsigned NOT NULL default '0', ADD `status_fail_date` datetime NOT NULL default '0000-00-00 00:00:00', ADD `status_rec_date` datetime NOT NULL default '0000-00-00 00:00:00', ADD `status_last_error` varchar(50) default '', ADD `min_time` decimal(7,5) default '9.99999', ADD `max_time` decimal(7,5) default '0.00000', ADD `cur_time` decimal(7,5) default '0.00000', ADD `avg_time` decimal(7,5) default '0.00000', ADD `total_polls` int(12) unsigned default '0', ADD `failed_polls` int(12) unsigned default '0', ADD `availability` decimal(7,5) default '100.000' NOT NULL;"); db_install_execute("0.8.6", "UPDATE snmp_query_graph_rrd_sv set text = REPLACE(text,' (In)','') where snmp_query_graph_id = 2;"); db_install_execute("0.8.6", "UPDATE graph_tree set sort_type = '1';"); /* update the sort cache */ $host_snmp_query = db_fetch_assoc("select host_id,snmp_query_id from host_snmp_query"); if (sizeof($host_snmp_query) > 0) { foreach ($host_snmp_query as $item) { update_data_query_sort_cache($item["host_id"], $item["snmp_query_id"]); update_reindex_cache($item["host_id"], $item["snmp_query_id"]); } } /* script query data input methods */ $xml_data = "<cacti>\n\t\t\t<hash_030003332111d8b54ac8ce939af87a7eac0c06>\n\t\t\t\t<name>Get Script Server Data (Indexed)</name>\n\t\t\t\t<type_id>6</type_id>\n\t\t\t\t<input_string></input_string>\n\t\t\t\t<fields>\n\t\t\t\t\t<hash_070003172b4b0eacee4948c6479f587b62e512>\n\t\t\t\t\t\t<name>Index Type</name>\n\t\t\t\t\t\t<update_rra></update_rra>\n\t\t\t\t\t\t<regexp_match></regexp_match>\n\t\t\t\t\t\t<allow_nulls></allow_nulls>\n\t\t\t\t\t\t<type_code>index_type</type_code>\n\t\t\t\t\t\t<input_output>in</input_output>\n\t\t\t\t\t\t<data_name>index_type</data_name>\n\t\t\t\t\t</hash_070003172b4b0eacee4948c6479f587b62e512>\n\t\t\t\t\t<hash_07000330fb5d5bcf3d66bb5abe88596f357c26>\n\t\t\t\t\t\t<name>Index Value</name>\n\t\t\t\t\t\t<update_rra></update_rra>\n\t\t\t\t\t\t<regexp_match></regexp_match>\n\t\t\t\t\t\t<allow_nulls></allow_nulls>\n\t\t\t\t\t\t<type_code>index_value</type_code>\n\t\t\t\t\t\t<input_output>in</input_output>\n\t\t\t\t\t\t<data_name>index_value</data_name>\n\t\t\t\t\t</hash_07000330fb5d5bcf3d66bb5abe88596f357c26>\n\t\t\t\t\t<hash_07000331112c85ae4ff821d3b288336288818c>\n\t\t\t\t\t\t<name>Output Type ID</name>\n\t\t\t\t\t\t<update_rra></update_rra>\n\t\t\t\t\t\t<regexp_match></regexp_match>\n\t\t\t\t\t\t<allow_nulls></allow_nulls>\n\t\t\t\t\t\t<type_code>output_type</type_code>\n\t\t\t\t\t\t<input_output>in</input_output>\n\t\t\t\t\t\t<data_name>output_type</data_name>\n\t\t\t\t\t</hash_07000331112c85ae4ff821d3b288336288818c>\n\t\t\t\t\t<hash_0700035be8fa85472d89c621790b43510b5043>\n\t\t\t\t\t\t<name>Output Value</name>\n\t\t\t\t\t\t<update_rra>on</update_rra>\n\t\t\t\t\t\t<regexp_match></regexp_match>\n\t\t\t\t\t\t<allow_nulls></allow_nulls>\n\t\t\t\t\t\t<type_code></type_code>\n\t\t\t\t\t\t<input_output>out</input_output>\n\t\t\t\t\t\t<data_name>output</data_name>\n\t\t\t\t\t</hash_0700035be8fa85472d89c621790b43510b5043>\n\t\t\t\t</fields>\n\t\t\t</hash_030003332111d8b54ac8ce939af87a7eac0c06>\n\t\t</cacti>"; import_xml_data($xml_data); /* update trees to three characters per tier */ $trees = db_fetch_assoc("select id from graph_tree"); if (sizeof($trees) > 0) { foreach ($trees as $tree) { $tree_items = db_fetch_assoc("select\n\t\t\t\tgraph_tree_items.id,\n\t\t\t\tgraph_tree_items.order_key\n\t\t\t\tfrom graph_tree_items\n\t\t\t\twhere graph_tree_items.graph_tree_id='" . $tree["id"] . "'\n\t\t\t\torder by graph_tree_items.order_key"); if (sizeof($tree_items) > 0) { $_tier = 0; /* only do the upgrade once */ if ($tree_items[0]["order_key"] == "001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") { return; } foreach ($tree_items as $tree_item) { $tier = tree_tier($tree_item["order_key"], 2); /* back off */ if ($tier < $_tier) { for ($i = $_tier; $i > $tier; $i--) { $tier_counter[$i] = 0; } } /* we key tier==0 off of '1' and tier>0 off of '0' */ if (!isset($tier_counter[$tier])) { $tier_counter[$tier] = 1; } else { $tier_counter[$tier]++; } $search_key = preg_replace("/0+\$/", "", $tree_item["order_key"]); if (strlen($search_key) % 2 != 0) { $search_key .= "0"; } $new_search_key = ""; for ($i = 1; $i < $tier; $i++) { $new_search_key .= str_pad(strval($tier_counter[$i]), 3, '0', STR_PAD_LEFT); } /* build the new order key string */ $key = str_pad($new_search_key . str_pad(strval($tier_counter[$tier]), 3, '0', STR_PAD_LEFT), 90, '0', STR_PAD_RIGHT); db_execute("update graph_tree_items set order_key='{$key}' where id=" . $tree_item["id"]); $_tier = $tier; } } } } }
function item_remove() { /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); input_validate_input_number(get_request_var("tree_id")); /* ==================================================== */ /* modify for multi user start */ if (!check_tree_item($_GET["id"])) { access_denied(); } /* modify for multi user end */ if (read_config_option("deletion_verification") == "on" && !isset($_GET["confirm"])) { $graph_tree_item = db_fetch_row("select title,local_graph_id,host_id from graph_tree_items where id=" . $_GET["id"]); if (!empty($graph_tree_item["local_graph_id"])) { $text = "Are you sure you want to delete the graph item <strong>'" . db_fetch_cell("select title_cache from graph_templates_graph where local_graph_id=" . $graph_tree_item["local_graph_id"]) . "'</strong>?"; } elseif ($graph_tree_item["title"] != "") { $text = "Are you sure you want to delete the header item <strong>'" . $graph_tree_item["title"] . "'</strong>?"; } elseif (!empty($graph_tree_item["host_id"])) { $text = "Are you sure you want to delete the host item <strong>'" . db_fetch_cell("select CONCAT_WS('',description,' (',hostname,')') as hostname from host where id=" . $graph_tree_item["host_id"]) . "'</strong>?"; } include "./include/top_header.php"; form_confirm("Are You Sure?", $text, htmlspecialchars("tree.php?action=edit&id=" . $_GET["tree_id"]), htmlspecialchars("tree.php?action=item_remove&id=" . $_GET["id"] . "&tree_id=" . $_GET["tree_id"])); include "./include/bottom_footer.php"; exit; } if (read_config_option("deletion_verification") == "" || isset($_GET["confirm"])) { /* modify for multi user start */ if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) { $tree_item = db_fetch_row("SELECT graph_tree_id,local_graph_id,title,host_id,order_key FROM graph_tree_items WHERE id = '" . $_GET["id"] . "'"); // public graph if ($tree_item["graph_tree_id"] == $_SESSION["public_tree_id"] && $tree_item["local_graph_id"] > 0) { db_execute("DELETE FROM user_auth_perms WHERE user_id = '" . $_SESSION["sess_user_id"] . "' AND item_id = '" . $tree_item["local_graph_id"] . "' AND type = '1'"); // remove all reference favorites graph $rows = db_fetch_assoc("SELECT graph_tree_items.id FROM graph_tree_items WHERE graph_tree_id != '" . $_SESSION["private_tree_id"] . "' AND local_graph_id = '" . $tree_item["local_graph_id"] . "'"); foreach ($rows as $row) { delete_branch($row["id"]); } // private device (re-entry host tree_item) } elseif ($tree_item["graph_tree_id"] == $_SESSION["private_tree_id"] && $tree_item["host_id"] > 0) { exec("php ./cli/add_tree.php --type=node --node-type=host --tree-id=" . $_SESSION["private_tree_id"] . " --host-id=" . $tree_item["host_id"] . " --host-group-style=1"); // private header (re-entry host tree_item) } elseif ($tree_item["graph_tree_id"] == $_SESSION["private_tree_id"] && $tree_item["title"] != "") { $tier = tree_tier($tree_item["order_key"]); $order_key = substr($tree_item["order_key"], 0, $tier * CHARS_PER_TIER); $rows = db_fetch_assoc("SELECT host_id FROM graph_tree_items WHERE graph_tree_id = '" . $_SESSION["private_tree_id"] . "' AND host_id > 0 AND order_key LIKE '" . $order_key . "%'"); foreach ($rows as $row) { exec("php ./cli/add_tree.php --type=node --node-type=host --tree-id=" . $_SESSION["private_tree_id"] . " --host-id=" . $row["host_id"] . " --host-group-style=1"); } } } /* modify for multi user end */ delete_branch($_GET["id"]); } /* clear graph tree cache on save - affects current user only, other users should see changes in <5 minutes */ if (isset($_SESSION['dhtml_tree'])) { unset($_SESSION['dhtml_tree']); } header("Location: tree.php?action=edit&id=" . $_GET["tree_id"]); exit; }
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><<<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>>></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(); }
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'> <strong>Presets:</strong> </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'> <strong>From:</strong> </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"] : "");?>'> <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');"> </td> <td nowrap style='white-space: nowrap;' width='20'> <strong>To:</strong> </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"] : "");?>'> <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;'> <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;'> <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> Search:</strong> </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"> <strong>Graphs per Page:</strong> </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> Thumbnails: <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> <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><< "; 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 .= " >></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>"; }
/** * 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; }
function check_tree_item($tree_item_id) { $permission = TREE_ITEM_NG; if ($_SESSION["permission"] <= ACCESS_ADMINISTRATOR) { input_validate_input_number($tree_item_id); $tree_item = db_fetch_row("SELECT graph_tree_id,local_graph_id,title,host_id,order_key FROM graph_tree_items WHERE id = '" . $tree_item_id . "'"); if (isset($tree_item)) { if ($tree_item["graph_tree_id"] == $_SESSION["public_tree_id"]) { // public graph if ($tree_item["local_graph_id"] > 0) { if (db_fetch_cell("\r\n SELECT graph_local.id FROM graph_local\r\n INNER JOIN host ON graph_local.host_id = host.id\r\n INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'\r\n WHERE graph_local.id = '" . $tree_item["local_graph_id"] . "'")) { $permission = TREE_ITEM_PUBLIC; } // header } elseif ($tree_item["title"] != "") { $tier = tree_tier($tree_item["order_key"]); $order_key = substr($tree_item["order_key"], 0, $tier * CHARS_PER_TIER); if (db_fetch_cell("SELECT COUNT(id) FROM graph_tree_items WHERE graph_tree_id = '" . $_SESSION["public_tree_id"] . "' AND local_graph_id > 0 AND order_key LIKE '" . $order_key . "%'")) { $permission = TREE_ITEM_PUBLIC; } } } elseif ($tree_item["graph_tree_id"] == $_SESSION["private_tree_id"]) { $permission = TREE_ITEM_PRIVATE; if ($tree_item["local_graph_id"] > 0) { // other graph if (!db_fetch_cell("\r\n SELECT graph_local.id FROM graph_local\r\n INNER JOIN host ON graph_local.host_id = host.id\r\n INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'\r\n WHERE graph_local.id = '" . $tree_item["local_graph_id"] . "'")) { $permission = TREE_ITEM_OTHER; } // favorites header } elseif ($tree_item["title"] === "Favorites") { $permission = TREE_ITEM_PUBLIC; } } } } else { $permission = TREE_ITEM_PRIVATE; } return $permission; }
/** displayTreeNodes * @param int $id * @param string $nodeType * @param int $parentNode * @param bool $quietMode */ function displayTreeNodes($tree_id, $nodeType = "", $parentNode = "", $quietMode = FALSE) { require(CACTI_BASE_PATH . "/include/data_query/data_query_arrays.php"); require(CACTI_BASE_PATH . "/include/graph_tree/graph_tree_arrays.php"); if (!$quietMode) { echo __("Known Tree Nodes: (type, id, parentid, text)") . "\n"; } $parentID = 0; $nodes = db_fetch_assoc("SELECT id, local_graph_id, rra_id, title, device_id, device_grouping_type, order_key, sort_children_type FROM graph_tree_items WHERE graph_tree_id=$tree_id ORDER BY order_key"); if (sizeof($nodes)) { # add tier, parent_tier and parent_id foreach ($nodes as $key => $node) { $nodes{$key}["tier"] = tree_tier($node["order_key"]); if ($nodes{$key}["tier"] == 1) { $nodes{$key}["parent_tier"] = 'N/A'; $nodes{$key}["parent_id"] = 'N/A'; }else{ $nodes{$key}["parent_tier"] = substr($nodes{$key}["order_key"], 0, (($nodes{$key}["tier"] - 1) * CHARS_PER_TIER)); $nodes{$key}["parent_id"] = db_fetch_cell("SELECT id FROM graph_tree_items WHERE order_key LIKE '" . $nodes{$key}["parent_tier"] . "%%' AND graph_tree_id=$tree_id ORDER BY order_key LIMIT 1"); } } foreach ($nodes as $node) { $current_type = TREE_ITEM_TYPE_HEADER; if ($node["local_graph_id"] > 0) { $current_type = TREE_ITEM_TYPE_GRAPH; } if ($node["title"] != "") { $current_type = TREE_ITEM_TYPE_HEADER; } if ($node["device_id"] > 0) { $current_type = TREE_ITEM_TYPE_DEVICE; } switch ($current_type) { case TREE_ITEM_TYPE_HEADER: if ($nodeType == '' || strtolower($nodeType) == strtolower($tree_item_types[TREE_ITEM_TYPE_HEADER])) { echo $tree_item_types[$current_type]."\t"; echo $node["id"]."\t"; echo $node["parent_id"]."\t"; echo $node["title"]."\t"; echo $tree_sort_types[$node["sort_children_type"]]."\t"; echo "\n"; } break; case TREE_ITEM_TYPE_GRAPH: if ($nodeType == '' || strtolower($nodeType) == strtolower($tree_item_types[TREE_ITEM_TYPE_GRAPH])) { echo $tree_item_types[$current_type]."\t"; echo $node["id"]."\t"; echo $node["parent_id"]."\t"; /* fetch the title for that graph */ $graph_title = db_fetch_cell("SELECT graph_templates_graph.title_cache as name FROM ( graph_templates_graph, graph_local) WHERE graph_local.id=graph_templates_graph.local_graph_id and local_graph_id = " . $node["local_graph_id"]); $rra = db_fetch_cell("SELECT name FROM rra WHERE id =" . $node["rra_id"]); echo $graph_title ."\t"; echo $rra . "\t"; echo "\n"; } break; case TREE_ITEM_TYPE_DEVICE: if ($nodeType == '' || strtolower($nodeType) == strtolower($tree_item_types[TREE_ITEM_TYPE_DEVICE])) { echo $tree_item_types[$current_type]."\t"; echo $node["id"]."\t"; echo $node["parent_id"]."\t"; $name = db_fetch_cell("SELECT hostname FROM device WHERE id = " . $node["device_id"]); echo $name . "\t"; echo $tree_device_group_types[$node["device_grouping_type"]]."\t"; echo "\n"; } break; } } } if (!$quietMode) { echo "\n"; } }
function displayTreeNodes($tree_id, $nodeType = "", $parentNode = "", $quietMode = FALSE) { global $tree_sort_types, $tree_item_types, $host_group_types; if (!$quietMode) { echo "Known Tree Nodes:\n"; echo "type\tid\tparentid\ttitle\tattribs\n"; } $parentID = 0; $nodes = db_fetch_assoc("SELECT\n\t\tid,\n\t\tlocal_graph_id,\n\t\trra_id,\n\t\ttitle,\n\t\thost_id,\n\t\thost_grouping_type,\n\t\torder_key,\n\t\tsort_children_type\n\t\tFROM graph_tree_items\n\t\tWHERE graph_tree_id={$tree_id}\n\t\tORDER BY order_key"); if (sizeof($nodes)) { foreach ($nodes as $node) { /* taken from tree.php, funtion item_edit() */ $current_type = TREE_ITEM_TYPE_HEADER; if ($node["local_graph_id"] > 0) { $current_type = TREE_ITEM_TYPE_GRAPH; } if ($node["title"] != "") { $current_type = TREE_ITEM_TYPE_HEADER; } if ($node["host_id"] > 0) { $current_type = TREE_ITEM_TYPE_HOST; } switch ($current_type) { case TREE_ITEM_TYPE_HEADER: $starting_tier = tree_tier($node["order_key"]); if ($starting_tier == 1) { $parentID = 0; } else { $parent_tier = substr($node["order_key"], 0, ($starting_tier - 1) * CHARS_PER_TIER); $parentID = db_fetch_cell("SELECT id FROM graph_tree_items WHERE order_key LIKE '{$parent_tier}%%' AND graph_tree_id={$tree_id} ORDER BY order_key LIMIT 1"); } if ($nodeType == '' || $nodeType == 'header') { if ($parentNode == '' || $parentNode == $parentID) { echo $tree_item_types[$current_type] . "\t"; echo $node["id"] . "\t"; if ($parentID == 0) { echo "N/A\t"; } else { echo $parentID . "\t"; } echo $node["title"] . "\t"; echo $tree_sort_types[$node["sort_children_type"]] . "\t"; echo "\n"; } } $parentID = $node["id"]; break; case TREE_ITEM_TYPE_GRAPH: if ($nodeType == '' || $nodeType == 'graph') { if ($parentNode == '' || $parentNode == $parentID) { echo $tree_item_types[$current_type] . "\t"; echo $node["id"] . "\t"; if ($parentID == 0) { echo "N/A\t"; } else { echo $parentID . "\t"; } /* fetch the title for that graph */ $graph_title = db_fetch_cell("SELECT\n\t\t\t\t\t\t\tgraph_templates_graph.title_cache as name\n\t\t\t\t\t\t\tFROM (\n\t\t\t\t\t\t\t\tgraph_templates_graph,\n\t\t\t\t\t\t\t\tgraph_local)\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\tgraph_local.id=graph_templates_graph.local_graph_id and\n\t\t\t\t\t\t\t\tlocal_graph_id = " . $node["local_graph_id"]); $rra = db_fetch_cell("SELECT\n\t\t\t\t\t\t\t\tname\n\t\t\t\t\t\t\t\tFROM rra\n\t\t\t\t\t\t\t\tWHERE id =" . $node["rra_id"]); echo $graph_title . "\t"; echo $rra . "\t"; echo "\n"; } } break; case TREE_ITEM_TYPE_HOST: if ($nodeType == '' || $nodeType == 'host') { if ($parentNode == '' || $parentNode == $parentID) { echo $tree_item_types[$current_type] . "\t"; echo $node["id"] . "\t"; if ($parentID == 0) { echo "N/A\t"; } else { echo $parentID . "\t"; } $name = db_fetch_cell("SELECT\n\t\t\t\t\t\t\thostname\n\t\t\t\t\t\t\tFROM host\n\t\t\t\t\t\t\tWHERE id = " . $node["host_id"]); echo $name . "\t"; echo $host_group_types[$node["host_grouping_type"]] . "\t"; echo "\n"; } } break; } } } if (!$quietMode) { echo "\n"; } }
function create_dhtml_tree_export($tree_id) { require(CACTI_BASE_PATH . "/include/graph_tree/graph_tree_arrays.php"); require_once(CACTI_BASE_PATH . "/include/auth/auth_constants.php"); /* record start time */ list($micro,$seconds) = explode(" ", microtime()); $start = $seconds + $micro; $search_key = ""; $dhtml_tree = array(); $dhtml_tree[0] = $start; $dhtml_tree[1] = read_graph_config_option("expand_devices"); $dhtml_tree[2] = "foldersTree = gFld(\"\", \"\")\n"; $i = 2; $tree_list = get_graph_tree_array_export(); /* auth check for devices 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 (device.id=user_auth_perms.item_id AND user_auth_perms.type=" . PERM_DEVICES . " AND user_auth_perms.user_id=" . $current_user["id"] . ")"; if ($current_user["policy_devices"] == "1") { $sql_where = "AND !(user_auth_perms.user_id IS NOT NULL AND graph_tree_items.device_id>0)"; }elseif ($current_user["policy_devices"] == "2") { $sql_where = "AND !(user_auth_perms.user_id IS NULL AND graph_tree_items.device_id>0)"; } if (sizeof($tree_list) > 0) { foreach ($tree_list as $tree) { if (((read_config_option("export_tree_isolation") == CHECKED) && ($tree_id == $tree["id"])) || (read_config_option("export_tree_isolation") == "off")) { $i++; $hier_sql = "SELECT DISTINCT graph_tree_items.id, graph_tree_items.title, graph_tree_items.order_key, graph_tree_items.device_id, graph_tree_items.device_grouping_type, device.description as hostname FROM (graph_tree_items, graph_templates_graph) LEFT JOIN device ON (device.id=graph_tree_items.device_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"; $hierarchy = db_fetch_assoc($hier_sql); $dhtml_tree_id = 0; if (sizeof($hierarchy) > 0) { foreach ($hierarchy 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["device_id"] > 0) { //It's a device $dhtml_tree[$i] = "ou" . ($tier) . " = insFld(ou" . ($tier-1) . ", gFld(\"<strong>Host:</strong> " . $leaf["hostname"] . "\", \"" . clean_up_export_name($leaf["hostname"] . "_" . $leaf["id"]) . ".html\"))\n"; if (read_config_option("export_tree_expand_devices") == CHECKED) { if ($leaf["device_grouping_type"] == TREE_DEVICE_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.device_id=" . $leaf["device_id"] . " AND graph_templates_graph.export='on' 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["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"] . " 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["device_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(\"" . $leaf["title"] . "\", \"" . clean_up_export_name(get_tree_name($tree["id"]) . "_" . $leaf["title"] . "_" . $leaf["id"]) . "_leaf.html\"))\n"; } } }else{ 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"; $i++; } } } } } return $dhtml_tree; }
function delete_branch($tree_item_id) { if (empty($tree_item_id)) { return 0; } $tree_item = db_fetch_row("select order_key,local_graph_id,host_id,graph_tree_id from graph_tree_items where id={$tree_item_id}"); /* if this item is a graph/host, it will have NO children, so we can just delete the graph and exit. */ if (!empty($tree_item["local_graph_id"]) || !empty($tree_item["host_id"])) { db_execute("delete from graph_tree_items where id={$tree_item_id}"); return 0; } /* yeah, this would be really bad */ if (empty($tree_item["order_key"])) { return 0; } $starting_tier = tree_tier($tree_item["order_key"]); $order_key = substr($tree_item["order_key"], 0, CHARS_PER_TIER * $starting_tier); $tree = db_fetch_assoc("select\n\t\tgraph_tree_items.id, graph_tree_items.order_key\n\t\tfrom graph_tree_items\n\t\twhere graph_tree_items.order_key like '{$order_key}%%'\n\t\tand graph_tree_items.graph_tree_id='" . $tree_item["graph_tree_id"] . "'\n\t\torder by graph_tree_items.order_key"); if (sizeof($tree) > 0) { foreach ($tree as $item) { /* delete the folder */ db_execute("delete from graph_tree_items where id=" . $item["id"]); } } /* CLEANUP - reorder the tier that this branch lies in */ $order_key = substr($order_key, 0, CHARS_PER_TIER * ($starting_tier - 1)); $tree = db_fetch_assoc("select\n\t\tgraph_tree_items.id, graph_tree_items.order_key\n\t\tfrom graph_tree_items\n\t\twhere graph_tree_items.order_key like '{$order_key}%%'\n\t\tand graph_tree_items.graph_tree_id='" . $tree_item["graph_tree_id"] . "'\n\t\torder by graph_tree_items.order_key"); if (sizeof($tree) > 0) { $old_key_part = substr($tree[0]["order_key"], strlen($order_key), CHARS_PER_TIER); /* we key tier==0 off of '1' and tier>0 off of '0' */ if (tree_tier($order_key) == 0) { $i = 1; } else { $i = 0; } foreach ($tree as $tree_item) { /* this is the key column we are going to 'rekey' */ $new_key_part = substr($tree_item["order_key"], strlen($order_key), CHARS_PER_TIER); /* incriment a counter for the new key column */ if ($old_key_part != $new_key_part) { $i++; } /* build the new order key string */ $key = $order_key . str_pad(strval($i), CHARS_PER_TIER, '0', STR_PAD_LEFT) . substr($tree_item["order_key"], strlen($order_key) + CHARS_PER_TIER); db_execute("update graph_tree_items set order_key='{$key}' where id=" . $tree_item["id"]); $old_key_part = $new_key_part; } } }
function api_tree_item_save($id, $tree_id, $type, $parent_tree_item_id, $title, $local_graph_id, $rra_id, $host_id, $host_grouping_type, $sort_children_type, $propagate_changes) { global $config; input_validate_input_number($tree_id); input_validate_input_number($parent_tree_item_id); include_once $config["library_path"] . "/tree.php"; db_execute("LOCK TABLES graph_tree_items WRITE, graph_tree READ, graph_templates_graph READ, host READ"); $parent_order_key = db_fetch_cell("select order_key from graph_tree_items where id={$parent_tree_item_id}"); /* fetch some cache variables */ if (empty($id)) { /* new/save - generate new order key */ $order_key = get_next_tree_id($parent_order_key, "graph_tree_items", "order_key", "graph_tree_id={$tree_id}"); } else { /* edit/save - use old order_key */ $order_key = db_fetch_cell("select order_key from graph_tree_items where id={$id}"); } /* duplicate graph check */ $search_key = substr($parent_order_key, 0, tree_tier($parent_order_key) * CHARS_PER_TIER); if ($id == 0 && $type == TREE_ITEM_TYPE_GRAPH && sizeof(db_fetch_assoc("select id from graph_tree_items where local_graph_id='{$local_graph_id}' and graph_tree_id='{$tree_id}' and 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)) . "'")) > 0) { $value = db_fetch_cell("select id from graph_tree_items where local_graph_id='{$local_graph_id}' and graph_tree_id='{$tree_id}' and 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)) . "'"); db_execute("UNLOCK TABLES"); return $value; } /* Duplicate header check */ if ($id == 0 && $type == TREE_ITEM_TYPE_HEADER) { if (sizeof(db_fetch_assoc("SELECT id FROM graph_tree_items WHERE title='{$title}' AND graph_tree_id='{$tree_id}' AND 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 order_key NOT LIKE '{$search_key}" . str_repeat('0', MAX_TREE_DEPTH * CHARS_PER_TIER - strlen($search_key)) . "%'")) > 0) { $value = db_fetch_cell("select id from graph_tree_items where title='{$title}' and graph_tree_id='{$tree_id}' and 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)) . "'"); db_execute("UNLOCK TABLES"); return $value; } } /* Duplicate host check */ if ($id == 0 && $type == TREE_ITEM_TYPE_HOST && sizeof(db_fetch_assoc("select id from graph_tree_items where host_id='{$host_id}' and local_graph_id='{$local_graph_id}' and graph_tree_id='{$tree_id}' and 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)) . "'")) > 0) { $value = db_fetch_cell("select id from graph_tree_items where host_id='{$host_id}' and local_graph_id='{$local_graph_id}' and graph_tree_id='{$tree_id}' and 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)) . "'"); db_execute("UNLOCK TABLES"); return $value; } $save["id"] = $id; $save["graph_tree_id"] = $tree_id; $save["title"] = form_input_validate($title, "title", "", $type == TREE_ITEM_TYPE_HEADER ? false : true, 3); $save["order_key"] = $order_key; $save["local_graph_id"] = form_input_validate($local_graph_id, "local_graph_id", "", true, 3); $save["rra_id"] = form_input_validate($rra_id, "rra_id", "", true, 3); $save["host_id"] = form_input_validate($host_id, "host_id", "", true, 3); $save["host_grouping_type"] = form_input_validate($host_grouping_type, "host_grouping_type", "", true, 3); $save["sort_children_type"] = form_input_validate($sort_children_type, "sort_children_type", "", true, 3); $tree_item_id = 0; if (!is_error_message()) { $tree_item_id = sql_save($save, "graph_tree_items"); if ($tree_item_id) { raise_message(1); /* re-parent the branch if the parent item has changed */ if ($parent_tree_item_id != $tree_item_id) { reparent_branch($parent_tree_item_id, $tree_item_id); } $tree_sort_type = db_fetch_cell("select sort_type from graph_tree where id='{$tree_id}'"); /* tree item ordering */ if ($tree_sort_type == TREE_ORDERING_NONE) { /* resort our parent */ $parent_sorting_type = db_fetch_cell("select sort_children_type from graph_tree_items where id={$parent_tree_item_id}"); if (!empty($parent_tree_item_id) && $parent_sorting_type != TREE_ORDERING_NONE) { sort_tree(SORT_TYPE_TREE_ITEM, $parent_tree_item_id, $parent_sorting_type); } /* if this is a header, sort direct children */ if ($type == TREE_ITEM_TYPE_HEADER && $sort_children_type != TREE_ORDERING_NONE) { sort_tree(SORT_TYPE_TREE_ITEM, $tree_item_id, $sort_children_type); } /* tree ordering */ } else { /* potential speed savings for large trees */ if (tree_tier($save["order_key"]) == 1) { sort_tree(SORT_TYPE_TREE, $tree_id, $tree_sort_type); } else { sort_tree(SORT_TYPE_TREE_ITEM, $parent_tree_item_id, $tree_sort_type); } } /* if the user checked the 'Propagate Changes' box */ if ($type == TREE_ITEM_TYPE_HEADER && $propagate_changes == true) { $search_key = preg_replace("/0+\$/", "", $order_key); $tree_items = db_fetch_assoc("select\n\t\t\t\t\tgraph_tree_items.id\n\t\t\t\t\tfrom graph_tree_items\n\t\t\t\t\twhere graph_tree_items.host_id = 0\n\t\t\t\t\tand graph_tree_items.local_graph_id = 0\n\t\t\t\t\tand graph_tree_items.title != ''\n\t\t\t\t\tand graph_tree_items.order_key like '{$search_key}%%'\n\t\t\t\t\tand graph_tree_items.graph_tree_id='{$tree_id}'"); if (sizeof($tree_items) > 0) { foreach ($tree_items as $item) { db_execute("update graph_tree_items set sort_children_type = '{$sort_children_type}' where id = '" . $item["id"] . "'"); if ($sort_children_type != TREE_ORDERING_NONE) { sort_tree(SORT_TYPE_TREE_ITEM, $item["id"], $sort_children_type); } } } } } else { raise_message(2); } } db_execute("UNLOCK TABLES"); return $tree_item_id; }
function api_tree_item_save($id, $tree_id, $type, $parent_tree_item_id, $title, $local_graph_id, $rra_id, $host_id, $host_grouping_type, $sort_children_type, $propagate_changes) { global $config; input_validate_input_number($tree_id); input_validate_input_number($parent_tree_item_id); include_once($config["library_path"] . "/tree.php"); $parent_order_key = db_fetch_cell("select order_key from graph_tree_items where id=$parent_tree_item_id"); /* fetch some cache variables */ if (empty($id)) { /* new/save - generate new order key */ $order_key = get_next_tree_id($parent_order_key, "graph_tree_items", "order_key", "graph_tree_id=$tree_id"); }else{ /* edit/save - use old order_key */ $order_key = db_fetch_cell("select order_key from graph_tree_items where id=$id"); } /* duplicate graph check */ $search_key = substr($parent_order_key, 0, (tree_tier($parent_order_key) * CHARS_PER_TIER)); if (($type == TREE_ITEM_TYPE_GRAPH) && (sizeof(db_fetch_assoc("select id from graph_tree_items where local_graph_id='$local_graph_id' and rra_id='$rra_id' and graph_tree_id='$tree_id' and 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)) . "'")) > 0)) { return 0; } $save["id"] = $id; $save["graph_tree_id"] = $tree_id; $save["title"] = form_input_validate($title, "title", "", ($type == TREE_ITEM_TYPE_HEADER ? false : true), 3); $save["order_key"] = $order_key; $save["local_graph_id"] = form_input_validate($local_graph_id, "local_graph_id", "", true, 3); $save["rra_id"] = form_input_validate($rra_id, "rra_id", "", true, 3); $save["host_id"] = form_input_validate($host_id, "host_id", "", true, 3); $save["host_grouping_type"] = form_input_validate($host_grouping_type, "host_grouping_type", "", true, 3); $save["sort_children_type"] = form_input_validate($sort_children_type, "sort_children_type", "", true, 3); $tree_item_id = 0; if (!is_error_message()) { $tree_item_id = sql_save($save, "graph_tree_items"); if ($tree_item_id) { raise_message(1); /* re-parent the branch if the parent item has changed */ if ($parent_tree_item_id != $tree_item_id) { reparent_branch($parent_tree_item_id, $tree_item_id); } $tree_sort_type = db_fetch_cell("select sort_type from graph_tree where id='$tree_id'"); /* tree item ordering */ if ($tree_sort_type == TREE_ORDERING_NONE) { /* resort our parent */ $parent_sorting_type = db_fetch_cell("select sort_children_type from graph_tree_items where id=$parent_tree_item_id"); if ((!empty($parent_tree_item_id)) && ($parent_sorting_type != TREE_ORDERING_NONE)) { sort_tree(SORT_TYPE_TREE_ITEM, $parent_tree_item_id, $parent_sorting_type); } /* if this is a header, sort direct children */ if (($type == TREE_ITEM_TYPE_HEADER) && ($sort_children_type != TREE_ORDERING_NONE)) { sort_tree(SORT_TYPE_TREE_ITEM, $tree_item_id, $sort_children_type); } /* tree ordering */ }else{ /* potential speed savings for large trees */ if (tree_tier($save["order_key"]) == 1) { sort_tree(SORT_TYPE_TREE, $tree_id, $tree_sort_type); }else{ sort_tree(SORT_TYPE_TREE_ITEM, $parent_tree_item_id, $tree_sort_type); } } /* if the user checked the 'Propagate Changes' box */ if (($type == TREE_ITEM_TYPE_HEADER) && ($propagate_changes == true)) { $search_key = preg_replace("/0+$/", "", $order_key); $tree_items = db_fetch_assoc("select graph_tree_items.id from graph_tree_items where graph_tree_items.host_id = 0 and graph_tree_items.local_graph_id = 0 and graph_tree_items.title != '' and graph_tree_items.order_key like '$search_key%%' and graph_tree_items.graph_tree_id='$tree_id'"); if (sizeof($tree_items) > 0) { foreach ($tree_items as $item) { db_execute("update graph_tree_items set sort_children_type = '$sort_children_type' where id = '" . $item["id"] . "'"); if ($sort_children_type != TREE_ORDERING_NONE) { sort_tree(SORT_TYPE_TREE_ITEM, $item["id"], $sort_children_type); } } } } }else{ raise_message(2); } } return $tree_item_id; }
function nmidSmokeping_create_dhtml_tree( $SmokePingServer ) { /* Record Start Time */ list( $micro, $seconds ) = split( " ", microtime() ); $start = $seconds + $micro; $dhtml_tree = array(); $devices = array(); $i = 0; $tree_list = get_graph_tree_array(); if ( sizeof( $tree_list ) > 0 ) { foreach ( $tree_list as $tree ) { $i++; $heirarchy = db_fetch_assoc( "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, host.hostname as ipaddress from graph_tree_items left join host on (host.id=graph_tree_items.host_id) where graph_tree_items.graph_tree_id=" . $tree[ "id" ] . " and graph_tree_items.local_graph_id = 0 order by graph_tree_items.order_key" ); $treeName = preg_replace( "/\s/", "_", $tree[ "name" ] ); $treeName = preg_replace( "@/@", "-", $treeName ); $treeName = preg_replace( "@\)@", "-", $treeName ); $treeName = preg_replace( "@\(@", "-", $treeName ); $treeName = preg_replace( "@\.@", "", $treeName ); $treeName = preg_replace( "@\&@", "and", $treeName ); $treeName = preg_replace( "@\,@", "and", $treeName ); $treeName = preg_replace( "@\'@", "", $treeName ); $treeName = preg_replace( "@\+@", "", $treeName ); $treeName = preg_replace( "@\|@", "-", $treeName ); $treeName = preg_replace( "@\ä@", "ae", $treeName ); $treeName = preg_replace( "@\ö@", "oe", $treeName ); $treeName = preg_replace( "@\ü@", "ue", $treeName ); $treeName = preg_replace( "@\Ä@", "Ae", $treeName ); $treeName = preg_replace( "@\Ö@", "Oe", $treeName ); $treeName = preg_replace( "@\Ü@", "Ue", $treeName ); $treeName = preg_replace( "@\Ç@", "C", $treeName ); $treeName = preg_replace( "@\²@", "2", $treeName ); $treeName = preg_replace( "/\\\/", "-", $treeName ); $treeName = preg_replace( "@\[@", "_", $treeName ); $treeName = preg_replace( "@\]@", "_", $treeName ); $treeName = preg_replace( "/::/", "__", $treeName ); $dhtml_tree[ $i ] = "+ " . $treeName . "\n" . "menu = " . $tree[ "name" ] . "\n" . "title = " . $tree[ "name" ] . "\n" . "\n"; $current_tier = $treeName; $tierArr = array(); if ( sizeof( $heirarchy ) > 0 ) { foreach ( $heirarchy as $leaf ) { $i++; $tier = tree_tier( $leaf[ "order_key" ] ); if ( $leaf[ "host_id" ] > 0 ) { $nmid_data = db_fetch_assoc( "select nwmgmt_smokeping_server,nwmgmt_settings from host where id=" . $leaf[ "host_id" ] ); if ( preg_match( "@$SmokePingServer@", $nmid_data[ 0 ][ "nwmgmt_smokeping_server" ] ) > 0 ) { if ( preg_match( "/^s1/", $nmid_data[ 0 ][ "nwmgmt_settings" ] ) > 0 ) { $tierString = '+'; for ( $tierCount = 0; $tierCount < $tier; $tierCount++ ) { $tierString .= '+'; } $host_text = preg_replace( "/\s/", "_", $leaf[ "hostname" ] ); $host_text = preg_replace( "@/@", "-", $host_text ); $host_text = preg_replace( "@\)@", "-", $host_text ); $host_text = preg_replace( "@\(@", "-", $host_text ); $host_text = preg_replace( "@\.@", "", $host_text ); $host_text = preg_replace( "@\&@", "and", $host_text ); $host_text = preg_replace( "@\,@", "and", $host_text ); $host_text = preg_replace( "@\'@", "", $host_text ); $host_text = preg_replace( "@\+@", "", $host_text ); $host_text = preg_replace( "@\|@", "-", $host_text ); $host_text = preg_replace( "@\ä@", "ae", $host_text ); $host_text = preg_replace( "@\ö@", "oe", $host_text ); $host_text = preg_replace( "@\ü@", "ue", $host_text ); $host_text = preg_replace( "@\Ä@", "Ae", $host_text ); $host_text = preg_replace( "@\Ö@", "Oe", $host_text ); $host_text = preg_replace( "@\Ü@", "Ue", $host_text ); $host_text = preg_replace( "@\Ç@", "C", $host_text ); $host_text = preg_replace( "@\²@", "2", $host_text ); $host_text = preg_replace( "/\\\/", "-", $host_text ); if ( isset ( $devices[ $host_text ] ) ) { // nothing } else { $devices[ $host_text ] = TRUE; $dhtml_tree[ $i ] = $tierString . ' ' . $host_text . "\n" . "menu = " . $leaf[ "hostname" ] . "\n" . "title = Device " . $leaf[ "hostname" ] . "\n" . "host = " . $leaf[ "ipaddress" ] . "\n" . "\n"; $tierArr[ $tier ] = $host_text; $url = $current_tier; for ( $counter = 1; $counter < $tier + 1; $counter++ ) { $url .= '.' . $tierArr[ $counter ]; } db_execute( "UPDATE host SET nwmgmt_smokeping_path = \"$url\" WHERE id=" . $leaf[ "host_id" ] ); } } } } else { $tierString = '+'; for ( $tierCount = 0; $tierCount < $tier; $tierCount++ ) { $tierString .= '+'; } $title = $leaf[ "title" ]; $menu_text = preg_replace( "/\s/", "_", $title ); $menu_text = preg_replace( "@/@", "-", $menu_text ); $menu_text = preg_replace( "@\)@", "-", $menu_text ); $menu_text = preg_replace( "@\(@", "-", $menu_text ); $menu_text = preg_replace( "@\.@", "", $menu_text ); $menu_text = preg_replace( "@\&@", "and", $menu_text ); $menu_text = preg_replace( "@\,@", "and", $menu_text ); $menu_text = preg_replace( "@\'@", "", $menu_text ); $menu_text = preg_replace( "@\+@", "", $menu_text ); $menu_text = preg_replace( "@\|@", "-", $menu_text ); $menu_text = preg_replace( "@\ä@", "ae", $menu_text ); $menu_text = preg_replace( "@\ö@", "oe", $menu_text ); $menu_text = preg_replace( "@\ü@", "ue", $menu_text ); $menu_text = preg_replace( "@\Ä@", "Ae", $menu_text ); $menu_text = preg_replace( "@\Ö@", "Oe", $menu_text ); $menu_text = preg_replace( "@\Ü@", "Ue", $menu_text ); $menu_text = preg_replace( "@\Ç@", "C", $menu_text ); $menu_text = preg_replace( "@\²@", "2", $menu_text ); $title = preg_replace( "@\'@", "\"", $title ); $menu_text = preg_replace( "/\\\/", "-", $menu_text ); $dhtml_tree[ $i ] = $tierString . " " . $menu_text . "\n" . "menu = " . $title . "\n" . "title = Location/Devices in " . $title . "\n" . "\n"; $tierArr[ $tier ] = $menu_text; } } } } } return $dhtml_tree; }
function create_dhtml_tree_export($tree_id) { /* record start time */ list($micro,$seconds) = split(" ", microtime()); $start = $seconds + $micro; $dhtml_tree = array(); $dhtml_tree[0] = $start; $dhtml_tree[1] = read_graph_config_option("expand_hosts"); $dhtml_tree[2] = "foldersTree = gFld(\"\", \"\")\n"; $i = 2; $i++; $heirarchy = db_fetch_assoc("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) where graph_tree_items.graph_tree_id=" . $tree_id . " and graph_tree_items.local_graph_id = 0 order by graph_tree_items.order_key"); $dhtml_tree[$i] = "ou0 = insFld(foldersTree, gFld(\"" . get_tree_name($tree_id) . "\", \"index.html\"))\n"; if (sizeof($heirarchy) > 0) { foreach ($heirarchy as $leaf) { $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> " . $leaf["hostname"] . "\", \"".$leaf["hostname"]."_".$leaf["id"]. ".html\"))\n"; if (read_graph_config_option("expand_hosts") == "on") { 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"] . " 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"] . "\", \"".$leaf["title"]."_".$leaf["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" => "(Non Indexed)" )); 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"] . "\"".$leaf["title"]."_".$leaf["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"]); 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 . "\"".$leaf["title"]."_".$leaf["id"]. ".html\"))\n"; } } } } } }else { $dhtml_tree[$i] = "ou" . ($tier) . " = insFld(ou" . ($tier-1) . ", gFld(\"" . $leaf["title"] . "\", \"".$leaf["title"]."_".$leaf["id"]. ".html\"))\n"; } } } return $dhtml_tree; }
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) . ")'><< " . __("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") . " >></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"; }