function mactrack_macw_edit() { global $fields_mactrack_macw_edit; /* ================= input validation ================= */ get_filter_request_var('mac_id'); /* ==================================================== */ display_output_messages(); if (!isempty_request_var('mac_id')) { $mac_record = db_fetch_row_prepared('SELECT * FROM mac_track_macwatch WHERE mac_id = ?', array(get_request_var('mac_id'))); $header_label = __('MacTrack MacWatch [edit: %s]', $mac_record['name']); } else { $header_label = __('MacTrack MacWatch [new]'); } form_start('mactrack_macwatch.php', 'mactrack_macwatch'); html_start_box($header_label, '100%', '', '3', 'center', ''); draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => inject_form_variables($fields_mactrack_macw_edit, isset($mac_record) ? $mac_record : array()))); html_end_box(); form_save_button('mactrack_macwatch.php', 'return'); }
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 template() { global $host_actions, $item_rows; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request('page')); input_validate_input_number(get_request_var_request('rows')); /* ==================================================== */ /* clean up has_hosts string */ if (isset($_REQUEST['has_hosts'])) { $_REQUEST['has_hosts'] = sanitize_search_string(get_request_var_request('has_hosts')); } /* clean up search string */ if (isset($_REQUEST['filter'])) { $_REQUEST['filter'] = sanitize_search_string(get_request_var_request('filter')); } /* clean up sort_column */ if (isset($_REQUEST['sort_column'])) { $_REQUEST['sort_column'] = sanitize_search_string(get_request_var_request('sort_column')); } /* clean up sort_direction string */ if (isset($_REQUEST['sort_direction'])) { $_REQUEST['sort_direction'] = sanitize_search_string(get_request_var_request('sort_direction')); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST['clear_x'])) { kill_session_var('sess_host_template_current_page'); kill_session_var('sess_host_template_hosts'); kill_session_var('sess_host_template_filter'); kill_session_var('sess_default_rows'); kill_session_var('sess_host_template_sort_column'); kill_session_var('sess_host_template_sort_direction'); unset($_REQUEST['page']); unset($_REQUEST['has_hosts']); unset($_REQUEST['filter']); unset($_REQUEST['rows']); unset($_REQUEST['sort_column']); unset($_REQUEST['sort_direction']); } else { $changed = 0; $changed += check_changed('has_hosts', 'sess_host_template_has_hosts'); $changed += check_changed('rows', 'sess_default_rows'); $changed += check_changed('filter', 'sess_host_template_filter'); if ($changed) { $_REQUEST['page'] = 1; } } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value('page', 'sess_host_template_current_page', '1'); load_current_session_value('has_hosts', 'sess_host_template_has_hosts', 'true'); load_current_session_value('filter', 'sess_host_template_filter', ''); load_current_session_value('sort_column', 'sess_host_template_sort_column', 'name'); load_current_session_value('sort_direction', 'sess_host_template_sort_direction', 'ASC'); load_current_session_value('rows', 'sess_default_rows', read_config_option('num_rows_table')); display_output_messages(); html_start_box('<strong>Device Templates</strong>', '100%', '', '3', 'center', 'host_templates.php?action=edit'); ?> <tr class='even noprint'> <td> <form id="form_host_template" action="host_templates.php"> <table cellpadding="2" cellspacing="0" border="0"> <tr> <td width="50"> Search </td> <td> <input id='filter' type="text" name="filter" size="25" value="<?php print htmlspecialchars(get_request_var_request('filter')); ?> "> </td> <td style='white-space:nowrap;'> Device Templates </td> <td> <select id='rows' name="rows" onChange="applyFilter()"> <?php if (sizeof($item_rows) > 0) { foreach ($item_rows as $key => $value) { print "<option value='" . $key . "'"; if (get_request_var_request('rows') == $key) { print ' selected'; } print '>' . htmlspecialchars($value) . "</option>\n"; } } ?> </select> </td> <td> <input type="checkbox" id='has_hosts' <?php print $_REQUEST['has_hosts'] == 'true' ? 'checked' : ''; ?> > </td> <td> <label for='has_hosts' style='white-space:nowrap;'>Has Devices</label> </td> <td> <input type="button" id='refresh' value="Go" title="Set/Refresh Filters"> </td> <td> <input type="button" id='clear' name="clear_x" value="Clear" title="Clear Filters"> </td> </tr> </table> <input type='hidden' id='page' name='page' value='<?php print $_REQUEST['page']; ?> '> </form> </td> <script type='text/javascript'> function applyFilter() { strURL = 'host_templates.php?filter='+$('#filter').val()+'&rows='+$('#rows').val()+'&page='+$('#page').val()+'&has_hosts='+$('#has_hosts').is(':checked')+'&header=false'; $.get(strURL, function(data) { $('#main').html(data); applySkin(); }); } function clearFilter() { strURL = 'host_templates.php?clear_x=1&header=false'; $.get(strURL, function(data) { $('#main').html(data); applySkin(); }); } $(function() { $('#refresh, #has_hosts').click(function() { applyFilter(); }); $('#clear').click(function() { clearFilter(); }); $('#form_host_template').submit(function(event) { event.preventDefault(); applyFilter(); }); }); </script> </tr> <?php html_end_box(); /* form the 'where' clause for our main sql query */ if (strlen($_REQUEST['filter'])) { $sql_where = "WHERE (host_template.name LIKE '%%" . get_request_var_request('filter') . "%%')"; } else { $sql_where = ''; } /* print checkbox form for validation */ print "<form name='chk' method='post' action='host_templates.php'>\n"; html_start_box('', '100%', '', '3', 'center', ''); if ($_REQUEST['has_hosts'] == 'true') { $sql_having = 'HAVING hosts>0'; } else { $sql_having = ''; } $total_rows = db_fetch_cell("SELECT COUNT(rows)\n\t\tFROM (\n\t\t\tSELECT\n\t\t\tCOUNT(host_template.id) AS rows, COUNT(DISTINCT host.id) AS hosts\n\t\t\tFROM host_template\n\t\t\tLEFT JOIN host ON host.host_template_id=host_template.id\n\t\t\t{$sql_where}\n\t\t\tGROUP BY host_template.id\n\t\t\t{$sql_having}\n\t\t) AS rs"); $template_list = db_fetch_assoc("SELECT\n\t\thost_template.id,host_template.name, COUNT(DISTINCT host.id) AS hosts\n\t\tFROM host_template\n\t\tLEFT JOIN host ON host.host_template_id=host_template.id\n\t\t{$sql_where}\n\t\tGROUP BY host_template.id\n\t\t{$sql_having}\n\t\tORDER BY " . get_request_var_request('sort_column') . ' ' . get_request_var_request('sort_direction') . ' LIMIT ' . get_request_var_request('rows') * (get_request_var_request('page') - 1) . ',' . get_request_var_request('rows')); $nav = html_nav_bar('host_templates.php?filter=' . get_request_var_request('filter'), MAX_DISPLAY_PAGES, get_request_var_request('page'), get_request_var_request('rows'), $total_rows, 5, 'Device Templates', 'page', 'main'); print $nav; $display_text = array('name' => array('display' => 'Device Template Name', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'The name of this Device Template.'), "nosort" => array('display' => 'Deletable', 'align' => 'right', 'sort' => '', 'tip' => 'Device Templates in use can not be Deleted. In use is defined as being referenced by a Device.'), 'hosts' => array('display' => 'Devices Using', 'align' => 'right', 'sort' => 'DESC', 'tip' => 'The number of Devices using this Device Template.'), 'host_template.id' => array('display' => 'ID', 'align' => 'right', 'sort' => 'ASC', 'tip' => 'The internal database ID for this Device Template. Useful when performing automation or debugging.')); html_header_sort_checkbox($display_text, get_request_var_request('sort_column'), get_request_var_request('sort_direction'), false); $i = 0; if (sizeof($template_list) > 0) { foreach ($template_list as $template) { if ($template['hosts'] > 0) { $disabled = true; } else { $disabled = false; } form_alternate_row('line' . $template['id'], true, $disabled); form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars('host_templates.php?action=edit&id=' . $template['id']) . "'>" . (strlen(get_request_var_request('filter')) ? preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", htmlspecialchars($template['name'])) : htmlspecialchars($template['name'])) . '</a>', $template['id']); form_selectable_cell($disabled ? 'No' : 'Yes', $template['id'], '', 'text-align:right'); form_selectable_cell(number_format($template['hosts']), $template['id'], '', 'text-align:right'); form_selectable_cell($template['id'], $template['id'], '', 'text-align:right'); form_checkbox_cell($template['name'], $template['id'], $disabled); form_end_row(); } /* put the nav bar on the bottom as well */ print $nav; } else { print "<tr class='tableRow'><td colspan='4'><em>No Device Templates</em></td></tr>\n"; } html_end_box(false); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($host_actions); print "</form>\n"; }
function 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; /* ================= 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 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 template_edit() { /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ display_output_messages(); $graph_template_tabs = array( "general" => __("General"), "items" => __("Items"), "graphs" => __("Graphs"), ); if (!empty($_REQUEST["id"])) { $graph_template = db_fetch_row("select * from graph_templates where id=" . $_REQUEST["id"]); $header_label = __("[edit: ") . $graph_template["name"] . "]"; }else{ $graph_template = array(); $header_label = __("[new]"); #$_REQUEST["id"] = 0; } /* set the default settings category */ if (!isset($_REQUEST["tab"])) { /* there is no selected tab; select the first one */ $current_tab = array_keys($graph_template_tabs); $current_tab = $current_tab[0]; }else{ $current_tab = $_REQUEST["tab"]; } /* draw the categories tabs on the top of the page */ print "<table width='100%' cellspacing='0' cellpadding='0' align='center'><tr>"; print "<td><div class='tabs'>"; if (sizeof($graph_template_tabs) > 0) { foreach (array_keys($graph_template_tabs) as $tab_short_name) { print "<div class='tabDefault'><a " . (($tab_short_name == $current_tab) ? "class='tabSelected'" : "class='tabDefault'") . " href='" . htmlspecialchars("graph_templates.php?action=template_edit" . (isset($_REQUEST['id']) ? "&id=" . $_REQUEST['id'] . "&template_id=" . $_REQUEST['id']: "") . "&filter=&device_id=-1&tab=$tab_short_name") . "'>$graph_template_tabs[$tab_short_name]</a></div>"; if (!isset($_REQUEST["id"])) break; } } print "</div></td></tr></table>"; if (!isset($_REQUEST["tab"])) { $_REQUEST["tab"] = "general"; } switch (get_request_var_request("tab")) { case "graphs": include_once(CACTI_BASE_PATH . "/lib/graph/graphs_form.php"); include_once(CACTI_BASE_PATH . "/lib/utility.php"); include_once(CACTI_BASE_PATH . "/lib/api_graph.php"); include_once(CACTI_BASE_PATH . "/lib/api_tree.php"); include_once(CACTI_BASE_PATH . "/lib/api_data_source.php"); include_once(CACTI_BASE_PATH . "/lib/template.php"); include_once(CACTI_BASE_PATH . "/lib/html_tree.php"); include_once(CACTI_BASE_PATH . "/lib/html_form_template.php"); include_once(CACTI_BASE_PATH . "/lib/rrd.php"); include_once(CACTI_BASE_PATH . "/lib/data_query.php"); graph(); break; case "items": /* graph item list goes here */ if (!empty($_REQUEST["id"])) { graph_template_display_items(); } break; default: graph_template_display_general($graph_template, $header_label); break; } }
function mactrack_maca_edit() { global $colors, $fields_mactrack_maca_edit; /* ================= input validation ================= */ input_validate_input_number(get_request_var("mac_id")); /* ==================================================== */ display_output_messages(); if (!empty($_GET["mac_id"])) { $mac_record = db_fetch_row("SELECT * FROM mac_track_macauth WHERE mac_id=" . $_GET["mac_id"]); $header_label = "[edit: " . $mac_record["mac_address"] . "]"; }else{ $header_label = "[new]"; } html_start_box("<strong>MacTrack MacAuth</strong> $header_label", "100%", $colors["header"], "3", "center", ""); draw_edit_form(array( "config" => array("form_name" => "chk"), "fields" => inject_form_variables($fields_mactrack_maca_edit, (isset($mac_record) ? $mac_record : array())) )); html_end_box(); if (isset($mac_record)) { mactrack_save_button("mactrack_macauth.php", "save", "", "mac_id"); }else{ mactrack_save_button("cancel", "save", "", "mac_id"); } }
function mactrack_view_graphs() { global $current_user, $colors, $config; /* ================= input validation ================= */ input_validate_input_number(get_request_var("rra_id")); input_validate_input_regex(get_request_var_request('graph_list'), "^([\,0-9]+)$"); input_validate_input_regex(get_request_var_request('graph_add'), "^([\,0-9]+)$"); input_validate_input_regex(get_request_var_request('graph_remove'), "^([\,0-9]+)$"); /* ==================================================== */ define("ROWS_PER_PAGE", read_graph_config_option("preview_graphs_per_page")); /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("graph_template_id")); input_validate_input_number(get_request_var_request("page")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var_request("filter")); } $sql_or = ""; $sql_where = ""; $sql_join = ""; /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { kill_session_var("sess_graph_view_current_page"); kill_session_var("sess_graph_view_filter"); kill_session_var("sess_graph_view_graph_template"); unset($_REQUEST["page"]); unset($_REQUEST["filter"]); unset($_REQUEST["graph_template_id"]); unset($_REQUEST["graph_list"]); unset($_REQUEST["graph_add"]); unset($_REQUEST["graph_remove"]); } /* reset the page counter to '1' if a search in initiated */ if (isset($_REQUEST["filter"])) { $_REQUEST["page"] = "1"; } load_current_session_value("graph_template_id", "sess_graph_view_graph_template", "0"); load_current_session_value("filter", "sess_graph_view_filter", ""); load_current_session_value("page", "sess_graph_view_current_page", "1"); /* graph permissions */ if (read_config_option("auth_method") != 0) { $sql_where = "WHERE " . get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]); $sql_join = "LEFT JOIN host ON (host.id=graph_local.host_id) LEFT JOIN graph_templates ON (graph_templates.id=graph_local.graph_template_id) LEFT JOIN user_auth_perms ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id AND user_auth_perms.type=1 AND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (host.id=user_auth_perms.item_id AND user_auth_perms.type=3 AND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_templates.id=user_auth_perms.item_id AND user_auth_perms.type=4 AND user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . "))"; }else{ $sql_where = ""; $sql_join = ""; } /* the user select a bunch of graphs of the 'list' view and wants them dsplayed here */ if (isset($_REQUEST["style"])) { if ($_REQUEST["style"] == "selective") { /* process selected graphs */ if (! empty($_REQUEST["graph_list"])) { foreach (explode(",",$_REQUEST["graph_list"]) as $item) { $graph_list[$item] = 1; } }else{ $graph_list = array(); } if (! empty($_REQUEST["graph_add"])) { foreach (explode(",",$_REQUEST["graph_add"]) as $item) { $graph_list[$item] = 1; } } /* remove items */ if (! empty($_REQUEST["graph_remove"])) { foreach (explode(",",$_REQUEST["graph_remove"]) as $item) { unset($graph_list[$item]); } } $i = 0; foreach ($graph_list as $item => $value) { $graph_array[$i] = $item; $i++; } if ((isset($graph_array)) && (sizeof($graph_array) > 0)) { /* build sql string including each graph the user checked */ $sql_or = "AND " . array_to_sql_or($graph_array, "graph_templates_graph.local_graph_id"); /* clear the filter vars so they don't affect our results */ $_REQUEST["filter"] = ""; $set_rra_id = empty($rra_id) ? read_graph_config_option("default_rra_id") : $_REQUEST["rra_id"]; } } } $sql_base = "FROM (graph_templates_graph,graph_local) $sql_join $sql_where " . (empty($sql_where) ? "WHERE" : "AND") . " graph_templates_graph.local_graph_id > 0 AND graph_templates_graph.local_graph_id=graph_local.id " . (strlen($_REQUEST["filter"]) ? "AND graph_templates_graph.title_cache like '%%" . $_REQUEST["filter"] . "%%'":"") . " " . (empty($_REQUEST["graph_template_id"]) ? "" : " and graph_local.graph_template_id=" . $_REQUEST["graph_template_id"]) . " $sql_or"; $total_rows = count(db_fetch_assoc("SELECT graph_templates_graph.local_graph_id $sql_base")); /* reset the page if you have changed some settings */ if (ROWS_PER_PAGE * ($_REQUEST["page"]-1) >= $total_rows) { $_REQUEST["page"] = "1"; } $graphs = db_fetch_assoc("SELECT graph_templates_graph.local_graph_id, graph_templates_graph.title_cache $sql_base GROUP BY graph_templates_graph.local_graph_id ORDER BY graph_templates_graph.title_cache LIMIT " . (ROWS_PER_PAGE*($_REQUEST["page"]-1)) . "," . ROWS_PER_PAGE); ?> <script type="text/javascript"> <!-- function applyGraphPreviewFilterChange(objForm) { strURL = '?report=graphs&graph_template_id=' + objForm.graph_template_id.value; strURL = strURL + '&filter=' + objForm.filter.value; document.location = strURL; } --> </script> <?php /* include graph view filter selector */ display_output_messages(); mactrack_tabs(); html_start_box("<strong>Network Device Graphs</strong>", "100%", $colors["header"], "1", "center", ""); mactrack_graph_view_filter(); /* include time span selector */ if (read_graph_config_option("timespan_sel") == "on") { mactrack_timespan_selector(); } html_end_box(); /* do some fancy navigation url construction so we don't have to try and rebuild the url string */ if (ereg("page=[0-9]+",basename($_SERVER["QUERY_STRING"]))) { $nav_url = str_replace("page=" . $_REQUEST["page"], "page=<PAGE>", basename($_SERVER["PHP_SELF"]) . "?" . $_SERVER["QUERY_STRING"]); }else{ $nav_url = basename($_SERVER["PHP_SELF"]) . "?" . $_SERVER["QUERY_STRING"] . "&page=<PAGE>"; } $nav_url = ereg_replace("((\?|&)filter=[a-zA-Z0-9]*)", "", $nav_url); html_start_box("", "100%", $colors["header"], "3", "center", ""); mactrack_nav_bar($_REQUEST["page"], ROWS_PER_PAGE, $total_rows, $nav_url); if (read_graph_config_option("thumbnail_section_preview") == "on") { html_graph_thumbnail_area($graphs, "","graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end()); }else{ html_graph_area($graphs, "", "graph_start=" . get_current_graph_start() . "&graph_end=" . get_current_graph_end()); } if ($total_rows) { mactrack_nav_bar($_REQUEST["page"], ROWS_PER_PAGE, $total_rows, $nav_url); } html_end_box(); }
function settings() { global $tabs_graphs, $settings_graphs, $current_user, $graph_views, $current_user; $current_user = db_fetch_row_prepared('SELECT * FROM user_auth WHERE id = ?', array($_SESSION['sess_user_id'])); /* 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; } /* Find out whether this user has right here */ if (!is_view_allowed('graph_settings')) { print "<strong><font class='txtErrorTextBox'>YOU DO NOT HAVE RIGHTS TO CHANGE GRAPH SETTINGS</font></strong>"; bottom_footer(); exit; } if (read_config_option('auth_method') != 0) { $settings_graphs['tree']['default_tree_id']['sql'] = get_graph_tree_array(true); } print "<form method='post' action='graph_settings.php'>\n"; 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"]').click(function(event) { event.preventDefault(); href='<?php print $_SERVER['HTTP_REFERER']; ?> '; href=href+(href.indexOf('?') > 0 ? '&':'?')+'header=false'; $.post('graph_settings.php?header=false', $('input, select, textarea').serialize()).done(function(data) { document.location='<?php print $_SERVER['HTTP_REFERER']; ?> '; }); }); $('#timespan_sel').change(function() { graphSettings(); }); }); --> </script> <?php 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['graph_settings_referer'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'graph_view.php'; form_hidden_box('save_component_graph_config', '1', ''); form_save_button('graph_settings.php', 'save'); }
function template() { global $colors, $host_actions; display_output_messages(); html_start_box("<strong>Host Templates</strong>", "98%", $colors["header"], "3", "center", "host_templates.php?action=edit"); html_header_checkbox(array("Template Title")); $host_templates = db_fetch_assoc("select * from host_template order by name"); $i = 0; if (sizeof($host_templates) > 0) { foreach ($host_templates as $host_template) { form_alternate_row_color($colors["alternate"],$colors["light"],$i); $i++; ?> <td> <a class="linkEditMain" href="host_templates.php?action=edit&id=<?php print $host_template["id"];?>"><?php print $host_template["name"];?></a> </td> <td style="<?php print get_checkbox_style();?>" width="1%" align="right"> <input type='checkbox' style='margin: 0px;' name='chk_<?php print $host_template["id"];?>' title="<?php print $host_template["name"];?>"> </td> </tr> <?php } }else{ print "<tr><td><em>No Host Templates</em></td></tr>\n"; } html_end_box(false); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($host_actions); print "</form>\n"; }
Logged in as <strong><?php print db_fetch_cell("select username from user_auth where id=" . $_SESSION["sess_user_id"]);?></strong> (<a href="logout.php">Logout</a>) <?php } ?> </td> </tr> </table> </td> </tr> <tr> <td bgcolor="#f5f5f5" colspan="1" height="8" width="135" style="background-image: url(images/shadow_gray.gif); background-repeat: repeat-x; border-right: #aaaaaa 1px solid;"> <img src="images/transparent_line.gif" width="135" height="2" border="0"><br> </td> <td colspan="2" height="8" style="background-image: url(images/shadow.gif); background-repeat: repeat-x;" bgcolor="#ffffff"> </td> </tr> <tr height="5"> <td valign="top" rowspan="2" width="135" style="padding: 5px; border-right: #aaaaaa 1px solid;" bgcolor='#f5f5f5'> <table bgcolor="#f5f5f5" width="100%" cellpadding="1" cellspacing="0" border="0"> <?php draw_menu();?> </table> <img src="images/transparent_line.gif" width="135" height="5" border="0"><br> <p align="center"><a href='about.php'><img src="images/cacti_logo.gif" border="0"></a></p> <img src="images/transparent_line.gif" width="135" height="5" border="0"><br> </td> <td></td> </tr> <tr> <td width="135" height="500"></td> <td width="100%" valign="top"><?php display_output_messages();?>
function template() { global $colors, $host_actions; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("page")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* clean up sort_column */ if (isset($_REQUEST["sort_column"])) { $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column")); } /* clean up sort_direction string */ if (isset($_REQUEST["sort_direction"])) { $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction")); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { kill_session_var("sess_host_template_current_page"); kill_session_var("sess_host_template_filter"); kill_session_var("sess_host_template_sort_column"); kill_session_var("sess_host_template_sort_direction"); unset($_REQUEST["page"]); unset($_REQUEST["filter"]); unset($_REQUEST["sort_column"]); unset($_REQUEST["sort_direction"]); } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("page", "sess_host_template_current_page", "1"); load_current_session_value("filter", "sess_host_template_filter", ""); load_current_session_value("sort_column", "sess_host_template_sort_column", "name"); load_current_session_value("sort_direction", "sess_host_template_sort_direction", "ASC"); display_output_messages(); html_start_box("<strong>Host Templates</strong>", "100%", $colors["header"], "3", "center", "host_templates.php?action=edit"); include "./include/html/inc_graph_template_filter_table.php"; html_end_box(); /* form the 'where' clause for our main sql query */ $sql_where = "WHERE (host_template.name LIKE '%%" . $_REQUEST["filter"] . "%%')"; html_start_box("", "100%", $colors["header"], "3", "center", ""); $total_rows = db_fetch_cell("SELECT\n\t\tCOUNT(host_template.id)\n\t\tFROM host_template\n\t\t{$sql_where}"); $template_list = db_fetch_assoc("SELECT\n\t\thost_template.id,host_template.name\n\t\tFROM host_template\n\t\t{$sql_where}\n\t\tORDER BY " . $_REQUEST['sort_column'] . " " . $_REQUEST['sort_direction'] . " LIMIT " . read_config_option("num_rows_device") * ($_REQUEST["page"] - 1) . "," . read_config_option("num_rows_device")); /* generate page list */ $url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, read_config_option("num_rows_device"), $total_rows, "host_templates.php?filter=" . $_REQUEST["filter"]); $nav = "<tr bgcolor='#" . $colors["header"] . "'>\n\t\t<td colspan='7'>\n\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\n\t\t\t\t<tr>\n\t\t\t\t\t<td align='left' class='textHeaderDark'>\n\t\t\t\t\t\t<strong><< "; if ($_REQUEST["page"] > 1) { $nav .= "<a class='linkOverDark' href='host_templates.php?filter=" . $_REQUEST["filter"] . "&page=" . ($_REQUEST["page"] - 1) . "'>"; } $nav .= "Previous"; if ($_REQUEST["page"] > 1) { $nav .= "</a>"; } $nav .= "</strong>\n\t\t\t\t\t</td>\n\n\t\t\t\t\t<td align='center' class='textHeaderDark'>\n\t\t\t\t\t\tShowing Rows " . (read_config_option("num_rows_device") * ($_REQUEST["page"] - 1) + 1) . " to " . ($total_rows < read_config_option("num_rows_device") || $total_rows < read_config_option("num_rows_device") * $_REQUEST["page"] ? $total_rows : read_config_option("num_rows_device") * $_REQUEST["page"]) . " of {$total_rows} [{$url_page_select}]\n\t\t\t\t\t</td>\n\n\t\t\t\t\t<td align='right' class='textHeaderDark'>\n\t\t\t\t\t\t<strong>"; if ($_REQUEST["page"] * read_config_option("num_rows_device") < $total_rows) { $nav .= "<a class='linkOverDark' href='host_templates.php?filter=" . $_REQUEST["filter"] . "&page=" . ($_REQUEST["page"] + 1) . "'>"; } $nav .= "Next"; if ($_REQUEST["page"] * read_config_option("num_rows_device") < $total_rows) { $nav .= "</a>"; } $nav .= " >></strong>\n\t\t\t\t\t</td>\n\n\t\t\t\t</tr>\n\t\t\t</table>\n\t\t</td>\n\t\t</tr>\n"; print $nav; $display_text = array("name" => array("Template Title", "ASC")); html_header_sort_checkbox($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"]); $i = 0; if (sizeof($template_list) > 0) { foreach ($template_list as $template) { form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $template["id"]); $i++; form_selectable_cell("<a class='linkEditMain' href='host_templates.php?action=edit&id=" . $template["id"] . "'>" . (strlen($_REQUEST["filter"]) ? eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $template["name"]) : $template["name"]) . "</a>", $template["id"]); form_checkbox_cell($template["name"], $template["id"]); form_end_row(); } /* put the nav bar on the bottom as well */ print $nav; } else { print "<tr><td><em>No Host Templates</em></td></tr>\n"; } html_end_box(false); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($host_actions); print "</form>\n"; }
function mactrack_device_edit() { global $colors, $config, $fields_mactrack_device_edit; /* ================= input validation ================= */ input_validate_input_number(get_request_var("device_id")); /* ==================================================== */ display_output_messages(); if (!empty($_GET["device_id"])) { $device = db_fetch_row("select * from mac_track_devices where device_id=" . $_GET["device_id"]); $header_label = "[edit: " . $device["device_name"] . "]"; }else{ $header_label = "[new]"; } if (!empty($device["device_id"])) { ?> <table width="100%" align="center"> <tr> <td class="textInfo" colspan="2"> <?php print $device["device_name"];?> (<?php print $device["hostname"];?>) </td> </tr> <tr> <td class="textHeader"> SNMP Information<br> <span style="font-size: 10px; font-weight: normal; font-family: monospace;"> <?php /* force php to return numeric oid's */ if (function_exists("snmp_set_oid_numeric_print")) { snmp_set_oid_numeric_print(TRUE); } $snmp_system = cacti_snmp_get($device["hostname"], $device["snmp_readstring"], ".1.3.6.1.2.1.1.1.0", $device["snmp_version"], $device["snmp_username"], $device["snmp_password"], $device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"], $device["snmp_context"], $device["snmp_port"], $device["snmp_timeout"], $device["snmp_retries"], SNMP_WEBUI); if ($snmp_system == "") { print "<span style='color: #ff0000; font-weight: bold;'>SNMP error</span>\n"; }else{ $snmp_uptime = cacti_snmp_get($device["hostname"], $device["snmp_readstring"], ".1.3.6.1.2.1.1.3.0", $device["snmp_version"], $device["snmp_username"], $device["snmp_password"], $device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"], $device["snmp_context"], $device["snmp_port"], $device["snmp_timeout"], $device["snmp_retries"], SNMP_WEBUI); $snmp_hostname = cacti_snmp_get($device["hostname"], $device["snmp_readstring"], ".1.3.6.1.2.1.1.5.0", $device["snmp_version"], $device["snmp_username"], $device["snmp_password"], $device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"], $device["snmp_context"], $device["snmp_port"], $device["snmp_timeout"], $device["snmp_retries"], SNMP_WEBUI); $snmp_objid = cacti_snmp_get($device["hostname"], $device["snmp_readstring"], ".1.3.6.1.2.1.1.2.0", $device["snmp_version"], $device["snmp_username"], $device["snmp_password"], $device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"], $device["snmp_context"], $device["snmp_port"], $device["snmp_timeout"], $device["snmp_retries"], SNMP_WEBUI); $snmp_objid = str_replace("enterprises", ".1.3.6.1.4.1", $snmp_objid); $snmp_objid = str_replace("OID: ", "", $snmp_objid); $snmp_objid = str_replace(".iso", ".1", $snmp_objid); print "<strong>System:</strong> $snmp_system<br>\n"; print "<strong>Uptime:</strong> $snmp_uptime<br>\n"; print "<strong>Hostname:</strong> $snmp_hostname<br>\n"; print "<strong>ObjectID:</strong> $snmp_objid<br>\n"; if (isset($_GET["scan"])) print $_GET["scan"]==1 ? "<span style='color:#088A08'><strong>Port Scanning:</strong> Complete</span><br>\n" : "<span style='color:#ff0000'><strong>Port Scanning:</strong> Fail</span><br>\n"; } ?> </span> </td> </tr> </table> <br> <?php } html_start_box("<strong>MacTrack Devices</strong> $header_label", "100%", $colors["header"], "3", "center", ""); /* preserve the devices site id between refreshes via a GET variable */ if (!empty($_GET["site_id"])) { $fields_host_edit["site_id"]["value"] = $_GET["site_id"]; } draw_edit_form(array( "config" => array("form_name" => "chk"), "fields" => inject_form_variables($fields_mactrack_device_edit, (isset($device) ? $device : array())) )); html_end_box(); if (isset($device)) { mactrack_save_button($config["url_path"] . "plugins/mactrack/mactrack_devices.php", "save", "", "device_id"); }else{ mactrack_save_button("cancel", "save", "", "device_id"); } print "<script type='text/javascript' src='" . URL_PATH . "plugins/mactrack/mactrack_snmp.js'></script>"; }
</td> <td align="right"> <?php if (read_config_option("auth_method") != 0) { ?> Logged in as <strong><?php print db_fetch_cell("select username from user_auth where id=" . $_SESSION["sess_user_id"]);?></strong> (<a href="logout.php">Logout</a>) <?php } ?> </td> </tr> </table> </td> </tr> <tr> <td bgcolor="#f5f5f5" colspan="1" height="8" width="135" style="background-image: url(images/shadow_gray.gif); background-repeat: repeat-x; border-right: #aaaaaa 1px solid;"> <img src="images/transparent_line.gif" width="135" height="2" border="0"><br> </td> <td colspan="2" height="8" style="background-image: url(images/shadow.gif); background-repeat: repeat-x;" bgcolor="#ffffff"> </td> </tr> <tr> <td valign="top" colspan="1" rowspan="2" width="135" style="padding: 5px; border-right: #aaaaaa 1px solid;" bgcolor='#f5f5f5'> <table bgcolor="#f5f5f5" width="100%" cellpadding="1" cellspacing="0" border="0"> <?php draw_menu();?> </table> <img src="images/transparent_line.gif" width="135" height="5" border="0"><br> <p align="center"><a href='about.php'><img src="images/cacti_logo.gif" border="0"></a></p> <img src="images/transparent_line.gif" width="135" height="5" border="0"><br> </td> <td width="100%" colspan="2" valign="top" style="padding: 5px; border-right: #aaaaaa 1px solid;"><?php display_output_messages();?>
function settings() { global $colors, $tabs_graphs, $settings_graphs, $current_user, $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; } /* Find out whether this user has right here */ if($current_user["graph_settings"] == "") { print "<strong><font size='+1' color='#FF0000'>" . __("YOU DO NOT HAVE RIGHTS TO CHANGE GRAPH SETTINGS") . "</font></strong>"; include_once(CACTI_BASE_PATH . "/include/bottom_footer.php"); exit; } if (read_config_option("auth_method") != 0) { if ($current_user["policy_graphs"] == "1") { $sql_where = "where user_auth_tree.user_id is null"; }elseif ($current_user["policy_graphs"] == "2") { $sql_where = "where user_auth_tree.user_id is not null"; } $settings_graphs["tree"]["default_tree_id"]["sql"] = get_graph_tree_array(true); } /* draw the categories tabs on the top of the page */ print "<form method='post' action='graph_settings.php'>\n"; # the tabs print "<table width='100%' cellspacing='0' cellpadding='0' align='center'><tr><td><div class='tabs'>\n"; if (sizeof($settings_graphs) > 0) { foreach (array_keys($settings_graphs) as $tab_short_name) { print "<div><a id='tab_" . clean_up_name($tabs_graphs[$tab_short_name]) . "' " . (($tab_short_name == "General") ? "class='tab tabSelected'" : "class='tab tabDefault'") . " onClick='selectTab(\"" . clean_up_name($tabs_graphs[$tab_short_name]) . "\")' href='#'>$tabs_graphs[$tab_short_name]</a></div>\n"; } } print "</div></td></tr></table>\n"; # the tab contents while (list($tab_short_name, $tab_fields) = each($settings_graphs)) { print "<table cellpadding='0' cellspacing='0' width='100%'><tr><td><div class='tab_settings' id='settings_" . clean_up_name($tabs_graphs[$tab_short_name]) . "'>\n"; html_start_box("<strong>" . __("Graph Settings") . " (" . $tabs_graphs[$tab_short_name] . ")</strong>", "100", $colors["header"], 0, "center", "", false, "Tab_Settings_" . clean_up_name($tabs_graphs[$tab_short_name])); $header_items = array(__("Field"), __("Value")); print "<tr><td>"; html_header($header_items, 2, true, "Header_Settings_" . clean_up_name($tabs_graphs[$tab_short_name]),'left wp100'); $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("select value from settings_graphs where name='$sub_field_name' and user_id=" . $_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("select value from settings_graphs where name='$field_name' and user_id=" . $_SESSION["sess_user_id"]); } } draw_edit_form( array( "config" => array("no_form_tag" => true), "fields" => $form_array ) ); print "</table></td></tr>"; /* end of html_header */ html_end_box(); print "</div></td></tr></table>\n"; } 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); } } form_hidden_box("referer", "graph_view.php",""); form_hidden_box("save_component_graph_config","1",""); form_save_button_alt("", "save", "save"); ?> <script type="text/javascript"> <!-- function selectTab(tab) { $('.tab_settings').hide(); $('.tab').removeClass("tabSelected"); $('.tab').addClass("tabDefault"); $('#settings_'+tab).show(); $('#tab_'+tab).removeClass("tabDefault"); $('#tab_'+tab).addClass("tabSelected"); } $().ready(function() { selectTab('General'); }); //--> </script> <?php include(CACTI_BASE_PATH . "/include/bottom_footer.php"); }
draw_menu(); ?> </table> <img src="<?php echo $config['url_path']; ?> images/transparent_line.gif" style="height:5px;width:135px;" border="0"><br> <p style="width:135px;" align="center"><a href='<?php echo $config['url_path']; ?> about.php'><img src="<?php echo $config['url_path']; ?> images/cacti_logo.gif" border="0"></a></p> <img src="<?php echo $config['url_path']; ?> images/transparent_line.gif" style="height:5px;width:135px;" border="0"><br> </td> <td width="100%" colspan="2" valign="top" style="padding: 5px; border-right: #aaaaaa 1px solid;"><?php display_output_messages(); ?> <div style='position:relative;' id='main'> <?php } else { ?> <tr> <td width="100%" valign="top"><?php display_output_messages(); }
function settings() { global $tabs_graphs, $settings_graphs, $current_user, $graph_views, $current_user, $graph_tree_views; /* 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; } /* Find out whether this user has right here */ if ($current_user["graph_settings"] == "") { print "<strong><font size='+1' color='#FF0000'>YOU DO NOT HAVE RIGHTS TO CHANGE GRAPH SETTINGS</font></strong>"; include_once "./include/bottom_footer.php"; exit; } if (read_config_option("auth_method") != 0) { if ($current_user["policy_graphs"] == "1") { $sql_where = "where user_auth_tree.user_id is null"; } elseif ($current_user["policy_graphs"] == "2") { $sql_where = "where user_auth_tree.user_id is not null"; } $settings_graphs["tree"]["default_tree_id"]["sql"] = get_graph_tree_array(true); } print "<form method='post' action='graph_settings.php'>\n"; html_start_box("<strong>Graph Settings</strong>", "100%", "", "3", "center", ""); while (list($tab_short_name, $tab_fields) = each($settings_graphs)) { ?> <tr> <td colspan='2' class='textSubHeaderDark' style='padding: 3px;'> <?php print $tabs_graphs[$tab_short_name]; ?> </td> </tr> <?php $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("select value from settings_graphs where name='{$sub_field_name}' and user_id=" . $_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("select value from settings_graphs where name='{$field_name}' and user_id=" . $_SESSION["sess_user_id"]); } } draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => $form_array)); } html_end_box(); ?> <script type="text/javascript"> <!-- function graphSettings() { var custom_fonts = document.getElementById('custom_fonts').checked; switch(custom_fonts) { case true: document.getElementById('row_title_size').style.display = ""; document.getElementById('row_title_font').style.display = ""; document.getElementById('row_legend_size').style.display = ""; document.getElementById('row_legend_font').style.display = ""; document.getElementById('row_axis_size').style.display = ""; document.getElementById('row_axis_font').style.display = ""; document.getElementById('row_unit_size').style.display = ""; document.getElementById('row_unit_font').style.display = ""; break; case false: document.getElementById('row_title_size').style.display = "none"; document.getElementById('row_title_font').style.display = "none"; document.getElementById('row_legend_size').style.display = "none"; document.getElementById('row_legend_font').style.display = "none"; document.getElementById('row_axis_size').style.display = "none"; document.getElementById('row_axis_font').style.display = "none"; document.getElementById('row_unit_size').style.display = "none"; document.getElementById('row_unit_font').style.display = "none"; 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(graphSettings); --> </script> <?php print "<br>"; 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["graph_settings_referer"] = isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : "graph_view.php"; form_hidden_box("save_component_graph_config", "1", ""); form_save_button("graph_settings.php", "save"); }
function form_mactrack_snmp_actions() { global $config, $mactrack_snmp_actions; /* ================= input validation ================= */ get_filter_request_var('drp_action'); /* ==================================================== */ /* if we are to save this form, instead of display it */ if (isset_request_var('selected_items')) { $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items')); if ($selected_items != false) { if (get_nfilter_request_var('drp_action') == '1') { /* delete */ db_execute('DELETE FROM mac_track_snmp WHERE ' . array_to_sql_or($selected_items, 'id')); db_execute('DELETE FROM mac_track_snmp_items WHERE ' . str_replace('id', 'snmp_id', array_to_sql_or($selected_items, 'id'))); } elseif (get_nfilter_request_var('drp_action') == '2') { /* duplicate */ for ($i = 0; $i < count($selected_items); $i++) { duplicate_mactrack($selected_items[$i], get_nfilter_request_var('name_format')); } } header('Location: mactrack_snmp.php?header=false'); exit; } } /* setup some variables */ $snmp_groups = ''; $i = 0; /* loop through each of the graphs selected on the previous page and get more info about them */ while (list($var, $val) = each($_POST)) { if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) { /* ================= input validation ================= */ input_validate_input_number($matches[1]); /* ==================================================== */ $snmp_groups .= '<li>' . db_fetch_cell_prepared('SELECT name FROM mac_track_snmp WHERE id = ?', array($matches[1])) . '</li>'; $mactrack_array[$i] = $matches[1]; $i++; } } general_header(); display_output_messages(); ?> <script type='text/javascript'> function goTo(strURL) { loadPageNoHeader(strURL); } </script> <?php form_start('mactrack_snmp.php', 'mactrack'); html_start_box($mactrack_snmp_actions[get_nfilter_request_var('drp_action')], '60%', '', '3', 'center', ''); if (!isset($mactrack_array)) { print "<tr><td class='even'><span class='textError'>" . __('You must select at least one SNMP Option.') . "</span></td></tr>\n"; $save_html = ""; } else { $save_html = "<input type='submit' value='" . __('Yes') . "' name='save'>"; if (get_nfilter_request_var("drp_action") == '1') { /* delete */ print "<tr>\n\t\t\t\t<td class='textArea'>\n\t\t\t\t\t<p>" . __('Are you sure you want to delete the following SNMP Options?') . "</p>\n\t\t\t\t\t<p><ul>{$snmp_groups}</ul></p>\n\t\t\t\t</td>\n\t\t\t</tr>"; } elseif (get_nfilter_request_var("drp_action") == '2') { /* duplicate */ print "<tr>\n\t\t\t\t<td class='textArea'>\n\t\t\t\t\t<p>" . __('When you click save, the following SNMP Options will be duplicated. You can optionally change the title format for the new SNMP Options.') . "</p>\n\t\t\t\t\t<p><ul>{$snmp_groups}</ul></p>\n\t\t\t\t\t<p>" . __('Name Format:') . "<br>"; form_text_box('name_format', '<name> (1)', '', '255', '30', 'text'); print "</p>\n\t\t\t\t</td>\n\t\t\t</tr>"; } } print "\t<tr>\n\t\t<td align='right' class='saveRow'>\n\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t<input type='hidden' name='selected_items' value='" . (isset($mactrack_array) ? serialize($mactrack_array) : '') . "'>\n\t\t\t<input type='hidden' name='drp_action' value='" . get_nfilter_request_var("drp_action") . "'>\n\t\t\t<input type='button' onClick='goTo(\"" . "mactrack_snmp.php" . "\")' value='" . ($save_html == '' ? 'Return' : 'No') . "' name='cancel'>\n\t\t\t{$save_html}\n\t\t</td>\n\t</tr>"; html_end_box(); bottom_footer(); }
function mactrack_site_edit() { global $colors, $fields_mactrack_site_edit; /* ================= input validation ================= */ input_validate_input_number(get_request_var("site_id")); /* ==================================================== */ display_output_messages(); if (!empty($_GET["site_id"])) { $site = db_fetch_row("select * from mac_track_sites where site_id=" . $_GET["site_id"]); $header_label = "[edit: " . $site["site_name"] . "]"; }else{ $header_label = "[new]"; } html_start_box("<strong>MacTrack Site</strong> $header_label", "100%", $colors["header"], "3", "center", ""); draw_edit_form(array( "config" => array("form_name" => "chk"), "fields" => inject_form_variables($fields_mactrack_site_edit, (isset($site) ? $site : array())) )); html_end_box(); if (isset($site)) { mactrack_save_button("mactrack_sites.php", "save", "", "site_id"); }else{ mactrack_save_button("cancel", "save", "", "site_id"); } }
function template() { global $colors, $host_actions; /* clean up sort_column */ if (isset($_REQUEST["sort_column"])) { $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column")); } /* clean up search string */ if (isset($_REQUEST["sort_direction"])) { $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction")); } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("sort_column", "sess_host_template_column", "name"); load_current_session_value("sort_direction", "sess_host_template_sort_direction", "ASC"); display_output_messages(); html_start_box("<strong>Host Templates</strong>", "98%", $colors["header"], "3", "center", "host_templates.php?action=edit"); $display_text = array( "name" => array("Template Title", "ASC")); html_header_sort_checkbox($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"]); $host_templates = db_fetch_assoc("SELECT * FROM host_template ORDER BY " . $_REQUEST['sort_column'] . " " . $_REQUEST['sort_direction']); $i = 0; if (sizeof($host_templates) > 0) { foreach ($host_templates as $host_template) { form_alternate_row_color($colors["alternate"],$colors["light"],$i); $i++; ?> <td> <a class="linkEditMain" href="host_templates.php?action=edit&id=<?php print $host_template["id"];?>"><?php print $host_template["name"];?></a> </td> <td style="<?php print get_checkbox_style();?>" width="1%" align="right"> <input type='checkbox' style='margin: 0px;' name='chk_<?php print $host_template["id"];?>' title="<?php print $host_template["name"];?>"> </td> </tr> <?php } }else{ print "<tr><td><em>No Host Templates</em></td></tr>\n"; } html_end_box(false); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($host_actions); print "</form>\n"; }
function bottom_footer() { global $config; if (!isset($_REQUEST['header']) || $_REQUEST['header'] == false) { include $config['base_path'] . '/include/bottom_footer.php'; } else { ?> <script type='text/javascript'> var message = "<?php print display_output_messages(); ?> "; if (message != '') { $('#message_container').html(message).show().delay(2000).slideUp('fast'); window.scrollTo(0,0); } </script> <?php /* we use this session var to store field values for when a save fails, this way we can restore the field's previous values. we reset it here, because they only need to be stored for a single page */ kill_session_var("sess_field_values"); /* make sure the debug log doesn't get too big */ debug_log_clear(); /* close the database connection */ db_close(); } }
function poller() { global $colors, $poller_actions, $item_rows; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("page")); input_validate_input_number(get_request_var_request("rows")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* clean up sort_column */ if (isset($_REQUEST["sort_column"])) { $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column")); } /* clean up sort_direction string */ if (isset($_REQUEST["sort_direction"])) { $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction")); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { kill_session_var("sess_poller_current_page"); kill_session_var("sess_poller_rows"); kill_session_var("sess_poller_filter"); kill_session_var("sess_poller_sort_column"); kill_session_var("sess_poller_sort_direction"); unset($_REQUEST["page"]); unset($_REQUEST["rows"]); unset($_REQUEST["filter"]); unset($_REQUEST["sort_column"]); unset($_REQUEST["sort_direction"]); } ?> <script type="text/javascript"> <!-- function applyFilterChange(objForm) { strURL = '?rows=' + objForm.rows.value; strURL = strURL + '&filter=' + objForm.filter.value; document.location = strURL; } --> </script> <?php /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("page", "sess_poller_current_page", "1"); load_current_session_value("rows", "sess_poller_rows", "-1"); load_current_session_value("filter", "sess_poller_filter", ""); load_current_session_value("sort_column", "sess_poller_sort_column", "description"); load_current_session_value("sort_direction", "sess_poller_sort_direction", "ASC"); display_output_messages(); html_start_box("<strong>" . __("Pollers") . "</strong>", "100", $colors["header"], "3", "center", "pollers.php?action=edit", true); ?> <tr class='rowAlternate2'> <td> <form name="form_pollers" action="pollers.php"> <table cellpadding="0" cellspacing="3"> <tr> <td class="nw50"> <?php print __("Search:");?> </td> <td class="w1"> <input type="text" name="filter" size="40" value="<?php print $_REQUEST["filter"];?>"> </td> <td class="nw50"> <?php print __("Rows:");?> </td> <td class="w1"> <select name="rows" onChange="applyFilterChange(document.form_pollers)"> <option value="-1"<?php if (get_request_var_request("rows") == "-1") {?> selected<?php }?>>Default</option> <?php if (sizeof($item_rows) > 0) { foreach ($item_rows as $key => $value) { print "<option value='" . $key . "'"; if (get_request_var_request("rows") == $key) { print " selected"; } print ">" . $value . "</option>\n"; } } ?> </select> </td> <td class="nw120"> <input type="submit" Value="<?php print __("Go");?>" name="go" align="middle"> <input type="submit" Value="<?php print __("Clear");?>" name="clear_x" align="middle"> </td> </tr> </table> <div><input type='hidden' name='page' value='1'></div> </form> </td> </tr> <?php html_end_box(false); /* form the 'where' clause for our main sql query */ if ($_REQUEST["filter"] != "") { $sql_where = "WHERE (p.description LIKE '%%" . $_REQUEST["filter"] . "%%')"; }else{ $sql_where = ""; } html_start_box("", "100", $colors["header"], "0", "center", ""); $total_rows = db_fetch_cell("SELECT COUNT(*) FROM poller $sql_where"); if (get_request_var_request("rows") == "-1") { $rows = read_config_option("num_rows_device"); }else{ $rows = get_request_var_request("rows"); } $poller_list = db_fetch_assoc("SELECT p.*, sum(CASE WHEN h.poller_id IS NOT NULL THEN 1 ELSE NULL END) AS total_devices FROM poller AS p LEFT JOIN device AS h ON h.poller_id=p.id $sql_where GROUP BY p.id ORDER BY " . get_request_var_request('sort_column') . " " . get_request_var_request('sort_direction') . " LIMIT " . ($rows*(get_request_var_request("page")-1)) . "," . $rows); /* generate page list navigation */ $nav = html_create_nav($_REQUEST["page"], MAX_DISPLAY_PAGES, $rows, $total_rows, 7, "pollers.php"); print $nav; html_end_box(false); $display_text = array( "description" => array(__("Description"), "ASC"), "id" => array(__("ID"), "ASC"), "total_devices" => array(__("Devices"), "DESC"), "nosort2" => array(__("Poller Items"), "DESC"), "hostname" => array(__("Hostname"), "ASC"), "nosort1" => array(__("Status"), ""), "last_update" => array(__("Last Updated"), "ASC")); html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction")); if (sizeof($poller_list) > 0) { foreach ($poller_list as $poller) { form_alternate_row_color('line' . $poller["id"], true); form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars("pollers.php?action=edit&id=" . $poller["id"]) . "'>" . (strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span class=\"filter\">\\1</span>", $poller["description"]) : $poller["description"]) . "</a>", $poller["id"]); form_selectable_cell($poller["id"], $poller["id"]); form_selectable_cell($poller["total_devices"], $poller["id"]); form_selectable_cell(db_fetch_cell("SELECT count(*) FROM poller_item WHERE poller_id=" . $poller["id"]), $poller["id"]); form_selectable_cell($poller["hostname"], $poller["id"]); form_selectable_cell(get_colored_poller_status(($poller["disabled"] == CHECKED ? true : false), $poller["last_update"]), $poller["id"]); form_selectable_cell($poller["last_update"], $poller["id"]); form_checkbox_cell($poller["description"], $poller["id"]); form_end_row(); } form_end_table(); /* put the nav bar on the bottom as well */ print $nav; }else{ print "<tr><td><em>" . __("No Pollers Defined") . "</em></td></tr>\n"; } print "</table>\n"; # end table of html_header_sort_checkbox /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($poller_actions); print "</form>\n"; # end form of html_header_sort_checkbox }
function template() { global $colors, $host_actions; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("page")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* clean up sort_column */ if (isset($_REQUEST["sort_column"])) { $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column")); } /* clean up sort_direction string */ if (isset($_REQUEST["sort_direction"])) { $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction")); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { kill_session_var("sess_host_template_current_page"); kill_session_var("sess_host_template_filter"); kill_session_var("sess_host_template_sort_column"); kill_session_var("sess_host_template_sort_direction"); unset($_REQUEST["page"]); unset($_REQUEST["filter"]); unset($_REQUEST["sort_column"]); unset($_REQUEST["sort_direction"]); } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("page", "sess_host_template_current_page", "1"); load_current_session_value("filter", "sess_host_template_filter", ""); load_current_session_value("sort_column", "sess_host_template_sort_column", "name"); load_current_session_value("sort_direction", "sess_host_template_sort_direction", "ASC"); display_output_messages(); html_start_box("<strong>Host Templates</strong>", "100%", $colors["header"], "3", "center", "host_templates.php?action=edit"); ?> <tr bgcolor="<?php print $colors["panel"];?>"> <form name="form_graph_template"> <td> <table width="100%" cellpadding="0" cellspacing="0"> <tr> <td nowrap style='white-space: nowrap;' width="50"> Search: </td> <td width="1"> <input type="text" name="filter" size="40" value="<?php print clean_html_output(get_request_var_request("filter"));?>"> </td> <td nowrap style='white-space: nowrap;'> <input type="image" src="images/button_go.gif" alt="Go" border="0" align="absmiddle"> <input type="image" src="images/button_clear.gif" name="clear" alt="Clear" border="0" align="absmiddle"> </td> </tr> </table> </td> <input type='hidden' name='page' value='1'> </form> </tr> <?php html_end_box(); /* form the 'where' clause for our main sql query */ $sql_where = "WHERE (host_template.name LIKE '%%" . get_request_var_request("filter") . "%%')"; html_start_box("", "100%", $colors["header"], "3", "center", ""); $total_rows = db_fetch_cell("SELECT COUNT(host_template.id) FROM host_template $sql_where"); $template_list = db_fetch_assoc("SELECT host_template.id,host_template.name FROM host_template $sql_where ORDER BY " . get_request_var_request("sort_column") . " " . get_request_var_request("sort_direction") . " LIMIT " . (read_config_option("num_rows_device")*(get_request_var_request("page")-1)) . "," . read_config_option("num_rows_device")); /* generate page list */ $url_page_select = get_page_list(get_request_var_request("page"), MAX_DISPLAY_PAGES, read_config_option("num_rows_device"), $total_rows, "host_templates.php?filter=" . get_request_var_request("filter")); $nav = "<tr bgcolor='#" . $colors["header"] . "'> <td colspan='7'> <table width='100%' cellspacing='0' cellpadding='0' border='0'> <tr> <td align='left' class='textHeaderDark'> <strong><< "; if (get_request_var_request("page") > 1) { $nav .= "<a class='linkOverDark' href='host_templates.php?filter=" . get_request_var_request("filter") . "&page=" . (get_request_var_request("page")-1) . "'>"; } $nav .= "Previous"; if (get_request_var_request("page") > 1) { $nav .= "</a>"; } $nav .= "</strong> </td>\n <td align='center' class='textHeaderDark'> Showing Rows " . ((read_config_option("num_rows_device")*(get_request_var_request("page")-1))+1) . " to " . ((($total_rows < read_config_option("num_rows_device")) || ($total_rows < (read_config_option("num_rows_device")*get_request_var_request("page")))) ? $total_rows : (read_config_option("num_rows_device")*get_request_var_request("page"))) . " of $total_rows [$url_page_select] </td>\n <td align='right' class='textHeaderDark'> <strong>"; if ((get_request_var_request("page") * read_config_option("num_rows_device")) < $total_rows) { $nav .= "<a class='linkOverDark' href='host_templates.php?filter=" . get_request_var_request("filter") . "&page=" . (get_request_var_request("page")+1) . "'>"; } $nav .= "Next"; if ((get_request_var_request("page") * read_config_option("num_rows_device")) < $total_rows) { $nav .= "</a>"; } $nav .= " >></strong> </td>\n </tr> </table> </td> </tr>\n"; print $nav; $display_text = array( "name" => array("Template Title", "ASC")); html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction")); $i = 0; if (sizeof($template_list) > 0) { foreach ($template_list as $template) { form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $template["id"]);$i++; form_selectable_cell("<a class='linkEditMain' href='host_templates.php?action=edit&id=" . $template["id"] . "'>" . (strlen(get_request_var_request("filter")) ? eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $template["name"]) : $template["name"]) . "</a>", $template["id"]); form_checkbox_cell($template["name"], $template["id"]); form_end_row(); } /* put the nav bar on the bottom as well */ print $nav; }else{ print "<tr><td><em>No Host Templates</em></td></tr>\n"; } html_end_box(false); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($host_actions); print "</form>\n"; }
function syslog_filter($sql_where, $tab) { global $colors, $config, $graph_timespans, $graph_timeshifts, $reset_multi, $page_refresh_interval; include dirname(__FILE__) . "/config.php"; if (isset($_SESSION["sess_current_date1"])) { $filter_text = "</strong> [ Start: '" . $_SESSION["sess_current_date1"] . "' to End: '" . $_SESSION["sess_current_date2"] . "' ]"; } else { $filter_text = "</strong>"; } ?> <script type="text/javascript"> <!-- // Initialize the calendar calendar=null; // This function displays the calendar associated to the input field 'id' function showCalendar(id) { var el = document.getElementById(id); if (calendar != null) { // we already have some calendar created calendar.hide(); // so we hide it first. } else { // first-time call, create the calendar. var cal = new Calendar(true, null, selected, closeHandler); cal.weekNumbers = false; // Do not display the week number cal.showsTime = true; // Display the time cal.time24 = true; // Hours have a 24 hours format cal.showsOtherMonths = false; // Just the current month is displayed calendar = cal; // remember it in the global var cal.setRange(1900, 2070); // min/max year allowed. cal.create(); } calendar.setDateFormat('%Y-%m-%d %H:%M'); // set the specified date format calendar.parseDate(el.value); // try to parse the text in field calendar.sel = el; // inform it what input field we use // Display the calendar below the input field calendar.showAtElement(el, "Br"); // show the calendar return false; } // This function update the date in the input field when selected function selected(cal, date) { cal.sel.value = date; // just update the date in the input field. } // This function gets called when the end-user clicks on the 'Close' button. // It just hides the calendar without destroying it. function closeHandler(cal) { cal.hide(); // hide the calendar calendar = null; } function applyTimespanFilterChange(objForm) { strURL = '?predefined_timespan=' + objForm.predefined_timespan.value; strURL = strURL + '&predefined_timeshift=' + objForm.predefined_timeshift.value; document.location = strURL; } --> </script> <form style='margin:0px;padding:0px;' id="syslog_form" name="syslog_form" method="post" action="syslog.php"> <table width="100%" cellspacing="0" cellpadding="0" border="0"> <tr> <td colspan="2" style="background-color:#EFEFEF;"> <table width='100%' cellpadding="0" cellspacing="0" border="0"> <tr> <td width='100%'> <?php html_start_box("<strong>Syslog Message Filter{$filter_text}", "100%", $colors["header"], "1", "center", ""); ?> <tr bgcolor="<?php print $colors["panel"]; ?> " class="noprint"> <td class="noprint"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td nowrap style='white-space: nowrap;' width='60'> <strong>Presets:</strong> </td> <td nowrap style='white-space: nowrap;' width='130'> <select name='predefined_timespan' onChange="applyTimespanFilterChange(document.syslog_form)"> <?php if ($_SESSION["custom"]) { $graph_timespans[GT_CUSTOM] = "Custom"; $_REQUEST["predefined_timespan"] = GT_CUSTOM; $start_val = 0; $end_val = sizeof($graph_timespans); } else { if (isset($graph_timespans[GT_CUSTOM])) { asort($graph_timespans); array_shift($graph_timespans); } $start_val = 1; $end_val = sizeof($graph_timespans) + 1; } if (sizeof($graph_timespans) > 0) { for ($value = $start_val; $value < $end_val; $value++) { print "<option value='{$value}'"; if ($_REQUEST["predefined_timespan"] == $value) { print " selected"; } print ">" . title_trim($graph_timespans[$value], 40) . "</option>\n"; } } ?> </select> </td> <td nowrap style='white-space: nowrap;' width='30'> <strong>From:</strong> </td> <td width='150' nowrap style='white-space: nowrap;'> <input type='text' name='date1' id='date1' title='Graph Begin Timestamp' size='14' value='<?php print isset($_SESSION["sess_current_date1"]) ? $_SESSION["sess_current_date1"] : ""; ?> '> <input style='padding-bottom: 4px;' type='image' src='<?php print $config["url_path"]; ?> images/calendar.gif' alt='Start date selector' title='Start date selector' border='0' align='absmiddle' onclick="return showCalendar('date1');"> </td> <td nowrap style='white-space: nowrap;' width='20'> <strong>To:</strong> </td> <td width='150' nowrap style='white-space: nowrap;'> <input type='text' name='date2' id='date2' title='Graph End Timestamp' size='14' value='<?php print isset($_SESSION["sess_current_date2"]) ? $_SESSION["sess_current_date2"] : ""; ?> '> <input style='padding-bottom: 4px;' type='image' src='<?php print $config["url_path"]; ?> images/calendar.gif' alt='End date selector' title='End date selector' border='0' align='absmiddle' onclick="return showCalendar('date2');"> </td> <td width='125' nowrap style='white-space: nowrap;'> <input style='padding-bottom: 4px;' type='image' name='move_left' src='<?php print $config["url_path"]; ?> images/move_left.gif' alt='Left' border='0' align='absmiddle' title='Shift Left'> <select name='predefined_timeshift' title='Define Shifting Interval' onChange="applyTimespanFilterChange(document.syslog_form)"> <?php $start_val = 1; $end_val = sizeof($graph_timeshifts) + 1; if (sizeof($graph_timeshifts) > 0) { for ($shift_value = $start_val; $shift_value < $end_val; $shift_value++) { print "<option value='{$shift_value}'"; if ($_REQUEST["predefined_timeshift"] == $shift_value) { print " selected"; } print ">" . title_trim($graph_timeshifts[$shift_value], 40) . "</option>\n"; } } ?> </select> <input style='padding-bottom: 4px;' type='image' name='move_right' src='<?php print $config["url_path"]; ?> images/move_right.gif' alt='Right' border='0' align='absmiddle' title='Shift Right'> </td> <td> <input type="submit" value='Go' name='go' title="Go"> </td> <td> <input type='submit' value='Clear' name='button_clear_x' title='Return to the default time span'> </td> <td> <input type='submit' value='Export' name='export' title='Export Records to CSV'> </td> <td> <input type='hidden' name='action' value='actions'> <input type='hidden' name='syslog_pdt_change' value='false'> </td> </tr> </table> </td><?php if (api_plugin_user_realm_auth('syslog_alerts.php')) { ?> <td align='right' style='white-space:nowrap;'> <input type='button' value='Alerts' title='View Syslog Alert Rules' onClick='javascript:document.location="<?php print $config['url_path'] . "plugins/syslog/syslog_alerts.php"; ?> "'> <input type='button' value='Removals' title='View Syslog Removal Rules' onClick='javascript:document.location="<?php print $config['url_path'] . "plugins/syslog/syslog_removal.php"; ?> "'> <input type='button' value='Reports' title='View Syslog Reports' onClick='javascript:document.location="<?php print $config['url_path'] . "plugins/syslog/syslog_reports.php"; ?> "'> </td><?php } ?> </tr> </table> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr bgcolor="<?php print $colors["panel"]; ?> " class="noprint"> <td> <table cellpadding="0" cellspacing="0"> <tr> <td nowrap style='white-space: nowrap;' width='60'> <strong>Search:</strong> </td> <td style='padding-right:2px;'> <input type="text" name="filter" size="30" value="<?php print $_REQUEST["filter"]; ?> "> </td> <?php api_plugin_hook('syslog_extend_filter'); ?> <td style='padding-right:2px;'> <select name="efacility" onChange="javascript:document.getElementById('syslog_form').submit();" title="Facilities"> <option value="0"<?php if ($_REQUEST["efacility"] == "0") { ?> selected<?php } ?> >All Facilities</option> <?php if (!isset($hostfilter)) { $hostfilter = ""; } $efacilities = syslog_db_fetch_assoc("SELECT DISTINCT f.facility_id, f.facility\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM `" . $syslogdb_default . "`.`syslog_host_facilities` AS fh\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tINNER JOIN `" . $syslogdb_default . "`.`syslog_facilities` AS f\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tON f.facility_id=fh.facility_id " . (strlen($hostfilter) ? "WHERE " : "") . $hostfilter . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tORDER BY facility"); if (sizeof($efacilities)) { foreach ($efacilities as $efacility) { print "<option value=" . $efacility["facility_id"]; if ($_REQUEST["efacility"] == $efacility["facility_id"]) { print " selected"; } print ">" . ucfirst($efacility["facility"]) . "</option>\n"; } } ?> </select> </td> <td style='padding-right:2px;'> <select name="elevel" onChange="javascript:document.getElementById('syslog_form').submit();" title="Priority Levels"> <option value="0"<?php if ($_REQUEST["elevel"] == "0") { ?> selected<?php } ?> >All Priorities</option> <option value="1"<?php if ($_REQUEST["elevel"] == "1") { ?> selected<?php } ?> >Emergency</option> <option value="2"<?php if ($_REQUEST["elevel"] == "2") { ?> selected<?php } ?> >Critical++</option> <option value="2o"<?php if ($_REQUEST["elevel"] == "2o") { ?> selected<?php } ?> >Critical</option> <option value="3"<?php if ($_REQUEST["elevel"] == "3") { ?> selected<?php } ?> >Alert++</option> <option value="3o"<?php if ($_REQUEST["elevel"] == "3o") { ?> selected<?php } ?> >Alert</option> <option value="4"<?php if ($_REQUEST["elevel"] == "4") { ?> selected<?php } ?> >Error++</option> <option value="4o"<?php if ($_REQUEST["elevel"] == "4o") { ?> selected<?php } ?> >Error</option> <option value="5"<?php if ($_REQUEST["elevel"] == "5") { ?> selected<?php } ?> >Warning++</option> <option value="5o"<?php if ($_REQUEST["elevel"] == "5o") { ?> selected<?php } ?> >Warning</option> <option value="6"<?php if ($_REQUEST["elevel"] == "6") { ?> selected<?php } ?> >Notice++</option> <option value="6o"<?php if ($_REQUEST["elevel"] == "6o") { ?> selected<?php } ?> >Notice</option> <option value="7"<?php if ($_REQUEST["elevel"] == "7") { ?> selected<?php } ?> >Info++</option> <option value="7o"<?php if ($_REQUEST["elevel"] == "7o") { ?> selected<?php } ?> >Info</option> <option value="8"<?php if ($_REQUEST["elevel"] == "8") { ?> selected<?php } ?> >Debug</option> </select> </td> <?php if ($_REQUEST["tab"] == "syslog") { ?> <td style='padding-right:2px;'> <select name="removal" onChange="javascript:document.getElementById('syslog_form').submit();" title="Removal Handling"> <option value="1"<?php if ($_REQUEST["removal"] == "1") { ?> selected<?php } ?> >All Records</option> <option value="-1"<?php if ($_REQUEST["removal"] == "-1") { ?> selected<?php } ?> >Main Records</option> <option value="2"<?php if ($_REQUEST["removal"] == "2") { ?> selected<?php } ?> >Removed Records</option> </select> </td> <?php } ?> <td style='padding-right:2px;'> <select name="rows" onChange="javascript:document.getElementById('syslog_form').submit();" title="Display Rows"> <option value="10"<?php if ($_REQUEST["rows"] == "10") { ?> selected<?php } ?> >10</option> <option value="15"<?php if ($_REQUEST["rows"] == "15") { ?> selected<?php } ?> >15</option> <option value="20"<?php if ($_REQUEST["rows"] == "20") { ?> selected<?php } ?> >20</option> <option value="25"<?php if ($_REQUEST["rows"] == "25") { ?> selected<?php } ?> >25</option> <option value="30"<?php if ($_REQUEST["rows"] == "30") { ?> selected<?php } ?> >30</option> <option value="35"<?php if ($_REQUEST["rows"] == "35") { ?> selected<?php } ?> >35</option> <option value="40"<?php if ($_REQUEST["rows"] == "40") { ?> selected<?php } ?> >40</option> <option value="45"<?php if ($_REQUEST["rows"] == "45") { ?> selected<?php } ?> >45</option> <option value="50"<?php if ($_REQUEST["rows"] == "50") { ?> selected<?php } ?> >50</option> <option value="100"<?php if ($_REQUEST["rows"] == "100") { ?> selected<?php } ?> >100</option> <option value="200"<?php if ($_REQUEST["rows"] == "200") { ?> selected<?php } ?> >200</option> <option value="500"<?php if ($_REQUEST["rows"] == "500") { ?> selected<?php } ?> >500</option> </select> </td> <td style='padding-right:2px;'> <select name="trimval" onChange="javascript:document.getElementById('syslog_form').submit();" title="Message Trim"> <option value="1024"<?php if ($_REQUEST["trimval"] == "1024") { ?> selected<?php } ?> >All Text</option> <option value="30"<?php if ($_REQUEST["trimval"] == "30") { ?> selected<?php } ?> >30 Chars</option> <option value="50"<?php if ($_REQUEST["trimval"] == "50") { ?> selected<?php } ?> >50 Chars</option> <option value="75"<?php if ($_REQUEST["trimval"] == "75") { ?> selected<?php } ?> >75 Chars</option> <option value="100"<?php if ($_REQUEST["trimval"] == "100") { ?> selected<?php } ?> >100 Chars</option> <option value="150"<?php if ($_REQUEST["trimval"] == "150") { ?> selected<?php } ?> >150 Chars</option> <option value="300"<?php if ($_REQUEST["trimval"] == "300") { ?> selected<?php } ?> >300 Chars</option> </select> </td> <td width="1"> <select name="refresh" onChange="javascript:document.getElementById('syslog_form').submit();"> <?php foreach ($page_refresh_interval as $seconds => $display_text) { print "<option value='" . $seconds . "'"; if ($_REQUEST["refresh"] == $seconds) { print " selected"; } print ">" . $display_text . "</option>\n"; } ?> </select> </td> </tr> </table> </td> </tr> <?php html_end_box(false); ?> </tr> </table> </td> </tr> <tr> <td valign="top" style="border-right: #aaaaaa 1px solid;" bgcolor='#efefef'> <table align="center" cellpadding="1" cellspacing="0" border="0"> <tr> <td> <?php html_start_box("", "", $colors["header"], "3", "center", ""); ?> <tr> <td class="textHeader" nowrap> Select Host(s): </td> </tr> <tr> <td> <select title="Host Filters" id="host_select" name="host[]" multiple size="20" style="width: 150px; overflow: scroll; height: auto;" onChange="javascript:document.getElementById('syslog_form').submit();"> <?php if ($tab == "syslog") { ?> <option id="host_all" value="0"<?php if (is_array($_REQUEST["host"]) && $_REQUEST["host"][0] == "0" || $reset_multi) { ?> selected<?php } ?> >Show All Hosts</option><?php } else { ?> <option id="host_all" value="0"<?php if (is_array($_REQUEST["host"]) && $_REQUEST["host"][0] == "0" || $reset_multi) { ?> selected<?php } ?> >Show All Logs</option> <option id="host_none" value="-1"<?php if (is_array($_REQUEST["host"]) && $_REQUEST["host"][0] == "-1") { ?> selected<?php } ?> >Threshold Logs</option><?php } ?> <?php $hosts_where = ""; $hosts_where = api_plugin_hook_function('syslog_hosts_where', $hosts_where); $hosts = syslog_db_fetch_assoc("SELECT * FROM `" . $syslogdb_default . "`.`syslog_hosts` {$hosts_where} ORDER BY host"); if (sizeof($hosts)) { foreach ($hosts as $host) { print "<option value=" . $host["host_id"]; if (sizeof($_REQUEST["host"])) { foreach ($_REQUEST["host"] as $rh) { if ($rh == $host["host_id"] && !$reset_multi) { print " selected"; break; } } } else { if ($host["host_id"] == $_REQUEST["host"] && !$reset_multi) { print " selected"; } } print ">"; print $host["host"] . "</option>\n"; } } ?> </select> </td> </tr> <?php html_end_box(false); ?> </td> </tr> </table> </td> <td width="100%" valign="top" style="padding: 0px;"> <table width="100%" cellspacing="0" cellpadding="1"> <tr> <td width="100%" valign="top"><?php display_output_messages(); ?> <?php if ($tab == "syslog") { if ($_REQUEST["removal"] == 1) { $total_rows = syslog_db_fetch_cell("SELECT SUM(totals)\n\t\t\t\t\t\t\t\t\t\t\tFROM (\n\t\t\t\t\t\t\t\t\t\t\tSELECT count(*) AS totals\n\t\t\t\t\t\t\t\t\t\t\tFROM `" . $syslogdb_default . "`.`syslog` " . $sql_where . "\n\t\t\t\t\t\t\t\t\t\t\tUNION\n\t\t\t\t\t\t\t\t\t\t\tSELECT count(*) AS totals\n\t\t\t\t\t\t\t\t\t\t\tFROM `" . $syslogdb_default . "`.`syslog_removed` " . $sql_where . ") AS rowcount"); } elseif ($_REQUEST["removal"] == -1) { $total_rows = syslog_db_fetch_cell("SELECT count(*) FROM `" . $syslogdb_default . "`.`syslog` " . $sql_where); } else { $total_rows = syslog_db_fetch_cell("SELECT count(*) FROM `" . $syslogdb_default . "`.`syslog_removed` " . $sql_where); } } else { $total_rows = syslog_db_fetch_cell("SELECT count(*)\n\t\t\t\t\t\t\t\t\tFROM `" . $syslogdb_default . "`.`syslog_logs` AS sl\n\t\t\t\t\t\t\t\t\tLEFT JOIN `" . $syslogdb_default . "`.`syslog_facilities` AS sf\n\t\t\t\t\t\t\t\t\tON sl.facility=sf.facility\n\t\t\t\t\t\t\t\t\tLEFT JOIN `" . $syslogdb_default . "`.`syslog_priorities` AS sp\n\t\t\t\t\t\t\t\t\tON sl.priority=sp.priority\n\t\t\t\t\t\t\t\t\tLEFT JOIN `" . $syslogdb_default . "`.`syslog_hosts` AS sh\n\t\t\t\t\t\t\t\t\tON sl.host=sh.host\n\t\t\t\t\t\t\t\t\tLEFT JOIN `" . $syslogdb_default . "`.`syslog_alert` AS sa\n\t\t\t\t\t\t\t\t\tON sl.alert_id=sa.id " . $sql_where); } html_start_box("", "100%", $colors["header"], "3", "center", ""); $hostarray = ""; if (is_array($_REQUEST["host"])) { foreach ($_REQUEST["host"] as $h) { $hostarray .= "host[]={$h}&"; } } else { $hostarray .= "host[]=" . $_REQUEST["host"] . "&"; } return $total_rows; }
function settings() { global $colors, $tabs_graphs, $settings_graphs, $current_user, $graph_views, $current_user, $graph_tree_views; /* 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; } /* Find out whether this user has right here */ if($current_user["graph_settings"] == "") { print "<strong><font size='+1' color='#FF0000'>YOU DO NOT HAVE RIGHTS TO CHANGE GRAPH SETTINGS</font></strong>"; include_once("./include/bottom_footer.php"); exit; } if (read_config_option("auth_method") != 0) { if ($current_user["policy_graphs"] == "1") { $sql_where = "where user_auth_tree.user_id is null"; }elseif ($current_user["policy_graphs"] == "2") { $sql_where = "where user_auth_tree.user_id is not null"; } $settings_graphs["tree"]["default_tree_id"]["sql"] = get_graph_tree_array(true); } print "<form method='post' action='graph_settings.php'>\n"; html_graph_start_box(1, true); print "<tr bgcolor='#" . $colors["header"] . "'><td colspan='3'><table cellspacing='0' cellpadding='3' width='100%'><tr><td class='textHeaderDark'><strong>Graph Settings</strong></td></tr></table></td></tr>"; while (list($tab_short_name, $tab_fields) = each($settings_graphs)) { ?> <tr bgcolor='<?php print $colors["header_panel"];?>'> <td colspan='2' class='textSubHeaderDark' style='padding: 3px;'> <?php print $tabs_graphs[$tab_short_name];?> </td> </tr> <?php $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("select value from settings_graphs where name='$sub_field_name' and user_id=" . $_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("select value from settings_graphs where name='$field_name' and user_id=" . $_SESSION["sess_user_id"]); } } draw_edit_form( array( "config" => array( "no_form_tag" => true ), "fields" => $form_array ) ); } html_graph_end_box(); print "<br>"; 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); } } form_hidden_box("referer",(isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : ""),""); form_hidden_box("save_component_graph_config","1",""); form_save_button("graph_settings.php", "save"); }
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 template() { global $host_actions; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("page")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* clean up sort_column */ if (isset($_REQUEST["sort_column"])) { $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column")); } /* clean up sort_direction string */ if (isset($_REQUEST["sort_direction"])) { $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction")); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { kill_session_var("sess_host_template_current_page"); kill_session_var("sess_host_template_filter"); kill_session_var("sess_host_template_sort_column"); kill_session_var("sess_host_template_sort_direction"); unset($_REQUEST["page"]); unset($_REQUEST["filter"]); unset($_REQUEST["sort_column"]); unset($_REQUEST["sort_direction"]); } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("page", "sess_host_template_current_page", "1"); load_current_session_value("filter", "sess_host_template_filter", ""); load_current_session_value("sort_column", "sess_host_template_sort_column", "name"); load_current_session_value("sort_direction", "sess_host_template_sort_direction", "ASC"); display_output_messages(); html_start_box("<strong>Host Templates</strong>", "100%", "", "3", "center", "host_templates.php?action=edit"); ?> <tr class='even noprint'> <td> <form name="form_graph_template" action="host_templates.php"> <table width="100%" cellpadding="0" cellspacing="0"> <tr> <td nowrap style='white-space: nowrap;' width="50"> Search: </td> <td width="1"> <input type="text" name="filter" size="40" value="<?php print htmlspecialchars(get_request_var_request("filter")); ?> "> </td> <td nowrap style='white-space: nowrap;'> <input type="submit" value="Go" title="Set/Refresh Filters"> <input type="submit" name="clear_x" value="Clear" title="Clear Filters"> </td> </tr> </table> <input type='hidden' name='page' value='1'> </form> </td> </tr> <?php html_end_box(); /* form the 'where' clause for our main sql query */ if (strlen($_REQUEST['filter'])) { $sql_where = "WHERE (host_template.name LIKE '%%" . get_request_var_request("filter") . "%%')"; } else { $sql_where = ""; } /* print checkbox form for validation */ print "<form name='chk' method='post' action='host_templates.php'>\n"; html_start_box("", "100%", "", "3", "center", ""); $total_rows = db_fetch_cell("SELECT\n\t\tCOUNT(host_template.id)\n\t\tFROM host_template\n\t\t{$sql_where}"); $template_list = db_fetch_assoc("SELECT\n\t\thost_template.id,host_template.name, COUNT(host.id) AS hosts\n\t\tFROM host_template\n\t\tLEFT JOIN host ON host.host_template_id=host_template.id\n\t\t{$sql_where}\n\t\tGROUP BY host_template.id\n\t\tORDER BY " . get_request_var_request("sort_column") . " " . get_request_var_request("sort_direction") . " LIMIT " . read_config_option("num_rows_device") * (get_request_var_request("page") - 1) . "," . read_config_option("num_rows_device")); $nav = html_nav_bar("host_templates.php?filter=" . get_request_var_request("filter"), MAX_DISPLAY_PAGES, get_request_var_request("page"), read_config_option("num_rows_device"), $total_rows, 4); print $nav; $display_text = array("name" => array("Template Title", "ASC"), "host_template.id" => array("ID", "ASC"), "hosts" => array("Hosts", "DESC")); html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction"), false); $i = 0; if (sizeof($template_list) > 0) { foreach ($template_list as $template) { form_alternate_row('line' . $template["id"], true); form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars("host_templates.php?action=edit&id=" . $template["id"]) . "'>" . (strlen(get_request_var_request("filter")) ? preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", htmlspecialchars($template["name"])) : htmlspecialchars($template["name"])) . "</a>", $template["id"]); form_selectable_cell($template["id"], $template["id"]); form_selectable_cell(number_format($template["hosts"]), $template["id"]); form_checkbox_cell($template["name"], $template["id"]); form_end_row(); } /* put the nav bar on the bottom as well */ print $nav; } else { print "<tr><td><em>No Host Templates</em></td></tr>\n"; } html_end_box(false); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($host_actions); print "</form>\n"; }
function settings() { global $colors, $themes; $themes["default"] = _("System Default (Global Setting)"); /* you cannot have per-user settings if cacti's user management is not turned on */ if (read_config_option("auth_method") == "0") { raise_message(6); display_output_messages(); return; } /* get user settings */ $user = api_user_info( array( "id" => $_SESSION["sess_user_id"] ) ); print "<form method='post'>\n"; html_start_box("<strong>" . _("User Settings") . "</strong>", "98%", $colors["header_background"], "3", "center", ""); ?> <tr bgcolor='<?php print $colors["header_panel_background"];?>'> <td colspan='2' class='textSubHeaderDark' style='padding: 3px;'>General</td> </tr> <?php $form_array = array( "current_theme" => array( "friendly_name" => _("Visual Theme"), "description" => _("The Cacti theme to use. Changes the look of Cacti."), "method" => "drop_array", "array" => $themes, "value" => api_user_theme($_SESSION["sess_user_id"]), "default" => "default" ) ); draw_edit_form( array( "config" => array( "no_form_tag" => true ), "fields" => $form_array ) ); html_end_box(); form_hidden_box("save_component_user","1",""); form_save_button((isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : "index.php"), "save"); }
function mactrack_device_type_edit() { global $config, $fields_mactrack_device_type_edit; /* ================= input validation ================= */ get_filter_request_var('device_type_id'); /* ==================================================== */ display_output_messages(); if (!isempty_request_var('device_type_id')) { $device_type = db_fetch_row_prepared('SELECT * FROM mac_track_device_types WHERE device_type_id = ?', array(get_request_var('device_type_id'))); $header_label = __('MacTrack Device Types [edit: %s]', $device_type['description']); } else { $header_label = __('MacTrack Device Types [new]'); } form_start('mactrack_device_types.php', 'chk'); html_start_box($header_label, '100%', '', '3', 'center', ''); draw_edit_form(array('config' => array('no_form_tag' => 'true'), 'fields' => inject_form_variables($fields_mactrack_device_type_edit, isset($device_type) ? $device_type : array()))); html_end_box(); form_save_button('mactrack_device_types.php', 'return', 'device_type_id'); }