function wmGenerateFooterLinks() { global $colors; global $WEATHERMAP_VERSION; print '<br />'; html_start_box("<center><a target=\"_blank\" class=\"linkOverDark\" href=\"docs/\">Local Documentation</a> -- " . "<a target=\"_blank\" class=\"linkOverDark\" href=\"http://www.network-weathermap.com/\">Weathermap" . " Website</a> -- <a target=\"_target\" class=\"linkOverDark\" " . "href=\"weathermap-cacti-plugin-editor.php?plug=1\">Weathermap Editor</a> -- " . "This is version {$WEATHERMAP_VERSION}</center>", "78%", $colors["header"], "2", "center", ""); html_end_box(); }
function thold_add_select_host() { global $config; $host_id = get_filter_request_var('host_id'); $local_graph_id = get_filter_request_var('local_graph_id'); $data_template_rrd_id = get_filter_request_var('data_template_rrd_id'); $hosts = get_allowed_devices(); top_header(); form_start('thold.php?action=save', 'tholdform'); html_start_box(__('Threshold Creation Wizard'), '50%', '', '3', 'center', ''); if ($host_id == '') { print '<tr><td class="center">' . __('Please select a Device') . '</td></tr>'; } else { if ($local_graph_id == '') { print '<tr><td class="center">' . __('Please select a Graph') . '</td></tr>'; } else { if ($data_template_rrd_id == '') { print '<tr><td class="center">' . __('Please select a Data Source') . '</td></tr>'; } else { print '<tr><td class="center">' . __('Please press \'Create\' to activate your Threshold') . '</td></tr>'; } } } html_end_box(); html_start_box('', '50%', '', '3', 'center', ''); /* display the host dropdown */ ?> <tr><td><table class='filterTable' align='center'> <tr> <?php print html_host_filter(get_request_var('host_id')); ?> </tr><?php if ($host_id != '') { $graphs = get_allowed_graphs('gl.host_id=' . $host_id); ?> <tr> <td> <?php print __('Graph'); ?> </td> <td> <select id='local_graph_id' name='local_graph_id' onChange='applyFilter("graph")'> <option value=''></option><?php foreach ($graphs as $row) { echo "<option value='" . $row['local_graph_id'] . "'" . ($row['local_graph_id'] == $local_graph_id ? ' selected' : '') . '>' . htmlspecialchars($row['title_cache'], ENT_QUOTES) . '</option>'; } ?> </select> </td> </tr><?php } else { ?> <tr> <td> <input type='hidden' id='local_graph_id' name='local_graph_id' value=''> </td> </tr><?php } if ($local_graph_id != '') { $dt_sql = 'SELECT DISTINCT dtr.local_data_id FROM data_template_rrd AS dtr LEFT JOIN graph_templates_item AS gti ON gti.task_item_id=dtr.id LEFT JOIN graph_local AS gl ON gl.id=gti.local_graph_id WHERE gl.id = ' . $local_graph_id; $local_data_id = db_fetch_cell($dt_sql); $dss = db_fetch_assoc('SELECT DISTINCT id, data_source_name FROM data_template_rrd WHERE local_data_id IN (' . $dt_sql . ') ORDER BY data_source_name'); /* show the data source options */ ?> <tr> <td> <?php print __('Data Source'); ?> </td> <td> <input type='hidden' id='local_data_id' name='local_data_id' value='<?php print $local_data_id; ?> '> <select id='data_template_rrd_id' name='data_template_rrd_id' onChange='applyFilter("ds")'> <option value=''></option><?php foreach ($dss as $row) { echo "<option value='" . $row['id'] . "'" . ($row['id'] == $data_template_rrd_id ? ' selected' : '') . '>' . htmlspecialchars($row['data_source_name'], ENT_QUOTES) . '</option>'; } ?> </select> </td> </tr></table></td></tr><?php } else { ?> <tr> <td> <input type='hidden' id='data_template_rrd_id' name='data_template_rrd_id' value=''> </td> </tr></table></td></tr><?php } if ($data_template_rrd_id != '') { echo "<tr><td class='center' colspan='2'><input type='hidden' name='save' id='save' value='save'><input id='go' type='button' value='" . __('Create') . "' title='" . __('Create Threshold') . "'></td></tr>"; } else { echo "<tr><td class='center' colspan='2'></td></tr>"; } html_end_box(); form_end(); html_start_box('', '50%', '', '3', 'center', ''); if ($local_graph_id != '') { print "<tr><td style='text-align:center'><img id='graphi' src='../../graph_image.php?local_graph_id={$local_graph_id}&rra_id=0'></td></tr>"; } html_end_box(); ?> <script type='text/javascript'> function applyFilter(target) { strURL = 'thold.php?action=add&header=false&host_id=' + $('#host_id').val(); if (target != 'host_id') { strURL += '&local_graph_id=' + $('#local_graph_id').val(); } if (target == 'ds') { strURL += '&data_template_rrd_id=' + $('#data_template_rrd_id').val(); } loadPageNoHeader(strURL); } $(function() { $('#go').button().click(function() { strURL = $('#tholdform').attr('action'); json = $('input, select').serializeObject(); $.post(strURL, json).done(function(data) { $('#main').html(data); applySkin(); window.scrollTo(0, 0); }); }); }); </script> <?php }
function item_edit() { global $colors, $struct_graph_item, $graph_item_types, $consolidation_functions; if (!empty($_GET["id"])) { $template_item = db_fetch_row("select * from graph_templates_item where id=" . $_GET["id"]); $host_id = db_fetch_cell("select host_id from graph_local where id=" . $_GET["local_graph_id"]); } $header_label = "[edit graph: " . db_fetch_cell("select title_cache from graph_templates_graph where local_graph_id=" . $_GET["local_graph_id"]) . "]"; html_start_box("<strong>Graph Items</strong> $header_label", "98%", $colors["header"], "3", "center", ""); /* by default, select the LAST DS chosen to make everyone's lives easier */ if (!empty($_GET["local_graph_id"])) { $default = db_fetch_row("select task_item_id from graph_templates_item where local_graph_id=" . $_GET["local_graph_id"] . " order by sequence DESC"); if (sizeof($default) > 0) { $struct_graph_item["task_item_id"]["default"] = $default["task_item_id"]; }else{ $struct_graph_item["task_item_id"]["default"] = 0; } /* modifications to the default graph items array */ $struct_graph_item["task_item_id"]["sql"] = "select CONCAT_WS('',case when host.description is null then 'No Host' when host.description is not null then host.description end,' - ',data_template_data.name_cache,' (',data_template_rrd.data_source_name,')') as name, data_template_rrd.id from data_template_data,data_template_rrd,data_local left join host on data_local.host_id=host.id where data_template_rrd.local_data_id=data_local.id and data_template_data.local_data_id=data_local.id " . (((!empty($host_id)) || (!empty($_GET["host_id"]))) ? (!empty($host_id) ? " and data_local.host_id=$host_id" : " and data_local.host_id=" . $_GET["host_id"]) : "") . " order by name"; } $form_array = array(); while (list($field_name, $field_array) = each($struct_graph_item)) { $form_array += array($field_name => $struct_graph_item[$field_name]); $form_array[$field_name]["value"] = (isset($template_item) ? $template_item[$field_name] : ""); $form_array[$field_name]["form_id"] = (isset($template_item) ? $template_item["id"] : "0"); } draw_edit_form( array( "config" => array( ), "fields" => $form_array ) ); form_hidden_box("local_graph_id", $_GET["local_graph_id"], "0"); form_hidden_box("graph_template_item_id", (isset($template_item) ? $template_item["id"] : "0"), ""); form_hidden_box("local_graph_template_item_id", (isset($template_item) ? $template_item["local_graph_template_item_id"] : "0"), ""); form_hidden_box("graph_template_id", (isset($template_item) ? $template_item["graph_template_id"] : "0"), ""); form_hidden_box("sequence", (isset($template_item) ? $template_item["sequence"] : "0"), ""); form_hidden_box("_graph_type_id", (isset($template_item) ? $template_item["graph_type_id"] : "0"), ""); form_hidden_box("save_component_item", "1", ""); html_end_box(); form_save_button("graphs.php?action=graph_edit&id=" . $_GET["local_graph_id"]); }
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 graph() { global $colors, $graph_actions, $item_rows; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("host_id")); input_validate_input_number(get_request_var_request("graph_rows")); input_validate_input_number(get_request_var_request("template_id")); input_validate_input_number(get_request_var_request("page")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* clean up sort_column string */ if (isset($_REQUEST["sort_column"])) { $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column")); } /* clean up sort_direction string */ if (isset($_REQUEST["sort_direction"])) { $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction")); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { kill_session_var("sess_graph_current_page"); kill_session_var("sess_graph_filter"); kill_session_var("sess_graph_sort_column"); kill_session_var("sess_graph_sort_direction"); kill_session_var("sess_graph_host_id"); kill_session_var("sess_graph_rows"); kill_session_var("sess_graph_template_id"); unset($_REQUEST["page"]); unset($_REQUEST["filter"]); unset($_REQUEST["sort_column"]); unset($_REQUEST["sort_direction"]); unset($_REQUEST["host_id"]); unset($_REQUEST["graph_rows"]); unset($_REQUEST["template_id"]); } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("page", "sess_graph_current_page", "1"); load_current_session_value("filter", "sess_graph_filter", ""); load_current_session_value("sort_column", "sess_graph_sort_column", "title_cache"); load_current_session_value("sort_direction", "sess_graph_sort_direction", "ASC"); load_current_session_value("host_id", "sess_graph_host_id", "-1"); load_current_session_value("graph_rows", "sess_graph_rows", read_config_option("num_rows_graph")); load_current_session_value("template_id", "sess_graph_template_id", "-1"); /* if the number of rows is -1, set it to the default */ if (get_request_var_request("graph_rows") == -1) { $_REQUEST["graph_rows"] = read_config_option("num_rows_graph"); } ?> <script type="text/javascript"> <!-- function applyGraphsFilterChange(objForm) { strURL = '?host_id=' + objForm.host_id.value; strURL = strURL + '&graph_rows=' + objForm.graph_rows.value; strURL = strURL + '&filter=' + objForm.filter.value; strURL = strURL + '&template_id=' + objForm.template_id.value; document.location = strURL; } --> </script> <?php html_start_box("<strong>Graph Management</strong>", "100%", $colors["header"], "3", "center", "graphs.php?action=graph_edit&host_id=" . get_request_var_request("host_id")); ?> <tr bgcolor="<?php print $colors["panel"];?>"> <form name="form_graph_id"> <td> <table cellpadding="1" cellspacing="0"> <tr> <td width="50"> Host: </td> <td width="1"> <select name="host_id" onChange="applyGraphsFilterChange(document.form_graph_id)"> <option value="-1"<?php if (get_request_var_request("host_id") == "-1") {?> selected<?php }?>>Any</option> <option value="0"<?php if (get_request_var_request("host_id") == "0") {?> selected<?php }?>>None</option> <?php if (read_config_option("auth_method") != 0) { /* get policy information for the sql where clause */ $current_user = db_fetch_row("select * from user_auth where id=" . $_SESSION["sess_user_id"]); $sql_where = get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]); $hosts = db_fetch_assoc("SELECT DISTINCT host.id, CONCAT_WS('',host.description,' (',host.hostname,')') as name FROM (graph_templates_graph,host) LEFT JOIN graph_local ON (graph_local.host_id=host.id) LEFT JOIN graph_templates ON (graph_templates.id=graph_local.graph_template_id) LEFT JOIN user_auth_perms ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=1 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (host.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_templates.id=user_auth_perms.item_id and user_auth_perms.type=4 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ")) WHERE graph_templates_graph.local_graph_id=graph_local.id " . (empty($sql_where) ? "" : "and $sql_where") . " ORDER BY name"); }else{ $hosts = db_fetch_assoc("SELECT DISTINCT host.id, CONCAT_WS('',host.description,' (',host.hostname,')') as name FROM host ORDER BY name"); } if (sizeof($hosts) > 0) { foreach ($hosts as $host) { print "<option value=' " . $host["id"] . "'"; if (get_request_var_request("host_id") == $host["id"]) { print " selected"; } print ">" . title_trim($host["name"], 40) . "</option>\n"; } } ?> </select> </td> <td width="70"> Template: </td> <td width="1"> <select name="template_id" onChange="applyGraphsFilterChange(document.form_graph_id)"> <option value="-1"<?php if (get_request_var_request("template_id") == "-1") {?> selected<?php }?>>Any</option> <option value="0"<?php if (get_request_var_request("template_id") == "0") {?> selected<?php }?>>None</option> <?php if (read_config_option("auth_method") != 0) { $templates = db_fetch_assoc("SELECT DISTINCT graph_templates.id, graph_templates.name FROM (graph_templates_graph,graph_local) LEFT JOIN host ON (host.id=graph_local.host_id) LEFT JOIN graph_templates ON (graph_templates.id=graph_local.graph_template_id) LEFT JOIN user_auth_perms ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=1 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (host.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_templates.id=user_auth_perms.item_id and user_auth_perms.type=4 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ")) WHERE graph_templates_graph.local_graph_id=graph_local.id AND graph_templates.id IS NOT NULL " . (empty($sql_where) ? "" : "AND $sql_where") . " ORDER BY name"); }else{ $templates = db_fetch_assoc("SELECT DISTINCT graph_templates.id, graph_templates.name FROM graph_templates ORDER BY name"); } if (sizeof($templates) > 0) { foreach ($templates as $template) { print "<option value=' " . $template["id"] . "'"; if (get_request_var_request("template_id") == $template["id"]) { print " selected"; } print ">" . title_trim($template["name"], 40) . "</option>\n"; } } ?> </select> </td> <td width="120" nowrap style='white-space: nowrap;'> <input type="image" src="images/button_go.gif" alt="Go" border="0" align="absmiddle"> <input type="image" src="images/button_clear.gif" name="clear" alt="Clear" border="0" align="absmiddle"> </td> </tr> </table> <table cellpadding="1" cellspacing="0"> <tr> <td width="50"> Search: </td> <td> <input type="text" name="filter" size="40" value="<?php print get_request_var_request("filter");?>"> </td> <td nowrap style='white-space: nowrap;' width="50"> Rows per Page: </td> <td width="1"> <select name="graph_rows" onChange="applyGraphsFilterChange(document.form_graph_id)"> <option value="-1"<?php if (get_request_var_request("graph_rows") == "-1") {?> selected<?php }?>>Default</option> <?php if (sizeof($item_rows) > 0) { foreach ($item_rows as $key => $value) { print "<option value='" . $key . "'"; if (get_request_var_request("graph_rows") == $key) { print " selected"; } print ">" . $value . "</option>\n"; } } ?> </select> </td> </tr> </table> </td> <input type='hidden' name='page' value='1'> </form> </tr> <?php html_end_box(); /* form the 'where' clause for our main sql query */ if (strlen(get_request_var_request("filter"))) { $sql_where = "AND (graph_templates_graph.title_cache like '%%" . get_request_var_request("filter") . "%%'" . " OR graph_templates.name like '%%" . get_request_var_request("filter") . "%%')"; }else{ $sql_where = ""; } if (get_request_var_request("host_id") == "-1") { /* Show all items */ }elseif (get_request_var_request("host_id") == "0") { $sql_where .= " AND graph_local.host_id=0"; }elseif (!empty($_REQUEST["host_id"])) { $sql_where .= " AND graph_local.host_id=" . get_request_var_request("host_id"); } if (get_request_var_request("template_id") == "-1") { /* Show all items */ }elseif (get_request_var_request("template_id") == "0") { $sql_where .= " AND graph_templates_graph.graph_template_id=0"; }elseif (!empty($_REQUEST["template_id"])) { $sql_where .= " AND graph_templates_graph.graph_template_id=" . get_request_var_request("template_id"); } html_start_box("", "100%", $colors["header"], "3", "center", ""); $total_rows = db_fetch_cell("SELECT COUNT(graph_templates_graph.id) FROM (graph_local,graph_templates_graph) LEFT JOIN graph_templates ON (graph_local.graph_template_id=graph_templates.id) WHERE graph_local.id=graph_templates_graph.local_graph_id $sql_where"); $graph_list = db_fetch_assoc("SELECT graph_templates_graph.id, graph_templates_graph.local_graph_id, graph_templates_graph.height, graph_templates_graph.width, graph_templates_graph.title_cache, graph_templates.name, graph_local.host_id FROM (graph_local,graph_templates_graph) LEFT JOIN graph_templates ON (graph_local.graph_template_id=graph_templates.id) WHERE graph_local.id=graph_templates_graph.local_graph_id $sql_where ORDER BY " . $_REQUEST["sort_column"] . " " . get_request_var_request("sort_direction") . " LIMIT " . (get_request_var_request("graph_rows")*(get_request_var_request("page")-1)) . "," . get_request_var_request("graph_rows")); /* generate page list */ $url_page_select = get_page_list(get_request_var_request("page"), MAX_DISPLAY_PAGES, get_request_var_request("graph_rows"), $total_rows, "graphs.php?filter=" . get_request_var_request("filter") . "&host_id=" . get_request_var_request("host_id")); $nav = "<tr bgcolor='#" . $colors["header"] . "'> <td colspan='5'> <table width='100%' cellspacing='0' cellpadding='0' border='0'> <tr> <td align='left' class='textHeaderDark'> <strong><< "; if (get_request_var_request("page") > 1) { $nav .= "<a class='linkOverDark' href='graphs.php?filter=" . get_request_var_request("filter") . "&host_id=" . get_request_var_request("host_id") . "&page=" . (get_request_var_request("page")-1) . "'>"; } $nav .= "Previous"; if (get_request_var_request("page") > 1) { $nav .= "</a>"; } $nav .= "</strong> </td>\n <td align='center' class='textHeaderDark'> Showing Rows " . ((get_request_var_request("graph_rows")*(get_request_var_request("page")-1))+1) . " to " . ((($total_rows < get_request_var_request("graph_rows")) || ($total_rows < (get_request_var_request("graph_rows")*get_request_var_request("page")))) ? $total_rows : (get_request_var_request("graph_rows")*get_request_var_request("page"))) . " of $total_rows [$url_page_select] </td>\n <td align='right' class='textHeaderDark'> <strong>"; if ((get_request_var_request("page") * get_request_var_request("graph_rows")) < $total_rows) { $nav .= "<a class='linkOverDark' href='graphs.php?filter=" . get_request_var_request("filter") . "&host_id=" . get_request_var_request("host_id") . "&page=" . (get_request_var_request("page")+1) . "'>"; } $nav .= "Next"; if ((get_request_var_request("page") * get_request_var_request("graph_rows")) < $total_rows) { $nav .= "</a>"; } $nav .= " >></strong> </td>\n </tr> </table> </td> </tr>\n"; print $nav; $display_text = array( "title_cache" => array("Graph Title", "ASC"), "local_graph_id" => array("ID", "ASC"), "name" => array("Template Name", "ASC"), "height" => array("Size", "ASC")); html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction")); $i = 0; if (sizeof($graph_list) > 0) { foreach ($graph_list as $graph) { $template_name = ((empty($graph["name"])) ? "<em>None</em>" : $graph["name"]); form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $graph["local_graph_id"]); $i++; form_selectable_cell("<a class='linkEditMain' href='graphs.php?action=graph_edit&id=" . $graph["local_graph_id"] . "' title='" . htmlspecialchars($graph["title_cache"]) . "'>" . ((get_request_var_request("filter") != "") ? eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", title_trim($graph["title_cache"], read_config_option("max_title_graph"))) : title_trim($graph["title_cache"], read_config_option("max_title_graph"))) . "</a>", $graph["local_graph_id"]); form_selectable_cell($graph["local_graph_id"], $graph["local_graph_id"]); form_selectable_cell(((get_request_var_request("filter") != "") ? eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $template_name) : $template_name) . "</a>", $graph["local_graph_id"]); form_selectable_cell($graph["height"] . "x" . $graph["width"], $graph["local_graph_id"]); form_checkbox_cell($graph["title_cache"], $graph["local_graph_id"]); form_end_row(); } /* put the nav bar on the bottom as well */ print $nav; }else{ print "<tr><td><em>No Graphs Found</em></td></tr>"; } html_end_box(false); /* add a list of tree names to the actions dropdown */ add_tree_names_to_actions_array(); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($graph_actions); print "</form>\n"; }
function import() { global $colors, $hash_type_names; ?> <form method="post" action="templates_import.php" enctype="multipart/form-data"> <?php if (isset($_SESSION["import_debug_info"]) && is_array($_SESSION["import_debug_info"])) { html_start_box("<strong>Import Results</strong>", "100%", "aaaaaa", "3", "center", ""); print "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td><p class='textArea'>Cacti has imported the following items:</p>"; while (list($type, $type_array) = each($_SESSION["import_debug_info"])) { print "<p><strong>" . $hash_type_names[$type] . "</strong></p>"; while (list($index, $vals) = each($type_array)) { if ($vals["result"] == "success") { $result_text = "<span style='color: green;'>[success]</span>"; } else { $result_text = "<span style='color: red;'>[fail]</span>"; } if ($vals["type"] == "update") { $type_text = "<span style='color: gray;'>[update]</span>"; } else { $type_text = "<span style='color: blue;'>[new]</span>"; } print "<span style='font-family: monospace;'>{$result_text} " . $vals["title"] . " {$type_text}</span><br>\n"; $dep_text = ""; $there_are_dep_errors = false; if (isset($vals["dep"]) && sizeof($vals["dep"]) > 0) { while (list($dep_hash, $dep_status) = each($vals["dep"])) { if ($dep_status == "met") { $dep_status_text = "<span style='color: navy;'>Found Dependency:</span>"; } else { $dep_status_text = "<span style='color: red;'>Unmet Dependency:</span>"; $there_are_dep_errors = true; } $dep_text .= "<span style='font-family: monospace;'> + {$dep_status_text} " . hash_to_friendly_name($dep_hash, true) . "</span><br>\n"; } } /* only print out dependency details if they contain errors; otherwise it would get too long */ if ($there_are_dep_errors == true) { print $dep_text; } } } print "</td></tr>"; html_end_box(); kill_session_var("import_debug_info"); } html_start_box("<strong>Import Templates</strong>", "100%", $colors["header"], "3", "center", ""); form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], 0); ?> <td width="50%"> <font class="textEditTitle">Import Template from Local File</font><br> If the XML file containing template data is located on your local machine, select it here. </td> <td> <input type="file" name="import_file"> </td> </tr> <?php form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], 1); ?> <td width="50%"> <font class="textEditTitle">Import Template from Text</font><br> If you have the XML file containing template data as text, you can paste it into this box to import it. </td> <td> <?php form_text_area("import_text", "", "10\t", "50", ""); ?> </td> </tr> <?php form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], 0); ?> <td width="50%"> <font class="textEditTitle">Import RRA Settings</font><br> Choose whether to allow Cacti to import custom RRA settings from imported templates or whether to use the defaults for this installation. </td> <td> <?php form_radio_button("import_rra", 1, 1, "Use defaults for this installation (Recommended)", 1); echo "<br />"; form_radio_button("import_rra", 1, 2, "Use custom RRA settings from the template", 1); ?> </td> </tr> <?php form_hidden_box("save_component_import", "1", ""); html_end_box(); form_save_button("templates_import.php", "save"); }
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 gprint_presets() { global $colors; html_start_box("<strong>GPRINT Presets</strong>", "100%", $colors["header"], "3", "center", "gprint_presets.php?action=edit"); print " <tr bgcolor='#" . $colors["header_panel"] . "'> <td colspan='2' class='textSubHeaderDark'>GPRINT Preset Title</td> </tr>"; $template_list = db_fetch_assoc("select graph_templates_gprint.id, graph_templates_gprint.name from graph_templates_gprint"); $i = 0; if (sizeof($template_list) > 0) { foreach ($template_list as $template) { form_alternate_row_color($colors["alternate"],$colors["light"],$i); ?> <td> <a class="linkEditMain" href="gprint_presets.php?action=edit&id=<?php print $template["id"];?>"><?php print $template["name"];?></a> </td> <td align="right"> <a href="gprint_presets.php?action=remove&id=<?php print $template["id"];?>"><img src="images/delete_icon.gif" width="10" height="10" border="0" alt="Delete"></a> </td> </tr> <?php $i++; } }else{ form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],0); ?> <td colspan="2"> <em>No Items</em> </td> </tr><?php } html_end_box(); }
function ds() { global $colors, $ds_actions; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("host_id")); input_validate_input_number(get_request_var_request("page")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* clean up sort_column string */ if (isset($_REQUEST["sort_column"])) { $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column")); } /* clean up sort_direction string */ if (isset($_REQUEST["sort_direction"])) { $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction")); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { kill_session_var("sess_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_host_id"); unset($_REQUEST["page"]); unset($_REQUEST["filter"]); unset($_REQUEST["sort_column"]); unset($_REQUEST["sort_direction"]); unset($_REQUEST["host_id"]); } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("page", "sess_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("host_id", "sess_ds_host_id", "-1"); $host = db_fetch_row("select hostname from host where id=" . $_REQUEST["host_id"]); html_start_box("<strong>Data Sources</strong> [host: " . (empty($host["hostname"]) ? "No Host" : $host["hostname"]) . "]", "100%", $colors["header"], "3", "center", "data_sources.php?action=ds_edit&host_id=" . $_REQUEST["host_id"]); include "./include/html/inc_data_source_filter_table.php"; html_end_box(); /* form the 'where' clause for our main sql query */ if (strlen($_REQUEST["filter"])) { $sql_where = "AND (data_template_data.name_cache like '%%" . $_REQUEST["filter"] . "%%'" . " OR data_template.name like '%%" . $_REQUEST["filter"] . "%%'" . " OR data_input.name like '%%" . $_REQUEST["filter"] . "%%')"; } else { $sql_where = ""; } if ($_REQUEST["host_id"] == "-1") { /* Show all items */ } elseif ($_REQUEST["host_id"] == "0") { $sql_where .= " AND data_local.host_id=0"; } elseif (!empty($_REQUEST["host_id"])) { $sql_where .= " AND data_local.host_id=" . $_REQUEST["host_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_where}")); $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_where}\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_where}\n\t\tORDER BY " . $_REQUEST['sort_column'] . " " . $_REQUEST['sort_direction'] . " LIMIT " . read_config_option("num_rows_data_source") * ($_REQUEST["page"] - 1) . "," . read_config_option("num_rows_data_source")); html_start_box("", "100%", $colors["header"], "3", "center", ""); /* generate page list */ $url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, read_config_option("num_rows_data_source"), $total_rows, "data_sources.php?filter=" . $_REQUEST["filter"] . "&host_id=" . $_REQUEST["host_id"]); $nav = "<tr bgcolor='#" . $colors["header"] . "'>\n\t\t\t<td colspan='6'>\n\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td align='left' class='textHeaderDark'>\n\t\t\t\t\t\t\t<strong><< "; if ($_REQUEST["page"] > 1) { $nav .= "<a class='linkOverDark' href='data_sources.php?filter=" . $_REQUEST["filter"] . "&host_id=" . $_REQUEST["host_id"] . "&page=" . ($_REQUEST["page"] - 1) . "'>"; } $nav .= "Previous"; if ($_REQUEST["page"] > 1) { $nav .= "</a>"; } $nav .= "</strong>\n\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\n\t\t\t\t\t\t\tShowing Rows " . (read_config_option("num_rows_data_source") * ($_REQUEST["page"] - 1) + 1) . " to " . ($total_rows < read_config_option("num_rows_data_source") || $total_rows < read_config_option("num_rows_data_source") * $_REQUEST["page"] ? $total_rows : read_config_option("num_rows_data_source") * $_REQUEST["page"]) . " of {$total_rows} [{$url_page_select}]\n\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t<td align='right' class='textHeaderDark'>\n\t\t\t\t\t\t\t<strong>"; if ($_REQUEST["page"] * read_config_option("num_rows_data_source") < $total_rows) { $nav .= "<a class='linkOverDark' href='data_sources.php?filter=" . $_REQUEST["filter"] . "&host_id=" . $_REQUEST["host_id"] . "&page=" . ($_REQUEST["page"] + 1) . "'>"; } $nav .= "Next"; if ($_REQUEST["page"] * read_config_option("num_rows_data_source") < $total_rows) { $nav .= "</a>"; } $nav .= " >></strong>\n\t\t\t\t\t\t</td>\n\n\t\t\t\t\t</tr>\n\t\t\t\t</table>\n\t\t\t</td>\n\t\t</tr>\n"; print $nav; $display_text = array("name_cache" => array("Name", "ASC"), "data_input_name" => array("Data Input Method", "ASC"), "nosort" => array("Poller<br>Interval", "ASC"), "active" => array("Active", "ASC"), "data_template_name" => array("Template Name", "ASC")); html_header_sort_checkbox($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"]); $i = 0; if (sizeof($data_sources) > 0) { foreach ($data_sources as $data_source) { $data_template_name = empty($data_source["data_template_name"]) ? "<em>None</em>" : $data_source["data_template_name"]; $data_input_name = empty($data_source["data_input_name"]) ? "<em>External</em>" : $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_color($colors["alternate"], $colors["light"], $i, 'line' . $data_source["local_data_id"]); $i++; form_selectable_cell("<a class='linkEditMain' href='data_sources.php?action=ds_edit&id=" . $data_source["local_data_id"] . "'>" . ($_REQUEST["filter"] != "" ? eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", title_trim(htmlentities($data_source["name_cache"]), read_config_option("max_title_data_source"))) : title_trim(htmlentities($data_source["name_cache"]), read_config_option("max_title_data_source"))) . "</a>", $data_source["local_data_id"]); form_selectable_cell(($_REQUEST["filter"] != "" ? eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $data_input_name) : $data_input_name) . "</a>", $data_source["local_data_id"]); form_selectable_cell(get_poller_interval($poller_interval), $data_source["local_data_id"]); form_selectable_cell($data_source['active'], $data_source["local_data_id"]); form_selectable_cell(($_REQUEST["filter"] != "" ? eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $data_source['data_template_name']) : $data_source['data_template_name']) . "</a>", $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 item_edit() { global $colors; if (!empty($_GET["id"])) { $graph_template_item = db_fetch_row("select * from graph_template_item where id=" . $_GET["id"]); } /* by default, select the LAST DS chosen to make everyone's lives easier */ $default = db_fetch_row("select data_template_item_id from graph_template_item where graph_template_id=" . $_GET["graph_template_id"] . " order by sequence DESC"); if (sizeof($default) > 0) { $graph_template_item["data_template_item_id"] = $default["data_template_item_id"]; } else { $graph_template_item["data_template_item_id"] = 0; } form_start("graph_templates_items.php", "form_graph_template"); /* ==================== Box: Graph Item ==================== */ html_start_box("<strong>" . _("Graph Item") . "</strong> [" . _("Graph Template: ") . db_fetch_cell("select template_name from graph_template where id=" . $_GET["graph_template_id"]) . "]", "98%", $colors["header_background"], "3", "center", ""); _graph_item_field__data_template_item_id("data_template_item_id", isset($graph_template_item["data_template_item_id"]) ? $graph_template_item["data_template_item_id"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]); _graph_item_field__color("color", isset($graph_template_item["color"]) ? $graph_template_item["color"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]); _graph_item_field__graph_item_type("graph_item_type", isset($graph_template_item["graph_item_type"]) ? $graph_template_item["graph_item_type"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]); _graph_item_field__consolidation_function("consolidation_function", isset($graph_template_item["consolidation_function"]) ? $graph_template_item["consolidation_function"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]); _graph_item_field__cdef("cdef", isset($graph_template_item["cdef"]) ? $graph_template_item["cdef"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]); _graph_item_field__gprint_format("gprint_format", isset($graph_template_item["gprint_format"]) ? $graph_template_item["gprint_format"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]); _graph_item_field__legend_value("legend_value", isset($graph_template_item["legend_value"]) ? $graph_template_item["legend_value"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]); _graph_item_field__legend_format("legend_format", isset($graph_template_item["legend_format"]) ? $graph_template_item["legend_format"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]); _graph_item_field__hard_return("hard_return", isset($graph_template_item["hard_return"]) ? $graph_template_item["hard_return"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]); html_end_box(); form_hidden_box("graph_template_item_id", !empty($graph_template_item["id"]) ? $graph_template_item["id"] : "0", ""); form_hidden_box("graph_template_id", $_GET["graph_template_id"], "0"); form_hidden_box("save_component_item", "1", ""); form_save_button("graph_templates.php?action=edit&id=" . $_GET["graph_template_id"]); }
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(); }
function host() { global $colors, $device_actions; /* 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"); unset($_REQUEST["page"]); unset($_REQUEST["filter"]); unset($_REQUEST["host_template_id"]); } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("page", "sess_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"); html_start_box("<strong>Devices</strong>", "98%", $colors["header"], "3", "center", "host.php?action=edit&host_template_id=" . $_REQUEST["host_template_id"]); include("./include/html/inc_device_filter_table.php"); html_end_box(); /* form the 'where' clause for our main sql query */ $sql_where = "where host.description like '%%" . $_REQUEST["filter"] . "%%'"; if ($_REQUEST["host_template_id"] == "-1") { /* Show all items */ }elseif ($_REQUEST["host_template_id"] == "0") { $sql_where .= " and host.host_template_id=0"; }elseif (!empty($_REQUEST["host_template_id"])) { $sql_where .= " and host.host_template_id=" . $_REQUEST["host_template_id"]; } html_start_box("", "98%", $colors["header"], "3", "center", ""); $total_rows = db_fetch_cell("select COUNT(host.id) from host $sql_where"); $hosts = db_fetch_assoc("select host.id, host.disabled, host.status, host.hostname, host.description, host.min_time, host.max_time, host.cur_time, host.avg_time, host.availability from host $sql_where order by host.description limit " . (read_config_option("num_rows_device")*($_REQUEST["page"]-1)) . "," . read_config_option("num_rows_device")); /* generate page list */ $url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, read_config_option("num_rows_device"), $total_rows, "host.php?filter=" . $_REQUEST["filter"] . "&host_template_id=" . $_REQUEST["host_template_id"]); $nav = "<tr bgcolor='#" . $colors["header"] . "'> <td colspan='7'> <table width='100%' cellspacing='0' cellpadding='0' border='0'> <tr> <td align='left' class='textHeaderDark'> <strong><< "; if ($_REQUEST["page"] > 1) { $nav .= "<a class='linkOverDark' href='host.php?filter=" . $_REQUEST["filter"] . "&host_template_id=" . $_REQUEST["host_template_id"] . "&page=" . ($_REQUEST["page"]-1) . "'>"; } $nav .= "Previous"; if ($_REQUEST["page"] > 1) { $nav .= "</a>"; } $nav .= "</strong> </td>\n <td align='center' class='textHeaderDark'> Showing Rows " . ((read_config_option("num_rows_device")*($_REQUEST["page"]-1))+1) . " to " . ((($total_rows < read_config_option("num_rows_device")) || ($total_rows < (read_config_option("num_rows_device")*$_REQUEST["page"]))) ? $total_rows : (read_config_option("num_rows_device")*$_REQUEST["page"])) . " of $total_rows [$url_page_select] </td>\n <td align='right' class='textHeaderDark'> <strong>"; if (($_REQUEST["page"] * read_config_option("num_rows_device")) < $total_rows) { $nav .= "<a class='linkOverDark' href='host.php?filter=" . $_REQUEST["filter"] . "&host_template_id=" . $_REQUEST["host_template_id"] . "&page=" . ($_REQUEST["page"]+1) . "'>"; } $nav .= "Next"; if (($_REQUEST["page"] * read_config_option("num_rows_device")) < $total_rows) { $nav .= "</a>"; } $nav .= " >></strong> </td>\n </tr> </table> </td> </tr>\n"; print $nav; html_header_checkbox(array("Description", "Status", "Hostname", "Current (ms)", "Average (ms)", "Availability")); $i = 0; if (sizeof($hosts) > 0) { foreach ($hosts as $host) { form_alternate_row_color($colors["alternate"],$colors["light"],$i); $i++; ?> <td width=200> <a class="linkEditMain" href="host.php?action=edit&id=<?php print $host["id"];?>"><?php print eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $host["description"]);?></a> </td> <td> <?php print get_colored_device_status(($host["disabled"] == "on" ? true : false), $host["status"]);?> </td> <td> <?php print $host["hostname"];?> </td> <td> <?php print round(($host["cur_time"]), 2);?> </td> <td> <?php print round(($host["avg_time"]), 2);?> </td> <td> <?php print round($host["availability"], 2);?>% </td> <td style="<?php print get_checkbox_style();?>" width="1%" align="right"> <input type='checkbox' style='margin: 0px;' name='chk_<?php print $host["id"];?>' title="<?php print $host["description"];?>"> </td> </tr> <?php } /* put the nav bar on the bottom as well */ print $nav; }else{ print "<tr><td><em>No Hosts</em></td></tr>"; } html_end_box(false); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($device_actions); }
function syslog_alerts() { global $colors, $syslog_actions, $config, $message_types, $severities; include dirname(__FILE__) . "/config.php"; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("id")); input_validate_input_number(get_request_var_request("page")); input_validate_input_number(get_request_var_request("enabled")); input_validate_input_number(get_request_var_request("rows")); /* ==================================================== */ /* clean up 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"])) { kill_session_var("sess_syslog_alerts_page"); kill_session_var("sess_syslog_alerts_rows"); kill_session_var("sess_syslog_alerts_filter"); kill_session_var("sess_syslog_alerts_enabled"); kill_session_var("sess_syslog_alerts_sort_column"); kill_session_var("sess_syslog_alerts_sort_direction"); $_REQUEST["page"] = 1; unset($_REQUEST["filter"]); unset($_REQUEST["enabled"]); unset($_REQUEST["rows"]); unset($_REQUEST["sort_column"]); unset($_REQUEST["sort_direction"]); } else { /* if any of the settings changed, reset the page number */ $changed = 0; $changed += syslog_check_changed("filter", "sess_syslog_alerts_filter"); $changed += syslog_check_changed("enabled", "sess_syslog_alerts_enabled"); $changed += syslog_check_changed("rows", "sess_syslog_alerts_rows"); $changed += syslog_check_changed("sort_column", "sess_syslog_alerts_sort_column"); $changed += syslog_check_changed("sort_direction", "sess_syslog_alerts_sort_direction"); if ($changed) { $_REQUEST["page"] = "1"; } } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("page", "sess_syslog_alerts_paage", "1"); load_current_session_value("rows", "sess_syslog_alerts_rows", "-1"); load_current_session_value("enabled", "sess_syslog_alerts_enabled", "-1"); load_current_session_value("filter", "sess_syslog_alerts_filter", ""); load_current_session_value("sort_column", "sess_syslog_alerts_sort_column", "name"); load_current_session_value("sort_direction", "sess_syslog_alerts_sort_direction", "ASC"); html_start_box("<strong>Syslog Alert Filters</strong>", "100%", $colors["header"], "3", "center", "syslog_alerts.php?action=edit"); syslog_filter(); html_end_box(); html_start_box("", "100%", $colors["header"], "3", "center", ""); $sql_where = ""; if ($_REQUEST["rows"] == "-1") { $row_limit = read_config_option("num_rows_syslog"); } elseif ($_REQUEST["rows"] == -2) { $row_limit = 999999; } else { $row_limit = $_REQUEST["rows"]; } $alerts = syslog_get_alert_records($sql_where, $row_limit); $rows_query_string = "SELECT COUNT(*)\n\t\tFROM `" . $syslogdb_default . "`.`syslog_alert`\n\t\t{$sql_where}"; $total_rows = syslog_db_fetch_cell($rows_query_string); ?> <script type="text/javascript"> <!-- function applyChange(objForm) { strURL = '?enabled=' + objForm.enabled.value; strURL = strURL + '&filter=' + objForm.filter.value; strURL = strURL + '&rows=' + objForm.rows.value; document.location = strURL; } --> </script> <?php /* generate page list */ $url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, $row_limit, $total_rows, "syslog_alerts.php?filter=" . $_REQUEST["filter"]); if ($total_rows > 0) { $nav = "<tr bgcolor='#" . $colors["header"] . "'>\n\t\t\t\t\t<td colspan='13'>\n\t\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td align='left' class='textHeaderDark'>\n\t\t\t\t\t\t\t\t\t<strong><< "; if ($_REQUEST["page"] > 1) { $nav .= "<a class='linkOverDark' href='syslog_alerts.php?report=arp&page=" . ($_REQUEST["page"] - 1) . "'>"; } $nav .= "Previous"; if ($_REQUEST["page"] > 1) { $nav .= "</a>"; } $nav .= "</strong>\n\t\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\n\t\t\t\t\t\t\t\t\tShowing Rows " . ($total_rows == 0 ? "None" : $row_limit * ($_REQUEST["page"] - 1) + 1 . " to " . ($total_rows < $row_limit || $total_rows < $row_limit * $_REQUEST["page"] ? $total_rows : $row_limit * $_REQUEST["page"]) . " of {$total_rows} [{$url_page_select}]") . "\n\t\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t\t\t<td align='right' class='textHeaderDark'>\n\t\t\t\t\t\t\t\t\t<strong>"; if ($_REQUEST["page"] * $row_limit < $total_rows) { $nav .= "<a class='linkOverDark' href='syslog_alerts.php?report=arp&page=" . ($_REQUEST["page"] + 1) . "'>"; } $nav .= "Next"; if ($_REQUEST["page"] * $row_limit < $total_rows) { $nav .= "</a>"; } $nav .= " >></strong>\n\t\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t</table>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n"; } else { $nav = "<tr bgcolor='#" . $colors["header"] . "' class='noprint'>\n\t\t\t\t\t<td colspan='22'>\n\t\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\n\t\t\t\t\t\t\t\t\tNo Rows Found\n\t\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t</table>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n"; } print $nav; $display_text = array("name" => array("Alert<br>Name", "ASC"), "severity" => array("<br>Severity", "ASC"), "method" => array("<br>Method", "ASC"), "num" => array("Threshold<br>Count", "ASC"), "enabled" => array("<br>Enabled", "ASC"), "type" => array("Match<br>Type", "ASC"), "message" => array("Search<br>String", "ASC"), "email" => array("E-Mail<br>Addresses", "DESC"), "date" => array("Last<br>Modified", "ASC"), "user" => array("By<br>User", "DESC")); html_header_sort_checkbox($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"]); $i = 0; if (sizeof($alerts) > 0) { foreach ($alerts as $alert) { form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $alert["id"]); $i++; form_selectable_cell("<a class='linkEditMain' href='" . $config['url_path'] . "plugins/syslog/syslog_alerts.php?action=edit&id=" . $alert["id"] . "'>" . ($_REQUEST["filter"] != "" ? eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $alert["name"]) : $alert["name"]) . "</a>", $alert["id"]); form_selectable_cell($severities[$alert["severity"]], $alert["id"]); form_selectable_cell($alert["method"] == 1 ? "Threshold" : "Individual", $alert["id"]); form_selectable_cell($alert["method"] == 1 ? $alert["num"] : "N/A", $alert["id"]); form_selectable_cell($alert["enabled"] == "on" ? "Yes" : "No", $alert["id"]); form_selectable_cell($message_types[$alert["type"]], $alert["id"]); form_selectable_cell(title_trim($alert["message"], 60), $alert["id"]); form_selectable_cell(substr_count($alert["email"], ",") ? "Multiple" : $alert["email"], $alert["id"]); form_selectable_cell(date("Y-m-d H:i:s", $alert["date"]), $alert["id"]); form_selectable_cell($alert["user"], $alert["id"]); form_checkbox_cell($alert["name"], $alert["id"]); form_end_row(); } } else { print "<tr><td colspan='4'><em>No Syslog Alerts Defined</em></td></tr>"; } html_end_box(false); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($syslog_actions); }
function input_edit() { global $colors, $consolidation_functions, $graph_item_types, $struct_graph_item, $fields_graph_template_input_edit; $header_label = "[edit graph: " . db_fetch_cell("select name from graph_templates where id=" . $_GET["graph_template_id"]) . "]"; /* get a list of all graph item field names and populate an array for user display */ while (list($field_name, $field_array) = each($struct_graph_item)) { if ($field_array["method"] != "view") { $graph_template_items[$field_name] = $field_array["friendly_name"]; } } if (!empty($_GET["id"])) { $graph_template_input = db_fetch_row("select * from graph_template_input where id=" . $_GET["id"]); } html_start_box("<strong>Graph Item Inputs</strong> $header_label", "98%", $colors["header"], "3", "center", ""); draw_edit_form(array( "config" => array(), "fields" => inject_form_variables($fields_graph_template_input_edit, (isset($graph_template_input) ? $graph_template_input : array()), (isset($graph_template_items) ? $graph_template_items : array()), $_GET) )); if (!(isset($_GET["id"]))) { $_GET["id"] = 0; } $item_list = db_fetch_assoc("select CONCAT_WS(' - ',data_template_data.name,data_template_rrd.data_source_name) as data_source_name, graph_templates_item.text_format, graph_templates_item.id as graph_templates_item_id, graph_templates_item.graph_type_id, graph_templates_item.consolidation_function_id, graph_template_input_defs.graph_template_input_id from graph_templates_item left join graph_template_input_defs on (graph_template_input_defs.graph_template_item_id=graph_templates_item.id and graph_template_input_defs.graph_template_input_id=" . $_GET["id"] . ") left join data_template_rrd on graph_templates_item.task_item_id=data_template_rrd.id left join data_local on data_template_rrd.local_data_id=data_local.id left join data_template_data on data_local.id=data_template_data.local_data_id where graph_templates_item.local_graph_id=0 and graph_templates_item.graph_template_id=" . $_GET["graph_template_id"] . " order by graph_templates_item.sequence"); form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],1); ?> <td width="50%"> <font class="textEditTitle">Associated Graph Items</font><br> Select the graph items that you want to accept user input for. </td> <td> <?php $i = 0; $any_selected_item = ""; if (sizeof($item_list) > 0) { foreach ($item_list as $item) { if ($item["graph_template_input_id"] == "") { $old_value = ""; }else{ $old_value = "on"; $any_selected_item = $item["graph_templates_item_id"]; } if ($graph_item_types{$item["graph_type_id"]} == "GPRINT") { $start_bold = ""; $end_bold = ""; }else{ $start_bold = "<strong>"; $end_bold = "</strong>"; } $name = "$start_bold Item #" . ($i+1) . ": " . $graph_item_types{$item["graph_type_id"]} . " (" . $consolidation_functions{$item["consolidation_function_id"]} . ")$end_bold"; form_checkbox("i_" . $item["graph_templates_item_id"], $old_value, $name,"",$_GET["graph_template_id"],true); print "<br>"; $i++; } }else{ print "<em>No Items</em>"; } ?> </td> </tr> <?php html_end_box(); form_hidden_box("any_selected_item", $any_selected_item, ""); form_save_button("graph_templates.php?action=template_edit&id=" . $_GET["graph_template_id"]); }
function data_query() { global $colors; html_start_box("<strong>Data Queries</strong>", "98%", $colors["header"], "3", "center", "data_queries.php?action=edit"); print "<tr bgcolor='#" . $colors["header_panel"] . "'>"; DrawMatrixHeaderItem("Name",$colors["header_text"],1); DrawMatrixHeaderItem("Data Input Method",$colors["header_text"],1); DrawMatrixHeaderItem(" ",$colors["header_text"],1); print "</tr>"; $snmp_queries = db_fetch_assoc("SELECT snmp_query.id, snmp_query.name, data_input.name AS data_input_method FROM snmp_query INNER JOIN data_input ON snmp_query.data_input_id = data_input.id ORDER BY snmp_query.name"); $i = 0; if (sizeof($snmp_queries) > 0) { foreach ($snmp_queries as $snmp_query) { form_alternate_row_color($colors["alternate"],$colors["light"],$i); $i++; ?> <td> <a class="linkEditMain" href="data_queries.php?action=edit&id=<?php print $snmp_query["id"];?>"><?php print $snmp_query["name"];?></a> </td> <td> <?php print $snmp_query["data_input_method"]; ?> </td> <td align="right"> <a href="data_queries.php?action=remove&id=<?php print $snmp_query["id"];?>"><img src="images/delete_icon.gif" width="10" height="10" border="0" alt="Delete"></a> </td> </tr> <?php } } html_end_box(); }
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 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 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 }
| This program is distributed in the hope that it will be useful, | | but WITHOUT ANY WARRANTY; without even the implied warranty of | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | | GNU General Public License for more details. | +-------------------------------------------------------------------------+ | Cacti: The Complete RRDTool-based Graphing Solution | +-------------------------------------------------------------------------+ | This code is designed, written, and maintained by the Cacti Group. See | | about.php and/or the AUTHORS file for specific developer information. | +-------------------------------------------------------------------------+ | http://www.cacti.net/ | +-------------------------------------------------------------------------+ */ include "./include/auth.php"; include "./include/top_header.php"; html_start_box("<strong>About Cacti</strong>", "100%", $colors["header"], "3", "center", ""); ?> <tr> <td bgcolor="#<?php print $colors["header_panel"]; ?> " colspan="2"> <strong><font color="#<?php print $colors["header_text"]; ?> ">Version <?php print $config["cacti_version"]; ?> </font></strong> </td>
function template() { $menu_items = array("remove" => "Remove", "duplicate" => "Duplicate"); $filter_array = array(); /* search field: filter (searches template name) */ if (isset_get_var("search_filter")) { $filter_array["template_name"] = get_get_var("search_filter"); } /* get a list of all data templates on this page */ $data_templates = api_data_template_list($filter_array); /* get a list of data input types for display in the data sources list */ $data_input_types = api_data_source_input_type_list(); form_start("data_templates.php"); $box_id = "1"; html_start_box("<strong>" . _("Data Templates") . "</strong>", "data_templates.php?action=edit"); html_header_checkbox(array(_("Template Name"), _("Data Input Type"), _("Status")), $box_id); $i = 0; if (sizeof($data_templates) > 0) { foreach ($data_templates as $data_template) { ?> <tr class="item" id="box-<?php echo $box_id; ?> -row-<?php echo $data_template["id"]; ?> " onClick="display_row_select('<?php echo $box_id; ?> ',document.forms[0],'box-<?php echo $box_id; ?> -row-<?php echo $data_template["id"]; ?> ', 'box-<?php echo $box_id; ?> -chk-<?php echo $data_template["id"]; ?> ')" onMouseOver="display_row_hover('box-<?php echo $box_id; ?> -row-<?php echo $data_template["id"]; ?> ')" onMouseOut="display_row_clear('box-<?php echo $box_id; ?> -row-<?php echo $data_template["id"]; ?> ')"> <td class="title"> <a onClick="display_row_block('box-<?php echo $box_id; ?> -row-<?php echo $data_template["id"]; ?> ')" href="data_templates.php?action=edit&id=<?php echo $data_template["id"]; ?> "><span id="box-<?php echo $box_id; ?> -text-<?php echo $data_template["id"]; ?> "><?php echo html_highlight_words(get_get_var("search_filter"), $data_template["template_name"]); ?> </span></a> </td> <td> <?php echo $data_input_types[$data_template["data_input_type"]]; ?> </td> <td> <?php if ($data_template["active"] == "1") { echo _("Active"); } else { echo _("Disabled"); } ?> </td> <td class="checkbox" align="center"> <input type='checkbox' name='box-<?php echo $box_id; ?> -chk-<?php echo $data_template["id"]; ?> ' id='box-<?php echo $box_id; ?> -chk-<?php echo $data_template["id"]; ?> ' title="<?php echo $data_template["template_name"]; ?> "> </td> </tr> <?php } } else { ?> <tr class="empty"> <td colspan="6"> No data templates found. </td> </tr> <?php } html_box_toolbar_draw($box_id, "0", "3", HTML_BOX_SEARCH_NO_ICON); html_end_box(false); html_box_actions_menu_draw($box_id, "0", $menu_items); html_box_actions_area_create($box_id); form_hidden_box("action_post", "data_template_list"); form_end(); ?> <script language="JavaScript"> <!-- function action_area_handle_type(box_id, type, parent_div, parent_form) { if (type == 'remove') { parent_div.appendChild(document.createTextNode('Are you sure you want to remove these data templates?')); parent_div.appendChild(action_area_generate_selected_rows(box_id)); action_area_update_header_caption(box_id, 'Remove Data Template'); action_area_update_submit_caption(box_id, 'Remove'); action_area_update_selected_rows(box_id, parent_form); }else if (type == 'duplicate') { parent_div.appendChild(document.createTextNode('Are you sure you want to duplicate these data templates?')); parent_div.appendChild(action_area_generate_selected_rows(box_id)); parent_div.appendChild(action_area_generate_input('text', 'box-' + box_id + '-action-area-txt1', '')); action_area_update_header_caption(box_id, 'Duplicate Data Templates'); action_area_update_submit_caption(box_id, 'Duplicate'); action_area_update_selected_rows(box_id, parent_form); } } --> </script> <?php }
function item_edit() { global $colors, $struct_graph_item, $graph_item_types, $consolidation_functions; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("id")); input_validate_input_number(get_request_var_request("local_graph_id")); input_validate_input_number(get_request_var_request("host_id")); /* ==================================================== */ /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { kill_session_var("sess_ds_host_id"); unset($_REQUEST["host_id"]); } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("filter", "sess_ds_filter", ""); load_current_session_value("host_id", "sess_ds_host_id", "-1"); $host = db_fetch_row("select hostname from host where id=" . $_REQUEST["host_id"]); html_start_box("<strong>Data Source by Host</strong> [host: " . (empty($host["hostname"]) ? "No Host" : $host["hostname"]) . "]", "98%", $colors["header"], "3", "center", ""); include("./include/html/inc_graph_items_filter_table.php"); html_end_box(); if ($_REQUEST["host_id"] == "-1") { $sql_where = ""; }elseif ($_REQUEST["host_id"] == "0") { $sql_where = " and data_local.host_id=0"; }elseif (!empty($_REQUEST["host_id"])) { $sql_where = " and data_local.host_id=" . $_REQUEST["host_id"]; } if (!empty($_REQUEST["id"])) { $template_item = db_fetch_row("select * from graph_templates_item where id=" . $_REQUEST["id"]); $host_id = db_fetch_cell("select host_id from graph_local where id=" . $_REQUEST["local_graph_id"]); } $header_label = "[edit graph: " . db_fetch_cell("select title_cache from graph_templates_graph where local_graph_id=" . $_REQUEST["local_graph_id"]) . "]"; html_start_box("<strong>Graph Items</strong> $header_label", "98%", $colors["header"], "3", "center", ""); /* by default, select the LAST DS chosen to make everyone's lives easier */ if (!empty($_REQUEST["local_graph_id"])) { $default = db_fetch_row("select task_item_id from graph_templates_item where local_graph_id=" . $_REQUEST["local_graph_id"] . " order by sequence DESC"); if (sizeof($default) > 0) { $struct_graph_item["task_item_id"]["default"] = $default["task_item_id"]; }else{ $struct_graph_item["task_item_id"]["default"] = 0; } /* modifications to the default graph items array */ $struct_graph_item["task_item_id"]["sql"] = "select CONCAT_WS('',data_template_data.name_cache,' (',data_template_rrd.data_source_name,')') as name, data_template_rrd.id from data_template_data,data_template_rrd,data_local left join host on data_local.host_id=host.id where data_template_rrd.local_data_id=data_local.id and data_template_data.local_data_id=data_local.id " . (((!empty($host_id)) || (!empty($_REQUEST["host_id"]))) ? (!empty($host_id) ? " and data_local.host_id=$host_id" : " and data_local.host_id=" . $_REQUEST["host_id"]) : "") . " order by name"; } $form_array = array(); while (list($field_name, $field_array) = each($struct_graph_item)) { $form_array += array($field_name => $struct_graph_item[$field_name]); $form_array[$field_name]["value"] = (isset($template_item) ? $template_item[$field_name] : ""); $form_array[$field_name]["form_id"] = (isset($template_item) ? $template_item["id"] : "0"); } draw_edit_form( array( "config" => array( ), "fields" => $form_array ) ); form_hidden_box("local_graph_id", $_REQUEST["local_graph_id"], "0"); form_hidden_box("graph_template_item_id", (isset($template_item) ? $template_item["id"] : "0"), ""); form_hidden_box("local_graph_template_item_id", (isset($template_item) ? $template_item["local_graph_template_item_id"] : "0"), ""); form_hidden_box("graph_template_id", (isset($template_item) ? $template_item["graph_template_id"] : "0"), ""); form_hidden_box("sequence", (isset($template_item) ? $template_item["sequence"] : "0"), ""); form_hidden_box("_graph_type_id", (isset($template_item) ? $template_item["graph_type_id"] : "0"), ""); form_hidden_box("save_component_item", "1", ""); html_end_box(); form_save_button("graphs.php?action=graph_edit&id=" . $_REQUEST["local_graph_id"]); }
function graphs() { global $colors; /* use the first host in the list as the default */ if (!isset($_SESSION["sess_graphs_new_host_id"]) && empty($_REQUEST["host_id"])) { $_REQUEST["host_id"] = db_fetch_cell("select id from host order by description,hostname limit 1"); } /* remember these search fields in session vars so we don't have to keep passing them around */ if (isset($_REQUEST["host_id"])) { $_SESSION["sess_graphs_new_host_id"] = $_REQUEST["host_id"]; } else { $_REQUEST["host_id"] = $_SESSION["sess_graphs_new_host_id"]; } $host = db_fetch_row("select id,description,hostname,host_template_id from host where id=" . $_REQUEST["host_id"]); ?> <table width="98%" align="center"> <form name="form_graph_id"> <tr> <td class="textInfo" colspan="2"> <?php print $host["description"]; ?> (<?php print $host["hostname"]; ?> ) </td> <td align="right" class="textInfo" style="color: #aaaaaa;"> <?php if (!empty($host["host_template_id"])) { print db_fetch_cell("select name from host_template where id=" . $host["host_template_id"]); } ?> </td> </tr> <tr> <td> </td> </tr> <tr> <td class="textArea" style="padding: 3px;" width="300" nowrap> <?php echo _("Create new graphs for the following host:"); ?> </td> <td class="textInfo" rowspan="2" valign="top"> <span style="color: #c16921;">*</span><a href="devices.php?action=edit&id=<?php print $_REQUEST["host_id"]; ?> "><?php echo _("Edit this Host"); ?> </a><br> <span style="color: #c16921;">*</span><a href="devices.php?action=edit"><?php echo _("Create New Host"); ?> </a> </td> </tr> <td> <select name="cbo_graph_id" onChange="window.location=document.form_graph_id.cbo_graph_id.options[document.form_graph_id.cbo_graph_id.selectedIndex].value"> <?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='graphs_new.php?host_id=" . $item["id"] . "'"; if ($_REQUEST["host_id"] == $item["id"]) { print " selected"; } print ">" . $item["name"] . "</option>\n"; } } ?> </select> </td> </tr> </form> </table> <br> <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"])); /* we give users the option to turn off the javascript features for data queries with lots of rows */ if (read_config_option("max_data_query_javascript_rows") >= $total_rows) { $use_javascript = true; } else { $use_javascript = false; } /* ==================== Box: Graph Templates ==================== */ html_start_box("<strong>" . _("Graph Templates") . "</strong>", "98%", $colors["header_background"], "3", "center", ""); print "\t<tr bgcolor='#" . $colors["header_panel"] . "'>\n\t\t\t<td class='textSubHeaderDark'>" . _("Name") . "</td>\n\t\t\t<td width='1%' align='center' bgcolor='#819bc0' 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</tr>\n"; $ht_graph_templates = db_fetch_assoc("select\n\t\tgraph_template.id,\n\t\tgraph_template.template_name\n\t\tfrom host_graph,graph_template\n\t\twhere host_graph.graph_template_id=graph_template.id\n\t\tand host_graph.host_id = " . $_REQUEST["host_id"] . "\n\t\torder by graph_template.template_name"); $ht_created_graph_templates = db_fetch_assoc("select\n\t\tgraph.graph_template_id\n\t\tfrom graph,host_graph\n\t\twhere graph.graph_template_id=host_graph.graph_template_id\n\t\tand graph.host_id = " . $host["id"] . "\n\t\tgroup by graph.graph_template_id"); print "<script type='text/javascript'>\nvar gt_created_graphs = new Array()\n</script>\n"; if (sizeof($ht_created_graph_templates) > 0 && $use_javascript == true) { print "<script type='text/javascript'>\n<!--\n"; print "var gt_created_graphs = new Array("; $cg_ctr = 0; foreach ($ht_created_graph_templates as $item) { print ($cg_ctr > 0 ? "," : "") . "'" . $item["graph_template_id"] . "'"; $cg_ctr++; } print ")\n"; print "//-->\n</script>\n"; } /* create a row for each graph template associated with the host template */ $i = 0; if (sizeof($ht_graph_templates) > 0) { foreach ($ht_graph_templates as $item) { $query_row = $item["id"]; print "<tr id='gt_line{$query_row}' bgcolor='#" . ($i % 2 == 0 ? $colors["form_alternate1"] : $colors["form_alternate2"]) . "'>"; $i++; print "\t\t<td" . ($use_javascript == true ? " onClick='gt_select_line(" . $item["id"] . ");'" : "") . "><span id='gt_text{$query_row}" . "_0'>\n\t\t\t\t\t\t<span id='gt_text{$query_row}" . "_0'><strong>" . _("Create:") . "</strong> " . $item["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}'" . ($use_javascript == true ? " onClick='gt_update_selection_indicators();'" : "") . ">\n\t\t\t\t\t</td>\n\t\t\t\t</tr>"; } } else { print "<tr><td bgcolor='#" . $colors["form_alternate1"] . "' colspan=7><em>" . _("No graph templates specified for this host template.") . "</em></td></tr>"; } if ($use_javascript == true) { print "<script type='text/javascript'>gt_update_deps(1);</script>\n"; } $available_graph_templates = db_fetch_assoc("SELECT\n\t\tgraph_template.id,\n\t\tgraph_template.template_name as name\n\t\tFROM snmp_query_graph RIGHT JOIN graph_template\n\t\tON (snmp_query_graph.graph_template_id = graph_template.id)\n\t\tWHERE (((snmp_query_graph.name) Is Null))\n\t\tORDER BY graph_template.template_name"); /* create a row at the bottom that lets the user create any graph they choose */ print "\t<tr bgcolor='#" . ($i % 2 == 0 ? $colors["form_alternate1"] : $colors["form_alternate2"]) . "'>\n\t\t\t<td colspan='2' width='60' nowrap>\n\t\t\t\t<strong>Create:</strong> "; form_dropdown("cg_g", $available_graph_templates, "name", "id", "", "(" . _("Select a graph type to create") . ")", "", "font-size: 10px;"); print "\t\t</td>\n\t\t</tr>"; html_end_box(); /* get a list of all data queries that are assigned to this device */ $data_queries = api_data_query_device_assigned_list($host["id"]); echo "<script type='text/javascript'>\nvar created_graphs = new Array()\n</script>\n"; if (sizeof($data_queries) > 0) { foreach ($data_queries as $data_query) { /* we give users the option to turn off the javascript features for data queries with lots of rows */ if (read_config_option("max_data_query_javascript_rows") >= api_data_query_cache_num_rows_get($data_query["id"], $host["id"])) { $use_javascript = true; } else { $use_javascript = false; } /* get a list of all graph templates that reference this data query */ $attached_graph_templates = api_data_query_attached_graphs_list($data_query["id"]); /* build a javascript array that keeps tracks of which graphs have already been created */ if (sizeof($attached_graph_templates) > 0 && $use_javascript == true) { echo "<script type='text/javascript'>\n<!--\n"; foreach ($attached_graph_templates as $graph_template) { /* get a list of all data query indexes that have been created as graphs using this graph template */ $created_graphs = api_data_query_graphed_indexes_list($graph_template["id"], $host["id"]); echo "created_graphs[" . $graph_template["id"] . "] = new Array("; $cg_ctr = 0; if (sizeof($created_graphs) > 0) { foreach ($created_graphs as $created_graph) { echo ($cg_ctr > 0 ? "," : "") . "'" . encode_data_query_index($created_graph["data_query_index"]) . "'"; $cg_ctr++; } } echo ")\n"; } echo "//-->\n</script>\n"; } $data_query_indexes = array(); $data_query_field_names = array(); $data_query_field_desc = array(); $num_visible_columns = 0; $data_query_fields = api_data_query_field_list($data_query["id"], DATA_QUERY_FIELD_TYPE_INPUT); /* retrieve a list of values for each data query field from the cache */ if (sizeof($data_query_fields) > 0) { foreach ($data_query_fields as $field) { $cache_data = api_data_query_cache_field_get($data_query["id"], $host["id"], $field["name"]); /* be sure to ignore the fields which contain no data */ if (sizeof($cache_data) > 0) { foreach ($cache_data as $row) { $data_query_data[$row["index_value"]][$field["name"]] = $row["field_value"]; if (!in_array($row["index_value"], $data_query_indexes, true)) { $data_query_indexes[] = $row["index_value"]; } } /* always make sure that the index field is the first column */ if ($data_query["index_field_id"] == $field["id"] && sizeof($data_query_field_names) > 0) { $data_query_field_names[] = $data_query_field_names[0]; $data_query_field_names[0] = $field["name"]; } else { $data_query_field_names[] = $field["name"]; } /* keep a hash of field name->desc mappings for the row headings */ $data_query_field_desc[$field["name"]] = $field["name_desc"]; $num_visible_columns++; } } } /* if the user specified a prefered sort order; sort the list of indexes before displaying them */ if ($data_query["index_order_type"] == DATA_QUERY_INDEX_SORT_TYPE_ALPHABETIC) { usort($data_query_indexes, "usort_alphabetic"); } else { if ($data_query["index_order_type"] == DATA_QUERY_INDEX_SORT_TYPE_NATURAL) { usort($data_query_indexes, "usort_natural"); } else { if ($data_query["index_order_type"] == DATA_QUERY_INDEX_SORT_TYPE_NUMERIC) { usort($data_query_indexes, "usort_numeric"); } } } ?> <table width='98%' style='background-color: #<?php echo $colors["form_alternate2"]; ?> ; border: 1px solid #<?php echo $colors["header_background"]; ?> ;' align='center' cellpadding='3' cellspacing='0'> <tr> <td bgcolor='#<?php echo $colors["header_background"]; ?> ' colspan='<?php echo sizeof($data_query_field_names) + 1; ?> '> <table cellspacing='0' cellpadding='0' width='100%' > <tr> <td class='textHeaderDark'> <strong><?php echo _("Data Query"); ?> </strong> [<?php echo $data_query["name"]; ?> ] </td> <td align='right' nowrap> <a href='graphs_new.php?action=query_reload&id=<?php echo $data_query["id"]; ?> &host_id=<?php echo $host["id"]; ?> '><img src='<?php echo html_get_theme_images_path("reload_icon_small.gif"); ?> ' alt='<?php echo _("Reload Associated Query"); ?> ' border='0' align='absmiddle'></a> </td> </tr> </table> </td> </tr> <?php if (sizeof($attached_graph_templates) == 0) { echo "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td>" . _("This data query is not being used by any graph templates. You must create at least one graph template that references to a data template using this data query.") . "</td></tr>\n"; } else { if (sizeof($data_query_field_names) == 0) { echo "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td>" . _("This data query returned 0 rows, perhaps there was a problem executing this data query. You can") . " <a href='devices.php?action=query_verbose&id=" . $data_query["id"] . "&host_id=" . $host["id"] . "'>" . _("run this data query in debug mode</a> to get more information.") . "</td></tr>\n"; } else { echo "<tr bgcolor='#" . $colors["header_panel_background"] . "'>\n"; foreach ($data_query_field_names as $field_name) { echo "<td height='1'><strong><font color='#" . $colors["header_text"] . "'>" . $data_query_field_desc[$field_name] . "</font></strong></td>\n"; } echo "<td width='1%' align='center' bgcolor='#" . $colors["header_panel_background"] . "' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_" . $data_query["id"] . "' title='Select All' onClick='" . _("SelectAll") . "(\"sg_" . $data_query["id"] . "\",this.checked);" . ($use_javascript == true ? "dq_update_selection_indicators();" : "") . "'></td>\n</tr>\n"; } } $row_counter = 0; foreach ($data_query_indexes as $index_value) { $query_row = $data_query["id"] . "_" . encode_data_query_index($index_value); echo "<tr id='line{$query_row}' bgcolor='#" . ($row_counter % 2 == 0 ? $colors["form_alternate1"] : $colors["form_alternate2"]) . "'>"; $i++; $column_counter = 0; foreach ($data_query_field_names as $field_name) { echo "<td " . ($use_javascript == true ? "onClick='dq_select_line(" . $data_query["id"] . ",\"" . encode_data_query_index($index_value) . "\");'" : "") . "><span id='text{$query_row}" . "_" . $column_counter . "'>" . (isset($data_query_data[$index_value][$field_name]) ? $data_query_data[$index_value][$field_name] : "") . "</span></td>"; $column_counter++; } echo "<td align='right'>"; echo "<input type='checkbox' name='sg_{$query_row}' id='sg_{$query_row}' " . ($use_javascript == true ? "onClick='dq_update_selection_indicators();'" : "") . ">"; echo "</td>"; echo "</tr>\n"; $row_counter++; } echo "</table>"; if (sizeof($attached_graph_templates) == 1) { form_hidden_box("sgg_" . $data_query["id"] . "' id='sgg_" . $data_query["id"], $attached_graph_templates[0]["id"], ""); } elseif (sizeof($attached_graph_templates) > 1) { print "\t<table align='center' width='98%'>\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='" . html_get_theme_images_path("arrow.gif") . "' alt='' align='absmiddle'> \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_" . $data_query["id"] . "' id='sgg_" . $data_query["id"] . "' " . ($use_javascript == true ? "onChange='dq_update_deps(" . $data_query["id"] . "," . $num_visible_columns . ");'" : "") . ">\n\t\t\t\t\t\t\t\t\t"; html_create_list($attached_graph_templates, "template_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>"; if ($use_javascript == true) { print "<script type='text/javascript'>dq_update_deps(" . $data_query["id"] . "," . $num_visible_columns . ");</script>\n"; } } } form_hidden_box("save_component_graph", "1", ""); form_hidden_box("host_id", $host["id"], "0"); form_save_button("graphs_new.php"); print "<script type='text/javascript'>dq_update_selection_indicators();</script>\n"; print "<script type='text/javascript'>gt_update_selection_indicators();</script>\n"; }
function package() { $menu_items = array( "remove" => "Remove", "duplicate" => "Duplicate" ); $filter_array = array(); /* search field: filter (searches package name) */ if (isset_get_var("search_filter")) { $filter_array["name"] = get_get_var("search_filter"); } /* get a list of all packages on this page */ $packages = api_package_list($filter_array); form_start("packages.php"); $box_id = "1"; html_start_box("<strong>" . _("Template Packages") . "</strong>", "packages.php?action=new"); html_header_checkbox(array(_("Name"), _("Author"), _("Category")), $box_id); $i = 0; if (sizeof($packages) > 0) { foreach ($packages as $package) { ?> <tr class="item" id="box-<?php echo $box_id;?>-row-<?php echo $package["id"];?>" onClick="display_row_select('<?php echo $box_id;?>',document.forms[0],'box-<?php echo $box_id;?>-row-<?php echo $package["id"];?>', 'box-<?php echo $box_id;?>-chk-<?php echo $package["id"];?>')" onMouseOver="display_row_hover('box-<?php echo $box_id;?>-row-<?php echo $package["id"];?>')" onMouseOut="display_row_clear('box-<?php echo $box_id;?>-row-<?php echo $package["id"];?>')"> <td class="title"> <a onClick="display_row_block('box-<?php echo $box_id;?>-row-<?php echo $package["id"];?>')" href="packages.php?action=view&id=<?php echo $package["id"];?>"><span id="box-<?php echo $box_id;?>-text-<?php echo $package["id"];?>"><?php echo html_highlight_words(get_get_var("search_filter"), $package["name"]);?></span></a> </td> <td> Ian Berry </td> <td> <?php echo $package["category"];?> </td> <td class="checkbox" align="center"> <input type='checkbox' name='box-<?php echo $box_id;?>-chk-<?php echo $package["id"];?>' id='box-<?php echo $box_id;?>-chk-<?php echo $package["id"];?>' title="<?php echo $package["name"];?>"> </td> </tr> <?php } }else{ ?> <tr class="empty"> <td colspan="6"> No template packages found. </td> </tr> <?php } html_box_toolbar_draw($box_id, "0", "3", HTML_BOX_SEARCH_NONE); html_end_box(false); //html_box_actions_menu_draw($box_id, "0", $menu_items); html_box_actions_area_create($box_id); form_hidden_box("action_post", "package_list"); form_end(); echo "<br />\n"; form_start("packages.php", "import_package", true); html_start_box("<strong>" . _("Import Package") . "</strong>"); _package_import_field__file("import_package_file"); _package_import_field__text("import_package_text"); ?> <tr> <td style="border-top: 1px solid #b5b5b5; padding: 1px;" colspan="2"> <table width="100%" cellpadding="2" cellspacing="0"> <tr> <td align="right"> <input type="image" src="<?php echo html_get_theme_images_path('button_import.gif');?>" alt="<?php echo _('Import');?>" name="package_import" align="absmiddle"> </td> </tr> </table> </td> </tr> <?php html_end_box(); form_hidden_box("action", "save"); form_hidden_box("action_post", "package_import"); form_end(); //print_a(htmlspecialchars(package_export("1"))); ?> <script language="JavaScript"> <!-- function action_area_handle_type(box_id, type, parent_div, parent_form) { if (type == 'remove') { parent_div.appendChild(document.createTextNode('Are you sure you want to remove these data templates?')); parent_div.appendChild(action_area_generate_selected_rows(box_id)); action_area_update_header_caption(box_id, 'Remove Data Template'); action_area_update_submit_caption(box_id, 'Remove'); action_area_update_selected_rows(box_id, parent_form); }else if (type == 'duplicate') { parent_div.appendChild(document.createTextNode('Are you sure you want to duplicate these data templates?')); parent_div.appendChild(action_area_generate_selected_rows(box_id)); parent_div.appendChild(action_area_generate_input('text', 'box-' + box_id + '-action-area-txt1', '')); action_area_update_header_caption(box_id, 'Duplicate Data Templates'); action_area_update_submit_caption(box_id, 'Duplicate'); action_area_update_selected_rows(box_id, parent_form); } } --> </script> <?php }
function item_edit() { global $colors, $struct_graph_item, $graph_item_types, $consolidation_functions; /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); input_validate_input_number(get_request_var("graph_template_id")); /* ==================================================== */ $header_label = "[edit graph: " . db_fetch_cell("select name from graph_templates where id=" . $_GET["graph_template_id"]) . "]"; html_start_box("<strong>Graph Template Items</strong> $header_label", "100%", $colors["header"], "3", "center", ""); if (!empty($_GET["id"])) { $template_item = db_fetch_row("select * from graph_templates_item where id=" . $_GET["id"]); } /* by default, select the LAST DS chosen to make everyone's lives easier */ if (!empty($_GET["graph_template_id"])) { $default = db_fetch_row("select task_item_id from graph_templates_item where graph_template_id=" . $_GET["graph_template_id"] . " and local_graph_id=0 order by sequence DESC"); if (sizeof($default) > 0) { $struct_graph_item["task_item_id"]["default"] = $default["task_item_id"]; }else{ $struct_graph_item["task_item_id"]["default"] = 0; } } /* modifications to the default graph items array */ $struct_graph_item["task_item_id"]["sql"] = "select CONCAT_WS('',data_template.name,' - ',' (',data_template_rrd.data_source_name,')') as name, data_template_rrd.id from (data_template_data,data_template_rrd,data_template) where data_template_rrd.data_template_id=data_template.id and data_template_data.data_template_id=data_template.id and data_template_data.local_data_id=0 and data_template_rrd.local_data_id=0 order by data_template.name,data_template_rrd.data_source_name"; $form_array = array(); while (list($field_name, $field_array) = each($struct_graph_item)) { $form_array += array($field_name => $struct_graph_item[$field_name]); $form_array[$field_name]["value"] = (isset($template_item) ? $template_item[$field_name] : ""); $form_array[$field_name]["form_id"] = (isset($template_item) ? $template_item["id"] : "0"); } if (!empty($_GET["id"])) { /* we want to mark the fields that are associated with a graph item input */ $graph_item_input_fields = db_fetch_assoc("select graph_template_input.id, graph_template_input.column_name from (graph_template_input,graph_template_input_defs) where graph_template_input.id=graph_template_input_defs.graph_template_input_id and graph_template_input.graph_template_id=" . $_GET["graph_template_id"] . " and graph_template_input_defs.graph_template_item_id=" . $_GET["id"] . " group by graph_template_input.column_name"); if (sizeof($graph_item_input_fields) > 0) { foreach ($graph_item_input_fields as $field) { $form_array{$field["column_name"]}["friendly_name"] .= " [<a href='graph_templates_inputs.php?action=input_edit&id=" . $field["id"] . "&graph_template_id=" . $_GET["graph_template_id"] . "'>Field Not Templated</a>]"; } } } draw_edit_form( array( "config" => array( ), "fields" => $form_array ) ); html_end_box(); form_hidden_box("graph_template_item_id", (isset($template_item) ? $template_item["id"] : "0"), ""); form_hidden_box("graph_template_id", $_GET["graph_template_id"], "0"); form_hidden_box("sequence", (isset($template_item) ? $template_item["sequence"] : "0"), ""); form_hidden_box("_graph_type_id", (isset($template_item) ? $template_item["graph_type_id"] : "0"), ""); form_hidden_box("_task_item_id", (isset($template_item) ? $template_item["task_item_id"] : "0"), ""); form_hidden_box("save_component_item", "1", ""); form_hidden_box("invisible_alpha", $form_array["alpha"]["value"], "FF"); form_hidden_box("rrdtool_version", read_config_option("rrdtool_version"), ""); form_save_button("graph_templates.php?action=template_edit&id=" . $_GET["graph_template_id"]); //Now we need some javascript to make it dynamic ?> <script language="JavaScript"> dynamic(); function dynamic() { //alert("RRDTool Version is '" + document.getElementById('rrdtool_version').value + "'"); //alert("Color is '" + document.getElementById('color_id').value + "'"); document.getElementById('alpha').disabled=true; if ((document.getElementById('rrdtool_version').value != 'rrd-1.0.x') && (document.getElementById('color_id').value != 0)) { document.getElementById('alpha').disabled=false; } } function changeColorId() { //alert("Selected Color Index is '" + document.getElementById('color_id').selectedIndex + "'"); if ((document.getElementById('rrdtool_version').value != 'rrd-1.0.x') && (document.getElementById('color_id').selectedIndex != 0)) { document.getElementById('alpha').disabled=false; } } </script> <?php }
function settings() { global $colors, $themes; $themes["default"] = _("System Default (Global Setting)"); /* you cannot have per-user settings if cacti's user management is not turned on */ if (read_config_option("auth_method") == "0") { raise_message(6); display_output_messages(); return; } /* get user settings */ $user = api_user_info( array( "id" => $_SESSION["sess_user_id"] ) ); print "<form method='post'>\n"; html_start_box("<strong>" . _("User Settings") . "</strong>", "98%", $colors["header_background"], "3", "center", ""); ?> <tr bgcolor='<?php print $colors["header_panel_background"];?>'> <td colspan='2' class='textSubHeaderDark' style='padding: 3px;'>General</td> </tr> <?php $form_array = array( "current_theme" => array( "friendly_name" => _("Visual Theme"), "description" => _("The Cacti theme to use. Changes the look of Cacti."), "method" => "drop_array", "array" => $themes, "value" => api_user_theme($_SESSION["sess_user_id"]), "default" => "default" ) ); draw_edit_form( array( "config" => array( "no_form_tag" => true ), "fields" => $form_array ) ); html_end_box(); form_hidden_box("save_component_user","1",""); form_save_button((isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : "index.php"), "save"); }
function tree() { global $colors; html_start_box("<strong>Graph Trees</strong>", "100%", $colors["header"], "3", "center", "tree.php?action=edit"); print "<tr bgcolor='#" . $colors["header_panel"] . "'>"; DrawMatrixHeaderItem("Name",$colors["header_text"],1); DrawMatrixHeaderItem(" ",$colors["header_text"],1); print "</tr>"; $trees = db_fetch_assoc("SELECT * FROM graph_tree ORDER BY name"); $i = 0; if (sizeof($trees) > 0) { foreach ($trees as $tree) { form_alternate_row_color($colors["alternate"],$colors["light"],$i); $i++; ?> <td> <a class="linkEditMain" href="tree.php?action=edit&id=<?php print $tree["id"];?>"><?php print $tree["name"];?></a> </td> <td align="right"> <a href="tree.php?action=remove&id=<?php print $tree["id"];?>"><img src="images/delete_icon.gif" width="10" height="10" border="0" alt="Delete"></a> </td> </tr> <?php } }else{ print "<tr><td><em>No Graphs Trees</em></td></tr>\n"; } html_end_box(); }
function utilities() { html_start_box("<strong>Cacti System Utilities</strong>", "100%", "", "3", "center", ""); ?> <colgroup span="3"> <col valign="top" width="20%"></col> <col valign="top" width="80%"></col> </colgroup> <?php html_header(array("Technical Support"), 2); form_alternate_row(); ?> <td class="textArea"> <a href='<?php print htmlspecialchars("utilities.php?action=view_tech"); ?> '>Technical Support</a> </td> <td class="textArea"> Cacti technical support page. Used by developers and technical support persons to assist with issues in Cacti. Includes checks for common configuration issues. </td> </tr> <?php html_header(array("Log Administration"), 2); form_alternate_row(); ?> <td class="textArea"> <a href='<?php print htmlspecialchars("utilities.php?action=view_logfile"); ?> '>View Cacti Log File</a> </td> <td class="textArea"> The Cacti Log File stores statistic, error and other message depending on system settings. This information can be used to identify problems with the poller and application. </td> </tr> <?php form_alternate_row(); ?> <td class="textArea"> <a href='<?php print htmlspecialchars("utilities.php?action=view_user_log"); ?> '>View User Log</a> </td> <td class="textArea"> Allows Administrators to browse the user log. Administrators can filter and export the log as well. </td> </tr> <?php html_header(array("Poller Cache Administration"), 2); form_alternate_row(); ?> <td class="textArea"> <a href='<?php print htmlspecialchars("utilities.php?action=view_poller_cache"); ?> '>View Poller Cache</a> </td> <td class="textArea"> This is the data that is being passed to the poller each time it runs. This data is then in turn executed/interpreted and the results are fed into the rrd files for graphing or the database for display. </td> </tr> <?php form_alternate_row(); ?> <td class="textArea"> <a href='<?php print htmlspecialchars("utilities.php?action=view_snmp_cache"); ?> '>View SNMP Cache</a> </td> <td class="textArea"> The SNMP cache stores information gathered from SNMP queries. It is used by cacti to determine the OID to use when gathering information from an SNMP-enabled host. </td> </tr> <?php form_alternate_row(); ?> <td class="textArea"> <a href='<?php print htmlspecialchars("utilities.php?action=clear_poller_cache"); ?> '>Rebuild Poller Cache</a> </td> <td class="textArea"> The poller cache will be cleared and re-generated if you select this option. Sometimes host/data source data can get out of sync with the cache in which case it makes sense to clear the cache and start over. </td> </tr> <?php api_plugin_hook('utilities_list'); html_end_box(); }
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 mactrack_view() { global $title, $colors, $mactrack_rows, $config; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("rows")); input_validate_input_number(get_request_var_request("page")); input_validate_input_number(get_request_var_request("issues")); input_validate_input_number(get_request_var_request("bwusage")); input_validate_input_number(get_request_var_request("device")); input_validate_input_number(get_request_var_request("site")); input_validate_input_number(get_request_var_request("type")); /* ==================================================== */ /* clean up filter */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* clean up totals */ if (isset($_REQUEST["totals"])) { $_REQUEST["totals"] = sanitize_search_string(get_request_var("totals")); } /* clean up */ if (isset($_REQUEST["sort_column"])) { $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column")); } /* clean up */ 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"]) || isset($_REQUEST["reset"])) { kill_session_var("sess_mactrack_int_current_page"); kill_session_var("sess_mactrack_int_rows"); kill_session_var("sess_mactrack_int_totals"); kill_session_var("sess_mactrack_int_device_id"); kill_session_var("sess_mactrack_int_state"); kill_session_var("sess_mactrack_int_site"); kill_session_var("sess_mactrack_int_device"); kill_session_var("sess_mactrack_int_issues"); kill_session_var("sess_mactrack_int_bwusage"); kill_session_var("sess_mactrack_int_type"); kill_session_var("sess_mactrack_int_period"); kill_session_var("sess_mactrack_int_filter"); kill_session_var("sess_mactrack_int_sort_column"); kill_session_var("sess_mactrack_int_sort_direction"); $_REQUEST["page"] = 1; if (isset($_REQUEST["clear_x"])) { unset($_REQUEST["device_id"]); unset($_REQUEST["totals"]); unset($_REQUEST["state"]); unset($_REQUEST["site"]); unset($_REQUEST["totals"]); unset($_REQUEST["device"]); unset($_REQUEST["issues"]); unset($_REQUEST["bwusage"]); unset($_REQUEST["type"]); unset($_REQUEST["period"]); unset($_REQUEST["filter"]); unset($_REQUEST["rows"]); unset($_REQUEST["sort_column"]); unset($_REQUEST["sort_direction"]); } }else{ /* if any of the settings changed, reset the page number */ $changed = 0; $changed += mactrack_check_changed("device_id", "sess_mactrack_int_device_id"); $changed += mactrack_check_changed("site", "sess_mactrack_int_site"); $changed += mactrack_check_changed("totals", "sess_mactrack_int_totals"); $changed += mactrack_check_changed("device", "sess_mactrack_int_device"); $changed += mactrack_check_changed("issues", "sess_mactrack_int_issues"); $changed += mactrack_check_changed("bwusage", "sess_mactrack_int_bwusage"); $changed += mactrack_check_changed("type", "sess_mactrack_int_type"); $changed += mactrack_check_changed("period", "sess_mactrack_int_period"); $changed += mactrack_check_changed("filter", "sess_mactrack_int_filter"); $changed += mactrack_check_changed("rows", "sess_mactrack_int_rows"); $changed += mactrack_check_changed("sort_column", "sess_mactrack_int_sort_column"); $changed += mactrack_check_changed("sort_direction", "sess_mactrack_int_sort_direction"); if ($changed) { $_REQUEST["page"] = "1"; } } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("page", "sess_mactrack_int_current_page", "1"); load_current_session_value("totals", "sess_mactrack_int_totals", "on"); load_current_session_value("rows", "sess_mactrack_int_rows", read_config_option("num_rows_device")); load_current_session_value("device_id", "sess_mactrack_int_device_id", "-1"); load_current_session_value("site", "sess_mactrack_int_site", "-1"); load_current_session_value("issues", "sess_mactrack_int_issues", "-3"); load_current_session_value("bwusage", "sess_mactrack_int_bwusage", read_config_option("mactrack_interface_high")); load_current_session_value("type", "sess_mactrack_int_type", "-1"); load_current_session_value("device", "sess_mactrack_int_device", "-1"); load_current_session_value("period", "sess_mactrack_int_period", "-2"); load_current_session_value("filter", "sess_mactrack_int_filter", ""); load_current_session_value("sort_column", "sess_mactrack_int_sort_column", "device_name"); load_current_session_value("sort_direction", "sess_mactrack_int_sort_direction", "DESC"); include_once("./plugins/mactrack/general_header.php"); print "<script type='text/javascript' src='" . $config["url_path"] . "plugins/mactrack/mactrack.js'></script>"; $sql_where = ""; if ($_REQUEST["rows"] == -1) { $row_limit = read_config_option("num_rows_device"); }elseif ($_REQUEST["rows"] == -2) { $row_limit = 99999999; }else{ $row_limit = $_REQUEST["rows"]; } $stats = mactrack_get_records($sql_where, TRUE, $row_limit); mactrack_tabs(); html_start_box("<strong>Scanned Device Interfaces</strong>", "100%", $colors["header"], "3", "center", ""); mactrack_filter_table(); html_end_box(); //Last device restart: if ($_REQUEST["device"]!=-1){ html_start_box("", "100%", $colors["header"], "3", "center", ""); print "<tr>"; if (sizeof($stats)>0) $last_run_time = max(strtotime($stats[0]["last_up_time"]),strtotime($stats[0]["last_down_time"])); else $last_run_time = read_config_option("mt_last_run_time", TRUE); $diff = strtotime("now") - $last_run_time; $upTime = ($stats[0]["sysUptime"]/100) + $diff; $days = intval($upTime / (60*60*24)); $remainder = $upTime % (60*60*24); $hours = intval($remainder / (60*60)); $remainder = $remainder % (60*60); $minutes = intval($remainder / (60)); $upTime = $days . "d:" . $hours . "h:" . $minutes . "m"; print "<td style='text-align:right'><strong>Last device restart:</strong> ".$upTime."</td>"; print "</tr>"; html_end_box(false); } html_start_box("", "100%", $colors["header"], "3", "center", ""); $rows_query_string = "SELECT COUNT(*) FROM mac_track_interfaces INNER JOIN mac_track_devices ON mac_track_interfaces.device_id=mac_track_devices.device_id INNER JOIN mac_track_device_types ON mac_track_device_types.device_type_id=mac_track_devices.device_type_id $sql_where"; //echo $rows_query_string; $total_rows = db_fetch_cell($rows_query_string); /* generate page list */ if ($total_rows > 0) { $url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, $row_limit, $total_rows, "mactrack_view_interfaces.php?report=interfaces"); $nav = "<tr bgcolor='#" . $colors["header"] . "' class='noprint'> <td colspan='22'> <table width='100%' cellspacing='0' cellpadding='0' border='0'> <tr> <td align='left' class='textHeaderDark'> <strong><< "; if ($_REQUEST["page"] > 1) { $nav .= "<a class='linkOverDark' href='mactrack_view_interfaces.php?page=" . ($_REQUEST["page"]-1) . "'>"; } $nav .= "Previous"; if ($_REQUEST["page"] > 1) { $nav .= "</a>"; } $nav .= "</strong> </td>\n <td align='center' class='textHeaderDark'> Showing Rows " . (($row_limit*($_REQUEST["page"]-1))+1) . " to " . ((($total_rows < $row_limit) || ($total_rows < ($row_limit*$_REQUEST["page"]))) ? $total_rows : ($row_limit*$_REQUEST["page"])) . " of $total_rows [$url_page_select] </td>\n <td align='right' class='textHeaderDark'> <strong>"; if (($_REQUEST["page"] * $row_limit) < $total_rows) { $nav .= "<a class='linkOverDark' href='mactrack_view_interfaces.php?page=" . ($_REQUEST["page"]+1) . "'>"; } $nav .= "Next"; if (($_REQUEST["page"] * $row_limit) < $total_rows) { $nav .= "</a>"; } $nav .= " >></strong> </td>\n </tr> </table> </td> </tr>\n"; }else{ $nav = "<tr bgcolor='#" . $colors["header"] . "' class='noprint'> <td colspan='22'> <table width='100%' cellspacing='0' cellpadding='0' border='0'> <tr> <td align='center' class='textHeaderDark'> No Rows Found </td>\n </tr> </table> </td> </tr>\n"; } print $nav; $display_text = mactrack_display_array(); html_header_sort($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"]); $i = 0; if (sizeof($stats) > 0) { //$stats = order_by_name($stats); foreach ($stats as $stat) { /* find the background color and enclose it */ $bgc = mactrack_int_row_color($stat); if ($bgc) { print "<tr id='row_" . $stat["device_id"] . "_" . $stat["ifName"] . "' style='background-color:#$bgc;'>\n"; $i++; }else{ if (($i % 2) == 1) { $current_color = $colors["alternate"]; }else{ $current_color = $colors["light"]; } print "<tr id='row_" . $stat["device_id"] . "' style='background-color:#$bgc;'>\n"; $i++; } print mactrack_format_interface_row($stat); } }else{ print "<tr><td colspan='7'><em>No Scanner Devices Found</em></td></tr>"; } /* put the nav bar on the bottom as well */ print $nav; html_end_box(false); html_start_box("", "100%", $colors["header"], "3", "center", ""); print "<tr>"; mactrack_legend_row("mt_int_up_bgc", "Interface Up"); mactrack_legend_row("mt_int_up_wo_alias_bgc", "No Alias"); mactrack_legend_row("mt_int_errors_bgc", "Errors Present"); mactrack_legend_row("mt_int_discards_bgc", "Discards Present"); mactrack_legend_row("mt_int_unmapped_bgc", "Unmapped to Tree"); mactrack_legend_row("mt_int_no_graph_bgc", "No Graphs"); mactrack_legend_row("mt_int_no_device_bgc", "Not Integrated"); mactrack_legend_row("mt_int_down_bgc", "Interface Down"); print "</tr>"; html_end_box(false); mactrack_display_stats(); print "<div id='response'></div>"; print "<script> function printreport(id){ if (id==-1 ||typeof id == 'undefined') alert('To generate the report, you must select one device.'); else window.open('https://monitorizacion.urjc.es/cacti/plugins/mactrack/pdfreport.php?did='+id, '_blank'); } </script>"; include_once("./include/bottom_footer.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); } }