function mikrotik_view_graphs() { global $current_user, $colors, $config, $host_template_hashes, $graph_template_hashes; include './lib/timespan_settings.php'; include './lib/html_graph.php'; html_graph_validate_preview_request_vars(); /* include graph view filter selector */ html_start_box('<strong>Graph Preview Filters</strong>' . (isset($_REQUEST['style']) && strlen($_REQUEST['style']) ? ' [ Custom Graph List Applied - Filtering from List ]' : ''), '100%', '', '3', 'center', ''); html_graph_preview_filter('mikrotik.php', 'graphs', 'ht.hash IN ("' . implode('","', $host_template_hashes) . '")', 'gt.hash IN ("' . implode('","', $graph_template_hashes) . '")'); html_end_box(); /* the user select a bunch of graphs of the 'list' view and wants them displayed here */ $sql_or = ''; if (isset($_REQUEST['style'])) { if (get_request_var_request('style') == 'selective') { /* process selected graphs */ if (!empty($_REQUEST['graph_list'])) { foreach (explode(',', $_REQUEST['graph_list']) as $item) { $graph_list[$item] = 1; } } else { $graph_list = array(); } if (!empty($_REQUEST['graph_add'])) { foreach (explode(',', $_REQUEST['graph_add']) as $item) { $graph_list[$item] = 1; } } /* remove items */ if (!empty($_REQUEST['graph_remove'])) { foreach (explode(',', $_REQUEST['graph_remove']) as $item) { unset($graph_list[$item]); } } $i = 0; foreach ($graph_list as $item => $value) { $graph_array[$i] = $item; $i++; } if (isset($graph_array) && sizeof($graph_array) > 0) { /* build sql string including each graph the user checked */ $sql_or = array_to_sql_or($graph_array, 'gtg.local_graph_id'); $set_rra_id = empty($rra_id) ? read_graph_config_option('default_rra_id') : get_request_var_request('rra_id'); } } } $total_graphs = 0; // Filter sql_where $sql_where = strlen($_REQUEST['filter']) ? "gtg.title_cache LIKE '%" . get_request_var_request('filter') . "%'" : ''; $sql_where .= (strlen($sql_or) && strlen($sql_where) ? ' AND ' : '') . $sql_or; // Host Id sql_where if ($_REQUEST['host_id'] > 0) { $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.host_id=' . $_REQUEST['host_id']; } else { $host_ids = mikrotik_host_ids_from_hashes($host_template_hashes); if (sizeof($host_ids)) { $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.host_id IN (' . implode(',', $host_ids) . ')'; } else { $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' 1=0'; } } // Graph Template Id sql_where if ($_REQUEST['graph_template_id'] > 0) { $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.graph_template_id=' . $_REQUEST['graph_template_id']; } else { $graph_template_ids = mikrotik_graph_templates_from_hashes($graph_template_hashes); if (sizeof($graph_template_ids)) { $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' gl.graph_template_id IN (' . implode(',', $graph_template_ids) . ')'; } else { $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' 1=0'; } } $limit = $_REQUEST['graphs'] * ($_REQUEST['page'] - 1) . ',' . $_REQUEST['graphs']; $order = 'gtg.title_cache'; $graphs = get_allowed_graphs($sql_where, $order, $limit, $total_graphs); /* do some fancy navigation url construction so we don't have to try and rebuild the url string */ if (preg_match('/page=[0-9]+/', basename($_SERVER['QUERY_STRING']))) { $nav_url = str_replace('&page=' . get_request_var_request('page'), '', get_browser_query_string()); } else { $nav_url = get_browser_query_string() . '&host_id=' . get_request_var_request('host_id'); } $nav_url = preg_replace('/((\\?|&)host_id=[0-9]+|(\\?|&)filter=[a-zA-Z0-9]*)/', '', $nav_url); html_start_box('', '100%', '', '3', 'center', ''); $nav = html_nav_bar($nav_url, MAX_DISPLAY_PAGES, get_request_var_request('page'), get_request_var_request('graphs'), $total_graphs, get_request_var_request('columns'), 'Graphs', 'page', 'main'); print $nav; if (get_request_var_request('thumbnails') == 'true') { html_graph_thumbnail_area($graphs, '', 'graph_start=' . get_current_graph_start() . '&graph_end=' . get_current_graph_end(), '', get_request_var_request('columns')); } else { html_graph_area($graphs, '', 'graph_start=' . get_current_graph_start() . '&graph_end=' . get_current_graph_end(), '', get_request_var_request('columns')); } if ($total_graphs > 0) { print $nav; } html_end_box(); bottom_footer(); }
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 graphs() { global $item_rows; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request('host_id')); input_validate_input_number(get_request_var_request('graph_type')); 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')); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST['clear_x'])) { kill_session_var('sess_graphs_new_filter'); kill_session_var('sess_default_rows'); unset($_REQUEST['filter']); unset($_REQUEST['rows']); $changed = true; } else { /* if any of the settings changed, reset the page number */ $changed = false; $changed += check_changed('host_id', 'sess_graphs_new_host_id'); $changed += check_changed('graph_type', 'sess_graphs_new_graph_type'); $changed += check_changed('filter', 'sess_graphs_new_filter'); $changed += check_changed('rows', 'sess_default_rows'); } load_current_session_value('host_id', 'sess_graphs_new_host_id', db_fetch_cell('SELECT id FROM host ORDER BY description, hostname LIMIT 1')); load_current_session_value('graph_type', 'sess_graphs_new_graph_type', read_config_option('default_graphs_new_dropdown')); load_current_session_value('filter', 'sess_graphs_new_filter', ''); load_current_session_value('rows', 'sess_default_rows', read_config_option('num_rows_table')); if (!empty($_REQUEST['host_id'])) { $host = db_fetch_row_prepared('SELECT id, description, hostname, host_template_id FROM host WHERE id = ?', array($_REQUEST['host_id'])); $header = ' [ ' . htmlspecialchars($host['description']) . ' (' . htmlspecialchars($host['hostname']) . ') ' . (!empty($host['host_template_id']) ? htmlspecialchars(db_fetch_cell_prepared('SELECT name FROM host_template WHERE id = ?', array($host['host_template_id']))) : '') . ' ]'; } else { $host = array(); $header = 'None Host Type'; } $row_limit = get_request_var_request('rows'); html_start_box("<strong>New Graphs for</strong> {$header}", '100%', '', '3', 'center', ''); form_alternate_row(); print '<td class="even">'; ?> <script type='text/javascript'> <!-- function applyFilter() { strURL = '?graph_type=' + $('#graph_type').val(); strURL = strURL + '&host_id=' + $('#host_id').val(); strURL = strURL + '&filter=' + $('#filter').val();; strURL = strURL + '&rows=' + $('#rows').val();; document.location = strURL; } --> </script> <form name='form_graphs_new' action='graphs_new.php'> <table width='100%' cellpadding='2' cellspacing='0' border='0' align='left'> <tr> <?php print html_host_filter($_REQUEST['host_id']); ?> <td style='white-space:nowrap;' width='1'> Graph Types </td> <td width='1'> <select id='graph_type' name='graph_type' onChange='applyFilter()'> <option value='-2'<?php if ($_REQUEST['graph_type'] == '-2') { ?> selected<?php } ?> >All</option> <option value='-1'<?php if ($_REQUEST['graph_type'] == '-1') { ?> selected<?php } ?> >Graph Template Based</option> <?php $snmp_queries = db_fetch_assoc_prepared('SELECT snmp_query.id, snmp_query.name, snmp_query.xml_path FROM (snmp_query, host_snmp_query) WHERE host_snmp_query.snmp_query_id = snmp_query.id AND host_snmp_query.host_id = ? ORDER BY snmp_query.name', array($host['id'])); if (sizeof($snmp_queries) > 0) { foreach ($snmp_queries as $query) { print "<option value='" . $query['id'] . "'"; if ($_REQUEST['graph_type'] == $query['id']) { print ' selected'; } print '>' . $query['name'] . "</option>\n"; } } ?> </select> </td> <td width='50'> Rows </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 rowspan='3' class='textInfo' align='right' valign='top'> <span class='linkMarker'>*</span><a class='hyperLink' href='<?php print htmlspecialchars('host.php?action=edit&id=' . $_REQUEST['host_id']); ?> '>Edit this Device</a><br> <span class='linkMarker'>*</span><a class='hyperLink' href='<?php print htmlspecialchars('host.php?action=edit'); ?> '>Create New Device</a><br> <?php api_plugin_hook('graphs_new_top_links'); ?> </td> </tr> <tr style='<?php if ($_REQUEST['graph_type'] <= 0) { ?> display:none;<?php } ?> '> <td width='50'> Search </td> <td style='white-space:nowrap;'> <input id='filter' type='text' name='filter' size='25' value='<?php print htmlspecialchars(get_request_var_request('filter')); ?> '> </td> <td colspan='3' style='white-space:nowrap;'> <input type='submit' value='Go' title='Set/Refresh Filters'> <input type='submit' name='clear_x' value='Clear' title='Clear Filters'> </td> </tr> </table> </form> </td> </tr> <?php html_end_box(); ?> <form name='chk' method='post' action='graphs_new.php'> <?php $total_rows = sizeof(db_fetch_assoc_prepared('SELECT graph_template_id FROM host_graph WHERE host_id = ?', array($_REQUEST['host_id']))); $i = 0; if ($changed) { foreach ($snmp_queries as $query) { kill_session_var('sess_graphs_new_page' . $query['id']); unset($_REQUEST['page' . $query['id']]); load_current_session_value('page' . $query['id'], 'sess_graphs_new_page' . $query['id'], '1'); } } if ($_REQUEST['graph_type'] > 0) { load_current_session_value('page' . $_REQUEST['graph_type'], 'sess_graphs_new_page' . $_REQUEST['graph_type'], '1'); } else { if ($_REQUEST['graph_type'] == -2) { foreach ($snmp_queries as $query) { load_current_session_value('page' . $query['id'], 'sess_graphs_new_page' . $query['id'], '1'); } } } $script = "<script type='text/javascript'>\nvar gt_created_graphs = new Array();\nvar created_graphs = new Array()\n"; if ($_REQUEST['graph_type'] < 0) { html_start_box('<strong>Graph Templates</strong>', '100%', '', '3', 'center', ''); print "<tr class='tableHeader'>\n\t\t\t\t<td class='tableSubHeaderColumn'>Graph Template Name</td>\n\t\t\t\t<td width='1%' align='center' class='tableSubHeaderCheckbox' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_cg' title='Select All' onClick='SelectAll(\"sg\",this.checked);'></td>\n\n\t\t\t</tr>\n"; $graph_templates = db_fetch_assoc_prepared('SELECT graph_templates.id AS graph_template_id, graph_templates.name AS graph_template_name FROM (host_graph, graph_templates) WHERE host_graph.graph_template_id = graph_templates.id AND host_graph.host_id = ? ORDER BY graph_templates.name', array($_REQUEST['host_id'])); if (!empty($_REQUEST['host_id'])) { $template_graphs = db_fetch_assoc_prepared('SELECT graph_local.graph_template_id FROM (graph_local, host_graph) WHERE graph_local.graph_template_id = host_graph.graph_template_id AND graph_local.host_id = host_graph.host_id AND graph_local.host_id = ? GROUP BY graph_local.graph_template_id', array($host['id'])); if (sizeof($template_graphs) > 0) { $script .= 'var gt_created_graphs = new Array('; $cg_ctr = 0; foreach ($template_graphs as $template_graph) { $script .= ($cg_ctr > 0 ? ',' : '') . "'" . $template_graph['graph_template_id'] . "'"; $cg_ctr++; } $script .= ")\n"; } } /* create a row for each graph template associated with the host template */ if (sizeof($graph_templates) > 0) { foreach ($graph_templates as $graph_template) { $query_row = $graph_template['graph_template_id']; print "<tr id='gt_line{$query_row}' class='selectable " . ($i % 2 == 0 ? 'odd' : 'even') . "'>"; $i++; print "<td>\n\t\t\t\t\t\t<span id='gt_text{$query_row}" . "_0'>" . htmlspecialchars($graph_template['graph_template_name']) . "</span>\n\t\t\t\t\t</td>\n\t\t\t\t\t<td align='right' class='checkbox'>\n\t\t\t\t\t\t<input type='checkbox' name='cg_{$query_row}' id='cg_{$query_row}'>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>"; } } html_end_box(); html_start_box('', '100%', '', '3', 'center', ''); $available_graph_templates = db_fetch_assoc('SELECT graph_templates.id, graph_templates.name FROM snmp_query_graph RIGHT JOIN graph_templates ON (snmp_query_graph.graph_template_id = graph_templates.id) WHERE (((snmp_query_graph.name) Is Null)) ORDER BY graph_templates.name'); /* create a row at the bottom that lets the user create any graph they choose */ print "\t<tr class='even'>\n\t\t\t\t<td width='1'><i>Create</i></td>\n\t\t\t\t<td align='left'>"; form_dropdown('cg_g', $available_graph_templates, 'name', 'id', '', '(Select a graph type to create)', '', 'textArea'); print '</td> </tr>'; html_end_box(); } if ($_REQUEST['graph_type'] != -1 && !empty($_REQUEST['host_id'])) { $snmp_queries = db_fetch_assoc('SELECT snmp_query.id, snmp_query.name, snmp_query.xml_path FROM (snmp_query,host_snmp_query) WHERE host_snmp_query.snmp_query_id=snmp_query.id AND host_snmp_query.host_id=' . $host['id'] . ($_REQUEST['graph_type'] != -2 ? ' AND snmp_query.id=' . $_REQUEST['graph_type'] : '') . ' ORDER BY snmp_query.name'); if (sizeof($snmp_queries) > 0) { foreach ($snmp_queries as $snmp_query) { unset($total_rows); if (!$changed) { $page = $_REQUEST['page' . $snmp_query['id']]; } else { $page = 1; } $xml_array = get_data_query_array($snmp_query['id']); $num_input_fields = 0; $num_visible_fields = 0; if ($xml_array != false) { /* loop through once so we can find out how many input fields there are */ reset($xml_array['fields']); while (list($field_name, $field_array) = each($xml_array['fields'])) { if ($field_array['direction'] == 'input') { $num_input_fields++; if (!isset($total_rows)) { $total_rows = db_fetch_cell_prepared('SELECT count(*) FROM host_snmp_cache WHERE host_id = ? AND snmp_query_id = ? AND field_name = ?', array($host['id'], $snmp_query['id'], $field_name)); } } } } if (!isset($total_rows)) { $total_rows = 0; } $snmp_query_graphs = db_fetch_assoc_prepared('SELECT snmp_query_graph.id,snmp_query_graph.name FROM snmp_query_graph WHERE snmp_query_graph.snmp_query_id = ? ORDER BY snmp_query_graph.name', array($snmp_query['id'])); if (sizeof($snmp_query_graphs) > 0) { foreach ($snmp_query_graphs as $snmp_query_graph) { $created_graphs = db_fetch_assoc_prepared("SELECT DISTINCT\n\t\t\t\t\t\tdata_local. snmp_index\n\t\t\t\t\t\tFROM (data_local, data_template_data)\n\t\t\t\t\t\tLEFT JOIN data_input_data ON (data_template_data.id = data_input_data.data_template_data_id)\n\t\t\t\t\t\tLEFT JOIN data_input_fields ON (data_input_data.data_input_field_id = data_input_fields.id)\n\t\t\t\t\t\tWHERE data_local.id = data_template_data.local_data_id\n\t\t\t\t\t\tAND data_input_fields.type_code = 'output_type'\n\t\t\t\t\t\tAND data_input_data.value = ?\n\t\t\t\t\t\tAND data_local.host_id = ?", array($snmp_query_graph['id'], $host['id'])); $script .= 'created_graphs[' . $snmp_query_graph['id'] . '] = new Array('; $cg_ctr = 0; if (sizeof($created_graphs) > 0) { foreach ($created_graphs as $created_graph) { $script .= ($cg_ctr > 0 ? ',' : '') . "'" . encode_data_query_index($created_graph['snmp_index']) . "'"; $cg_ctr++; } } $script .= ")\n"; } } print "\t<table width='100%' class='cactiTable' align='center' cellpadding='3' cellspacing='0'>\n\n\t\t\t\t\t<tr class='cactiTableTitle'>\n\t\t\t\t\t\t<td colspan='" . ($num_input_fields + 1) . "'>\n\t\t\t\t\t\t\t<table cellspacing='0' cellpadding='0' width='100%' >\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td class='textHeaderDark'>\n\t\t\t\t\t\t\t\t\t\t<strong>Data Query</strong> [" . $snmp_query['name'] . "]\n\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t<td align='right' nowrap>\n\t\t\t\t\t\t\t\t\t\t<a href='" . htmlspecialchars('graphs_new.php?action=query_reload&id=' . $snmp_query['id'] . '&host_id=' . $host['id']) . "'><img src='images/reload_icon_small.gif' title='Reload Associated Query' alt='' border='0' align='absmiddle'></a>\n\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>"; if ($xml_array != false) { $html_dq_header = ''; $snmp_query_indexes = array(); reset($xml_array['fields']); /* if there is a where clause, get the matching snmp_indexes */ $sql_where = ''; if (strlen($_REQUEST['filter'])) { $sql_where = ''; $indexes = db_fetch_assoc("SELECT DISTINCT snmp_index\n\t\t\t\t\t\tFROM host_snmp_cache\n\t\t\t\t\t\tWHERE field_value LIKE '%%" . $_REQUEST['filter'] . "%%'\n\t\t\t\t\t\tAND snmp_query_id=" . $snmp_query['id'] . "\n\t\t\t\t\t\tAND host_id=" . $host['id']); if (sizeof($indexes)) { foreach ($indexes as $index) { if (strlen($sql_where)) { $sql_where .= ", '" . $index['snmp_index'] . "'"; } else { $sql_where .= " AND snmp_index IN('" . $index['snmp_index'] . "'"; } } $sql_where .= ')'; } } if (strlen($_REQUEST['filter']) == 0 || strlen($_REQUEST['filter']) && sizeof($indexes)) { /* determine the sort order */ if (isset($xml_array['index_order_type'])) { if ($xml_array['index_order_type'] == 'numeric') { $sql_order = 'ORDER BY CAST(snmp_index AS unsigned)'; } else { if ($xml_array['index_order_type'] == 'alphabetic') { $sql_order = 'ORDER BY snmp_index'; } else { if ($xml_array['index_order_type'] == 'natural') { $sql_order = 'ORDER BY INET_ATON(snmp_index)'; } else { $sql_order = ''; } } } } else { $sql_order = ''; } /* get the unique field values from the database */ $field_names = db_fetch_assoc_prepared('SELECT DISTINCT field_name FROM host_snmp_cache WHERE host_id = ? AND snmp_query_id = ?', array($host['id'], $snmp_query['id'])); /* build magic query */ $sql_query = 'SELECT host_id, snmp_query_id, snmp_index'; $num_visible_fields = sizeof($field_names); $i = 0; if (sizeof($field_names) > 0) { foreach ($field_names as $column) { $field_name = $column['field_name']; $sql_query .= ", MAX(CASE WHEN field_name='{$field_name}' THEN field_value ELSE NULL END) AS '{$field_name}'"; $i++; } } $sql_query .= ' FROM host_snmp_cache WHERE host_id=' . $host['id'] . ' AND snmp_query_id=' . $snmp_query['id'] . "\n\t\t\t\t\t\t{$sql_where}\n\t\t\t\t\t\tGROUP BY host_id, snmp_query_id, snmp_index\n\t\t\t\t\t\t{$sql_order}\n\t\t\t\t\t\tLIMIT " . $row_limit * ($page - 1) . ',' . $row_limit; $rows_query = 'SELECT host_id, snmp_query_id, snmp_index FROM host_snmp_cache WHERE host_id=' . $host['id'] . ' AND snmp_query_id=' . $snmp_query['id'] . "\n\t\t\t\t\t\t{$sql_where}\n\t\t\t\t\t\tGROUP BY host_id, snmp_query_id, snmp_index"; $snmp_query_indexes = db_fetch_assoc($sql_query); $total_rows = sizeof(db_fetch_assoc($rows_query)); if (($page - 1) * $row_limit > $total_rows) { $page = 1; $_REQUEST['page' . $query['id']] = $page; load_current_session_value('page' . $query['id'], 'sess_graphs_new_page' . $query['id'], '1'); } $nav = html_nav_bar('graphs_new.php', MAX_DISPLAY_PAGES, $page, $row_limit, $total_rows, 15, 'Items', 'page' . $snmp_query['id']); print $nav; while (list($field_name, $field_array) = each($xml_array['fields'])) { if ($field_array['direction'] == 'input' && sizeof($field_names)) { foreach ($field_names as $row) { if ($row['field_name'] == $field_name) { $html_dq_header .= "<td class='tableSubHeaderColumn'>" . $field_array['name'] . "</td>\n"; break; } } } } if (!sizeof($snmp_query_indexes)) { print "<tr class='odd'><td>This Data Query returned 0 rows, perhaps there was a problem executing this\n\t\t\t\t\t\t\tData Query. You can <a href='" . htmlspecialchars('host.php?action=query_verbose&id=' . $snmp_query['id'] . '&host_id=' . $host['id']) . "'>run this Data Query in debug mode</a> to get more information.</td></tr>\n"; } else { print "<tr class='tableHeader'>\n\t\t\t\t\t\t\t\t{$html_dq_header}\n\t\t\t\t\t\t\t\t<td width='1%' align='center' class='tableSubHeaderCheckbox' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_" . $snmp_query['id'] . "' title='Select All' onClick='SelectAll(\"sg_" . $snmp_query['id'] . "\",this.checked)'></td>\n\n\t\t\t\t\t\t\t</tr>\n"; } $row_counter = 0; $column_counter = 0; $fields = array_rekey($field_names, 'field_name', 'field_name'); if (sizeof($snmp_query_indexes) > 0) { foreach ($snmp_query_indexes as $row) { $query_row = $snmp_query['id'] . '_' . encode_data_query_index($row['snmp_index']); print "<tr id='line{$query_row}' class='selectable " . ($row_counter % 2 == 0 ? 'odd' : 'even') . "'>"; $i++; $column_counter = 0; reset($xml_array['fields']); while (list($field_name, $field_array) = each($xml_array['fields'])) { if ($field_array['direction'] == 'input') { if (in_array($field_name, $fields)) { if (isset($row[$field_name])) { print "<td><span id='text{$query_row}" . '_' . $column_counter . "'>" . (strlen($_REQUEST['filter']) ? preg_replace('/(' . preg_quote($_REQUEST['filter']) . ')/i', "<span class='filteredValue'>\\1</span>", $row[$field_name]) : $row[$field_name]) . '</span></td>'; } else { print "<td><span id='text{$query_row}" . '_' . $column_counter . "'></span></td>"; } $column_counter++; } } } print "<td class='checkbox' align='right'>"; print "<input type='checkbox' name='sg_{$query_row}' id='sg_{$query_row}'>"; print '</td>'; print "</tr>\n"; $row_counter++; } } if ($total_rows > $row_limit) { print $nav; } } else { print "<tr class='odd'><td class='textError'>Search Returned no Rows.</td></tr>\n"; } } else { print "<tr class='odd'><td class='textError'>Error in data query.</td></tr>\n"; } print '</table>'; /* draw the graph template drop down here */ $data_query_graphs = db_fetch_assoc_prepared('SELECT snmp_query_graph.id, snmp_query_graph.name FROM snmp_query_graph WHERE snmp_query_graph.snmp_query_id = ? ORDER BY snmp_query_graph.name', array($snmp_query['id'])); if (sizeof($data_query_graphs) == 1) { echo "<input type='hidden' id='sgg_" . $snmp_query['id'] . "' name='sgg_" . $snmp_query['id'] . "' value='" . $data_query_graphs[0]['id'] . "'>\n"; } elseif (sizeof($data_query_graphs) > 1) { print "\t<table align='center' width='100%'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td width='100%' valign='middle'>\n\t\t\t\t\t\t\t\t<img src='images/arrow.gif' align='absmiddle' alt=''>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td style='white-space:nowrap;font-style: italic;'' align='right'>\n\t\t\t\t\t\t\t\tSelect a Graph Type to Create\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td align='right'>\n\t\t\t\t\t\t\t\t<select name='sgg_" . $snmp_query['id'] . "' id='sgg_" . $snmp_query['id'] . "' onChange='dqUpdateDeps(" . $snmp_query['id'] . ',' . (isset($column_counter) ? $column_counter : '') . ");'>\n\t\t\t\t\t\t\t\t\t"; html_create_list($data_query_graphs, 'name', 'id', '0'); print "\n\t\t\t\t\t\t\t\t</select>\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"; } print '<br>'; $script .= 'dqUpdateDeps(' . $snmp_query['id'] . ',' . $num_visible_fields . ");\n"; } } } if (strlen($script)) { $script .= "</script>\n"; print $script; } form_hidden_box('save_component_graph', '1', ''); if (!empty($_REQUEST['host_id'])) { form_hidden_box('host_id', $host['id'], '0'); form_hidden_box('host_template_id', $host['host_template_id'], '0'); } if (isset($_SERVER['HTTP_REFERER']) && !substr_count($_SERVER['HTTP_REFERER'], 'graphs_new')) { $_REQUEST['returnto'] = basename($_SERVER['HTTP_REFERER']); } load_current_session_value('returnto', 'sess_graphs_new_returnto', ''); form_save_button($_REQUEST['returnto']); }
function snmpagent_utilities_run_eventlog() { global $item_rows; define("MAX_DISPLAY_PAGES", 21); $severity_levels = array(SNMPAGENT_EVENT_SEVERITY_LOW => 'LOW', SNMPAGENT_EVENT_SEVERITY_MEDIUM => 'MEDIUM', SNMPAGENT_EVENT_SEVERITY_HIGH => 'HIGH', SNMPAGENT_EVENT_SEVERITY_CRITICAL => 'CRITICAL'); $severity_colors = array(SNMPAGENT_EVENT_SEVERITY_LOW => '#00FF00', SNMPAGENT_EVENT_SEVERITY_MEDIUM => '#FFFF00', SNMPAGENT_EVENT_SEVERITY_HIGH => '#FF0000', SNMPAGENT_EVENT_SEVERITY_CRITICAL => '#FF00FF'); $receivers = db_fetch_assoc("SELECT DISTINCT manager_id, hostname FROM snmpagent_notifications_log INNER JOIN snmpagent_managers ON snmpagent_managers.id = snmpagent_notifications_log.manager_id"); /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("receiver")); if (!in_array(get_request_var_request("severity"), array_keys($severity_levels)) && get_request_var_request("severity") != '-1' && get_request_var_request("severity") != "") { die_html_input_error(); } input_validate_input_number(get_request_var_request("page")); input_validate_input_number(get_request_var_request("rows")); /* ==================================================== */ /* clean up search filter */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } if (isset($_REQUEST["purge_x"])) { db_execute("TRUNCATE table snmpagent_notifications_log;"); /* reset filters */ $_REQUEST["clear_x"] = true; } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { kill_session_var("sess_snmpagent__logs_receiver"); kill_session_var("sess_snmpagent__logs_severity"); kill_session_var("sess_snmpagent__logs_current_page"); kill_session_var("sess_snmpagent__logs_filter"); kill_session_var("sess_default_rows"); unset($_REQUEST["receiver"]); unset($_REQUEST["severity"]); unset($_REQUEST["page"]); unset($_REQUEST["filter"]); unset($_REQUEST["rows"]); } /* reset the current page if the user changed the severity */ if (isset($_SESSION["sess_snmpagent__logs_severity"]) && get_request_var_request("severity") != $_SESSION["sess_snmpagent__logs_severity"]) { kill_session_var("sess_snmpagent__logs_current_page"); unset($_REQUEST["page"]); } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("receiver", "sess_snmpagent__logs_receiver", "-1"); load_current_session_value("page", "sess_snmpagent__logs_current_page", "1"); load_current_session_value("severity", "sess_snmpagent__logs_severity", "-1"); load_current_session_value("filter", "sess_snmpagent__logs_filter", ""); load_current_session_value('rows', 'sess_default_rows', read_config_option('num_rows_table')); /* if the number of rows is -1, set it to the default */ if ($_REQUEST["rows"] == -1) { $_REQUEST["rows"] = read_config_option("num_rows_table"); } $_REQUEST['page_referrer'] = 'view_snmpagent_events'; load_current_session_value('page_referrer', 'page_referrer', 'view_snmpagent_events'); ?> <script type="text/javascript"> <!-- function applyFilter() { strURL = 'utilities.php?action=view_snmpagent_events'; strURL = strURL + '&severity=' + $('#severity').val(); strURL = strURL + '&receiver=' + $('#receiver').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 = 'utilities.php?action=view_snmpagent_events&clear_x=1&header=false'; $.get(strURL, function(data) { $('#main').html(data); applySkin(); }); } $(function(data) { $('#refresh').click(function() { applyFilter(); }); $('#clear').click(function() { clearFilter(); }); $('#form_snmpagent_notifications').submit(function(event) { event.preventDefault(); applyFilter(); }); }); --> </script> <?php html_start_box("<strong>SNMPAgent Notification Log</strong>", "100%", "", "3", "center", ""); ?> <tr class='even noprint'> <td> <form id='form_snmpagent_notifications' name="form_snmpagent_notifications" action="utilities.php"> <table cellpadding="2" cellspacing="0"> <tr> <td> Severity: </td> <td> <select id="severity" name="severity" onChange="applyFilter()"> <option value="-1"<?php if (get_request_var_request("severity") == "-1") { ?> selected<?php } ?> >Any</option> <?php foreach ($severity_levels as $level => $name) { print "<option value='" . $level . "'"; if (get_request_var_request("severity") == $level) { print " selected"; } print ">" . $name . "</option>\n"; } ?> </select> </td> <td> Receiver: </td> <td width="1"> <select id="receiver" name="receiver" onChange="applyFilter()"> <option value="-1"<?php if (get_request_var_request("receiver") == "-1") { ?> selected<?php } ?> >Any</option> <?php foreach ($receivers as $receiver) { print "<option value='" . $receiver["manager_id"] . "'"; if (get_request_var_request("receiver") == $receiver["manager_id"]) { print " selected"; } print ">" . $receiver["hostname"] . "</option>\n"; } ?> </select> </td> <td> 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> Rows: </td> <td> <select id='rows' name="rows" onChange="applyFilter()"> <option value="-1"<?php if (get_request_var_request("rows") == "-1") { ?> selected<?php } ?> >Default</option> <?php if (sizeof($item_rows) > 0) { foreach ($item_rows as $key => $value) { print "<option value='" . $key . "'"; if (get_request_var_request("rows") == $key) { print " selected"; } print ">" . htmlspecialchars($value) . "</option>\n"; } } ?> </select> </td> <td> <input type="submit" id="refresh" name="go" value="Go" title="Set/Refresh Filters"> <input type="submit" id="clear" name="clear_x" value="Clear" title="Clear Filters"> <input type="submit" id="purge" name="purge_x" value="Purge" title="Purge Notification Log"> </td> </tr> </table> <input type='hidden' id='page' name='page' value='<?php print $_REQUEST['page']; ?> '> </form> </td> </tr> <?php html_end_box(); $sql_where = " 1"; /* filter by severity */ if (get_request_var_request("receiver") != "-1") { $sql_where .= " AND snmpagent_notifications_log.manager_id='" . get_request_var_request("receiver") . "'"; } /* filter by severity */ if (get_request_var_request("severity") == "-1") { /* Show all items */ } elseif (!empty($_REQUEST["severity"])) { $sql_where .= " AND snmpagent_notifications_log.severity='" . get_request_var_request("severity") . "'"; } /* filter by search string */ if (get_request_var_request("filter") != "") { $sql_where .= " AND (`varbinds` LIKE '%%" . get_request_var_request("filter") . "%%')"; } $sql_where .= ' ORDER by `time` DESC'; $sql_query = "SELECT snmpagent_notifications_log.*, snmpagent_managers.hostname, snmpagent_cache.description FROM snmpagent_notifications_log\n\t\t\t\t\t INNER JOIN snmpagent_managers ON snmpagent_managers.id = snmpagent_notifications_log.manager_id\n\t\t\t\t\t LEFT JOIN snmpagent_cache ON snmpagent_cache.name = snmpagent_notifications_log.notification\n\t\t\t\t\t WHERE {$sql_where} LIMIT " . read_config_option("num_rows_data_source") * (get_request_var_request("page") - 1) . "," . read_config_option("num_rows_data_source"); /* print checkbox form for validation */ print "<form name='chk' method='post' action='managers.php'>\n"; html_start_box("", "100%", "", "3", "center", ""); $total_rows = db_fetch_cell("SELECT COUNT(*) FROM snmpagent_notifications_log WHERE {$sql_where}"); $logs = db_fetch_assoc($sql_query); /* generate page list */ $nav = html_nav_bar("utilities.php?action=view_snmpagent_events&severity=" . get_request_var_request("severity") . "&receiver=" . get_request_var_request("receiver") . "&filter=" . get_request_var_request("filter"), MAX_DISPLAY_PAGES, get_request_var_request("page"), get_request_var_request("rows"), $total_rows, 11, '', 'page', 'main'); print $nav; html_header(array(" ", "Time", "Receiver", "Notification", "Varbinds")); if (sizeof($logs) > 0) { foreach ($logs as $item) { $varbinds = strlen(get_request_var_request("filter")) ? preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $item["varbinds"]) : $item["varbinds"]; form_alternate_row('line' . $item["id"], false); print "<td title='Severity Level: " . $severity_levels[$item["severity"]] . "' style='width:10px;background-color: " . $severity_colors[$item["severity"]] . ";border-top:1px solid white;border-bottom:1px solid white;'></td>"; print "<td style='white-space: nowrap;'>" . date("Y/m/d H:i:s", $item["time"]) . "</td>"; print "<td>" . $item["hostname"] . "</td>"; if ($item["description"]) { print '<td><a href="#" title="<div class=\'header\'>' . $item["notification"] . '</div><div class=\'content preformatted\'>' . $item["description"] . '</div>" class="tooltip">' . $item["notification"] . '</a></td>'; } else { print "<td>{$item["notification"]}</td>"; } print "<td>{$varbinds}</td>"; form_end_row(); } print $nav; } else { print "<tr><td><em>No SNMP Notification Log Entries</em></td></tr>"; } html_end_box(); ?> <script language="javascript" type="text/javascript" > $('.tooltip').tooltip({ track: true, position: { collision: "flipfit" }, content: function() { return $(this).attr('title'); } }); </script> <?php }
function mactrack_site() { global $site_actions, $config, $item_rows; mactrack_site_validate_req_vars(); if (get_request_var('rows') == -1) { $row_limit = read_config_option('num_rows_table'); } elseif (get_request_var('rows') == -2) { $row_limit = 999999; } else { $row_limit = get_request_var('rows'); } html_start_box(__('MacTrack Site Filters'), '100%', '', '3', 'center', 'mactrack_sites.php?action=edit'); mactrack_site_filter(); html_end_box(); $sql_where = ''; $sites = mactrack_site_get_site_records($sql_where, $row_limit); if (get_request_var('detail') == 'false') { $total_rows = db_fetch_cell("SELECT\n\t\t\tCOUNT(mac_track_sites.site_id)\n\t\t\tFROM mac_track_sites\n\t\t\t{$sql_where}"); } else { $total_rows = db_fetch_cell("SELECT count(*)\n\t\t\tFROM (mac_track_device_types\n\t\t\tRIGHT JOIN mac_track_devices ON (mac_track_device_types.device_type_id = mac_track_devices.device_type_id))\n\t\t\tRIGHT JOIN mac_track_sites ON (mac_track_devices.site_id = mac_track_sites.site_id)\n\t\t\t{$sql_where}\n\t\t\tGROUP BY mac_track_sites.site_name, mac_track_device_types.device_type_id"); } if (get_request_var('detail') == 'false') { $nav = html_nav_bar('mactrack_sites.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_filter_request_var('page'), $row_limit, $total_rows, 9, __('Sites')); print $nav; html_start_box('', '100%', '', '3', 'center', ''); $display_text = array('site_name' => array(__('Site Name'), 'ASC'), 'total_devices' => array(__('Devices'), 'DESC'), 'total_ips' => array(__('Total IP\'s'), 'DESC'), 'total_user_ports' => array(__('User Ports'), 'DESC'), 'total_oper_ports' => array(__('User Ports Up'), 'DESC'), 'total_macs' => array(__('MACS Found'), 'DESC'), 'total_device_errors' => array(__('Device Errors'), 'DESC')); html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction')); $i = 0; if (sizeof($sites)) { foreach ($sites as $site) { form_alternate_row('line' . $site['site_id'], true); form_selectable_cell("<a class='linkEditMain' href='mactrack_sites.php?action=edit&site_id=" . $site['site_id'] . "'>" . (get_request_var('filter') != '' ? preg_replace('/(' . preg_quote(get_request_var('filter')) . ')/i', "<span class='filteredValue'>\\1</span>", $site['site_name']) : $site['site_name']) . '</a>', $site['site_id']); form_selectable_cell(number_format_i18n($site['total_devices']), $site['site_id']); form_selectable_cell(number_format_i18n($site['total_ips']), $site['site_id']); form_selectable_cell(number_format_i18n($site['total_user_ports']), $site['site_id']); form_selectable_cell(number_format_i18n($site['total_oper_ports']), $site['site_id']); form_selectable_cell(number_format_i18n($site['total_macs']), $site['site_id']); form_selectable_cell($site['total_device_errors'], $site['site_id']); form_checkbox_cell($site['site_name'], $site['site_id']); form_end_row(); } } else { print '<tr><td><em>' . __('No MacTrack Sites') . '</em></td></tr>'; } html_end_box(false); if (sizeof($sites)) { print $nav; } } else { $nav = html_nav_bar('mactrack_sites.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_filter_request_var('page'), $row_limit, $total_rows, 10, __('Sites')); print $nav; html_start_box('', '100%', '', '3', 'center', ''); $display_text = array('site_name' => array(__('Site Name'), 'ASC'), 'vendor' => array(__('Vendor'), 'ASC'), 'description' => array(__('Device Type'), 'DESC'), 'total_devices' => array(__('Total Devices'), 'DESC'), 'sum_ips_total' => array(__('Total IP\'s'), 'DESC'), 'sum_ports_total' => array(__('Total User Ports'), 'DESC'), 'sum_ports_active' => array(__('Total Oper Ports'), 'DESC'), 'sum_ports_trunk' => array(__('Total Trunks'), 'DESC'), 'sum_macs_active' => array(__('MACS Found'), 'DESC')); html_header_sort($display_text, get_request_var('sort_column'), get_request_var('sort_direction')); if (sizeof($sites)) { foreach ($sites as $site) { form_alternate_row(); ?> <td width=200> <a class='linkEditMain' href='mactrack_sites.php?action=edit&site_id=<?php print $site['site_id']; ?> '><?php print get_request_var('filter') != '' ? preg_replace('/(' . preg_quote(get_request_var('filter')) . ')/i', "<span class='filteredValue'>\\1</span>", $site['site_name']) : $site['site_name']; ?> </a> </td> <td><?php print get_request_var('filter') != '' ? preg_replace('/(' . preg_quote(get_request_var('filter')) . ')/i', "<span class='filteredValue'>\\1</span>", $site['vendor']) : $site['vendor']; ?> </td> <td><?php print get_request_var('filter') != '' ? preg_replace('/(' . preg_quote(get_request_var('filter')) . ')/i', "<span class='filteredValue'>\\1</span>", $site['description']) : $site['description']; ?> </td> <td><?php print number_format_i18n($site['total_devices']); ?> </td> <td><?php print number_format_i18n($site['sum_ips_total']); ?> </td> <td><?php print number_format_i18n($site['sum_ports_total']); ?> </td> <td><?php print number_format_i18n($site['sum_ports_active']); ?> </td> <td><?php print number_format_i18n($site['sum_ports_trunk']); ?> </td> <td><?php print number_format_i18n($site['sum_macs_active']); ?> </td> </tr> <?php } } else { print '<tr><td><em>' . __('No MacTrack Sites') . '</em></td></tr>'; } html_end_box(false); if (sizeof($sites)) { print $nav; } } /* draw the dropdown containing a list of available actions for this form */ if (get_request_var('detail') == 'false') { draw_actions_dropdown($site_actions); } }
function update_show_current() { global $plugins, $pluginslist, $plugin_architecture, $config, $status_names, $actions, $item_rows; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("page")); input_validate_input_number(get_request_var_request("rows")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* clean up sort_column */ if (isset($_REQUEST["sort_column"])) { $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column")); } /* clean up search string */ if (isset($_REQUEST["sort_direction"])) { $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction")); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { kill_session_var("sess_plugins_filter"); kill_session_var("sess_plugins_rows"); kill_session_var("sess_plugins_sort_column"); kill_session_var("sess_plugins_sort_direction"); unset($_REQUEST["page"]); unset($_REQUEST["rows"]); unset($_REQUEST["filter"]); unset($_REQUEST["sort_column"]); unset($_REQUEST["sort_direction"]); $_REQUEST["page"] = 1; } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("filter", "sess_plugins_filter", ""); load_current_session_value("rows", "sess_plugins_rows", "-1"); load_current_session_value("sort_column", "sess_plugins_sort_column", "name"); load_current_session_value("sort_direction", "sess_plugins_sort_direction", "ASC"); load_current_session_value("page", "sess_plugins_current_page", "1"); $table = plugins_load_temp_table(); ?> <script type="text/javascript"> <!-- function applyFilterChange(objForm) { strURL = '?rows=' + objForm.rows.value; strURL = strURL + '&filter=' + objForm.filter.value; document.location = strURL; } --> </script> <?php html_start_box("<strong>Plugin Management</strong> (Cacti Version: " . $config["cacti_version"] . (isset($plugin_architecture['version']) ? ", Plugin Architecture Version: " . $plugin_architecture['version'] : "") . ")", "100%", "", "3", "center", ""); ?> <tr class='even noprint'> <td class="noprint"> <form name="form_plugins" method="get" action="plugins.php"> <table cellpadding="0" cellspacing="0"> <tr class="noprint"> <td nowrap style='white-space: nowrap;' width="50"> Search: </td> <td width="1"> <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: </td> <td width="1"> <select name="rows" onChange="applyFilterChange(document.form_plugins)"> <option value="-1"<?php if (get_request_var_request("rows") == "-1") { ?> selected<?php } ?> >Default</option> <?php if (sizeof($item_rows) > 0) { foreach ($item_rows as $key => $value) { print "<option value='" . $key . "'"; if (get_request_var_request("rows") == $key) { print " selected"; } print ">" . htmlspecialchars($value) . "</option>\n"; } } ?> </select> </td> <td nowrap style='white-space: nowrap;'> <input type="submit" value="Go" title="Set/Refresh Filters"> </td> <td nowrap style='white-space: nowrap;'> <input type="submit" name="clear_x" value="Clear" title="Clear Filters"> </td> </tr> </table> <input type='hidden' name='page' value='1'> </form> </td> </tr> <?php html_end_box(); /* print checkbox form for validation */ print "<form name='chk' method='post' action='plugins.php'>\n"; html_start_box("", "100%", "", "3", "center", ""); /* form the 'where' clause for our main sql query */ $sql_where = "WHERE ({$table}.name LIKE '%%" . get_request_var_request("filter") . "%%')"; if (get_request_var_request("sort_column") == "version") { $sortc = "version+0"; } else { $sortc = get_request_var_request("sort_column"); } if (get_request_var_request("sort_column") == "id") { $sortd = "ASC"; } else { $sortd = get_request_var_request("sort_direction"); } if ($_REQUEST['rows'] == '-1') { $rows = read_config_option('num_rows_device'); } else { $rows = get_request_var_request('rows'); } $total_rows = db_fetch_cell("SELECT\n\t\tcount(*)\n\t\tFROM {$table}\n\t\t{$sql_where}"); $plugins = db_fetch_assoc("SELECT *\n\t\tFROM {$table}\n\t\t{$sql_where}\n\t\tORDER BY " . $sortc . " " . $sortd . "\n\t\tLIMIT " . $rows * (get_request_var_request("page") - 1) . "," . $rows); db_execute("DROP TABLE {$table}"); $nav = html_nav_bar("plugins.php?filter=" . get_request_var_request("filter"), MAX_DISPLAY_PAGES, get_request_var_request("page"), $rows, $total_rows, 8); print $nav; $display_text = array("nosort" => array("Actions", ""), "directory" => array("Name", "ASC"), "version" => array("Version", "ASC"), "id" => array("Load Order", "ASC"), "name" => array("Description", "ASC"), "nosort1" => array("Type", "ASC"), "status" => array("Status", "ASC"), "author" => array("Author", "ASC")); html_header_sort($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction"), 1); $i = 0; if (sizeof($plugins)) { if (get_request_var_request("sort_column") == "id") { $inst_system_plugins = get_system_plugins($plugins); if (sizeof($inst_system_plugins)) { foreach ($inst_system_plugins as $plugin) { form_alternate_row('', true); print format_plugin_row($plugin, false, false, true); } } } $j = 0; foreach ($plugins as $plugin) { if (isset($plugins[$j + 1]) && $plugins[$j + 1]['status'] < 0 || !isset($plugins[$j + 1])) { $last_plugin = true; } else { $last_plugin = false; } if ($plugin['status'] <= 0 || is_system_plugin($plugin) || get_request_var_request('sort_column') != 'id') { $load_ordering = false; } else { $load_ordering = true; } if (get_request_var_request("sort_column") == "id") { if (!is_system_plugin($plugin)) { form_alternate_row('', true); print format_plugin_row($plugin, $last_plugin, $load_ordering, false); $i++; } } else { form_alternate_row('', true); print format_plugin_row($plugin, $last_plugin, $load_ordering, is_system_plugin($plugin)); $i++; } $j++; } print $nav; } else { print "<tr><td><em>No Plugins Found</em></td></tr>"; } html_end_box(false); html_start_box("", "100%", "", "3", "center", ""); echo "<tr><td colspan=10><strong>NOTE:</strong> Please sort by 'Load Order' to change plugin load ordering.<br><strong>NOTE:</strong> SYSTEM plugins can not be ordered.</td></tr>"; html_end_box(); print "</form>\n"; }
}else{ $nav_url = basename($_SERVER["PHP_SELF"]) . "?" . $_SERVER["QUERY_STRING"] . "&page=<PAGE>&host_id=" . $_REQUEST["host_id"]; } $nav_url = ereg_replace("((\?|&)host_id=[0-9]+|(\?|&)filter=[a-zA-Z0-9]*)", "", $nav_url); html_graph_start_box(1, true); html_nav_bar($colors["header_panel"], read_graph_config_option("num_columns"), $_REQUEST["page"], ROWS_PER_PAGE, $total_rows, $nav_url); if (read_graph_config_option("thumbnail_section_preview") == "on") { html_graph_thumbnail_area($graphs, "","graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end()); }else{ html_graph_area($graphs, "", "graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end()); } html_nav_bar($colors["header_panel"], read_graph_config_option("num_columns"), $_REQUEST["page"], ROWS_PER_PAGE, $total_rows, $nav_url); html_graph_end_box(); print "<br><br>"; break; case 'list': define("ROWS_PER_PAGE", read_graph_config_option("list_graphs_per_page")); if ((read_config_option("auth_method") != 0) && (empty($current_user["show_list"]))) { print "<strong><font size='+1' color='FF0000'>YOU DO NOT HAVE RIGHTS FOR LIST VIEW</font></strong>"; exit; }
function data_query() { global $dq_actions, $item_rows; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request('page')); 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_data_queries_filter'); kill_session_var('sess_default_rows'); kill_session_var('sess_data_queries_sort_column'); kill_session_var('sess_data_queries_sort_direction'); unset($_REQUEST['page']); unset($_REQUEST['filter']); unset($_REQUEST['rows']); unset($_REQUEST['sort_column']); unset($_REQUEST['sort_direction']); $_REQUEST['page'] = 1; } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value('sort_column', 'sess_data_queries_sort_column', 'name'); load_current_session_value('sort_direction', 'sess_data_queries_sort_direction', 'ASC'); load_current_session_value('page', 'sess_data_queries_current_page', '1'); load_current_session_value('filter', 'sess_data_queries_filter', ''); load_current_session_value('rows', 'sess_default_rows', read_config_option('num_rows_table')); html_start_box('<strong>Data Queries</strong>', '100%', '', '3', 'center', 'data_queries.php?action=edit'); ?> <tr class='even noprint'> <td class="noprint"> <form id="form_data_queries" method="get" action="data_queries.php"> <table cellpadding="2" cellspacing="0"> <tr class="noprint"> <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 style='white-space:nowrap;'> Data Queries </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> <script type='text/javascript'> function applyFilter() { strURL = 'data_queries.php?filter='+$('#filter').val()+'&rows='+$('#rows').val()+'&page='+$('#page').val()+'&header=false'; $.get(strURL, function(data) { $('#main').html(data); applySkin(); }); } function clearFilter() { strURL = 'data_queries.php?clear_x=1&header=false'; $.get(strURL, function(data) { $('#main').html(data); applySkin(); }); } $(function() { $('#refresh').click(function() { applyFilter(); }); $('#clear').click(function() { clearFilter(); }); $('#form_data_queries').submit(function(event) { event.preventDefault(); applyFilter(); }); }); </script> </td> </tr> <?php html_end_box(); /* print checkbox form for validation */ print "<form name='chk' method='post' action='data_queries.php'>\n"; html_start_box('', '100%', '', '3', 'center', ''); /* form the 'where' clause for our main sql query */ if (strlen(get_request_var_request('filter'))) { $sql_where = "WHERE (sq.name like '%%" . get_request_var_request('filter') . "%%' OR di.name like '%%" . get_request_var_request('filter') . "%%')"; } else { $sql_where = ''; } $total_rows = db_fetch_cell("SELECT\n\t\tCOUNT(*)\n\t\tFROM snmp_query AS sq\n\t\tINNER JOIN data_input AS di\n\t\tON (sq.data_input_id=di.id)\n\t\t{$sql_where}"); $snmp_queries = db_fetch_assoc("SELECT sq.id, sq.name,\n\t\tdi.name AS data_input_method, \n\t\tCOUNT(DISTINCT gl.id) AS graphs,\n\t\tCOUNT(DISTINCT sqg.graph_template_id) AS templates\n\t\tFROM snmp_query AS sq\n\t\tLEFT JOIN snmp_query_graph AS sqg\n\t\tON sq.id=sqg.snmp_query_id\n\t\tLEFT JOIN data_input AS di\n\t\tON (sq.data_input_id=di.id)\n\t\tLEFT JOIN graph_local AS gl\n\t\tON gl.snmp_query_id=sq.id\n\t\t{$sql_where}\n\t\tGROUP BY sq.id\n\t\tORDER BY " . get_request_var_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('data_queries.php?filter=' . get_request_var_request('filter'), MAX_DISPLAY_PAGES, get_request_var_request('page'), get_request_var_request('rows'), $total_rows, 7, 'Data Queries', 'page', 'main'); print $nav; $display_text = array('name' => array('display' => 'Data Query Name', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'The name of this Data Query.'), 'nosort' => array('display' => 'Deletable', 'align' => 'right', 'tip' => 'Data Queries that are in use can not be Deleted. In use is defined as being referenced by either a Graph or a Graph Template.'), 'graphs' => array('display' => 'Graphs Using', 'align' => 'right', 'sort' => 'DESC', 'tip' => 'The number of Graphs using this Data Query.'), 'templates' => array('display' => 'Templates Using', 'align' => 'right', 'sort' => 'DESC', 'tip' => 'The number of Graphs Templates using this Data Query.'), 'data_input_method' => array('display' => 'Data Input Method', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'The Data Input Method used to collect data for Data Sources associated with this Data Query.'), 'id' => array('display' => 'ID', 'align' => 'right', 'sort' => 'ASC', 'tip' => 'The internal ID for this Graph Template. Useful when performing automation or debugging.')); html_header_sort_checkbox($display_text, get_request_var_request('sort_column'), get_request_var_request('sort_direction'), false); $i = 0; if (sizeof($snmp_queries) > 0) { foreach ($snmp_queries as $snmp_query) { if ($snmp_query['graphs'] == 0 && $snmp_query['templates'] == 0) { $disabled = false; } else { $disabled = true; } form_alternate_row('line' . $snmp_query['id'], true, $disabled); form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars('data_queries.php?action=edit&id=' . $snmp_query['id']) . "'>" . (strlen(get_request_var_request('filter')) ? preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", htmlspecialchars($snmp_query['name'])) : htmlspecialchars($snmp_query['name'])) . '</a>', $snmp_query['id']); form_selectable_cell($disabled ? 'No' : 'Yes', $snmp_query['id'], '', 'text-align:right'); form_selectable_cell(number_format($snmp_query['graphs']), $snmp_query['id'], '', 'text-align:right'); form_selectable_cell(number_format($snmp_query['templates']), $snmp_query['id'], '', 'text-align:right'); form_selectable_cell(strlen(get_request_var_request('filter')) ? preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", $snmp_query['data_input_method']) : $snmp_query['data_input_method'], $snmp_query['id']); form_selectable_cell($snmp_query['id'], $snmp_query['id'], '', 'text-align:right;'); form_checkbox_cell($snmp_query['name'], $snmp_query['id'], $disabled); form_end_row(); } print $nav; } else { print "<tr class='tableRow'><td colspan='5'><em>No Data Queries</em></td></tr>"; } html_end_box(false); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($dq_actions); }
function domains() { global $domain_types, $actions, $item_rows; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request('page')); 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_domains_filter'); kill_session_var('sess_domains_rows'); kill_session_var('sess_domains_sort_column'); kill_session_var('sess_domains_sort_direction'); unset($_REQUEST['page']); unset($_REQUEST['rows']); unset($_REQUEST['filter']); unset($_REQUEST['sort_column']); unset($_REQUEST['sort_direction']); $_REQUEST['page'] = 1; } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value('filter', 'sess_domains_filter', ''); load_current_session_value('rows', 'sess_table_rows', read_config_option('num_rows_table')); load_current_session_value('sort_column', 'sess_domains_sort_column', 'domain_name'); load_current_session_value('sort_direction', 'sess_domains_sort_direction', 'ASC'); load_current_session_value('page', 'sess_domains_current_page', '1'); html_start_box('<strong>User Domains</strong>', '100%', '', '3', 'center', 'user_domains.php?action=edit'); ?> <tr class='even' class='noprint'> <td class='noprint'> <form id='form_domains' method='get' action='user_domains.php'> <table cellpadding='2' cellspacing='0' border='0'> <tr class='noprint'> <td width='50'> Search </td> <td> <input id='filter' type='text' name='filter' size='25' value='<?php print get_request_var_request('filter'); ?> '> </td> <td> Domains </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 id='refresh' type='button' value='Go' title='Set/Refresh Filters'> </td> <td> <input id='clear' type='button' name='clear_x' value='Clear' title='Clear Filters'> </td> </tr> </table> <input type='hidden' name='page' value='<?php print $_REQUEST['page']; ?> '> </form> <script type='text/javascript'> function applyFilter() { strURL = 'user_domains.php?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 = 'user_domains.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_domains').submit(function(event) { event.preventDefault(); applyFilter(); }); }); </script> </td> </tr> <?php html_end_box(); /* print checkbox form for validation */ print "<form name='chk' method='post' action='user_domains.php'>\n"; html_start_box('', '100%', '', '3', 'center', ''); /* form the 'where' clause for our main sql query */ if ($_REQUEST['filter'] != '') { $sql_where = "WHERE (domain_name LIKE '%%" . get_request_var_request('filter') . "%%') ||\n\t\t\t(type LIKE '%%" . get_request_var_request('filter') . "%%')"; } else { $sql_where = ''; } $total_rows = db_fetch_cell("SELECT\n\t\tcount(*)\n\t\tFROM user_domains\n\t\t{$sql_where}"); $domains = db_fetch_assoc("SELECT *\n\t\tFROM user_domains\n\t\t{$sql_where}\n\t\tORDER BY " . get_request_var_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('user_user_domains.php?filter=' . get_request_var_request('filter'), MAX_DISPLAY_PAGES, get_request_var_request('page'), get_request_var_request('rows'), $total_rows, 6, 'User Domains', 'page', 'main'); print $nav; $display_text = array('domain_name' => array('Domain Name', 'ASC'), 'type' => array('Domain Type', 'ASC'), 'defdomain' => array('Default', 'ASC'), 'user_id' => array('Effective User', 'ASC'), 'enabled' => array('Enabled', 'ASC')); html_header_sort_checkbox($display_text, get_request_var_request('sort_column'), get_request_var_request('sort_direction'), false); $i = 0; if (sizeof($domains) > 0) { foreach ($domains as $domain) { /* hide system types */ form_alternate_row('line' . $domain['domain_id'], true); form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars('user_domains.php?action=edit&domain_id=' . $domain['domain_id']) . "'>" . (strlen(get_request_var_request('filter')) ? eregi_replace('(' . preg_quote(get_request_var_request('filter')) . ')', "<span class='filteredValue>\\1</span>", $domain['domain_name']) : $domain['domain_name']) . '</a>', $domain['domain_id']); form_selectable_cell($domain_types[$domain['type']], $domain['domain_id']); form_selectable_cell($domain['defdomain'] == '0' ? '--' : 'Yes', $domain['domain_id']); form_selectable_cell($domain['user_id'] == '0' ? 'None Selected' : db_fetch_cell_prepared('SELECT username FROM user_auth WHERE id = ?', array($domain['user_id'])), $domain['domain_id']); form_selectable_cell($domain['enabled'] == 'on' ? 'Yes' : 'No', $domain['domain_id']); form_checkbox_cell($domain['domain_name'], $domain['domain_id']); form_end_row(); } print $nav; } else { print '<tr><td><em>No User Domains Defined</em></td></tr>'; } html_end_box(false); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($actions); print "</form>\n"; }
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'] . '/html_utility.php'; if (empty($tree_id)) { return; } if (empty($leaf_id)) { $leaf_id = 0; } $sql_where = ''; $sql_join = ''; $title = ''; $title_delimeter = ''; $leaf = db_fetch_row("SELECT title, host_id, host_grouping_type\n\t\tFROM graph_tree_items\n\t\tWHERE id={$leaf_id}"); $leaf_type = api_tree_get_item_type($leaf_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); $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>Device:</strong>' . htmlspecialchars($host_name); $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%', "", '3', 'center', ''); /* include time span selector */ if (read_graph_config_option('timespan_sel') == 'on') { ?> <tr class='even noprint'> <td class='noprint'> <form name='form_timespan_selector' method='post' action='graph_view.php'> <table cellpadding='2' cellspacing='0'> <tr id='timespan'> <td width='50'> 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='middle' 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='middle' 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='middle' 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='middle' 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> <tr id='realtime' style='display:none;'> <td width='50'> Window </td> <td> <select name='graph_start' id='graph_start' onChange='self.imageOptionsChanged("timespan")'> <?php foreach ($realtime_window as $interval => $text) { printf('<option value="%d"%s>%s</option>', $interval, $interval == $_SESSION['sess_realtime_window'] ? ' selected="selected"' : '', $text); } ?> </select> </td> <td> Refresh </td> <td> <select name='ds_step' id='ds_step' onChange="self.imageOptionsChanged('interval')"> <?php foreach ($realtime_refresh as $interval => $text) { printf('<option value="%d"%s>%s</option>', $interval, $interval == $_SESSION['sess_realtime_dsstep'] ? ' selected="selected"' : '', $text); } ?> </select> </td> <td> <input type='button' id='realtimeoff' value='Stop'> </td> <td align='center' colspan='6'> <span id='countdown'></span> </td> </tr> </table> </form> </td> </tr> <?php } ?> <tr class='even noprint' id='search'> <td class='noprint'> <form name='form_graph_view' method='post' onSubmit='changeFilter();return false'> <table cellpadding='2' cellspacing='0'> <tr> <td width='50'> Search </td> <td> <input id='filter' size='30' name='filter' value='<?php print htmlspecialchars(get_request_var_request('filter')); ?> '> </td> <td> Graphs </td> <td> <select name='graphs' id='graphs' onChange='changeFilter()'> <?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> <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' : ''; ?> >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> <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() { var navBar = "<div id='navBar' class='navBar'><?php print draw_navigation_text(); ?> </div>"; if (navBar != '') { $('#navBar').replaceWith(navBar); } setupBreadcrumbs(); }); function changeFilter() { $.get('graph_view.php?action=tree_content&tree_id=<?php print $_SESSION['sess_graph_tree_tree_id']; ?> &leaf_id=<?php print $_SESSION['sess_graph_tree_leaf_id']; ?> &host_group_data=<?php print $_SESSION['sess_graph_tree_host_group_data']; ?> &graphs='+$('#graphs').val()+'&filter='+$('#filter').val()+'&thumbnails='+$('#thumbnails').is(':checked')+'&columns='+$('#columns').val()+'&nodeid='+'<?php print $_SESSION['sess_graph_tree_nodeid']; ?> ', function(data) { $('#main').html(data); applySkin(); }); } function clearFilter() { $.get('graph_view.php?action=tree_content&tree_id=<?php print $_SESSION['sess_graph_tree_tree_id']; ?> &leaf_id=<?php print $_SESSION['sess_graph_tree_leaf_id']; ?> &host_group_data=<?php print $_SESSION['sess_graph_tree_host_group_data']; ?> &clear_x=1&nodeid='+'<?php print $_SESSION['sess_graph_tree_nodeid']; ?> ', function(data) { $('#main').html(data); applySkin(); }); } function spanTime() { $.get('graph_view.php?action=tree_content&tree_id=<?php print $_SESSION['sess_graph_tree_tree_id']; ?> &leaf_id=<?php print $_SESSION['sess_graph_tree_leaf_id']; ?> &host_group_data=<?php print $_SESSION['sess_graph_tree_host_group_data']; ?> &nodeid='+'<?php print $_SESSION['sess_graph_tree_nodeid']; ?> &predefined_timespan='+$('#predefined_timespan').val()+'&predefined_timeshift='+$('#predefined_timeshift').val(), function(data) { $('#main').html(data); applySkin(); }); } 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 $_SESSION['sess_graph_tree_tree_id']; ?> &leaf_id=<?php print $_SESSION['sess_graph_tree_leaf_id']; ?> &host_group_data=<?php print $_SESSION['sess_graph_tree_host_group_data']; ?> &nodeid=<?php print $_SESSION['sess_graph_tree_nodeid']; ?> '; $.post(url, json).done(function(data) { $('#main').html(data); applySkin(); }); } 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 $_SESSION['sess_graph_tree_tree_id']; ?> &leaf_id=<?php print $_SESSION['sess_graph_tree_leaf_id']; ?> &host_group_data=<?php print $_SESSION['sess_graph_tree_host_group_data']; ?> &nodeid=<?php print $_SESSION['sess_graph_tree_nodeid']; ?> '; $.post(url, json).done(function(data) { $('#main').html(data); applySkin(); }); } 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 $_SESSION['sess_graph_tree_tree_id']; ?> &leaf_id=<?php print $_SESSION['sess_graph_tree_leaf_id']; ?> &host_group_data=<?php print $_SESSION['sess_graph_tree_host_group_data']; ?> &nodeid=<?php print $_SESSION['sess_graph_tree_nodeid']; ?> '; $.post(url, json).done(function(data) { $('#main').html(data); applySkin(); }); } 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 $_SESSION['sess_graph_tree_tree_id']; ?> &leaf_id=<?php print $_SESSION['sess_graph_tree_leaf_id']; ?> &host_group_data=<?php print $_SESSION['sess_graph_tree_host_group_data']; ?> &nodeid=<?php print $_SESSION['sess_graph_tree_nodeid']; ?> '; $.post(url, json).done(function(data) { $('#main').html(data); applySkin(); }); } function url_graph(strNavURL) { return ''; } </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)) { $sql_where = ''; if (strlen(get_request_var_request('filter'))) { $sql_where = " (gtg.title_cache LIKE '%" . get_request_var_request('filter') . "%' OR gtg.title LIKE '%" . get_request_var_request('filter') . "%')"; } $graph_list = get_allowed_tree_header_graphs($tree_id, $leaf_id, $sql_where); } elseif ($leaf_type == 'host') { /* graph template grouping */ if ($leaf['host_grouping_type'] == HOST_GROUPING_GRAPH_TEMPLATE) { $sql_where = 'gl.host_id=' . $leaf['host_id'] . (empty($graph_template_id) ? '' : ' AND gt.id=' . $graph_template_id); $graph_templates = get_allowed_graph_templates($sql_where); /* 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) { $sql_where = ''; if (strlen(get_request_var_request('filter'))) { $sql_where = " (gtg.title_cache LIKE '%" . get_request_var_request('filter') . "%')"; } $sql_where .= (strlen($sql_where) ? 'AND' : '') . ' gl.graph_template_id=' . $graph_template['id'] . ' AND gl.host_id=' . $leaf['host_id']; $graphs = get_allowed_graphs($sql_where); /* 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 sq.id, sq.name\n\t\t\t\tFROM graph_local AS gl\n\t\t\t\tINNER JOIN snmp_query AS sq\n\t\t\t\tON gl.snmp_query_id=sq.id\n\t\t\t\tWHERE gl.host_id=" . $leaf['host_id'] . "\n\t\t\t\t" . (!isset($data_query_id) ? '' : "AND sq.id={$data_query_id}") . "\n\t\t\t\tGROUP BY sq.id\n\t\t\t\tORDER BY sq.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) { $sql_where = ''; /* 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 = " (gtg.title_cache LIKE '%" . get_request_var_request('filter') . "%')"; } /* grab a list of all graphs for this host/data query combination */ $sql_where .= (strlen($sql_where) ? ' AND ' : '') . ' gl.snmp_query_id=' . $data_query['id'] . ' AND gl.host_id=' . $leaf['host_id'] . "\n " . (empty($data_query_index) ? '' : " AND gl.snmp_index='{$data_query_index}'"); $graphs = get_allowed_graphs($sql_where); /* 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 */ $nav = html_nav_bar("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'), MAX_DISPLAY_PAGES, get_request_var_request('page'), get_request_var_request('graphs'), $total_rows, 5, 'Graphs', 'page', 'main'); print $nav; /* start graph display */ print "<tr class='tableHeader'><td width='390' colspan='11' class='graphSubHeaderColumn 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'); if ($total_rows > 0) { print $nav; } html_end_box(); }
function thold_show_log() { global $config, $item_rows, $thold_log_states, $thold_status, $thold_types, $thold_log_retention; $step = read_config_option('poller_interval'); /* ================= input validation and session storage ================= */ $filters = array('rows' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'page' => array('filter' => FILTER_VALIDATE_INT, 'default' => '1'), 'filter' => array('filter' => FILTER_CALLBACK, 'pageset' => true, 'default' => '', 'options' => array('options' => 'sanitize_search_string')), 'sort_column' => array('filter' => FILTER_CALLBACK, 'default' => 'time', 'options' => array('options' => 'sanitize_search_string')), 'sort_direction' => array('filter' => FILTER_CALLBACK, 'default' => 'DESC', 'options' => array('options' => 'sanitize_search_string')), 'threshold_id' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'host_id' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'status' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1')); validate_store_request_vars($filters, 'sess_thold_log'); /* ================= input validation ================= */ /* if the number of rows is -1, set it to the default */ if (get_request_var('rows') == -1) { $rows = read_config_option('num_rows_table'); } else { $rows = get_request_var('rows'); } $days = read_config_option('thold_log_storage'); if (isset($thold_log_retention[$days])) { $days = $thold_log_retention[$days]; } else { $days = __('%d Days', $days); } html_start_box(__('Threshold Log for [ %s ]', $days), '100%', '', '3', 'center', ''); form_thold_log_filter(); html_end_box(); $sql_where = ''; if (get_request_var('host_id') == '-1') { /* Show all items */ } elseif (get_request_var('host_id') == '0') { $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' h.id IS NULL'; } elseif (!isempty_request_var('host_id')) { $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' tl.host_id=' . get_request_var('host_id'); } if (get_request_var('threshold_id') == '-1') { /* Show all items */ } elseif (get_request_var('threshold_id') == '0') { $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' td.id IS NULL'; } elseif (!isempty_request_var('threshold_id')) { $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' tl.threshold_id=' . get_request_var('threshold_id'); } if (get_request_var('status') == '-1') { /* Show all items */ } else { $sql_where .= (strlen($sql_where) ? ' AND' : '') . ' tl.status=' . get_request_var('status'); } if (strlen(get_request_var('filter'))) { $sql_where .= (strlen($sql_where) ? ' AND' : '') . " tl.description LIKE '%" . get_request_var('filter') . "%'"; } $sortby = get_request_var('sort_column') . ' ' . get_request_var('sort_direction'); $limit = $rows * (get_request_var('page') - 1) . ',' . $rows; $logs = get_allowed_threshold_logs($sql_where, $sortby, $limit, $total_rows); $nav = html_nav_bar('thold_graph.php?action=log', MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 8, __('Log Entries'), 'page', 'main'); print $nav; html_start_box('', '100%', '', '3', 'center', ''); $display_text = array('hdescription' => array('display' => __('Device'), 'sort' => 'ASC', 'align' => 'left'), 'time' => array('display' => __('Time'), 'sort' => 'ASC', 'align' => 'left'), 'type' => array('display' => __('Type'), 'sort' => 'DESC', 'align' => 'left'), 'description' => array('display' => __('Event Description'), 'sort' => 'ASC', 'align' => 'left'), 'threshold_value' => array('display' => __('Alert Value'), 'sort' => 'ASC', 'align' => 'right'), 'current' => array('display' => __('Measured Value'), 'sort' => 'ASC', 'align' => 'right')); html_header_sort($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false, 'thold_graph.php?action=log'); $i = 0; if (sizeof($logs)) { foreach ($logs as $l) { ?> <tr class='<?php print $thold_log_states[$l['status']]['class']; ?> '> <td class='left nowrap'><?php print $l['hdescription']; ?> </td> <td class='left nowrap'><?php print date('Y-m-d H:i:s', $l['time']); ?> </td> <td class='left nowrap'><?php print $thold_types[$l['type']]; ?> </td> <td class='left nowrap'><?php print strlen($l['description']) ? $l['description'] : __('Restoral Event'); ?> </td> <td class='right'><?php print $l['threshold_value'] != '' ? thold_format_number($l['threshold_value']) : __('N/A'); ?> </td> <td class='right'><?php print $l['current'] != '' ? thold_format_number($l['current']) : __('N/A'); ?> </td> <?php form_end_row(); } } else { print '<tr><td class="center" colspan="8">' . __('No Threshold Logs Found') . '</td></tr>'; } html_end_box(false); if (sizeof($logs)) { print $nav; } log_legend(); }
function lists() { global $actions, $item_rows; /* ================= input validation and session storage ================= */ $filters = array('rows' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'page' => array('filter' => FILTER_VALIDATE_INT, 'default' => '1'), 'filter' => array('filter' => FILTER_CALLBACK, 'pageset' => true, 'default' => '', 'options' => array('options' => 'sanitize_search_string')), 'sort_column' => array('filter' => FILTER_CALLBACK, 'default' => 'description', 'options' => array('options' => 'sanitize_search_string')), 'sort_direction' => array('filter' => FILTER_CALLBACK, 'default' => 'ASC', 'options' => array('options' => 'sanitize_search_string'))); validate_store_request_vars($filters, 'sess_lists'); /* ================= input validation ================= */ /* if the number of rows is -1, set it to the default */ if (get_request_var('rows') == -1) { $rows = read_config_option('num_rows_table'); } else { $rows = get_request_var('rows'); } html_start_box(__('Notification Lists'), '100%', '', '3', 'center', 'notify_lists.php?action=edit'); ?> <tr class='even'> <td> <form id='lists' action='notify_lists.php'> <table class='filterTable'> <tr> <td> <?php print __('Search'); ?> </td> <td> <input type='text' id='filter' size='25' value='<?php print htmlspecialchars(get_request_var('filter')); ?> '> </td> <td> <?php print __('Lists'); ?> </td> <td> <select id='rows' onChange='applyFilter()'> <option value='-1'<?php if (get_request_var('rows') == '-1') { ?> selected<?php } ?> ><?php print __('Default'); ?> </option> <?php if (sizeof($item_rows) > 0) { foreach ($item_rows as $key => $value) { print "<option value='" . $key . "'"; if (get_request_var('rows') == $key) { print ' selected'; } print '>' . htmlspecialchars($value) . "</option>\n"; } } ?> </select> </td> <td> <input type='button' value='<?php print __('Go'); ?> ' title='<?php print __('Set/Refresh Filters'); ?> ' onClick='applyFilter()'> </td> <td> <input type='button' name='clear' value='<?php print __('Clear'); ?> ' title='<?php print __('Clear Filters'); ?> ' onClick='clearFilter()'> </td> </tr> </table> <input type='hidden' id='page' value='<?php print get_filter_request_var('page'); ?> '> </form> <script type='text/javascript'> function applyFilter() { strURL = 'notify_lists.php?header=false'; strURL += '&rows=' + $('#rows').val(); strURL += '&filter=' + $('#filter').val(); loadPageNoHeader(strURL); } function clearFilter() { strURL = 'notify_lists.php?header=false&clear=1'; loadPageNoHeader(strURL); } $(function() { $('#lists').submit(function(event) { event.preventDefault(); applyFilter(); }); }); </script> </td> </tr> <?php html_end_box(); /* form the 'where' clause for our main sql query */ if (strlen(get_request_var('filter'))) { $sql_where = "WHERE (name LIKE '%" . get_request_var('filter') . "%' OR\n\t\tdescription LIKE '%" . get_request_var('filter') . "%' OR\n\t\temails LIKE '%" . get_request_var('filter') . "%')"; } else { $sql_where = ''; } $total_rows = db_fetch_cell("SELECT\n\t\tCOUNT(*)\n\t\tFROM plugin_notification_lists\n\t\t{$sql_where}"); $lists = db_fetch_assoc("SELECT id, name, description, emails\n\t\tFROM plugin_notification_lists\n\t\t{$sql_where}\n\t\tORDER BY " . get_request_var('sort_column') . ' ' . get_request_var('sort_direction') . ' LIMIT ' . $rows * (get_request_var('page') - 1) . ',' . $rows); $nav = html_nav_bar('notify_lists.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 10, __('Lists'), 'page', 'main'); form_start('notify_lists.php', 'chk'); print $nav; html_start_box('', '100%', '', '3', 'center', ''); $display_text = array('name' => array(__('List Name'), 'ASC'), 'description' => array(__('Description'), 'ASC'), 'emails' => array(__('Emails'), 'ASC')); html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false); if (sizeof($lists)) { foreach ($lists as $item) { form_alternate_row('line' . $item['id'], true); form_selectable_cell(filter_value($item['name'], get_request_var('filter'), 'notify_lists.php?action=edit&id=' . $item['id']), $item['id'], '25%'); form_selectable_cell(filter_value($item['description'], get_request_var('filter')), $item['id'], '35%'); form_selectable_cell(filter_value($item['emails'], get_request_var('filter')), $item['id']); form_checkbox_cell($item['name'], $item['id']); form_end_row(); } } else { print '<tr><td><em>' . __('No Notification Lists') . '</em></td></tr>'; } html_end_box(false); if (sizeof($lists)) { print $nav; } form_hidden_box('save_list', '1', ''); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($actions); form_end(); }
function mikrotik_user() { global $user_actions, $item_rows; /* ================= input validation and session storage ================= */ $filters = array('rows' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'type' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'page' => array('filter' => FILTER_VALIDATE_INT, 'default' => '1'), 'status' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'filter' => array('filter' => FILTER_CALLBACK, 'pageset' => true, 'default' => '', 'options' => array('options' => 'sanitize_search_string')), 'sort_column' => array('filter' => FILTER_CALLBACK, 'default' => 'name', 'options' => array('options' => 'sanitize_search_string')), 'sort_direction' => array('filter' => FILTER_CALLBACK, 'default' => 'ASC', 'options' => array('options' => 'sanitize_search_string'))); validate_store_request_vars($filters, 'sess_mtue'); /* ================= input validation and session storage ================= */ /* if the number of rows is -1, set it to the default */ if (get_request_var('rows') != '-1') { $rows = get_request_var('rows'); } else { $rows = read_config_option('num_rows_table'); } ?> <script type='text/javascript'> function applyFilter(objForm) { strURL = 'mikrotik_users.php?filter=' + $('#filter').val(); strURL += '&status=' + $('#status').val(); strURL += '&type=' + $('#type').val(); strURL += '&rows=' + $('#rows').val(); strURL += '&header=false'; loadPageNoHeader(strURL); } function clearFilter() { strURL = 'mikrotik_users.php?clear=1'; strURL += '&header=false'; loadPageNoHeader(strURL); } $(function() { $('#users').submit(function(event) { event.preventDefault(); applyFilter(); }); }); </script> <?php html_start_box(__('MikroTik Users'), '100%', '', '3', 'center', ''); ?> <tr class='even'> <td> <form id='users' action='mikrotik_users.php'> <table class='filterTable'> <tr> <td> <?php print __('Search'); ?> </td> <td> <input type='text' id='filter' size='25' value='<?php print htmlspecialchars(get_request_var('filter')); ?> '> </td> <td> <?php print __('Type'); ?> </td> <td> <select id='type' onChange='applyFilter()'> <option value='-1'<?php if (get_request_var('type') == '-1') { ?> selected<?php } ?> ><?php print __('All'); ?> </option> <option value='0'<?php if (get_request_var('type') == '0') { ?> selected<?php } ?> ><?php print __('Hotspot'); ?> </option> <option value='1'<?php if (get_request_var('type') == '1') { ?> selected<?php } ?> ><?php print __('PPPoe'); ?> </option> </select> </td> <td> <?php print __('Users'); ?> </td> <td> <select id='rows' onChange='applyFilter()'> <option value='-1'<?php if (get_request_var('rows') == '-1') { ?> selected<?php } ?> ><?php print __('Default'); ?> </option> <?php if (sizeof($item_rows) > 0) { foreach ($item_rows as $key => $value) { print "<option value='" . $key . "'"; if (get_request_var('rows') == $key) { print ' selected'; } print '>' . htmlspecialchars($value) . "</option>\n"; } } ?> </select> </td> <td> <?php print __('Status'); ?> </td> <td> <select id='status' onChange='applyFilter()'> <option value='-1'<?php if (get_request_var('status') == '-1') { ?> selected<?php } ?> ><?php print __('All'); ?> </option> <option value='1'<?php if (get_request_var('status') == '1') { ?> selected<?php } ?> ><?php print __('Active'); ?> </option> <option value='2'<?php if (get_request_var('status') == '2') { ?> selected<?php } ?> ><?php print __('Inactive'); ?> </option> </select> <td> <input type='button' value='<?php print __('Go'); ?> ' title='<?php print __('Set/Refresh Filters'); ?> ' onClick='applyFilter()'> </td> <td> <input type='button' name='clear_x' value='<?php print __('Clear'); ?> ' title='<?php print __('Clear Filters'); ?> ' onClick='clearFilter()'> </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('filter'))) { $sql_where = "WHERE (name LIKE '%%" . get_request_var('filter') . "%%') AND name!=''"; } else { $sql_where = "WHERE name!=''"; } if (get_request_var('status') == 1) { $sql_where .= ' AND present=1'; } elseif (get_request_var('status') == 2) { $sql_where .= ' AND present=0'; } if (get_request_var('type') == '0') { $sql_where .= (strlen($sql_where) ? ' AND' : 'WHERE') . ' userType=0'; } elseif (get_request_var('type') == '1') { $sql_where .= (strlen($sql_where) ? ' AND' : 'WHERE') . ' userType=1'; } $total_rows = db_fetch_cell("SELECT \n\t\tCOUNT(DISTINCT name)\n\t\tFROM plugin_mikrotik_users\n\t\t{$sql_where}"); $sortby = get_request_var('sort_column'); $sql_query = "SELECT name, domain, userType, MAX(last_seen) AS last_seen, MAX(present) AS present\n\t\tFROM plugin_mikrotik_users\n\t\t{$sql_where}\n\t\tGROUP BY name, domain\n\t\tORDER BY " . $sortby . ' ' . get_request_var('sort_direction') . ' LIMIT ' . $rows * (get_request_var('page') - 1) . ',' . $rows; $users = db_fetch_assoc($sql_query); $nav = html_nav_bar('mikrotik_users.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 6, __('Users'), 'page', 'main'); form_start('mikrotik_users.php', 'chk'); print $nav; html_start_box('', '100%', '', '3', 'center', ''); $display_text = array('name' => array(__('User Name'), 'ASC'), 'domain' => array(__('Domain'), 'ASC'), 'type' => array(__('Type'), 'ASC'), 'last_seen' => array(__('Last Seen'), 'DESC'), 'present' => array(__('Active'), 'ASC')); html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false); if (sizeof($users)) { foreach ($users as $user) { form_alternate_row('line' . $user['name'], true); form_selectable_cell("<span class='noLinkEditMain'>" . filter_value($user['name'], get_request_var('filter')) . '</span>', $user['name'], 250); form_selectable_cell($user['domain'] != '' ? $user['domain'] : 'Not Set', $user['name']); form_selectable_cell($user['userType'] == '0' ? 'Hotspot' : 'PPPoe', $user['name']); form_selectable_cell($user['last_seen'], $user['name']); form_selectable_cell($user['present'] == 0 ? '<b><i>' . __('Inactive') . '</i></b>' : '<b><i>' . __('Active') . '</i></b>', $user['name']); form_checkbox_cell($user['name'], $user['name']); form_end_row(); } } else { print '<tr><td><em>' . __('No Users Found') . '</em></td></tr>'; } html_end_box(false); if (sizeof($users)) { print $nav; } /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($user_actions); form_end(); }
function list_tholds() { global $thold_states, $config, $host_id, $timearray, $thold_types; $thold_actions = array(1 => __('Delete'), 2 => __('Disable'), 3 => __('Enable'), 4 => __('Reapply Suggested Names'), 5 => __('Propagate Template')); thold_request_validation(); /* if the number of rows is -1, set it to the default */ if (get_request_var('rows') == -1) { $rows = read_config_option('num_rows_table'); } else { $rows = get_request_var('rows'); } $statefilter = ''; if (isset_request_var('state')) { if (get_request_var('state') == '-1') { $statefilter = ''; } else { if (get_request_var('state') == '0') { $statefilter = "thold_data.thold_enabled='off'"; } if (get_request_var('state') == '2') { $statefilter = "thold_data.thold_enabled='on'"; } if (get_request_var('state') == '1') { $statefilter = '(thold_data.thold_alert!=0 OR thold_data.bl_alert>0)'; } if (get_request_var('state') == '3') { $statefilter = '((thold_data.thold_alert!=0 AND thold_data.thold_fail_count >= thold_data.thold_fail_trigger) OR (thold_data.bl_alert>0 AND thold_data.bl_fail_count >= thold_data.bl_fail_trigger))'; } } } top_header(); $sql_where = ''; $sort = get_request_var('sort_column'); $limit = ' LIMIT ' . $rows * (get_request_var('page') - 1) . ", {$rows}"; if (!isempty_request_var('host_id') && get_request_var('host_id') != '-1') { $sql_where .= (!strlen($sql_where) ? '(' : ' AND ') . "td.host_id = " . get_request_var('host_id'); } if (!isempty_request_var('data_template_id') && get_request_var('data_template_id') != '-1') { $sql_where .= (!strlen($sql_where) ? '(' : ' AND ') . "td.data_template_id = " . get_request_var('data_template_id'); } if ($statefilter != '') { $sql_where .= (!strlen($sql_where) ? '(' : ' AND ') . "{$statefilter}"; } if ($sql_where != '') { $sql_where .= ')'; } $tholds = get_allowed_thresholds($sql_where, $sort . ' ' . get_request_var('sort_direction'), $rows * (get_request_var('page') - 1) . ", {$rows}", $total_rows); $data_templates = db_fetch_assoc("SELECT DISTINCT data_template.id, data_template.name\n\t\tFROM data_template\n\t\tINNER JOIN thold_data \n\t\tON thold_data.data_template_id = data_template.id\n\t\tORDER BY data_template.name"); html_start_box(__('Threshold Management'), '100%', '', '3', 'center', 'thold.php?action=add'); ?> <tr class='even'> <td> <form id='listthold' action='thold.php' method='post'> <table class='filterTable'> <tr> <td> <?php print __('Search'); ?> </td> <td> <input type='text' id='filter' size='25' value='<?php print get_request_var('filter'); ?> '> </td> <?php print html_host_filter(get_request_var('host_id')); ?> <td> <?php print __('Template'); ?> </td> <td> <select id='data_template_id' onChange='applyFilter()'> <option value='-1'><?php print __('Any'); ?> </option> <?php foreach ($data_templates as $row) { echo "<option value='" . $row['id'] . "'" . (isset_request_var('data_template_id') && $row['id'] == get_request_var('data_template_id') ? ' selected' : '') . '>' . $row['name'] . '</option>'; } ?> </select> </td> <td> <?php print __('State'); ?> </td> <td> <select id='state' onChange='applyFilter()'> <option value='-1'<?php if (get_request_var('state') == '-1') { ?> selected<?php } ?> ><?php print __('All'); ?> </option> <option value='1'<?php if (get_request_var('state') == '1') { ?> selected<?php } ?> ><?php print __('Breached'); ?> </option> <option value='3'<?php if (get_request_var('state') == '3') { ?> selected<?php } ?> ><?php print __('Triggered'); ?> </option> <option value='2'<?php if (get_request_var('state') == '2') { ?> selected<?php } ?> ><?php print __('Enabled'); ?> </option> <option value='0'<?php if (get_request_var('state') == '0') { ?> selected<?php } ?> ><?php print __('Disabled'); ?> </option> </select> </td> <td> <input type='button' id='refresh' value='<?php print __('Go'); ?> ' title='<?php print __('Apply Filters'); ?> ' onClick='applyFilter()'> </td> <td> <input type='button' id='clear' value='<?php print __('Clear'); ?> ' title='<?php print __('Return to Defaults'); ?> ' onClick='clearFilter()'> </td> </tr> </table> <input type='hidden' name='search' value='search'> <input type='hidden' id='page' value='<?php print get_filter_request_var('page'); ?> '> </form> <script type='text/javascript'> function applyFilter() { strURL = 'thold.php?header=false&host_id=' + $('#host_id').val(); strURL += '&state=' + $('#state').val(); strURL += '&data_template_id=' + $('#data_template_id').val(); strURL += '&filter=' + $('#filter').val(); loadPageNoHeader(strURL); } function clearFilter() { strURL = 'thold.php?header=false&clear=1'; loadPageNoHeader(strURL); } $(function() { $('#listthold').submit(function(event) { event.preventDefault(); applyFilter(); }); }); </script> </td> </tr> <?php html_end_box(); $nav = html_nav_bar('thold.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 14, __('Thresholds'), 'page', 'main'); form_start('thold.php', 'chk'); print $nav; html_start_box('', '100%', '', '4', 'center', ''); $display_text = array('name' => array('display' => __('Name'), 'sort' => 'ASC', 'align' => 'left'), 'id' => array('display' => __('ID'), 'sort' => 'ASC', 'align' => 'right'), 'thold_type' => array('display' => __('Type'), 'sort' => 'ASC', 'align' => 'right'), 'data_source' => array('display' => __('DSName'), 'sort' => 'ASC', 'align' => 'right'), 'lastread' => array('display' => __('Current'), 'sort' => 'ASC', 'align' => 'right', 'tip' => __('The last measured value for the Data Source')), 'thold_hi' => array('display' => __('High'), 'sort' => 'ASC', 'align' => 'right', 'tip' => __('High Threshold values for Warning/Alert')), 'thold_low' => array('display' => __('Low'), 'sort' => 'ASC', 'align' => 'right', 'tip' => __('Low Threshold values for Warning/Alert')), 'nosort3' => array('display' => __('Trigger'), 'sort' => '', 'align' => 'right'), 'nosort4' => array('display' => __('Duration'), 'sort' => '', 'align' => 'right'), 'repeat_alert' => array('display' => __('Repeat'), 'sort' => 'ASC', 'align' => 'right'), 'thold_alert' => array('display' => __('Triggered'), 'sort' => 'ASC', 'align' => 'right'), 'template_enabled' => array('display' => __('Templated'), 'sort' => 'ASC', 'align' => 'right')); html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false); $c = 0; $i = 0; if (sizeof($tholds)) { foreach ($tholds as $thold_data) { $c++; $grapharr = db_fetch_row('SELECT DISTINCT graph_templates_item.local_graph_id FROM graph_templates_item, data_template_rrd WHERE (data_template_rrd.local_data_id=' . $thold_data['local_data_id'] . ' AND data_template_rrd.id=graph_templates_item.task_item_id)'); $local_graph_id = $grapharr['local_graph_id']; $alertstat = __('No'); $bgcolor = 'green'; if ($thold_data['thold_type'] == 0) { if ($thold_data['thold_alert'] != 0) { $alertstat = __('Yes'); if ($thold_data['thold_fail_count'] >= $thold_data['thold_fail_trigger']) { $bgcolor = 'red'; } elseif ($thold_data['thold_warning_fail_count'] >= $thold_data['thold_warning_fail_trigger']) { $bgcolor = 'warning'; } else { $bgcolor = 'yellow'; } } } elseif ($thold_data['thold_type'] == 2) { if ($thold_data['thold_alert'] != 0) { $alertstat = __('Yes'); if ($thold_data['thold_fail_count'] >= $thold_data['time_fail_trigger']) { $bgcolor = 'red'; } elseif ($thold_data['thold_warning_fail_count'] >= $thold_data['time_warning_fail_trigger']) { $bgcolor = 'warning'; } else { $bgcolor = 'yellow'; } } } else { if ($thold_data['bl_alert'] == 1) { $alertstat = __('baseline-LOW'); $bgcolor = $thold_data['bl_fail_count'] >= $thold_data['bl_fail_trigger'] ? 'orange' : 'yellow'; } elseif ($thold_data['bl_alert'] == 2) { $alertstat = __('baseline-HIGH'); $bgcolor = $thold_data['bl_fail_count'] >= $thold_data['bl_fail_trigger'] ? 'orange' : 'yellow'; } } $data_source = db_fetch_cell_prepared('SELECT data_source_name FROM data_template_rrd WHERE id = ?', array($thold_data['data_template_rrd_id'])); if ($thold_data['thold_enabled'] == 'off') { print "<tr class='selectable " . $thold_states['grey']['class'] . "' id='line" . $thold_data['id'] . "'>\n"; } else { print "<tr class='selectable " . $thold_states[$bgcolor]['class'] . "' id='line" . $thold_data['id'] . "'>\n"; } form_selectable_cell(filter_value($thold_data['name'] != '' ? $thold_data['name'] : $thold_data['name_cache'] . ' [' . $thold_data['data_source_name'] . ']', get_request_var('filter'), 'thold.php?action=edit&id=' . $thold_data['id']) . '</a>', $thold_data['id'], '', 'text-align:left'); form_selectable_cell($thold_data['id'], $thold_data['id'], '', 'text-align:right'); form_selectable_cell($thold_types[$thold_data['thold_type']], $thold_data['id'], '', 'text-align:right'); form_selectable_cell($data_source, $thold_data['id'], '', 'text-align:right'); switch ($thold_data['thold_type']) { case 0: form_selectable_cell(thold_format_number($thold_data['lastread']), $thold_data['id'], '', 'text-align:right'); form_selectable_cell(thold_format_number($thold_data['thold_warning_hi']) . ' / ' . thold_format_number($thold_data['thold_hi']), $thold_data['id'], '', 'text-align:right'); form_selectable_cell(thold_format_number($thold_data['thold_warning_low']) . ' / ' . thold_format_number($thold_data['thold_low']), $thold_data['id'], '', 'text-align:right'); form_selectable_cell('<i>' . plugin_thold_duration_convert($thold_data['local_data_id'], $thold_data['thold_fail_trigger'], 'alert') . '</i>', $thold_data['id'], '', 'text-align:right'); form_selectable_cell(__('N/A'), $thold_data['id'], '', 'text-align:right'); break; case 1: form_selectable_cell(thold_format_number($thold_data['lastread']), $thold_data['id'], '', 'text-align:right'); form_selectable_cell(thold_format_number($thold_data['thold_warning_hi']) . ' / ' . thold_format_number($thold_data['thold_hi']), $thold_data['id'], '', 'text-align:right'); form_selectable_cell(thold_format_number($thold_data['thold_warning_low']) . ' / ' . thold_format_number($thold_data['thold_low']), $thold_data['id'], '', 'text-align:right'); form_selectable_cell('<i>' . plugin_thold_duration_convert($thold_data['local_data_id'], $thold_data['bl_fail_trigger'], 'alert') . '</i>', $thold_data['id'], '', 'text-align:right'); form_selectable_cell($timearray[$thold_data['bl_ref_time_range'] / 300], $thold_data['id'], '', 'text-align:right'); break; case 2: form_selectable_cell(thold_format_number($thold_data['lastread']), $thold_data['id'], '', 'text-align:right'); form_selectable_cell(thold_format_number($thold_data['time_warning_hi']) . ' / ' . thold_format_number($thold_data['time_hi']), $thold_data['id'], '', 'text-align:right'); form_selectable_cell(thold_format_number($thold_data['time_warning_low']) . ' / ' . thold_format_number($thold_data['time_low']), $thold_data['id'], '', 'text-align:right'); form_selectable_cell('<i>' . __('%d Triggers', $thold_data['time_fail_trigger']) . '</i>', $thold_data['id'], '', 'text-align:right'); form_selectable_cell('<i>' . plugin_thold_duration_convert($thold_data['local_data_id'], $thold_data['time_fail_length'], 'time') . '</i>', $thold_data['id'], '', 'text-align:right'); break; default: form_selectable_cell(thold_format_number($thold_data['lastread']), $thold_data['id'], '', 'text-align:right'); form_selectable_cell('- / -', $thold_data['id'], '', 'text-align:right'); form_selectable_cell('- / -', $thold_data['id'], '', 'text-align:right'); form_selectable_cell(__('N/A'), $thold_data['id'], '', 'text-align:right'); form_selectable_cell(__('N/A'), $thold_data['id'], '', 'text-align:right'); } form_selectable_cell($thold_data['repeat_alert'] == '' ? '' : plugin_thold_duration_convert($thold_data['local_data_id'], $thold_data['repeat_alert'], 'repeat'), $thold_data['id'], '', 'text-align:right'); form_selectable_cell($alertstat, $thold_data['id'], '', 'text-align:right'); if ($thold_data['thold_template_id'] != 0) { form_selectable_cell($thold_data['template_enabled'] == '' ? __('No') : __('Yes'), $thold_data['id'], '', 'text-align:right'); } else { form_selectable_cell(__('No'), $thold_data['id'], '', 'text-align:right'); } form_checkbox_cell($thold_data['name'], $thold_data['id'], '', 'text-align:left'); form_end_row(); } } else { print "<tr class='even'><td colspan='14'><center>" . __('No Thresholds') . "</center></td></tr>\n"; } html_end_box(false); if (sizeof($tholds)) { print $nav; } thold_legend(); draw_actions_dropdown($thold_actions); if (isset($host_id) && $host_id != '') { print "<input type='hidden' name='host_id' value='{$host_id}'>"; } form_end(); bottom_footer(); }
function data() { global $input_types, $di_actions, $item_rows; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request('page')); 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_data_input_filter'); kill_session_var('sess_default_rows'); kill_session_var('sess_data_input_sort_column'); kill_session_var('sess_data_input_sort_direction'); unset($_REQUEST['page']); unset($_REQUEST['filter']); unset($_REQUEST['rows']); unset($_REQUEST['sort_column']); unset($_REQUEST['sort_direction']); $_REQUEST['page'] = 1; } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value('filter', 'sess_data_input_filter', ''); load_current_session_value('sort_column', 'sess_data_input_sort_column', 'name'); load_current_session_value('sort_direction', 'sess_data_input_sort_direction', 'ASC'); load_current_session_value('page', 'sess_data_input_current_page', '1'); load_current_session_value('rows', 'sess_default_rows', read_config_option('num_rows_table')); html_start_box('<strong>Data Input Methods</strong>', '100%', '', '3', 'center', 'data_input.php?action=edit'); ?> <tr class='even noprint'> <td class="noprint"> <form id="form_data_input" method="get" action="data_input.php"> <table cellpadding="2" cellspacing="0"> <tr class="noprint"> <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 style='white-space:nowrap;'> Input Methods </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="submit" 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> <script type='text/javascript'> function applyFilter() { strURL = 'data_input.php?filter='+$('#filter').val()+'&rows='+$('#rows').val()+'&page='+$('#page').val()+'&header=false'; $.get(strURL, function(data) { $('#main').html(data); applySkin(); }); } function clearFilter() { strURL = 'data_input.php?clear_x=1&header=false'; $.get(strURL, function(data) { $('#main').html(data); applySkin(); }); } $(function() { $('#refresh').click(function() { applyFilter(); }); $('#clear').click(function() { clearFilter(); }); $('#form_data_input').submit(function(event) { event.preventDefault(); applyFilter(); }); }); </script> </td> </tr> <?php html_end_box(); /* print checkbox form for validation */ print "<form name='chk' method='post' action='data_input.php'>\n"; html_start_box('', '100%', '', '3', 'center', ''); /* form the 'where' clause for our main sql query */ if ($_REQUEST['filter'] != '') { $sql_where = "WHERE (di.name like '%" . get_request_var_request('filter') . "%')"; } else { $sql_where = ''; } $sql_where .= (strlen($sql_where) ? ' AND' : 'WHERE') . " (di.name!='Get Script Data (Indexed)'\n\t\tAND di.name!='Get Script Server Data (Indexed)'\n\t\tAND di.name!='Get SNMP Data'\n\t\tAND di.name!='Get SNMP Data (Indexed)')"; $total_rows = db_fetch_cell("SELECT\n\t\tcount(*)\n\t\tFROM data_input AS di\n\t\t{$sql_where}"); $data_inputs = db_fetch_assoc("SELECT di.*,\n\t\tSUM(CASE WHEN dtd.local_data_id=0 THEN 1 ELSE 0 END) AS templates,\n\t\tSUM(CASE WHEN dtd.local_data_id>0 THEN 1 ELSE 0 END) AS data_sources\n\t\tFROM data_input AS di\n\t\tLEFT JOIN data_template_data AS dtd\n\t\tON di.id=dtd.data_template_id\n\t\t{$sql_where}\n\t\tGROUP BY di.id\n\t\tORDER BY " . get_request_var_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('data_input.php?filter=' . get_request_var_request('filter'), MAX_DISPLAY_PAGES, get_request_var_request('page'), get_request_var_request('rows'), $total_rows, 6, 'Input Methods', 'page', 'main'); print $nav; $display_text = array('name' => array('display' => 'Data Input Name', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'The name of this Data Input Method.'), 'nosort' => array('display' => 'Deletable', 'align' => 'right', 'tip' => 'Data Inputs that are in use can not be Deleted. In use is defined as being referenced either by a Data Source or a Data Template.'), 'data_sources' => array('display' => 'Data Sources Using', 'align' => 'right', 'sort' => 'DESC', 'tip' => 'The number of Data Sources that use this Data Input Method.'), 'templates' => array('display' => 'Templates Using', 'align' => 'right', 'sort' => 'DESC', 'tip' => 'The number of Data Templates that use this Data Input Method.'), 'type_id' => array('display' => 'Data Input Method', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'The method used to gather information for this Data Input Method.')); html_header_sort_checkbox($display_text, get_request_var_request('sort_column'), get_request_var_request('sort_direction'), false); $i = 0; if (sizeof($data_inputs) > 0) { foreach ($data_inputs as $data_input) { /* hide system types */ if ($data_input['templates'] > 0 || $data_input['data_sources'] > 0) { $disabled = true; } else { $disabled = false; } form_alternate_row('line' . $data_input['id'], true, $disabled); form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars('data_input.php?action=edit&id=' . $data_input['id']) . "'>" . (strlen(get_request_var_request('filter')) ? preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", htmlspecialchars($data_input['name'])) : htmlspecialchars($data_input['name'])) . '</a>', $data_input['id']); form_selectable_cell($disabled ? 'No' : 'Yes', $data_input['id'], '', 'text-align:right'); form_selectable_cell(number_format($data_input['data_sources']), $data_input['id'], '', 'text-align:right'); form_selectable_cell(number_format($data_input['templates']), $data_input['id'], '', 'text-align:right'); form_selectable_cell($input_types[$data_input['type_id']], $data_input['id']); form_checkbox_cell($data_input['name'], $data_input['id'], $disabled); form_end_row(); } print $nav; } else { print "<tr><td colspan='5'><em>No Data Input Methods</em></td></tr>"; } html_end_box(false); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($di_actions); print "</form>\n"; }
function syslog_removal() { global $syslog_actions, $message_types, $config; include dirname(__FILE__) . '/config.php'; /* ================= input validation and session storage ================= */ $filters = array('rows' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'page' => array('filter' => FILTER_VALIDATE_INT, 'default' => '1'), 'id' => array('filter' => FILTER_VALIDATE_INT, 'default' => '1'), 'enabled' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'filter' => array('filter' => FILTER_CALLBACK, 'pageset' => true, 'default' => '', 'options' => array('options' => 'sanitize_search_string')), 'sort_column' => array('filter' => FILTER_CALLBACK, 'default' => 'name', 'options' => array('options' => 'sanitize_search_string')), 'sort_direction' => array('filter' => FILTER_CALLBACK, 'default' => 'ASC', 'options' => array('options' => 'sanitize_search_string'))); validate_store_request_vars($filters, 'sess_syslogr'); /* ================= input validation ================= */ html_start_box(__('Syslog Removal Rule Filters'), '100%', '', '3', 'center', 'syslog_removal.php?action=edit&type=1'); syslog_filter(); html_end_box(); $sql_where = ''; if (get_request_var('rows') == -1) { $row_limit = read_config_option('num_rows_table'); } elseif (get_request_var('rows') == -2) { $row_limit = 999999; } else { $row_limit = get_request_var('rows'); } $removals = syslog_get_removal_records($sql_where, $row_limit); $rows_query_string = "SELECT COUNT(*)\n\t\tFROM `" . $syslogdb_default . "`.`syslog_remove`\n\t\t{$sql_where}"; $total_rows = syslog_db_fetch_cell($rows_query_string); $nav = html_nav_bar('syslog_removal.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_request_var('page'), $row_limit, $total_rows, 13, 'Rules', 'page', 'main'); form_start('syslog_removal.php', 'chk'); print $nav; html_start_box('', '100%', '', '3', 'center', ''); $display_text = array('name' => array(__('Removal Name'), 'ASC'), 'enabled' => array(__('Enabled'), 'ASC'), 'type' => array(__('Match Type'), 'ASC'), 'message' => array(__('Search String'), 'ASC'), 'method' => array(__('Method'), 'DESC'), 'date' => array(__('Last Modified'), 'ASC'), 'user' => array(__('By User'), 'DESC')); html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction')); if (sizeof($removals)) { foreach ($removals as $removal) { form_alternate_row('line' . $removal['id'], true); form_selectable_cell(filter_value(title_trim($removal['name'], read_config_option('max_title_length')), get_request_var('filter'), $config['url_path'] . 'plugins/syslog/syslog_removal.php?action=edit&id=' . $removal['id']), $removal['id']); form_selectable_cell($removal['enabled'] == 'on' ? __('Yes') : __('No'), $removal['id']); form_selectable_cell($message_types[$removal['type']], $removal['id']); form_selectable_cell($removal['message'], $removal['id']); form_selectable_cell($removal['method'] == 'del' ? __('Deletion') : __('Transfer'), $removal['id']); form_selectable_cell(date('Y-m-d H:i:s', $removal['date']), $removal['id']); form_selectable_cell($removal['user'], $removal['id']); form_checkbox_cell($removal['name'], $removal['id']); form_end_row(); } } else { print "<tr><td colspan='4'><em>" . __('No Syslog Removal Rules Defined') . "</em></td></tr>"; } html_end_box(false); if (sizeof($removals)) { print $nav; } draw_actions_dropdown($syslog_actions); form_end(); }
function list_rrd() { global $config, $item_rows, $ds_actions, $rra_path, $hash_version_codes; /* suppress warnings */ error_reporting(0); /* install the rrdclean error handler */ set_error_handler('rrdclean_error_handler'); /* ================= input validation ================= */ input_validate_input_number(get_request_var_request('page')); input_validate_input_number(get_request_var_request('age')); input_validate_input_number(get_request_var_request('rows')); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST['filter'])) { $_REQUEST['filter'] = sanitize_search_string(get_request_var('filter')); } /* clean up sort_column 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_rrdclean_current_page'); kill_session_var('sess_rrdclean_age'); kill_session_var('sess_default_rows'); kill_session_var('sess_rrdclean_filter'); kill_session_var('sess_rrdclean_sort_column'); kill_session_var('sess_rrdclean_sort_direction'); unset($_REQUEST['page']); unset($_REQUEST['age']); unset($_REQUEST['rows']); unset($_REQUEST['filter']); unset($_REQUEST['sort_column']); unset($_REQUEST['sort_direction']); } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value('page', 'sess_rrdclean_current_page', '1'); load_current_session_value('age', 'sess_rrdclean_current_age', '1'); load_current_session_value('rows', 'sess_rrdclean_rows', read_config_option('num_rows_table')); load_current_session_value('filter', 'sess_rrdclean_filter', ''); load_current_session_value('sort_column', 'sess_rrdclean_sort_column', 'name'); load_current_session_value('sort_direction', 'sess_rrdclean_sort_direction', 'ASC'); $width = '100%'; if (isset($hash_version_codes[$config['cacti_version']])) { if ($hash_version_codes[$config['cacti_version']] > 13) { $width = '100%'; } } html_start_box('<strong>RRD Cleaner</strong>', $width, '', '3', 'center', ''); filter(); html_end_box(); $sql_where = 'WHERE in_cacti=0'; /* form the 'where' clause for our main sql query */ if ($_REQUEST['filter'] != '') { $sql_where .= " AND (rc.name LIKE '%" . $_REQUEST['filter'] . "%' OR rc.name_cache LIKE '%" . $_REQUEST['filter'] . "%' OR dt.name LIKE '%" . $_REQUEST['filter'] . "%')"; } $secsback = $_REQUEST['age']; if ($REQUEST['age'] != 0) { $sql_where .= " AND last_mod>='" . date("Y-m-d H:i:s", time() - 86400 * 7) . "'"; } else { $sql_where .= " AND last_mod<='" . date("Y-m-d H:i:s", time() - $secsback) . "'"; } print "<form action='rrdcleaner.php' method='post'>\n"; html_start_box('', $width, '', '3', 'center', ''); $total_rows = db_fetch_cell("SELECT COUNT(rc.name) \n\t\tFROM data_source_purge_temp AS rc\n\t\tLEFT JOIN data_template AS dt\n\t\tON dt.id = rc.data_template_id\n\t\t{$sql_where}"); $total_size = db_fetch_cell("SELECT ROUND(SUM(size),2) \n\t\tFROM data_source_purge_temp AS rc\n\t\tLEFT JOIN data_template AS dt\n\t\tON dt.id = rc.data_template_id\n\t\t{$sql_where}"); $file_list = db_fetch_assoc("SELECT rc.id, rc.name, rc.last_mod, rc.size, \n\t\trc.name_cache, rc.local_data_id, rc.data_template_id, dt.name AS data_template_name\n\t\tFROM data_source_purge_temp AS rc\n\t\tLEFT JOIN data_template AS dt\n\t\tON dt.id = rc.data_template_id\n\t\t{$sql_where} \n\t\tORDER BY " . $_REQUEST['sort_column'] . ' ' . $_REQUEST['sort_direction'] . ' LIMIT ' . $_REQUEST['rows'] * ($_REQUEST['page'] - 1) . ',' . $_REQUEST['rows']); $nav = html_nav_bar($config['url_path'] . 'rrdcleaner.php?filter' . get_request_var_request('filter'), MAX_DISPLAY_PAGES, get_request_var_request('page'), get_request_var_request('rows'), $total_rows, 8, 'RRD Files', 'page', 'main'); print $nav; $display_text = array('name' => array('RRD File Name', 'ASC'), 'name_cache' => array('DS Name', 'ASC'), 'local_data_id' => array('DS ID', 'ASC'), 'data_template_id' => array('Template ID', 'ASC'), 'data_template_name' => array('Template', 'ASC'), 'last_mod' => array('Last Modified', 'DESC'), 'size' => array('Size [KB]', 'DESC')); html_header_sort_checkbox($display_text, $_REQUEST['sort_column'], $_REQUEST['sort_direction'], false); if (sizeof($file_list)) { foreach ($file_list as $file) { $data_template_name = empty($file['data_template_name']) ? '<em>None</em>' : $file['data_template_name']; form_alternate_row('line' . $file['id'], true); form_selectable_cell(($_REQUEST['filter'] != '' ? eregi_replace('(' . preg_quote($_REQUEST['filter']) . ')', "<span class='filteredValue'>\\1</span>", $file['name']) : $file['name']) . '</a>', $file['id']); form_selectable_cell($file['local_data_id'] != 0 ? "<a class='linkEditMain' href='../../data_sources.php?action=ds_edit&id=" . $file['local_data_id'] . "'>" . ($_REQUEST['filter'] != '' ? eregi_replace('(' . preg_quote($_REQUEST['filter']) . ')', "<span class='filteredValue'>\\1</span>", title_trim(htmlentities($file['name_cache']), read_config_option('max_title_length'))) : title_trim(htmlentities($file['name_cache']), read_config_option('max_title_length'))) . '</a>' : '<i>Deleted</i>', $file['id']); form_selectable_cell($file['local_data_id'] > 0 ? $file['local_data_id'] : '<i>Deleted</i>', $file['id']); form_selectable_cell($file['data_template_id'] > 0 ? $file['data_template_id'] : '<i>Deleted</i>', $file['id']); form_selectable_cell($file['data_template_id'] > 0 ? $_REQUEST['filter'] != '' ? eregi_replace('(' . preg_quote($_REQUEST['filter']) . ')', "<span class='filteredValue'>\\1</span>", $file['data_template_name']) . '</a>' : $file['data_template_name'] : '<i>Deleted</i>', $file['id']); form_selectable_cell($file['last_mod'], $file['id']); form_selectable_cell($file['size'], $file['id']); form_checkbox_cell($file['id'], $file['id']); form_end_row(); $i++; } /* put the nav bar on the bottom as well */ print $nav; } else { print "<tr><td><em>No unused RRD Files</em></td></tr>\n"; } html_end_box(false); rrdcleaner_legend($total_size); draw_actions_dropdown($ds_actions); print "</form>\n"; /* restore original error handler */ restore_error_handler(); }
left join user_auth_perms on ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=1 and user_auth_perms.user_id=' . $_SESSION['sess_user_id'] . ') OR (host.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=' . $_SESSION['sess_user_id'] . ') OR (graph_templates.id=user_auth_perms.item_id and user_auth_perms.type=4 and user_auth_perms.user_id=' . $_SESSION['sess_user_id'] . '))'; } else { $sql_where = ''; $sql_join = ''; } $sql_base = "from (graph_templates_graph,graph_local)\n\t\t{$sql_join}\n\t\t{$sql_where}\n\t\t" . (empty($sql_where) ? 'where' : 'and') . " graph_templates_graph.local_graph_id > 0\n\t\tand graph_templates_graph.local_graph_id=graph_local.id\n\t\tand graph_templates_graph.title_cache like '%" . $_REQUEST['filter'] . "%'\n\t\t" . (empty($_REQUEST['host_id']) ? '' : ' and graph_local.host_id=' . $_REQUEST['host_id']) . ' ' . (empty($_REQUEST['graph_template_id']) ? '' : ' and graph_local.graph_template_id=' . $_REQUEST['graph_template_id']); $total_rows = count(db_fetch_assoc("select\n\t\tgraph_templates_graph.local_graph_id\n\t\t{$sql_base}")); $graphs = db_fetch_assoc("select\n\t\tgraph_templates_graph.local_graph_id,\n\t\thost.description,\n\t\tgraph_templates.name AS template_name,\n\t\tgraph_templates_graph.title_cache,\n\t\tgraph_templates_graph.height,\n\t\tgraph_templates_graph.width\n\t\t{$sql_base}\n\t\tgroup by graph_templates_graph.local_graph_id\n\t\torder by graph_templates_graph.title_cache\n\t\tlimit " . $_REQUEST['rows'] * ($_REQUEST['page'] - 1) . ',' . $_REQUEST['rows']); ?> <form name='chk' id='chk' action='graph_view.php' method='get' onSubmit='form_graph(document.chk,document.chk)'> <?php html_start_box('', '100%', '', '3', 'center', ''); $nav = html_nav_bar("graph_view.php?action=list", MAX_DISPLAY_PAGES, get_request_var_request("page"), get_request_var_request("rows"), $total_rows, 5, "Graphs"); print $nav; html_header_checkbox(array('Graph Title', 'Host', 'Graph Template', 'Graph Size'), false); $i = 0; if (sizeof($graphs)) { foreach ($graphs as $graph) { form_alternate_row('line' . $graph['local_graph_id'], true); form_selectable_cell("<strong><a href='" . htmlspecialchars('graph.php?local_graph_id=' . $graph['local_graph_id'] . '&rra_id=all') . "'>" . htmlspecialchars($graph['title_cache']) . '</a></strong>', $graph['local_graph_id'], '30%'); form_selectable_cell($graph['description'], $graph['local_graph_id']); form_selectable_cell($graph['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(); } print $nav; }
function ds() { global $ds_actions, $item_rows; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("ds_rows")); input_validate_input_number(get_request_var_request("host_id")); input_validate_input_number(get_request_var_request("template_id")); input_validate_input_number(get_request_var_request("method_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_ds_current_page"); kill_session_var("sess_ds_filter"); kill_session_var("sess_ds_sort_column"); kill_session_var("sess_ds_sort_direction"); kill_session_var("sess_ds_rows"); kill_session_var("sess_ds_host_id"); kill_session_var("sess_ds_template_id"); kill_session_var("sess_ds_method_id"); unset($_REQUEST["page"]); unset($_REQUEST["filter"]); unset($_REQUEST["sort_column"]); unset($_REQUEST["sort_direction"]); unset($_REQUEST["ds_rows"]); unset($_REQUEST["host_id"]); unset($_REQUEST["template_id"]); unset($_REQUEST["method_id"]); } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("page", "sess_ds_current_page", "1"); load_current_session_value("filter", "sess_ds_filter", ""); load_current_session_value("sort_column", "sess_ds_sort_column", "name_cache"); load_current_session_value("sort_direction", "sess_ds_sort_direction", "ASC"); load_current_session_value("ds_rows", "sess_ds_rows", read_config_option("num_rows_data_source")); load_current_session_value("host_id", "sess_ds_host_id", "-1"); load_current_session_value("template_id", "sess_ds_template_id", "-1"); load_current_session_value("method_id", "sess_ds_method_id", "-1"); $host = db_fetch_row("select hostname from host where id=" . get_request_var_request("host_id")); /* if the number of rows is -1, set it to the default */ if (get_request_var_request("ds_rows") == -1) { $_REQUEST["ds_rows"] = read_config_option("num_rows_data_source"); } ?> <script type="text/javascript"> <!-- function applyDSFilterChange(objForm) { strURL = '?host_id=' + objForm.host_id.value; strURL = strURL + '&filter=' + objForm.filter.value; strURL = strURL + '&ds_rows=' + objForm.ds_rows.value; strURL = strURL + '&template_id=' + objForm.template_id.value; strURL = strURL + '&method_id=' + objForm.method_id.value; document.location = strURL; } --> </script> <?php html_start_box("<strong>Data Sources</strong> [host: " . (empty($host["hostname"]) ? "No Host" : htmlspecialchars($host["hostname"])) . "]", "100%", "", "3", "center", "data_sources.php?action=ds_edit&host_id=" . get_request_var_request("host_id")); ?> <tr class='even noprint'> <td> <form name="form_data_sources" action="data_sources.php"> <table cellpadding="1" cellspacing="0"> <tr> <td width="50"> Host: </td> <td> <select name="host_id" onChange="applyDSFilterChange(document.form_data_sources)"> <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 $hosts = db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"); 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="50"> Template: </td> <td width="1"> <select name="template_id" onChange="applyDSFilterChange(document.form_data_sources)"> <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 = db_fetch_assoc("SELECT DISTINCT data_template.id, data_template.name\n\t\t\t\t\t\t\t\tFROM data_template\n\t\t\t\t\t\t\t\tINNER JOIN data_template_data\n\t\t\t\t\t\t\t\tON data_template.id=data_template_data.data_template_id\n\t\t\t\t\t\t\t\tWHERE data_template_data.local_data_id>0\n\t\t\t\t\t\t\t\tORDER BY data_template.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 nowrap style='white-space: nowrap;'> <input type="submit" value="Go" title="Set/Refresh Filters"> <input type="submit" name="clear_x" value="Clear" title="Clear Filters"> </td> </tr> <tr> <td width="50"> Method: </td> <td width="1"> <select name="method_id" onChange="applyDSFilterChange(document.form_data_sources)"> <option value="-1"<?php if (get_request_var_request("method_id") == "-1") { ?> selected<?php } ?> >Any</option> <option value="0"<?php if (get_request_var_request("method_id") == "0") { ?> selected<?php } ?> >None</option> <?php $methods = db_fetch_assoc("SELECT DISTINCT data_input.id, data_input.name\n\t\t\t\t\t\t\t\tFROM data_input\n\t\t\t\t\t\t\t\tINNER JOIN data_template_data\n\t\t\t\t\t\t\t\tON data_input.id=data_template_data.data_input_id\n\t\t\t\t\t\t\t\tWHERE data_template_data.local_data_id>0\n\t\t\t\t\t\t\t\tORDER BY data_input.name"); if (sizeof($methods) > 0) { foreach ($methods as $method) { print "<option value='" . $method["id"] . "'"; if (get_request_var_request("method_id") == $method["id"]) { print " selected"; } print ">" . title_trim(htmlspecialchars($method["name"]), 40) . "</option>\n"; } } ?> </select> </td> <td nowrap style='white-space: nowrap;' width="50"> Rows per Page: </td> <td width="1"> <select name="ds_rows" onChange="applyDSFilterChange(document.form_data_sources)"> <option value="-1"<?php if (get_request_var_request("ds_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("ds_rows") == $key) { print " selected"; } print ">" . htmlspecialchars($value) . "</option>\n"; } } ?> </select> </td> </tr> </table> <table cellpadding="1" cellspacing="0"> <tr> <td width="50"> Search: </td> <td width="1"> <input type="text" name="filter" size="40" value="<?php print htmlspecialchars(get_request_var_request("filter")); ?> "> </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_where1 = "AND (data_template_data.name_cache like '%%" . get_request_var_request("filter") . "%%'" . " OR data_template_data.local_data_id like '%%" . get_request_var_request("filter") . "%%'" . " OR data_template.name like '%%" . get_request_var_request("filter") . "%%'" . " OR data_input.name like '%%" . get_request_var_request("filter") . "%%')"; $sql_where2 = "AND (data_template_data.name_cache like '%%" . get_request_var_request("filter") . "%%'" . " OR data_template.name like '%%" . get_request_var_request("filter") . "%%')"; } else { $sql_where1 = ""; $sql_where2 = ""; } if (get_request_var_request("host_id") == "-1") { /* Show all items */ } elseif (get_request_var_request("host_id") == "0") { $sql_where1 .= " AND data_local.host_id=0"; $sql_where2 .= " AND data_local.host_id=0"; } elseif (!empty($_REQUEST["host_id"])) { $sql_where1 .= " AND data_local.host_id=" . get_request_var_request("host_id"); $sql_where2 .= " AND data_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_where1 .= " AND data_template_data.data_template_id=0"; $sql_where2 .= " AND data_template_data.data_template_id=0"; } elseif (!empty($_REQUEST["host_id"])) { $sql_where1 .= " AND data_template_data.data_template_id=" . get_request_var_request("template_id"); $sql_where2 .= " AND data_template_data.data_template_id=" . get_request_var_request("template_id"); } if (get_request_var_request("method_id") == "-1") { /* Show all items */ } elseif (get_request_var_request("method_id") == "0") { $sql_where1 .= " AND data_template_data.data_input_id=0"; $sql_where2 .= " AND data_template_data.data_input_id=0"; } elseif (!empty($_REQUEST["method_id"])) { $sql_where1 .= " AND data_template_data.data_input_id=" . get_request_var_request("method_id"); $sql_where2 .= " AND data_template_data.data_input_id=" . get_request_var_request("method_id"); } $total_rows = sizeof(db_fetch_assoc("SELECT\n\t\tdata_local.id\n\t\tFROM (data_local,data_template_data)\n\t\tLEFT JOIN data_input\n\t\tON (data_input.id=data_template_data.data_input_id)\n\t\tLEFT JOIN data_template\n\t\tON (data_local.data_template_id=data_template.id)\n\t\tWHERE data_local.id=data_template_data.local_data_id\n\t\t{$sql_where1}")); $poller_intervals = array_rekey(db_fetch_assoc("SELECT data_template_data.local_data_id AS id,\n\t\tMin(data_template_data.rrd_step*rra.steps) AS poller_interval\n\t\tFROM data_template\n\t\tINNER JOIN (data_local\n\t\tINNER JOIN ((data_template_data_rra\n\t\tINNER JOIN data_template_data ON data_template_data_rra.data_template_data_id=data_template_data.id)\n\t\tINNER JOIN rra ON data_template_data_rra.rra_id = rra.id) ON data_local.id = data_template_data.local_data_id) ON data_template.id = data_template_data.data_template_id\n\t\t{$sql_where2}\n\t\tGROUP BY data_template_data.local_data_id"), "id", "poller_interval"); $data_sources = db_fetch_assoc("SELECT\n\t\tdata_template_data.local_data_id,\n\t\tdata_template_data.name_cache,\n\t\tdata_template_data.active,\n\t\tdata_input.name as data_input_name,\n\t\tdata_template.name as data_template_name,\n\t\tdata_local.host_id\n\t\tFROM (data_local,data_template_data)\n\t\tLEFT JOIN data_input\n\t\tON (data_input.id=data_template_data.data_input_id)\n\t\tLEFT JOIN data_template\n\t\tON (data_local.data_template_id=data_template.id)\n\t\tWHERE data_local.id=data_template_data.local_data_id\n\t\t{$sql_where1}\n\t\tORDER BY " . get_request_var_request("sort_column") . " " . get_request_var_request("sort_direction") . " LIMIT " . get_request_var_request("ds_rows") * (get_request_var_request("page") - 1) . "," . get_request_var_request("ds_rows")); print "<form name='chk' method='post' action='data_sources.php'>\n"; html_start_box("", "100%", "", "3", "center", ""); $nav = html_nav_bar("data_sources.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("ds_rows"), $total_rows, 7); print $nav; $display_text = array("name_cache" => array("Name", "ASC"), "local_data_id" => array("ID", "ASC"), "data_input_name" => array("Data Input Method", "ASC"), "nosort" => array("Poller Interval", "ASC"), "active" => array("Active", "ASC"), "data_template_name" => array("Template Name", "ASC")); html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction"), false); $i = 0; if (sizeof($data_sources) > 0) { foreach ($data_sources as $data_source) { $data_source["data_template_name"] = htmlspecialchars($data_source["data_template_name"]); $data_name_cache = title_trim(htmlspecialchars($data_source["name_cache"]), read_config_option("max_title_data_source")); if (trim(get_request_var_request("filter") != "")) { $data_name_cache = preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $data_name_cache); } /* keep copy of data source for comparison */ $data_source_orig = $data_source; $data_source = api_plugin_hook_function('data_sources_table', $data_source); /* we're escaping strings here, so no need to escape them on form_selectable_cell */ if (empty($data_source["data_template_name"])) { $data_template_name = "<em>None</em>"; } elseif ($data_source_orig["data_template_name"] != $data_source["data_template_name"]) { /* was changed by plugin, plugin has to take care for html-escaping */ $data_template_name = empty($data_source["data_template_name"]) ? "<em>None</em>" : $data_source["data_template_name"]; } elseif (trim(get_request_var_request("filter") != "")) { /* we take care of html-escaping */ $data_template_name = preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", htmlspecialchars($data_source['data_template_name'])); } else { $data_template_name = htmlspecialchars($data_source["data_template_name"]); } if (empty($data_source["data_input_name"])) { $data_input_name = "<em>None</em>"; } elseif ($data_source_orig["data_input_name"] != $data_source["data_input_name"]) { /* was changed by plugin, plugin has to take care for html-escaping */ $data_input_name = empty($data_source["data_input_name"]) ? "<em>None</em>" : $data_source["data_input_name"]; } elseif (trim(get_request_var_request("filter") != "")) { /* we take care of html-escaping */ $data_input_name = preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", htmlspecialchars($data_source['data_input_name'])); } else { $data_input_name = htmlspecialchars($data_source["data_input_name"]); } $poller_interval = isset($poller_intervals[$data_source["local_data_id"]]) ? $poller_intervals[$data_source["local_data_id"]] : 0; form_alternate_row('line' . $data_source["local_data_id"], true); form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars("data_sources.php?action=ds_edit&id=" . $data_source["local_data_id"]) . "' title='" . htmlspecialchars($data_source["name_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($data_source["name_cache"]), read_config_option("max_title_data_source"))) : title_trim(htmlspecialchars($data_source["name_cache"]), read_config_option("max_title_data_source"))) . "</a>", $data_source["local_data_id"]); form_selectable_cell($data_source['local_data_id'], $data_source['local_data_id']); form_selectable_cell($data_input_name, $data_source["local_data_id"]); form_selectable_cell(get_poller_interval($poller_interval), $data_source["local_data_id"]); form_selectable_cell($data_source['active'] == "on" ? "Yes" : "No", $data_source["local_data_id"]); form_selectable_cell($data_template_name, $data_source["local_data_id"]); form_checkbox_cell($data_source["name_cache"], $data_source["local_data_id"]); form_end_row(); } /* put the nav bar on the bottom as well */ print $nav; } else { print "<tr><td><em>No Data Sources</em></td></tr>"; } html_end_box(false); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($ds_actions); print "</form>\n"; }
function show_devices() { global $action, $expire_arr, $rotation_arr, $version_arr, $nesting_arr; global $config, $flow_actions; /* ================= input validation and session storage ================= */ $filters = array('page' => array('filter' => FILTER_VALIDATE_INT, 'default' => '1'), 'filter' => array('filter' => FILTER_CALLBACK, 'pageset' => true, 'default' => '', 'options' => array('options' => 'sanitize_search_string')), 'sort_column' => array('filter' => FILTER_CALLBACK, 'default' => 'name', 'options' => array('options' => 'sanitize_search_string')), 'sort_direction' => array('filter' => FILTER_CALLBACK, 'default' => 'ASC', 'options' => array('options' => 'sanitize_search_string'))); validate_store_request_vars($filters, 'sess_fvd'); /* ================= input validation ================= */ $sql_where = get_request_var('filter') != '' ? "name LIKE '%" . get_request_var('filter') . "%'" : ''; $num_rows = read_config_option('num_rows_table'); $sql = "SELECT * \n\t\tFROM plugin_flowview_devices \n\t\t{$sql_where}\n\t\tORDER BY " . get_request_var('sort_column') . ' ' . get_request_var('sort_direction') . ' LIMIT ' . ($num_rows * (get_request_var('page') - 1) . ',' . $num_rows); $result = db_fetch_assoc($sql); $total_rows = db_fetch_cell("SELECT COUNT(*) FROM plugin_flowview_devices {$sql_where}"); html_start_box('FlowView Listeners', '100%', '', '4', 'center', 'flowview_devices.php?action=edit'); ?> <tr class='even'> <td> <form name='listeners' action='flowview_devices.php'> <table class='fitlerTable'> <tr> <td> Search </td> <td> <input type='text' id='filter' size='40' value='<?php print htmlspecialchars(get_request_var('filter')); ?> '> </td> <td> <input id='refresh' type='button' value='Go' title='Set/Refresh Filters'> </td> <td> <input id='clear' type='button' name='clear' value='Clear' title='Clear Filters'> </td> </tr> </table> <input type='hidden' name='page' value='<?php print get_request_var('page'); ?> '> </form> </td> </tr> <?php html_end_box(); $nav = html_nav_bar('flowview_devices.php', MAX_DISPLAY_PAGES, get_request_var('page'), $num_rows, $total_rows, 10, 'Listeners', 'page', 'main'); form_start('flowview_devices.php', 'chk'); print $nav; html_start_box('', '100%', '', '4', 'center', ''); $display_array = array('name' => array('Name', 'ASC'), 'folder' => array('Directory', 'ASC'), 'nexting' => array('Nesting', 'ASC'), 'allowfrom' => array('Allowed From', 'ASC'), 'port' => array('Port', 'ASC'), 'version' => array('Version', 'ASC'), 'compression' => array('Compression', 'ASC'), 'rotation' => array('Rotation', 'ASC'), 'expire' => array('Expire', 'ASC')); html_header_sort_checkbox($display_array, get_request_var('sort_column'), get_request_var('sort_direction'), false); if (count($result)) { foreach ($result as $row) { form_alternate_row('line' . $row['id'], true); form_selectable_cell('<a class="linkEditMain" href="flowview_devices.php?&tab=listeners&action=edit&id=' . $row['id'] . '">' . $row['name'] . '</a>', $row['id']); form_selectable_cell($row['folder'], $row['id']); form_selectable_cell($nesting_arr[$row['nesting']], $row['id']); form_selectable_cell($row['allowfrom'], $row['id']); form_selectable_cell($row['port'], $row['id']); form_selectable_cell($version_arr[$row['version']], $row['id']); form_selectable_cell($row['compression'], $row['id']); form_selectable_cell($rotation_arr[$row['rotation']], $row['id']); form_selectable_cell($expire_arr[$row['expire']], $row['id']); form_checkbox_cell($row['name'], $row['id']); form_end_row(); } } else { print "<tr class='even'><td colspan=10><center>No Devices</center></td></tr>\n"; } html_end_box(false); if (count($result)) { print $nav; } draw_actions_dropdown($flow_actions); form_end(); }
function webseer_urls($header_label) { global $assoc_actions, $item_rows; /* ================= input validation and session storage ================= */ $filters = array('rows' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'page' => array('filter' => FILTER_VALIDATE_INT, 'default' => '1'), 'filter' => array('filter' => FILTER_CALLBACK, 'pageset' => true, 'default' => '', 'options' => array('options' => 'sanitize_search_string')), 'associated' => array('filter' => FILTER_CALLBACK, 'default' => 'true', 'options' => array('options' => 'sanitize_search_string'))); validate_store_request_vars($filters, 'sess_maint_ws'); /* ================= input validation ================= */ /* if the number of rows is -1, set it to the default */ if (get_request_var('rows') == '-1') { $rows = read_config_option('num_rows_table'); } else { $rows = get_request_var('rows'); } ?> <script type='text/javascript'> function applyFilter() { strURL = 'maint.php?tab=webseer&action=edit&id=<?php print get_request_var('id'); ?> '; strURL += '&rows=' + $('#rows').val(); strURL += '&associated=' + $('#associated').is(':checked'); strURL += '&filter=' + $('#filter').val(); strURL += '&header=false'; loadPageNoHeader(strURL); } function clearFilter() { strURL = 'maint.php?tab=webseer&action=edit&id=<?php print get_request_var('id'); ?> &clear=true&header=false'; loadPageNoHeader(strURL); } </script> <?php html_start_box(__('Associated Web URL\'s ') . htmlspecialchars($header_label), '100%', '', '3', 'center', ''); ?> <tr class='even'> <td> <form name='form_devices' method='post' action='maint.php?action=edit&tab=webseer'> <table class='filterTable'> <tr> <td> <?php print __('Search'); ?> </td> <td> <input type='text' id='filter' size='25' value='<?php print htmlspecialchars(get_request_var('filter')); ?> ' onChange='applyFilter()'> </td> <td> <?php print __('Rules'); ?> </td> <td> <select id='rows' onChange='applyFilter()'> <option value='-1'<?php if (get_request_var('rows') == '-1') { ?> selected<?php } ?> ><?php print __('Default'); ?> </option> <?php if (sizeof($item_rows) > 0) { foreach ($item_rows as $key => $value) { print "<option value='" . $key . "'"; if (get_request_var('rows') == $key) { print ' selected'; } print '>' . htmlspecialchars($value) . "</option>\n"; } } ?> </select> </td> <td> <input type='checkbox' id='associated' onChange='applyFilter()' <?php print get_request_var('associated') == 'true' || get_request_var('associated') == 'on' ? 'checked' : ''; ?> > </td> <td> <label for='associated'><?php print __('Associated'); ?> </label> </td> <td> <input type='button' value='<?php print __('Go'); ?> ' onClick='applyFilter()' title='<?php print __('Set/Refresh Filters'); ?> '> </td> <td> <input type='button' name='clear' value='<?php print __('Clear'); ?> ' onClick='clearFilter()' title='<?php print __('Clear Filters'); ?> '> </td> </tr> </table> <input type='hidden' name='page' value='<?php print get_request_var('page'); ?> '> <input type='hidden' name='id' value='<?php print get_request_var('id'); ?> '> </form> </td> </tr> <?php html_end_box(); /* form the 'where' clause for our main sql query */ if (strlen(get_request_var('filter'))) { $sql_where = "WHERE ((u.url LIKE '%" . get_request_var('filter') . "%') \n\t\t\tOR (u.display_name LIKE '%" . get_request_var('filter') . "%') \n\t\t\tOR (u.ip LIKE '%" . get_request_var('filter') . "%'))"; } else { $sql_where = ''; } if (get_request_var('associated') == 'false') { $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . ' (pmh.type=2 OR pmh.type IS NULL)'; } else { $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . ' pmh.type=2 AND pmh.schedule=' . get_request_var('id'); } $total_rows = db_fetch_cell("SELECT\n\t\tCOUNT(*)\n\t\tFROM plugin_webseer_urls AS u\n\t\tLEFT JOIN plugin_maint_hosts AS pmh\n\t\tON u.id=pmh.host\n\t\t{$sql_where}"); $sql_query = "SELECT u.*, pmh.host AS associated, pmh.type AS maint_type\n\t\tFROM plugin_webseer_urls AS u\n\t\tLEFT JOIN plugin_maint_hosts AS pmh\n\t\tON u.id=pmh.host\n\t\t{$sql_where} \n\t\tLIMIT " . $rows * (get_request_var('page') - 1) . ',' . $rows; $urls = db_fetch_assoc($sql_query); $nav = html_nav_bar('notify_lists.php?action=edit&id=' . get_request_var('id'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 13, __('Lists'), 'page', 'main'); form_start('maint.php', 'chk'); print $nav; html_start_box('', '100%', '', '3', 'center', ''); $display_text = array(__('Description'), __('ID'), __('Associated Schedules'), __('Enabled'), __('Hostname'), __('URL')); html_header_checkbox($display_text); if (sizeof($urls)) { foreach ($urls as $url) { form_alternate_row('line' . $url['id']); form_selectable_cell(strlen(get_request_var('filter')) ? preg_replace('/(' . preg_quote(get_request_var('filter')) . ')/i', "<span class='filteredValue'>\\1</span>", htmlspecialchars($url['display_name'])) : htmlspecialchars($url['display_name']), $url['id'], 250); form_selectable_cell(round($url['id'], 2), $url['id']); if ($url['associated'] != '' && $url['maint_type'] == '2') { form_selectable_cell('<span class="deviceUp">' . __('Current Schedule') . '</span>', $url['id']); } else { if (sizeof($lists = db_fetch_assoc('SELECT name FROM plugin_maint_schedules INNER JOIN plugin_maint_hosts ON plugin_maint_schedules.id=plugin_maint_hosts.schedule WHERE type=2 AND host=' . $url['id']))) { $names = ''; foreach ($lists['name'] as $name) { $names .= (strlen($names) ? ', ' : '') . "<span class='deviceRecovering'>{$name}</span>"; } form_selectable_cell($names, $url['id']); } else { form_selectable_cell('<span class="deviceUnknown">' . __('No Schedules') . '</span>', $url['id']); } } form_selectable_cell($url['enabled'] == 'on' ? __('Enabled') : __('Disabled'), $url['id']); if (empty($url['ip'])) { $url['ip'] = __('USING DNS'); } form_selectable_cell(strlen(get_request_var('filter')) ? preg_replace('/(' . preg_quote(get_request_var('filter')) . ')/i', "<span class='filteredValue'>\\1</span>", '<i>' . htmlspecialchars($url['ip'])) . '</i>' : '<i>' . htmlspecialchars($url['ip']) . '</i>', $url['id']); form_selectable_cell(strlen(get_request_var('filter')) ? preg_replace('/(' . preg_quote(get_request_var('filter')) . ')/i', "<span class='filteredValue'>\\1</span>", htmlspecialchars($url['url'])) : htmlspecialchars($url['url']), $url['id']); form_checkbox_cell($url['display_name'], $url['id']); form_end_row(); } } else { print "<tr><td><em>" . __('No Associated WebSeer URL\'s Found') . "</em></td></tr>"; } html_end_box(false); if (sizeof($urls)) { print $nav; } form_hidden_box('id', get_request_var('id'), ''); form_hidden_box('save_webseer', '1', ''); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($assoc_actions); form_end(); }
$graphs = db_fetch_assoc("SELECT " . "graph_templates_graph.local_graph_id, " . "graph_templates_graph.height, " . "graph_templates_graph.title_cache " . $sql_base . " " . "GROUP BY graph_templates_graph.local_graph_id " . "ORDER BY graph_templates_graph.title_cache " . "limit " . $_REQUEST["rows"] * ($_REQUEST["page"] - 1) . "," . $_REQUEST["rows"]); /* do some fancy navigation url construction so we don't have to try and rebuild the url string */ if (ereg("page=[0-9]+", basename($_SERVER["QUERY_STRING"]))) { $nav_url = str_replace("page=" . get_request_var_request("page"), "page=<PAGE>", get_browser_query_string()); } else { $nav_url = get_browser_query_string() . (substr_count(get_browser_query_string(), "?") ? "&" : "?") . "page=<PAGE>&host_id=" . get_request_var_request("host_id"); } $nav_url = preg_replace("/((\\?|&)host_id=[0-9]+|(\\?|&)filter=[a-zA-Z0-9]*)/", "", $nav_url); html_start_box("", "100%", $colors["header"], "1", "center", ""); html_nav_bar($colors["header"], read_graph_config_option("num_columns"), get_request_var_request("page"), $_REQUEST["rows"], $total_rows, $nav_url); if (read_graph_config_option("thumbnail_section_preview") == "on") { html_graph_thumbnail_area($graphs, "", "graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end()); } else { html_graph_area($graphs, "", "graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end()); } html_nav_bar($colors["header"], read_graph_config_option("num_columns"), get_request_var_request("page"), $_REQUEST["rows"], $total_rows, $nav_url); html_end_box(); break; case 'list': if (read_config_option("auth_method") != 0 && empty($current_user["show_list"])) { print "<strong><font size='+1' color='FF0000'>YOU DO NOT HAVE RIGHTS FOR LIST VIEW</font></strong>"; exit; } /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("host_id")); input_validate_input_number(get_request_var_request("graph_template_id")); input_validate_input_number(get_request_var_request("rows")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var_request("filter"));
function mactrack_view_sites() { global $title, $config, $item_rows; mactrack_sites_request_validation(); if (get_request_var('rows') == -1) { $row_limit = read_config_option('num_rows_table'); } elseif (get_request_var('rows') == -2) { $row_limit = 999999; } else { $row_limit = get_request_var('rows'); } $webroot = $config['url_path'] . '/plugins/mactrack/'; mactrack_tabs(); html_start_box($title, '100%', '', '3', 'center', ''); mactrack_site_filter('mactrack_view_sites.php'); html_end_box(); $sql_where = ''; $sites = mactrack_view_get_site_records($sql_where, $row_limit); if (get_request_var('detail') == 'false') { $total_rows = db_fetch_cell("SELECT\n\t\t\tCOUNT(mac_track_sites.site_id)\n\t\t\tFROM mac_track_sites\n\t\t\t{$sql_where}"); } else { $total_rows = sizeof(db_fetch_assoc("SELECT\n\t\t\tmac_track_device_types.device_type_id, mac_track_sites.site_name\n\t\t\tFROM (mac_track_device_types\n\t\t\tRIGHT JOIN mac_track_devices ON (mac_track_device_types.device_type_id = mac_track_devices.device_type_id))\n\t\t\tRIGHT JOIN mac_track_sites ON (mac_track_devices.site_id = mac_track_sites.site_id)\n\t\t\t{$sql_where}\n\t\t\tGROUP BY mac_track_sites.site_name, mac_track_device_types.device_type_id")); } $nav = html_nav_bar('mactrack_view_sites.php', MAX_DISPLAY_PAGES, get_request_var('page'), $row_limit, $total_rows, 11, __('Sites')); print $nav; html_start_box('', '100%', '', '3', 'center', ''); if (get_request_var('detail') == 'false') { $display_text = array('nosort' => array(__('Actions'), ''), 'site_name' => array(__('Site Name'), 'ASC'), 'total_devices' => array(__('Devices'), 'DESC'), 'total_ips' => array(__('Total IP\'s'), 'DESC'), 'total_user_ports' => array(__('User Ports'), 'DESC'), 'total_oper_ports' => array(__('User Ports Up'), 'DESC'), 'total_macs' => array(__('MACS Found'), 'DESC'), 'total_device_errors' => array(__('Device Errors'), 'DESC')); html_header_sort($display_text, get_request_var('sort_column'), get_request_var('sort_direction')); if (sizeof($sites) > 0) { foreach ($sites as $site) { form_alternate_row('row_' . $site['site_id'], true); ?> <td width=140> <?php if (api_user_realm_auth('mactrack_sites.php')) { echo "<a href='" . htmlspecialchars($webroot . 'mactrack_sites.php?action=edit&site_id=' . $site['site_id']) . "' title='" . __('Edit Site') . "'><img border='0' src='" . $webroot . "images/edit_object.png'></a>"; echo "<a href='#'><img id='r_" . $site['site_id'] . "' src='" . $webroot . "images/rescan_site.gif' alt='' onClick='site_scan(" . $site['site_id'] . ")' title='" . __('Rescan Site') . "' border='0'></a>"; } ?> <a href='<?php print htmlspecialchars($webroot . 'mactrack_view_devices.php?report=devices&reset&site_id=' . $site['site_id']); ?> ' title='<?php print __('View Devices'); ?> '><img border='0' src='<?php print $webroot; ?> images/view_devices.gif'></a> <a href='<?php print htmlspecialchars($webroot . 'mactrack_view_ips.php?report=ips&reset&site_id=' . $site['site_id']); ?> ' title='<?php print __('View IP Ranges'); ?> '><img border='0' src='<?php print $webroot; ?> images/view_networks.gif'></a> <a href='<?php print htmlspecialchars($webroot . 'plugins/mactrack/mactrack_view_arp.php?report=arp&reset&site_id=' . $site['site_id']); ?> ' title='<?php print __('View IP Addresses'); ?> '><img border='0' src='<?php print $webroot; ?> images/view_ipaddresses.gif'></a> <a href='<?php print htmlspecialchars($webroot . 'plugins/mactrack/mactrack_view_macs.php?report=macs&reset&device_id=-1&scan_date=3&site_id=' . $site['site_id']); ?> ' title='<?php print __('View MAC Addresses'); ?> '><img border='0' src='<?php print $webroot; ?> images/view_macs.gif'></a> <a href='<?php print htmlspecialchars($webroot . 'mactrack_view_interfaces.php?report=interfaces&reset&site=' . $site['site_id']); ?> ' title='<?php print __('View Interfaces'); ?> '><img border='0' src='<?php print $webroot; ?> images/view_interfaces.gif'></a> </td> <td class='hyperLink'> <?php print filter_value($site['site_name'], get_request_var('filter')); ?> </td> <td><?php print number_format_i18n($site['total_devices']); ?> </td> <td><?php print number_format_i18n($site['total_ips']); ?> </td> <td><?php print number_format_i18n($site['total_user_ports']); ?> </td> <td><?php print number_format_i18n($site['total_oper_ports']); ?> </td> <td><?php print number_format_i18n($site['total_macs']); ?> </td> <td><?php print $site['total_device_errors']; ?> </td> </tr> <?php } } else { print '<tr><td colspan="10"><em>' . __('No MacTrack Sites') . '</em></td></tr>'; } html_end_box(false); if (sizeof($sites)) { print $nav; mactrack_display_stats(); } } else { $display_text = array('nosort' => array(__('Actions'), ''), 'site_name' => array(__('Site Name'), 'ASC'), 'vendor' => array(__('Vendor'), 'ASC'), 'description' => array(__('Device Type'), 'DESC'), 'total_devices' => array(__('Total Devices'), 'DESC'), 'sum_ips_total' => array(__('Total IP\'s'), 'DESC'), 'sum_ports_total' => array(__('Total User Ports'), 'DESC'), 'sum_ports_active' => array(__('Total Oper Ports'), 'DESC'), 'sum_ports_trunk' => array(__('Total Trunks'), 'DESC'), 'sum_macs_active' => array(__('MACS Found'), 'DESC')); html_header_sort($display_text, get_request_var('sort_column'), get_request_var('sort_direction')); if (sizeof($sites)) { foreach ($sites as $site) { form_alternate_row(); ?> <td width=100> <?php if (api_user_realm_auth('mactrack_sites.php')) { echo "<a href='" . htmlspecialchars($webroot . 'mactrack_sites.php?action=edit&site_id=' . $site['site_id']) . "' title='" . __('Edit Site') . "'><img border='0' src='" . $webroot . "images/edit_object.png'></a>"; } ?> <a href='<?php print htmlspecialchars($webroot . 'mactrack_view_devices.php?report=devices&site_id=' . $site['site_id'] . '&device_type_id=' . $site['device_type_id'] . '&type_id=-1&status=-1&filter='); ?> ' title='<?php print __('View Devices'); ?> '><img border='0' src='<?php print $webroot; ?> images/view_devices.gif'></a> <a href='<?php print htmlspecialchars($webroot . 'mactrack_view_ips.php?report=ips&reset&site_id=' . $site['site_id']); ?> ' title='<?php print __('View IP Ranges'); ?> '><img border='0' src='<?php print $webroot; ?> images/view_networks.gif'></a> <a href='<?php print htmlspecialchars($webroot . 'mactrack_view_macs.php?report=macs&reset&device_id=-1&scan_date=3&site_id=' . $site['site_id']); ?> ' title='<?php print __('View MAC Addresses'); ?> '><img border='0' src='<?php print $webroot; ?> images/view_macs.gif'></a> <a href='<?php print htmlspecialchars($webroot . 'mactrack_view_interfaces.php?report=interfaces&reset&site=' . $site['site_id']); ?> ' title='<?php print __('View Interfaces'); ?> '><img border='0' src='<?php print $webroot; ?> images/view_interfaces.gif'></a> </td> <td class='hyperLink'> <?php print filter_value($site['site_name'], get_request_var('filter')); ?> </td> <td><?php print filter_value($site['vendor'], get_request_var('filter')); ?> <td><?php print filter_value($site['description'], get_request_var('filter')); ?> <td><?php print number_format_i18n($site['total_devices']); ?> </td> <td><?php print $site['device_type'] == '1' ? __('N/A') : number_format_i18n($site['sum_ips_total']); ?> </td> <td><?php print $site['device_type'] == '3' ? __('N/A') : number_format_i18n($site['sum_ports_total']); ?> </td> <td><?php print $site['device_type'] == '3' ? __('N/A') : number_format_i18n($site['sum_ports_active']); ?> </td> <td><?php print $site['device_type'] == '3' ? __('N/A') : number_format_i18n($site['sum_ports_trunk']); ?> </td> <td><?php print $site['device_type'] == '3' ? __('N/A') : number_format_i18n($site['sum_macs_active']); ?> </td> </tr> <?php } } else { print '<tr><td colspan="10"><em>' . __('No MacTrack Sites') . '</em></td></tr>'; } html_end_box(false); if (sizeof($sites)) { print $nav; mactrack_display_stats(); } } print '<div id="response"></div>'; }
function mikrotik_user() { global $user_actions, $item_rows; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request('page')); input_validate_input_number(get_request_var_request('rows')); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST['filter'])) { $_REQUEST['filter'] = sanitize_search_string(get_request_var('filter')); } /* clean up sort_column */ if (isset($_REQUEST['sort_column'])) { $_REQUEST['sort_column'] = sanitize_search_string(get_request_var('sort_column')); } /* clean up search string */ if (isset($_REQUEST['sort_direction'])) { $_REQUEST['sort_direction'] = sanitize_search_string(get_request_var('sort_direction')); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST['clear'])) { kill_session_var('sess_mtu_current_page'); kill_session_var('sess_mtu_filter'); kill_session_var('sess_mtu_rows'); kill_session_var('sess_mtu_sort_column'); kill_session_var('sess_mtu_sort_direction'); unset($_REQUEST['page']); unset($_REQUEST['filter']); unset($_REQUEST['rows']); unset($_REQUEST['sort_column']); unset($_REQUEST['sort_direction']); } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value('page', 'sess_mtu_current_page', '1'); load_current_session_value('filter', 'sess_mtu_filter', ''); load_current_session_value('rows', 'sess_mtu_rows', read_config_option('num_rows_device')); load_current_session_value('sort_column', 'sess_mtu_sort_column', 'name'); load_current_session_value('sort_direction', 'sess_mtu_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_device'); } ?> <script type='text/javascript'> function applyFilter(objForm) { strURL = 'mikrotik_users.php?filter=' + $('#filter').val(); strURL += '&rows=' + $('#rows').val(); strURL += '&header=false'; loadPageNoHeader(strURL); } function clearFilter() { strURL = 'mikrotik_users.php?clear=1'; strURL += '&header=false'; loadPageNoHeader(strURL); } </script> <?php html_start_box('<strong>MikroTik Users</strong>', '100%', '', '3', 'center', ''); ?> <tr class='even'> <td> <form name='users' action='mikrotik_users.php'> <table class='filterTable'> <tr> <td> Search </td> <td> <input type='text' id='filter' size='25' value='<?php print htmlspecialchars(get_request_var_request('filter')); ?> '> </td> <td> Users </td> <td> <select id='rows' onChange='applyFilter()'> <option value='-1'<?php if (get_request_var_request('rows') == '-1') { ?> selected<?php } ?> >Default</option> <?php if (sizeof($item_rows) > 0) { foreach ($item_rows as $key => $value) { print "<option value='" . $key . "'"; if (get_request_var_request('rows') == $key) { print ' selected'; } print '>' . htmlspecialchars($value) . "</option>\n"; } } ?> </select> </td> <td> <input type='button' value='Go' title='Set/Refresh Filters' onClick='applyFilter()'> </td> <td> <input type='button' name='clear_x' value='Clear' title='Clear Filters' onClick='clearFilter()'> </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 = "WHERE (name LIKE '%%" . get_request_var_request('filter') . "%%') AND name!=''"; } else { $sql_where = "WHERE name!=''"; } /* print checkbox form for validation */ print "<form name='chk' method='post' action='mikrotik_users.php'>\n"; html_start_box('', '100%', '', '3', 'center', ''); $total_rows = db_fetch_cell("SELECT \n\t\tCOUNT(DISTINCT name)\n\t\tFROM plugin_mikrotik_users\n\t\t{$sql_where}"); $sortby = get_request_var_request('sort_column'); $sql_query = "SELECT name, domain, MAX(last_seen) AS last_seen, MAX(present) AS present\n\t\tFROM plugin_mikrotik_users\n\t\t{$sql_where}\n\t\tGROUP BY name, domain\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'); $users = db_fetch_assoc($sql_query); $nav = html_nav_bar('mikrotik_users.php?filter=' . get_request_var_request('filter'), MAX_DISPLAY_PAGES, get_request_var_request('page'), get_request_var_request('rows'), $total_rows, 5, 'Users', 'page', 'main'); print $nav; $display_text = array('name' => array('User Name', 'ASC'), 'domain' => array('Domain', 'ASC'), 'last_seen' => array('Last Seen', 'ASC'), 'present' => array('Active', 'ASC')); html_header_sort_checkbox($display_text, get_request_var_request('sort_column'), get_request_var_request('sort_direction'), false); $i = 0; if (sizeof($users) > 0) { foreach ($users as $user) { form_alternate_row_color($colors['alternate'], $colors['light'], $i, 'line' . $user['name']); $i++; form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars('user.php?action=edit&id=' . $user['id']) . "'>" . (strlen(get_request_var_request('filter')) ? eregi_replace('(' . preg_quote(get_request_var_request('filter')) . ')', "<span class='filteredValue'>\\1</span>", htmlspecialchars($user['name'])) : htmlspecialchars($user['name'])) . '</a>', $user['name'], 250); form_selectable_cell($user['domain'] != '' ? $user['domain'] : 'Not Set', $user['name']); form_selectable_cell($user['last_seen'], $user['name']); form_selectable_cell($user['present'] == 0 ? '<b><i>Inactive</i></b>' : '<b><i>Active</i></b>', $user['name']); form_checkbox_cell($user['name'], $user['name']); form_end_row(); } print $nav; } else { print '<tr><td><em>No Users Found</em></td></tr>'; } html_end_box(false); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($user_actions); print "</form>\n"; }
function template() { global $host_actions, $item_rows; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request('page')); input_validate_input_number(get_request_var_request('rows')); /* ==================================================== */ /* clean up has_hosts string */ if (isset($_REQUEST['has_hosts'])) { $_REQUEST['has_hosts'] = sanitize_search_string(get_request_var_request('has_hosts')); } /* 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 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_host_template_current_page'); kill_session_var('sess_host_template_hosts'); kill_session_var('sess_host_template_filter'); kill_session_var('sess_default_rows'); kill_session_var('sess_host_template_sort_column'); kill_session_var('sess_host_template_sort_direction'); unset($_REQUEST['page']); unset($_REQUEST['has_hosts']); unset($_REQUEST['filter']); unset($_REQUEST['rows']); unset($_REQUEST['sort_column']); unset($_REQUEST['sort_direction']); } else { $changed = 0; $changed += check_changed('has_hosts', 'sess_host_template_has_hosts'); $changed += check_changed('rows', 'sess_default_rows'); $changed += check_changed('filter', 'sess_host_template_filter'); if ($changed) { $_REQUEST['page'] = 1; } } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value('page', 'sess_host_template_current_page', '1'); load_current_session_value('has_hosts', 'sess_host_template_has_hosts', 'true'); load_current_session_value('filter', 'sess_host_template_filter', ''); load_current_session_value('sort_column', 'sess_host_template_sort_column', 'name'); load_current_session_value('sort_direction', 'sess_host_template_sort_direction', 'ASC'); load_current_session_value('rows', 'sess_default_rows', read_config_option('num_rows_table')); display_output_messages(); html_start_box('<strong>Device Templates</strong>', '100%', '', '3', 'center', 'host_templates.php?action=edit'); ?> <tr class='even noprint'> <td> <form id="form_host_template" action="host_templates.php"> <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 style='white-space:nowrap;'> Device Templates </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="checkbox" id='has_hosts' <?php print $_REQUEST['has_hosts'] == 'true' ? 'checked' : ''; ?> > </td> <td> <label for='has_hosts' style='white-space:nowrap;'>Has Devices</label> </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> <script type='text/javascript'> function applyFilter() { strURL = 'host_templates.php?filter='+$('#filter').val()+'&rows='+$('#rows').val()+'&page='+$('#page').val()+'&has_hosts='+$('#has_hosts').is(':checked')+'&header=false'; $.get(strURL, function(data) { $('#main').html(data); applySkin(); }); } function clearFilter() { strURL = 'host_templates.php?clear_x=1&header=false'; $.get(strURL, function(data) { $('#main').html(data); applySkin(); }); } $(function() { $('#refresh, #has_hosts').click(function() { applyFilter(); }); $('#clear').click(function() { clearFilter(); }); $('#form_host_template').submit(function(event) { event.preventDefault(); applyFilter(); }); }); </script> </tr> <?php html_end_box(); /* form the 'where' clause for our main sql query */ if (strlen($_REQUEST['filter'])) { $sql_where = "WHERE (host_template.name LIKE '%%" . get_request_var_request('filter') . "%%')"; } else { $sql_where = ''; } /* print checkbox form for validation */ print "<form name='chk' method='post' action='host_templates.php'>\n"; html_start_box('', '100%', '', '3', 'center', ''); if ($_REQUEST['has_hosts'] == 'true') { $sql_having = 'HAVING hosts>0'; } else { $sql_having = ''; } $total_rows = db_fetch_cell("SELECT COUNT(rows)\n\t\tFROM (\n\t\t\tSELECT\n\t\t\tCOUNT(host_template.id) AS rows, COUNT(DISTINCT host.id) AS hosts\n\t\t\tFROM host_template\n\t\t\tLEFT JOIN host ON host.host_template_id=host_template.id\n\t\t\t{$sql_where}\n\t\t\tGROUP BY host_template.id\n\t\t\t{$sql_having}\n\t\t) AS rs"); $template_list = db_fetch_assoc("SELECT\n\t\thost_template.id,host_template.name, COUNT(DISTINCT host.id) AS hosts\n\t\tFROM host_template\n\t\tLEFT JOIN host ON host.host_template_id=host_template.id\n\t\t{$sql_where}\n\t\tGROUP BY host_template.id\n\t\t{$sql_having}\n\t\tORDER BY " . get_request_var_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('host_templates.php?filter=' . get_request_var_request('filter'), MAX_DISPLAY_PAGES, get_request_var_request('page'), get_request_var_request('rows'), $total_rows, 5, 'Device Templates', 'page', 'main'); print $nav; $display_text = array('name' => array('display' => 'Device Template Name', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'The name of this Device Template.'), "nosort" => array('display' => 'Deletable', 'align' => 'right', 'sort' => '', 'tip' => 'Device Templates in use can not be Deleted. In use is defined as being referenced by a Device.'), 'hosts' => array('display' => 'Devices Using', 'align' => 'right', 'sort' => 'DESC', 'tip' => 'The number of Devices using this Device Template.'), 'host_template.id' => array('display' => 'ID', 'align' => 'right', 'sort' => 'ASC', 'tip' => 'The internal database ID for this Device Template. Useful when performing automation or debugging.')); html_header_sort_checkbox($display_text, get_request_var_request('sort_column'), get_request_var_request('sort_direction'), false); $i = 0; if (sizeof($template_list) > 0) { foreach ($template_list as $template) { if ($template['hosts'] > 0) { $disabled = true; } else { $disabled = false; } form_alternate_row('line' . $template['id'], true, $disabled); form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars('host_templates.php?action=edit&id=' . $template['id']) . "'>" . (strlen(get_request_var_request('filter')) ? preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", htmlspecialchars($template['name'])) : htmlspecialchars($template['name'])) . '</a>', $template['id']); form_selectable_cell($disabled ? 'No' : 'Yes', $template['id'], '', 'text-align:right'); form_selectable_cell(number_format($template['hosts']), $template['id'], '', 'text-align:right'); form_selectable_cell($template['id'], $template['id'], '', 'text-align:right'); form_checkbox_cell($template['name'], $template['id'], $disabled); form_end_row(); } /* put the nav bar on the bottom as well */ print $nav; } else { print "<tr class='tableRow'><td colspan='4'><em>No Device Templates</em></td></tr>\n"; } html_end_box(false); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($host_actions); print "</form>\n"; }
function mactrack_snmp() { global $config, $item_rows; global $mactrack_snmp_actions; /* ================= input validation and session storage ================= */ $filters = array('rows' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'page' => array('filter' => FILTER_VALIDATE_INT, 'default' => '1'), 'filter' => array('filter' => FILTER_CALLBACK, 'pageset' => true, 'default' => '', 'options' => array('options' => 'sanitize_search_string')), 'sort_column' => array('filter' => FILTER_CALLBACK, 'default' => 'name', 'options' => array('options' => 'sanitize_search_string')), 'sort_direction' => array('filter' => FILTER_CALLBACK, 'default' => 'ASC', 'options' => array('options' => 'sanitize_search_string'))); validate_store_request_vars($filters, 'sess_mactrack_snmp'); /* ================= input validation ================= */ if (get_request_var('rows') == '-1') { $rows = read_config_option('num_rows_table'); } else { $rows = get_request_var('rows'); } html_start_box(__('Mactrack SNMP Options'), '100%', '', '3', 'center', 'mactrack_snmp.php?action=edit'); snmp_options_filter(); html_end_box(); /* form the 'where' clause for our main sql query */ $sql_where = ''; if (get_request_var('filter') != '') { $sql_where .= "WHERE (mac_track_snmp.name LIKE '%" . get_request_var('filter') . "%')"; } $total_rows = db_fetch_cell("SELECT\n\t\tCOUNT(mac_track_snmp.id)\n\t\tFROM mac_track_snmp\n\t\t{$sql_where}"); $snmp_groups = db_fetch_assoc("SELECT *\n\t\tFROM mac_track_snmp\n\t\t{$sql_where}\n\t\tORDER BY " . get_request_var('sort_column') . ' ' . get_request_var('sort_direction') . ' LIMIT ' . $rows * (get_request_var('page') - 1) . ',' . $rows); $nav = html_nav_bar('mactrack_snmp.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 12, __('SNMP Settings')); print $nav; html_start_box('', '100%', '', '3', 'center', ''); $display_text = array('name' => array(__('Title of SNMP Option Set'), 'ASC')); html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction')); if (sizeof($snmp_groups)) { foreach ($snmp_groups as $snmp_group) { form_alternate_row('line' . $snmp_group['id'], true); form_selectable_cell(filter_value($snmp_group['name'], get_request_var('filter'), 'mactrack_snmp.php?action=edit&id=' . $snmp_group['id'] . '&page=1'), $snmp_group['id']); form_checkbox_cell($snmp_group['name'], $snmp_group['id']); form_end_row(); } } else { print '<tr><td colspan="3"><em>' . __('No SNMP Option Sets') . '</em></td></tr>'; } html_end_box(false); if (sizeof($snmp_groups)) { print $nav; } draw_actions_dropdown($mactrack_snmp_actions); form_end(); }
function template() { global $ds_actions; /* ================= input validation ================= */ 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_data_template_current_page"); kill_session_var("sess_data_template_filter"); kill_session_var("sess_data_template_sort_column"); kill_session_var("sess_data_template_sort_direction"); unset($_REQUEST["page"]); unset($_REQUEST["filter"]); unset($_REQUEST["sort_column"]); unset($_REQUEST["sort_direction"]); } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("page", "sess_data_template_current_page", "1"); load_current_session_value("filter", "sess_data_template_filter", ""); load_current_session_value("sort_column", "sess_data_template_sort_column", "name"); load_current_session_value("sort_direction", "sess_data_template_sort_direction", "ASC"); html_start_box("<strong>Data Templates</strong>", "100%", "", "3", "center", "data_templates.php?action=template_edit"); ?> <tr class='even noprint'> <td> <form name="form_data_template" action="data_templates.php"> <table width="100%" cellpadding="0" cellspacing="0"> <tr> <td nowrap style='white-space: nowrap;' width="50"> Search: </td> <td width="1"> <input type="text" name="filter" size="40" value="<?php print htmlspecialchars(get_request_var_request("filter")); ?> "> </td> <td nowrap style='white-space: nowrap;'> <input type="submit" value="Go" title="Set/Refresh Filters"> <input type="submit" name="clear_x" value="Clear" title="Clear Filters"> </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 */ $sql_where = "WHERE data_template.id=data_template_data.data_template_id AND data_template_data.local_data_id=0"; $rows_where = ""; if (strlen($_REQUEST['filter'])) { $sql_where .= " AND (data_template.name like '%%" . get_request_var_request("filter") . "%%')"; $rows_where = "WHERE (data_template.name like '%%" . get_request_var_request("filter") . "%%')"; } /* print checkbox form for validation */ print "<form name='chk' method='post' action='data_templates.php'>\n"; html_start_box("", "100%", "", "3", "center", ""); $total_rows = db_fetch_cell("SELECT\n\t\tCOUNT(data_template.id)\n\t\tFROM data_template\n\t\t{$rows_where}"); $template_list = db_fetch_assoc("SELECT\n\t\tdata_template.id,\n\t\tdata_template.name,\n\t\tdata_input.name AS data_input_method,\n\t\tdata_template_data.active AS active\n\t\tFROM (data_template,data_template_data)\n\t\tLEFT JOIN data_input\n\t\tON (data_template_data.data_input_id = data_input.id)\n\t\t{$sql_where}\n\t\tGROUP BY data_template.id\n\t\tORDER BY " . get_request_var_request("sort_column") . " " . get_request_var_request("sort_direction") . " LIMIT " . read_config_option("num_rows_device") * (get_request_var_request("page") - 1) . "," . read_config_option("num_rows_device")); $nav = html_nav_bar("data_templates.php?filter=" . get_request_var_request("filter"), MAX_DISPLAY_PAGES, get_request_var_request("page"), read_config_option("num_rows_device"), $total_rows, 5); print $nav; $display_text = array("name" => array("Template Name", "ASC"), "id" => array("ID", "ASC"), "data_input_method" => array("Data Input Method", "ASC"), "active" => array("Status", "ASC")); html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction"), false); if (sizeof($template_list) > 0) { foreach ($template_list as $template) { form_alternate_row('line' . $template["id"], true); form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars("data_templates.php?action=template_edit&id=" . $template["id"]) . "'>" . (strlen(get_request_var_request("filter")) ? preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", htmlspecialchars($template["name"])) : htmlspecialchars($template["name"])) . "</a>", $template["id"]); form_selectable_cell($template['id'], $template["id"]); form_selectable_cell(empty($template["data_input_method"]) ? "<em>None</em>" : htmlspecialchars($template["data_input_method"]), $template["id"]); form_selectable_cell($template["active"] == "on" ? "Active" : "Disabled", $template["id"]); form_checkbox_cell($template["name"], $template["id"]); form_end_row(); } /* put the nav bar on the bottom as well */ print $nav; } else { print "<tr><td><em>No Data Templates</em></td></tr>\n"; } html_end_box(false); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($ds_actions); print "</form>\n"; }
function graphs() { /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("host_id")); input_validate_input_number(get_request_var_request("graph_type")); /* ==================================================== */ /* 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_graphs_new_filter"); unset($_REQUEST["filter"]); $changed = true; } else { /* if any of the settings changed, reset the page number */ $changed = false; $changed += check_changed("host_id", "sess_graphs_new_host_id"); $changed += check_changed("graph_type", "sess_graphs_new_graph_type"); $changed += check_changed("filter", "sess_graphs_new_filter"); } load_current_session_value("host_id", "sess_graphs_new_host_id", db_fetch_cell("select id from host order by description,hostname limit 1")); load_current_session_value("graph_type", "sess_graphs_new_graph_type", read_config_option("default_graphs_new_dropdown")); load_current_session_value("filter", "sess_graphs_new_filter", ""); $host = db_fetch_row("select id,description,hostname,host_template_id from host where id=" . $_REQUEST["host_id"]); $row_limit = read_config_option("num_rows_data_query"); $debug_log = debug_log_return("new_graphs"); $header = " [ " . htmlspecialchars($host["description"]) . " (" . htmlspecialchars($host["hostname"]) . ") " . (!empty($host["host_template_id"]) ? htmlspecialchars(db_fetch_cell("select name from host_template where id=" . $host["host_template_id"])) : '') . " ]"; html_start_box("<strong>New Graphs for</strong> {$header}", "100%", "", "3", "center", ""); form_alternate_row(); print "<td>"; if (!empty($debug_log)) { debug_log_clear("new_graphs"); if (read_config_option("cacti_popup_messages") == "on") { ?> <div id='message'> <?php print "<table align='center' class='cactiTable' width='100%'><tr><td style='align:center;padding:3px;font-weight:bold;font-size:10pt;text-align:center;'>Graphs Created</td><td style='width:1px;align:right;'><input type='button' value='Clear' onClick='javascript:document.getElementById(\"message\").style.display=\"none\"' style='align=right;'></td></tr></table>"; ?> <?php print "<table align='left' style='width:100%;'><tr><td><ul style='text-align:left;white-space:nowrap;color:#000000;padding:2px 10px;margin:10px;'>" . $debug_log . "</ul></td></tr></table>"; ?> </div> <?php } else { ?> <table width='100%' class='textArea' align='center'> <tr class='even'> <td style="padding: 3px; font-family: monospace;"> <ul style='margin:0px 5px;padding-left:10px'><?php print $debug_log; ?> </ul> </td> </tr> </table> <br><?php } } ?> <script type="text/javascript"> <!-- <?php if (read_config_option("cacti_popup_messages") == "on") { ?> var obj = document.getElementById('message'); if (obj) { if (window.innerHeight) { height = window.innerHeight; width = window.innerWidth; }else{ height = document.body.clientHeight; width = document.body.clientWidth; } obj.style.class = "popupBox"; cw = obj.offsetWidth; // Adjust for IE6 if (!cw) cw = 150; ch = obj.offsetHeight; obj.style.top = '65px'; obj.style.left = ((width/2) - (cw/2) - 88)+'px'; } <?php } ?> function applyGraphsNewFilterChange(objForm) { strURL = '?graph_type=' + objForm.graph_type.value; strURL = strURL + '&host_id=' + objForm.host_id.value; strURL = strURL + '&filter=' + objForm.filter.value;; document.location = strURL; } --> </script> <form name="form_graphs_new" action="graphs_new.php"> <table width="100%" class="textHeader" cellpadding="2" align="left"> <tr> <td width="55" valign='top'> Host: </td> <td width="1" valign='top'> <select name="host_id" onChange="applyGraphsNewFilterChange(document.form_graphs_new)"> <?php $hosts = db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"); if (sizeof($hosts) > 0) { foreach ($hosts as $item) { print "<option value='" . $item["id"] . "'"; if ($_REQUEST["host_id"] == $item["id"]) { print " selected"; } print ">" . htmlspecialchars($item["name"]) . "</option>\n"; } } ?> </select> </td> <td style='white-space:nowrap;' valign='top' width="100"> Graph Types: </td> <td width="1" valign='top'> <select name="graph_type" onChange="applyGraphsNewFilterChange(document.form_graphs_new)"> <option value="-2"<?php if ($_REQUEST["graph_type"] == "-2") { ?> selected<?php } ?> >All</option> <option value="-1"<?php if ($_REQUEST["graph_type"] == "-1") { ?> selected<?php } ?> >Graph Template Based</option> <?php $snmp_queries = db_fetch_assoc("SELECT\n\t\t\t\t\tsnmp_query.id,\n\t\t\t\t\tsnmp_query.name,\n\t\t\t\t\tsnmp_query.xml_path\n\t\t\t\t\tFROM (snmp_query,host_snmp_query)\n\t\t\t\t\tWHERE host_snmp_query.snmp_query_id=snmp_query.id\n\t\t\t\t\tAND host_snmp_query.host_id=" . $host["id"] . "\n\t\t\t\t\tORDER BY snmp_query.name"); if (sizeof($snmp_queries) > 0) { foreach ($snmp_queries as $query) { print "<option value='" . $query["id"] . "'"; if ($_REQUEST["graph_type"] == $query["id"]) { print " selected"; } print ">" . $query["name"] . "</option>\n"; } } ?> </select> </td> <td rowspan="2" class="textInfo" align="right" valign="top"> <span class="linkMarker">*</span><a href="<?php print htmlspecialchars("host.php?action=edit&id=" . $_REQUEST["host_id"]); ?> ">Edit this Host</a><br> <span class="linkMarker">*</span><a href="<?php print htmlspecialchars("host.php?action=edit"); ?> ">Create New Host</a><br> <?php api_plugin_hook('graphs_new_top_links'); ?> </td> </tr> <?php if ($_REQUEST["graph_type"] > 0) { ?> <tr> <td width="55" valign='top'> Search: </td> <td valign='top'> <input type="text" name="filter" size="30" value="<?php print htmlspecialchars(get_request_var_request("filter")); ?> "> </td> <td colspan='2' valign='top'> <input type="submit" value="Go" title="Set/Refresh Filters"> <input type="submit" name="clear_x" value="Clear" title="Clear Filters"> </td> </tr> <?php } else { form_hidden_box("filter", $_REQUEST["filter"], ""); } ?> </table> </form> </td> </tr> <?php html_end_box(); ?> <form name="chk" method="post" action="graphs_new.php"> <?php $total_rows = sizeof(db_fetch_assoc("select graph_template_id from host_graph where host_id=" . $_REQUEST["host_id"])); $i = 0; if ($changed) { foreach ($snmp_queries as $query) { kill_session_var("sess_graphs_new_page" . $query["id"]); unset($_REQUEST["page" . $query["id"]]); load_current_session_value("page" . $query["id"], "sess_graphs_new_page" . $query["id"], "1"); } } if ($_REQUEST["graph_type"] > 0) { load_current_session_value("page" . $_REQUEST["graph_type"], "sess_graphs_new_page" . $_REQUEST["graph_type"], "1"); } else { if ($_REQUEST["graph_type"] == -2) { foreach ($snmp_queries as $query) { load_current_session_value("page" . $query["id"], "sess_graphs_new_page" . $query["id"], "1"); } } } $script = "<script type='text/javascript'>\nvar gt_created_graphs = new Array();\nvar created_graphs = new Array()\n"; if ($_REQUEST["graph_type"] < 0) { html_start_box("<strong>Graph Templates</strong>", "100%", "", "3", "center", ""); print "<tr class='tableHeader'>\n\t\t\t\t<td class='tableSubHeaderColumn'>Graph Template Name</td>\n\t\t\t\t<td width='1%' align='center' class='tableSubHeaderCheckbox' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_cg' title='Select All' onClick='SelectAll(\"cg\",this.checked);gt_update_selection_indicators();'></td>\n\n\t\t\t</tr>\n"; $graph_templates = db_fetch_assoc("SELECT\n\t\t\tgraph_templates.id AS graph_template_id,\n\t\t\tgraph_templates.name AS graph_template_name\n\t\t\tFROM (host_graph,graph_templates)\n\t\t\tWHERE host_graph.graph_template_id=graph_templates.id\n\t\t\tAND host_graph.host_id=" . $_REQUEST["host_id"] . "\n\t\t\tORDER BY graph_templates.name"); $template_graphs = db_fetch_assoc("SELECT\n\t\t\tgraph_local.graph_template_id\n\t\t\tFROM (graph_local,host_graph)\n\t\t\tWHERE graph_local.graph_template_id=host_graph.graph_template_id\n\t\t\tAND graph_local.host_id=host_graph.host_id\n\t\t\tAND graph_local.host_id=" . $host["id"] . "\n\t\t\tGROUP BY graph_local.graph_template_id"); if (sizeof($template_graphs) > 0) { $script .= "var gt_created_graphs = new Array("; $cg_ctr = 0; foreach ($template_graphs as $template_graph) { $script .= ($cg_ctr > 0 ? "," : "") . "'" . $template_graph["graph_template_id"] . "'"; $cg_ctr++; } $script .= ")\n"; } /* create a row for each graph template associated with the host template */ if (sizeof($graph_templates) > 0) { foreach ($graph_templates as $graph_template) { $query_row = $graph_template["graph_template_id"]; print "<tr id='gt_line{$query_row}' class='" . ($i % 2 == 0 ? "odd" : "even") . "'>"; $i++; print "\t\t<td onClick='gt_select_line(" . $graph_template["graph_template_id"] . ");'>\n\t\t\t\t\t\t<span id='gt_text{$query_row}" . "_0'><strong>Create:</strong> " . htmlspecialchars($graph_template["graph_template_name"]) . "</span>\n\t\t\t\t\t</td>\n\t\t\t\t\t<td align='right'>\n\t\t\t\t\t\t<input type='checkbox' name='cg_{$query_row}' id='cg_{$query_row}' onClick='gt_update_selection_indicators();'>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>"; } } $script .= "gt_update_deps(1);\n"; $available_graph_templates = db_fetch_assoc("SELECT\n\t\t\tgraph_templates.id, graph_templates.name\n\t\t\tFROM snmp_query_graph RIGHT JOIN graph_templates\n\t\t\tON (snmp_query_graph.graph_template_id = graph_templates.id)\n\t\t\tWHERE (((snmp_query_graph.name) Is Null)) ORDER BY graph_templates.name"); /* create a row at the bottom that lets the user create any graph they choose */ print "\t<tr class='" . ($i % 2 == 0 ? "odd" : "even") . "'>\n\t\t\t\t<td colspan='2' width='60' nowrap>\n\t\t\t\t\t<strong>Create:</strong> "; form_dropdown("cg_g", $available_graph_templates, "name", "id", "", "(Select a graph type to create)", "", "textArea"); print "\t\t</td>\n\t\t\t</tr>"; html_end_box(); } if ($_REQUEST["graph_type"] != -1) { $snmp_queries = db_fetch_assoc("SELECT\n\t\t\tsnmp_query.id,\n\t\t\tsnmp_query.name,\n\t\t\tsnmp_query.xml_path\n\t\t\tFROM (snmp_query,host_snmp_query)\n\t\t\tWHERE host_snmp_query.snmp_query_id=snmp_query.id\n\t\t\tAND host_snmp_query.host_id=" . $host["id"] . ($_REQUEST["graph_type"] != -2 ? " AND snmp_query.id=" . $_REQUEST["graph_type"] : '') . "\n\t\t\tORDER BY snmp_query.name"); if (sizeof($snmp_queries) > 0) { foreach ($snmp_queries as $snmp_query) { unset($total_rows); if (!$changed) { $page = $_REQUEST["page" . $snmp_query["id"]]; } else { $page = 1; } $xml_array = get_data_query_array($snmp_query["id"]); $num_input_fields = 0; $num_visible_fields = 0; if ($xml_array != false) { /* loop through once so we can find out how many input fields there are */ reset($xml_array["fields"]); while (list($field_name, $field_array) = each($xml_array["fields"])) { if ($field_array["direction"] == "input") { $num_input_fields++; if (!isset($total_rows)) { $total_rows = db_fetch_cell("SELECT count(*) FROM host_snmp_cache WHERE host_id=" . $host["id"] . " and snmp_query_id=" . $snmp_query["id"] . " AND field_name='{$field_name}'"); } } } } if (!isset($total_rows)) { $total_rows = 0; } $snmp_query_graphs = db_fetch_assoc("SELECT snmp_query_graph.id,snmp_query_graph.name FROM snmp_query_graph WHERE snmp_query_graph.snmp_query_id=" . $snmp_query["id"] . " ORDER BY snmp_query_graph.name"); if (sizeof($snmp_query_graphs) > 0) { foreach ($snmp_query_graphs as $snmp_query_graph) { $created_graphs = db_fetch_assoc("SELECT DISTINCT\n\t\t\t\t\t\tdata_local.snmp_index\n\t\t\t\t\t\tFROM (data_local,data_template_data)\n\t\t\t\t\t\tLEFT JOIN data_input_data ON (data_template_data.id=data_input_data.data_template_data_id)\n\t\t\t\t\t\tLEFT JOIN data_input_fields ON (data_input_data.data_input_field_id=data_input_fields.id)\n\t\t\t\t\t\tWHERE data_local.id=data_template_data.local_data_id\n\t\t\t\t\t\tAND data_input_fields.type_code='output_type'\n\t\t\t\t\t\tAND data_input_data.value='" . $snmp_query_graph["id"] . "'\n\t\t\t\t\t\tAND data_local.host_id=" . $host["id"]); $script .= "created_graphs[" . $snmp_query_graph["id"] . "] = new Array("; $cg_ctr = 0; if (sizeof($created_graphs) > 0) { foreach ($created_graphs as $created_graph) { $script .= ($cg_ctr > 0 ? "," : "") . "'" . encode_data_query_index($created_graph["snmp_index"]) . "'"; $cg_ctr++; } } $script .= ")\n"; } } print "\t<table width='100%' class='cactiTable' align='center' cellpadding='3' cellspacing='0'>\n\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td colspan='" . ($num_input_fields + 1) . "'>\n\t\t\t\t\t\t\t<table cellspacing='0' cellpadding='0' width='100%' >\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td class='textHeaderDark'>\n\t\t\t\t\t\t\t\t\t\t<strong>Data Query</strong> [" . $snmp_query["name"] . "]\n\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t<td align='right' nowrap>\n\t\t\t\t\t\t\t\t\t\t<a href='" . htmlspecialchars("graphs_new.php?action=query_reload&id=" . $snmp_query["id"] . "&host_id=" . $host["id"]) . "'><img src='images/reload_icon_small.gif' title='Reload Associated Query' alt='' border='0' align='middle'></a>\n\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>"; if ($xml_array != false) { $html_dq_header = ""; $snmp_query_indexes = array(); reset($xml_array["fields"]); /* if there is a where clause, get the matching snmp_indexes */ $sql_where = ""; if (strlen($_REQUEST["filter"])) { $sql_where = ""; $indexes = db_fetch_assoc("SELECT DISTINCT snmp_index\n\t\t\t\t\t\tFROM host_snmp_cache\n\t\t\t\t\t\tWHERE field_value LIKE '%%" . $_REQUEST["filter"] . "%%'\n\t\t\t\t\t\tAND snmp_query_id=" . $snmp_query["id"] . "\n\t\t\t\t\t\tAND host_id=" . $host["id"]); if (sizeof($indexes)) { foreach ($indexes as $index) { if (strlen($sql_where)) { $sql_where .= ", '" . $index["snmp_index"] . "'"; } else { $sql_where .= " AND snmp_index IN('" . $index["snmp_index"] . "'"; } } $sql_where .= ")"; } } if (strlen($_REQUEST["filter"]) == 0 || strlen($_REQUEST["filter"]) && sizeof($indexes)) { /* determine the sort order */ if (isset($xml_array["index_order_type"])) { if ($xml_array["index_order_type"] == "numeric") { $sql_order = "ORDER BY CAST(snmp_index AS unsigned)"; } else { if ($xml_array["index_order_type"] == "alphabetic") { $sql_order = "ORDER BY snmp_index"; } else { if ($xml_array["index_order_type"] == "natural") { $sql_order = "ORDER BY INET_ATON(snmp_index)"; } else { $sql_order = ""; } } } } else { $sql_order = ""; } /* get the unique field values from the database */ $field_names = db_fetch_assoc("SELECT DISTINCT field_name\n\t\t\t\t\t\tFROM host_snmp_cache\n\t\t\t\t\t\tWHERE host_id=" . $host["id"] . "\n\t\t\t\t\t\tAND snmp_query_id=" . $snmp_query["id"]); /* build magic query */ $sql_query = "SELECT host_id, snmp_query_id, snmp_index"; $num_visible_fields = sizeof($field_names); $i = 0; if (sizeof($field_names) > 0) { foreach ($field_names as $column) { $field_name = $column["field_name"]; $sql_query .= ", MAX(CASE WHEN field_name='{$field_name}' THEN field_value ELSE NULL END) AS '{$field_name}'"; $i++; } } $sql_query .= " FROM host_snmp_cache\n\t\t\t\t\t\tWHERE host_id=" . $host["id"] . "\n\t\t\t\t\t\tAND snmp_query_id=" . $snmp_query["id"] . "\n\t\t\t\t\t\t{$sql_where}\n\t\t\t\t\t\tGROUP BY host_id, snmp_query_id, snmp_index\n\t\t\t\t\t\t{$sql_order}\n\t\t\t\t\t\tLIMIT " . $row_limit * ($page - 1) . "," . $row_limit; $rows_query = "SELECT host_id, snmp_query_id, snmp_index\n\t\t\t\t\t\tFROM host_snmp_cache\n\t\t\t\t\t\tWHERE host_id=" . $host["id"] . "\n\t\t\t\t\t\tAND snmp_query_id=" . $snmp_query["id"] . "\n\t\t\t\t\t\t{$sql_where}\n\t\t\t\t\t\tGROUP BY host_id, snmp_query_id, snmp_index"; $snmp_query_indexes = db_fetch_assoc($sql_query); $total_rows = sizeof(db_fetch_assoc($rows_query)); if (($page - 1) * $row_limit > $total_rows) { $page = 1; $_REQUEST["page" . $query["id"]] = $page; load_current_session_value("page" . $query["id"], "sess_graphs_new_page" . $query["id"], "1"); } $nav = html_nav_bar("graphs_new.php", MAX_DISPLAY_PAGES, $page, $row_limit, $total_rows, 15, "Items", "page" . $snmp_query["id"]); print $nav; while (list($field_name, $field_array) = each($xml_array["fields"])) { if ($field_array["direction"] == "input") { foreach ($field_names as $row) { if ($row["field_name"] == $field_name) { $html_dq_header .= "<td class='tableSubHeaderColumn'>" . $field_array["name"] . "</td>\n"; break; } } } } if (!sizeof($snmp_query_indexes)) { print "<tr class='odd'><td>This data query returned 0 rows, perhaps there was a problem executing this\n\t\t\t\t\t\t\tdata query. You can <a href='" . htmlspecialchars("host.php?action=query_verbose&id=" . $snmp_query["id"] . "&host_id=" . $host["id"]) . "'>run this data\n\t\t\t\t\t\t\tquery in debug mode</a> to get more information.</td></tr>\n"; } else { print "<tr class='tableHeader'>\n\t\t\t\t\t\t\t\t{$html_dq_header}\n\t\t\t\t\t\t\t\t<td width='1%' align='center' class='tableSubHeaderCheckbox' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_" . $snmp_query["id"] . "' title='Select All' onClick='SelectAll(\"sg_" . $snmp_query["id"] . "\",this.checked);dq_update_selection_indicators();'></td>\n\n\t\t\t\t\t\t\t</tr>\n"; } $row_counter = 0; $column_counter = 0; $fields = array_rekey($field_names, "field_name", "field_name"); if (sizeof($snmp_query_indexes) > 0) { foreach ($snmp_query_indexes as $row) { $query_row = $snmp_query["id"] . "_" . encode_data_query_index($row["snmp_index"]); print "<tr id='line{$query_row}' class='" . ($row_counter % 2 == 0 ? "odd" : "even") . "'>"; $i++; $column_counter = 0; reset($xml_array["fields"]); while (list($field_name, $field_array) = each($xml_array["fields"])) { if ($field_array["direction"] == "input") { if (in_array($field_name, $fields)) { if (isset($row[$field_name])) { print "<td onClick='dq_select_line(" . $snmp_query["id"] . ",\"" . encode_data_query_index($row["snmp_index"]) . "\");'><span id='text{$query_row}" . "_" . $column_counter . "'>" . (strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $row[$field_name]) : $row[$field_name]) . "</span></td>"; } else { print "<td onClick='dq_select_line(" . $snmp_query["id"] . ",\"" . encode_data_query_index($row["snmp_index"]) . "\");'><span id='text{$query_row}" . "_" . $column_counter . "'></span></td>"; } $column_counter++; } } } print "<td align='right'>"; print "<input type='checkbox' name='sg_{$query_row}' id='sg_{$query_row}' onClick='dq_update_selection_indicators();'>"; print "</td>"; print "</tr>\n"; $row_counter++; } } if ($total_rows > $row_limit) { print $nav; } } else { print "<tr class='odd'><td colspan='2' style='color: red; font-size: 12px; font-weight: bold;'>Search Returned no Rows.</td></tr>\n"; } } else { print "<tr class='odd'><td colspan='2' style='color: red; font-size: 12px; font-weight: bold;'>Error in data query.</td></tr>\n"; } print "</table>"; /* draw the graph template drop down here */ $data_query_graphs = db_fetch_assoc("select snmp_query_graph.id,snmp_query_graph.name from snmp_query_graph where snmp_query_graph.snmp_query_id=" . $snmp_query["id"] . " order by snmp_query_graph.name"); if (sizeof($data_query_graphs) == 1) { echo "<input type='hidden' id='sgg_" . $snmp_query["id"] . "' name='sgg_" . $snmp_query["id"] . "' value='" . $data_query_graphs[0]["id"] . "'>\n"; } elseif (sizeof($data_query_graphs) > 1) { print "\t<table align='center' width='100%'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td width='1' valign='top'>\n\t\t\t\t\t\t\t\t<img src='images/arrow.gif' alt=''> \n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td align='right'>\n\t\t\t\t\t\t\t\t<span style='font-size: 12px; font-style: italic;'>Select a graph type:</span> \n\t\t\t\t\t\t\t\t<select name='sgg_" . $snmp_query["id"] . "' id='sgg_" . $snmp_query["id"] . "' onChange='dq_update_deps(" . $snmp_query["id"] . "," . (isset($column_counter) ? $column_counter : "") . ");'>\n\t\t\t\t\t\t\t\t\t"; html_create_list($data_query_graphs, "name", "id", "0"); print "\n\t\t\t\t\t\t\t\t</select>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>"; } print "<br>"; $script .= "dq_update_deps(" . $snmp_query["id"] . "," . $num_visible_fields . ");\n"; } } } if (strlen($script)) { $script .= "</script>\n"; print $script; } form_hidden_box("save_component_graph", "1", ""); form_hidden_box("host_id", $host["id"], "0"); form_hidden_box("host_template_id", $host["host_template_id"], "0"); if (isset($_SERVER["HTTP_REFERER"]) && !substr_count($_SERVER["HTTP_REFERER"], "graphs_new")) { $_REQUEST["returnto"] = basename($_SERVER["HTTP_REFERER"]); } load_current_session_value("returnto", "sess_graphs_new_returnto", ""); form_save_button($_REQUEST["returnto"]); print "<script type='text/javascript'>dq_update_selection_indicators();</script>\n"; print "<script type='text/javascript'>gt_update_selection_indicators();</script>\n"; }
function utilities_view_poller_cache() { global $poller_actions; define("MAX_DISPLAY_PAGES", 21); /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("host_id")); input_validate_input_number(get_request_var_request("page")); input_validate_input_number(get_request_var_request("poller_action")); /* ==================================================== */ /* clean up search filter */ 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 sort direction */ 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_poller_current_page"); kill_session_var("sess_poller_host_id"); kill_session_var("sess_poller_poller_action"); kill_session_var("sess_poller_filter"); unset($_REQUEST["page"]); unset($_REQUEST["filter"]); unset($_REQUEST["host_id"]); unset($_REQUEST["poller_action"]); } if (!empty($_SESSION["sess_poller_action"]) && !empty($_REQUEST["poller_action"])) { if ($_SESSION["sess_poller_poller_action"] != $_REQUEST["poller_action"]) { $_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_poller_current_page", "1"); load_current_session_value("host_id", "sess_poller_host_id", "-1"); load_current_session_value("poller_action", "sess_poller_poller_action", "-1"); load_current_session_value("filter", "sess_poller_filter", ""); load_current_session_value("sort_column", "sess_poller_sort_column", "data_template_data.name_cache"); load_current_session_value("sort_direction", "sess_poller_sort_direction", "ASC"); $_REQUEST['page_referrer'] = 'view_poller_cache'; load_current_session_value('page_referrer', 'page_referrer', 'view_poller_cache'); ?> <script type="text/javascript"> <!-- function applyPItemFilterChange(objForm) { strURL = '?poller_action=' + objForm.poller_action.value; strURL = strURL + '&host_id=' + objForm.host_id.value; strURL = strURL + '&filter=' + objForm.filter.value; strURL = strURL + '&action=view_poller_cache'; document.location = strURL; } --> </script> <?php html_start_box("<strong>Poller Cache Items</strong>", "100%", "", "3", "center", ""); ?> <tr class='even noprint'> <td> <form name="form_pollercache" action="utilities.php"> <table cellpadding="0" cellspacing="0"> <tr> <td nowrap style='white-space: nowrap;' width="50"> Host: </td> <td width="1"> <select name="host_id" onChange="applyPItemFilterChange(document.form_pollercache)"> <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 $hosts = db_fetch_assoc("select id,description,hostname from host order by description"); 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 ">" . $host["description"] . "</option>\n"; } } ?> </select> </td> <td nowrap style='white-space: nowrap;' width="50"> Action: </td> <td width="1"> <select name="poller_action" onChange="applyPItemFilterChange(document.form_pollercache)"> <option value="-1"<?php if (get_request_var_request("poller_action") == '-1') { ?> selected<?php } ?> >Any</option> <option value="0"<?php if (get_request_var_request("poller_action") == '0') { ?> selected<?php } ?> >SNMP</option> <option value="1"<?php if (get_request_var_request("poller_action") == '1') { ?> selected<?php } ?> >Script</option> <option value="2"<?php if (get_request_var_request("poller_action") == '2') { ?> selected<?php } ?> >Script Server</option> </select> </td> <td nowrap style='white-space: nowrap;' width="50"> Search: </td> <td width="1"> <input type="text" name="filter" size="40" value="<?php print htmlspecialchars(get_request_var_request("filter")); ?> "> </td> <td nowrap style='white-space: nowrap;'> <input type="submit" name="go" value="Go" title="Set/Refresh Filters"> <input type="submit" name="clear_x" value="Clear" title="Clear Filters"> </td> </tr> </table> <input type='hidden' name='page' value='1'> <input type='hidden' name='action' value='view_poller_cache'> </form> </td> </tr> <?php html_end_box(); /* form the 'where' clause for our main sql query */ $sql_where = "WHERE poller_item.local_data_id=data_template_data.local_data_id"; if (get_request_var_request("poller_action") != "-1") { $sql_where .= " AND poller_item.action='" . get_request_var_request("poller_action") . "'"; } if (get_request_var_request("host_id") == "-1") { /* Show all items */ } elseif (get_request_var_request("host_id") == "0") { $sql_where .= " AND poller_item.host_id=0"; } elseif (!empty($_REQUEST["host_id"])) { $sql_where .= " AND poller_item.host_id=" . get_request_var_request("host_id"); } if (strlen(get_request_var_request("filter"))) { $sql_where .= " AND (data_template_data.name_cache LIKE '%%" . get_request_var_request("filter") . "%%'\n\t\t\tOR host.description LIKE '%%" . get_request_var_request("filter") . "%%'\n\t\t\tOR poller_item.arg1 LIKE '%%" . get_request_var_request("filter") . "%%'\n\t\t\tOR poller_item.hostname LIKE '%%" . get_request_var_request("filter") . "%%'\n\t\t\tOR poller_item.rrd_path LIKE '%%" . get_request_var_request("filter") . "%%')"; } html_start_box("", "100%", "", "3", "center", ""); $total_rows = db_fetch_cell("SELECT\n\t\tCOUNT(*)\n\t\tFROM data_template_data\n\t\tRIGHT JOIN (poller_item\n\t\tLEFT JOIN host\n\t\tON poller_item.host_id=host.id)\n\t\tON data_template_data.local_data_id=poller_item.local_data_id\n\t\t{$sql_where}"); $poller_sql = "SELECT\n\t\tpoller_item.*,\n\t\tdata_template_data.name_cache,\n\t\thost.description\n\t\tFROM data_template_data\n\t\tRIGHT JOIN (poller_item\n\t\tLEFT JOIN host\n\t\tON poller_item.host_id=host.id)\n\t\tON data_template_data.local_data_id=poller_item.local_data_id\n\t\t{$sql_where}\n\t\tORDER BY " . get_request_var_request("sort_column") . " " . get_request_var_request("sort_direction") . ", action ASC\n\t\tLIMIT " . read_config_option("num_rows_data_source") * (get_request_var_request("page") - 1) . "," . read_config_option("num_rows_data_source"); $poller_cache = db_fetch_assoc($poller_sql); $nav = html_nav_bar("utilities.php?action=view_poller_cache&host_id=" . get_request_var_request("host_id") . "&poller_action=" . get_request_var_request("poller_action"), MAX_DISPLAY_PAGES, get_request_var_request("page"), read_config_option("num_rows_data_source"), $total_rows, 3); print $nav; $display_text = array("data_template_data.name_cache" => array("Data Source Name", "ASC"), "nosort" => array("Details", "ASC")); html_header_sort($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction")); $i = 0; if (sizeof($poller_cache) > 0) { foreach ($poller_cache as $item) { form_alternate_row(); ?> <td width="375"> <a class="linkEditMain" href="<?php print htmlspecialchars("data_sources.php?action=ds_edit&id=" . $item["local_data_id"]); ?> "><?php print strlen(get_request_var_request("filter")) ? preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $item["name_cache"]) : $item["name_cache"]; ?> </a> </td> <td> <?php if ($item["action"] == 0) { if ($item["snmp_version"] != 3) { $details = "SNMP Version: " . $item["snmp_version"] . ", " . "Community: " . $item["snmp_community"] . ", " . "OID: " . (strlen(get_request_var_request("filter")) ? preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $item["arg1"]) : $item["arg1"]); } else { $details = "SNMP Version: " . $item["snmp_version"] . ", " . "User: "******"snmp_username"] . ", OID: " . $item["arg1"]; } } elseif ($item["action"] == 1) { $details = "Script: " . (strlen(get_request_var_request("filter")) ? preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $item["arg1"]) : $item["arg1"]); } else { $details = "Script Server: " . (strlen(get_request_var_request("filter")) ? preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $item["arg1"]) : $item["arg1"]); } print $details; ?> </td> </tr> <?php form_alternate_row(); ?> <td> </td> <td> RRD: <?php print $item["rrd_path"]; ?> </td> </tr> <?php $i++; } } print $nav; html_end_box(); }
function mactrack_view_aggregated_macs() { global $title, $report, $mactrack_search_types, $rows_selector, $config; global $mactrack_view_agg_macs_actions, $item_rows; mactrack_tabs(); html_start_box($title, '100%', '', '3', 'center', ''); mactrack_mac_filter(); html_end_box(); $sql_where = ''; if (get_request_var('rows') == -1) { $row_limit = read_config_option('num_rows_table'); } elseif (get_request_var('rows') == -2) { $row_limit = 999999; } else { $row_limit = get_request_var('rows'); } $port_results = mactrack_view_get_mac_records($sql_where, TRUE, $row_limit); /* prevent table scans, either a device or site must be selected */ if (get_request_var('site_id') == -1 && get_request_var('device_id') == -1) { $total_rows = 0; } else { $rows_query_string = 'SELECT COUNT(*) FROM mac_track_aggregated_ports LEFT JOIN mac_track_sites ON (mac_track_aggregated_ports.site_id=mac_track_sites.site_id) LEFT JOIN mac_track_oui_database ON (mac_track_oui_database.vendor_mac=mac_track_aggregated_ports.vendor_mac) ' . str_replace('mac_track_ports', 'mac_track_aggregated_ports', $sql_where); $total_rows = db_fetch_cell($rows_query_string); } $nav = html_nav_bar('mactrack_view_macs.php?report=macs&scan_date=3', MAX_DISPLAY_PAGES, get_request_var('page'), $row_limit, $total_rows, 12, 'MAC Addresses'); print $nav; html_start_box('', '100%', '', '3', 'center', ''); $display_text = array('device_name' => array(__('Switch Name'), 'ASC'), 'hostname' => array(__('Switch Hostname'), 'ASC'), 'ip_address' => array(__('ED IP Address'), 'ASC')); if (strlen(read_config_option('mt_reverse_dns')) > 0) { $display_text['dns_hostname'] = array('ED DNS Hostname', 'ASC'); } $display_text = array_merge($display_text, array('mac_address' => array(__('ED MAC Address'), 'ASC'), 'vendor_name' => array(__('Vendor Name'), 'ASC'), 'port_number' => array(__('Port Number'), 'DESC'), 'port_name' => array(__('Port Name'), 'ASC'), 'vlan_id' => array(__('VLAN ID'), 'DESC'), 'vlan_name' => array(__('VLAN Name'), 'ASC'))); if (get_request_var('rows') == 1) { $display_text['max_scan_date'] = array(__('Last Scan Date'), 'DESC'); } else { $display_text['scan_date'] = array(__('Last Scan Date'), 'DESC'); } if (get_request_var('scan_date') == 3) { $display_text['count_rec'] = array(__('Count'), 'ASC'); } if (mactrack_check_user_realm(2122)) { html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction')); } else { html_header_sort($display_text, get_request_var('sort_column'), get_request_var('sort_direction')); } $i = 0; $delim = read_config_option('mt_mac_delim'); if (sizeof($port_results)) { foreach ($port_results as $port_result) { if ($port_result['active_last'] == 1) { $color_line_date = "<span style='font-weight: bold;'>"; } else { $color_line_date = ''; } $key = str_replace($delim, '_', $port_result['mac_address']) . '-' . $port_result['device_id'] . $port_result['port_number'] . '-' . $port_result['date_last']; $key = $port_result['row_id']; form_alternate_row('line' . $key, true); form_selectable_cell(filter_value($port_result['device_name'], get_request_var('filter')), $key); form_selectable_cell(filter_value($port_result['hostname'], get_request_var('filter')), $key); form_selectable_cell(filter_value($port_result['ip_address'], get_request_var('filter')), $key); if (strlen(read_config_option('mt_reverse_dns')) > 0) { form_selectable_cell(filter_value($port_result['dns_hostname'], get_request_var('filter')), $key); } form_selectable_cell(filter_value($port_result['mac_address'], get_request_var('filter')), $key); form_selectable_cell(filter_value($port_result['vendor_name'], get_request_var('filter')), $key); form_selectable_cell($port_result['port_number'], $key); form_selectable_cell(filter_value($port_result['port_name'], get_request_var('filter')), $key); form_selectable_cell($port_result['vlan_id'], $key); form_selectable_cell(filter_value($port_result['vlan_name'], get_request_var('filter')), $key); form_selectable_cell($color_line_date . $port_result['date_last'], $key); form_selectable_cell($port_result['count_rec'], $key); if (mactrack_check_user_realm(2122)) { form_checkbox_cell($port_result['mac_address'], $key); } form_end_row(); } } else { if (get_request_var('site_id') == -1 && get_request_var('device_id') == -1) { print "<tr><td colspan='10'><em>" . __('You must first choose a Site, Device or other search criteria.') . "</em></td></tr>"; } else { print "<tr><td colspan='10'><em>" . __('No MacTrack Port Results') . "</em></td></tr>"; } } html_end_box(false); if (sizeof($port_results)) { print $nav; mactrack_display_stats(); } if (mactrack_check_user_realm(2122)) { /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($mactrack_view_agg_macs_actions); } }