function host() { global $device_actions, $item_rows; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request('host_template_id')); input_validate_input_number(get_request_var_request('page')); input_validate_input_number(get_request_var_request('host_status')); input_validate_input_number(get_request_var_request('rows')); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST['filter'])) { $_REQUEST['filter'] = sanitize_search_string(get_request_var_request('filter')); } /* clean up sort_column */ if (isset($_REQUEST['sort_column'])) { $_REQUEST['sort_column'] = sanitize_search_string(get_request_var_request('sort_column')); } /* clean up search string */ if (isset($_REQUEST['sort_direction'])) { $_REQUEST['sort_direction'] = sanitize_search_string(get_request_var_request('sort_direction')); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST['clear_x'])) { kill_session_var('sess_device_current_page'); kill_session_var('sess_device_filter'); kill_session_var('sess_device_host_template_id'); kill_session_var('sess_host_status'); kill_session_var('sess_default_rows'); kill_session_var('sess_host_sort_column'); kill_session_var('sess_host_sort_direction'); unset($_REQUEST['page']); unset($_REQUEST['filter']); unset($_REQUEST['host_template_id']); unset($_REQUEST['host_status']); unset($_REQUEST['rows']); unset($_REQUEST['sort_column']); unset($_REQUEST['sort_direction']); } if (!empty($_SESSION['sess_host_status']) && !empty($_REQUEST['host_status'])) { if ($_SESSION['sess_host_status'] != $_REQUEST['host_status']) { $_REQUEST['page'] = 1; } } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value('page', 'sess_device_current_page', '1'); load_current_session_value('filter', 'sess_device_filter', ''); load_current_session_value('host_template_id', 'sess_device_host_template_id', '-1'); load_current_session_value('host_status', 'sess_host_status', '-1'); load_current_session_value('rows', 'sess_default_rows', read_config_option('num_rows_table')); load_current_session_value('sort_column', 'sess_host_sort_column', 'description'); load_current_session_value('sort_direction', 'sess_host_sort_direction', 'ASC'); /* if the number of rows is -1, set it to the default */ if ($_REQUEST['rows'] == -1) { $_REQUEST['rows'] = read_config_option('num_rows_table'); } ?> <script type="text/javascript"> <!-- function applyFilter() { strURL = 'host.php?host_status=' + $('#host_status').val(); strURL = strURL + '&host_template_id=' + $('#host_template_id').val(); strURL = strURL + '&rows=' + $('#rows').val(); strURL = strURL + '&filter=' + $('#filter').val(); strURL = strURL + '&page=' + $('#page').val(); strURL = strURL + '&header=false'; $.get(strURL, function(data) { $('#main').html(data); applySkin(); }); } function clearFilter() { strURL = 'host.php?clear_x=1&header=false'; $.get(strURL, function(data) { $('#main').html(data); applySkin(); }); } $(function(data) { $('#refresh').click(function() { applyFilter(); }); $('#clear').click(function() { clearFilter(); }); $('#form_devices').submit(function(event) { event.preventDefault(); applyFilter(); }); }); --> </script> <?php html_start_box('<strong>Devices</strong>', '100%', '', '3', 'center', 'host.php?action=edit&host_template_id=' . htmlspecialchars(get_request_var_request('host_template_id')) . '&host_status=' . htmlspecialchars(get_request_var_request('host_status'))); ?> <tr class='even noprint'> <td> <form id='form_devices' name="form_devices" action="host.php"> <table cellpadding="2" cellspacing="0"> <tr> <td width='50'> Search </td> <td> <input id='filter' type="text" name="filter" size="25" value="<?php print htmlspecialchars(get_request_var_request('filter')); ?> " onChange='applyFilter()'> </td> <td> Template </td> <td> <select id='host_template_id' name="host_template_id" onChange="applyFilter()"> <option value="-1"<?php if (get_request_var_request('host_template_id') == '-1') { ?> selected<?php } ?> >Any</option> <option value="0"<?php if (get_request_var_request('host_template_id') == '0') { ?> selected<?php } ?> >None</option> <?php $host_templates = db_fetch_assoc('SELECT id, name FROM host_template ORDER BY name'); if (sizeof($host_templates) > 0) { foreach ($host_templates as $host_template) { print "<option value='" . $host_template['id'] . "'"; if (get_request_var_request('host_template_id') == $host_template['id']) { print ' selected'; } print '>' . htmlspecialchars($host_template['name']) . "</option>\n"; } } ?> </select> </td> <td> Status </td> <td> <select id='host_status' name="host_status" onChange="applyFilter()"> <option value="-1"<?php if (get_request_var_request('host_status') == '-1') { ?> selected<?php } ?> >Any</option> <option value="-3"<?php if (get_request_var_request('host_status') == '-3') { ?> selected<?php } ?> >Enabled</option> <option value="-2"<?php if (get_request_var_request('host_status') == '-2') { ?> selected<?php } ?> >Disabled</option> <option value="-4"<?php if (get_request_var_request('host_status') == '-4') { ?> selected<?php } ?> >Not Up</option> <option value="3"<?php if (get_request_var_request('host_status') == '3') { ?> selected<?php } ?> >Up</option> <option value="1"<?php if (get_request_var_request('host_status') == '1') { ?> selected<?php } ?> >Down</option> <option value="2"<?php if (get_request_var_request('host_status') == '2') { ?> selected<?php } ?> >Recovering</option> <option value="0"<?php if (get_request_var_request('host_status') == '0') { ?> selected<?php } ?> >Unknown</option> </select> </td> <td> Devices </td> <td> <select id='rows' name="rows" onChange="applyFilter()"> <?php if (sizeof($item_rows) > 0) { foreach ($item_rows as $key => $value) { print "<option value='" . $key . "'"; if (get_request_var_request('rows') == $key) { print ' selected'; } print '>' . htmlspecialchars($value) . "</option>\n"; } } ?> </select> </td> <td> <input type="button" id='refresh' value="Go" title="Set/Refresh Filters"> </td> <td> <input type="button" id='clear' name="clear_x" value="Clear" title="Clear Filters"> </td> </tr> </table> <input type='hidden' id='page' name='page' value='<?php print $_REQUEST['page']; ?> '> </form> </td> </tr> <?php html_end_box(); /* form the 'where' clause for our main sql query */ if (strlen(get_request_var_request('filter'))) { $sql_where = "where (host.hostname like '%%" . get_request_var_request('filter') . "%%' OR host.description like '%%" . get_request_var_request('filter') . "%%')"; } else { $sql_where = ''; } if (get_request_var_request('host_status') == '-1') { /* Show all items */ } elseif (get_request_var_request('host_status') == '-2') { $sql_where .= strlen($sql_where) ? " AND host.disabled='on'" : " WHERE host.disabled='on'"; } elseif (get_request_var_request('host_status') == '-3') { $sql_where .= strlen($sql_where) ? " AND host.disabled=''" : " WHERE host.disabled=''"; } elseif (get_request_var_request('host_status') == '-4') { $sql_where .= strlen($sql_where) ? " AND (host.status!='3' OR host.disabled='on')" : " WHERE (host.status!='3' OR host.disabled='on')"; } else { $sql_where .= strlen($sql_where) ? ' AND (host.status=' . get_request_var_request('host_status') . " AND host.disabled = '')" : 'where (host.status=' . get_request_var_request('host_status') . " AND host.disabled = '')"; } if (get_request_var_request('host_template_id') == '-1') { /* Show all items */ } elseif (get_request_var_request('host_template_id') == '0') { $sql_where .= strlen($sql_where) ? ' AND host.host_template_id=0' : ' WHERE host.host_template_id=0'; } elseif (!empty($_REQUEST['host_template_id'])) { $sql_where .= strlen($sql_where) ? ' AND host.host_template_id=' . get_request_var_request('host_template_id') : ' WHERE host.host_template_id=' . get_request_var_request('host_template_id'); } /* print checkbox form for validation */ print "<form name='chk' method='post' action='host.php'>\n"; html_start_box('', '100%', '', '3', 'center', ''); $total_rows = db_fetch_cell("SELECT\n\t\tCOUNT(host.id)\n\t\tFROM host\n\t\t{$sql_where}"); $sortby = get_request_var_request('sort_column'); if ($sortby == 'hostname') { $sortby = 'INET_ATON(hostname)'; } $sql_query = "SELECT host.*, graphs, data_sources\n\t\tFROM host\n\t\tLEFT JOIN (SELECT host_id, COUNT(*) AS graphs FROM graph_local GROUP BY host_id) AS gl\n\t\tON host.id=gl.host_id\n\t\tLEFT JOIN (SELECT host_id, COUNT(*) AS data_sources FROM data_local GROUP BY host_id) AS dl\n\t\tON host.id=dl.host_id\n\t\t{$sql_where}\n\t\tGROUP BY host.id\n\t\tORDER BY " . $sortby . ' ' . get_request_var_request('sort_direction') . ' LIMIT ' . get_request_var_request('rows') * (get_request_var_request('page') - 1) . ',' . get_request_var_request('rows'); $hosts = db_fetch_assoc($sql_query); $nav = html_nav_bar('host.php?filter=' . get_request_var_request('filter') . '&host_template_id=' . get_request_var_request('host_template_id') . '&host_status=' . get_request_var_request('host_status'), MAX_DISPLAY_PAGES, get_request_var_request('page'), get_request_var_request('rows'), $total_rows, 13, 'Devices', 'page', 'main'); print $nav; $display_text = array('description' => array('display' => 'Device Description', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'The name by which this Device will be referred to.'), 'hostname' => array('display' => 'Hostname', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'Either an IP address, or hostname. If a hostname, it must be resolvable by either DNS, or from your hosts file.'), 'id' => array('display' => 'ID', 'align' => 'right', 'sort' => 'ASC', 'tip' => 'The internal database ID for this Device. Useful when performing automation or debugging.'), 'graphs' => array('display' => 'Graphs', 'align' => 'right', 'sort' => 'ASC', 'tip' => 'The total number of Graphs generated from this Device.'), 'data_sources' => array('display' => 'Data Sources', 'align' => 'right', 'sort' => 'ASC', 'tip' => 'The total number of Data Sources generated from this Device.'), 'status' => array('display' => 'Status', 'align' => 'center', 'sort' => 'ASC', 'tip' => 'The monitoring status of the Device based upon ping results. If this Device is a special type Device, by using the hostname "localhost", or due to the setting to not perform an Availability Check, it will always remain Up. When using cmd.php data collector, a Device with no Graphs, is not pinged by the data collector and will remain in an "Unknown" state.'), 'status_rec_date' => array('display' => 'In State', 'align' => 'right', 'sort' => 'ASC', 'tip' => 'The amount of time that this Device has been in its current state.'), 'snmp_sysUpTimeInstance' => array('display' => 'Uptime', 'align' => 'right', 'sort' => 'ASC', 'tip' => 'The current amount of time that the host has been up.'), 'polling_time' => array('display' => 'Poll Time', 'align' => 'right', 'sort' => 'ASC', 'tip' => 'The the amount of time it takes to collect data from this Device.'), 'cur_time' => array('display' => 'Current (ms)', 'align' => 'right', 'sort' => 'DESC', 'tip' => 'The current ping time in milliseconds to reach the Device.'), 'avg_time' => array('display' => 'Average (ms)', 'align' => 'right', 'sort' => 'DESC', 'tip' => 'The average ping time in milliseconds to reach the Device since the counters were cleared for this Device.'), 'availability' => array('display' => 'Availability', 'align' => 'right', 'sort' => 'ASC', 'tip' => 'The availability percentage based upon ping results insce the counters were cleared for this Device.')); html_header_sort_checkbox($display_text, get_request_var_request('sort_column'), get_request_var_request('sort_direction'), false); $i = 0; if (sizeof($hosts) > 0) { foreach ($hosts as $host) { if ($host['disabled'] == '' && ($host['status'] == HOST_RECOVERING || $host['status'] == HOST_UP) && ($host['availability_method'] != AVAIL_NONE && $host['availability_method'] != AVAIL_PING)) { $snmp_uptime = $host['snmp_sysUpTimeInstance']; $days = intval($snmp_uptime / (60 * 60 * 24 * 100)); $remainder = $snmp_uptime % (60 * 60 * 24 * 100); $hours = intval($remainder / (60 * 60 * 100)); $remainder = $remainder % (60 * 60 * 100); $minutes = intval($remainder / (60 * 100)); $uptime = "{$days} d {$hours} h {$minutes} m"; } else { $uptime = "N/A"; } form_alternate_row('line' . $host['id'], true); form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars('host.php?action=edit&id=' . $host['id']) . "'>" . (strlen(get_request_var_request('filter')) ? preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", htmlspecialchars($host['description'])) : htmlspecialchars($host['description'])) . '</a>', $host['id']); form_selectable_cell(strlen(get_request_var_request('filter')) ? preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", htmlspecialchars($host['hostname'])) : htmlspecialchars($host['hostname']), $host['id']); form_selectable_cell($host['id'], $host['id'], '', 'text-align:right'); form_selectable_cell(number_format($host['graphs']), $host['id'], '', 'text-align:right'); form_selectable_cell(number_format($host['data_sources']), $host['id'], '', 'text-align:right'); form_selectable_cell(get_colored_device_status($host['disabled'] == 'on' ? true : false, $host['status']), $host['id'], '', 'text-align:center'); form_selectable_cell(get_timeinstate($host), $host['id'], '', 'text-align:right'); form_selectable_cell($uptime, $host['id'], '', 'text-align:right'); form_selectable_cell(round($host['polling_time'], 2), $host['id'], '', 'text-align:right'); form_selectable_cell(round($host['cur_time'], 2), $host['id'], '', 'text-align:right'); form_selectable_cell(round($host['avg_time'], 2), $host['id'], '', 'text-align:right'); form_selectable_cell(round($host['availability'], 2) . ' %', $host['id'], '', 'text-align:right'); form_checkbox_cell($host['description'], $host['id']); form_end_row(); } /* put the nav bar on the bottom as well */ print $nav; } else { print "<tr class='tableRow'><td colspan='11'><em>No Devices</em></td></tr>"; } html_end_box(false); /* add a list of tree names to the actions dropdown */ add_tree_names_to_actions_array(); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($device_actions); print "</form>\n"; }
function graph() { global $colors, $graph_actions, $item_rows; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("host_id")); input_validate_input_number(get_request_var_request("graph_rows")); input_validate_input_number(get_request_var_request("template_id")); input_validate_input_number(get_request_var_request("page")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* clean up sort_column string */ if (isset($_REQUEST["sort_column"])) { $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column")); } /* clean up sort_direction string */ if (isset($_REQUEST["sort_direction"])) { $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction")); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { kill_session_var("sess_graph_current_page"); kill_session_var("sess_graph_filter"); kill_session_var("sess_graph_sort_column"); kill_session_var("sess_graph_sort_direction"); kill_session_var("sess_graph_host_id"); kill_session_var("sess_graph_rows"); kill_session_var("sess_graph_template_id"); unset($_REQUEST["page"]); unset($_REQUEST["filter"]); unset($_REQUEST["sort_column"]); unset($_REQUEST["sort_direction"]); unset($_REQUEST["host_id"]); unset($_REQUEST["graph_rows"]); unset($_REQUEST["template_id"]); } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("page", "sess_graph_current_page", "1"); load_current_session_value("filter", "sess_graph_filter", ""); load_current_session_value("sort_column", "sess_graph_sort_column", "title_cache"); load_current_session_value("sort_direction", "sess_graph_sort_direction", "ASC"); load_current_session_value("host_id", "sess_graph_host_id", "-1"); load_current_session_value("graph_rows", "sess_graph_rows", read_config_option("num_rows_graph")); load_current_session_value("template_id", "sess_graph_template_id", "-1"); /* if the number of rows is -1, set it to the default */ if (get_request_var_request("graph_rows") == -1) { $_REQUEST["graph_rows"] = read_config_option("num_rows_graph"); } ?> <script type="text/javascript"> <!-- function applyGraphsFilterChange(objForm) { strURL = '?host_id=' + objForm.host_id.value; strURL = strURL + '&graph_rows=' + objForm.graph_rows.value; strURL = strURL + '&filter=' + objForm.filter.value; strURL = strURL + '&template_id=' + objForm.template_id.value; document.location = strURL; } --> </script> <?php html_start_box("<strong>Graph Management</strong>", "100%", $colors["header"], "3", "center", "graphs.php?action=graph_edit&host_id=" . get_request_var_request("host_id")); ?> <tr bgcolor="<?php print $colors["panel"];?>"> <form name="form_graph_id"> <td> <table cellpadding="1" cellspacing="0"> <tr> <td width="50"> Host: </td> <td width="1"> <select name="host_id" onChange="applyGraphsFilterChange(document.form_graph_id)"> <option value="-1"<?php if (get_request_var_request("host_id") == "-1") {?> selected<?php }?>>Any</option> <option value="0"<?php if (get_request_var_request("host_id") == "0") {?> selected<?php }?>>None</option> <?php if (read_config_option("auth_method") != 0) { /* get policy information for the sql where clause */ $current_user = db_fetch_row("select * from user_auth where id=" . $_SESSION["sess_user_id"]); $sql_where = get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]); $hosts = db_fetch_assoc("SELECT DISTINCT host.id, CONCAT_WS('',host.description,' (',host.hostname,')') as name FROM (graph_templates_graph,host) LEFT JOIN graph_local ON (graph_local.host_id=host.id) LEFT JOIN graph_templates ON (graph_templates.id=graph_local.graph_template_id) LEFT JOIN user_auth_perms ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=1 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (host.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_templates.id=user_auth_perms.item_id and user_auth_perms.type=4 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ")) WHERE graph_templates_graph.local_graph_id=graph_local.id " . (empty($sql_where) ? "" : "and $sql_where") . " ORDER BY name"); }else{ $hosts = db_fetch_assoc("SELECT DISTINCT host.id, CONCAT_WS('',host.description,' (',host.hostname,')') as name FROM host ORDER BY name"); } if (sizeof($hosts) > 0) { foreach ($hosts as $host) { print "<option value=' " . $host["id"] . "'"; if (get_request_var_request("host_id") == $host["id"]) { print " selected"; } print ">" . title_trim($host["name"], 40) . "</option>\n"; } } ?> </select> </td> <td width="70"> Template: </td> <td width="1"> <select name="template_id" onChange="applyGraphsFilterChange(document.form_graph_id)"> <option value="-1"<?php if (get_request_var_request("template_id") == "-1") {?> selected<?php }?>>Any</option> <option value="0"<?php if (get_request_var_request("template_id") == "0") {?> selected<?php }?>>None</option> <?php if (read_config_option("auth_method") != 0) { $templates = db_fetch_assoc("SELECT DISTINCT graph_templates.id, graph_templates.name FROM (graph_templates_graph,graph_local) LEFT JOIN host ON (host.id=graph_local.host_id) LEFT JOIN graph_templates ON (graph_templates.id=graph_local.graph_template_id) LEFT JOIN user_auth_perms ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=1 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (host.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_templates.id=user_auth_perms.item_id and user_auth_perms.type=4 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ")) WHERE graph_templates_graph.local_graph_id=graph_local.id AND graph_templates.id IS NOT NULL " . (empty($sql_where) ? "" : "AND $sql_where") . " ORDER BY name"); }else{ $templates = db_fetch_assoc("SELECT DISTINCT graph_templates.id, graph_templates.name FROM graph_templates ORDER BY name"); } if (sizeof($templates) > 0) { foreach ($templates as $template) { print "<option value=' " . $template["id"] . "'"; if (get_request_var_request("template_id") == $template["id"]) { print " selected"; } print ">" . title_trim($template["name"], 40) . "</option>\n"; } } ?> </select> </td> <td width="120" nowrap style='white-space: nowrap;'> <input type="image" src="images/button_go.gif" alt="Go" border="0" align="absmiddle"> <input type="image" src="images/button_clear.gif" name="clear" alt="Clear" border="0" align="absmiddle"> </td> </tr> </table> <table cellpadding="1" cellspacing="0"> <tr> <td width="50"> Search: </td> <td> <input type="text" name="filter" size="40" value="<?php print get_request_var_request("filter");?>"> </td> <td nowrap style='white-space: nowrap;' width="50"> Rows per Page: </td> <td width="1"> <select name="graph_rows" onChange="applyGraphsFilterChange(document.form_graph_id)"> <option value="-1"<?php if (get_request_var_request("graph_rows") == "-1") {?> selected<?php }?>>Default</option> <?php if (sizeof($item_rows) > 0) { foreach ($item_rows as $key => $value) { print "<option value='" . $key . "'"; if (get_request_var_request("graph_rows") == $key) { print " selected"; } print ">" . $value . "</option>\n"; } } ?> </select> </td> </tr> </table> </td> <input type='hidden' name='page' value='1'> </form> </tr> <?php html_end_box(); /* form the 'where' clause for our main sql query */ if (strlen(get_request_var_request("filter"))) { $sql_where = "AND (graph_templates_graph.title_cache like '%%" . get_request_var_request("filter") . "%%'" . " OR graph_templates.name like '%%" . get_request_var_request("filter") . "%%')"; }else{ $sql_where = ""; } if (get_request_var_request("host_id") == "-1") { /* Show all items */ }elseif (get_request_var_request("host_id") == "0") { $sql_where .= " AND graph_local.host_id=0"; }elseif (!empty($_REQUEST["host_id"])) { $sql_where .= " AND graph_local.host_id=" . get_request_var_request("host_id"); } if (get_request_var_request("template_id") == "-1") { /* Show all items */ }elseif (get_request_var_request("template_id") == "0") { $sql_where .= " AND graph_templates_graph.graph_template_id=0"; }elseif (!empty($_REQUEST["template_id"])) { $sql_where .= " AND graph_templates_graph.graph_template_id=" . get_request_var_request("template_id"); } html_start_box("", "100%", $colors["header"], "3", "center", ""); $total_rows = db_fetch_cell("SELECT COUNT(graph_templates_graph.id) FROM (graph_local,graph_templates_graph) LEFT JOIN graph_templates ON (graph_local.graph_template_id=graph_templates.id) WHERE graph_local.id=graph_templates_graph.local_graph_id $sql_where"); $graph_list = db_fetch_assoc("SELECT graph_templates_graph.id, graph_templates_graph.local_graph_id, graph_templates_graph.height, graph_templates_graph.width, graph_templates_graph.title_cache, graph_templates.name, graph_local.host_id FROM (graph_local,graph_templates_graph) LEFT JOIN graph_templates ON (graph_local.graph_template_id=graph_templates.id) WHERE graph_local.id=graph_templates_graph.local_graph_id $sql_where ORDER BY " . $_REQUEST["sort_column"] . " " . get_request_var_request("sort_direction") . " LIMIT " . (get_request_var_request("graph_rows")*(get_request_var_request("page")-1)) . "," . get_request_var_request("graph_rows")); /* generate page list */ $url_page_select = get_page_list(get_request_var_request("page"), MAX_DISPLAY_PAGES, get_request_var_request("graph_rows"), $total_rows, "graphs.php?filter=" . get_request_var_request("filter") . "&host_id=" . get_request_var_request("host_id")); $nav = "<tr bgcolor='#" . $colors["header"] . "'> <td colspan='5'> <table width='100%' cellspacing='0' cellpadding='0' border='0'> <tr> <td align='left' class='textHeaderDark'> <strong><< "; if (get_request_var_request("page") > 1) { $nav .= "<a class='linkOverDark' href='graphs.php?filter=" . get_request_var_request("filter") . "&host_id=" . get_request_var_request("host_id") . "&page=" . (get_request_var_request("page")-1) . "'>"; } $nav .= "Previous"; if (get_request_var_request("page") > 1) { $nav .= "</a>"; } $nav .= "</strong> </td>\n <td align='center' class='textHeaderDark'> Showing Rows " . ((get_request_var_request("graph_rows")*(get_request_var_request("page")-1))+1) . " to " . ((($total_rows < get_request_var_request("graph_rows")) || ($total_rows < (get_request_var_request("graph_rows")*get_request_var_request("page")))) ? $total_rows : (get_request_var_request("graph_rows")*get_request_var_request("page"))) . " of $total_rows [$url_page_select] </td>\n <td align='right' class='textHeaderDark'> <strong>"; if ((get_request_var_request("page") * get_request_var_request("graph_rows")) < $total_rows) { $nav .= "<a class='linkOverDark' href='graphs.php?filter=" . get_request_var_request("filter") . "&host_id=" . get_request_var_request("host_id") . "&page=" . (get_request_var_request("page")+1) . "'>"; } $nav .= "Next"; if ((get_request_var_request("page") * get_request_var_request("graph_rows")) < $total_rows) { $nav .= "</a>"; } $nav .= " >></strong> </td>\n </tr> </table> </td> </tr>\n"; print $nav; $display_text = array( "title_cache" => array("Graph Title", "ASC"), "local_graph_id" => array("ID", "ASC"), "name" => array("Template Name", "ASC"), "height" => array("Size", "ASC")); html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction")); $i = 0; if (sizeof($graph_list) > 0) { foreach ($graph_list as $graph) { $template_name = ((empty($graph["name"])) ? "<em>None</em>" : $graph["name"]); form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $graph["local_graph_id"]); $i++; form_selectable_cell("<a class='linkEditMain' href='graphs.php?action=graph_edit&id=" . $graph["local_graph_id"] . "' title='" . htmlspecialchars($graph["title_cache"]) . "'>" . ((get_request_var_request("filter") != "") ? eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", title_trim($graph["title_cache"], read_config_option("max_title_graph"))) : title_trim($graph["title_cache"], read_config_option("max_title_graph"))) . "</a>", $graph["local_graph_id"]); form_selectable_cell($graph["local_graph_id"], $graph["local_graph_id"]); form_selectable_cell(((get_request_var_request("filter") != "") ? eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $template_name) : $template_name) . "</a>", $graph["local_graph_id"]); form_selectable_cell($graph["height"] . "x" . $graph["width"], $graph["local_graph_id"]); form_checkbox_cell($graph["title_cache"], $graph["local_graph_id"]); form_end_row(); } /* put the nav bar on the bottom as well */ print $nav; }else{ print "<tr><td><em>No Graphs Found</em></td></tr>"; } html_end_box(false); /* add a list of tree names to the actions dropdown */ add_tree_names_to_actions_array(); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($graph_actions); print "</form>\n"; }
function host() { global $colors, $device_actions; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("host_template_id")); input_validate_input_number(get_request_var_request("page")); input_validate_input_number(get_request_var_request("host_status")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* clean up sort_column */ if (isset($_REQUEST["sort_column"])) { $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column")); } /* clean up search string */ if (isset($_REQUEST["sort_direction"])) { $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction")); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { kill_session_var("sess_device_current_page"); kill_session_var("sess_device_filter"); kill_session_var("sess_device_host_template_id"); kill_session_var("sess_host_status"); kill_session_var("sess_host_sort_column"); kill_session_var("sess_host_sort_direction"); unset($_REQUEST["page"]); unset($_REQUEST["filter"]); unset($_REQUEST["host_template_id"]); unset($_REQUEST["host_status"]); unset($_REQUEST["sort_column"]); unset($_REQUEST["sort_direction"]); } if ((!empty($_SESSION["sess_host_status"])) && (!empty($_REQUEST["host_status"]))) { if ($_SESSION["sess_host_status"] != $_REQUEST["host_status"]) { $_REQUEST["page"] = 1; } } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("page", "sess_device_current_page", "1"); load_current_session_value("filter", "sess_device_filter", ""); load_current_session_value("host_template_id", "sess_device_host_template_id", "-1"); load_current_session_value("host_status", "sess_host_status", "-1"); load_current_session_value("sort_column", "sess_host_sort_column", "description"); load_current_session_value("sort_direction", "sess_host_sort_direction", "ASC"); html_start_box("<strong>Devices</strong>", "100%", $colors["header"], "3", "center", "host.php?action=edit&host_template_id=" . $_REQUEST["host_template_id"] . "&host_status=" . $_REQUEST["host_status"]); include("./include/html/inc_device_filter_table.php"); html_end_box(); /* form the 'where' clause for our main sql query */ if (strlen($_REQUEST["filter"])) { $sql_where = "where (host.hostname like '%%" . $_REQUEST["filter"] . "%%' OR host.description like '%%" . $_REQUEST["filter"] . "%%')"; }else{ $sql_where = ""; } if ($_REQUEST["host_status"] == "-1") { /* Show all items */ }elseif ($_REQUEST["host_status"] == "-2") { $sql_where .= (strlen($sql_where) ? " and host.disabled='on'" : "where host.disabled='on'"); }elseif ($_REQUEST["host_status"] == "-3") { $sql_where .= (strlen($sql_where) ? " and host.disabled=''" : "where host.disabled=''"); }elseif ($_REQUEST["host_status"] == "-4") { $sql_where .= (strlen($sql_where) ? " and (host.status!='3' or host.disabled='on')" : "where (host.status!='3' or host.disabled='on')"); }else { $sql_where .= (strlen($sql_where) ? " and (host.status=" . $_REQUEST["host_status"] . " AND host.disabled = '')" : "where (host.status=" . $_REQUEST["host_status"] . " AND host.disabled = '')"); } if ($_REQUEST["host_template_id"] == "-1") { /* Show all items */ }elseif ($_REQUEST["host_template_id"] == "0") { $sql_where .= (strlen($sql_where) ? " and host.host_template_id=0" : "where host.host_template_id=0"); }elseif (!empty($_REQUEST["host_template_id"])) { $sql_where .= (strlen($sql_where) ? " and host.host_template_id=" . $_REQUEST["host_template_id"] : "where host.host_template_id=" . $_REQUEST["host_template_id"]); } html_start_box("", "100%", $colors["header"], "3", "center", ""); $total_rows = db_fetch_cell("select COUNT(host.id) from host $sql_where"); $sortby = $_REQUEST["sort_column"]; if ($sortby=="hostname") { $sortby = "INET_ATON(hostname)"; } $host_graphs = array_rekey(db_fetch_assoc("SELECT host_id, count(*) as graphs FROM graph_local GROUP BY host_id"), "host_id", "graphs"); $host_data_sources = array_rekey(db_fetch_assoc("SELECT host_id, count(*) as data_sources FROM data_local GROUP BY host_id"), "host_id", "data_sources"); $sql_query = "SELECT host.id, host.disabled, host.status, host.hostname, host.description, host.min_time, host.max_time, host.cur_time, host.avg_time, host.availability FROM host $sql_where ORDER BY " . $sortby . " " . $_REQUEST["sort_direction"] . " LIMIT " . (read_config_option("num_rows_device")*($_REQUEST["page"]-1)) . "," . read_config_option("num_rows_device"); //print $sql_query; $hosts = db_fetch_assoc($sql_query); /* generate page list */ $url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, read_config_option("num_rows_device"), $total_rows, "host.php?filter=" . $_REQUEST["filter"] . "&host_template_id=" . $_REQUEST["host_template_id"] . "&host_status=" . $_REQUEST["host_status"]); $nav = "<tr bgcolor='#" . $colors["header"] . "'> <td colspan='9'> <table width='100%' cellspacing='0' cellpadding='0' border='0'> <tr> <td align='left' class='textHeaderDark'> <strong><< "; if ($_REQUEST["page"] > 1) { $nav .= "<a class='linkOverDark' href='host.php?filter=" . $_REQUEST["filter"] . "&host_template_id=" . $_REQUEST["host_template_id"] . "&host_status=" . $_REQUEST["host_status"] . "&page=" . ($_REQUEST["page"]-1) . "'>"; } $nav .= "Previous"; if ($_REQUEST["page"] > 1) { $nav .= "</a>"; } $nav .= "</strong> </td>\n <td align='center' class='textHeaderDark'> Showing Rows " . ((read_config_option("num_rows_device")*($_REQUEST["page"]-1))+1) . " to " . ((($total_rows < read_config_option("num_rows_device")) || ($total_rows < (read_config_option("num_rows_device")*$_REQUEST["page"]))) ? $total_rows : (read_config_option("num_rows_device")*$_REQUEST["page"])) . " of $total_rows [$url_page_select] </td>\n <td align='right' class='textHeaderDark'> <strong>"; if (($_REQUEST["page"] * read_config_option("num_rows_device")) < $total_rows) { $nav .= "<a class='linkOverDark' href='host.php?filter=" . $_REQUEST["filter"] . "&host_template_id=" . $_REQUEST["host_template_id"] . "&host_status=" . $_REQUEST["host_status"] . "&page=" . ($_REQUEST["page"]+1) . "'>"; } $nav .= "Next"; if (($_REQUEST["page"] * read_config_option("num_rows_device")) < $total_rows) { $nav .= "</a>"; } $nav .= " >></strong> </td>\n </tr> </table> </td> </tr>\n"; print $nav; $display_text = array( "description" => array("Description", "ASC"), "nosort1" => array("Graphs", "ASC"), "nosort2" => array("Data Sources", "ASC"), "status" => array("Status", "ASC"), "hostname" => array("Hostname", "ASC"), "cur_time" => array("Current (ms)", "DESC"), "avg_time" => array("Average (ms)", "DESC"), "availability" => array("Availability", "ASC")); html_header_sort_checkbox($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"]); $i = 0; if (sizeof($hosts) > 0) { foreach ($hosts as $host) { form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $host["id"]); $i++; form_selectable_cell("<a class='linkEditMain' href='host.php?action=edit&id=" . $host["id"] . "'>" . (strlen($_REQUEST["filter"]) ? eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $host["description"]) : $host["description"]) . "</a>", $host["id"], 250); form_selectable_cell((isset($host_graphs[$host["id"]]) ? $host_graphs[$host["id"]] : 0), $host["id"]); form_selectable_cell((isset($host_data_sources[$host["id"]]) ? $host_data_sources[$host["id"]] : 0), $host["id"]); form_selectable_cell(get_colored_device_status(($host["disabled"] == "on" ? true : false), $host["status"]), $host["id"]); form_selectable_cell((strlen($_REQUEST["filter"]) ? eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $host["hostname"]) : $host["hostname"]), $host["id"]); form_selectable_cell(round(($host["cur_time"]), 2), $host["id"]); form_selectable_cell(round(($host["avg_time"]), 2), $host["id"]); form_selectable_cell(round($host["availability"], 2), $host["id"]); form_checkbox_cell($host["description"], $host["id"]); form_end_row(); } /* put the nav bar on the bottom as well */ print $nav; }else{ print "<tr><td><em>No Hosts</em></td></tr>"; } html_end_box(false); /* add a list of tree names to the actions dropdown */ add_tree_names_to_actions_array(); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($device_actions); }
function host() { global $colors, $device_actions, $item_rows; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("host_template_id")); input_validate_input_number(get_request_var_request("page")); input_validate_input_number(get_request_var_request("host_status")); input_validate_input_number(get_request_var_request("host_rows")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* clean up sort_column */ if (isset($_REQUEST["sort_column"])) { $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column")); } /* clean up search string */ if (isset($_REQUEST["sort_direction"])) { $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction")); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { kill_session_var("sess_device_current_page"); kill_session_var("sess_device_filter"); kill_session_var("sess_device_host_template_id"); kill_session_var("sess_host_status"); kill_session_var("sess_host_rows"); kill_session_var("sess_host_sort_column"); kill_session_var("sess_host_sort_direction"); unset($_REQUEST["page"]); unset($_REQUEST["filter"]); unset($_REQUEST["host_template_id"]); unset($_REQUEST["host_status"]); unset($_REQUEST["host_rows"]); unset($_REQUEST["sort_column"]); unset($_REQUEST["sort_direction"]); } if (!empty($_SESSION["sess_host_status"]) && !empty($_REQUEST["host_status"])) { if ($_SESSION["sess_host_status"] != $_REQUEST["host_status"]) { $_REQUEST["page"] = 1; } } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("page", "sess_device_current_page", "1"); load_current_session_value("filter", "sess_device_filter", ""); load_current_session_value("host_template_id", "sess_device_host_template_id", "-1"); load_current_session_value("host_status", "sess_host_status", "-1"); load_current_session_value("host_rows", "sess_host_rows", read_config_option("num_rows_device")); load_current_session_value("sort_column", "sess_host_sort_column", "description"); load_current_session_value("sort_direction", "sess_host_sort_direction", "ASC"); /* if the number of rows is -1, set it to the default */ if ($_REQUEST["host_rows"] == -1) { $_REQUEST["host_rows"] = read_config_option("num_rows_device"); } ?> <script type="text/javascript"> <!-- function applyViewDeviceFilterChange(objForm) { strURL = '?host_status=' + objForm.host_status.value; strURL = strURL + '&host_template_id=' + objForm.host_template_id.value; strURL = strURL + '&host_rows=' + objForm.host_rows.value; strURL = strURL + '&filter=' + objForm.filter.value; document.location = strURL; } --> </script> <?php html_start_box("<strong>Devices</strong>", "100%", $colors["header"], "3", "center", "host.php?action=edit&host_template_id=" . get_request_var_request("host_template_id") . "&host_status=" . get_request_var_request("host_status")); ?> <tr bgcolor="<?php print $colors["panel"]; ?> "> <form name="form_devices"> <td> <table width="100%" cellpadding="0" cellspacing="0"> <tr> <td nowrap style='white-space: nowrap;' width="50"> Type: </td> <td width="1"> <select name="host_template_id" onChange="applyViewDeviceFilterChange(document.form_devices)"> <option value="-1"<?php if (get_request_var_request("host_template_id") == "-1") { ?> selected<?php } ?> >Any</option> <option value="0"<?php if (get_request_var_request("host_template_id") == "0") { ?> selected<?php } ?> >None</option> <?php $host_templates = db_fetch_assoc("select id,name from host_template order by name"); if (sizeof($host_templates) > 0) { foreach ($host_templates as $host_template) { print "<option value='" . $host_template["id"] . "'"; if (get_request_var_request("host_template_id") == $host_template["id"]) { print " selected"; } print ">" . $host_template["name"] . "</option>\n"; } } ?> </select> </td> <td nowrap style='white-space: nowrap;' width="50"> Status: </td> <td width="1"> <select name="host_status" onChange="applyViewDeviceFilterChange(document.form_devices)"> <option value="-1"<?php if (get_request_var_request("host_status") == "-1") { ?> selected<?php } ?> >Any</option> <option value="-3"<?php if (get_request_var_request("host_status") == "-3") { ?> selected<?php } ?> >Enabled</option> <option value="-2"<?php if (get_request_var_request("host_status") == "-2") { ?> selected<?php } ?> >Disabled</option> <option value="-4"<?php if (get_request_var_request("host_status") == "-4") { ?> selected<?php } ?> >Not Up</option> <option value="3"<?php if (get_request_var_request("host_status") == "3") { ?> selected<?php } ?> >Up</option> <option value="1"<?php if (get_request_var_request("host_status") == "1") { ?> selected<?php } ?> >Down</option> <option value="2"<?php if (get_request_var_request("host_status") == "2") { ?> selected<?php } ?> >Recovering</option> <option value="0"<?php if (get_request_var_request("host_status") == "0") { ?> selected<?php } ?> >Unknown</option> </select> </td> <td nowrap style='white-space: nowrap;' width="20"> Search: </td> <td width="1"> <input type="text" name="filter" size="20" value="<?php print get_request_var_request("filter"); ?> "> </td> <td nowrap style='white-space: nowrap;' width="50"> Rows per Page: </td> <td width="1"> <select name="host_rows" onChange="applyViewDeviceFilterChange(document.form_devices)"> <option value="-1"<?php if (get_request_var_request("host_rows") == "-1") { ?> selected<?php } ?> >Default</option> <?php if (sizeof($item_rows) > 0) { foreach ($item_rows as $key => $value) { print "<option value='" . $key . "'"; if (get_request_var_request("host_rows") == $key) { print " selected"; } print ">" . $value . "</option>\n"; } } ?> </select> </td> <td 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> <input type='hidden' name='page' value='1'> </form> </tr> <?php html_end_box(); /* form the 'where' clause for our main sql query */ if (strlen(get_request_var_request("filter"))) { $sql_where = "where (host.hostname like '%%" . get_request_var_request("filter") . "%%' OR host.description like '%%" . get_request_var_request("filter") . "%%')"; } else { $sql_where = ""; } if (get_request_var_request("host_status") == "-1") { /* Show all items */ } elseif (get_request_var_request("host_status") == "-2") { $sql_where .= strlen($sql_where) ? " and host.disabled='on'" : "where host.disabled='on'"; } elseif (get_request_var_request("host_status") == "-3") { $sql_where .= strlen($sql_where) ? " and host.disabled=''" : "where host.disabled=''"; } elseif (get_request_var_request("host_status") == "-4") { $sql_where .= strlen($sql_where) ? " and (host.status!='3' or host.disabled='on')" : "where (host.status!='3' or host.disabled='on')"; } else { $sql_where .= strlen($sql_where) ? " and (host.status=" . get_request_var_request("host_status") . " AND host.disabled = '')" : "where (host.status=" . get_request_var_request("host_status") . " AND host.disabled = '')"; } if (get_request_var_request("host_template_id") == "-1") { /* Show all items */ } elseif (get_request_var_request("host_template_id") == "0") { $sql_where .= strlen($sql_where) ? " and host.host_template_id=0" : "where host.host_template_id=0"; } elseif (!empty($_REQUEST["host_template_id"])) { $sql_where .= strlen($sql_where) ? " and host.host_template_id=" . get_request_var_request("host_template_id") : "where host.host_template_id=" . get_request_var_request("host_template_id"); } html_start_box("", "100%", $colors["header"], "3", "center", ""); $total_rows = db_fetch_cell("select\n\t\tCOUNT(host.id)\n\t\tfrom host\n\t\t{$sql_where}"); $sortby = get_request_var_request("sort_column"); if ($sortby == "hostname") { $sortby = "INET_ATON(hostname)"; } $host_graphs = array_rekey(db_fetch_assoc("SELECT host_id, count(*) as graphs FROM graph_local GROUP BY host_id"), "host_id", "graphs"); $host_data_sources = array_rekey(db_fetch_assoc("SELECT host_id, count(*) as data_sources FROM data_local GROUP BY host_id"), "host_id", "data_sources"); $sql_query = "SELECT *\n\t\tFROM host\n\t\t{$sql_where}\n\t\tORDER BY " . $sortby . " " . get_request_var_request("sort_direction") . "\n\t\tLIMIT " . get_request_var_request("host_rows") * (get_request_var_request("page") - 1) . "," . get_request_var_request("host_rows"); $hosts = db_fetch_assoc($sql_query); /* generate page list */ $url_page_select = get_page_list(get_request_var_request("page"), MAX_DISPLAY_PAGES, get_request_var_request("host_rows"), $total_rows, "host.php?filter=" . get_request_var_request("filter") . "&host_template_id=" . get_request_var_request("host_template_id") . "&host_status=" . get_request_var_request("host_status")); $nav = "<tr bgcolor='#" . $colors["header"] . "'>\n\t\t\t<td colspan='11'>\n\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td align='left' class='textHeaderDark'>\n\t\t\t\t\t\t\t<strong><< "; if (get_request_var_request("page") > 1) { $nav .= "<a class='linkOverDark' href='host.php?filter=" . get_request_var_request("filter") . "&host_template_id=" . get_request_var_request("host_template_id") . "&host_status=" . get_request_var_request("host_status") . "&page=" . (get_request_var_request("page") - 1) . "'>"; } $nav .= "Previous"; if (get_request_var_request("page") > 1) { $nav .= "</a>"; } $nav .= "</strong>\n\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\n\t\t\t\t\t\t\tShowing Rows " . (get_request_var_request("host_rows") * (get_request_var_request("page") - 1) + 1) . " to " . ($total_rows < read_config_option("num_rows_device") || $total_rows < get_request_var_request("host_rows") * get_request_var_request("page") ? $total_rows : get_request_var_request("host_rows") * get_request_var_request("page")) . " of {$total_rows} [{$url_page_select}]\n\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t<td align='right' class='textHeaderDark'>\n\t\t\t\t\t\t\t<strong>"; if (get_request_var_request("page") * get_request_var_request("host_rows") < $total_rows) { $nav .= "<a class='linkOverDark' href='host.php?filter=" . get_request_var_request("filter") . "&host_template_id=" . get_request_var_request("host_template_id") . "&host_status=" . get_request_var_request("host_status") . "&page=" . (get_request_var_request("page") + 1) . "'>"; } $nav .= "Next"; if (get_request_var_request("page") * get_request_var_request("host_rows") < $total_rows) { $nav .= "</a>"; } $nav .= " >></strong>\n\t\t\t\t\t\t</td>\n\n\t\t\t\t\t</tr>\n\t\t\t\t</table>\n\t\t\t</td>\n\t\t</tr>\n"; print $nav; $display_text = array("description" => array("Description", "ASC"), "id" => array("ID", "ASC"), "nosort1" => array("Graphs", "ASC"), "nosort2" => array("Data Sources", "ASC"), "status" => array("Status", "ASC"), "status_event_count" => array("Event Count", "ASC"), "hostname" => array("Hostname", "ASC"), "cur_time" => array("Current (ms)", "DESC"), "avg_time" => array("Average (ms)", "DESC"), "availability" => array("Availability", "ASC")); html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction")); $i = 0; if (sizeof($hosts) > 0) { foreach ($hosts as $host) { form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $host["id"]); $i++; form_selectable_cell("<a class='linkEditMain' href='host.php?action=edit&id=" . $host["id"] . "'>" . (strlen(get_request_var_request("filter")) ? eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $host["description"]) : $host["description"]) . "</a>", $host["id"], 250); form_selectable_cell(round($host["id"], 2), $host["id"]); form_selectable_cell(isset($host_graphs[$host["id"]]) ? $host_graphs[$host["id"]] : 0, $host["id"]); form_selectable_cell(isset($host_data_sources[$host["id"]]) ? $host_data_sources[$host["id"]] : 0, $host["id"]); form_selectable_cell(get_colored_device_status($host["disabled"] == "on" ? true : false, $host["status"]), $host["id"]); form_selectable_cell(round($host["status_event_count"], 2), $host["id"]); form_selectable_cell(strlen(get_request_var_request("filter")) ? eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $host["hostname"]) : $host["hostname"], $host["id"]); form_selectable_cell(round($host["cur_time"], 2), $host["id"]); form_selectable_cell(round($host["avg_time"], 2), $host["id"]); form_selectable_cell(round($host["availability"], 2), $host["id"]); form_checkbox_cell($host["description"], $host["id"]); form_end_row(); } /* put the nav bar on the bottom as well */ print $nav; } else { print "<tr><td><em>No Hosts</em></td></tr>"; } html_end_box(false); /* add a list of tree names to the actions dropdown */ add_tree_names_to_actions_array(); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($device_actions); print "</form>\n"; }
function graph() { global $colors, $graph_actions; /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { kill_session_var("sess_graph_current_page"); kill_session_var("sess_graph_filter"); kill_session_var("sess_graph_host_id"); unset($_REQUEST["page"]); unset($_REQUEST["filter"]); unset($_REQUEST["host_id"]); } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("page", "sess_graph_current_page", "1"); load_current_session_value("filter", "sess_graph_filter", ""); load_current_session_value("host_id", "sess_graph_host_id", "-1"); html_start_box("<strong>Graph Management</strong>", "98%", $colors["header"], "3", "center", "graphs.php?action=graph_edit&host_id=" . $_REQUEST["host_id"]); include("./include/html/inc_graph_filter_table.php"); html_end_box(); /* form the 'where' clause for our main sql query */ $sql_where = "and graph_templates_graph.title_cache like '%%" . $_REQUEST["filter"] . "%%'"; if ($_REQUEST["host_id"] == "-1") { /* Show all items */ }elseif ($_REQUEST["host_id"] == "0") { $sql_where .= " and graph_local.host_id=0"; }elseif (!empty($_REQUEST["host_id"])) { $sql_where .= " and graph_local.host_id=" . $_REQUEST["host_id"]; } html_start_box("", "98%", $colors["header"], "3", "center", ""); $total_rows = db_fetch_cell("select COUNT(graph_templates_graph.id) from graph_local,graph_templates_graph where graph_local.id=graph_templates_graph.local_graph_id $sql_where"); $graph_list = db_fetch_assoc("select graph_templates_graph.id, graph_templates_graph.local_graph_id, graph_templates_graph.height, graph_templates_graph.width, graph_templates_graph.title_cache, graph_templates.name, graph_local.host_id from graph_local,graph_templates_graph left join graph_templates on graph_local.graph_template_id=graph_templates.id where graph_local.id=graph_templates_graph.local_graph_id $sql_where order by graph_templates_graph.title_cache,graph_local.host_id limit " . (read_config_option("num_rows_graph")*($_REQUEST["page"]-1)) . "," . read_config_option("num_rows_graph")); /* generate page list */ $url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, read_config_option("num_rows_graph"), $total_rows, "graphs.php?filter=" . $_REQUEST["filter"] . "&host_id=" . $_REQUEST["host_id"]); $nav = "<tr bgcolor='#" . $colors["header"] . "'> <td colspan='4'> <table width='100%' cellspacing='0' cellpadding='0' border='0'> <tr> <td align='left' class='textHeaderDark'> <strong><< "; if ($_REQUEST["page"] > 1) { $nav .= "<a class='linkOverDark' href='graphs.php?filter=" . $_REQUEST["filter"] . "&host_id=" . $_REQUEST["host_id"] . "&page=" . ($_REQUEST["page"]-1) . "'>"; } $nav .= "Previous"; if ($_REQUEST["page"] > 1) { $nav .= "</a>"; } $nav .= "</strong> </td>\n <td align='center' class='textHeaderDark'> Showing Rows " . ((read_config_option("num_rows_graph")*($_REQUEST["page"]-1))+1) . " to " . ((($total_rows < read_config_option("num_rows_graph")) || ($total_rows < (read_config_option("num_rows_graph")*$_REQUEST["page"]))) ? $total_rows : (read_config_option("num_rows_graph")*$_REQUEST["page"])) . " of $total_rows [$url_page_select] </td>\n <td align='right' class='textHeaderDark'> <strong>"; if (($_REQUEST["page"] * read_config_option("num_rows_graph")) < $total_rows) { $nav .= "<a class='linkOverDark' href='graphs.php?filter=" . $_REQUEST["filter"] . "&host_id=" . $_REQUEST["host_id"] . "&page=" . ($_REQUEST["page"]+1) . "'>"; } $nav .= "Next"; if (($_REQUEST["page"] * read_config_option("num_rows_graph")) < $total_rows) { $nav .= "</a>"; } $nav .= " >></strong> </td>\n </tr> </table> </td> </tr>\n"; print $nav; html_header_checkbox(array("Graph Title", "Template Name", "Size")); $i = 0; if (sizeof($graph_list) > 0) { foreach ($graph_list as $graph) { form_alternate_row_color($colors["alternate"],$colors["light"],$i); $i++; ?> <td> <a class="linkEditMain" href="graphs.php?action=graph_edit&id=<?php print $graph["local_graph_id"];?>"><?php print eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", title_trim($graph["title_cache"], read_config_option("max_title_graph")));?></a> </td> <td> <?php print ((empty($graph["name"])) ? "<em>None</em>" : $graph["name"]); ?> </td> <td> <?php print $graph["height"];?>x<?php print $graph["width"];?> </td> <td style="<?php print get_checkbox_style();?>" width="1%" align="right"> <input type='checkbox' style='margin: 0px;' name='chk_<?php print $graph["local_graph_id"];?>' title="<?php print $graph["title_cache"];?>"> </td> </tr> <?php } /* put the nav bar on the bottom as well */ print $nav; }else{ print "<tr><td><em>No Graphs Found</em></td></tr>"; } html_end_box(false); /* add a list of tree names to the actions dropdown */ add_tree_names_to_actions_array(); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($graph_actions); print "</form>\n"; }
function graph() { global $colors, $graph_actions; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("host_id")); input_validate_input_number(get_request_var_request("page")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* clean up sort_column string */ if (isset($_REQUEST["sort_column"])) { $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column")); } /* clean up sort_direction string */ if (isset($_REQUEST["sort_direction"])) { $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction")); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { kill_session_var("sess_graph_current_page"); kill_session_var("sess_graph_filter"); kill_session_var("sess_graph_sort_column"); kill_session_var("sess_graph_sort_direction"); kill_session_var("sess_graph_host_id"); unset($_REQUEST["page"]); unset($_REQUEST["filter"]); unset($_REQUEST["sort_column"]); unset($_REQUEST["sort_direction"]); unset($_REQUEST["host_id"]); } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("page", "sess_graph_current_page", "1"); load_current_session_value("filter", "sess_graph_filter", ""); load_current_session_value("sort_column", "sess_graph_sort_column", "title_cache"); load_current_session_value("sort_direction", "sess_graph_sort_direction", "ASC"); load_current_session_value("host_id", "sess_graph_host_id", "-1"); html_start_box("<strong>Graph Management</strong>", "100%", $colors["header"], "3", "center", "graphs.php?action=graph_edit&host_id=" . $_REQUEST["host_id"]); include("./include/html/inc_graph_filter_table.php"); html_end_box(); /* form the 'where' clause for our main sql query */ if (strlen($_REQUEST["filter"])) { $sql_where = "AND (graph_templates_graph.title_cache like '%%" . $_REQUEST["filter"] . "%%'" . " OR graph_templates.name like '%%" . $_REQUEST["filter"] . "%%')"; }else{ $sql_where = ""; } if ($_REQUEST["host_id"] == "-1") { /* Show all items */ }elseif ($_REQUEST["host_id"] == "0") { $sql_where .= " AND graph_local.host_id=0"; }elseif (!empty($_REQUEST["host_id"])) { $sql_where .= " AND graph_local.host_id=" . $_REQUEST["host_id"]; } html_start_box("", "100%", $colors["header"], "3", "center", ""); $total_rows = db_fetch_cell("SELECT COUNT(graph_templates_graph.id) FROM graph_templates_graph, graph_local LEFT JOIN graph_templates ON (graph_local.graph_template_id=graph_templates.id) WHERE graph_local.id=graph_templates_graph.local_graph_id $sql_where"); $graph_list = db_fetch_assoc("SELECT graph_templates_graph.id, graph_templates_graph.local_graph_id, graph_templates_graph.height, graph_templates_graph.width, graph_templates_graph.title_cache, graph_templates.name, graph_local.host_id from graph_templates_graph,graph_local left join graph_templates ON (graph_local.graph_template_id=graph_templates.id) where graph_local.id=graph_templates_graph.local_graph_id $sql_where order by " . $_REQUEST['sort_column'] . " " . $_REQUEST['sort_direction'], read_config_option("num_rows_graph"),(read_config_option("num_rows_graph")*($_REQUEST["page"]-1))); /* generate page list */ $url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, read_config_option("num_rows_graph"), $total_rows, "graphs.php?filter=" . $_REQUEST["filter"] . "&host_id=" . $_REQUEST["host_id"]); $nav = "<tr bgcolor='#" . $colors["header"] . "'> <td colspan='4'> <table width='100%' cellspacing='0' cellpadding='0' border='0'> <tr> <td align='left' class='textHeaderDark'> <strong><< "; if ($_REQUEST["page"] > 1) { $nav .= "<a class='linkOverDark' href='graphs.php?filter=" . $_REQUEST["filter"] . "&host_id=" . $_REQUEST["host_id"] . "&page=" . ($_REQUEST["page"]-1) . "'>"; } $nav .= "Previous"; if ($_REQUEST["page"] > 1) { $nav .= "</a>"; } $nav .= "</strong> </td>\n <td align='center' class='textHeaderDark'> Showing Rows " . ((read_config_option("num_rows_graph")*($_REQUEST["page"]-1))+1) . " to " . ((($total_rows < read_config_option("num_rows_graph")) || ($total_rows < (read_config_option("num_rows_graph")*$_REQUEST["page"]))) ? $total_rows : (read_config_option("num_rows_graph")*$_REQUEST["page"])) . " of $total_rows [$url_page_select] </td>\n <td align='right' class='textHeaderDark'> <strong>"; if (($_REQUEST["page"] * read_config_option("num_rows_graph")) < $total_rows) { $nav .= "<a class='linkOverDark' href='graphs.php?filter=" . $_REQUEST["filter"] . "&host_id=" . $_REQUEST["host_id"] . "&page=" . ($_REQUEST["page"]+1) . "'>"; } $nav .= "Next"; if (($_REQUEST["page"] * read_config_option("num_rows_graph")) < $total_rows) { $nav .= "</a>"; } $nav .= " >></strong> </td>\n </tr> </table> </td> </tr>\n"; print $nav; $display_text = array( "title_cache" => array("Graph Title", "ASC"), "name" => array("Template Name", "ASC"), "height" => array("Size", "ASC")); html_header_sort_checkbox($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"]); $i = 0; if (sizeof($graph_list) > 0) { foreach ($graph_list as $graph) { $template_name = ((empty($graph["name"])) ? "<em>None</em>" : $graph["name"]); form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $graph["local_graph_id"]); $i++; form_selectable_cell("<a class='linkEditMain' href='graphs.php?action=graph_edit&id=" . $graph["local_graph_id"] . "' title='" . htmlspecialchars($graph["title_cache"]) . "'>" . (($_REQUEST["filter"] != "") ? eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", title_trim($graph["title_cache"], read_config_option("max_title_graph"))) : title_trim($graph["title_cache"], read_config_option("max_title_graph"))) . "</a>", $graph["local_graph_id"]); form_selectable_cell((($_REQUEST["filter"] != "") ? eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $template_name) : $template_name) . "</a>", $graph["local_graph_id"]); form_selectable_cell($graph["height"] . "x" . $graph["width"], $graph["local_graph_id"]); form_checkbox_cell($graph["title_cache"], $graph["local_graph_id"]); form_end_row(); } /* put the nav bar on the bottom as well */ print $nav; }else{ print "<tr><td><em>No Graphs Found</em></td></tr>"; } html_end_box(false); /* add a list of tree names to the actions dropdown */ add_tree_names_to_actions_array(); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($graph_actions); print "</form>\n"; }
function host() { global $colors, $device_actions; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("host_template_id")); input_validate_input_number(get_request_var_request("page")); input_validate_input_number(get_request_var_request("host_status")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { kill_session_var("sess_device_current_page"); kill_session_var("sess_device_filter"); kill_session_var("sess_device_host_template_id"); kill_session_var("sess_host_status"); unset($_REQUEST["page"]); unset($_REQUEST["filter"]); unset($_REQUEST["host_template_id"]); unset($_REQUEST["host_status"]); } if (!empty($_SESSION["sess_host_status"])) { if ($_SESSION["sess_host_status"] != $_REQUEST["host_status"]) { $_REQUEST["page"] = 1; } } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("page", "sess_device_current_page", "1"); load_current_session_value("filter", "sess_device_filter", ""); load_current_session_value("host_template_id", "sess_device_host_template_id", "-1"); load_current_session_value("host_status", "sess_host_status", "-1"); html_start_box("<strong>Devices</strong>", "98%", $colors["header"], "3", "center", "host.php?action=edit&host_template_id=" . $_REQUEST["host_template_id"] . "&host_status=" . $_REQUEST["host_status"]); include("./include/html/inc_device_filter_table.php"); html_end_box(); /* form the 'where' clause for our main sql query */ $sql_where = "where (host.hostname like '%%" . $_REQUEST["filter"] . "%%' OR host.description like '%%" . $_REQUEST["filter"] . "%%')"; if ($_REQUEST["host_status"] == "-1") { /* Show all items */ }elseif ($_REQUEST["host_status"] == "-2") { $sql_where .= " and host.disabled='on'"; }else { $sql_where .= " and (host.status=" . $_REQUEST["host_status"] . " AND host.disabled = '')"; } if ($_REQUEST["host_template_id"] == "-1") { /* Show all items */ }elseif ($_REQUEST["host_template_id"] == "0") { $sql_where .= " and host.host_template_id=0"; }elseif (!empty($_REQUEST["host_template_id"])) { $sql_where .= " and host.host_template_id=" . $_REQUEST["host_template_id"]; } html_start_box("", "98%", $colors["header"], "3", "center", ""); $total_rows = db_fetch_cell("select COUNT(host.id) from host $sql_where"); $hosts = db_fetch_assoc("select host.id, host.disabled, host.status, host.hostname, host.description, host.min_time, host.max_time, host.cur_time, host.avg_time, host.availability from host $sql_where order by host.description limit " . (read_config_option("num_rows_device")*($_REQUEST["page"]-1)) . "," . read_config_option("num_rows_device")); /* generate page list */ $url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, read_config_option("num_rows_device"), $total_rows, "host.php?filter=" . $_REQUEST["filter"] . "&host_template_id=" . $_REQUEST["host_template_id"] . "&host_status=" . $_REQUEST["host_status"]); $nav = "<tr bgcolor='#" . $colors["header"] . "'> <td colspan='7'> <table width='100%' cellspacing='0' cellpadding='0' border='0'> <tr> <td align='left' class='textHeaderDark'> <strong><< "; if ($_REQUEST["page"] > 1) { $nav .= "<a class='linkOverDark' href='host.php?filter=" . $_REQUEST["filter"] . "&host_template_id=" . $_REQUEST["host_template_id"] . "&host_status=" . $_REQUEST["host_status"] . "&page=" . ($_REQUEST["page"]-1) . "'>"; } $nav .= "Previous"; if ($_REQUEST["page"] > 1) { $nav .= "</a>"; } $nav .= "</strong> </td>\n <td align='center' class='textHeaderDark'> Showing Rows " . ((read_config_option("num_rows_device")*($_REQUEST["page"]-1))+1) . " to " . ((($total_rows < read_config_option("num_rows_device")) || ($total_rows < (read_config_option("num_rows_device")*$_REQUEST["page"]))) ? $total_rows : (read_config_option("num_rows_device")*$_REQUEST["page"])) . " of $total_rows [$url_page_select] </td>\n <td align='right' class='textHeaderDark'> <strong>"; if (($_REQUEST["page"] * read_config_option("num_rows_device")) < $total_rows) { $nav .= "<a class='linkOverDark' href='host.php?filter=" . $_REQUEST["filter"] . "&host_template_id=" . $_REQUEST["host_template_id"] . "&host_status=" . $_REQUEST["host_status"] . "&page=" . ($_REQUEST["page"]+1) . "'>"; } $nav .= "Next"; if (($_REQUEST["page"] * read_config_option("num_rows_device")) < $total_rows) { $nav .= "</a>"; } $nav .= " >></strong> </td>\n </tr> </table> </td> </tr>\n"; print $nav; html_header_checkbox(array("Description", "Status", "Hostname", "Current (ms)", "Average (ms)", "Availability")); $i = 0; if (sizeof($hosts) > 0) { foreach ($hosts as $host) { form_alternate_row_color($colors["alternate"],$colors["light"],$i); $i++; ?> <td width=250> <a class="linkEditMain" href="host.php?action=edit&id=<?php print $host["id"];?>"><?php print eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $host["description"]);?></a> </td> <td><?php print get_colored_device_status(($host["disabled"] == "on" ? true : false), $host["status"]);?></td> <td><?php print eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $host["hostname"]);?></td> <td><?php print round(($host["cur_time"]), 2);?></td> <td><?php print round(($host["avg_time"]), 2);?></td> <td><?php print round($host["availability"], 2);?>%</td> <td style="<?php print get_checkbox_style();?>" width="1%" align="right"> <input type='checkbox' style='margin: 0px;' name='chk_<?php print $host["id"];?>' title="<?php print $host["description"];?>"> </td> </tr> <?php } /* put the nav bar on the bottom as well */ print $nav; }else{ print "<tr><td><em>No Hosts</em></td></tr>"; } html_end_box(false); /* add a list of tree names to the actions dropdown */ add_tree_names_to_actions_array(); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($device_actions); }
function graph() { global $colors, $graph_actions, $item_rows; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request('host_id')); input_validate_input_number(get_request_var_request('rows')); input_validate_input_number(get_request_var_request('template_id')); input_validate_input_number(get_request_var_request('page')); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST['filter'])) { $_REQUEST['filter'] = sanitize_search_string(get_request_var_request('filter')); } /* clean up sort_column string */ if (isset($_REQUEST['sort_column'])) { $_REQUEST['sort_column'] = sanitize_search_string(get_request_var_request('sort_column')); } /* clean up sort_direction string */ if (isset($_REQUEST['sort_direction'])) { $_REQUEST['sort_direction'] = sanitize_search_string(get_request_var_request('sort_direction')); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST['clear_x'])) { kill_session_var('sess_graph_current_page'); kill_session_var('sess_graph_filter'); kill_session_var('sess_graph_sort_column'); kill_session_var('sess_graph_sort_direction'); kill_session_var('sess_graph_host_id'); kill_session_var('sess_default_rows'); kill_session_var('sess_graph_template_id'); unset($_REQUEST['page']); unset($_REQUEST['filter']); unset($_REQUEST['sort_column']); unset($_REQUEST['sort_direction']); unset($_REQUEST['host_id']); unset($_REQUEST['rows']); unset($_REQUEST['template_id']); } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value('page', 'sess_graph_current_page', '1'); load_current_session_value('filter', 'sess_graph_filter', ''); load_current_session_value('sort_column', 'sess_graph_sort_column', 'title_cache'); load_current_session_value('sort_direction', 'sess_graph_sort_direction', 'ASC'); load_current_session_value('host_id', 'sess_graph_host_id', '-1'); load_current_session_value('rows', 'sess_default_rows', read_config_option('num_rows_table')); load_current_session_value('template_id', 'sess_graph_template_id', '-1'); /* if the number of rows is -1, set it to the default */ if (get_request_var_request('rows') == -1) { $_REQUEST['rows'] = read_config_option('num_rows_table'); } ?> <script type="text/javascript"> <!-- function applyFilter() { strURL = 'graphs.php?host_id=' + $('#host_id').val(); strURL = strURL + '&rows=' + $('#rows').val(); strURL = strURL + '&page=' + $('#page').val(); strURL = strURL + '&filter=' + $('#filter').val(); strURL = strURL + '&template_id=' + $('#template_id').val(); strURL = strURL + '&header=false'; $.get(strURL, function(data) { $('#main').html(data); applySkin(); }); } function clearFilter() { strURL = 'graphs.php?clear_x=1&header=false'; $.get(strURL, function(data) { $('#main').html(data); applySkin(); }); } $(function() { $('#refresh').click(function() { applyFilter(); }); $('#clear').click(function() { clearFilter(); }); $('#filter').change(function() { applyFilter(); }); $('#form_graphs').submit(function(event) { event.preventDefault(); applyFilter(); }); }); --> </script> <?php if (read_config_option('grds_creation_method') == 1) { $add_url = htmlspecialchars('graphs.php?action=graph_edit&host_id=' . get_request_var_request('host_id')); } else { $add_url = ''; } html_start_box('<strong>Graph Management</strong>', '100%', '', '3', 'center', $add_url); ?> <tr class='even noprint'> <td> <form id='form_graphs' name='form_graphs' action='graphs.php'> <table cellpadding='2' cellspacing='0' border='0'> <tr> <?php print html_host_filter($_REQUEST['host_id']); ?> <td> Template </td> <td> <select id='template_id' name='template_id' onChange='applyFilter()'> <option value='-1'<?php if (get_request_var_request('template_id') == '-1') { ?> selected<?php } ?> >Any</option> <option value='0'<?php if (get_request_var_request('template_id') == '0') { ?> selected<?php } ?> >None</option> <?php $templates = get_allowed_graph_templates(); if (sizeof($templates) > 0) { foreach ($templates as $template) { print "<option value='" . $template['id'] . "'"; if (get_request_var_request('template_id') == $template['id']) { print ' selected'; } print '>' . title_trim(htmlspecialchars($template['name']), 40) . "</option>\n"; } } ?> </select> </td> <td> <input type='button' id='refresh' value='Go' title='Set/Refresh Filters'> </td> <td> <input type='button' id='clear' name='clear_x' value='Clear' title='Clear Filters'> </td> </tr> </table> <table cellpadding='2' cellspacing='0' border='0'> <tr> <td width='50'> Search </td> <td> <input id='filter' type='text' name='filter' size='25' value='<?php print htmlspecialchars(get_request_var_request('filter')); ?> '> </td> <td> Graphs </td> <td> <select id='rows' name='rows' onChange='applyFilter()'> <?php if (sizeof($item_rows) > 0) { foreach ($item_rows as $key => $value) { print "<option value='" . $key . "'"; if (get_request_var_request('rows') == $key) { print ' selected'; } print '>' . htmlspecialchars($value) . "</option>\n"; } } ?> </select> </td> </tr> </table> <input type='hidden' id='page' name='page' value='<?php print $_REQUEST['page']; ?> '> </form> </td> </tr> <?php html_end_box(); /* form the 'where' clause for our main sql query */ if (strlen(get_request_var_request('filter'))) { $sql_where = " AND (graph_templates_graph.title_cache like '%%" . get_request_var_request('filter') . "%%'" . " OR graph_templates.name like '%%" . get_request_var_request('filter') . "%%')"; } else { $sql_where = ''; } if (get_request_var_request('host_id') == '-1') { /* Show all items */ } elseif (get_request_var_request('host_id') == '0') { $sql_where .= ' AND graph_local.host_id=0'; } elseif (!empty($_REQUEST['host_id'])) { $sql_where .= ' AND graph_local.host_id=' . get_request_var_request('host_id'); } if (get_request_var_request('template_id') == '-1') { /* Show all items */ } elseif (get_request_var_request('template_id') == '0') { $sql_where .= ' AND graph_templates_graph.graph_template_id=0'; } elseif (!empty($_REQUEST['template_id'])) { $sql_where .= ' AND graph_templates_graph.graph_template_id=' . get_request_var_request('template_id'); } /* allow plugins to modify sql_where */ $sql_where .= api_plugin_hook_function('graphs_sql_where', $sql_where); /* print checkbox form for validation */ print "<form name='chk' method='post' action='graphs.php'>\n"; html_start_box('', '100%', '', '3', 'center', ''); $total_rows = db_fetch_cell("SELECT\n\t\tCOUNT(graph_templates_graph.id)\n\t\tFROM (graph_local, graph_templates_graph)\n\t\tLEFT JOIN graph_templates ON (graph_local.graph_template_id = graph_templates.id)\n\t\tWHERE graph_local.id = graph_templates_graph.local_graph_id\n\t\t{$sql_where}"); $graph_list = db_fetch_assoc("SELECT\n\t\tgraph_templates_graph.id,\n\t\tgraph_templates_graph.local_graph_id,\n\t\tgraph_templates_graph.height,\n\t\tgraph_templates_graph.width,\n\t\tgraph_templates_graph.title_cache,\n\t\tgraph_templates.name,\n\t\tgraph_local.host_id\n\t\tFROM (graph_local, graph_templates_graph)\n\t\tLEFT JOIN graph_templates ON (graph_local.graph_template_id = graph_templates.id)\n\t\tWHERE graph_local.id = graph_templates_graph.local_graph_id\n\t\t{$sql_where}\n\t\tORDER BY " . $_REQUEST['sort_column'] . ' ' . get_request_var_request('sort_direction') . ' LIMIT ' . get_request_var_request('rows') * (get_request_var_request('page') - 1) . ',' . get_request_var_request('rows')); $nav = html_nav_bar('graphs.php?filter=' . get_request_var_request('filter') . '&host_id=' . get_request_var_request('host_id'), MAX_DISPLAY_PAGES, get_request_var_request('page'), get_request_var_request('rows'), $total_rows, 5, 'Graphs', 'page', 'main'); print $nav; $display_text = array('title_cache' => array('display' => 'Graph Name', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'The Title of this Graph. Generally programatically generated from the Graph Template defition or Suggested Naming rules. The max length of the Title is controlled under Settings->Visual.'), 'local_graph_id' => array('display' => 'ID', 'align' => 'right', 'sort' => 'ASC', 'tip' => 'The internal database ID fro this Graph. Useful when performing automation or debugging.'), 'name' => array('display' => 'Template Name', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'The Graph Template that this Graph was based upon.'), 'height' => array('display' => 'Size', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'The size of this Graph when not in Preview mode.')); html_header_sort_checkbox($display_text, get_request_var_request('sort_column'), get_request_var_request('sort_direction'), false); $i = 0; if (sizeof($graph_list) > 0) { foreach ($graph_list as $graph) { /* we're escaping strings here, so no need to escape them on form_selectable_cell */ $template_name = empty($graph['name']) ? '<em>None</em>' : htmlspecialchars($graph['name']); form_alternate_row('line' . $graph['local_graph_id'], true); form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars('graphs.php?action=graph_edit&id=' . $graph['local_graph_id']) . "' title='" . htmlspecialchars($graph['title_cache']) . "'>" . (get_request_var_request('filter') != '' ? preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", title_trim(htmlspecialchars($graph['title_cache']), read_config_option('max_title_length'))) : title_trim(htmlspecialchars($graph['title_cache']), read_config_option('max_title_length'))) . '</a>', $graph['local_graph_id']); form_selectable_cell($graph['local_graph_id'], $graph['local_graph_id'], '', 'text-align:right'); form_selectable_cell(get_request_var_request('filter') != '' ? preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", $template_name) : $template_name, $graph['local_graph_id']); form_selectable_cell($graph['height'] . 'x' . $graph['width'], $graph['local_graph_id']); form_checkbox_cell($graph['title_cache'], $graph['local_graph_id']); form_end_row(); } /* put the nav bar on the bottom as well */ print $nav; } else { print "<tr class='tableRow'><td colspan='5'><em>No Graphs Found</em></td></tr>"; } html_end_box(false); /* add a list of tree names to the actions dropdown */ add_tree_names_to_actions_array(); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($graph_actions); print "</form>\n"; }
function graph() { global $colors, $graph_actions, $item_rows; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("host_id")); input_validate_input_number(get_request_var_request("graph_rows")); input_validate_input_number(get_request_var_request("template_id")); input_validate_input_number(get_request_var_request("page")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* clean up sort_column string */ if (isset($_REQUEST["sort_column"])) { $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column")); } /* clean up sort_direction string */ if (isset($_REQUEST["sort_direction"])) { $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction")); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { kill_session_var("sess_graph_current_page"); kill_session_var("sess_graph_filter"); kill_session_var("sess_graph_sort_column"); kill_session_var("sess_graph_sort_direction"); kill_session_var("sess_graph_host_id"); kill_session_var("sess_graph_rows"); kill_session_var("sess_graph_template_id"); unset($_REQUEST["page"]); unset($_REQUEST["filter"]); unset($_REQUEST["sort_column"]); unset($_REQUEST["sort_direction"]); unset($_REQUEST["host_id"]); unset($_REQUEST["graph_rows"]); unset($_REQUEST["template_id"]); } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("page", "sess_graph_current_page", "1"); load_current_session_value("filter", "sess_graph_filter", ""); load_current_session_value("sort_column", "sess_graph_sort_column", "title_cache"); load_current_session_value("sort_direction", "sess_graph_sort_direction", "ASC"); load_current_session_value("host_id", "sess_graph_host_id", "-1"); load_current_session_value("graph_rows", "sess_graph_rows", read_config_option("num_rows_graph")); load_current_session_value("template_id", "sess_graph_template_id", "-1"); /* if the number of rows is -1, set it to the default */ if (get_request_var_request("graph_rows") == -1) { $_REQUEST["graph_rows"] = read_config_option("num_rows_graph"); } ?> <script type="text/javascript"> <!-- function applyGraphsFilterChange(objForm) { strURL = '?host_id=' + objForm.host_id.value; strURL = strURL + '&graph_rows=' + objForm.graph_rows.value; strURL = strURL + '&filter=' + objForm.filter.value; strURL = strURL + '&template_id=' + objForm.template_id.value; document.location = strURL; } --> </script> <?php html_start_box("<strong>Graph Management</strong>", "100%", "", "3", "center", "graphs.php?action=graph_edit&host_id=" . htmlspecialchars(get_request_var_request("host_id"))); ?> <tr class='even noprint'> <td> <form name="form_graph_id" action="graphs.php"> <table cellpadding="2" cellspacing="0"> <tr> <td width="50"> Host: </td> <td width="1"> <select name="host_id" onChange="applyGraphsFilterChange(document.form_graph_id)"> <option value="-1"<?php if (get_request_var_request("host_id") == "-1") { ?> selected<?php } ?> >Any</option> <option value="0"<?php if (get_request_var_request("host_id") == "0") { ?> selected<?php } ?> >None</option> <?php if (read_config_option("auth_method") != 0) { /* get policy information for the sql where clause */ $current_user = db_fetch_row("select * from user_auth where id=" . $_SESSION["sess_user_id"]); $sql_where = get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]); $hosts = db_fetch_assoc("SELECT DISTINCT host.id, CONCAT_WS('',host.description,' (',host.hostname,')') as name\n\t\t\t\t\t\t\t\t\tFROM (graph_templates_graph,host)\n\t\t\t\t\t\t\t\t\tLEFT JOIN graph_local ON (graph_local.host_id=host.id)\n\t\t\t\t\t\t\t\t\tLEFT JOIN graph_templates ON (graph_templates.id=graph_local.graph_template_id)\n\t\t\t\t\t\t\t\t\tLEFT JOIN user_auth_perms ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=1 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (host.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_templates.id=user_auth_perms.item_id and user_auth_perms.type=4 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . "))\n\t\t\t\t\t\t\t\t\tWHERE graph_templates_graph.local_graph_id=graph_local.id\n\t\t\t\t\t\t\t\t\t" . (empty($sql_where) ? "" : "and {$sql_where}") . "\n\t\t\t\t\t\t\t\t\tORDER BY name"); } else { $hosts = db_fetch_assoc("SELECT DISTINCT host.id, CONCAT_WS('',host.description,' (',host.hostname,')') as name\n\t\t\t\t\t\t\t\t\tFROM host\n\t\t\t\t\t\t\t\t\tORDER BY name"); } if (sizeof($hosts) > 0) { foreach ($hosts as $host) { print "<option value='" . $host["id"] . "'"; if (get_request_var_request("host_id") == $host["id"]) { print " selected"; } print ">" . title_trim(htmlspecialchars($host["name"]), 40) . "</option>\n"; } } ?> </select> </td> <td width="70"> Template: </td> <td width="1"> <select name="template_id" onChange="applyGraphsFilterChange(document.form_graph_id)"> <option value="-1"<?php if (get_request_var_request("template_id") == "-1") { ?> selected<?php } ?> >Any</option> <option value="0"<?php if (get_request_var_request("template_id") == "0") { ?> selected<?php } ?> >None</option> <?php if (read_config_option("auth_method") != 0) { $templates = db_fetch_assoc("SELECT DISTINCT graph_templates.id, graph_templates.name\n\t\t\t\t\t\t\t\t\tFROM (graph_templates_graph,graph_local)\n\t\t\t\t\t\t\t\t\tLEFT JOIN host ON (host.id=graph_local.host_id)\n\t\t\t\t\t\t\t\t\tLEFT JOIN graph_templates ON (graph_templates.id=graph_local.graph_template_id)\n\t\t\t\t\t\t\t\t\tLEFT JOIN user_auth_perms ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=1 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (host.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_templates.id=user_auth_perms.item_id and user_auth_perms.type=4 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . "))\n\t\t\t\t\t\t\t\t\tWHERE graph_templates_graph.local_graph_id=graph_local.id\n\t\t\t\t\t\t\t\t\tAND graph_templates.id IS NOT NULL\n\t\t\t\t\t\t\t\t\t" . (empty($sql_where) ? "" : "AND {$sql_where}") . "\n\t\t\t\t\t\t\t\t\tORDER BY name"); } else { $templates = db_fetch_assoc("SELECT DISTINCT graph_templates.id, graph_templates.name\n\t\t\t\t\t\t\t\t\tFROM graph_templates\n\t\t\t\t\t\t\t\t\tORDER BY name"); } if (sizeof($templates) > 0) { foreach ($templates as $template) { print "<option value='" . $template["id"] . "'"; if (get_request_var_request("template_id") == $template["id"]) { print " selected"; } print ">" . title_trim(htmlspecialchars($template["name"]), 40) . "</option>\n"; } } ?> </select> </td> <td> <input type="submit" value="Go" title="Set/Refresh Filters"> </td> <td> <input type="submit" name="clear_x" value="Clear" title="Clear Filters"> </td> </tr> <tr> <td width="50"> Search: </td> <td> <input type="text" name="filter" size="40" value="<?php print htmlspecialchars(get_request_var_request("filter")); ?> "> </td> <td style='white-space: nowrap;'> Rows per Page: </td> <td width="1"> <select name="graph_rows" onChange="applyGraphsFilterChange(document.form_graph_id)"> <option value="-1"<?php if (get_request_var_request("graph_rows") == "-1") { ?> selected<?php } ?> >Default</option> <?php if (sizeof($item_rows) > 0) { foreach ($item_rows as $key => $value) { print "<option value='" . $key . "'"; if (get_request_var_request("graph_rows") == $key) { print " selected"; } print ">" . htmlspecialchars($value) . "</option>\n"; } } ?> </select> </td> </tr> </table> <input type='hidden' name='page' value='1'> </form> </td> </tr> <?php html_end_box(); /* form the 'where' clause for our main sql query */ if (strlen(get_request_var_request("filter"))) { $sql_where = " AND (graph_templates_graph.title_cache like '%%" . get_request_var_request("filter") . "%%'" . " OR graph_templates.name like '%%" . get_request_var_request("filter") . "%%')"; } else { $sql_where = ""; } if (get_request_var_request("host_id") == "-1") { /* Show all items */ } elseif (get_request_var_request("host_id") == "0") { $sql_where .= " AND graph_local.host_id=0"; } elseif (!empty($_REQUEST["host_id"])) { $sql_where .= " AND graph_local.host_id=" . get_request_var_request("host_id"); } if (get_request_var_request("template_id") == "-1") { /* Show all items */ } elseif (get_request_var_request("template_id") == "0") { $sql_where .= " AND graph_templates_graph.graph_template_id=0"; } elseif (!empty($_REQUEST["template_id"])) { $sql_where .= " AND graph_templates_graph.graph_template_id=" . get_request_var_request("template_id"); } /* allow plugins to modify sql_where */ $sql_where .= api_plugin_hook_function('graphs_sql_where', $sql_where); /* print checkbox form for validation */ print "<form name='chk' method='post' action='graphs.php'>\n"; html_start_box("", "100%", "", "3", "center", ""); $total_rows = db_fetch_cell("SELECT\n\t\tCOUNT(graph_templates_graph.id)\n\t\tFROM (graph_local,graph_templates_graph)\n\t\tLEFT JOIN graph_templates ON (graph_local.graph_template_id=graph_templates.id)\n\t\tWHERE graph_local.id=graph_templates_graph.local_graph_id\n\t\t{$sql_where}"); $graph_list = db_fetch_assoc("SELECT\n\t\tgraph_templates_graph.id,\n\t\tgraph_templates_graph.local_graph_id,\n\t\tgraph_templates_graph.height,\n\t\tgraph_templates_graph.width,\n\t\tgraph_templates_graph.title_cache,\n\t\tgraph_templates.name,\n\t\tgraph_local.host_id\n\t\tFROM (graph_local,graph_templates_graph)\n\t\tLEFT JOIN graph_templates ON (graph_local.graph_template_id=graph_templates.id)\n\t\tWHERE graph_local.id=graph_templates_graph.local_graph_id\n\t\t{$sql_where}\n\t\tORDER BY " . $_REQUEST["sort_column"] . " " . get_request_var_request("sort_direction") . " LIMIT " . get_request_var_request("graph_rows") * (get_request_var_request("page") - 1) . "," . get_request_var_request("graph_rows")); $nav = html_nav_bar("graphs.php?filter=" . get_request_var_request("filter") . "&host_id=" . get_request_var_request("host_id"), MAX_DISPLAY_PAGES, get_request_var_request("page"), get_request_var_request("graph_rows"), $total_rows, 5); print $nav; $display_text = array("title_cache" => array("Graph Title", "ASC"), "local_graph_id" => array("ID", "ASC"), "name" => array("Template Name", "ASC"), "height" => array("Size", "ASC")); html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction"), false); $i = 0; if (sizeof($graph_list) > 0) { foreach ($graph_list as $graph) { /* we're escaping strings here, so no need to escape them on form_selectable_cell */ $template_name = empty($graph["name"]) ? "<em>None</em>" : htmlspecialchars($graph["name"]); form_alternate_row('line' . $graph["local_graph_id"], true); form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars("graphs.php?action=graph_edit&id=" . $graph["local_graph_id"]) . "' title='" . htmlspecialchars($graph["title_cache"], ENT_QUOTES) . "'>" . (get_request_var_request("filter") != "" ? preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", title_trim(htmlspecialchars($graph["title_cache"]), read_config_option("max_title_graph"))) : title_trim(htmlspecialchars($graph["title_cache"]), read_config_option("max_title_graph"))) . "</a>", $graph["local_graph_id"]); form_selectable_cell($graph["local_graph_id"], $graph["local_graph_id"]); form_selectable_cell(get_request_var_request("filter") != "" ? preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $template_name) : $template_name, $graph["local_graph_id"]); form_selectable_cell($graph["height"] . "x" . $graph["width"], $graph["local_graph_id"]); form_checkbox_cell($graph["title_cache"], $graph["local_graph_id"]); form_end_row(); } /* put the nav bar on the bottom as well */ print $nav; } else { print "<tr><td><em>No Graphs Found</em></td></tr>"; } html_end_box(false); /* add a list of tree names to the actions dropdown */ add_tree_names_to_actions_array(); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($graph_actions); print "</form>\n"; }