function inject_form_variables(&$form_array, $arg1 = array(), $arg2 = array(), $arg3 = array(), $arg4 = array()) { $check_fields = array("value", "array", "friendly_name", "description", "sql", "sql_print", "form_id", "items"); /* loop through each available field */ while (list($field_name, $field_array) = each($form_array)) { /* loop through each sub-field that we are going to check for variables */ foreach ($check_fields as $field_to_check) { if (isset($field_array[$field_to_check]) && (is_array($form_array[$field_name][$field_to_check]))) { /* if the field/sub-field combination is an array, resolve it recursively */ $form_array[$field_name][$field_to_check] = inject_form_variables($form_array[$field_name][$field_to_check], $arg1); }elseif (isset($field_array[$field_to_check]) && (!is_array($field_array[$field_to_check])) && (ereg("\|(arg[123]):([a-zA-Z0-9_]*)\|", $field_array[$field_to_check], $matches))) { /* an empty field name in the variable means don't treat this as an array */ if ($matches[2] == "") { if (is_array(${$matches[1]})) { /* the existing value is already an array, leave it alone */ $form_array[$field_name][$field_to_check] = ${$matches[1]}; }else{ /* the existing value is probably a single variable */ $form_array[$field_name][$field_to_check] = str_replace($matches[0], ${$matches[1]}, $field_array[$field_to_check]); } }else{ /* copy the value down from the array/key specified in the variable */ $form_array[$field_name][$field_to_check] = str_replace($matches[0], ((isset(${$matches[1]}{$matches[2]})) ? ${$matches[1]}{$matches[2]} : ""), $field_array[$field_to_check]); } } } } return $form_array; }
function syslog_action_edit() { global $colors, $message_types, $syslog_freqs, $syslog_times; include dirname(__FILE__) . "/config.php"; /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); input_validate_input_number(get_request_var("type")); /* ==================================================== */ if (isset($_GET["id"])) { $report = syslog_db_fetch_row("SELECT *\n\t\t\tFROM `" . $syslogdb_default . "`.`syslog_reports`\n\t\t\tWHERE id=" . $_GET["id"]); $header_label = "[edit: " . $report["name"] . "]"; } else { $header_label = "[new]"; $report["name"] = "New Report Record"; } html_start_box("<strong>Report Edit</strong> {$header_label}", "100%", $colors["header"], "3", "center", ""); $fields_syslog_report_edit = array("spacer0" => array("method" => "spacer", "friendly_name" => "Report Details"), "name" => array("method" => "textbox", "friendly_name" => "Report Name", "description" => "Please describe this Report.", "value" => "|arg1:name|", "max_length" => "250"), "enabled" => array("method" => "drop_array", "friendly_name" => "Enabled?", "description" => "Is this Report Enabled?", "value" => "|arg1:enabled|", "array" => array("on" => "Enabled", "" => "Disabled"), "default" => "on"), "type" => array("method" => "drop_array", "friendly_name" => "String Match Type", "description" => "Define how you would like this string matched.", "value" => "|arg1:type|", "array" => $message_types, "default" => "matchesc"), "message" => array("method" => "textbox", "friendly_name" => "Syslog Message Match String", "description" => "The matching component of the syslog message.", "value" => "|arg1:message|", "default" => "", "max_length" => "255"), "timespan" => array("method" => "drop_array", "friendly_name" => "Report Frequency", "description" => "How often should this Report be sent to the distribution list?", "value" => "|arg1:timespan|", "array" => $syslog_freqs, "default" => "del"), "timepart" => array("method" => "drop_array", "friendly_name" => "Send Time", "description" => "What time of day should this report be sent?", "value" => "|arg1:timepart|", "array" => $syslog_times, "default" => "del"), "message" => array("friendly_name" => "Syslog Message Match String", "description" => "The matching component of the syslog message.", "method" => "textbox", "max_length" => "255", "value" => "|arg1:message|", "default" => ""), "body" => array("friendly_name" => "Report Body Text", "textarea_rows" => "5", "textarea_cols" => "60", "description" => "The information that will be contained in the body of the report.", "method" => "textarea", "class" => "textAreaNotes", "value" => "|arg1:body|", "default" => ""), "email" => array("friendly_name" => "Report e-mail Addresses", "textarea_rows" => "3", "textarea_cols" => "60", "description" => "Comma delimited list of e-mail addresses to send the report to.", "method" => "textarea", "class" => "textAreaNotes", "value" => "|arg1:email|", "default" => ""), "notes" => array("friendly_name" => "Report Notes", "textarea_rows" => "3", "textarea_cols" => "60", "description" => "Space for Notes on the Report", "method" => "textarea", "class" => "textAreaNotes", "value" => "|arg1:notes|", "default" => ""), "id" => array("method" => "hidden_zero", "value" => "|arg1:id|"), "_id" => array("method" => "hidden_zero", "value" => "|arg1:id|"), "save_component_report" => array("method" => "hidden", "value" => "1")); draw_edit_form(array("config" => array("form_name" => "chk"), "fields" => inject_form_variables($fields_syslog_report_edit, isset($report) ? $report : array()))); html_end_box(); form_save_button("syslog_reports.php", "", "id"); }
function template_edit() { global $struct_data_source, $struct_data_source_item, $data_source_types, $fields_data_template_template_edit; /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); input_validate_input_number(get_request_var("view_rrd")); /* ==================================================== */ if (!empty($_GET["id"])) { $template_data = db_fetch_row("select * from data_template_data where data_template_id=" . $_GET["id"] . " and local_data_id=0"); $template = db_fetch_row("select * from data_template where id=" . $_GET["id"]); $header_label = "[edit: " . $template["name"] . "]"; } else { $header_label = "[new]"; } html_start_box("<strong>Data Templates</strong> " . htmlspecialchars($header_label), "100%", "", "3", "center", ""); draw_edit_form(array("config" => array(), "fields" => inject_form_variables($fields_data_template_template_edit, isset($template) ? $template : array(), isset($template_data) ? $template_data : array(), $_GET))); html_end_box(); html_start_box("<strong>Data Source</strong>", "100%", "", "3", "center", ""); /* make sure 'data source path' doesn't show up for a template... we should NEVER template this field */ unset($struct_data_source["data_source_path"]); $form_array = array(); while (list($field_name, $field_array) = each($struct_data_source)) { $form_array += array($field_name => $struct_data_source[$field_name]); if ($field_array["flags"] == "ALWAYSTEMPLATE") { $form_array[$field_name]["description"] = "<em>This field is always templated.</em>"; } else { $form_array[$field_name]["description"] = ""; $form_array[$field_name]["sub_checkbox"] = array("name" => "t_" . $field_name, "friendly_name" => "Use Per-Data Source Value (Ignore this Value)", "value" => isset($template_data["t_" . $field_name]) ? $template_data["t_" . $field_name] : ""); } $form_array[$field_name]["value"] = isset($template_data[$field_name]) ? $template_data[$field_name] : ""; $form_array[$field_name]["form_id"] = isset($template_data) ? $template_data["data_template_id"] : "0"; } draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => inject_form_variables($form_array, isset($template_data) ? $template_data : array()))); html_end_box(); /* fetch ALL rrd's for this data source */ if (!empty($_GET["id"])) { $template_data_rrds = db_fetch_assoc("select id,data_source_name from data_template_rrd where data_template_id=" . $_GET["id"] . " and local_data_id=0 order by data_source_name"); } /* select the first "rrd" of this data source by default */ if (empty($_GET["view_rrd"])) { $_GET["view_rrd"] = isset($template_data_rrds[0]["id"]) ? $template_data_rrds[0]["id"] : "0"; } /* get more information about the rrd we chose */ if (!empty($_GET["view_rrd"])) { $template_rrd = db_fetch_row("select * from data_template_rrd where id=" . $_GET["view_rrd"]); } $i = 0; if (isset($template_data_rrds)) { if (sizeof($template_data_rrds) > 1) { /* draw the data source tabs on the top of the page */ print "\t<table class='tabs' width='100%' cellspacing='0' cellpadding='3' align='center'>\n\t\t\t\t<tr>\n"; foreach ($template_data_rrds as $template_data_rrd) { $i++; print "\t<td " . ($template_data_rrd["id"] == $_GET["view_rrd"] ? "class='tabSelected tab'" : "class='tabNotSelected tab'") . " width='" . (strlen($template_data_rrd["data_source_name"]) * 9 + 50) . "' align='center'>\n\t\t\t\t\t\t\t<span class='textHeader'><a href='" . htmlspecialchars("data_templates.php?action=template_edit&id=" . $_GET["id"] . "&view_rrd=" . $template_data_rrd["id"]) . "'>{$i}: " . htmlspecialchars($template_data_rrd["data_source_name"]) . "</a> <a href='" . htmlspecialchars("data_templates.php?action=rrd_remove&id=" . $template_data_rrd["id"] . "&data_template_id=" . $_GET["id"]) . "'><img src='images/delete_icon.gif' border='0' alt='Delete'></a></span>\n\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t<td width='1'></td>\n"; } print "\n\t\t\t\t<td></td>\n\n\t\t\t\t</tr>\n\t\t\t</table>\n"; } elseif (sizeof($template_data_rrds) == 1) { $_GET["view_rrd"] = $template_data_rrds[0]["id"]; } } html_start_box("", "100%", "", "3", "center", ""); print "\t<tr class='cactiTableTitle'>\n\t\t\t<td class='textHeaderDark'>\n\t\t\t\t<strong>Data Source Item</strong> [" . (isset($template_rrd) ? htmlspecialchars($template_rrd["data_source_name"]) : "") . "]\n\t\t\t</td>\n\t\t\t<td class='textHeaderDark' align='right'>\n\t\t\t\t" . (!empty($_GET["id"]) ? "<strong><a class='linkOverDark' href='" . htmlspecialchars("data_templates.php?action=rrd_add&id=" . $_GET["id"]) . "'>New</a> </strong>" : "") . "\n\t\t\t</td>\n\t\t</tr>\n"; /* data input fields list */ if (empty($template_data["data_input_id"]) || db_fetch_cell("select type_id from data_input where id=" . $template_data["data_input_id"]) != "1" && db_fetch_cell("select type_id from data_input where id=" . $template_data["data_input_id"]) != "5") { unset($struct_data_source_item["data_input_field_id"]); } else { $struct_data_source_item["data_input_field_id"]["sql"] = "select id,CONCAT(data_name,' - ',name) as name from data_input_fields where data_input_id=" . $template_data["data_input_id"] . " and input_output='out' and update_rra='on' order by data_name,name"; } $form_array = array(); while (list($field_name, $field_array) = each($struct_data_source_item)) { $form_array += array($field_name => $struct_data_source_item[$field_name]); $form_array[$field_name]["description"] = ""; $form_array[$field_name]["value"] = isset($template_rrd) ? $template_rrd[$field_name] : ""; $form_array[$field_name]["sub_checkbox"] = array("name" => "t_" . $field_name, "friendly_name" => "Use Per-Data Source Value (Ignore this Value)", "value" => isset($template_rrd) ? $template_rrd["t_" . $field_name] : ""); } draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => $form_array + array("data_template_rrd_id" => array("method" => "hidden", "value" => isset($template_rrd) ? $template_rrd["id"] : "0")))); html_end_box(); $i = 0; if (!empty($_GET["id"])) { /* get each INPUT field for this data input source */ $fields = db_fetch_assoc("select * from data_input_fields where data_input_id=" . $template_data["data_input_id"] . " and input_output='in' order by name"); html_start_box("<strong>Custom Data</strong> [data input: " . htmlspecialchars(db_fetch_cell("select name from data_input where id=" . $template_data["data_input_id"])) . "]", "100%", "", "3", "center", ""); /* loop through each field found */ if (sizeof($fields) > 0) { foreach ($fields as $field) { $data_input_data = db_fetch_row("select t_value,value from data_input_data where data_template_data_id=" . $template_data["id"] . " and data_input_field_id=" . $field["id"]); if (sizeof($data_input_data) > 0) { $old_value = $data_input_data["value"]; } else { $old_value = ""; } form_alternate_row(); ?> <td width="50%"> <strong><?php print $field["name"]; ?> </strong><br> <?php form_checkbox("t_value_" . $field["data_name"], $data_input_data["t_value"], "Use Per-Data Source Value (Ignore this Value)", "", "", $_GET["id"]); ?> </td> <td> <?php form_text_box("value_" . $field["data_name"], $old_value, "", ""); ?> <?php if (preg_match('/^' . VALID_HOST_FIELDS . '$/i', $field["type_code"]) && $data_input_data["t_value"] == "") { print "<br><em>Value will be derived from the host if this field is left empty.</em>\n"; } ?> </td> </tr> <?php $i++; } } else { print "<tr><td><em>No Input Fields for the Selected Data Input Source</em></td></tr>"; } html_end_box(); } form_save_button("data_templates.php", "return"); }
function host_edit() { global $fields_host_edit, $reindex_types; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request('id')); /* ==================================================== */ api_plugin_hook('host_edit_top'); if (!empty($_REQUEST['id'])) { $host = db_fetch_row_prepared('SELECT * FROM host WHERE id = ?', array($_REQUEST['id'])); $header_label = '[edit: ' . htmlspecialchars($host['description']) . ']'; } else { $header_label = '[new]'; } if (!empty($host['id'])) { ?> <table width='100%' align='center'> <tr> <td class='textInfo' colspan='2'> <?php print htmlspecialchars($host['description']); ?> (<?php print htmlspecialchars($host['hostname']); ?> ) </td> <td rowspan='2' class='textInfo' valign='top' align='right'> <span class='linkMarker'>*</span><a class='hyperLink' href='<?php print htmlspecialchars('graphs_new.php?host_id=' . $host['id']); ?> '>Create Graphs for this Device</a><br> <span class='linkMarker'>*</span><a class='hyperLink' href='<?php print htmlspecialchars('data_sources.php?host_id=' . $host['id'] . '&ds_rows=30&filter=&template_id=-1&method_id=-1&page=1'); ?> '>Data Source List</a><br> <span class='linkMarker'>*</span><a class='hyperLink' href='<?php print htmlspecialchars('graphs.php?host_id=' . $host['id'] . '&graph_rows=30&filter=&template_id=-1&page=1'); ?> '>Graph List</a> <?php api_plugin_hook('device_edit_top_links'); ?> </td> </tr> <tr> <td valign='top' class='textHeader'> <div id='ping_results'>Pinging Device <i style='font-size:12px;' class='fa fa-spin fa-spinner'></i><br><br></div> </td> </tr> </table> <?php } html_start_box("<strong>Device</strong> {$header_label}", '100%', '', '3', 'center', ''); /* preserve the host template id if passed in via a GET variable */ if (!empty($_REQUEST['host_template_id'])) { $fields_host_edit['host_template_id']['value'] = $_REQUEST['host_template_id']; } draw_edit_form(array('config' => array('form_name' => 'chk'), 'fields' => inject_form_variables($fields_host_edit, isset($host) ? $host : array()))); /* we have to hide this button to make a form change in the main form trigger the correct * submit action */ echo "<div style='display:none;'><input type='submit' value='Default Submit Button'></div>"; html_end_box(); ?> <script type="text/javascript"> <!-- // default snmp information var snmp_community = $('#snmp_community').val(); var snmp_username = $('#snmp_username').val(); var snmp_password = $('#snmp_password').val(); var snmp_auth_protocol = $('#snmp_auth_protocol').val(); var snmp_priv_passphrase = $('#snmp_priv_passphrase').val(); var snmp_priv_protocol = $('#snmp_priv_protocol').val(); var snmp_context = $('#snmp_context').val(); var snmp_port = $('#snmp_port').val(); var snmp_timeout = $('#snmp_timeout').val(); var max_oids = $('#max_oids').val(); // default ping methods var ping_method = $('#ping_method').val(); var ping_port = $('#ping_port').val(); var ping_timeout = $('#ping_timeout').val(); var ping_retries = $('#ping_retries').val(); function setPing() { availability_method = $('#availability_method').val(); ping_method = $('#ping_method').val(); switch(availability_method) { case '0': // none $('#row_ping_method').css('display', 'none'); $('#row_ping_port').css('display', 'none'); $('#row_ping_timeout').css('display', 'none'); $('#row_ping_retries').css('display', 'none'); break; case '2': // snmp case '5': // snmp sysDesc case '6': // snmp getNext $('#row_ping_method').css('display', 'none'); $('#row_ping_port').css('display', 'none'); $('#row_ping_timeout').css('display', ''); $('#row_ping_retries').css('display', ''); break; default: // ping ok switch(ping_method) { case '1': // ping icmp $('#row_ping_method').css('display', ''); $('#row_ping_port').css('display', 'none'); $('#row_ping_timeout').css('display', ''); $('#row_ping_retries').css('display', ''); break; case '2': // ping udp case '3': // ping tcp $('#row_ping_method').css('display', ''); $('#row_ping_port').css('display', ''); $('#row_ping_timeout').css('display', ''); $('#row_ping_retries').css('display', ''); break; } break; } } function setAvailability() { if ($('#snmp_version').val() == '0') { methods = [ { value: '0', text: 'None' }, { value: '3', text: 'Ping' } ]; if ($('#availability_method').val() != '3' && $('#availability_method').val() != '0') { $('#availability_method').val('3'); } $('#availability_method').replaceOptions(methods, $('#availability_method').val()); }else{ methods = [ { value: '0', text: 'None' }, { value: '1', text: 'Ping and SNMP Uptime' }, { value: '2', text: 'SNMP Uptime' }, { value: '3', text: 'Ping' }, { value: '4', text: 'Ping or SNMP Uptime' }, { value: '5', text: 'SNMP Desc' }, { value: '6', text: 'SNMP GetNext' } ]; $('#availability_method').replaceOptions(methods, $('#availability_method').val()); } switch($('#availibility_method').val()) { case '0': // availability none $('#row_ping_method').hide(); $('#ping_method').val(0); $('#row_ping_timeout').hide(); $('#row_ping_port').hide(); $('#row_ping_timeout').hide(); $('#row_ping_retrie').hide(); break; case '1': // ping and snmp sysUptime case '3': // ping case '4': // ping or snmp sysUptime if (($('#row_ping_method').css('display', 'none')) || ($('#row_ping_method').css('display') == undefined)) { $('#ping_method').val(ping_method); $('#row_ping_method').css('display', ''); } break; case '2': // snmp sysUptime case '5': // snmp sysDesc case '6': // snmp getNext $('#row_ping_method').css('display', 'none'); $('#ping_method').val(0); break; } if ($('#availability_method-button').length) { $('#availability_method').selectmenu('refresh'); } } function changeHostForm() { setSNMP(); setAvailability(); setPing(); } function setSNMP() { snmp_version = $('#snmp_version').val(); switch(snmp_version) { case '0': // No SNMP $('#row_snmp_username').hide(); $('#row_snmp_password').hide(); $('#row_snmp_community').hide(); $('#row_snmp_auth_protocol').hide(); $('#row_snmp_priv_passphrase').hide(); $('#row_snmp_priv_protocol').hide(); $('#row_snmp_context').hide(); $('#row_snmp_port').hide(); $('#row_snmp_timeout').hide(); $('#row_max_oids').hide(); break; case '1': // SNMP v1 case '2': // SNMP v2c $('#row_snmp_username').hide(); $('#row_snmp_password').hide(); $('#row_snmp_community').show(); $('#row_snmp_auth_protocol').hide(); $('#row_snmp_priv_passphrase').hide(); $('#row_snmp_priv_protocol').hide(); $('#row_snmp_context').hide(); $('#row_snmp_port').show(); $('#row_snmp_timeout').show(); $('#row_max_oids').show(); break; case '3': // SNMP v3 $('#row_snmp_username').show(); $('#row_snmp_password').show(); $('#row_snmp_community').hide(); $('#row_snmp_auth_protocol').show(); $('#row_snmp_priv_passphrase').show(); $('#row_snmp_priv_protocol').show(); $('#row_snmp_context').show(); $('#row_snmp_port').show(); $('#row_snmp_timeout').show(); $('#row_max_oids').show(); break; } } $(function() { changeHostForm(); $('#dbghide').click(function(data) { $('#dqdebug').fadeOut('fast'); }); $.get('host.php?action=ping_host&id='+$('#id').val(), function(data) { $('#ping_results').html(data); }); }); --> </script> <?php if (isset($_REQUEST['display_dq_details']) && isset($_SESSION['debug_log']['data_query'])) { print "<table id='dqdebug' width='100%' class='cactiDebugTable' cellpadding='0' cellspacing='0' border='0' align='center'><tr><td>\n"; print "<table width='100%' class='cactiTableTitle' cellspacing='0' cellpadding='3' border='0'>\n"; print "<tr><td class='textHeaderDark'><a name='dqdbg'></a><strong>Data Query Debug Information</strong></td><td class='textHeaderDark' align='right'><a style='cursor:pointer;' id='dbghide' class='linkOverDark'>Hide</a></td></tr>\n"; print "</table>\n"; print "<table width='100%' class='cactiTable' cellspacing='0' cellpadding='3' border='0'>\n"; print "<tr><td class='odd'><span style='font-family: monospace;'>" . debug_log_return('data_query') . "</span></td></tr>"; print "</table>\n"; print "</table>\n"; } if (!empty($host['id'])) { html_start_box('<strong>Associated Graph Templates</strong>', '100%', '', '3', 'center', ''); html_header(array('Graph Template Name', 'Status'), 2); $selected_graph_templates = db_fetch_assoc_prepared('SELECT graph_templates.id, graph_templates.name FROM (graph_templates, host_graph) WHERE graph_templates.id = host_graph.graph_template_id AND host_graph.host_id = ? ORDER BY graph_templates.name', array($_REQUEST['id'])); $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'); $i = 0; if (sizeof($selected_graph_templates) > 0) { foreach ($selected_graph_templates as $item) { form_alternate_row('', true); /* get status information for this graph template */ $is_being_graphed = sizeof(db_fetch_assoc_prepared('SELECT id FROM graph_local WHERE graph_template_id = ? AND host_id = ?', array($item['id'], $_REQUEST['id']))) > 0 ? true : false; ?> <td style="padding: 4px;"> <strong><?php print $i; ?> )</strong> <?php print htmlspecialchars($item['name']); ?> </td> <td> <?php print $is_being_graphed == true ? "<span style='color: green;'>Is Being Graphed</span> (<a href='" . htmlspecialchars('graphs.php?action=graph_edit&id=' . db_fetch_cell_prepared('SELECT id FROM graph_local WHERE graph_template_id = ? AND host_id = ? LIMIT 0,1', array($item['id'], $_REQUEST['id']))) . "'>Edit</a>)" : "<span style='color: #484848;'>Not Being Graphed</span>"; ?> </td> <td align='right' nowrap> <a href='<?php print htmlspecialchars('host.php?action=gt_remove&id=' . $item['id'] . '&host_id=' . $_REQUEST['id']); ?> '><img src='images/delete_icon_large.gif' title='Delete Graph Template Association' alt='Delete Graph Template Association' border='0' align='middle'></a> </td> <?php form_end_row(); $i++; } } else { print "<tr class='tableRow'><td colspan='2'><em>No associated graph templates.</em></td></tr>"; } ?> <tr class='odd'> <td class='saveRow' colspan="4"> <table cellspacing="0" cellpadding="1" width="100%"> <td nowrap>Add Graph Template: <?php form_dropdown('graph_template_id', $available_graph_templates, 'name', 'id', '', '', ''); ?> </td> <td align="right"> <input type="submit" value="Add" name="add_gt_x" title="Add Graph Template to Device"> </td> </table> </td> </tr> <?php html_end_box(); html_start_box('<strong>Associated Data Queries</strong>', '100%', '', '3', 'center', ''); html_header(array('Data Query Name', 'Debugging', 'Re-Index Method', 'Status'), 2); $selected_data_queries = db_fetch_assoc_prepared('SELECT snmp_query.id, snmp_query.name, host_snmp_query.reindex_method FROM (snmp_query, host_snmp_query) WHERE snmp_query.id = host_snmp_query.snmp_query_id AND host_snmp_query.host_id = ? ORDER BY snmp_query.name', array($_REQUEST['id'])); $available_data_queries = db_fetch_assoc('SELECT snmp_query.id, snmp_query.name FROM snmp_query ORDER BY snmp_query.name'); $keeper = array(); foreach ($available_data_queries as $item) { if (sizeof(db_fetch_assoc_prepared('SELECT snmp_query_id FROM host_snmp_query WHERE host_id = ? AND snmp_query_id = ?', array($_REQUEST['id'], $item['id']))) > 0) { /* do nothing */ } else { array_push($keeper, $item); } } $available_data_queries = $keeper; $i = 0; if (sizeof($selected_data_queries) > 0) { foreach ($selected_data_queries as $item) { form_alternate_row('', true); /* get status information for this data query */ $num_dq_items = sizeof(db_fetch_assoc_prepared('SELECT snmp_index FROM host_snmp_cache WHERE host_id = ? AND snmp_query_id = ?', array($_REQUEST['id'], $item['id']))); $num_dq_rows = sizeof(db_fetch_assoc_prepared('SELECT snmp_index FROM host_snmp_cache WHERE host_id = ? AND snmp_query_id = ? GROUP BY snmp_index', array($_REQUEST['id'], $item['id']))); $status = 'success'; ?> <td style="padding: 4px;"> <strong><?php print $i; ?> )</strong> <?php print htmlspecialchars($item['name']); ?> </td> <td> (<a href="<?php print htmlspecialchars('host.php?action=query_verbose&id=' . $item['id'] . '&host_id=' . $_REQUEST['id']); ?> ">Verbose Query</a>) </td> <td> <?php print $reindex_types[$item['reindex_method']]; ?> </td> <td> <?php print $status == 'success' ? "<span style='color: green;'>Success</span>" : "<span style='color: green;'>Fail</span>"; ?> [<?php print $num_dq_items; ?> Item<?php print $num_dq_items == 1 ? '' : 's'; ?> , <?php print $num_dq_rows; ?> Row<?php print $num_dq_rows == 1 ? '' : 's'; ?> ] </td> <td align='right' nowrap> <a href='<?php print htmlspecialchars('host.php?action=query_reload&id=' . $item['id'] . '&host_id=' . $_REQUEST['id']); ?> '><img src='images/reload_icon_small.gif' title='Reload Data Query' alt='Reload Data Query' border='0' align='middle'></a> <a href='<?php print htmlspecialchars('host.php?action=query_remove&id=' . $item['id'] . '&host_id=' . $_REQUEST['id']); ?> '><img src='images/delete_icon_large.gif' title='Delete Data Query Association' alt='Delete Data Query Association' border='0' align='middle'></a> </td> <?php form_end_row(); $i++; } } else { print "<tr class='tableRow'><td colspan='4'><em>No associated data queries.</em></td></tr>"; } ?> <tr class='odd'> <td class='saveRow' colspan="5"> <table cellspacing="0" cellpadding="1" width="100%"> <td nowrap>Add Data Query: <?php form_dropdown('snmp_query_id', $available_data_queries, 'name', 'id', '', '', ''); ?> </td> <td nowrap>Re-Index Method: <?php form_dropdown('reindex_method', $reindex_types, '', '', read_config_option('reindex_method'), '', ''); ?> </td> <td align="right"> <input type="submit" value="Add" name="add_dq_x" title="Add Data Query to Device"> </td> </table> <a name='dqtop'></a> </td> </tr> <?php html_end_box(); } form_save_button('host.php', 'return'); api_plugin_hook('host_edit_bottom'); }
function mactrack_site_edit() { global $fields_mactrack_site_edit; /* ================= input validation ================= */ get_filter_request_var('site_id'); /* ==================================================== */ display_output_messages(); if (!isempty_request_var('site_id')) { $site = db_fetch_row('SELECT * FROM mac_track_sites WHERE site_id=' . get_request_var('site_id')); $header_label = __('MacTrack Site [edit: %s]', $site['site_name']); } else { $header_label = __('MacTrack Site [new]'); } form_start('mactrack_sites.php'); html_start_box($header_label, '100%', '', '3', 'center', ''); draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => inject_form_variables($fields_mactrack_site_edit, isset($site) ? $site : array()))); html_end_box(); form_save_button('mactrack_sites.php', 'return', 'site_id'); }
function ds_edit() { global $colors, $struct_data_source, $struct_data_source_item, $data_source_types; /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ $use_data_template = true; $host_id = 0; if (!empty($_GET["id"])) { $data_local = db_fetch_row("select host_id,data_template_id from data_local where id='" . $_GET["id"] . "'"); $data = db_fetch_row("select * from data_template_data where local_data_id='" . $_GET["id"] . "'"); if (isset($data_local["data_template_id"]) && $data_local["data_template_id"] >= 0) { $data_template = db_fetch_row("select id,name from data_template where id='" . $data_local["data_template_id"] . "'"); $data_template_data = db_fetch_row("select * from data_template_data where data_template_id='" . $data_local["data_template_id"] . "' and local_data_id=0"); } else { $_SESSION["sess_messages"] = 'Data Source "' . $_GET["id"] . '" does not exist.'; header("Location: data_sources.php"); exit; } $header_label = "[edit: " . get_data_source_title($_GET["id"]) . "]"; if (empty($data_local["data_template_id"])) { $use_data_template = false; } } else { $header_label = "[new]"; $use_data_template = false; } /* handle debug mode */ if (isset($_GET["debug"])) { if ($_GET["debug"] == "0") { kill_session_var("ds_debug_mode"); } elseif ($_GET["debug"] == "1") { $_SESSION["ds_debug_mode"] = true; } } include_once "./include/top_header.php"; if (!empty($_GET["id"])) { ?> <table width="100%" align="center"> <tr> <td class="textInfo" colspan="2" valign="top"> <?php print get_data_source_title($_GET["id"]); ?> </td> <td class="textInfo" align="right" valign="top"> <span style="color: #c16921;">*<a href='data_sources.php?action=ds_edit&id=<?php print isset($_GET["id"]) ? $_GET["id"] : 0; ?> &debug=<?php print isset($_SESSION["ds_debug_mode"]) ? "0" : "1"; ?> '>Turn <strong><?php print isset($_SESSION["ds_debug_mode"]) ? "Off" : "On"; ?> </strong> Data Source Debug Mode.</a> </td> </tr> </table> <br> <?php } html_start_box("<strong>Data Template Selection</strong> {$header_label}", "100%", $colors["header"], "3", "center", ""); $form_array = array("data_template_id" => array("method" => "drop_sql", "friendly_name" => "Selected Data Template", "description" => "The name given to this data template.", "value" => isset($data_template) ? $data_template["id"] : "0", "none_value" => "None", "sql" => "select id,name from data_template order by name"), "host_id" => array("method" => "drop_sql", "friendly_name" => "Host", "description" => "Choose the host that this graph belongs to.", "value" => isset($_GET["host_id"]) ? $_GET["host_id"] : $data_local["host_id"], "none_value" => "None", "sql" => "select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"), "_data_template_id" => array("method" => "hidden", "value" => isset($data_template) ? $data_template["id"] : "0"), "_host_id" => array("method" => "hidden", "value" => empty($data_local["host_id"]) ? isset($_GET["host_id"]) ? $_GET["host_id"] : "0" : $data_local["host_id"]), "_data_input_id" => array("method" => "hidden", "value" => isset($data["data_input_id"]) ? $data["data_input_id"] : "0"), "data_template_data_id" => array("method" => "hidden", "value" => isset($data) ? $data["id"] : "0"), "local_data_template_data_id" => array("method" => "hidden", "value" => isset($data) ? $data["local_data_template_data_id"] : "0"), "local_data_id" => array("method" => "hidden", "value" => isset($data) ? $data["local_data_id"] : "0")); draw_edit_form(array("config" => array(), "fields" => $form_array)); html_end_box(); /* only display the "inputs" area if we are using a data template for this data source */ if (!empty($data["data_template_id"])) { $template_data_rrds = db_fetch_assoc("select * from data_template_rrd where local_data_id=" . $_GET["id"] . " order by data_source_name"); html_start_box("<strong>Supplemental Data Template Data</strong>", "100%", $colors["header"], "3", "center", ""); draw_nontemplated_fields_data_source($data["data_template_id"], $data["local_data_id"], $data, "|field|", "<strong>Data Source Fields</strong>", true, true, 0); draw_nontemplated_fields_data_source_item($data["data_template_id"], $template_data_rrds, "|field|_|id|", "<strong>Data Source Item Fields</strong>", true, true, true, 0); draw_nontemplated_fields_custom_data($data["id"], "value_|id|", "<strong>Custom Data</strong>", true, true, 0); form_hidden_box("save_component_data", "1", ""); html_end_box(); } if ((isset($_GET["id"]) || isset($_GET["new"])) && empty($data["data_template_id"])) { html_start_box("<strong>Data Source</strong>", "100%", $colors["header"], "3", "center", ""); $form_array = array(); while (list($field_name, $field_array) = each($struct_data_source)) { $form_array += array($field_name => $struct_data_source[$field_name]); if (!($use_data_template == false || !empty($data_template_data["t_" . $field_name]) || $field_array["flags"] == "NOTEMPLATE")) { $form_array[$field_name]["description"] = ""; } $form_array[$field_name]["value"] = isset($data[$field_name]) ? $data[$field_name] : ""; $form_array[$field_name]["form_id"] = empty($data["id"]) ? "0" : $data["id"]; if (!($use_data_template == false || !empty($data_template_data["t_" . $field_name]) || $field_array["flags"] == "NOTEMPLATE")) { $form_array[$field_name]["method"] = "template_" . $form_array[$field_name]["method"]; } } draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => inject_form_variables($form_array, isset($data) ? $data : array()))); html_end_box(); /* fetch ALL rrd's for this data source */ if (!empty($_GET["id"])) { $template_data_rrds = db_fetch_assoc("select id,data_source_name from data_template_rrd where local_data_id=" . $_GET["id"] . " order by data_source_name"); } /* select the first "rrd" of this data source by default */ if (empty($_GET["view_rrd"])) { $_GET["view_rrd"] = isset($template_data_rrds[0]["id"]) ? $template_data_rrds[0]["id"] : "0"; } /* get more information about the rrd we chose */ if (!empty($_GET["view_rrd"])) { $local_data_template_rrd_id = db_fetch_cell("select local_data_template_rrd_id from data_template_rrd where id=" . $_GET["view_rrd"]); $rrd = db_fetch_row("select * from data_template_rrd where id=" . $_GET["view_rrd"]); $rrd_template = db_fetch_row("select * from data_template_rrd where id={$local_data_template_rrd_id}"); $header_label = "[edit: " . $rrd["data_source_name"] . "]"; } else { $header_label = ""; } $i = 0; if (isset($template_data_rrds)) { if (sizeof($template_data_rrds) > 1) { /* draw the data source tabs on the top of the page */ print "\t<table class='tabs' width='100%' cellspacing='0' cellpadding='3' align='center'>\n\t\t\t\t\t<tr>\n"; foreach ($template_data_rrds as $template_data_rrd) { $i++; print "\t<td " . ($template_data_rrd["id"] == $_GET["view_rrd"] ? "bgcolor='silver'" : "bgcolor='#DFDFDF'") . " nowrap='nowrap' width='" . (strlen($template_data_rrd["data_source_name"]) * 9 + 50) . "' align='center' class='tab'>\n\t\t\t\t\t\t\t\t<span class='textHeader'><a href='data_sources.php?action=ds_edit&id=" . $_GET["id"] . "&view_rrd=" . $template_data_rrd["id"] . "'>{$i}: " . $template_data_rrd["data_source_name"] . "</a>" . ($use_data_template == false ? " <a href='data_sources.php?action=rrd_remove&id=" . $template_data_rrd["id"] . "&local_data_id=" . $_GET["id"] . "'><img src='images/delete_icon.gif' border='0' alt='Delete'></a>" : "") . "</span>\n\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t\t<td width='1'></td>\n"; } print "\n\t\t\t\t\t<td></td>\n\n\t\t\t\t\t</tr>\n\t\t\t\t</table>\n"; } elseif (sizeof($template_data_rrds) == 1) { $_GET["view_rrd"] = $template_data_rrds[0]["id"]; } } html_start_box("", "100%", $colors["header"], "3", "center", ""); print "\t<tr>\n\t\t\t\t<td bgcolor='#" . $colors["header"] . "' class='textHeaderDark'>\n\t\t\t\t\t<strong>Data Source Item</strong> {$header_label}\n\t\t\t\t</td>\n\t\t\t\t<td class='textHeaderDark' align='right' bgcolor='" . $colors["header"] . "'>\n\t\t\t\t\t" . (!empty($_GET["id"]) && empty($data_template["id"]) ? "<strong><a class='linkOverDark' href='data_sources.php?action=rrd_add&id=" . $_GET["id"] . "'>New</a> </strong>" : "") . "\n\t\t\t\t</td>\n\t\t\t</tr>\n"; /* data input fields list */ if (empty($data["data_input_id"]) || db_fetch_cell("select type_id from data_input where id=" . $data["data_input_id"]) > "1") { unset($struct_data_source_item["data_input_field_id"]); } else { $struct_data_source_item["data_input_field_id"]["sql"] = "select id,CONCAT(data_name,' - ',name) as name from data_input_fields where data_input_id=" . $data["data_input_id"] . " and input_output='out' and update_rra='on' order by data_name,name"; } $form_array = array(); while (list($field_name, $field_array) = each($struct_data_source_item)) { $form_array += array($field_name => $struct_data_source_item[$field_name]); if (!($use_data_template == false || $rrd_template["t_" . $field_name] == "on")) { $form_array[$field_name]["description"] = ""; } $form_array[$field_name]["value"] = isset($rrd) ? $rrd[$field_name] : ""; if (!($use_data_template == false || $rrd_template["t_" . $field_name] == "on")) { $form_array[$field_name]["method"] = "template_" . $form_array[$field_name]["method"]; } } draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => array("data_template_rrd_id" => array("method" => "hidden", "value" => isset($rrd) ? $rrd["id"] : "0"), "local_data_template_rrd_id" => array("method" => "hidden", "value" => isset($rrd) ? $rrd["local_data_template_rrd_id"] : "0")) + $form_array)); html_end_box(); /* data source data goes here */ data_edit(); form_hidden_box("current_rrd", $_GET["view_rrd"], "0"); } /* display the debug mode box if the user wants it */ if (isset($_SESSION["ds_debug_mode"]) && isset($_GET["id"])) { ?> <table width="100%" align="center"> <tr> <td> <span class="textInfo">Data Source Debug</span><br> <pre><?php print rrdtool_function_create($_GET["id"], true, array()); ?> </pre> </td> </tr> </table> <?php } if (isset($_GET["id"]) || isset($_GET["new"])) { form_hidden_box("save_component_data_source", "1", ""); } else { form_hidden_box("save_component_data_source_new", "1", ""); } form_save_button("data_sources.php"); include_once "./include/bottom_footer.php"; }
function syslog_action_edit() { global $colors, $message_types, $severities; include dirname(__FILE__) . "/config.php"; /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); input_validate_input_number(get_request_var("type")); /* ==================================================== */ if (isset($_GET["id"]) && $_GET["action"] == "edit") { $alert = syslog_db_fetch_row("SELECT *\n\t\t\tFROM `" . $syslogdb_default . "`.`syslog_alert`\n\t\t\tWHERE id=" . $_GET["id"]); $header_label = "[edit: " . $alert["name"] . "]"; } else { if (isset($_GET["id"]) && $_GET["action"] == "newedit") { $syslog_rec = syslog_db_fetch_row("SELECT * FROM `" . $syslogdb_default . "`.`syslog` WHERE seq=" . $_GET["id"] . " AND logtime='" . $_GET["date"] . "'"); $header_label = "[new]"; if (sizeof($syslog_rec)) { $alert["message"] = $syslog_rec["message"]; } $alert["name"] = "New Alert Rule"; } else { $header_label = "[new]"; $alert["name"] = "New Alert Rule"; } } $alert_retention = read_config_option("syslog_alert_retention"); if ($alert_retention != '' && $alert_retention > 0 && $alert_retention < 365) { $repeat_end = $alert_retention * 24 * 60 / 5; } $repeatarray = array(0 => 'Not Set', 1 => '5 Minutes', 2 => '10 Minutes', 3 => '15 Minutes', 4 => '20 Minutes', 6 => '30 Minutes', 8 => '45 Minutes', 12 => '1 Hour', 24 => '2 Hours', 36 => '3 Hours', 48 => '4 Hours', 72 => '6 Hours', 96 => '8 Hours', 144 => '12 Hours', 288 => '1 Day', 576 => '2 Days', 2016 => '1 Week', 4032 => '2 Weeks', 8640 => 'Month'); if ($repeat_end) { foreach ($repeatarray as $i => $value) { if ($i > $repeat_end) { unset($repeatarray[$i]); } } } html_start_box("<strong>Alert Edit</strong> {$header_label}", "100%", $colors["header"], "3", "center", ""); $fields_syslog_alert_edit = array("spacer0" => array("method" => "spacer", "friendly_name" => "Alert Details"), "name" => array("method" => "textbox", "friendly_name" => "Alert Name", "description" => "Please describe this Alert.", "value" => "|arg1:name|", "max_length" => "250", "size" => 80), "severity" => array("method" => "drop_array", "friendly_name" => "Severity", "description" => "What is the Severity Level of this Alert?", "value" => "|arg1:severity|", "array" => $severities, "default" => "1"), "method" => array("method" => "drop_array", "friendly_name" => "Reporting Method", "description" => "Define how to Alert on the syslog messages.", "value" => "|arg1:method|", "array" => array("0" => "Individual", "1" => "Threshold"), "default" => "0"), "num" => array("method" => "textbox", "friendly_name" => "Threshold", "description" => "For the 'Threshold' method, If the number seen is above this value\n\t\tan Alert will be triggered.", "value" => "|arg1:num|", "size" => "4", "max_length" => "10", "default" => "1"), "type" => array("method" => "drop_array", "friendly_name" => "String Match Type", "description" => "Define how you would like this string matched. If using the SQL Expression type you may use any valid SQL expression\n\t\tto generate the alarm. Available fields include 'message', 'facility', 'priority', and 'host'.", "value" => "|arg1:type|", "array" => $message_types, "on_change" => "changeTypes()", "default" => "matchesc"), "message" => array("friendly_name" => "Syslog Message Match String", "description" => "The matching component of the syslog message.", "textarea_rows" => "2", "textarea_cols" => "70", "method" => "textarea", "class" => "textAreaNotes", "value" => "|arg1:message|", "default" => ""), "enabled" => array("method" => "drop_array", "friendly_name" => "Alert Enabled", "description" => "Is this Alert Enabled?", "value" => "|arg1:enabled|", "array" => array("on" => "Enabled", "" => "Disabled"), "default" => "on"), "repeat_alert" => array("friendly_name" => "Re-Alert Cycle", "method" => "drop_array", "array" => $repeatarray, "default" => "0", "description" => "Do not resend this alert again for the same host, until this amount of time has elapsed. For threshold\n\t\tbased alarms, this applies to all hosts.", "value" => "|arg1:repeat_alert|"), "notes" => array("friendly_name" => "Alert Notes", "textarea_rows" => "5", "textarea_cols" => "70", "description" => "Space for Notes on the Alert", "method" => "textarea", "class" => "textAreaNotes", "value" => "|arg1:notes|", "default" => ""), "spacer1" => array("method" => "spacer", "friendly_name" => "Alert Actions"), "open_ticket" => array("method" => "drop_array", "friendly_name" => "Open Ticket", "description" => "Should a Help Desk Ticket be opened for this Alert", "value" => "|arg1:open_ticket|", "array" => array("on" => "Yes", "" => "No"), "default" => ""), "email" => array("method" => "textarea", "friendly_name" => "E-Mails to Notify", "textarea_rows" => "5", "textarea_cols" => "70", "description" => "Please enter a comma delimited list of e-mail addresses to inform. If you\n\t\twish to send out e-mail to a recipient in SMS format, please prefix that recipient's e-mail address\n\t\twith <b>'sms@'</b>. For example, if the recipients SMS address is <b>'*****@*****.**'</b>, you would\n\t\tenter it as <b>'sms@2485551212@mycarrier.net'</b> and it will be formatted as an SMS message.", "class" => "textAreaNotes", "value" => "|arg1:email|", "max_length" => "255"), "command" => array("friendly_name" => "Alert Command", "textarea_rows" => "5", "textarea_cols" => "70", "description" => "When an Alert is triggered, run the following command. The following replacement variables\n\t\tare available <b>'<HOSTNAME>'</b>, <b>'<ALERTID>'</b>, <b>'<MESSAGE>'</b>,\n\t\t<b>'<FACILITY>'</b>, <b>'<PRIORITY>'</b>, <b>'<SEVERITY>'</b>. Please\n\t\tnote that <b>'<HOSTNAME>'</b> is only available on individual thresholds.", "method" => "textarea", "class" => "textAreaNotes", "value" => "|arg1:command|", "default" => ""), "id" => array("method" => "hidden_zero", "value" => "|arg1:id|"), "_id" => array("method" => "hidden_zero", "value" => "|arg1:id|"), "save_component_alert" => array("method" => "hidden", "value" => "1")); echo "<form method='post' autocomplete='off' onsubmit='changeTypes()' action='syslog_alerts.php' name='chk'>"; draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => inject_form_variables($fields_syslog_alert_edit, isset($alert) ? $alert : array()))); html_end_box(); form_save_button("syslog_alerts.php", "", "id"); ?> <script type='text/javascript'> function changeTypes() { if (document.getElementById('type').value == 'sql') { document.getElementById('message').rows = 6; }else{ document.getElementById('message').rows = 2; } } </script> <?php }
function data_query_edit() { global $colors, $fields_data_query_edit, $config; if (!empty($_GET["id"])) { $snmp_query = db_fetch_row("select * from snmp_query where id=" . $_GET["id"]); $header_label = "[edit: " . $snmp_query["name"] . "]"; }else{ $header_label = "[new]"; } html_start_box("<strong>Data Queries</strong> $header_label", "98%", $colors["header"], "3", "center", ""); draw_edit_form(array( "config" => array(), "fields" => inject_form_variables($fields_data_query_edit, (isset($snmp_query) ? $snmp_query : array())) )); html_end_box(); if (!empty($snmp_query["id"])) { $xml_filename = str_replace("<path_cacti>", $config["base_path"], $snmp_query["xml_path"]); if ((file_exists($xml_filename)) && (is_file($xml_filename))) { $text = "<font color='#0d7c09'><strong>Successfully located XML file</strong></font>"; $xml_file_exists = true; }else{ $text = "<font color='#ff0000'><strong>Could not locate XML file.</strong></font>"; $xml_file_exists = false; } html_start_box("", "98%", "aaaaaa", "3", "center", ""); print "<tr bgcolor='#f5f5f5'><td>$text</td></tr>"; html_end_box(); if ($xml_file_exists == true) { html_start_box("<strong>Associated Graph Templates</strong>", "98%", $colors["header"], "3", "center", "data_queries.php?action=item_edit&snmp_query_id=" . $snmp_query["id"]); print " <tr bgcolor='#" . $colors["header_panel"] . "'> <td><span style='color: white; font-weight: bold;'>Name</span></td> <td><span style='color: white; font-weight: bold;'>Graph Template Name</span></td> <td></td> </tr>"; $snmp_query_graphs = db_fetch_assoc("select snmp_query_graph.id, graph_templates.name as graph_template_name, snmp_query_graph.name from snmp_query_graph left join graph_templates on snmp_query_graph.graph_template_id=graph_templates.id where snmp_query_graph.snmp_query_id=" . $snmp_query["id"] . " order by snmp_query_graph.name"); $i = 0; if (sizeof($snmp_query_graphs) > 0) { foreach ($snmp_query_graphs as $snmp_query_graph) { form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],$i); $i++; ?> <td> <strong><a href="data_queries.php?action=item_edit&id=<?php print $snmp_query_graph["id"];?>&snmp_query_id=<?php print $snmp_query["id"];?>"><?php print $snmp_query_graph["name"];?></a></strong> </td> <td> <?php print $snmp_query_graph["graph_template_name"];?> </td> <td align="right"> <a href="data_queries.php?action=item_remove&id=<?php print $snmp_query_graph["id"];?>&snmp_query_id=<?php print $snmp_query["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 Graph Templates Defined.</em></td></tr>"; } html_end_box(); } } form_save_button("data_queries.php"); }
function data_edit() { global $fields_data_input_edit; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request('id')); /* ==================================================== */ if (!empty($_REQUEST['id'])) { $data_input = db_fetch_row_prepared('SELECT * FROM data_input WHERE id = ?', array(get_request_var_request('id'))); $header_label = '[edit: ' . htmlspecialchars($data_input['name']) . ']'; } else { $header_label = '[new]'; } html_start_box("<strong>Data Input Methods</strong> {$header_label}", '100%', '', '3', 'center', ''); draw_edit_form(array('config' => array(), 'fields' => inject_form_variables($fields_data_input_edit, isset($data_input) ? $data_input : array()))); html_end_box(); if (!empty($_REQUEST['id'])) { html_start_box('<strong>Input Fields</strong>', '100%', '', '3', 'center', 'data_input.php?action=field_edit&type=in&data_input_id=' . htmlspecialchars(get_request_var_request('id'))); print "<tr class='tableHeader'>"; DrawMatrixHeaderItem('Name', '', 1); DrawMatrixHeaderItem('Field Order', '', 1); DrawMatrixHeaderItem('Friendly Name', '', 2); print '</tr>'; $fields = db_fetch_assoc_prepared("SELECT id, data_name, name, sequence FROM data_input_fields WHERE data_input_id = ? AND input_output = 'in' ORDER BY sequence, data_name", array(get_request_var_request('id'))); $i = 0; if (sizeof($fields) > 0) { foreach ($fields as $field) { form_alternate_row('', true); ?> <td> <a class="linkEditMain" href="<?php print htmlspecialchars('data_input.php?action=field_edit&id=' . $field['id'] . '&data_input_id=' . $_REQUEST['id']); ?> "><?php print htmlspecialchars($field['data_name']); ?> </a> </td> <td> <?php print $field['sequence']; if ($field['sequence'] == '0') { print ' (Not In Use)'; } ?> </td> <td> <?php print htmlspecialchars($field['name']); ?> </td> <td align="right"> <a href="<?php print htmlspecialchars('data_input.php?action=field_remove&id=' . $field['id'] . '&data_input_id=' . $_REQUEST['id']); ?> "><img src="images/delete_icon.gif" style="height:10px;width:10px;" border="0" alt="Delete"></a> </td> </tr> <?php } } else { print '<tr><td><em>No Input Fields</em></td></tr>'; } html_end_box(); html_start_box('<strong>Output Fields</strong>', '100%', '', '3', 'center', 'data_input.php?action=field_edit&type=out&data_input_id=' . $_REQUEST['id']); print "<tr class='tableHeader'>"; DrawMatrixHeaderItem('Name', '', 1); DrawMatrixHeaderItem('Field Order', '', 1); DrawMatrixHeaderItem('Friendly Name', '', 1); DrawMatrixHeaderItem('Update RRA', '', 2); print '</tr>'; $fields = db_fetch_assoc_prepared("SELECT id, name, data_name, update_rra, sequence FROM data_input_fields WHERE data_input_id = ? and input_output = 'out' ORDER BY sequence, data_name", array(get_request_var_request('id'))); $i = 0; if (sizeof($fields) > 0) { foreach ($fields as $field) { form_alternate_row('', true); ?> <td> <a class="linkEditMain" href="<?php print htmlspecialchars('data_input.php?action=field_edit&id=' . $field['id'] . '&data_input_id=' . $_REQUEST['id']); ?> "><?php print htmlspecialchars($field['data_name']); ?> </a> </td> <td> <?php print $field['sequence']; if ($field['sequence'] == '0') { print ' (Not In Use)'; } ?> </td> <td> <?php print htmlspecialchars($field['name']); ?> </td> <td> <?php print html_boolean_friendly($field['update_rra']); ?> </td> <td align="right"> <a href="<?php print htmlspecialchars('data_input.php?action=field_remove&id=' . $field['id'] . '&data_input_id=' . $_REQUEST['id']); ?> "><img src="images/delete_icon.gif" style="height:10px;width:10px;" border="0" alt="Delete"></a> </td> </tr> <?php } } else { print '<tr><td><em>No Output Fields</em></td></tr>'; } html_end_box(); } form_save_button('data_input.php', 'return'); }
function graph_template_display_general($graph_template, $header_label) { global $colors; require_once(CACTI_BASE_PATH . "/lib/graph/graph_info.php"); require_once(CACTI_BASE_PATH . "/lib/graph_template/graph_template_info.php"); # fetch all settings for this graph template if (isset($graph_template["id"])) { $template_graph = db_fetch_row("select * from graph_templates_graph where graph_template_id=" . $graph_template["id"] . " and local_graph_id=0"); }else { $template_graph = array(); } print "<form method='post' action='" . basename($_SERVER["PHP_SELF"]) . "' name='graph_template_edit'>\n"; # the template header html_start_box("<strong>" . __("Graph Template") . "</strong> $header_label", "100", $colors["header"], "0", "center", "", true); $header_items = array(__("Field"), __("Value")); print "<tr><td>"; html_header($header_items, 1, true, 'header_template'); draw_edit_form(array( "config" => array("no_form_tag" => true), "fields" => inject_form_variables(graph_template_form_list(), (isset($graph_template) ? $graph_template : array()), (isset($template_graph) ? $template_graph : array())) )); print "</table></td></tr>"; /* end of html_header */ html_end_box(false); form_hidden_box("graph_template_id", (isset($template_graph["graph_template_id"]) ? $template_graph["graph_template_id"] : "0"), ""); form_hidden_box("graph_template_graph_id", (isset($template_graph["id"]) ? $template_graph["id"] : "0"), ""); form_hidden_box("save_component_template", 1, ""); # the global graph template fields go here # html_start_box("<strong>" . __("Graph Template") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template"); /* id tags of tables (set via html_start_box) required for initial js on load */ html_start_box("<strong>" . __("Graph Template Labels") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_labels"); draw_template_edit_form('header_graph_labels', graph_labels_form_list(), $template_graph, false); html_end_box(false); /* TODO: we should not use rrd version in the code, when going data-driven */ if ( read_config_option("rrdtool_version") != RRD_VERSION_1_0 && read_config_option("rrdtool_version") != RRD_VERSION_1_2) { html_start_box("<strong>" . __("Graph Template Right Axis Settings") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_right_axis"); draw_template_edit_form('header_graph_right_axis', graph_right_axis_form_list(), $template_graph, false); } html_end_box(false); html_start_box("<strong>" . __("Graph Template Size") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_size"); draw_template_edit_form('header_graph_size', graph_size_form_list(), $template_graph, false); html_end_box(false); html_start_box("<strong>" . __("Graph Template Limits") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_limits"); draw_template_edit_form('header_graph_limits', graph_limits_form_list(), $template_graph, false); html_end_box(false); html_start_box("<strong>" . __("Graph Template Grid") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_grid"); draw_template_edit_form('header_graph_grid', graph_grid_form_list(), $template_graph, false); html_end_box(false); html_start_box("<strong>" . __("Graph Template Color") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_color"); draw_template_edit_form('header_graph_color', graph_color_form_list(), $template_graph, false); html_end_box(false); html_start_box("<strong>" . __("Graph Template Legend") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_legend"); draw_template_edit_form('header_graph_legend', graph_legend_form_list(), $template_graph, false); html_end_box(false); html_start_box("<strong>" . __("Graph Template Misc") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_misc"); draw_template_edit_form('header_graph_misc', graph_misc_form_list(), $template_graph, false); html_end_box(false); html_start_box("<strong>" . __("Graph Template Cacti Specifics") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_cacti"); draw_template_edit_form('header_graph_cacti', graph_cacti_form_list(), $template_graph, false); html_end_box(false); # the id tag is required for our js code! form_hidden_box("hidden_rrdtool_version", read_config_option("rrdtool_version"), ""); # html_end_box(false); form_save_button_alt("url!graph_templates.php"); include_once(CACTI_BASE_PATH . "/access/js/colorpicker.js"); include_once(CACTI_BASE_PATH . "/access/js/graph_template_options.js"); }
function mactrack_snmp_edit() { global $config, $fields_mactrack_snmp_edit; include_once $config['base_path'] . '/plugins/mactrack/lib/mactrack_functions.php'; /* ================= input validation ================= */ get_filter_request_var('id'); get_filter_request_var('page'); /* ==================================================== */ /* clean up rule name */ if (isset_request_var('name')) { set_request_var('name', sanitize_search_string(get_request_var('name'))); } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value('page', 'sess_mactrack_edit_current_page', '1'); load_current_session_value('rows', 'sess_default_rows', read_config_option('num_rows_table')); /* display the mactrack snmp option set */ $snmp_group = array(); if (!isempty_request_var('id')) { $snmp_group = db_fetch_row_prepared('SELECT * FROM mac_track_snmp where id = ?', array(get_request_var('id'))); $header_label = __('SNMP Option Set [edit: %s]', $snmp_group['name']); } else { $header_label = __('SNMP Option Set [new]'); } form_start('mactrack_snmp.php', 'mactrack_snmp_group'); html_start_box($header_label, '100%', '', '3', 'center', ''); draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => inject_form_variables($fields_mactrack_snmp_edit, $snmp_group))); html_end_box(); form_hidden_box('id', isset_request_var('id') ? get_request_var('id') : '0', ''); form_hidden_box('save_component_mactrack_snmp', '1', ''); if (!isempty_request_var('id')) { $items = db_fetch_assoc_prepared('SELECT * FROM mac_track_snmp_items WHERE snmp_id= ? ORDER BY sequence', array(get_request_var('id'))); html_start_box(__('Mactrack SNMP Options'), '100%', '', '3', 'center', 'mactrack_snmp.php?action=item_edit&id=' . get_request_var('id')); print "<tr class='tableHeader'>"; DrawMatrixHeaderItem(__('Item'), '', 1); DrawMatrixHeaderItem(__('Version'), '', 1); DrawMatrixHeaderItem(__('Community'), '', 1); DrawMatrixHeaderItem(__('Port'), '', 1); DrawMatrixHeaderItem(__('Timeout'), '', 1); DrawMatrixHeaderItem(__('Retries'), '', 1); DrawMatrixHeaderItem(__('Max OIDs'), '', 1); DrawMatrixHeaderItem(__('Username'), '', 1); DrawMatrixHeaderItem(__('Auth Proto'), '', 1); DrawMatrixHeaderItem(__('Priv Proto'), '', 1); DrawMatrixHeaderItem(__('Actions'), '', 1); print '</tr>'; $i = 1; if (sizeof($items)) { foreach ($items as $item) { form_alternate_row(); $form_data = '<td><a class="linkEditMain" href="' . htmlspecialchars('mactrack_snmp.php?action=item_edit&item_id=' . $item['id'] . '&id=' . $item['snmp_id']) . '">Item#' . $i . '</a></td>'; $form_data .= '<td>' . $item['snmp_version'] . '</td>'; $form_data .= '<td>' . ($item['snmp_version'] == 3 ? __('N/A') : $item['snmp_readstring']) . '</td>'; $form_data .= '<td>' . $item['snmp_port'] . '</td>'; $form_data .= '<td>' . $item['snmp_timeout'] . '</td>'; $form_data .= '<td>' . $item['snmp_retries'] . '</td>'; $form_data .= '<td>' . $item['max_oids'] . '</td>'; $form_data .= '<td>' . ($item['snmp_version'] == 3 ? $item['snmp_username'] : __('N/A')) . '</td>'; $form_data .= '<td>' . ($item['snmp_version'] == 3 ? $item['snmp_auth_protocol'] : __('N/A')) . '</td>'; $form_data .= '<td>' . ($item['snmp_version'] == 3 ? $item['snmp_priv_protocol'] : __('N/A')) . '</td>'; $form_data .= '<td class="right">' . ($i < sizeof($items) ? '<a class="remover fa fa-caret-down moveArrow" href="' . htmlspecialchars($config['url_path'] . 'plugins/mactrack/mactrack_snmp.php?action=item_movedown&item_id=' . $item["id"] . '&id=' . $item["snmp_id"]) . '"></a>' : '<span class="moveArrowNone"></span>') . ($i > 1 ? '<a class="remover fa fa-caret-up moveArrow" href="' . htmlspecialchars($config['url_path'] . 'plugins/mactrack/mactrack_snmp.php?action=item_moveup&item_id=' . $item["id"] . '&id=' . $item["snmp_id"]) . '"></a>' : '<span class="moveArrowNone"></span>'); $form_data .= '<a class="delete deleteMarker fa fa-remove" href="' . htmlspecialchars($config['url_path'] . 'plugins/mactrack/mactrack_snmp.php?action=item_remove&item_id=' . $item["id"] . '&id=' . $item["snmp_id"]) . '"></a>' . '</td></tr>'; print $form_data; $i++; } } else { print '<tr><td colspan="5"><em>' . __('No SNMP Items') . '</em></td></tr>'; } html_end_box(); } form_save_button('mactrack_snmp.php'); }
function site_edit() { global $colors; require_once(CACTI_BASE_PATH . "/lib/site/site_info.php"); /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ display_output_messages(); if (!empty($_GET["id"])) { $site = db_fetch_row("select * from sites where id=" . get_request_var("id")); $header_label = "[edit: " . $site["name"] . "]"; }else{ $header_label = "[new]"; } print "<form method='post' action='" . basename($_SERVER["PHP_SELF"]) . "' name='site_edit'>\n"; html_start_box("<strong>" . __("Site") . "</strong> $header_label", "100", $colors["header"], 0, "center", ""); $header_items = array(__("Field"), __("Value")); print "<tr><td>"; html_header($header_items, 1, true, 'site_edit'); draw_edit_form(array( "config" => array("form_name" => "chk", "no_form_tag" => true), "fields" => inject_form_variables(site_form_list(), (isset($site) ? $site : array())) )); print "</table></td></tr>"; /* end of html_header */ html_end_box(); form_hidden_box("id", (isset($site["id"]) ? $site["id"] : "0"), ""); form_hidden_box("hidden_id", (isset($site["hidden_id"]) ? $site["hidden_id"] : "0"), ""); form_hidden_box("save_component_site", "1", ""); form_save_button_alt(); }
function rra_edit() { global $fields_rra_edit; /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ if (!empty($_GET["id"])) { $rra = db_fetch_row("select * from rra where id=" . $_GET["id"]); $header_label = "[edit: " . htmlspecialchars($rra["name"]) . "]"; } else { $header_label = "[new]"; } html_start_box("<strong>Round Robin Archives</strong> {$header_label}", "100%", "", "3", "center", ""); draw_edit_form(array("config" => array(), "fields" => inject_form_variables($fields_rra_edit, isset($rra) ? $rra : array()))); html_end_box(); form_save_button("rra.php"); }
function edit_devices() { global $device_edit; /* ================= input validation ================= */ get_filter_request_var('id'); /* ==================================================== */ $device = array(); if (!isempty_request_var('id')) { $device = db_fetch_row('SELECT * FROM plugin_flowview_devices WHERE id=' . get_request_var('id'), FALSE); $header_label = '[edit: ' . $device['name'] . ']'; } else { $header_label = '[new]'; } form_start('flowview_devices.php', 'chk'); html_start_box("Device: {$header_label}", '100%', '', '3', 'center', ''); draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => inject_form_variables($device_edit, $device))); html_end_box(); form_save_button('flowview_devices.php?tab=listeners'); }
function syslog_action_edit() { global $message_types; include dirname(__FILE__) . '/config.php'; /* ================= input validation ================= */ get_filter_request_var('id'); get_filter_request_var('type'); get_filter_request_var('date'); /* ==================================================== */ if (isset_request_var('id') && get_nfilter_request_var('action') == 'edit') { $removal = syslog_db_fetch_row('SELECT * FROM `' . $syslogdb_default . '`.`syslog_remove` WHERE id=' . get_request_var('id')); if (sizeof($removal)) { $header_label = __('Removal Rule Edit [edit: %s]', $removal['name']); } else { $header_label = __('Removal Rule Edit [new]'); $removal['name'] = __('New Removal Record'); } } else { if (isset_request_var('id') && get_nfilter_request_var('action') == 'newedit') { $syslog_rec = syslog_db_fetch_row('SELECT * FROM `' . $syslogdb_default . '`.`syslog` WHERE seq=' . get_request_var('id') . (isset_request_var('date') ? " AND logtime='" . get_request_var('date') . "'" : "")); $header_label = __('Removal Rule Edit [new]'); if (sizeof($syslog_rec)) { $removal['message'] = $syslog_rec['message']; } $removal['name'] = __('New Removal Rule'); } else { $header_label = '[new]'; $removal['name'] = __('New Removal Record'); } } $fields_syslog_removal_edit = array('spacer0' => array('method' => 'spacer', 'friendly_name' => __('Removel Rule Details')), 'name' => array('method' => 'textbox', 'friendly_name' => __('Removal Rule Name'), 'description' => __('Please describe this Removal Rule.'), 'value' => '|arg1:name|', 'max_length' => '250', 'size' => 80), 'enabled' => array('method' => 'drop_array', 'friendly_name' => __('Enabled?'), 'description' => __('Is this Removal Rule Enabled?'), 'value' => '|arg1:enabled|', 'array' => array('on' => __('Enabled'), '' => __('Disabled')), 'default' => 'on'), 'type' => array('method' => 'drop_array', 'friendly_name' => __('String Match Type'), 'description' => __('Define how you would like this string matched. If using the SQL Expression type you may use any valid SQL expression to generate the alarm. Available fields include \'message\', \'facility\', \'priority\', and \'host\'.'), 'value' => '|arg1:type|', 'array' => $message_types, 'on_change' => 'changeTypes()', 'default' => 'matchesc'), 'message' => array('friendly_name' => __('Syslog Message Match String'), 'description' => __('Enter the matching component of the syslog message, the facility or host name, or the SQL where clause if using the SQL Expression Match Type.'), 'method' => 'textarea', 'textarea_rows' => '2', 'textarea_cols' => '70', 'class' => 'textAreaNotes', 'value' => '|arg1:message|', 'default' => ''), 'rmethod' => array('method' => 'drop_array', 'friendly_name' => __('Method of Removal'), 'value' => '|arg1:method|', 'array' => array('del' => __('Deletion'), 'trans' => __('Transferal')), 'default' => 'del'), 'notes' => array('friendly_name' => __('Removal Rule Notes'), 'textarea_rows' => '5', 'textarea_cols' => '70', 'description' => __('Space for Notes on the Removal rule'), 'method' => 'textarea', 'class' => 'textAreaNotes', 'value' => '|arg1:notes|', 'default' => ''), 'id' => array('method' => 'hidden_zero', 'value' => '|arg1:id|'), '_id' => array('method' => 'hidden_zero', 'value' => '|arg1:id|'), 'save_component_removal' => array('method' => 'hidden', 'value' => '1')); form_start('syslog_removal.php', 'syslog_edit'); html_start_box($header_label, '100%', '', '3', 'center', ''); draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => inject_form_variables($fields_syslog_removal_edit, isset($removal) ? $removal : array()))); html_end_box(); form_save_button('syslog_removal.php', '', 'id'); ?> <script type='text/javascript'> function changeTypes() { if ($('#type').val == 'sql') { $('#message').prop('rows', 5); }else{ $('#message').prop('rows', 2); } } </script> <?php }
function host_edit() { global $colors, $fields_host_edit, $reindex_types; /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ display_output_messages(); if (!empty($_GET["id"])) { $host = db_fetch_row("select * from host where id=" . $_GET["id"]); $header_label = "[edit: " . $host["description"] . "]"; } else { $header_label = "[new]"; } if (!empty($host["id"])) { ?> <table width="100%" align="center"> <tr> <td class="textInfo" colspan="2"> <?php print $host["description"]; ?> (<?php print $host["hostname"]; ?> ) </td> </tr> <tr> <td class="textHeader"> <?php if ($host["availability_method"] == AVAIL_SNMP || $host["availability_method"] == AVAIL_SNMP_AND_PING || $host["availability_method"] == AVAIL_SNMP_OR_PING) { ?> SNMP Information<br> <span style="font-size: 10px; font-weight: normal; font-family: monospace;"> <?php if ($host["snmp_community"] == "" && $host["snmp_username"] == "" || $host["snmp_version"] == 0) { print "<span style='color: #ab3f1e; font-weight: bold;'>SNMP not in use</span>\n"; } else { $snmp_system = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.1.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"], $host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI); /* modify for some system descriptions */ /* 0000937: System output in hosts.php poor for Alcatel */ if (substr_count($snmp_system, "00:")) { $snmp_system = str_replace("00:", "", $snmp_system); $snmp_system = str_replace(":", " ", $snmp_system); } if ($snmp_system == "") { print "<span style='color: #ff0000; font-weight: bold;'>SNMP error</span>\n"; } else { $snmp_uptime = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.3.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"], $host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI); $snmp_hostname = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.5.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"], $host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI); $snmp_location = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.6.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"], $host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI); $snmp_contact = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.4.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"], $host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI); print "<strong>System:</strong>" . html_split_string($snmp_system) . "<br>\n"; $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)); print "<strong>Uptime:</strong> {$snmp_uptime}"; print " ({$days} days, {$hours} hours, {$minutes} minutes)<br>\n"; print "<strong>Hostname:</strong> {$snmp_hostname}<br>\n"; print "<strong>Location:</strong> {$snmp_location}<br>\n"; print "<strong>Contact:</strong> {$snmp_contact}<br>\n"; } } ?> </span> <?php } if ($host["availability_method"] == AVAIL_PING || $host["availability_method"] == AVAIL_SNMP_AND_PING || $host["availability_method"] == AVAIL_SNMP_OR_PING) { /* create new ping socket for host pinging */ $ping = new Net_Ping(); $ping->host = $host; $ping->port = $host["ping_port"]; /* perform the appropriate ping check of the host */ if ($ping->ping($host["availability_method"], $host["ping_method"], $host["ping_timeout"], $host["ping_retries"])) { $host_down = false; $color = "#000000"; } else { $host_down = true; $color = "#ff0000"; } ?> <br>Ping Results<br> <span style="font-size: 10px; font-weight: normal; color: <?php print $color; ?> ; font-family: monospace;"> <?php print $ping->ping_response; ?> </span> <?php } else { if ($host["availability_method"] == AVAIL_NONE) { ?> No Availability Check In Use<br> <?php } } ?> </td> <td class="textInfo" valign="top"> <span style="color: #c16921;">*</span><a href="graphs_new.php?host_id=<?php print $host["id"]; ?> ">Create Graphs for this Host</a><br> <span style="color: #c16921;">*</span><a href="data_sources.php?host_id=<?php print $host["id"]; ?> &ds_rows=30&filter=&template_id=-1&method_id=-1&page=1">Data Source List</a><br> <span style="color: #c16921;">*</span><a href="graphs.php?host_id=<?php print $host["id"]; ?> &graph_rows=30&filter=&template_id=-1&page=1">Graph List</a> </td> </tr> </table> <?php } html_start_box("<strong>Devices</strong> {$header_label}", "100%", $colors["header"], "3", "center", ""); /* preserve the host template id if passed in via a GET variable */ if (!empty($_GET["host_template_id"])) { $fields_host_edit["host_template_id"]["value"] = $_GET["host_template_id"]; } draw_edit_form(array("config" => array("form_name" => "chk"), "fields" => inject_form_variables($fields_host_edit, isset($host) ? $host : array()))); html_end_box(); ?> <script type="text/javascript"> <!-- // default snmp information var snmp_community = document.getElementById('snmp_community').value; var snmp_username = document.getElementById('snmp_username').value; var snmp_password = document.getElementById('snmp_password').value; var snmp_auth_protocol = document.getElementById('snmp_auth_protocol').value; var snmp_priv_passphrase = document.getElementById('snmp_priv_passphrase').value; var snmp_priv_protocol = document.getElementById('snmp_priv_protocol').value; var snmp_context = document.getElementById('snmp_context').value; var snmp_port = document.getElementById('snmp_port').value; var snmp_timeout = document.getElementById('snmp_timeout').value; var max_oids = document.getElementById('max_oids').value; // default ping methods var ping_method = document.getElementById('ping_method').value; var ping_port = document.getElementById('ping_port').value; var ping_timeout = document.getElementById('ping_timeout').value; var ping_retries = document.getElementById('ping_retries').value; var availability_methods = document.getElementById('availability_method').options; var num_methods = document.getElementById('availability_method').length; var selectedIndex = document.getElementById('availability_method').selectedIndex; var agent = navigator.userAgent; agent = agent.match("MSIE"); function setPingVisibility() { availability_method = document.getElementById('availability_method').value; ping_method = document.getElementById('ping_method').value; /* debugging, uncomment as required */ //alert("The availability method is '" + availability_method + "'"); //alert("The ping method is '" + ping_method + "'"); switch(availability_method) { case "0": // none document.getElementById('row_ping_method').style.display = "none"; document.getElementById('row_ping_port').style.display = "none"; document.getElementById('row_ping_timeout').style.display = "none"; document.getElementById('row_ping_retries').style.display = "none"; break; case "2": // snmp document.getElementById('row_ping_method').style.display = "none"; document.getElementById('row_ping_port').style.display = "none"; document.getElementById('row_ping_timeout').style.display = ""; document.getElementById('row_ping_retries').style.display = ""; break; default: // ping ok switch(ping_method) { case "1": // ping icmp document.getElementById('row_ping_method').style.display = ""; document.getElementById('row_ping_port').style.display = "none"; document.getElementById('row_ping_timeout').style.display = ""; document.getElementById('row_ping_retries').style.display = ""; break; case "2": // ping udp case "3": // ping tcp document.getElementById('row_ping_method').style.display = ""; document.getElementById('row_ping_port').style.display = ""; document.getElementById('row_ping_timeout').style.display = ""; document.getElementById('row_ping_retries').style.display = ""; break; } break; } } function addSelectItem(item, formObj) { if (agent != "MSIE") { formObj.add(item,null); // standards compliant }else{ formObj.add(item); // IE only } } function setAvailability(type) { /* get the availability structure */ var am=document.getElementById('availability_method'); /* get current selectedIndex */ selectedIndex = document.getElementById('availability_method').selectedIndex; /* debugging uncomment as required */ //alert("The selectedIndex is '" + selectedIndex + "'"); //alert("The array length is '" + am.length + "'"); switch(type) { case "NoSNMP": /* remove snmp options */ if (am.length == 5) { am.remove(1); am.remove(1); am.remove(1); } /* set the index to something valid, like "ping" */ if (selectedIndex > 1) { am.selectedIndex=1; } break; case "All": /* restore all options */ if (am.length == 2) { am.remove(0); am.remove(0); var a=document.createElement('option'); var b=document.createElement('option'); var c=document.createElement('option'); var d=document.createElement('option'); var e=document.createElement('option'); a.value="0"; a.text="None"; addSelectItem(a,am); b.value="1"; b.text="Ping and SNMP"; addSelectItem(b,am); e.value="4"; e.text="Ping or SNMP"; addSelectItem(e,am); c.value="2"; c.text="SNMP"; addSelectItem(c,am); d.value="3"; d.text="Ping"; addSelectItem(d,am); /* restore the correct index number */ if (selectedIndex == 0) { am.selectedIndex = 0; }else{ am.selectedIndex = 3; } } break; } setAvailabilityVisibility(type, am.selectedIndex); setPingVisibility(); } function setAvailabilityVisibility(type, selectedIndex) { switch(type) { case "NoSNMP": switch(selectedIndex) { case "0": // availability none document.getElementById('row_ping_method').style.display="none"; document.getElementById('ping_method').value=0; break; case "1": // ping document.getElementById('row_ping_method').style.display=""; document.getElementById('ping_method').value=ping_method; break; } case "All": switch(selectedIndex) { case "0": // availability none document.getElementById('row_ping_method').style.display="none"; document.getElementById('ping_method').value=0; break; case "1": // ping and snmp case "3": // ping case "4": // ping or snmp if ((document.getElementById('row_ping_method').style.display == "none") || (document.getElementById('row_ping_method').style.display == undefined)) { document.getElementById('ping_method').value=ping_method; document.getElementById('row_ping_method').style.display=""; } break; case "2": // snmp document.getElementById('row_ping_method').style.display="none"; document.getElementById('ping_method').value="0"; break; } } } function changeHostForm() { snmp_version = document.getElementById('snmp_version').value; switch(snmp_version) { case "0": setAvailability("NoSNMP"); setSNMP("None"); break; case "1": case "2": setAvailability("All"); setSNMP("v1v2"); break; case "3": setAvailability("All"); setSNMP("v3"); break; } } function setSNMP(snmp_type) { switch(snmp_type) { case "None": document.getElementById('row_snmp_username').style.display = "none"; document.getElementById('row_snmp_password').style.display = "none"; document.getElementById('row_snmp_community').style.display = "none"; document.getElementById('row_snmp_auth_protocol').style.display = "none"; document.getElementById('row_snmp_priv_passphrase').style.display = "none"; document.getElementById('row_snmp_priv_protocol').style.display = "none"; document.getElementById('row_snmp_context').style.display = "none"; document.getElementById('row_snmp_port').style.display = "none"; document.getElementById('row_snmp_timeout').style.display = "none"; document.getElementById('row_max_oids').style.display = "none"; break; case "v1v2": document.getElementById('row_snmp_username').style.display = "none"; document.getElementById('row_snmp_password').style.display = "none"; document.getElementById('row_snmp_community').style.display = ""; document.getElementById('row_snmp_auth_protocol').style.display = "none"; document.getElementById('row_snmp_priv_passphrase').style.display = "none"; document.getElementById('row_snmp_priv_protocol').style.display = "none"; document.getElementById('row_snmp_context').style.display = "none"; document.getElementById('row_snmp_port').style.display = ""; document.getElementById('row_snmp_timeout').style.display = ""; document.getElementById('row_max_oids').style.display = ""; break; case "v3": document.getElementById('row_snmp_username').style.display = ""; document.getElementById('row_snmp_password').style.display = ""; document.getElementById('row_snmp_community').style.display = "none"; document.getElementById('row_snmp_auth_protocol').style.display = ""; document.getElementById('row_snmp_priv_passphrase').style.display = ""; document.getElementById('row_snmp_priv_protocol').style.display = ""; document.getElementById('row_snmp_context').style.display = ""; document.getElementById('row_snmp_port').style.display = ""; document.getElementById('row_snmp_timeout').style.display = ""; document.getElementById('row_max_oids').style.display = ""; break; } } function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { if (oldonload) { oldonload(); } func(); } } } addLoadEvent(changeHostForm); --> </script> <?php if (isset($_GET["display_dq_details"]) && isset($_SESSION["debug_log"]["data_query"])) { html_start_box("<strong>Data Query Debug Information</strong>", "100%", $colors["header"], "3", "center", ""); print "<tr><td><span style='font-family: monospace;'>" . debug_log_return("data_query") . "</span></td></tr>"; html_end_box(); } if (!empty($host["id"])) { html_start_box("<strong>Associated Graph Templates</strong>", "100%", $colors["header"], "3", "center", ""); html_header(array("Graph Template Name", "Status"), 2); $selected_graph_templates = db_fetch_assoc("select\n\t\t\tgraph_templates.id,\n\t\t\tgraph_templates.name\n\t\t\tfrom (graph_templates,host_graph)\n\t\t\twhere graph_templates.id=host_graph.graph_template_id\n\t\t\tand host_graph.host_id=" . $_GET["id"] . "\n\t\t\torder by graph_templates.name"); $available_graph_templates = db_fetch_assoc("SELECT\n\t\t\tgraph_templates.id, graph_templates.name\n\t\t\tFROM snmp_query_graph RIGHT JOIN graph_templates\n\t\t\tON (snmp_query_graph.graph_template_id = graph_templates.id)\n\t\t\tWHERE (((snmp_query_graph.name) Is Null)) ORDER BY graph_templates.name"); $i = 0; if (sizeof($selected_graph_templates) > 0) { foreach ($selected_graph_templates as $item) { $i++; /* get status information for this graph template */ $is_being_graphed = sizeof(db_fetch_assoc("select id from graph_local where graph_template_id=" . $item["id"] . " and host_id=" . $_GET["id"])) > 0 ? true : false; ?> <tr> <td style="padding: 4px;"> <strong><?php print $i; ?> )</strong> <?php print $item["name"]; ?> </td> <td> <?php print $is_being_graphed == true ? "<span style='color: green;'>Is Being Graphed</span> (<a href='graphs.php?action=graph_edit&id=" . db_fetch_cell("select id from graph_local where graph_template_id=" . $item["id"] . " and host_id=" . $_GET["id"] . " limit 0,1") . "'>Edit</a>)" : "<span style='color: #484848;'>Not Being Graphed</span>"; ?> </td> <td align='right' nowrap> <a href='host.php?action=gt_remove&id=<?php print $item["id"]; ?> &host_id=<?php print $_GET["id"]; ?> '><img src='images/delete_icon_large.gif' title='Delete Graph Template Association' alt='Delete Graph Template Association' border='0' align='absmiddle'></a> </td> </tr> <?php } } else { print "<tr><td><em>No associated graph templates.</em></td></tr>"; } ?> <tr bgcolor="#<?php print $colors["form_alternate1"]; ?> "> <td colspan="4"> <table cellspacing="0" cellpadding="1" width="100%"> <td nowrap>Add Graph Template: <?php form_dropdown("graph_template_id", $available_graph_templates, "name", "id", "", "", ""); ?> </td> <td align="right"> <input type="image" src="images/button_add.gif" alt="Add" name="add_gt" align="absmiddle"> </td> </table> </td> </tr> <?php html_end_box(); html_start_box("<strong>Associated Data Queries</strong>", "100%", $colors["header"], "3", "center", ""); html_header(array("Data Query Name", "Debugging", "Re-Index Method", "Status"), 2); $selected_data_queries = db_fetch_assoc("select\n\t\t\tsnmp_query.id,\n\t\t\tsnmp_query.name,\n\t\t\thost_snmp_query.reindex_method\n\t\t\tfrom (snmp_query,host_snmp_query)\n\t\t\twhere snmp_query.id=host_snmp_query.snmp_query_id\n\t\t\tand host_snmp_query.host_id=" . $_GET["id"] . "\n\t\t\torder by snmp_query.name"); $available_data_queries = db_fetch_assoc("select\n\t\t\tsnmp_query.id,\n\t\t\tsnmp_query.name\n\t\t\tfrom snmp_query\n\t\t\torder by snmp_query.name"); $keeper = array(); foreach ($available_data_queries as $item) { if (sizeof(db_fetch_assoc("SELECT snmp_query_id FROM host_snmp_query " . " WHERE ((host_id=" . $_GET["id"] . ")" . " and (snmp_query_id=" . $item["id"] . "))")) > 0) { /* do nothing */ } else { array_push($keeper, $item); } } $available_data_queries = $keeper; $i = 0; if (sizeof($selected_data_queries) > 0) { foreach ($selected_data_queries as $item) { $i++; /* get status information for this data query */ $num_dq_items = sizeof(db_fetch_assoc("select snmp_index from host_snmp_cache where host_id=" . $_GET["id"] . " and snmp_query_id=" . $item["id"])); $num_dq_rows = sizeof(db_fetch_assoc("select snmp_index from host_snmp_cache where host_id=" . $_GET["id"] . " and snmp_query_id=" . $item["id"] . " group by snmp_index")); $status = "success"; ?> <tr> <td style="padding: 4px;"> <strong><?php print $i; ?> )</strong> <?php print $item["name"]; ?> </td> <td> (<a href="host.php?action=query_verbose&id=<?php print $item["id"]; ?> &host_id=<?php print $_GET["id"]; ?> ">Verbose Query</a>) </td> <td> <?php print $reindex_types[$item["reindex_method"]]; ?> </td> <td> <?php print $status == "success" ? "<span style='color: green;'>Success</span>" : "<span style='color: green;'>Fail</span>"; ?> [<?php print $num_dq_items; ?> Item<?php print $num_dq_items == 1 ? "" : "s"; ?> , <?php print $num_dq_rows; ?> Row<?php print $num_dq_rows == 1 ? "" : "s"; ?> ] </td> <td align='right' nowrap> <a href='host.php?action=query_reload&id=<?php print $item["id"]; ?> &host_id=<?php print $_GET["id"]; ?> '><img src='images/reload_icon_small.gif' title='Reload Data Query' alt='Reload Data Query' border='0' align='absmiddle'></a> <a href='host.php?action=query_remove&id=<?php print $item["id"]; ?> &host_id=<?php print $_GET["id"]; ?> '><img src='images/delete_icon_large.gif' title='Delete Data Query Association' alt='Delete Data Query Association' border='0' align='absmiddle'></a> </td> </tr> <?php } } else { print "<tr><td><em>No associated data queries.</em></td></tr>"; } ?> <tr bgcolor="#<?php print $colors["form_alternate1"]; ?> "> <td colspan="5"> <table cellspacing="0" cellpadding="1" width="100%"> <td nowrap>Add Data Query: <?php form_dropdown("snmp_query_id", $available_data_queries, "name", "id", "", "", ""); ?> </td> <td nowrap>Re-Index Method: <?php form_dropdown("reindex_method", $reindex_types, "", "", read_config_option("reindex_method"), "", ""); ?> </td> <td align="right"> <input type="image" src="images/button_add.gif" alt="Add" name="add_dq" align="absmiddle"> </td> </table> </td> </tr> <?php html_end_box(); } form_save_button("host.php"); }
function syslog_uninstall_advisor() { global $config, $colors; include dirname(__FILE__) . '/config.php'; syslog_connect(); $syslog_exists = sizeof(syslog_db_fetch_row('SHOW TABLES FROM `' . $syslogdb_default . "` LIKE 'syslog'")); top_header(); $fields_syslog_update = array('uninstall_method' => array('method' => 'drop_array', 'friendly_name' => __('What uninstall method do you want to use?'), 'description' => __('When uninstalling syslog, you can remove everything, or only components, just in case you plan on re-installing in the future.'), 'value' => 'all', 'array' => array('all' => __('Remove Everything (Logs, Tables, Settings)'), 'syslog' => __('Syslog Data Only'))), 'mode' => array('method' => 'hidden', 'value' => 'uninstall'), 'id' => array('method' => 'hidden', 'value' => 'syslog')); print "<form action='plugins.php' method='get'>\n"; print "<table align='center' width='80%'><tr><td>\n"; html_start_box(__('Syslog Uninstall Preferences'), '100%', $colors['header'], '3', 'center', ''); draw_edit_form(array('config' => array(), 'fields' => inject_form_variables($fields_syslog_update, array()))); html_end_box(); syslog_confirm_button('uninstall', 'plugins.php', $syslog_exists); print "</td></tr></table>\n"; bottom_footer(); exit; }
function template_edit() { global $colors, $fields_host_template_edit; /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ display_output_messages(); if (!empty($_GET["id"])) { $host_template = db_fetch_row("select * from host_template where id=" . $_GET["id"]); $header_label = "[edit: " . $host_template["name"] . "]"; }else{ $header_label = "[new]"; $_GET["id"] = 0; } html_start_box("<strong>Host Templates</strong> $header_label", "98%", $colors["header"], "3", "center", ""); draw_edit_form(array( "config" => array(), "fields" => inject_form_variables($fields_host_template_edit, (isset($host_template) ? $host_template : array())) )); html_end_box(); if (!empty($_GET["id"])) { html_start_box("<strong>Associated Graph Templates</strong>", "98%", $colors["header"], "3", "center", ""); $selected_graph_templates = db_fetch_assoc("select graph_templates.id, graph_templates.name from (graph_templates,host_template_graph) where graph_templates.id=host_template_graph.graph_template_id and host_template_graph.host_template_id=" . $_GET["id"] . " order by graph_templates.name"); $i = 0; if (sizeof($selected_graph_templates) > 0) { foreach ($selected_graph_templates as $item) { $i++; ?> <tr> <td style="padding: 4px;"> <strong><?php print $i;?>)</strong> <?php print $item["name"];?> </td> <td align="right"> <a href='host_templates.php?action=item_remove_gt&id=<?php print $item["id"];?>&host_template_id=<?php print $_GET["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 associated graph templates.</em></td></tr>"; } ?> <tr bgcolor="#<?php print $colors["form_alternate1"];?>"> <td colspan="2"> <table cellspacing="0" cellpadding="1" width="100%"> <td nowrap>Add Graph Template: <?php form_dropdown("graph_template_id",db_fetch_assoc("select graph_templates.id, graph_templates.name from graph_templates left join host_template_graph on (graph_templates.id=host_template_graph.graph_template_id and host_template_graph.host_template_id=" . $_GET["id"] . ") where host_template_graph.host_template_id is null order by graph_templates.name"),"name","id","","","");?> </td> <td align="right"> <input type="image" src="images/button_add.gif" alt="Add" name="add_gt" align="absmiddle"> </td> </table> </td> </tr> <?php html_end_box(); html_start_box("<strong>Associated Data Queries</strong>", "98%", $colors["header"], "3", "center", ""); $selected_data_queries = db_fetch_assoc("select snmp_query.id, snmp_query.name from (snmp_query,host_template_snmp_query) where snmp_query.id=host_template_snmp_query.snmp_query_id and host_template_snmp_query.host_template_id=" . $_GET["id"] . " order by snmp_query.name"); $i = 0; if (sizeof($selected_data_queries) > 0) { foreach ($selected_data_queries as $item) { $i++; ?> <tr> <td style="padding: 4px;"> <strong><?php print $i;?>)</strong> <?php print $item["name"];?> </td> <td align='right'> <a href='host_templates.php?action=item_remove_dq&id=<?php print $item["id"];?>&host_template_id=<?php print $_GET["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 associated data queries.</em></td></tr>"; } ?> <tr bgcolor="#<?php print $colors["form_alternate1"];?>"> <td colspan="2"> <table cellspacing="0" cellpadding="1" width="100%"> <td nowrap>Add Data Query: <?php form_dropdown("snmp_query_id",db_fetch_assoc("select snmp_query.id, snmp_query.name from snmp_query left join host_template_snmp_query on (snmp_query.id=host_template_snmp_query.snmp_query_id and host_template_snmp_query.host_template_id=" . $_GET["id"] . ") where host_template_snmp_query.host_template_id is null order by snmp_query.name"),"name","id","","","");?> </td> <td align="right"> <input type="image" src="images/button_add.gif" alt="Add" name="add_dq" align="absmiddle"> </td> </table> </td> </tr> <?php html_end_box(); } form_save_button("host_templates.php"); }
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 settings() { global $tabs_graphs, $settings_graphs, $current_user, $graph_views, $current_user; /* you cannot have per-user graph settings if cacti's user management is not turned on */ if (read_config_option('auth_method') == 0) { raise_message(6); display_output_messages(); return; } if ($_REQUEST['action'] == 'edit') { if (isset($_SERVER['HTTP_REFERER'])) { $timespan_sel_pos = strpos($_SERVER['HTTP_REFERER'], '&predefined_timespan'); if ($timespan_sel_pos) { $_SERVER['HTTP_REFERER'] = substr($_SERVER['HTTP_REFERER'], 0, $timespan_sel_pos); } } $_SESSION['profile_referer'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'graph_view.php'; } print "<form method='post' action='auth_profile.php'>\n"; html_start_box('<strong>User Settings</strong>', '100%', '', '3', 'center', ''); $current_user = db_fetch_row_prepared('SELECT * FROM user_auth WHERE id = ?', array($_SESSION['sess_user_id'])); if (!sizeof($current_user)) { return; } /* file: user_admin.php, action: user_edit (host) */ $fields_user = array('username' => array('method' => 'value', 'friendly_name' => 'User Name', 'description' => 'The login name for this user.', 'value' => '|arg1:username|', 'max_length' => '40', 'size' => '40'), 'full_name' => array('method' => 'textbox', 'friendly_name' => 'Full Name', 'description' => 'A more descriptive name for this user, that can include spaces or special characters.', 'value' => '|arg1:full_name|', 'max_length' => '120', 'size' => '60'), 'email_address' => array('method' => 'textbox', 'friendly_name' => 'E-Mail Address', 'description' => 'An E-Mail Address you be reached at.', 'value' => '|arg1:email_address|', 'max_length' => '60', 'size' => '60')); draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => inject_form_variables($fields_user, isset($current_user) ? $current_user : array()))); html_end_box(); if (is_view_allowed('graph_settings') == true) { if (read_config_option('auth_method') != 0) { $settings_graphs['tree']['default_tree_id']['sql'] = get_graph_tree_array(true); } html_start_box('<strong>Graph Settings</strong>', '100%', '', '3', 'center', ''); while (list($tab_short_name, $tab_fields) = each($settings_graphs)) { $collapsible = true; print "<tr class='spacer tableHeader" . ($collapsible ? ' collapsible' : '') . "' id='row_{$tab_short_name}'><td colspan='2' style='cursor:pointer;' class='tableSubHeaderColumn'>" . $tabs_graphs[$tab_short_name] . ($collapsible ? "<div style='float:right;padding-right:4px;'><i class='fa fa-angle-double-up'></i></div>" : "") . "</td></tr>\n"; $form_array = array(); while (list($field_name, $field_array) = each($tab_fields)) { $form_array += array($field_name => $tab_fields[$field_name]); if (isset($field_array['items']) && is_array($field_array['items'])) { while (list($sub_field_name, $sub_field_array) = each($field_array['items'])) { if (graph_config_value_exists($sub_field_name, $_SESSION['sess_user_id'])) { $form_array[$field_name]['items'][$sub_field_name]['form_id'] = 1; } $form_array[$field_name]['items'][$sub_field_name]['value'] = db_fetch_cell_prepared('SELECT value FROM settings_graphs WHERE name = ? AND user_id = ?', array($sub_field_name, $_SESSION['sess_user_id'])); } } else { if (graph_config_value_exists($field_name, $_SESSION['sess_user_id'])) { $form_array[$field_name]['form_id'] = 1; } $form_array[$field_name]['value'] = db_fetch_cell_prepared('SELECT value FROM settings_graphs WHERE name = ? AND user_id = ?', array($field_name, $_SESSION['sess_user_id'])); } } draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => $form_array)); } html_end_box(); } ?> <script type="text/javascript"> <!-- var themeFonts=<?php print read_config_option('font_method'); ?> ; function graphSettings() { if (themeFonts == 1) { $('#row_fonts').hide(); $('#row_custom_fonts').hide(); $('#row_title_size').hide(); $('#row_title_font').hide(); $('#row_legend_size').hide(); $('#row_legend_font').hide(); $('#row_axis_size').hide(); $('#row_axis_font').hide(); $('#row_unit_size').hide(); $('#row_unit_font').hide(); }else{ var custom_fonts = $('#custom_fonts').is(':checked'); switch(custom_fonts) { case true: $('#row_fonts').show(); $('#row_title_size').show(); $('#row_title_font').show(); $('#row_legend_size').show(); $('#row_legend_font').show(); $('#row_axis_size').show(); $('#row_axis_font').show(); $('#row_unit_size').show(); $('#row_unit_font').show(); break; case false: $('#row_fonts').show(); $('#row_title_size').hide(); $('#row_title_font').hide(); $('#row_legend_size').hide(); $('#row_legend_font').hide(); $('#row_axis_size').hide(); $('#row_axis_font').hide(); $('#row_unit_size').hide(); $('#row_unit_font').hide(); break; } } if ($('#timespan_sel').is(':checked')) { $('#row_default_rra_id').hide(); $('#row_default_timespan').show(); $('#row_default_timeshift').show(); $('#row_allow_graph_dates_in_future').show(); $('#row_first_weekdayid').show(); $('#row_day_shift_start').show(); $('#row_day_shift_end').show(); } else { $('#row_default_rra_id').show(); $('#row_default_timespan').hide(); $('#row_default_timeshift').hide(); $('#row_allow_graph_dates_in_future').hide(); $('#row_first_weekdayid').hide(); $('#row_day_shift_start').hide(); $('#row_day_shift_end').hide(); } } $(function() { graphSettings(); $('#navigation').show(); $('#navigation_right').show(); $('input[value="Save"]').unbind().click(function(event) { event.preventDefault(); href='<?php print $_SERVER['HTTP_REFERER']; ?> '; href=href+(href.indexOf('?') > 0 ? '&':'?')+'header=false'; $.post('auth_profile.php?header=false', $('input, select, textarea').serialize()).done(function(data) { $.get('auth_profile.php?action=noreturn&header=false', function(data) { $('#main').html(data); applySkin(); }); }); }); $('input[value="Return"]').unbind().click(function(event) { console.log('The refer is:<?php print $_SESSION['profile_referer']; ?> '); document.location = '<?php print $_SESSION['profile_referer']; ?> '; }); $('#timespan_sel').change(function() { graphSettings(); }); }); --> </script> <?php form_hidden_box('save_component_graph_config', '1', ''); form_save_buttons(array(array('id' => 'return', 'value' => 'Return'), array('id' => 'save', 'value' => 'Save'))); }
function host_edit() { global $colors, $fields_host_edit, $reindex_types; display_output_messages(); if (!empty($_GET["id"])) { $host = db_fetch_row("select * from host where id=" . $_GET["id"]); $header_label = "[edit: " . $host["description"] . "]"; }else{ $header_label = "[new]"; } if (!empty($host["id"])) { ?> <table width="98%" align="center"> <tr> <td class="textInfo" colspan="2"> <?php print $host["description"];?> (<?php print $host["hostname"];?>) </td> </tr> <tr> <td class="textHeader"> SNMP Information<br> <span style="font-size: 10px; font-weight: normal; font-family: monospace;"> <?php if (($host["snmp_community"] == "") && ($host["snmp_username"] == "")) { print "<span style='color: #ab3f1e; font-weight: bold;'>SNMP not in use</span>\n"; }else{ $snmp_system = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.1.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_port"], $host["snmp_timeout"], SNMP_WEBUI); if ($snmp_system == "") { print "<span style='color: #ff0000; font-weight: bold;'>SNMP error</span>\n"; }else{ $snmp_uptime = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.3.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_port"], $host["snmp_timeout"], SNMP_WEBUI); $snmp_hostname = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.5.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_port"], $host["snmp_timeout"], SNMP_WEBUI); print "<strong>System:</strong> $snmp_system<br>\n"; print "<strong>Uptime:</strong> $snmp_uptime<br>\n"; print "<strong>Hostname:</strong> $snmp_hostname<br>\n"; } } ?> </span> </td> <td class="textInfo" valign="top"> <span style="color: #c16921;">*</span><a href="graphs_new.php?host_id=<?php print $host["id"];?>">Create Graphs for this Host</a> </td> </tr> </table> <br> <?php } html_start_box("<strong>Devices</strong> $header_label", "98%", $colors["header"], "3", "center", ""); /* preserve the host template id if passed in via a GET variable */ if (!empty($_GET["host_template_id"])) { $fields_host_edit["host_template_id"]["value"] = $_GET["host_template_id"]; } draw_edit_form(array( "config" => array("form_name" => "chk"), "fields" => inject_form_variables($fields_host_edit, (isset($host) ? $host : array())) )); html_end_box(); if ((isset($_GET["display_dq_details"])) && (isset($_SESSION["debug_log"]["data_query"]))) { html_start_box("<strong>Data Query Debug Information</strong>", "98%", $colors["header"], "3", "center", ""); print "<tr><td><span style='font-family: monospace;'>" . debug_log_return("data_query") . "</span></td></tr>"; html_end_box(); } if (!empty($host["id"])) { html_start_box("<strong>Associated Graph Templates</strong>", "98%", $colors["header"], "3", "center", ""); html_header(array("Graph Template Name", "Status"), 2); $selected_graph_templates = db_fetch_assoc("select graph_templates.id, graph_templates.name from graph_templates,host_graph where graph_templates.id=host_graph.graph_template_id and host_graph.host_id=" . $_GET["id"] . " order by graph_templates.name"); $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"); $i = 0; if (sizeof($selected_graph_templates) > 0) { foreach ($selected_graph_templates as $item) { $i++; /* get status information for this graph template */ $is_being_graphed = (sizeof(db_fetch_assoc("select id from graph_local where graph_template_id=" . $item["id"] . " and host_id=" . $_GET["id"])) > 0) ? true : false; ?> <tr> <td style="padding: 4px;"> <strong><?php print $i;?>)</strong> <?php print $item["name"];?> </td> <td> <?php print (($is_being_graphed == true) ? "<span style='color: green;'>Is Being Graphed</span> (<a href='graphs.php?action=graph_edit&id=" . db_fetch_cell("select id from graph_local where graph_template_id=" . $item["id"] . " and host_id=" . $_GET["id"] . " limit 0,1") . "'>Edit</a>)" : "<span style='color: #484848;'>Not Being Graphed</span>");?> </td> <td align='right' nowrap> <a href='host.php?action=gt_remove&id=<?php print $item["id"];?>&host_id=<?php print $_GET["id"];?>'><img src='images/delete_icon_large.gif' alt='Delete Graph Template Association' border='0' align='absmiddle'></a> </td> </tr> <?php } }else{ print "<tr><td><em>No associated graph templates.</em></td></tr>"; } ?> <tr bgcolor="#<?php print $colors["form_alternate1"];?>"> <td colspan="4"> <table cellspacing="0" cellpadding="1" width="100%"> <td nowrap>Add Graph Template: <?php form_dropdown("graph_template_id",$available_graph_templates,"name","id","","","");?> </td> <td align="right"> <input type="image" src="images/button_add.gif" alt="Add" name="add_gt" align="absmiddle"> </td> </table> </td> </tr> <?php html_end_box(); html_start_box("<strong>Associated Data Queries</strong>", "98%", $colors["header"], "3", "center", ""); html_header(array("Data Query Name", "Debugging", "Re-Index Method", "Status"), 2); $selected_data_queries = db_fetch_assoc("select snmp_query.id, snmp_query.name, host_snmp_query.reindex_method from snmp_query,host_snmp_query where snmp_query.id=host_snmp_query.snmp_query_id and host_snmp_query.host_id=" . $_GET["id"] . " order by snmp_query.name"); $available_data_queries = db_fetch_assoc("select snmp_query.id, snmp_query.name from snmp_query order by snmp_query.name"); $keeper = array(); foreach ($available_data_queries as $item) { if (sizeof(db_fetch_assoc("SELECT snmp_query_id FROM host_snmp_query " . " WHERE ((host_id=" . $_GET["id"] . ")" . " and (snmp_query_id=" . $item["id"] ."))")) > 0) { /* do nothing */ } else { array_push($keeper, $item); } } $available_data_queries = $keeper; $i = 0; if (sizeof($selected_data_queries) > 0) { foreach ($selected_data_queries as $item) { $i++; /* get status information for this data query */ $num_dq_items = sizeof(db_fetch_assoc("select snmp_index from host_snmp_cache where host_id=" . $_GET["id"] . " and snmp_query_id=" . $item["id"])); $num_dq_rows = sizeof(db_fetch_assoc("select snmp_index from host_snmp_cache where host_id=" . $_GET["id"] . " and snmp_query_id=" . $item["id"] . " group by snmp_index")); $status = "success"; ?> <tr> <td style="padding: 4px;"> <strong><?php print $i;?>)</strong> <?php print $item["name"];?> </td> <td> (<a href="host.php?action=query_verbose&id=<?php print $item["id"];?>&host_id=<?php print $_GET["id"];?>">Verbose Query</a>) </td> <td> <?php print $reindex_types{$item["reindex_method"]};?> </td> <td> <?php print (($status == "success") ? "<span style='color: green;'>Success</span>" : "<span style='color: green;'>Fail</span>");?> [<?php print $num_dq_items;?> Item<?php print ($num_dq_items == 1 ? "" : "s");?>, <?php print $num_dq_rows;?> Row<?php print ($num_dq_rows == 1 ? "" : "s");?>] </td> <td align='right' nowrap> <a href='host.php?action=query_reload&id=<?php print $item["id"];?>&host_id=<?php print $_GET["id"];?>'><img src='images/reload_icon_small.gif' alt='Reload Data Query' border='0' align='absmiddle'></a> <a href='host.php?action=query_remove&id=<?php print $item["id"];?>&host_id=<?php print $_GET["id"];?>'><img src='images/delete_icon_large.gif' alt='Delete Data Query Association' border='0' align='absmiddle'></a> </td> </tr> <?php } }else{ print "<tr><td><em>No associated data queries.</em></td></tr>"; } ?> <tr bgcolor="#<?php print $colors["form_alternate1"];?>"> <td colspan="5"> <table cellspacing="0" cellpadding="1" width="100%"> <td nowrap>Add Data Query: <?php form_dropdown("snmp_query_id",$available_data_queries,"name","id","","","");?> </td> <td nowrap>Re-Index Method: <?php form_dropdown("reindex_method",$reindex_types,"","","1","","");?> </td> <td align="right"> <input type="image" src="images/button_add.gif" alt="Add" name="add_dq" align="absmiddle"> </td> </table> </td> </tr> <?php html_end_box(); } form_save_button("host.php"); }
function cdef_edit() { global $colors, $cdef_item_types, $fields_cdef_edit; /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ if (!empty($_GET["id"])) { $cdef = db_fetch_row("select * from cdef where id=" . $_GET["id"]); $header_label = "[edit: " . $cdef["name"] . "]"; }else{ $header_label = "[new]"; } html_start_box("<strong>CDEF's</strong> $header_label", "98%", $colors["header"], "3", "center", ""); draw_edit_form(array( "config" => array(), "fields" => inject_form_variables($fields_cdef_edit, (isset($cdef) ? $cdef : array())) )); html_end_box(); if (!empty($_GET["id"])) { html_start_box("", "98%", "aaaaaa", "3", "center", ""); draw_cdef_preview($_GET["id"]); html_end_box(); html_start_box("<strong>CDEF Items</strong>", "98%", $colors["header"], "3", "center", "cdef.php?action=item_edit&cdef_id=" . $cdef["id"]); print "<tr bgcolor='#" . $colors["header_panel"] . "'>"; DrawMatrixHeaderItem("Item",$colors["header_text"],1); DrawMatrixHeaderItem("Item Value",$colors["header_text"],1); DrawMatrixHeaderItem(" ",$colors["header_text"],2); print "</tr>"; $cdef_items = db_fetch_assoc("select * from cdef_items where cdef_id=" . $_GET["id"] . " order by sequence"); $i = 0; if (sizeof($cdef_items) > 0) { foreach ($cdef_items as $cdef_item) { form_alternate_row_color($colors["alternate"],$colors["light"],$i); $i++; ?> <td> <a class="linkEditMain" href="cdef.php?action=item_edit&id=<?php print $cdef_item["id"];?>&cdef_id=<?php print $cdef["id"];?>">Item #<?php print $i;?></a> </td> <td> <em><?php $cdef_item_type = $cdef_item["type"]; print $cdef_item_types[$cdef_item_type];?></em>: <strong><?php print get_cdef_item_name($cdef_item["id"]);?></strong> </td> <td> <a href="cdef.php?action=item_movedown&id=<?php print $cdef_item["id"];?>&cdef_id=<?php print $cdef["id"];?>"><img src="images/move_down.gif" border="0" alt="Move Down"></a> <a href="cdef.php?action=item_moveup&id=<?php print $cdef_item["id"];?>&cdef_id=<?php print $cdef["id"];?>"><img src="images/move_up.gif" border="0" alt="Move Up"></a> </td> <td align="right"> <a href="cdef.php?action=item_remove&id=<?php print $cdef_item["id"];?>&cdef_id=<?php print $cdef["id"];?>"><img src="images/delete_icon.gif" width="10" height="10" border="0" alt="Delete"></a> </td> </tr> <?php } } html_end_box(); } form_save_button("cdef.php"); }
function tree_edit() { global $colors, $fields_tree_edit; /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ /* clean up subaction */ if (isset($_REQUEST["subaction"])) { $_REQUEST["subaction"] = sanitize_search_string(get_request_var("subaction")); } if (!empty($_GET["id"])) { $tree = db_fetch_row("select * from graph_tree where id=" . $_GET["id"]); $header_label = "[edit: " . $tree["name"] . "]"; }else{ $header_label = "[new]"; } html_start_box("<strong>Graph Trees</strong> $header_label", "100%", $colors["header"], "3", "center", ""); draw_edit_form(array( "config" => array(), "fields" => inject_form_variables($fields_tree_edit, (isset($tree) ? $tree : array())) )); html_end_box(); if (!empty($_GET["id"])) { html_start_box("<strong>Tree Items</strong>", "100%", $colors["header"], "3", "center", "tree.php?action=item_edit&tree_id=" . $tree["id"] . "&parent_id=0"); ?> <td> <a href='tree.php?action=edit&id=<?php print $_GET["id"];?>&subaction=expand_all'><img src='images/button_expand_all.gif' border='0' alt='Expand All'></a> <a href='tree.php?action=edit&id=<?php print $_GET["id"];?>&subaction=colapse_all'><img src='images/button_colapse_all.gif' border='0' alt='Colapse All'></a> </td> <?php print "<tr bgcolor='#" . $colors["header_panel"] . "'>"; DrawMatrixHeaderItem("Item",$colors["header_text"],1); DrawMatrixHeaderItem("Value",$colors["header_text"],1); DrawMatrixHeaderItem(" ",$colors["header_text"],2); print "</tr>"; grow_edit_graph_tree($_GET["id"], "", ""); html_end_box(); } form_save_button("tree.php"); }
function template_edit() { global $colors, $struct_graph, $image_types, $fields_graph_template_template_edit; /* graph item list goes here */ if (!empty($_GET["id"])) { item(); } if (!empty($_GET["id"])) { $template = db_fetch_row("select * from graph_templates where id=" . $_GET["id"]); $template_graph = db_fetch_row("select * from graph_templates_graph where graph_template_id=" . $_GET["id"] . " and local_graph_id=0"); $header_label = "[edit: " . $template["name"] . "]"; }else{ $header_label = "[new]"; } html_start_box("<strong>Template</strong> $header_label", "98%", $colors["header"], "3", "center", ""); draw_edit_form(array( "config" => array(), "fields" => inject_form_variables($fields_graph_template_template_edit, (isset($template) ? $template : array()), (isset($template_graph) ? $template_graph : array())) )); html_end_box(); html_start_box("<strong>Graph Template</strong>", "98%", $colors["header"], "3", "center", ""); $form_array = array(); while (list($field_name, $field_array) = each($struct_graph)) { $form_array += array($field_name => $struct_graph[$field_name]); $form_array[$field_name]["value"] = (isset($template_graph) ? $template_graph[$field_name] : ""); $form_array[$field_name]["form_id"] = (isset($template_graph) ? $template_graph["id"] : "0"); $form_array[$field_name]["description"] = ""; $form_array[$field_name]["sub_checkbox"] = array( "name" => "t_" . $field_name, "friendly_name" => "Use Per-Graph Value (Ignore this Value)", "value" => (isset($template_graph) ? $template_graph{"t_" . $field_name} : "") ); } draw_edit_form( array( "config" => array( ), "fields" => $form_array ) ); html_end_box(); form_save_button("graph_templates.php"); }
function template_edit() { global $fields_host_template_edit; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request('id')); /* ==================================================== */ if (!empty($_REQUEST['id'])) { $host_template = db_fetch_row_prepared('SELECT * FROM host_template WHERE id = ?', array(get_request_var_request('id'))); $header_label = '[edit: ' . $host_template['name'] . ']'; } else { $header_label = '[new]'; $_REQUEST['id'] = 0; } html_start_box('<strong>Device Templates</strong> ' . htmlspecialchars($header_label), '100%', '', '3', 'center', ''); draw_edit_form(array('config' => array('form_name' => 'chk'), 'fields' => inject_form_variables($fields_host_template_edit, isset($host_template) ? $host_template : array()))); /* we have to hide this button to make a form change in the main form trigger the correct * submit action */ echo "<div style='display:none;'><input type='submit' value='Default Submit Button'></div>"; html_end_box(); if (!empty($_REQUEST['id'])) { html_start_box('<strong>Associated Graph Templates</strong>', '100%', '', '3', 'center', ''); $selected_graph_templates = db_fetch_assoc_prepared('SELECT graph_templates.id, graph_templates.name FROM (graph_templates,host_template_graph) WHERE graph_templates.id = host_template_graph.graph_template_id AND host_template_graph.host_template_id = ? ORDER BY graph_templates.name', array(get_request_var_request('id'))); $i = 0; if (sizeof($selected_graph_templates) > 0) { foreach ($selected_graph_templates as $item) { form_alternate_row('', true); ?> <td style="padding: 4px;"> <strong><?php print $i; ?> )</strong> <?php print htmlspecialchars($item['name']); ?> </td> <td align="right"> <a href='<?php print htmlspecialchars('host_templates.php?action=item_remove_gt&id=' . $item['id'] . '&host_template_id=' . $_REQUEST['id']); ?> '><img src='images/delete_icon.gif' style="height:10px;width:10px;" border='0' alt='Delete'></a> </td> <?php form_end_row(); $i++; } } else { print '<tr><td><em>No associated graph templates.</em></td></tr>'; } ?> <tr class='odd'> <td colspan="2"> <table cellspacing="0" cellpadding="1" width="100%"> <td nowrap>Add Graph Template: <?php form_dropdown('graph_template_id', db_fetch_assoc_prepared('SELECT graph_templates.id, graph_templates.name FROM graph_templates LEFT JOIN host_template_graph ON (graph_templates.id = host_template_graph.graph_template_id AND host_template_graph.host_template_id = ?) WHERE host_template_graph.host_template_id is null ORDER BY graph_templates.name', array(get_request_var_request('id'))), 'name', 'id', '', '', ''); ?> </td> <td align="right"> <input type="submit" value="Add" name="add_gt_x" title="Add Graph Template to Device Template"> </td> </table> </td> </tr> <?php html_end_box(); html_start_box('<strong>Associated Data Queries</strong>', '100%', '', '3', 'center', ''); $selected_data_queries = db_fetch_assoc_prepared('SELECT snmp_query.id, snmp_query.name FROM (snmp_query, host_template_snmp_query) WHERE snmp_query.id = host_template_snmp_query.snmp_query_id AND host_template_snmp_query.host_template_id = ? ORDER BY snmp_query.name', array(get_request_var_request('id'))); $i = 0; if (sizeof($selected_data_queries) > 0) { foreach ($selected_data_queries as $item) { form_alternate_row('', true); ?> <td style="padding: 4px;"> <strong><?php print $i; ?> )</strong> <?php print htmlspecialchars($item['name']); ?> </td> <td align='right'> <a href='<?php print htmlspecialchars('host_templates.php?action=item_remove_dq&id=' . $item['id'] . '&host_template_id=' . $_REQUEST['id']); ?> '><img src='images/delete_icon.gif' style="height:10px;width:10px;" border='0' alt='Delete'></a> </td> <?php form_end_row(); $i++; } } else { print '<tr><td><em>No associated data queries.</em></td></tr>'; } ?> <tr class='odd'> <td colspan="2"> <table cellspacing="0" cellpadding="1" width="100%"> <td nowrap>Add Data Query: <?php form_dropdown('snmp_query_id', db_fetch_assoc_prepared('SELECT snmp_query.id, snmp_query.name FROM snmp_query LEFT JOIN host_template_snmp_query ON (snmp_query.id = host_template_snmp_query.snmp_query_id AND host_template_snmp_query.host_template_id = ?) WHERE host_template_snmp_query.host_template_id is null ORDER BY snmp_query.name', array(get_request_var_request('id'))), 'name', 'id', '', '', ''); ?> </td> <td align="right"> <input type="submit" value="Add" name="add_dq_x" title="Add Data Query to Device Template"> </td> </table> </td> </tr> <?php html_end_box(); } form_save_button('host_templates.php', 'return'); }
function user_edit() { global $colors, $fields_user_user_edit_host; if (!empty($_GET["id"])) { $user = db_fetch_row("select * from user_auth where id=" . $_GET["id"]); $header_label = "[edit: " . $user["username"] . "]"; }else{ $header_label = "[new]"; } html_start_box("<strong>User Management</strong> $header_label", "98%", $colors["header"], "3", "center", ""); draw_edit_form(array( "config" => array("form_name" => "chk"), "fields" => inject_form_variables($fields_user_user_edit_host, (isset($user) ? $user : array())) )); html_end_box(); if (!empty($_GET["id"])) { /* draw user admin nav tabs */ ?> <table class='tabs' width='98%' cellspacing='0' cellpadding='3' align='center'> <tr> <td width='1'></td> <td <?php print ((($_GET["action"] == "user_realms_edit") || ($_GET["action"] == "user_edit")) ? "bgcolor='silver'" : "bgcolor='#DFDFDF'");?> nowrap='nowrap' width='150' align='center' class='tab'> <span class='textHeader'><a href='user_admin.php?action=user_realms_edit&id=<?php print $_GET["id"];?>'>Realm Permissions</a></span> </td> <td width='1'></td> <td <?php print (($_GET["action"] == "graph_perms_edit") ? "bgcolor='silver'" : "bgcolor='#DFDFDF'");?> nowrap='nowrap' width='150' align='center' class='tab'> <span class='textHeader'><a href='user_admin.php?action=graph_perms_edit&id=<?php print $_GET["id"];?>'>Graph Permissions</a></span> </td> <td width='1'></td> <td <?php print (($_GET["action"] == "graph_settings_edit") ? "bgcolor='silver'" : "bgcolor='#DFDFDF'");?> nowrap='nowrap' width='130' align='center' class='tab'> <span class='textHeader'><a href='user_admin.php?action=graph_settings_edit&id=<?php print $_GET["id"];?>'>Graph Settings</a></span> </td> <td></td> </tr> </table> <?php } if ($_GET["action"] == "graph_settings_edit") { graph_settings_edit(); }elseif ($_GET["action"] == "user_realms_edit") { user_realms_edit(); }elseif ($_GET["action"] == "graph_perms_edit") { graph_perms_edit(); }else{ user_realms_edit(); } form_save_button("user_admin.php"); }
function gprint_presets_edit() { global $colors, $fields_grprint_presets_edit; /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ if (!empty($_GET["id"])) { $gprint_preset = db_fetch_row("select * from graph_templates_gprint where id=" . $_GET["id"]); $header_label = "[edit: " . $gprint_preset["name"] . "]"; }else{ $header_label = "[new]"; } html_start_box("<strong>GPRINT Presets</strong> $header_label", "100%", $colors["header"], "3", "center", ""); draw_edit_form(array( "config" => array(), "fields" => inject_form_variables($fields_grprint_presets_edit, (isset($gprint_preset) ? $gprint_preset : array())) )); html_end_box(); form_save_button("gprint_presets.php"); }
function poller_edit() { global $colors; require_once(CACTI_BASE_PATH . "/lib/poller/poller_info.php"); /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ /* remember if there's something we want to show to the user */ $debug_log = debug_log_return("poller"); if (!empty($debug_log)) { debug_log_clear("poller"); ?> <table class='topBoxAlt'> <tr bgcolor="<?php print $colors["light"];?>"> <td class='mono'> <?php print $debug_log;?> </td> </tr> </table> <br> <?php } if (!empty($_GET["id"])) { $poller = db_fetch_row("select * from poller where id=" . $_GET["id"]); $header_label = __("[edit: ") . $poller["description"] . "]"; }else{ $header_label = __("[new]"); $_GET["id"] = 0; } print "<form method='post' action='" . basename($_SERVER["PHP_SELF"]) . "' name='poller_edit'>\n"; html_start_box("<strong>" . __("Pollers") . "</strong> $header_label", "100", $colors["header"], 0, "center", "", true); $header_items = array(__("Field"), __("Value")); print "<tr><td>"; html_header($header_items, 1, true, 'poller_edit'); draw_edit_form(array( "config" => array(), "fields" => inject_form_variables(poller_form_list(), (isset($poller) ? $poller : array())) )); print "</table></td></tr>"; /* end of html_header */ html_end_box(); form_save_button_alt(); }
function template_edit() { global $colors, $struct_graph, $image_types, $fields_graph_template_template_edit; /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ /* graph item list goes here */ if (!empty($_GET["id"])) { item(); } if (!empty($_GET["id"])) { $template = db_fetch_row("select * from graph_templates where id=" . $_GET["id"]); $template_graph = db_fetch_row("select * from graph_templates_graph where graph_template_id=" . $_GET["id"] . " and local_graph_id=0"); $header_label = "[edit: " . $template["name"] . "]"; } else { $header_label = "[new]"; } html_start_box("<strong>Template</strong> {$header_label}", "100%", $colors["header"], "3", "center", ""); draw_edit_form(array("config" => array(), "fields" => inject_form_variables($fields_graph_template_template_edit, isset($template) ? $template : array(), isset($template_graph) ? $template_graph : array()))); html_end_box(); html_start_box("<strong>Graph Template</strong>", "100%", $colors["header"], "3", "center", ""); $form_array = array(); while (list($field_name, $field_array) = each($struct_graph)) { $form_array += array($field_name => $struct_graph[$field_name]); $form_array[$field_name]["value"] = isset($template_graph) ? $template_graph[$field_name] : ""; $form_array[$field_name]["form_id"] = isset($template_graph) ? $template_graph["id"] : "0"; $form_array[$field_name]["description"] = ""; $form_array[$field_name]["sub_checkbox"] = array("name" => "t_" . $field_name, "friendly_name" => "Use Per-Graph Value (Ignore this Value)", "value" => isset($template_graph) ? $template_graph["t_" . $field_name] : ""); } draw_edit_form(array("config" => array(), "fields" => $form_array)); form_hidden_box("rrdtool_version", read_config_option("rrdtool_version"), ""); html_end_box(); form_save_button("graph_templates.php"); //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("Log is '" + document.getElementById('auto_scale_log').checked + "'"); document.getElementById('t_scale_log_units').disabled=true; document.getElementById('scale_log_units').disabled=true; if ((document.getElementById('rrdtool_version').value != 'rrd-1.0.x') && (document.getElementById('auto_scale_log').checked)) { document.getElementById('t_scale_log_units').disabled=false; document.getElementById('scale_log_units').disabled=false; } } function changeScaleLog() { //alert("Log changed to '" + document.getElementById('auto_scale_log').checked + "'"); document.getElementById('t_scale_log_units').disabled=true; document.getElementById('scale_log_units').disabled=true; if ((document.getElementById('rrdtool_version').value != 'rrd-1.0.x') && (document.getElementById('auto_scale_log').checked)) { document.getElementById('t_scale_log_units').disabled=false; document.getElementById('scale_log_units').disabled=false; } } </script> <?php }
function template_edit() { global $struct_data_source, $struct_data_source_item, $data_source_types, $fields_data_template_template_edit; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request('id')); input_validate_input_number(get_request_var_request('view_rrd')); /* ==================================================== */ if (!empty($_REQUEST['id'])) { $template_data = db_fetch_row_prepared('SELECT * FROM data_template_data WHERE data_template_id = ? AND local_data_id = 0', array($_REQUEST['id'])); $template = db_fetch_row_prepared('SELECT * FROM data_template WHERE id = ?', array($_REQUEST['id'])); $header_label = '[edit: ' . $template['name'] . ']'; } else { $header_label = '[new]'; } html_start_box('<strong>Data Templates</strong> ' . htmlspecialchars($header_label), '100%', '', '3', 'center', ''); draw_edit_form(array('config' => array(), 'fields' => inject_form_variables($fields_data_template_template_edit, isset($template) ? $template : array(), isset($template_data) ? $template_data : array(), $_REQUEST))); html_end_box(); html_start_box('<strong>Data Source</strong>', '100%', '', '3', 'center', ''); /* make sure 'data source path' doesn't show up for a template... we should NEVER template this field */ unset($struct_data_source['data_source_path']); $form_array = array(); while (list($field_name, $field_array) = each($struct_data_source)) { $form_array += array($field_name => $struct_data_source[$field_name]); if ($field_array['flags'] == 'ALWAYSTEMPLATE') { $form_array[$field_name]['description'] = '<em>This field is always templated.</em>'; } else { $form_array[$field_name]['description'] = ''; $form_array[$field_name]['sub_checkbox'] = array('name' => 't_' . $field_name, 'friendly_name' => 'Use Per-Data Source Value (Ignore this Value)', 'value' => isset($template_data['t_' . $field_name]) ? $template_data['t_' . $field_name] : ''); } $form_array[$field_name]['value'] = isset($template_data[$field_name]) ? $template_data[$field_name] : ''; $form_array[$field_name]['form_id'] = isset($template_data) ? $template_data['data_template_id'] : '0'; } draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => inject_form_variables($form_array, isset($template_data) ? $template_data : array()))); html_end_box(); /* fetch ALL rrd's for this data source */ if (!empty($_REQUEST['id'])) { $template_data_rrds = db_fetch_assoc_prepared('SELECT id, data_source_name FROM data_template_rrd WHERE data_template_id = ? AND local_data_id = 0 ORDER BY data_source_name', array($_REQUEST['id'])); } /* select the first "rrd" of this data source by default */ if (empty($_REQUEST['view_rrd'])) { $_REQUEST['view_rrd'] = isset($template_data_rrds[0]['id']) ? $template_data_rrds[0]['id'] : '0'; } /* get more information about the rrd we chose */ if (!empty($_REQUEST['view_rrd'])) { $template_rrd = db_fetch_row_prepared('SELECT * FROM data_template_rrd WHERE id = ?', array($_REQUEST['view_rrd'])); } $i = 0; if (isset($template_data_rrds)) { if (sizeof($template_data_rrds) > 1) { /* draw the data source tabs on the top of the page */ print "\t<div class='tabs' style='float:left;'><nav><ul>\n"; foreach ($template_data_rrds as $template_data_rrd) { $i++; print "\t<li>\n\t\t\t\t<a " . ($template_data_rrd['id'] == $_REQUEST['view_rrd'] ? "class='selected'" : "class=''") . " href='" . htmlspecialchars('data_templates.php?action=template_edit&id=' . $_REQUEST['id'] . '&view_rrd=' . $template_data_rrd['id']) . "'>{$i}: " . htmlspecialchars($template_data_rrd['data_source_name']) . "</a>\n\t\t\t\t<span><a class='deleteMarker' href='" . htmlspecialchars('data_templates.php?action=rrd_remove&id=' . $template_data_rrd['id'] . '&data_template_id=' . $_REQUEST['id']) . "'><img src='images/delete_icon.gif' border='0' alt='Delete'></a></span></li>\n"; } print "\n\t\t</ul></nav>\n\n\t\t</div>\n"; } elseif (sizeof($template_data_rrds) == 1) { $_REQUEST['view_rrd'] = $template_data_rrds[0]['id']; } } html_start_box('<strong>Data Source Item</strong> [' . (isset($template_rrd) ? htmlspecialchars($template_rrd['data_source_name']) : '') . ']', '100%', '', '3', 'center', !empty($_REQUEST['id']) ? htmlspecialchars('data_templates.php?action=rrd_add&id=' . $_REQUEST['id']) : '', '<strong>New</scrong>'); /* data input fields list */ if (empty($template_data['data_input_id']) || db_fetch_cell('SELECT type_id FROM data_input WHERE id=' . $template_data['data_input_id']) != '1' && db_fetch_cell('SELECT type_id FROM data_input WHERE id=' . $template_data['data_input_id']) != '5') { unset($struct_data_source_item['data_input_field_id']); } else { $struct_data_source_item['data_input_field_id']['sql'] = "SELECT id,CONCAT(data_name,' - ',name) AS name FROM data_input_fields WHERE data_input_id=" . $template_data['data_input_id'] . " AND input_output='out' AND update_rra='on' ORDER BY data_name,name"; } $form_array = array(); while (list($field_name, $field_array) = each($struct_data_source_item)) { $form_array += array($field_name => $struct_data_source_item[$field_name]); $form_array[$field_name]['description'] = ''; $form_array[$field_name]['value'] = isset($template_rrd) ? $template_rrd[$field_name] : ''; $form_array[$field_name]['sub_checkbox'] = array('name' => 't_' . $field_name, 'friendly_name' => 'Use Per-Data Source Value (Ignore this Value)', 'value' => isset($template_rrd) ? $template_rrd['t_' . $field_name] : ''); } draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => $form_array + array('data_template_rrd_id' => array('method' => 'hidden', 'value' => isset($template_rrd) ? $template_rrd['id'] : '0')))); html_end_box(); $i = 0; if (!empty($_REQUEST['id'])) { /* get each INPUT field for this data input source */ $fields = db_fetch_assoc('SELECT * FROM data_input_fields WHERE data_input_id=' . $template_data['data_input_id'] . " AND input_output='in' ORDER BY name"); html_start_box('<strong>Custom Data</strong> [data input: ' . htmlspecialchars(db_fetch_cell('SELECT name FROM data_input WHERE id=' . $template_data['data_input_id'])) . ']', '100%', '', '3', 'center', ''); /* loop through each field found */ if (sizeof($fields) > 0) { foreach ($fields as $field) { $data_input_data = db_fetch_row('SELECT t_value,value FROM data_input_data WHERE data_template_data_id=' . $template_data['id'] . ' AND data_input_field_id=' . $field['id']); if (sizeof($data_input_data) > 0) { $old_value = $data_input_data['value']; } else { $old_value = ''; } form_alternate_row(); ?> <td width="50%"> <strong><?php print $field['name']; ?> </strong><br> <?php form_checkbox('t_value_' . $field['data_name'], $data_input_data['t_value'], 'Use Per-Data Source Value (Ignore this Value)', '', '', $_REQUEST['id']); ?> </td> <td> <?php form_text_box('value_' . $field['data_name'], $old_value, '', ''); ?> <?php if (preg_match('/^' . VALID_HOST_FIELDS . '$/i', $field['type_code']) && $data_input_data['t_value'] == '') { print "<br><em>Value will be derived from the host if this field is left empty.</em>\n"; } ?> </td> </tr> <?php $i++; } } else { print '<tr><td><em>No Input Fields for the Selected Data Input Source</em></td></tr>'; } html_end_box(); } form_save_button('data_templates.php', 'return'); }