function xaxis_edit() { global $colors; require(CACTI_BASE_PATH . "/include/presets/preset_xaxis_arrays.php"); require_once(CACTI_BASE_PATH . "/lib/presets/preset_xaxis_info.php"); /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ if (!empty($_GET["id"])) { $xaxis = db_fetch_row("select * from graph_templates_xaxis where id=" . $_GET["id"]); $header_label = __("[edit: ") . $xaxis["name"] . "]"; }else{ $header_label = __("[new]"); } print "<form method='post' action='" . basename($_SERVER["PHP_SELF"]) . "' name='xaxis_edit'>\n"; html_start_box("<strong>". __("X-Axis Presets") . "</strong> $header_label", "100", $colors["header"], 0, "center", ""); $header_items = array(__("Field"), __("Value")); print "<tr><td>"; html_header($header_items, 2, false, 'header_xaxis_edit','left wp100'); draw_edit_form(array( "config" => array("no_form_tag" => true), "fields" => inject_form_variables(preset_xaxis_form_list(), (isset($xaxis) ? $xaxis : array())) )); print "</table></td></tr>"; /* end of html_header */ html_end_box(); if (!empty($_GET["id"])) { $sql_query = "SELECT * FROM graph_templates_xaxis_items WHERE xaxis_id=" . $_GET["id"] . " ORDER BY timespan ASC"; $xaxis_items = db_fetch_assoc($sql_query); html_start_box("<strong>" . __("X-Axis Items") . "</strong>", "100", $colors["header"], 0, "center", "xaxis_presets.php?action=item_edit&xaxis_id=" . $_GET["id"], false, "xaxis"); $header_items = array(__("Item"), __("Name"), __("Timespan"), __("Global Grid Span"), __("Steps"), __("Major Grid Span"), __("Steps"), __("Label Grid Span"), __("Steps"), __("Relative Label Position"), __("Label Format")); print "<tr><td>"; html_header($header_items, 12, true, 'xaxis_item','left wp100'); if (sizeof($xaxis_items) > 0) { $i = 0; foreach ($xaxis_items as $xaxis_item) { form_alternate_row_color('line' . $xaxis_item["id"], true); form_selectable_cell("<a style='white-space:nowrap;' class='linkEditMain' href='" . htmlspecialchars("xaxis_presets.php?action=item_edit&id=" . $xaxis_item["id"] . "&xaxis_id=" . $_GET["id"]) . "'>Item# $i</a>", $xaxis_item["id"]); form_selectable_cell((isset($xaxis_item["item_name"]) ? $xaxis_item["item_name"] : ''), $xaxis_item["id"]); form_selectable_cell((isset($xaxis_item["timespan"]) ? $xaxis_item["timespan"] : 0), $xaxis_item["id"]); form_selectable_cell((isset($rrd_xaxis_timespans[$xaxis_item["gtm"]]) ? $rrd_xaxis_timespans[$xaxis_item["gtm"]] : __("None")), $xaxis_item["id"]); form_selectable_cell((isset($xaxis_item["gst"]) ? $xaxis_item["gst"] : 0), $xaxis_item["id"]); form_selectable_cell((isset($rrd_xaxis_timespans[$xaxis_item["mtm"]]) ? $rrd_xaxis_timespans[$xaxis_item["mtm"]] : __("None")), $xaxis_item["id"]); form_selectable_cell((isset($xaxis_item["mst"]) ? $xaxis_item["mst"] : 0), $xaxis_item["id"]); form_selectable_cell((isset($rrd_xaxis_timespans[$xaxis_item["ltm"]]) ? $rrd_xaxis_timespans[$xaxis_item["ltm"]] : __("None")), $xaxis_item["id"]); form_selectable_cell((isset($xaxis_item["lst"]) ? $xaxis_item["lst"] : 0), $xaxis_item["id"]); form_selectable_cell((isset($xaxis_item["lpr"]) ? $xaxis_item["lpr"] : 0), $xaxis_item["id"]); form_selectable_cell((isset($xaxis_item["lfm"]) ? $xaxis_item["lfm"] : __("None")), $xaxis_item["id"]); ?> <td align="right"><a href="<?php print htmlspecialchars("xaxis_presets.php?action=item_remove&id=" . $xaxis_item["id"] . "&xaxis_id=" . $xaxis["id"]);?>"><img class="buttonSmall" src="images/delete_icon.gif" alt="<?php print __("Delete");?>" align='middle'></a> </td> <?php $i++; form_end_row(); } }else{ print "<tr><td><em>" . __("No X-Axis Preset Items") . "</em></td></tr>"; } print "</table></td></tr>"; /* end of html_header */ html_end_box(); } form_hidden_box("id", (isset($_GET["id"]) ? $_GET["id"] : "0"), ""); form_hidden_box("save_component_xaxis", "1", ""); form_save_button_alt("path!xaxis_presets.php"); }
/** * data_source_template_item - list all data template items */ function data_template_display_items() { global $colors; require(CACTI_BASE_PATH . "/include/graph/graph_arrays.php"); /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ if (!empty($_GET["id"])) { $template = db_fetch_row("SELECT * FROM data_template WHERE id=" . $_REQUEST["id"]); $template_item_list = db_fetch_assoc("SELECT * FROM data_template_rrd WHERE data_template_id=" . $_REQUEST["id"] . " AND local_data_id=0 ORDER BY data_source_name"); $header_label = __("[edit: ") . $template["name"] . "]"; }else{ $template_item_list = array(); $header_label = __("[new]"); } html_start_box("<strong>" . __("Data Source Items") . "</strong> $header_label", "100", $colors["header"], "0", "center", "data_templates_items.php?action=item_edit&data_template_id=" . $_REQUEST["id"], true); draw_data_template_items_list($template_item_list, "data_templates_items.php", "data_template_id=" . $_REQUEST["id"], false); html_end_box(true); form_save_button_alt("url!data_templates.php"); }
function graph_template_display_items() { global $colors; require(CACTI_BASE_PATH . "/include/graph/graph_arrays.php"); /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ if (empty($_REQUEST["id"])) { $template_item_list = array(); $header_label = __("[new]"); }else{ $template_item_list = db_fetch_assoc("select graph_templates_item.id, graph_templates_item.text_format, graph_templates_item.value, graph_templates_item.hard_return, graph_templates_item.graph_type_id, graph_templates_item.line_width, graph_templates_item.dashes, graph_templates_item.dash_offset, graph_templates_item.textalign, graph_templates_item.shift, graph_templates_item.consolidation_function_id, CONCAT_WS(' - ',data_template_data.name,data_template_rrd.data_source_name) as data_source_name, cdef.name as cdef_name, colors.hex, graph_templates_gprint.name as gprint_name from graph_templates_item left join data_template_rrd on (graph_templates_item.task_item_id=data_template_rrd.id) left join data_local on (data_template_rrd.local_data_id=data_local.id) left join data_template_data on (data_local.id=data_template_data.local_data_id) left join cdef on (cdef_id=cdef.id) left join vdef on (vdef_id=vdef.id) left join colors on (color_id=colors.id) left join graph_templates_gprint on (gprint_id=graph_templates_gprint.id) where graph_templates_item.graph_template_id=" . $_REQUEST["id"] . " and graph_templates_item.local_graph_id=0 order by graph_templates_item.sequence"); $header_label = __("[edit: ") . db_fetch_cell("select name from graph_templates where id=" . $_REQUEST["id"]) . "]"; } /* graph template item */ html_start_box("<strong>" . __("Graph Template Items") . "</strong> $header_label", "100", $colors["header"], "0", "center", "graph_templates_items.php?action=item_edit&graph_template_id=" . $_REQUEST["id"], true); draw_graph_items_list($template_item_list, "graph_templates_items.php", "graph_template_id=" . $_REQUEST["id"], false); html_end_box(true); /* graph template inputs */ html_start_box("<strong>" . __("Graph Item Inputs") . "</strong>", "100", $colors["header"], "3", "center", "graph_templates_inputs.php?action=input_edit&graph_template_id=" . $_REQUEST["id"], true); print "<tr><td>\n"; html_header(array(__("Name")), 2,'','','left wp100'); $template_item_list = db_fetch_assoc("select id,name from graph_template_input where graph_template_id=" . $_REQUEST["id"] . " order by name"); if (sizeof($template_item_list) > 0) { foreach ($template_item_list as $item) { form_alternate_row_color("item" . $item["id"]); ?> <td><a class="linkEditMain" href='<?php print htmlspecialchars("graph_templates_inputs.php?action=input_edit&id=" . $item["id"] . "&graph_template_id=" . $_REQUEST["id"]);?>'><?php print $item["name"];?></a> </td> <td align="right"><a href='<?php print htmlspecialchars("graph_templates_inputs.php?action=input_remove&id=" . $item["id"] . "&graph_template_id=" . $_GET["id"]);?>'><img class="buttonSmall" src="images/delete_icon.gif" alt="<?php print __("Delete");?>" align='right'></a></td> <?php form_end_row(); } }else{ print "<tr class='rowAlternate1'><td colspan='2'><em>" . __("No Inputs") . "</em></td></tr>"; } print "</table></td></tr>"; html_end_box(true); form_save_button_alt("url!graph_templates.php"); ?> <script type="text/javascript"> <!-- $(document).ready(function(){ //drag and drop for graph items $('#graph_item').tableDnD({ onDrop: function(table, row) { // alert($.tableDnD.serialize()); $('#AjaxResult').load("lib/ajax/jquery.tablednd/graph_templates_item.ajax.php?id=<?php isset($_GET["id"]) ? print $_GET["id"] : print "";?>&"+$.tableDnD.serialize()); } }); }); //--> </script> <?php }
function export() { global $colors, $export_types; /* 'graph_template' should be the default */ if (!isset($_REQUEST["export_type"])) { $_REQUEST["export_type"] = "graph_template"; } ?> <form name="form_graph_id" action="templates_export.php"> <table class='topBoxAlt'> <tr> <td class="textArea"> <?php print __("What would you like to export?");?> <select name="cbo_graph_id" onChange="window.location=document.form_graph_id.cbo_graph_id.options[document.form_graph_id.cbo_graph_id.selectedIndex].value"> <?php while (list($key, $array) = each($export_types)) { print "<option value='templates_export.php?export_type=$key'"; if (get_request_var_request("export_type") == $key) { print " selected"; } print ">" . $array["name"] . "</option>\n"; } ?> </select> </td> </tr> </table> </form> <form action="templates_export.php" method="post"> <?php html_start_box("<strong>" . __("Export Template") . "</strong> [" . $export_types{get_request_var_request("export_type")}["name"] . "]", "100", $colors["header"], "3", "center", ""); form_alternate_row_color("item"); ?> <td width="50%"> <font class="textEditTitle"><?php print $export_types{$_REQUEST["export_type"]}["name"];?> <?php print __("to Export");?></font><br> <?php print __("Choose the exact item to export to XML.");?> </td> <td> <?php form_dropdown("export_item_id",db_fetch_assoc($export_types{get_request_var_request("export_type")}["dropdown_sql"]),"name","id","","","0");?> </td> </tr> <?php form_alternate_row_color("dependencies"); ?> <td width="50%"> <font class="textEditTitle"><?php print __("Include Dependencies");?></font><br> <?php print __("Some templates rely on other items in Cacti to function properly. It is highly recommended that you select this box or the resulting import may fail.");?> </td> <td> <?php form_checkbox("include_deps", CHECKED, __("Include Dependencies"), CHECKED, "", true);?> </td> </tr> <?php form_alternate_row_color("format"); ?> <td width="50%"> <font class="textEditTitle"><?php print __("Output Format");?></font><br> <?php print __("Choose the format to output the resulting XML file in.");?> </td> <td> <?php form_radio_button("output_format", "3", "1", __("Output to the Browser (within Cacti)"),"1",true); print "<br>"; form_radio_button("output_format", "3", "2", __("Output to the Browser (raw XML)"),"1",true); print "<br>"; form_radio_button("output_format", "3", "3", __("Save File Locally"),"1",true); ?> </td> </tr> <?php html_end_box(); form_hidden_box("export_type", get_request_var_request("export_type"), ""); form_hidden_box("save_component_export","1",""); form_save_button_alt("", "save", "export"); }
function user_edit() { global $colors, $fields_user_user_edit_device; /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ if (!empty($_GET["id"])) { $user = db_fetch_row("SELECT * FROM user_auth WHERE id = " . get_request_var("id")); $header_label = __("[edit: ") . $user["username"] . "]"; }else{ $header_label = __("[new]"); } api_plugin_hook_function('user_admin_edit', (isset($user) ? get_request_var("id") : 0)); $user_tabs = array( "user_edit" => array("name" => __("General Settings"), "title" => __("General Settings are common settings for all users.")), "user_realms_edit" => array("name" => __("Realm Permissions"), "title" => __("Realm permissions control which sections of Cacti this user will have access to.")), "graph_perms_edit" => array("name" => __("Graph Permissions"), "title" => __("Graph policies will be evaluated in the order shown until a match is found.")), "graph_settings_edit" => array("name" => __("Graph Settings"), "title" => __("Graph settings control how graphs are displayed for this user."))); /* draw the categories tabs on the top of the page */ /* set the default settings category */ if (!isset($_GET["action"])) { /* there is no selected tab; select the first one */ $current_tab = array_keys($user_tabs); $current_tab = $current_tab[0]; }else{ $current_tab = $_GET["action"]; } print "<table width='100%' cellspacing='0' cellpadding='0' align='center'><tr>"; print "<td><div class='tabs'>"; if (sizeof($user_tabs)) { foreach (array_keys($user_tabs) as $tab_short_name) { print "<div title='" . $user_tabs[$tab_short_name]["title"] . "' class='tabDefault'><a " . (($tab_short_name == $current_tab) ? "class='tabSelected'" : "class='tabDefault'") . " href='" . htmlspecialchars("user_admin.php?action=shift&action=" . $tab_short_name . "&id=" . get_request_var("id")) . "'>" . $user_tabs[$tab_short_name]["name"] . "</a></div>"; if (empty($_GET["id"])) break; } } print "</div></td></tr></table>\n"; print "<form method='post' action='" . basename($_SERVER["PHP_SELF"]) . "' name='user_edit'>\n"; if (get_request_var("action") == "user_edit") { html_start_box("<strong>" . __("General Settings") . "</strong>", "100", $colors["header"], 0, "center"); $header_items = array(__("Field"), __("Value")); print "<tr><td>"; html_header($header_items, 2, true, 'settings_general'); draw_edit_form(array( "config" => array("form_name" => "chk"), "fields" => inject_form_variables($fields_user_user_edit_device, (isset($user) ? $user : array())) )); print "</table></td></tr>"; /* end of html_header */ html_end_box(); }else{ # print "<span style='display:none;'>"; # # html_start_box("", "100%", $colors["header"], "3", "center"); # draw_edit_form(array( # "config" => array("form_name" => "chk"), # "fields" => inject_form_variables($fields_user_user_edit_device, (isset($user) ? $user : array())) # )); # html_end_box(); # # print "</span>"; if (get_request_var("action") == "graph_settings_edit") { graph_settings_edit(); }elseif (get_request_var("action") == "user_realms_edit") { user_realms_edit(); }elseif (get_request_var("action") == "graph_perms_edit") { graph_perms_edit(); }else{ if (!api_plugin_hook_function('user_admin_run_action', get_request_var_request("action"))) { user_realms_edit(); } } } form_save_button_alt("return!user_admin.php"); }
function data_source_edit() { global $colors; require_once(CACTI_BASE_PATH . "/lib/data_source/data_source_info.php"); /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ $use_data_template = true; $device_id = 0; if (!empty($_GET["id"])) { $data_local = db_fetch_row("select device_id,data_template_id from data_local where id='" . $_GET["id"] . "'"); $data = db_fetch_row("select * from data_template_data where local_data_id='" . $_GET["id"] . "'"); $data_source_items = db_fetch_assoc("select * from data_template_rrd where local_data_id=" . $_GET["id"] . " order by data_source_name"); if (isset($data_local["data_template_id"]) && $data_local["data_template_id"] >= 0) { $data_template = db_fetch_row("select id,name from data_template where id='" . $data_local["data_template_id"] . "'"); $data_template_data = db_fetch_row("select * from data_template_data where data_template_id='" . $data_local["data_template_id"] . "' and local_data_id=0"); } else { $_SESSION["sess_messages"] = 'Data Source "' . $_GET["id"] . '" does not exist.'; header ("Location: data_sources.php"); exit; } $header_label = __("[edit: ") . get_data_source_title($_GET["id"]) . "]"; if (empty($data_local["data_template_id"])) { $use_data_template = false; } }else{ $header_label = __("[new]"); $use_data_template = false; } /* handle debug mode */ if (isset($_GET["debug"])) { if (get_request_var("debug") == "0") { kill_session_var("ds_debug_mode"); }elseif (get_request_var("debug") == "1") { $_SESSION["ds_debug_mode"] = true; } } /* handle info mode */ if (isset($_GET["info"])) { if (get_request_var("info") == "0") { kill_session_var("ds_info_mode"); }elseif (get_request_var("info") == "1") { $_SESSION["ds_info_mode"] = true; } } include_once(CACTI_BASE_PATH . "/include/top_header.php"); $tip_text = ""; if (isset($data)) { $tip_text .= "<tr><td align=\\'right\\'><a class=\\'popup_item\\' id=\\'changeDSState\\' onClick=\\'changeDSState()\\' href=\\'#\\'>Unlock/Lock</a></td></tr>"; $tip_text .= "<tr><td align=\\'right\\'><a class=\\'popup_item\\' href=\\'" . htmlspecialchars('data_sources.php?action=data_source_toggle_status&id=' . (isset($_GET["id"]) ? $_GET["id"] : 0) . '&newstate=' . (($data["active"] == CHECKED) ? "0" : "1")) . "\\'>" . (($data["active"] == CHECKED) ? __("Disable") : __("Enable")) . "</a></td></tr>"; $tip_text .= "<tr><td align=\\'right\\'><a class=\\'popup_item\\' href=\\'" . htmlspecialchars('data_sources.php?action=data_source_edit&id=' . (isset($_GET["id"]) ? $_GET["id"] : 0) . '&debug=' . (isset($_SESSION["ds_debug_mode"]) ? "0" : "1")) . "\\'>" . __("Turn") . " <strong>" . (isset($_SESSION["ds_debug_mode"]) ? __("Off") : __(CHECKED)) . "</strong> " . __("Debug Mode") . "</a></td></tr>"; $tip_text .= "<tr><td align=\\'right\\'><a class=\\'popup_item\\' href=\\'" . htmlspecialchars('data_sources.php?action=data_source_edit&id=' . (isset($_GET["id"]) ? $_GET["id"] : 0) . '&info=' . (isset($_SESSION["ds_info_mode"]) ? "0" : "1")) . "\\'>" . __("Turn") . " <strong>" . (isset($_SESSION["ds_info_mode"]) ? __("Off") : __(CHECKED)) . "</strong> " . __("RRD Info Mode") . "</a><td></tr>"; } if (!empty($data_template["id"])) { $tip_text .= "<tr><td align=\\'right\\'><a class=\\'popup_item\\' href=\\'" . htmlspecialchars('data_templates.php?action=template_edit&id=' . (isset($data_template["id"]) ? $data_template["id"] : "0")) . "\\'>" . __("Edit Data Source Template") . "<br></a></td></td>"; } if (!empty($_GET["device_id"]) || !empty($data_local["device_id"])) { $tip_text .= "<tr><td align=\\'right\\'><a class=\\'popup_item\\' href=\\'" . htmlspecialchars('devices.php?action=edit&id=' . (isset($_GET["device_id"]) ? $_GET["device_id"] : $data_local["device_id"])) . "\\'>" . __("Edit Host") . "</a></td></tr>"; } if (!empty($_GET["id"])) { ?> <script type="text/javascript"> <!-- var disabled = true; $().ready(function() { $("input").attr("disabled","disabled") $("select").attr("disabled","disabled") $("#cancel").removeAttr("disabled"); }); function changeDSState() { if (disabled) { $("input").removeAttr("disabled"); $("select").removeAttr("disabled"); $("#cancel").removeAttr("disabled"); disabled = false; }else{ $("input").attr("disabled","disabled") $("select").attr("disabled","disabled") disabled = true; } } --> </script> <table width="100%" align="center"> <tr> <td class="textInfo" colspan="2" valign="top"> <?php print get_data_source_title(get_request_var("id"));?> </td> <td style="white-space:nowrap;" align="right" class="w1"><a id='tooltip' class='popup_anchor' href='#' onMouseOver="Tip('<?php print $tip_text;?>', BGCOLOR, '#EEEEEE', FIX, ['tooltip', -20, 0], STICKY, true, SHADOW, true, CLICKCLOSE, true, FADEOUT, 400, TEXTALIGN, 'right', BORDERCOLOR, '#F5F5F5')" onMouseOut="UnTip()">Data Source Options</a></td> </tr> </table> <?php } print "<form method='post' action='" . basename($_SERVER["PHP_SELF"]) . "' name='data_source_edit'>\n"; html_start_box("<strong>" . __("Data Source Template Selection") . "</strong> $header_label", "100", $colors["header"], 0, "center", ""); $header_items = array(__("Field"), __("Value")); print "<tr><td>"; html_header($header_items, 1, true, 'template'); $form_array = fields_data_source_form_list(); $form_array["data_template_id"]["id"] = (isset($data_template["id"]) ? $data_template["id"] : "0"); $form_array["data_template_id"]["name"] = db_fetch_cell("SELECT name FROM data_template WHERE id=" . $form_array["data_template_id"]["id"]); $form_array["device_id"]["id"] = (isset($_GET["device_id"]) ? $_GET["device_id"] : $data_local["device_id"]); $form_array["device_id"]["name"] = db_fetch_cell("SELECT CONCAT_WS('',description,' (',hostname,')') FROM device WHERE id=" . $form_array["device_id"]["id"]); draw_edit_form( array( "config" => array(), "fields" => $form_array ) ); print "</table></td></tr>"; /* end of html_header */ html_end_box(); form_hidden_box("hidden_data_template_id", (isset($data_template["id"]) ? $data_template["id"] : "0"), ""); form_hidden_box("hidden_device_id", (empty($data_local["device_id"]) ? (isset($_GET["device_id"]) ? $_GET["device_id"] : "0") : $data_local["device_id"]), ""); form_hidden_box("hidden_data_input_id", (isset($data["data_input_id"]) ? $data["data_input_id"] : "0"), ""); form_hidden_box("data_template_data_id", (isset($data) ? $data["id"] : "0"), ""); form_hidden_box("local_data_template_data_id", (isset($data) ? $data["local_data_template_data_id"] : "0"), ""); form_hidden_box("local_data_id", (isset($data) ? $data["local_data_id"] : "0"), ""); /* only display the "inputs" area if we are using a data template for this data source */ if (!empty($data["data_template_id"])) { html_start_box("<strong>" . __("Supplemental Data Source Template Data") . "</strong>", "100", $colors["header"], 0, "center", ""); draw_nontemplated_fields_data_source($data["data_template_id"], $data["local_data_id"], $data, "|field|", "<strong>" . __("Data Source Fields") . "</strong>", true, true, 0); draw_nontemplated_fields_data_source_item($data["data_template_id"], $data_source_items, "|field|_|id|", "<strong>" . __("Data Source Item Fields") . "</strong>", true, true, true, 0); draw_nontemplated_fields_custom_data($data["id"], "value_|id|", "<strong>" . __("Custom Data") . "</strong>", true, true, 0); html_end_box(); form_hidden_box("save_component_data","1",""); } if (((isset($_GET["id"])) || (isset($_GET["new"]))) && (empty($data["data_template_id"]))) { html_start_box("<strong>" . __("Data Source") . "</strong>", "100", $colors["header"], "3", "center", ""); $form_array = array(); $struct_data_source = data_source_form_list(); while (list($field_name, $field_array) = each($struct_data_source)) { $form_array += array($field_name => $struct_data_source[$field_name]); $form_array[$field_name]["value"] = (isset($data[$field_name]) ? $data[$field_name] : ""); $form_array[$field_name]["form_id"] = (empty($data["id"]) ? "0" : $data["id"]); if (!(($use_data_template == false) || (!empty($data_template_data{"t_" . $field_name})) || ($field_array["flags"] == "NOTEMPLATE"))) { $form_array[$field_name]["method"] = "template_" . $form_array[$field_name]["method"]; } } draw_edit_form( array( "config" => array("no_form_tag" => true), "fields" => inject_form_variables($form_array, (isset($data) ? $data : array())) ) ); html_end_box(); if (!empty($_GET["id"])) { html_start_box("<strong>" . __("Data Source Items") . "</strong>", "100", $colors["header"], "0", "center", "data_sources_items.php?action=item_edit&local_data_id=" . $_GET["id"], true); draw_data_template_items_list($data_source_items, "data_sources_items.php", "local_data_id=" . $_GET["id"], $use_data_template); html_end_box(false); } /* data source data goes here */ data_source_data_edit(); } /* display the debug mode box if the user wants it */ if ((isset($_SESSION["ds_debug_mode"])) && (isset($_GET["id"]))) { ?> <table width="100%" align="center"> <tr> <td> <span class="textInfo"><?php print __("Data Source Debug");?></span><br> <pre><?php print rrdtool_function_create(get_request_var("id"), true, array());?></pre> </td> </tr> </table> <?php } if ((isset($_SESSION["ds_info_mode"])) && (isset($_GET["id"]))) { $rrd_info = rrdtool_function_info($_GET["id"]); if (sizeof($rrd_info["rra"])) { $diff = rrdtool_cacti_compare($_GET["id"], $rrd_info); rrdtool_info2html($rrd_info, $diff); rrdtool_tune($rrd_info["filename"], $diff, true); } } if ((isset($_GET["id"])) || (isset($_GET["new"]))) { form_hidden_box("save_component_data_source","1",""); }else{ form_hidden_box("save_component_data_source_new","1",""); } form_save_button_alt(); include_once(CACTI_BASE_PATH . "/access/js/data_source_item.js"); include_once(CACTI_BASE_PATH . "/include/bottom_footer.php"); }
function tree_edit() { global $colors; require_once(CACTI_BASE_PATH . "/lib/graph_tree/graph_tree_info.php"); /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ /* clean up subaction */ if (isset($_REQUEST["subaction"])) { $_REQUEST["subaction"] = sanitize_search_string(get_request_var("subaction")); } if (!empty($_GET["id"])) { $tree = db_fetch_row("select * from graph_tree where id=" . $_GET["id"]); $header_label = __("[edit: ") . $tree["name"] . "]"; }else{ $header_label = __("[new]"); } print "<form method='post' action='" . basename($_SERVER["PHP_SELF"]) . "' name='tree_edit'>\n"; html_start_box("<strong>" . __("Graph Trees") . "</strong> $header_label", "100", $colors["header"], "3", "center", "", true); $header_items = array(__("Field"), __("Value")); print "<tr><td>"; html_header($header_items, 1, true, 'template'); draw_edit_form(array( "config" => array(), "fields" => inject_form_variables(graph_tree_form_list(), (isset($tree) ? $tree : array())) )); print "</table></td></tr>"; /* end of html_header */ html_end_box(FALSE); if (!empty($_GET["id"])) { /* setup the tree div's */ echo "<div id='tree' style='float:left;width:50%;'>"; html_start_box("<strong>" . __("Tree Items") . "</strong>", "100", $colors["header"], "3", "center", ""); $header_items = array(__("Item"), __("Value")); print "<tr><td>"; html_header($header_items, 3, true, 'tree'); grow_edit_graph_tree(get_request_var("id"), "", ""); print "</table></td></tr>"; /* end of html_header */ html_end_box(); echo "</div>"; /* setup the graph items div */ echo "<div id='items' style='float:right;width:50%';>"; html_start_box("<strong>" . __("Item Filter") . "</strong>", "100", $colors["header"], "3", "center", ""); $header_items = array(__("Item"), __("Value")); print "<tr><td>"; html_header($header_items, 3, true, 'tree'); print "</table></td></tr>"; /* end of html_header */ html_end_box(); echo "</div>"; } form_save_button_alt("path!tree.php"); }
function data_edit() { global $colors; require_once(CACTI_BASE_PATH . "/lib/data_input/data_input_info.php"); /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ if (!empty($_GET["id"])) { $data_input = db_fetch_row("select * from data_input where id=" . $_GET["id"]); $header_label = "[edit: " . $data_input["name"] . "]"; }else{ $header_label = "[new]"; } print "<form method='post' action='" . basename($_SERVER["PHP_SELF"]) . "' name='data_input_edit'>\n"; html_start_box("<strong>" . __("Data Input Methods") . "</strong> $header_label", "100", $colors["header"], 0, "center", ""); $header_items = array(__("Field"), __("Value")); print "<tr><td>"; html_header($header_items, 1, true, 'data_input','left wp100'); draw_edit_form(array( "config" => array(), "fields" => inject_form_variables(data_input_form_list(), (isset($data_input) ? $data_input : array())) )); print "</table></td></tr>"; /* end of html_header */ html_end_box(); if (!empty($_GET["id"])) { html_start_box("<strong>" . __("Input Fields") . "</strong>", "100", $colors["header"], 0, "center", "data_input.php?action=field_edit&type=in&data_input_id=" . $_GET["id"]); $header_items = array(__("Name"), __("Field Order"), __("Friendly Name")); print "<tr><td>"; html_header($header_items, 2, true, 'data_input_fields', 'left wp100'); $fields = db_fetch_assoc("select id,data_name,name,sequence from data_input_fields where data_input_id=" . $_GET["id"] . " and input_output='in' order by sequence, data_name"); if (sizeof($fields) > 0) { foreach ($fields as $field) { form_alternate_row_color("input_fields" . $field["id"]); ?> <td> <a class="linkEditMain" href="<?php print htmlspecialchars("data_input.php?action=field_edit&id=" . $field["id"] . "&data_input_id=" . $_GET["id"]);?>"><?php print $field["data_name"];?></a> </td> <td> <?php print $field["sequence"]; if ($field["sequence"] == "0") { print " (Not In Use)"; }?> </td> <td> <?php print $field["name"];?> </td> <td align="right"> <a href="<?php print htmlspecialchars("data_input.php?action=field_remove&id=" . $field["id"] . "&data_input_id=" . $_GET["id"]);?>"> <img class="buttonSmall" src="images/delete_icon.gif" alt="<?php print __("Delete");?>" align='right'> </a> </td> <?php form_end_row(); } }else{ print "<tr><td><em>" . __("No Input Fields") . "</em></td></tr>"; } print "</table></td></tr>"; /* end of html_header */ html_end_box(); html_start_box("<strong>" . __("Output Fields"). "</strong>", "100", $colors["header"], 0, "center", "data_input.php?action=field_edit&type=out&data_input_id=" . $_GET["id"]); $header_items = array(__("Name"), __("Field Order"), __("Friendly Name"), __("Update RRA")); print "<tr><td>"; html_header($header_items, 2, true, 'data_output_fields', 'left wp100'); $fields = db_fetch_assoc("select id,name,data_name,update_rra,sequence from data_input_fields where data_input_id=" . $_GET["id"] . " and input_output='out' order by sequence, data_name"); if (sizeof($fields) > 0) { foreach ($fields as $field) { form_alternate_row_color("output_fields" . $field["id"]); ?> <td> <a class="linkEditMain" href="<?php print htmlspecialchars("data_input.php?action=field_edit&id=" . $field["id"] . "&data_input_id=". $_GET["id"]);?>"><?php print $field["data_name"];?></a> </td> <td> <?php print $field["sequence"]; if ($field["sequence"] == "0") { print __(" (Not In Use)"); }?> </td> <td> <?php print $field["name"];?> </td> <td> <?php print html_boolean_friendly($field["update_rra"]);?> </td> <td align="right"> <a href="<?php print htmlspecialchars("data_input.php?action=field_remove&id=" . $field["id"] . "&data_input_id=" . $_GET["id"]);?>"> <img class="buttonSmall" src="images/delete_icon.gif" alt="<?php print __("Delete");?>" align='right'> </a> </td> <?php form_end_row(); } }else{ print "<tr><td><em>" . __("No Output Fields") . "</em></td></tr>"; } print "</table></td></tr>"; /* end of html_header */ html_end_box(); } form_save_button_alt("url!data_input.php"); }
if (config_value_exists($field_name)) { $form_array[$field_name]["form_id"] = 1; } $form_array[$field_name]["value"] = db_fetch_cell("select value from settings where name='$field_name'"); } } draw_edit_form( array( "config" => array(), "fields" => $form_array) ); print "</table></td></tr>"; /* end of html_header */ html_end_box(); include_once(CACTI_BASE_PATH . "/access/js/colorpicker.js"); include_once(CACTI_BASE_PATH . "/access/js/graph_template_options.js"); form_hidden_box("tab", $current_tab, ""); # the id tag is required for our js code! form_hidden_box("hidden_rrdtool_version", read_config_option("rrdtool_version"), ""); form_save_button_alt("url!index.php", "save", "save"); include(CACTI_BASE_PATH . "/include/bottom_footer.php"); break; }
function cdef_edit() { global $colors; require(CACTI_BASE_PATH . "/include/presets/preset_cdef_arrays.php"); require_once(CACTI_BASE_PATH . "/lib/presets/preset_cdef_info.php"); /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ if (!empty($_GET["id"])) { $cdef = db_fetch_row("select * from cdef where id=" . $_GET["id"]); $header_label = __("[edit: ") . $cdef["name"] . "]"; }else{ $header_label = __("[new]"); } print "<form method='post' action='" . basename($_SERVER["PHP_SELF"]) . "' name='cdef_edit'>\n"; html_start_box("<strong>". __("CDEF's") . "</strong> $header_label", "100", $colors["header"], 0, "center", ""); $header_items = array(__("Field"), __("Value")); print "<tr><td>"; html_header($header_items, 2, false, 'header_cdef_edit','left wp100'); draw_edit_form(array( "config" => array(), "fields" => inject_form_variables(preset_cdef_form_list(), (isset($cdef) ? $cdef : array())) )); print "</table></td></tr>"; /* end of html_header */ html_end_box(); if (!empty($_GET["id"])) { html_start_box("", "100", "aaaaaa", "3", "center", ""); draw_cdef_preview(get_request_var("id")); html_end_box(); html_start_box("<strong>" . __("CDEF Items") . "</strong>", "100", $colors["header"], 0, "center", "cdef.php?action=item_edit&cdef_id=" . $cdef["id"], false, "cdef"); $header_items = array(__("Item"), __("Item Value")); print "<tr><td>"; html_header($header_items, 2, true, 'cdef_item','left wp100'); $cdef_items = db_fetch_assoc("select * from cdef_items where cdef_id=" . $_GET["id"] . " order by sequence"); $i = 0; if (sizeof($cdef_items) > 0) { foreach ($cdef_items as $cdef_item) { form_alternate_row_color($cdef_item["id"], true); ?> <td> <a class="linkEditMain" href="<?php print htmlspecialchars("cdef.php?action=item_edit&id=" . $cdef_item["id"] . "&cdef_id=" . $cdef["id"]);?>">Item #<?php print $i;?></a> </td> <td> <em><?php $cdef_item_type = $cdef_item["type"]; print $cdef_item_types[$cdef_item_type];?></em>: <strong><?php print get_cdef_item_name($cdef_item["id"]);?></strong> </td> <td align="right"> <a href="<?php print htmlspecialchars("cdef.php?action=item_remove&id=" . $cdef_item["id"] . "&cdef_id=" . $cdef["id"]);?>"><img class="buttonSmall" src="images/delete_icon.gif" alt="<?php print __("Delete");?>" align='middle'></a> </td> <?php form_end_row(); $i++; } } print "</table></td></tr>"; /* end of html_header */ html_end_box(); } form_save_button_alt("path!cdef.php"); ?> <script type="text/javascript"> $('#cdef_item').tableDnD({ onDrop: function(table, row) { $('#AjaxResult').load("lib/ajax/jquery.tablednd/cdef.ajax.php?id=<?php isset($_GET["id"]) ? print $_GET["id"] : print 0;?>&"+$.tableDnD.serialize()); } }); </script> <?php }
function item_edit() { global $colors; require_once(CACTI_BASE_PATH . "/lib/graph/graph_info.php"); /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); input_validate_input_number(get_request_var("graph_template_id")); /* ==================================================== */ if (!empty($_GET["id"])) { $template_item = db_fetch_row("select * from graph_templates_item where id=" . get_request_var("id")); } /* by default, select the LAST DS chosen to make everyone's lives easier */ $struct_graph_item = graph_item_form_list(); if (!empty($_GET["graph_template_id"])) { $default = db_fetch_row("select task_item_id from graph_templates_item where graph_template_id=" . get_request_var("graph_template_id") . " and local_graph_id=0 order by sequence DESC"); if (sizeof($default) > 0) { $struct_graph_item["task_item_id"]["default"] = $default["task_item_id"]; }else{ $struct_graph_item["task_item_id"]["default"] = 0; } } /* modifications to the default graph items array */ $struct_graph_item["task_item_id"]["sql"] = "select CONCAT_WS('',data_template.name,' - ',' (',data_template_rrd.data_source_name,')') as name, data_template_rrd.id from (data_template_data,data_template_rrd,data_template) where data_template_rrd.data_template_id=data_template.id and data_template_data.data_template_id=data_template.id and data_template_data.local_data_id=0 and data_template_rrd.local_data_id=0 order by data_template.name,data_template_rrd.data_source_name"; $form_array = array(); while (list($field_name, $field_array) = each($struct_graph_item)) { $form_array += array($field_name => $struct_graph_item[$field_name]); $form_array[$field_name]["value"] = (isset($template_item) ? $template_item[$field_name] : ""); $form_array[$field_name]["form_id"] = (isset($template_item) ? $template_item["id"] : "0"); } if (!empty($_GET["id"])) { /* we want to mark the fields that are associated with a graph item input */ $graph_item_input_fields = db_fetch_assoc("select graph_template_input.id, graph_template_input.column_name from (graph_template_input,graph_template_input_defs) where graph_template_input.id=graph_template_input_defs.graph_template_input_id and graph_template_input.graph_template_id=" . get_request_var("graph_template_id") . " and graph_template_input_defs.graph_template_item_id=" . get_request_var("id") . " group by graph_template_input.column_name"); if (sizeof($graph_item_input_fields) > 0) { foreach ($graph_item_input_fields as $field) { $form_array{$field["column_name"]}["friendly_name"] .= " [<a href='" . htmlspecialchars("graph_templates_inputs.php?action=input_edit&id=" . $field["id"] . "&graph_template_id=" . get_request_var("graph_template_id")) . "'>Field Not Templated</a>]"; } } } if (!empty($_GET["graph_template_id"])) { $header_label = __("[edit graph: ") . db_fetch_cell("select name from graph_templates where id=" . get_request_var("graph_template_id")) . "]"; }else{ $header_label = __("[new]"); } print "<form method='post' action='" . basename($_SERVER["PHP_SELF"]) . "' name='graph_template_item_edit'>\n"; html_start_box("<strong>" . __("Graph Template Items") . "</strong> $header_label", "100", $colors["header"], 0, "center", "", true); $header_items = array(__("Field"), __("Value")); print "<tr><td>"; html_header($header_items, 2, true, 'header_graph_template_item_edit'); draw_edit_form( array( "config" => array("no_form_tag" => true), "fields" => $form_array ) ); print "</table></td></tr>"; /* end of html_header */ html_end_box(); form_hidden_box("graph_template_item_id", (isset($template_item) ? $template_item["id"] : "0"), ""); form_hidden_box("graph_template_id", get_request_var("graph_template_id"), "0"); # form_hidden_box("hidden_graph_type_id", (isset($template_item) ? $template_item["graph_type_id"] : "0"), ""); form_hidden_box("hidden_task_item_id", (isset($template_item) ? $template_item["task_item_id"] : "0"), ""); form_hidden_box("save_component_item", "1", ""); form_hidden_box("hidden_rrdtool_version", read_config_option("rrdtool_version"), ""); form_save_button_alt("url!" . (isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : "")); include_once(CACTI_BASE_PATH . "/access/js/graph_item_dependencies.js"); # this one modifies attr("disabled") include_once(CACTI_BASE_PATH . "/access/js/line_width.js"); include_once(CACTI_BASE_PATH . "/access/js/rrdtool_version.js"); # this one sets attr("disabled) and comes last! }
function graph_edit() { global $colors; require_once(CACTI_BASE_PATH . "/lib/graph/graph_info.php"); /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ $use_graph_template = true; if (!empty($_GET["id"])) { $local_graph_template_graph_id = db_fetch_cell("select local_graph_template_graph_id from graph_templates_graph where local_graph_id=" . get_request_var("id")); $graphs = db_fetch_row("select * from graph_templates_graph where local_graph_id=" . get_request_var("id")); $graphs_template = db_fetch_row("select * from graph_templates_graph where id=$local_graph_template_graph_id"); $device_id = db_fetch_cell("select device_id from graph_local where id=" . get_request_var("id")); $header_label = __("[edit: ") . get_graph_title(get_request_var("id")) . "]"; if ($graphs["graph_template_id"] == "0") { $use_graph_template = false; } }else{ $graphs = array(); $graphs_template = array(); $header_label = __("[new]"); $use_graph_template = false; } /* handle debug mode */ if (isset($_GET["debug"])) { if (get_request_var("debug") == "0") { kill_session_var("graph_debug_mode"); }elseif (get_request_var("debug") == "1") { $_SESSION["graph_debug_mode"] = true; } } $tip_text = "<tr><td align=\\'right\\'><a class=\\'popup_item\\' id=\\'changeGraphState\\' onClick=\\'changeGraphState()\\' href=\\'#\\'>Unlock/Lock</a></td></tr>"; $tip_text .= "<tr><td align=\\'right\\'><a class=\\'popup_item\\' href=\\'" . htmlspecialchars('graphs.php?action=graph_edit&id=' . (isset($_GET["id"]) ? get_request_var("id") : 0) . "&debug=" . (isset($_SESSION["graph_debug_mode"]) ? "0" : "1")) . "\\'>" . __("Turn") . " <strong>" . (isset($_SESSION["graph_debug_mode"]) ? __("Off") : __(CHECKED)) . "</strong> " . __("Debug Mode") . "</a></td></tr>"; if (!empty($graphs["graph_template_id"])) { $tip_text .= "<tr><td align=\\'right\\'><a class=\\'popup_item\\' href=\\'" . htmlspecialchars('graph_templates.php?action=template_edit&id=' . (isset($graphs["graph_template_id"]) ? $graphs["graph_template_id"] : "0")) . "\\'>" . __("Edit Template") . "</a></td></tr>"; } if (!empty($_GET["device_id"]) || !empty($device_id)) { $tip_text .= "<tr><td align=\\'right\\'><a class=\\'popup_item\\' href=\\'" . htmlspecialchars('devices.php?action=edit&id=' . (isset($_GET["device_id"]) ? get_request_var("device_id") : $device_id)) . "\\'>" . __("Edit Host") . "</a></td></tr>"; } if (!empty($_GET["id"])) { ?> <script type="text/javascript"> <!-- var disabled = true; $().ready(function() { $("input").attr("disabled","disabled"); $("select").attr("disabled","disabled"); $("#cancel").removeAttr("disabled"); }); function changeGraphState() { if (disabled) { $("input").removeAttr("disabled"); $("select").removeAttr("disabled"); disabled = false; rrdtool_graph_dependencies(); // even when unlocking, disable distinct rrdtool options }else{ $("input").attr("disabled","disabled"); $("select").attr("disabled","disabled"); $("#cancel").removeAttr("disabled"); disabled = true; } } //--> </script> <table width="100%" align="center"> <tr> <td class="textInfo" colspan="2" valign="top"> <?php print get_graph_title(get_request_var("id"));?> </td> <td style="white-space:nowrap;" align="right" width="1"><a id='tooltip' class='popup_anchor' href='#' onMouseOver="Tip('<?php print $tip_text;?>', BGCOLOR, '#EEEEEE', FIX, ['tooltip', -45, 0], STICKY, true, SHADOW, true, CLICKCLOSE, true, FADEOUT, 400, TEXTALIGN, 'right', BORDERCOLOR, '#F5F5F5')" onMouseOut="UnTip()">Graph Options</a></td> </tr> </table> <?php } print "<form method='post' action='" . basename($_SERVER["PHP_SELF"]) . "' name='graph_edit'>\n"; html_start_box("<strong>" . __("Graph Template Selection") . "</strong> $header_label", "100", $colors["header"], 0, "center", ""); $header_items = array(__("Field"), __("Value")); print "<tr><td>"; html_header($header_items, 1, true, 'template'); $form_array = array( "graph_template_id" => array( "method" => "autocomplete", "callback_function" => "./lib/ajax/get_graph_templates.php", "friendly_name" => __("Selected Graph Template"), "description" => __("Choose a graph template to apply to this graph. Please note that graph data may be lost if you change the graph template after one is already applied."), "id" => (isset($graphs["graph_template_id"]) ? $graphs["graph_template_id"] : "0"), "name" => db_fetch_cell("SELECT name FROM graph_templates WHERE id=" . (isset($graphs["graph_template_id"]) ? $graphs["graph_template_id"] : "0")) ), "device_id" => array( "method" => "autocomplete", "callback_function" => "./lib/ajax/get_device_detailed.php", "friendly_name" => __("Host"), "description" => __("Choose the device that this graph belongs to."), "id" => (isset($_GET["device_id"]) ? get_request_var("device_id") : $device_id), "name" => db_fetch_cell("SELECT CONCAT_WS('',description,' (',hostname,')') FROM device WHERE id=" . (isset($_GET['device_id']) ? $_GET['device_id'] : $device_id)) ), "graph_template_graph_id" => array( "method" => "hidden", "value" => (isset($graphs["id"]) ? $graphs["id"] : "0") ), "local_graph_id" => array( "method" => "hidden", "value" => (isset($graphs["local_graph_id"]) ? $graphs["local_graph_id"] : "0") ), "local_graph_template_graph_id" => array( "method" => "hidden", "value" => (isset($graphs["local_graph_template_graph_id"]) ? $graphs["local_graph_template_graph_id"] : "0") ), "_graph_template_id" => array( "method" => "hidden", "value" => (isset($graphs["graph_template_id"]) ? $graphs["graph_template_id"] : "0") ), "_device_id" => array( "method" => "hidden", "value" => (isset($device_id) ? $device_id : "0") ) ); draw_edit_form( array( "config" => array(), "fields" => $form_array ) ); print "</table></td></tr>"; /* end of html_header */ html_end_box(); # print "<form method='post' action='graphs.php'>\n"; /* only display the "inputs" area if we are using a graph template for this graph */ if (!empty($graphs["graph_template_id"])) { html_start_box("<strong>" . __("Supplemental Graph Template Data") . "</strong>", "100", $colors["header"], "0", "center", ""); draw_nontemplated_fields_graph($graphs["graph_template_id"], $graphs, "|field|", "<strong>" . __("Graph Fields") . "</strong>", true, true, 0); draw_nontemplated_fields_graph_item($graphs["graph_template_id"], get_request_var("id"), "|field|_|id|", "<strong>" . __("Graph Item Fields") ."</strong>", true); html_end_box(); } /* graph item list goes here */ if ((!empty($_GET["id"])) && (!array_key_exists("graph_template_id", $graphs))) { graph_template_item(); } if (!empty($_GET["id"])) { ?> <table width="100%" align="center"> <tr> <td align="center" class="textInfo" colspan="2"> <img src="<?php print htmlspecialchars("graph_image.php?action=edit&local_graph_id=" . get_request_var("id") . "&rra_id=" . read_graph_config_option("default_rra_id"));?>" alt=""> </td> <?php if ((isset($_SESSION["graph_debug_mode"])) && (isset($_GET["id"]))) { $graph_data_array = array(); $graph_data_array["output_flag"] = RRDTOOL_OUTPUT_STDERR; /* make rrdtool_function_graph to only print the command without executing it */ $graph_data_array["print_source"] = 1; ?> <td> <span class="textInfo"><?php print __("RRDTool Command:");?></span><br> <pre><?php print rrdtool_function_graph(get_request_var("id"), read_graph_config_option("default_rra_id"), $graph_data_array);?></pre> <span class="textInfo"><?php print __("RRDTool Says:");?></span><br> <?php /* make rrdtool_function_graph to generate AND execute the rrd command, but only for fetching the "return code" */ unset($graph_data_array["print_source"]);?> <pre><?php print rrdtool_function_graph(get_request_var("id"), read_graph_config_option("default_rra_id"), $graph_data_array);?></pre> </td> <?php } ?> </tr> </table> <?php } if (((isset($_GET["id"])) || (isset($_GET["new"]))) && (empty($graphs["graph_template_id"]))) { html_start_box("<strong>" . __("Graph Configuration") . "</strong>", "100", $colors["header"], "0", "center", ""); ############ html_start_box("<strong>" . __("Labels") . "</strong>", "100", $colors["header"], "0", "center", "", true); draw_template_edit_form('header_graph_labels', graph_labels_form_list(), $graphs, $use_graph_template); html_end_box(false); /* TODO: we should not use rrd version in the code, when going data-driven */ if ( read_config_option("rrdtool_version") != RRD_VERSION_1_0 && read_config_option("rrdtool_version") != RRD_VERSION_1_2) { html_start_box("<strong>" . __("Right Axis Settings") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_right_axis"); draw_template_edit_form('header_graph_right_axis', graph_right_axis_form_list(), $graphs, $use_graph_template); } html_end_box(false); html_start_box("<strong>" . __("Graph Template Size") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_size"); draw_template_edit_form('header_graph_size', graph_size_form_list(), $graphs, $use_graph_template); html_end_box(false); html_start_box("<strong>" . __("Graph Template Limits") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_limits"); draw_template_edit_form('header_graph_limits', graph_limits_form_list(), $graphs, $use_graph_template); html_end_box(false); html_start_box("<strong>" . __("Graph Template Grid") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_grid"); draw_template_edit_form('header_graph_grid', graph_grid_form_list(), $graphs, $use_graph_template); html_end_box(false); html_start_box("<strong>" . __("Graph Template Color") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_color"); draw_template_edit_form('header_graph_color', graph_color_form_list(), $graphs, $use_graph_template); html_end_box(false); html_start_box("<strong>" . __("Graph Template Legend") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_misc"); draw_template_edit_form('header_graph_legend', graph_legend_form_list(), $graphs, $use_graph_template); html_end_box(false); html_start_box("<strong>" . __("Graph Template Misc") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_misc"); draw_template_edit_form('header_graph_misc', graph_misc_form_list(), $graphs, $use_graph_template); html_end_box(false); html_start_box("<strong>" . __("Graph Template Cacti Specifics") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_cacti"); draw_template_edit_form('header_graph_cacti', graph_cacti_form_list(), $graphs, $use_graph_template); html_end_box(false); } if ((isset($_GET["id"])) || (isset($_GET["new"]))) { form_hidden_box("save_component_graph","1",""); form_hidden_box("save_component_input","1",""); }else{ form_hidden_box("save_component_graph_new","1",""); } form_hidden_box("hidden_rrdtool_version", read_config_option("rrdtool_version"), ""); form_save_button_alt(); include_once(CACTI_BASE_PATH . "/access/js/colorpicker.js"); include_once(CACTI_BASE_PATH . "/access/js/graph_template_options.js"); ?> <script type="text/javascript"> $('#graph_item').tableDnD({ onDrop: function(table, row) { $('#AjaxResult').load("lib/ajax/jquery.tablednd/graphs_item.ajax.php?id=<?php isset($_GET["id"]) ? print get_request_var("id") : print "";?>&"+$.tableDnD.serialize()); // location.reload(); } }); </script> <?php }
function device_display_general($device, $device_text) { global $colors; require(CACTI_BASE_PATH . "/include/data_query/data_query_arrays.php"); require_once(CACTI_BASE_PATH . "/lib/device/device_info.php"); if (isset($device["id"])) { html_start_box($device_text, "100", $colors["header"], "3", "center", "", true); ?> <tr> <?php if (($device["availability_method"] == AVAIL_SNMP) || ($device["availability_method"] == AVAIL_SNMP_AND_PING) || ($device["availability_method"] == AVAIL_SNMP_OR_PING)) { ?> <td class="textInfo"> <?php print __("SNMP Information");?><br> <span class="normal"> <?php if ((($device["snmp_community"] == "") && ($device["snmp_username"] == "")) || ($device["snmp_version"] == 0)) { print "<span class=\"info\">SNMP not in use</span>\n"; }else{ $snmp_system = cacti_snmp_get($device["hostname"], $device["snmp_community"], ".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"], read_config_option("snmp_retries"),SNMP_WEBUI); /* modify for some system descriptions */ /* 0000937: System output in devices.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 class=\"warning\">SNMP error</span>\n"; }else{ $snmp_uptime = cacti_snmp_get($device["hostname"], $device["snmp_community"], ".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"], read_config_option("snmp_retries"), SNMP_WEBUI); $snmp_hostname = cacti_snmp_get($device["hostname"], $device["snmp_community"], ".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"], read_config_option("snmp_retries"), SNMP_WEBUI); $snmp_location = cacti_snmp_get($device["hostname"], $device["snmp_community"], ".1.3.6.1.2.1.1.6.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"], read_config_option("snmp_retries"), SNMP_WEBUI); $snmp_contact = cacti_snmp_get($device["hostname"], $device["snmp_community"], ".1.3.6.1.2.1.1.4.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"], read_config_option("snmp_retries"), SNMP_WEBUI); print "<strong>System:</strong> " . html_split_string($snmp_system,200) . "<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> </td> <?php } if (($device["availability_method"] == AVAIL_PING) || ($device["availability_method"] == AVAIL_SNMP_AND_PING) || ($device["availability_method"] == AVAIL_SNMP_OR_PING)) { /* create new ping socket for device pinging */ $ping = new Net_Ping; $ping->device = $device; $ping->port = $device["ping_port"]; /* perform the appropriate ping check of the device */ if ($ping->ping($device["availability_method"], $device["ping_method"], $device["ping_timeout"], $device["ping_retries"])) { $device_down = false; $ping_class = "ping"; }else{ $device_down = true; $ping_class = "ping_warning"; } ?> <td class="textInfo" style="vertical-align:top;"> <?php print __("Ping Results");?><br> <span class="<?php $ping_class ?>"> <?php print $ping->ping_response; ?> </span> </td> <?php }else if ($device["availability_method"] == AVAIL_NONE) { ?> <td class="textInfo"> <?php print __("No Availability Check In Use");?><br> </td> <?php } ?> </tr> <?php }else{ html_start_box($device_text, "100", $colors["header"], "3", "center", "", false); } html_end_box(FALSE); print "<form method='post' action='" . basename($_SERVER["PHP_SELF"]) . "' name='device_edit_settings'>\n"; html_start_box("<strong>" . __("General Settings") . "</strong>", "100", $colors["header"], 0, "center", "", true); $header_items = array(__("Field"), __("Value")); print "<tr><td>"; html_header($header_items, 1, true, 'device'); /* preserve the device template id if passed in via a GET variable */ $fields_device_edit = device_form_list(); if (!empty($_GET["template_id"])) { // $fields_device_edit["device_template_id"]["value"] = $_GET["template_id"]; // $fields_device_edit["device_template_id"]["method"] = "hidden"; } /* if we are creating a device and have changed templates set that value */ if (!isset($device["id"])) { if (!empty($_GET["template_id"])) { $device["device_template_id"] = $_GET["template_id"]; } } /* draw basic fields only on first run for a new device */ draw_edit_form(array( "config" => array("form_name" => "chk", "no_form_tag" => true), "fields" => inject_form_variables($fields_device_edit, (is_array($device) ? $device : array())) )); /* if the device is new, check/set the $device array with some template values */ $override_permitted = true; $propagation_allowed = false; if (!isset($device["id"])) { $template_settings = db_fetch_row("SELECT * FROM device_template WHERE id=" . $_REQUEST["template_id"]); if (sizeof($template_settings)) { foreach($template_settings as $key => $value) { switch($key) { case "id": case "name": case "description": case "hash": case "image": unset($template_settings[$key]); break; case "override_defaults": if ($value == CHECKED) { $propagation_allowed = true; } unset($template_settings[$key]); break; case "override_permitted": if ($value != CHECKED) { $override_permitted = false; } break; default: break; } } } }else{ if (db_fetch_cell("SELECT override_defaults FROM device_template WHERE id=" . $device["device_template_id"]) == CHECKED) { $propagation_allowed = true; } } /* for a given device, display all availability options as well */ draw_edit_form(array( "config" => array("form_name" => "chk", "no_form_tag" => true), "fields" => inject_form_variables(device_availability_form_list(), (isset($template_settings) ? $template_settings : $device)) )); print "</table></td></tr>"; /* end of html_header */ html_end_box(!isset($device["id"])); form_hidden_box("id", (isset($device["id"]) ? $device["id"] : "0"), ""); form_hidden_box("hidden_device_template_id", (isset($device["device_template_id"]) ? $device["device_template_id"] : "0"), ""); form_hidden_box("save_basic_device", "1", ""); form_hidden_box("save_component_device", "1", ""); form_hidden_box("override_permitted", ($override_permitted ? "true":"false"), ""); form_hidden_box("propagation_allowed", ($propagation_allowed ? "true":"false"), ""); /* javascript relates to availability options, so include it only for existing devices */ ?> <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 == 4) { 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 toggleAvailabilityAndSnmp(template_enabled) { if (!template_enabled && $('#override_permitted').val() == 'true') { $('#override_permitted').removeAttr("disabled"); $('#availability_header').removeAttr("disabled"); $('#availability_method').removeAttr("disabled"); $('#ping_method').removeAttr("disabled"); $('#ping_port').removeAttr("disabled"); $('#ping_timeout').removeAttr("disabled"); $('#ping_retries').removeAttr("disabled"); $('#snmp_spacer').removeAttr("disabled"); $('#snmp_version').removeAttr("disabled"); $('#snmp_username').removeAttr("disabled"); $('#snmp_password').removeAttr("disabled"); $('#snmp_password_confirm').removeAttr("disabled"); $('#snmp_community').removeAttr("disabled"); $('#snmp_auth_protocol').removeAttr("disabled"); $('#snmp_priv_passphrase').removeAttr("disabled"); $('#snmp_priv_protocol').removeAttr("disabled"); $('#snmp_context').removeAttr("disabled"); $('#snmp_port').removeAttr("disabled"); $('#snmp_timeout').removeAttr("disabled"); $('#max_oids').removeAttr("disabled"); $('#device_threads').removeAttr("disabled"); }else{ $('#override_permitted').attr("disabled","disabled"); $('#availability_header').attr("disabled","disabled"); $('#availability_method').attr("disabled","disabled"); $('#ping_method').attr("disabled","disabled"); $('#ping_port').attr("disabled","disabled"); $('#ping_timeout').attr("disabled","disabled"); $('#ping_retries').attr("disabled","disabled"); $('#snmp_spacer').attr("disabled","disabled"); $('#snmp_version').attr("disabled","disabled"); $('#snmp_username').attr("disabled","disabled"); $('#snmp_password').attr("disabled","disabled"); $('#snmp_password_confirm').attr("disabled","disabled"); $('#snmp_community').attr("disabled","disabled"); $('#snmp_auth_protocol').attr("disabled","disabled"); $('#snmp_priv_passphrase').attr("disabled","disabled"); $('#snmp_priv_protocol').attr("disabled","disabled"); $('#snmp_context').attr("disabled","disabled"); $('#snmp_port').attr("disabled","disabled"); $('#snmp_timeout').attr("disabled","disabled"); $('#max_oids').attr("disabled","disabled"); $('#device_threads').attr("disabled","disabled"); } changeHostForm(); if ($('#override_permitted').val() == 'false') { $('#template_enabled').attr("checked","checked"); $('#template_enabled').attr("disabled","disabled"); } if ($('#propagation_allowed').val() == 'false') { $('#row_template_enabled').hide(); }else{ $('#row_template_enabled').show(); } } $().ready(function() { toggleAvailabilityAndSnmp(document.getElementById('template_enabled').checked); /* Hide options when override is turned off */ $("#template_enabled").change(function () { toggleAvailabilityAndSnmp(this.checked); }); if ($('#id').val() == 0) { $('#device_template_id').change(function() { document.location='devices.php?action=edit&template_id='+this.value+'&status=-1' }); } }); --> </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", "", true); print "<tr><td><span class=\"log\">" . debug_log_return("data_query") . "</span></td></tr>"; html_end_box(false); } if (isset($device["id"])) { html_start_box("<strong>". __("Associated Graph Templates") . "</strong>", "100", $colors["header"], 0, "center", "", true); print "<tr><td>"; html_header(array(__("Graph Template Name"), __("Status")), 2); $selected_graph_templates = db_fetch_assoc("select graph_templates.id, graph_templates.name from (graph_templates,device_graph) where graph_templates.id=device_graph.graph_template_id and device_graph.device_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"); /* omit those graph_templates, that have already been associated */ $keeper = array(); foreach ($available_graph_templates as $item) { if (sizeof(db_fetch_assoc("SELECT graph_template_id FROM device_graph " . " WHERE ((device_id=" . $_GET["id"] . ")" . " AND (graph_template_id=" . $item["id"] ."))")) > 0) { /* do nothing */ } else { array_push($keeper, $item); } } $available_graph_templates = $keeper; $i = 0; if (sizeof($selected_graph_templates) > 0) { foreach ($selected_graph_templates as $item) { $i++; form_alternate_row_color("graph_template" . $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 device_id=" . $_GET["id"])) > 0) ? true : false; ?> <td style="padding: 4px;"> <strong><?php print $i;?>)</strong> <?php print $item["name"];?> </td> <td> <?php print (($is_being_graphed == true) ? "<span class=\"success\">" . __("Is Being Graphed") . "</span> (<a href='" . htmlspecialchars("graphs.php?action=graph_edit&id=" . db_fetch_cell("select id from graph_local where graph_template_id=" . $item["id"] . " and device_id=" . get_request_var("id") . " limit 0,1")) . "'>" . __("Edit") . "</a>)" : "<span class=\"unknown\">" . __("Not Being Graphed") . "</span>");?> </td> <td align='right' nowrap> <a href='devices.php?action=gt_remove&id=<?php print $item["id"];?>&device_id=<?php print $_GET["id"];?>'><img align='middle' class='buttonSmall' src='images/delete_icon_large.gif' title='<?php print __("Delete Graph Template Association");?>' alt='<?php print __("Delete");?>'></a> </td> <?php form_end_row(); } }else{ print "<tr><td><em>" . __("No Associated Graph Templates.") . "</em></td></tr>"; } form_alternate_row_color("gt_device" . $device["id"]); ?> <td colspan="4"> <table cellspacing="0" cellpadding="1" width="100%"> <tr> <td nowrap><?php print __("Add Graph Template:");?> <?php form_dropdown("graph_template_id",$available_graph_templates,"name","id","","","");?> </td> <td align="right"> <input type="submit" value="<?php print __("Add");?>" name="add_gt_y" align="middle"> </td> </tr> </table> </td> <?php form_end_row(); print "</table></td></tr>"; /* end of html_header */ html_end_box(FALSE); html_start_box("<strong>" . __("Associated Data Queries") . "</strong>", "100", $colors["header"], 0, "center", "", true); print "<tr><td>"; 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, device_snmp_query.reindex_method from (snmp_query,device_snmp_query) where snmp_query.id=device_snmp_query.snmp_query_id and device_snmp_query.device_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 device_snmp_query " . " WHERE ((device_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++; form_alternate_row_color("selected_data_queries" . $i); /* get status information for this data query */ $num_dq_items = sizeof(db_fetch_assoc("select snmp_index from device_snmp_cache where device_id=" . $_GET["id"] . " and snmp_query_id=" . $item["id"])); $num_dq_rows = sizeof(db_fetch_assoc("select snmp_index from device_snmp_cache where device_id=" . $_GET["id"] . " and snmp_query_id=" . $item["id"] . " group by snmp_index")); $status = "success"; ?> <td style="padding: 4px;"> <strong><?php print $i;?>)</strong> <?php print $item["name"];?> </td> <td> (<a href="devices.php?action=query_verbose&id=<?php print $item["id"];?>&device_id=<?php print $_GET["id"];?>"><?php print __("Verbose Query");?></a>) </td> <td> <?php form_dropdown("reindex_method_device_".get_request_var("id")."_query_".$item["id"]."_method_".$item["reindex_method"],$reindex_types,"","",$item["reindex_method"],"","","","");?> </td> <td> <?php print (($status == "success") ? "<span class=\"success\">" . __("Success") . "</span>" : "<span class=\"fail\">" . __("Fail") . "</span>");?> [<?php print $num_dq_items;?> <?php print __("Item", $num_dq_items);?>, <?php print $num_dq_rows;?> <?php print __("Row", $num_dq_rows);?>] </td> <td align='right' nowrap> <a href='devices.php?action=query_reload&id=<?php print $item["id"];?>&device_id=<?php print $_GET["id"];?>'><img align='middle' class='buttonSmall' src='images/reload_icon_small.gif' title='<?php print __("Reload Data Query");?>' alt='<?php print __("Reload");?>'></a> <a href='devices.php?action=query_remove&id=<?php print $item["id"];?>&device_id=<?php print $_GET["id"];?>'><img align='middle' class='buttonSmall' src='images/delete_icon_large.gif' title='<?php print __("Delete Data Query Association");?>' alt='<?php print __("Delete");?>'></a> </td> <?php form_end_row(); } }else{ print "<tr><td><em>". __("No associated data queries.") . "</em></td></tr>"; } form_alternate_row_color("dq_device" . $device["id"]); ?> <td colspan="5"> <table cellspacing="0" cellpadding="1" width="100%"> <tr> <td nowrap><?php print __("Add Data Query:");?> <?php form_dropdown("snmp_query_id",$available_data_queries,"name","id","","","");?> </td> <td nowrap><?php print __("Re-Index Method:");?> <?php form_dropdown("reindex_method",$reindex_types,"","","1","","");?> </td> <td align="right"> <input type="submit" value="<?php print __("Add");?>" name="add_dq_y" align="middle"> </td> </tr> </table> </td> <?php form_end_row(); print "</table></td></tr>"; /* end of html_header */ html_end_box(); } form_save_button_alt(); }
function input_edit() { global $colors; require(CACTI_BASE_PATH . "/include/presets/preset_rra_arrays.php"); require_once(CACTI_BASE_PATH . "/lib/graph/graph_info.php"); require_once(CACTI_BASE_PATH . "/lib/graph_template/graph_template_info.php"); /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); input_validate_input_number(get_request_var("graph_template_id")); /* ==================================================== */ $header_label = __("[edit graph: ") . db_fetch_cell("select name from graph_templates where id=" . $_GET["graph_template_id"]) . "]"; if (!empty($_GET["local_graph_id"])) { $header_label = __("[edit graph: ") . db_fetch_cell("select name from graph_templates where id=" . $_GET["graph_template_id"]) . "]"; }else{ $header_label = __("[new]"); } /* get a list of all graph item field names and populate an array for user display */ $struct_graph_item = graph_item_form_list; while (list($field_name, $field_array) = each($struct_graph_item)) { if ($field_array["method"] != "view") { $graph_template_items[$field_name] = $field_array["friendly_name"]; } } if (!empty($_GET["id"])) { $graph_template_input = db_fetch_row("select * from graph_template_input where id=" . $_GET["id"]); } html_start_box("<strong>" . __("Graph Item Inputs") . "</strong> $header_label", "100", $colors["header"], "3", "center", ""); draw_edit_form(array( "config" => array(), "fields" => inject_form_variables(graph_template_input_form_list(), (isset($graph_template_input) ? $graph_template_input : array()), (isset($graph_template_items) ? $graph_template_items : array()), $_GET) )); if (!(isset($_GET["id"]))) { $_GET["id"] = 0; } $item_list = db_fetch_assoc("select CONCAT_WS(' - ',data_template_data.name,data_template_rrd.data_source_name) as data_source_name, graph_templates_item.text_format, graph_templates_item.id as graph_templates_item_id, graph_templates_item.graph_type_id, graph_templates_item.consolidation_function_id, graph_template_input_defs.graph_template_input_id from graph_templates_item left join graph_template_input_defs on (graph_template_input_defs.graph_template_item_id=graph_templates_item.id and graph_template_input_defs.graph_template_input_id=" . $_GET["id"] . ") left join data_template_rrd on (graph_templates_item.task_item_id=data_template_rrd.id) left join data_local on (data_template_rrd.local_data_id=data_local.id) left join data_template_data on (data_local.id=data_template_data.local_data_id) where graph_templates_item.local_graph_id=0 and graph_templates_item.graph_template_id=" . $_GET["graph_template_id"] . " order by graph_templates_item.sequence"); form_alternate_row_color(); ?> <td width="50%"> <font class="textEditTitle"><?php print __("Associated Graph Items");?></font><br> <?php print __("Select the graph items that you want to accept user input for.");?> </td> <td> <?php $i = 0; $any_selected_item = ""; if (sizeof($item_list) > 0) { foreach ($item_list as $item) { if ($item["graph_template_input_id"] == "") { $old_value = ""; }else{ $old_value = CHECKED; $any_selected_item = $item["graph_templates_item_id"]; } if ($item["graph_type_id"] == GRAPH_ITEM_TYPE_GPRINT_AVERAGE || $item["graph_type_id"] == GRAPH_ITEM_TYPE_GPRINT_LAST || $item["graph_type_id"] == GRAPH_ITEM_TYPE_GPRINT_MAX || $item["graph_type_id"] == GRAPH_ITEM_TYPE_GPRINT_MIN) { $start_bold = ""; $end_bold = ""; }else{ $start_bold = "<strong>"; $end_bold = "</strong>"; } $name = "$start_bold Item #" . ($i+1) . ": " . $graph_item_types{$item["graph_type_id"]} . " (" . $consolidation_functions{$item["consolidation_function_id"]} . ")$end_bold"; form_checkbox("i_" . $item["graph_templates_item_id"], $old_value, $name, "", "", get_request_var("graph_template_id")); print "<br>"; $i++; } }else{ print "<em>" . __("No Items") . "</em>"; } ?> </td> <?php form_end_row(); html_end_box(); form_hidden_box("any_selected_item", $any_selected_item, ""); form_save_button_alt("url!" . (isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : "")); }
function gprint_presets_edit() { global $colors; require_once(CACTI_BASE_PATH . "/lib/presets/preset_gprint_info.php"); /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ if (!empty($_GET["id"])) { $gprint_preset = db_fetch_row("select * from graph_templates_gprint where id=" . $_GET["id"]); $header_label = __("[edit: ") . $gprint_preset["name"] . "]"; }else{ $header_label = __("[new]"); } print "<form method='post' action='" . basename($_SERVER["PHP_SELF"]) . "' name='gprint_edit'>\n"; html_start_box("<strong>" . __("GPRINT Presets") . "</strong> $header_label", "100", $colors["header"], 0, "center", ""); $header_items = array(__("Field"), __("Value")); print "<tr><td>"; html_header($header_items, 2, true, 'header_gprint_preset'); draw_edit_form(array( "config" => array(), "fields" => inject_form_variables(preset_gprint_form_list(), (isset($gprint_preset) ? $gprint_preset : array())) )); print "</table></td></tr>"; /* end of html_header */ html_end_box(); form_save_button_alt(); }
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"); }
function data_query_edit() { global $colors, $config; require_once(CACTI_BASE_PATH . "/lib/data_query/data_query_info.php"); /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ if (!empty($_GET["id"])) { $snmp_query = db_fetch_row("select * from snmp_query where id=" . $_GET["id"]); $header_label = "[edit: " . $snmp_query["name"] . "]"; }else{ $header_label = "[new]"; } print "<form method='post' action='" . basename($_SERVER["PHP_SELF"]) . "' name='data_query_edit'>\n"; html_start_box("<strong>" . __("Data Queries") . "</strong> $header_label", "100", $colors["header"], 0, "center", ""); $header_items = array(__("Field"), __("Value")); print "<tr><td>"; html_header($header_items, 1, false, 'data_query', 'left wp100'); draw_edit_form(array( "config" => array(), "fields" => inject_form_variables(data_query_form_list(), (isset($snmp_query) ? $snmp_query : array())) )); print "</table></td></tr>"; /* end of html_header */ html_end_box(); if (!empty($snmp_query["id"])) { $xml_filename = str_replace("<path_cacti>", CACTI_BASE_PATH, $snmp_query["xml_path"]); if ((file_exists($xml_filename)) && (is_file($xml_filename))) { $text = "<font color='#0d7c09'><strong>" . __("Successfully located XML file") . "</strong></font>"; $xml_file_exists = true; }else{ $text = "<span class='warning'" . __("Could not locate XML file.") . "</span>"; $xml_file_exists = false; } html_start_box("", "100", "aaaaaa", "3", "center", ""); print "<tr class='textArea'><td>$text</td></tr>"; html_end_box(); if ($xml_file_exists == true) { html_start_box("<strong>" . __("Associated Graph Templates") . "</strong>", "100", $colors["header"], "0", "center", "data_queries.php?action=item_edit&snmp_query_id=" . $snmp_query["id"]); $header_items = array(__("Name"), __("Graph Template Name")); print "<tr><td>"; html_header($header_items, 2, true, 'assoc_graph_templates', 'left wp100'); $snmp_query_graphs = db_fetch_assoc("select snmp_query_graph.id, graph_templates.name as graph_template_name, snmp_query_graph.name from snmp_query_graph left join graph_templates on (snmp_query_graph.graph_template_id=graph_templates.id) where snmp_query_graph.snmp_query_id=" . $snmp_query["id"] . " order by snmp_query_graph.name"); if (sizeof($snmp_query_graphs) > 0) { foreach ($snmp_query_graphs as $snmp_query_graph) { form_alternate_row_color("id" . $snmp_query["id"] . "_" . $snmp_query_graph["id"], true); ?> <td> <strong><a href="<?php print htmlspecialchars("data_queries.php?action=item_edit&id=". $snmp_query_graph["id"] . "&snmp_query_id=" . $snmp_query["id"]);?>"><?php print $snmp_query_graph["name"];?></a></strong> </td> <td> <?php print $snmp_query_graph["graph_template_name"];?> </td> <td align="right"> <a href="<?php print htmlspecialchars("data_queries.php?action=item_remove&id=" . $snmp_query_graph["id"] . "&snmp_query_id=" . $snmp_query["id"]);?>"> <img class="buttonSmall" src="images/delete_icon.gif" alt="<?php print __("Delete");?>" align='right'> </a> </td> <?php form_end_row(); } }else{ print "<tr><td><em>" . __("No Graph Templates Defined.") . "</em></td></tr>"; } print "</table></td></tr>"; /* end of html_header */ html_end_box(); } } form_save_button_alt("path!data_queries.php"); }
function import() { global $colors, $hash_type_names; ?> <form action="templates_import.php" method="post" enctype="multipart/form-data"> <?php if ((isset($_SESSION["import_debug_info"])) && (is_array($_SESSION["import_debug_info"]))) { html_start_box("<strong>" . __("Import Results") . "</strong>", "100", "aaaaaa", "3", "center", "", true); print "<tr class='rowAlternate1'><td><p class='textArea'>" . __("Cacti has imported the following items:") . "</p>"; while (list($type, $type_array) = each($_SESSION["import_debug_info"])) { print "<p><strong>" . $hash_type_names[$type] . "</strong></p>"; while (list($index, $vals) = each($type_array)) { if ($vals["result"] == "success") { $result_text = "<span class=\"success\">" . __("[success]") . "</span>"; }else{ $result_text = "<span class=\"fail\">" . __("[fail]") . "</span>"; } if ($vals["type"] == "update") { $type_text = "<span class=\"unknown\">" . __("[update]") . "</span>"; }else{ $type_text = "<span class=\"new\">" . __("[new]") . "</span>"; } print "<span class=\"log\">$result_text " . $vals["title"] . " $type_text</span><br>\n"; $dep_text = ""; $there_are_dep_errors = false; if ((isset($vals["dep"])) && (sizeof($vals["dep"]) > 0)) { while (list($dep_hash, $dep_status) = each($vals["dep"])) { if ($dep_status == "met") { $dep_status_text = "<span class=\"dependant\">" . __("Found Dependency:") . "</span>"; }else{ $dep_status_text = "<span class=\"fail\">" . __("Unmet Dependency:") . "</span>"; $there_are_dep_errors = true; } $dep_text .= "<span class=\"log\"> + $dep_status_text " . hash_to_friendly_name($dep_hash, true) . "</span><br>\n"; } } /* only print out dependency details if they contain errors; otherwise it would get too long */ if ($there_are_dep_errors == true) { print $dep_text; } } } print "</td></tr>"; html_end_box(false); kill_session_var("import_debug_info"); } html_start_box("<strong>" . __("Import Templates") . "</strong>", "100", $colors["header"], "3", "center", ""); form_alternate_row_color("file"); ?> <td width="50%"> <font class="textEditTitle"><?php print __("Import Template from Local File");?></font><br> <?php print __("If the XML file containing template data is located on your local machine, select it here.");?> </td> <td> <input type="file" size="60" name="import_file"> </td> </tr> <?php form_alternate_row_color("text"); ?> <td width="50%"> <font class="textEditTitle"><?php print __("Import Template from Text");?></font><br> <?php print __("If you have the XML file containing template data as text, you can paste it into this box to import it.");?> </td> <td style="padding-right:10px;"> <?php form_text_area("import_text", "", "10 ", "60", "");?> </td> </tr> <?php form_alternate_row_color("rra"); ?> <td width="50%"> <font class="textEditTitle"><?php print __("Import RRA Settings");?></font><br> <?php print __("Choose whether to allow Cacti to import custom RRA settings from imported templates or whether to use the defaults for this installation.");?> </td> <td> <?php form_radio_button("import_rra", 1, 1, __("Use defaults for this installation (Recommended)"), 1); echo "<br>"; form_radio_button("import_rra", 1, 2, __("Use custom RRA settings from the template"), 1); ?> </td> </tr> <?php html_end_box(); form_hidden_box("save_component_import","1",""); form_save_button_alt("", "save", "import"); }
function item_edit() { global $colors; require_once(CACTI_BASE_PATH . "/lib/graph/graph_info.php"); /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("id")); input_validate_input_number(get_request_var_request("device_id")); input_validate_input_number(get_request_var_request("graph_template_id")); input_validate_input_number(get_request_var_request("local_graph_id")); input_validate_input_number(get_request_var_request("device_id")); input_validate_input_number(get_request_var_request("data_template_id")); /* ==================================================== */ /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("local_graph_id", "sess_local_graph_id", ""); load_current_session_value("device_id", "sess_ds_device_id", "-1"); load_current_session_value("data_template_id", "sess_data_template_id", "-1"); $id = (!empty($_REQUEST["id"]) ? "&id=" . get_request_var_request("id") : ""); $device = db_fetch_row("select hostname from device where id=" . get_request_var_request("device_id")); html_start_box("<strong>" . __("Data Sources") . "</strong> " . __("[device: ") . (empty($device["hostname"]) ? __("No Host") : $device["hostname"]) . "]", "100", $colors["header"], "3", "center", ""); ?> <tr> <td> <form name="form_graph_items"> <table cellpadding="0" cellspacing="0"> <tr> <td class="nw50"> <?php print __("Host");?>: </td> <td> <select name="cbo_device_id" onChange="window.location=document.form_graph_items.cbo_device_id.options[document.form_graph_items.cbo_device_id.selectedIndex].value"> <option value="<?php print htmlspecialchars("graphs_items.php?action=item_edit" . $id . "&local_graph_id=" . get_request_var_request("local_graph_id") . "&device_id=-1&data_template_id=" . get_request_var_request("data_template_id"));?>"<?php if (get_request_var_request("device_id") == "-1") {?> selected<?php }?>>Any</option> <option value="<?php print htmlspecialchars("graphs_items.php?action=item_edit" . $id . "&local_graph_id=" . get_request_var_request("local_graph_id") . "&device_id=0&data_template_id=" . get_request_var_request("data_template_id"));?>"<?php if (get_request_var_request("device_id") == "0") {?> selected<?php }?>>None</option> <?php $devices = db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from device order by description,hostname"); if (sizeof($devices) > 0) { foreach ($devices as $device) { print "<option value='" . htmlspecialchars("graphs_items.php?action=item_edit" . $id . "&local_graph_id=" . get_request_var_request("local_graph_id") . "&device_id=" . $device["id"] . "&data_template_id=" . get_request_var_request("data_template_id")) . "'"; if (get_request_var_request("device_id") == $device["id"]) { print " selected"; } print ">" . $device["name"] . "</option>\n"; } } ?> </select> </td> </tr> <tr> <td class="nw100"> <?php print __("Data Source Template:");?> </td> <td> <select name="cbo_data_template_id" onChange="window.location=document.form_graph_items.cbo_data_template_id.options[document.form_graph_items.cbo_data_template_id.selectedIndex].value"> <option value="graphs_items.php?action=item_edit<?php print $id; ?>&local_graph_id=<?php print get_request_var_request("local_graph_id");?>&data_template_id=-1&device_id=<?php print get_request_var_request("device_id");?>"<?php if (get_request_var_request("data_template_id") == "-1") {?> selected<?php }?>>Any</option> <option value="graphs_items.php?action=item_edit<?php print $id; ?>&local_graph_id=<?php print get_request_var_request("local_graph_id");?>&data_template_id=0&device_id=<?php print get_request_var_request("device_id");?>"<?php if (get_request_var_request("data_template_id") == "0") {?> selected<?php }?>>None</option> <?php $data_templates = db_fetch_assoc("select id, name from data_template order by name"); if (sizeof($data_templates) > 0) { foreach ($data_templates as $data_template) { print "<option value='graphs_items.php?action=item_edit" . $id . "&local_graph_id=" . get_request_var_request("local_graph_id") . "&data_template_id=" . $data_template["id"]. "&device_id=" . get_request_var_request("device_id") . "'"; if (get_request_var_request("data_template_id") == $data_template["id"]) { print " selected"; } print ">" . $data_template["name"] . "</option>\n"; } } ?> </select> </td> </tr> </table> </form> </td> </tr> <?php html_end_box(); if (get_request_var_request("device_id") == "-1") { $sql_where = ""; }elseif (get_request_var_request("device_id") == "0") { $sql_where = " data_local.device_id=0 and "; }elseif (!empty($_REQUEST["device_id"])) { $sql_where = " data_local.device_id=" . get_request_var_request("device_id") . " and "; } if (get_request_var_request("data_template_id") == "-1") { $sql_where .= ""; }elseif (get_request_var_request("data_template_id") == "0") { $sql_where .= " data_local.data_template_id=0 and "; }elseif (!empty($_REQUEST["data_template_id"])) { $sql_where .= " data_local.data_template_id=" . get_request_var_request("data_template_id") . " and "; } if (!empty($_REQUEST["id"])) { $template_item = db_fetch_row("select * from graph_templates_item where id=" . get_request_var_request("id")); $device_id = db_fetch_cell("select device_id from graph_local where id=" . get_request_var_request("local_graph_id")); } /* by default, select the LAST DS chosen to make everyone's lives easier */ $struct_graph_item = graph_item_form_list(); if (!empty($_REQUEST["local_graph_id"])) { $default = db_fetch_row("select task_item_id from graph_templates_item where local_graph_id=" . get_request_var_request("local_graph_id") . " order by sequence DESC"); if (sizeof($default) > 0) { $struct_graph_item["task_item_id"]["default"] = $default["task_item_id"]; }else{ $struct_graph_item["task_item_id"]["default"] = 0; } /* modifications to the default graph items array */ $struct_graph_item["task_item_id"]["sql"] = "select CONCAT_WS('',data_template_data.name_cache,' (',data_template_rrd.data_source_name,')') as name, data_template_rrd.id from (data_template_data,data_template_rrd,data_local) left join device on (data_local.device_id=device.id) where data_template_rrd.local_data_id=data_local.id and data_template_data.local_data_id=data_local.id "; /* Make sure we don't limit the list so that the selected DS isn't in the list in edit mode */ if (strlen($sql_where) > 0) { $sql_where = substr($sql_where,0,-5); if (!empty($_REQUEST["id"])) { $struct_graph_item["task_item_id"]["sql"] .= " and ((" . $sql_where . ") or (data_template_rrd.id = " . $template_item["task_item_id"] . "))"; } else { $struct_graph_item["task_item_id"]["sql"] .= " and (" . $sql_where . ")"; } } $struct_graph_item["task_item_id"]["sql"] .= " order by name"; } $form_array = array(); while (list($field_name, $field_array) = each($struct_graph_item)) { $form_array += array($field_name => $struct_graph_item[$field_name]); $form_array[$field_name]["value"] = (isset($template_item) ? $template_item[$field_name] : ""); $form_array[$field_name]["form_id"] = (isset($template_item) ? $template_item["id"] : "0"); } if (!empty($_GET["local_graph_id"])) { $header_label = __("[edit: ") . db_fetch_cell("select title_cache from graph_templates_graph where local_graph_id=" . get_request_var_request("local_graph_id")) . "]"; }else{ $header_label = __("[new]"); } print "<form method='post' action='" . basename($_SERVER["PHP_SELF"]) . "' name='graph_item_edit'>\n"; html_start_box("<strong>" . __("Graph Items") . "</strong> $header_label", "100", $colors["header"], 0, "center", "", true); $header_items = array(__("Field"), __("Value")); print "<tr><td>"; html_header($header_items, 2, true, 'header_graph_item_edit'); draw_edit_form( array( "config" => array("no_form_tag" => true), "fields" => $form_array ) ); form_hidden_box("local_graph_id", get_request_var_request("local_graph_id"), "0"); form_hidden_box("graph_template_item_id", (isset($template_item) ? $template_item["id"] : "0"), ""); form_hidden_box("local_graph_template_item_id", (isset($template_item) ? $template_item["local_graph_template_item_id"] : "0"), ""); form_hidden_box("graph_template_id", (isset($template_item) ? $template_item["graph_template_id"] : "0"), ""); # form_hidden_box("sequence", (isset($template_item) ? $template_item["sequence"] : "0"), ""); # form_hidden_box("_graph_type_id", (isset($template_item) ? $template_item["graph_type_id"] : "0"), ""); # form_hidden_box("hidden_task_item_id", (isset($template_item) ? $template_item["task_item_id"] : "0"), ""); form_hidden_box("save_component_item", "1", ""); form_hidden_box("hidden_rrdtool_version", read_config_option("rrdtool_version"), ""); print "</table></td></tr>"; /* end of html_header */ html_end_box(); form_save_button_alt("path!graphs.php|action!graph_edit|id!" . get_request_var_request("local_graph_id")); include_once(CACTI_BASE_PATH . "/access/js/graph_item_dependencies.js"); # this one modifies attr("disabled") include_once(CACTI_BASE_PATH . "/access/js/line_width.js"); include_once(CACTI_BASE_PATH . "/access/js/rrdtool_version.js"); # this one sets attr("disabled) and comes last! }
function color_edit() { global $colors; require_once(CACTI_BASE_PATH . "/lib/presets/preset_color_info.php"); /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ if (!empty($_GET["id"])) { $color = db_fetch_row("select * from colors where id=" . $_GET["id"]); $header_label = __("[edit: ") . $color["hex"] . "]"; }else{ $header_label = __("[new]"); } print "<form method='post' action='" . basename($_SERVER["PHP_SELF"]) . "' name='color_edit'>\n"; html_start_box("<strong>" . __("Colors") . "</strong> $header_label", "100", $colors["header"], 0, "center", ""); $header_items = array(__("Field"), __("Value")); print "<tr><td>"; html_header($header_items, 2, false, 'header_color_edit','left wp60'); draw_edit_form(array( "config" => array(), "fields" => inject_form_variables(preset_color_form_list(), (isset($color) ? $color : array())) )); print "</table></td></tr>"; /* end of html_header */ html_end_box(); include_once(CACTI_BASE_PATH . "/access/js/colorpicker.js"); form_save_button_alt(); }
function graphs_new() { global $colors; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("device_id")); input_validate_input_number(get_request_var_request("graph_type")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { if (!substr_count($_SERVER["REQUEST_URI"], "/devices.php")) { kill_session_var("sess_graphs_new_device_id"); } kill_session_var("sess_graphs_new_graph_type"); kill_session_var("sess_graphs_new_filter"); if (!substr_count($_SERVER["REQUEST_URI"], "/devices.php")) { unset($_REQUEST["device_id"]); } unset($_REQUEST["graph_type"]); unset($_REQUEST["filter"]); $changed = true; }else{ /* if any of the settings changed, reset the page number */ $changed = 0; $changed += check_changed("device_id", "sess_graphs_new_device_id"); $changed += check_changed("graph_type", "sess_graphs_new_graph_type"); $changed += check_changed("filter", "sess_graphs_new_filter"); } load_current_session_value("device_id", "sess_graphs_new_device_id", db_fetch_cell("select id from device order by description,hostname limit 1")); load_current_session_value("graph_type", "sess_graphs_new_graph_type", read_config_option("default_graphs_new_dropdown")); load_current_session_value("filter", "sess_graphs_new_filter", ""); if (substr_count($_SERVER["REQUEST_URI"], "/devices.php")) { $file = "devices.php?action=edit&tab=newgraphs&id=" . $_REQUEST["device_id"]; $file2 = "devices.php"; }else{ $file = "graphs_new.php?device_id=". $_REQUEST["device_id"]; $file2 = "graphs_new.php"; } $device = db_fetch_row("select id,description,hostname,device_template_id from device where id=" . $_REQUEST["device_id"]); $row_limit = read_config_option("num_rows_data_query"); $debug_log = debug_log_return("new_graphs"); ?> <script type="text/javascript"> <!-- function applyGraphsNewFilterChange(objForm) { strURL = '?action=edit&tab=newgraphs'; strURL = strURL + '&graph_type=' + objForm.graph_type.value; strURL = strURL + '&device_id=' + objForm.device_id.value; strURL = strURL + '&filter=' + objForm.filter.value;; document.location = strURL; } --> </script> <?php html_start_box("<strong>" . $device["description"] . "(" . $device["hostname"] . ")</strong> " . db_fetch_cell("select name from device_template where id=" . $device["device_template_id"]), "100", $colors["header"], "3", "center", ""); ?> <tr class='rowAlternate2'> <td> <form name="form_graphs_new" method="post" action="<?php print $file2;?>"> <table cellpadding="0" align="left"> <tr> <?php if (!isset($_REQUEST["tab"])) { ?> <td class="nw50 textGraphFilter"> Host: </td> <td width="1"> <select name="device_id" onChange="applyGraphsNewFilterChange(document.form_graphs_new)"> <?php $devices = db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from device order by description,hostname"); if (sizeof($devices) > 0) { foreach ($devices as $item) { print "<option value='" . $item["id"] . "'"; if (get_request_var_request("device_id") == $item["id"]) { print " selected"; } print ">" . $item["name"] . "</option>\n"; } } ?> </select> </td> <?php } ?> <td class="nw50 textGraphFilter"> <?php print __("Type:");?> </td> <td width="1"> <select name="graph_type" onChange="applyGraphsNewFilterChange(document.form_graphs_new)"> <option value="-2"<?php if (get_request_var_request("graph_type") == "-2") {?> selected<?php }?>><?php print __("All");?></option> <option value="-1"<?php if (get_request_var_request("graph_type") == "-1") {?> selected<?php }?>><?php print __("Graph Template Based");?></option> <?php $snmp_queries = db_fetch_assoc("SELECT snmp_query.id, snmp_query.name, snmp_query.xml_path FROM (snmp_query,device_snmp_query) WHERE device_snmp_query.snmp_query_id=snmp_query.id AND device_snmp_query.device_id=" . $device["id"] . " ORDER BY snmp_query.name"); if (sizeof($snmp_queries) > 0) { foreach ($snmp_queries as $query) { print "<option value='" . $query["id"] . "'"; if (get_request_var_request("graph_type") == $query["id"]) { print " selected"; } print ">" . $query["name"] . "</option>\n"; } } ?> </select> </td> <td style="white-space:nowrap;width:1%;" class="textInfo" align="center" valign="top"> <?php if (!isset($_REQUEST["tab"])) { ?><span class="tabedit">*</span><a href="devices.php?action=edit&id=<?php print $_REQUEST["device_id"];?>"><?php print __("Edit this Host");?></a><br><?php } ?> <?php api_plugin_hook('graphs_new_top_links'); ?> </td> </tr> </table> <?php if (get_request_var_request("graph_type") > 0) {?> <table cellpadding="0" align="left"> <tr> <td class="nw50 textGraphFilter"> Search: </td> <td class="nw200"> <input type="text" name="filter" size="30" width="200" value="<?php print $_REQUEST["filter"];?>"> </td> <td align="left" class="nw120"> <input type="submit" name="go" value="<?php print __("Go");?>" align="middle"> <input type="submit" name="clear_x" value="<?php print __("Clear");?>" align="middle"> <input type="hidden" name="action" value="edit"> <input type="hidden" name="tab" value="newgraphs"> </td> </tr> </table> <?php }else{ form_hidden_box("filter", get_request_var_request("filter"), ""); }?> </form> </td> </tr> <?php html_end_box(false); $total_rows = sizeof(db_fetch_assoc("select graph_template_id from device_graph where device_id=" . $_REQUEST["device_id"])); $i = 0; if (get_request_var_request("graph_type") > 0) { load_current_session_value("page" . get_request_var_request("graph_type"), "sess_graphs_new_page" . get_request_var_request("graph_type"), "1"); }else if (get_request_var_request("graph_type") == -2) { foreach($snmp_queries as $query) { load_current_session_value("page" . $query["id"], "sess_graphs_new_page" . $query["id"], "1"); } } print "<form name='chk' method='post' action='" . $file2 . "'>"; if (get_request_var_request("graph_type") < 0) { $graph_templates = db_fetch_assoc("SELECT graph_templates.id AS graph_template_id, graph_templates.name AS graph_template_name FROM (device_graph,graph_templates) WHERE device_graph.graph_template_id=graph_templates.id AND device_graph.device_id=" . $_REQUEST["device_id"] . " ORDER BY graph_templates.name"); $template_graphs = db_fetch_assoc("SELECT graph_local.graph_template_id FROM (graph_local,device_graph) WHERE graph_local.graph_template_id=device_graph.graph_template_id AND graph_local.device_id=device_graph.device_id AND graph_local.device_id=" . $device["id"] . " GROUP BY graph_local.graph_template_id"); if (sizeof($template_graphs) > 0) { print "<script type='text/javascript'>\n<!--\n"; print "var gt_created_graphs = new Array("; $cg_ctr = 0; foreach ($template_graphs as $template_graph) { print (($cg_ctr > 0) ? "," : "") . "'" . $template_graph["graph_template_id"] . "'"; $cg_ctr++; } print ")\n"; print "//-->\n</script>\n"; } else { print "<script type='text/javascript'>\nvar gt_created_graphs = new Array()\n</script>\n"; } print "<script type='text/javascript'>gt_update_deps(1);</script>\n"; print "<script type='text/javascript'>\nvar created_graphs = new Array()\n</script>\n"; html_start_box("<strong>" . __("Graph Templates") . "</strong>", "100", $colors["header"], "3", "center", ""); print " <tr class='rowSubHeader'> <td class='textSubHeaderDark'>" . __("Graph Template Name") . "</td> <td class='rowSubHeader' width='1%' align='center' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_cg' title='" . __("Select All") . "' onClick='SelectAll(\"cg\",this.checked);gt_update_selection_indicators();'></td>\n </tr>\n"; /* create a row for each graph template associated with the device template */ if (sizeof($graph_templates) > 0) { foreach ($graph_templates as $graph_template) { $query_row = $graph_template["graph_template_id"]; print "<tr id='gt_line$query_row' bgcolor='#" . (($i % 2 == 0) ? "ffffff" : $colors["light"]) . "'>"; $i++; print " <td onClick='gt_select_line(" . $graph_template["graph_template_id"] . ");'><span id='gt_text$query_row" . "_0'> <strong>" . __("Create:") . "</strong> " . $graph_template["graph_template_name"] . "</span> </td> <td align='right'> <input type='checkbox' name='cg_$query_row' id='cg_$query_row' onClick='gt_update_selection_indicators();'> </td> </tr>"; } } $available_graph_templates = db_fetch_assoc("SELECT graph_templates.id, graph_templates.name FROM snmp_query_graph RIGHT JOIN graph_templates ON (snmp_query_graph.graph_template_id = graph_templates.id) WHERE (((snmp_query_graph.name) Is Null)) ORDER BY graph_templates.name"); /* create a row at the bottom that lets the user create any graph they choose */ print " <tr bgcolor='#" . (($i % 2 == 0) ? "ffffff" : $colors["light"]) . "'> <td colspan='2' width='60' nowrap> <strong>" . __("Create:") . "</strong> "; form_dropdown("cg_g", $available_graph_templates, "name", "id", "", "(Select a graph type to create)", "", "textArea"); print " </td> </tr>"; html_end_box(); } if ($_REQUEST["graph_type"] != -1) { $snmp_queries = db_fetch_assoc("SELECT snmp_query.id, snmp_query.name, snmp_query.xml_path FROM (snmp_query,device_snmp_query) WHERE device_snmp_query.snmp_query_id=snmp_query.id AND device_snmp_query.device_id=" . $device["id"] . ($_REQUEST["graph_type"] != -2 ? " AND snmp_query.id=" . $_REQUEST["graph_type"] : '') . " ORDER BY snmp_query.name"); if (sizeof($snmp_queries) > 0) { foreach ($snmp_queries as $snmp_query) { unset($total_rows); if (isset($_REQUEST["page" . $snmp_query["id"]])) { $page = $_REQUEST["page" . $snmp_query["id"]]; }elseif (!$changed) { $page = $_REQUEST["page" . $snmp_query["id"]]; }else{ $page = 1; } $xml_array = get_data_query_array($snmp_query["id"]); $num_input_fields = 0; $num_visible_fields = 0; if ($xml_array != false) { /* loop through once so we can find out how many input fields there are */ reset($xml_array["fields"]); while (list($field_name, $field_array) = each($xml_array["fields"])) { if ($field_array["direction"] == "input") { $num_input_fields++; if (!isset($total_rows)) { $total_rows = db_fetch_cell("SELECT count(*) FROM device_snmp_cache WHERE device_id=" . $device["id"] . " and snmp_query_id=" . $snmp_query["id"] . " AND field_name='$field_name'"); } } } } if (!isset($total_rows)) { $total_rows = 0; } $snmp_query_graphs = db_fetch_assoc("SELECT snmp_query_graph.id,snmp_query_graph.name FROM snmp_query_graph WHERE snmp_query_graph.snmp_query_id=" . $snmp_query["id"] . " ORDER BY snmp_query_graph.name"); if (sizeof($snmp_query_graphs) > 0) { print "<script type='text/javascript'>\n<!--\n"; foreach ($snmp_query_graphs as $snmp_query_graph) { $created_graphs = db_fetch_assoc("SELECT DISTINCT data_local.snmp_index FROM (data_local,data_template_data) LEFT JOIN data_input_data ON (data_template_data.id=data_input_data.data_template_data_id) LEFT JOIN data_input_fields ON (data_input_data.data_input_field_id=data_input_fields.id) WHERE data_local.id=data_template_data.local_data_id AND data_input_fields.type_code='output_type' AND data_input_data.value='" . $snmp_query_graph["id"] . "' AND data_local.device_id=" . $device["id"]); print "created_graphs[" . $snmp_query_graph["id"] . "] = new Array("; $cg_ctr = 0; if (sizeof($created_graphs) > 0) { foreach ($created_graphs as $created_graph) { print (($cg_ctr > 0) ? "," : "") . "'" . encode_data_query_index($created_graph["snmp_index"]) . "'"; $cg_ctr++; } } print ")\n"; } print "//-->\n</script>\n"; } html_start_box_dq($snmp_query["name"], $snmp_query["id"], $device["id"], $num_input_fields+1, "100", $colors["header"], "0", "center"); if ($xml_array != false) { $html_dq_header = ""; $snmp_query_indexes = array(); reset($xml_array["fields"]); /* if there is a where clause, get the matching snmp_indexes */ $sql_where = ""; if (strlen(get_request_var_request("filter"))) { $sql_where = ""; $indexes = db_fetch_assoc("SELECT DISTINCT snmp_index FROM device_snmp_cache WHERE field_value LIKE '%%" . get_request_var_request("filter") . "%%' AND snmp_query_id=" . $snmp_query["id"] . " AND device_id=" . $device["id"]); if (sizeof($indexes)) { foreach($indexes as $index) { if (strlen($sql_where)) { $sql_where .= ", '" . $index["snmp_index"] . "'"; }else{ $sql_where .= " AND snmp_index IN('" . $index["snmp_index"] . "'"; } } $sql_where .= ")"; } } if ((strlen(get_request_var_request("filter")) == 0) || ((strlen(get_request_var_request("filter"))) && (sizeof($indexes)))) { /* determine the sort order */ if (isset($xml_array["index_order_type"])) { if ($xml_array["index_order_type"] == "numeric") { $sql_order = "ORDER BY CAST(snmp_index AS unsigned)"; }else if ($xml_array["index_order_type"] == "alphabetic") { $sql_order = "ORDER BY snmp_index"; }else if ($xml_array["index_order_type"] == "natural") { $sql_order = "ORDER BY INET_ATON(snmp_index)"; }else{ $sql_order = ""; } }else{ $sql_order = ""; } /* get the unique field values from the database */ $field_names = db_fetch_assoc("SELECT DISTINCT field_name FROM device_snmp_cache WHERE device_id=" . $device["id"] . " AND snmp_query_id=" . $snmp_query["id"]); /* build magic query */ $sql_query = "SELECT device_id, snmp_query_id, snmp_index"; $num_visible_fields = sizeof($field_names); $i = 0; if (sizeof($field_names) > 0) { foreach($field_names as $column) { $field_name = $column["field_name"]; $sql_query .= ", MAX(CASE WHEN field_name='$field_name' THEN field_value ELSE NULL END) AS '$field_name'"; $i++; } } $sql_query .= " FROM device_snmp_cache WHERE device_id=" . $device["id"] . " AND snmp_query_id=" . $snmp_query["id"] . " $sql_where GROUP BY device_id, snmp_query_id, snmp_index $sql_order LIMIT " . ($row_limit*($page-1)) . "," . $row_limit; $rows_query = "SELECT device_id, snmp_query_id, snmp_index FROM device_snmp_cache WHERE device_id=" . $device["id"] . " AND snmp_query_id=" . $snmp_query["id"] . " $sql_where GROUP BY device_id, snmp_query_id, snmp_index"; $snmp_query_indexes = db_fetch_assoc($sql_query); $total_rows = sizeof(db_fetch_assoc($rows_query)); if (($page-1) * $row_limit > $total_rows) { $page = 1; $_REQUEST["page" . $query["id"]] = $page; load_current_session_value("page" . $query["id"], "sess_graphs_new_page" . $query["id"], "1"); } if (substr_count($_SERVER["REQUEST_URI"], "/devices.php")) { $file = "devices.php?action=edit&tab=newgraphs&id=" . $_REQUEST["device_id"]; $file2 = "devices.php"; }else{ $file = "graphs_new.php?device_id=". $_REQUEST["device_id"]; $file2 = "graphs_new.php"; } if ($total_rows > $row_limit) { /* generate page list navigation */ $nav = html_create_nav($page, MAX_DISPLAY_PAGES, $row_limit, $total_rows, 40, $file, "page" . $snmp_query["id"]); print $nav; } while (list($field_name, $field_array) = each($xml_array["fields"])) { if ($field_array["direction"] == "input") { foreach($field_names as $row) { if ($row["field_name"] == $field_name) { # $html_dq_header .= "<td height='1' style='padding:0px 5px 0px 5px;' onMousemove='doColResize(this,event)' onMouseover='doColResize(this,event)' onMouseup='doneColResize()'><strong><font color='#" . $colors["header_text"] . "'>" . $field_array["name"] . "</font></strong></td>\n"; $html_dq_header .= "<th style='padding:0px 5px 0px 5px;' onMousemove='doColResize(this,event)' onMouseover='doColResize(this,event)' onMouseup='doneColResize()' class='textSubHeaderDark'><strong><font color='#" . $colors["header_text"] . "'>" . $field_array["name"] . "</font></strong></th>\n"; break; } } } } if (!sizeof($snmp_query_indexes)) { print "<tr class='rowAlternate1'><td>" . __("This data query returned 0 rows, perhaps there was a problem executing this data query. You can %s run this data query in debug mode %s to get more information.", "<a href='" . htmlspecialchars("devices.php?action=query_verbose&id=" . $snmp_query["id"] . "&device_id=" . $device["id"]) . "'>", "</a>") . "</td></tr>\n"; }else{ print "<tr class='rowSubHeader'> $html_dq_header <td class='rowSubHeader' width='1%' align='center' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_" . $snmp_query["id"] . "' title='" . __("Select All") ."' onClick='SelectAll(\"sg_" . $snmp_query["id"] . "\",this.checked);dq_update_selection_indicators();'></td>\n </tr>\n"; } $row_counter = 0; $column_counter = 0; $fields = array_rekey($field_names, "field_name", "field_name"); if (sizeof($snmp_query_indexes) > 0) { foreach($snmp_query_indexes as $row) { $query_row = $snmp_query["id"] . "_" . encode_data_query_index($row["snmp_index"]); form_alternate_row_color("line" . $query_row, true); $column_counter = 0; reset($xml_array["fields"]); while (list($field_name, $field_array) = each($xml_array["fields"])) { if ($field_array["direction"] == "input") { if (in_array($field_name, $fields)) { if (isset($row[$field_name])) { print "<td style='line-height: 1.5em;padding:0px 5px 0px 5px;' onClick='dq_select_line(" . $snmp_query["id"] . ",\"" . encode_data_query_index($row["snmp_index"]) . "\");'><span id='text$query_row" . "_" . $column_counter . "'>" . (strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span class=\"filter\">\\1</span>", $row[$field_name]) : $row[$field_name]) . "</span></td>"; }else{ print "<td style='line-height: 1.5em;padding:0px 5px 0px 5px;' onClick='dq_select_line(" . $snmp_query["id"] . ",\"" . encode_data_query_index($row["snmp_index"]) . "\");'><span id='text$query_row" . "_" . $column_counter . "'></span></td>"; } $column_counter++; } } } print "<td style='padding-right: 4px;' align='right'>"; print "<input type='checkbox' name='sg_$query_row' id='sg_$query_row' onClick='dq_update_selection_indicators();'>"; print "</td>"; print "</tr>\n"; $row_counter++; } } if ($total_rows > $row_limit) { print $nav; } }else{ print "<tr class='rowAlternate1'><td colspan='2' style='color: red; font-size: 12px; font-weight: bold;'>" . __("Search Returned no Rows.") . "</td></tr>\n"; } }else{ print "<tr class='rowAlternate1'><td colspan='2' style='color: red; font-size: 12px; font-weight: bold;'>" . __("Error in data query.") . "</td></tr>\n"; } /* draw the graph template drop down here */ $data_query_graphs = db_fetch_assoc("select snmp_query_graph.id,snmp_query_graph.name from snmp_query_graph where snmp_query_graph.snmp_query_id=" . $snmp_query["id"] . " order by snmp_query_graph.name"); if (sizeof($data_query_graphs) == 1) { html_end_box(); form_hidden_box("sgg_" . $snmp_query["id"], $data_query_graphs[0]["id"], ""); }elseif (sizeof($data_query_graphs) > 1) { html_end_box(FALSE); print "<table align='center' width='100%'> <tr> <td width='1' valign='top'> <img src='images/arrow.gif' alt='' align='middle'> </td> <td align='right'> <span class=\"italic\">" . __("Select a graph type:") . "</span> <select name='sgg_" . $snmp_query["id"] . "' id='sgg_" . $snmp_query["id"] . "' onChange='dq_update_deps(" . $snmp_query["id"] . "," . $column_counter . ");'> "; html_create_list($data_query_graphs,"name","id","0"); print " </select> </td> </tr> </table>"; } print "<script type='text/javascript'>dq_update_deps(" . $snmp_query["id"] . "," . ($num_visible_fields) . ");</script>\n"; } } } form_hidden_box("save_component_graph", "1", ""); form_hidden_box("device_id", $device["id"], "0"); form_hidden_box("device_template_id", $device["device_template_id"], "0"); form_save_button_alt("url!" . (isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : "")); if (!empty($debug_log)) { debug_log_clear("new_graphs"); ?> <table class='topBoxAlt'> <tr> <td class='mono'> <?php print $debug_log;?> </td> </tr> </table> <br> <?php } print "<script type='text/javascript'>dq_update_selection_indicators();</script>\n"; print "<script type='text/javascript'>gt_update_selection_indicators();</script>\n"; }
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(); }
/** * data_sources_item_edit - edit a data template item (aka data source in rrdtool lingo) */ function data_sources_item_edit() { global $colors; require_once(CACTI_BASE_PATH . "/lib/data_source/data_source_info.php"); /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); input_validate_input_number(get_request_var("local_data_id")); /* ==================================================== */ if (!empty($_GET["id"])) { $data_source = db_fetch_row("SELECT * FROM data_template_data WHERE local_data_id=" . $_GET["local_data_id"]); $item = db_fetch_row("SELECT * FROM data_template_rrd WHERE id=" . $_GET["id"]); $header_label = __("[edit: ") . $item["data_source_name"] . "]"; }else{ $data_source = array(); $item = array(); $header_label = __("[new]"); } # the template header html_start_box("<strong>" . __("Data Source Item") . "</strong> $header_label", "100", $colors["header"], 0, "center", "", true); $header_items = array(__("Field"), __("Value")); print "<tr><td>"; html_header($header_items, 2, true, 'header_data_sources_item_edit'); /* data input fields list */ $struct_data_source_item = data_source_item_form_list(); if ((empty($data_source["data_input_id"])) || ((db_fetch_cell("select type_id from data_input where id=" . $data_source["data_input_id"]) != "1") && (db_fetch_cell("select type_id from data_input where id=" . $data_source["data_input_id"]) != "5"))) { unset($struct_data_source_item["data_input_field_id"]); }else{ $struct_data_source_item["data_input_field_id"]["sql"] = "select id,CONCAT(data_name,' - ',name) as name from data_input_fields where data_input_id=" . $data_source["data_input_id"] . " and input_output='out' and update_rra='on' order by data_name,name"; } $form_array = array(); while (list($field_name, $field_array) = each($struct_data_source_item)) { $form_array += array($field_name => $struct_data_source_item[$field_name]); $form_array[$field_name]["description"] = ""; $form_array[$field_name]["value"] = (isset($item[$field_name]) ? $item[$field_name] : ""); $form_array[$field_name]["sub_checkbox"] = array( "name" => "t_" . $field_name, "friendly_name" => "Use Per-Data Source Value (Ignore this Value)", "value" => (isset($item[$field_name]) ? $item{"t_" . $field_name} : "") ); } draw_edit_form( array( "config" => array(), "fields" => $form_array ) ); html_end_box(); form_hidden_box("data_source_item_id", (isset($item["id"]) ? $item["id"] : "0"), ""); form_hidden_box("local_data_id", (isset($_GET["local_data_id"]) ? $_GET["local_data_id"] : "0"), ""); form_hidden_box("save_component_item", "1", ""); form_hidden_box("hidden_rrdtool_version", read_config_option("rrdtool_version"), ""); #form_save_button("data_sourcess.php?action=template_edit&id=" . $_GET["id"]); form_save_button_alt("url!" . (isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : "")); include_once(CACTI_BASE_PATH . "/access/js/data_source_item.js"); include_once(CACTI_BASE_PATH . "/access/js/field_description_hover.js"); }
function poller_edit() { global $colors; require_once(CACTI_BASE_PATH . "/lib/poller/poller_info.php"); /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ /* remember if there's something we want to show to the user */ $debug_log = debug_log_return("poller"); if (!empty($debug_log)) { debug_log_clear("poller"); ?> <table class='topBoxAlt'> <tr bgcolor="<?php print $colors["light"];?>"> <td class='mono'> <?php print $debug_log;?> </td> </tr> </table> <br> <?php } if (!empty($_GET["id"])) { $poller = db_fetch_row("select * from poller where id=" . $_GET["id"]); $header_label = __("[edit: ") . $poller["description"] . "]"; }else{ $header_label = __("[new]"); $_GET["id"] = 0; } print "<form method='post' action='" . basename($_SERVER["PHP_SELF"]) . "' name='poller_edit'>\n"; html_start_box("<strong>" . __("Pollers") . "</strong> $header_label", "100", $colors["header"], 0, "center", "", true); $header_items = array(__("Field"), __("Value")); print "<tr><td>"; html_header($header_items, 1, true, 'poller_edit'); draw_edit_form(array( "config" => array(), "fields" => inject_form_variables(poller_form_list(), (isset($poller) ? $poller : array())) )); print "</table></td></tr>"; /* end of html_header */ html_end_box(); form_save_button_alt(); }
function device_template_display_general($device_template, $header_label) { global $colors; require(CACTI_BASE_PATH . "/include/data_query/data_query_arrays.php"); require_once(CACTI_BASE_PATH . "/lib/device_template/device_template_info.php"); print "<form method='post' action='" . basename($_SERVER["PHP_SELF"]) . "' name='device_template_edit'>\n"; html_start_box("<strong>" . __("Device Templates") . "</strong> $header_label", "100", $colors["header"], "0", "center", "", true); $header_items = array(__("Field"), __("Value")); print "<tr><td>"; html_header($header_items, 1, true, 'device_template'); draw_edit_form(array( "config" => array("no_form_tag" => true), "fields" => inject_form_variables(device_template_form_list(), (isset($device_template) ? $device_template : array())) )); print "</table></td></tr>"; /* end of html_header */ html_end_box(); form_hidden_box("id", (isset($device_template["id"]) ? $device_template["id"] : "0"), ""); form_hidden_box("save_component_template", "1", ""); ?> <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; var device_threads = document.getElementById('device_threads').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; // default availability methods 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 == 4) { 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'); a.value="0"; a.text="<?php print __("None");?>"; addSelectItem(a,am); b.value="1"; b.text="<?php print __("Ping and SNMP");?>"; addSelectItem(b,am); c.value="2"; c.text="<?php print __("SNMP");?>"; addSelectItem(c,am); d.value="3"; d.text="<?php print __("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 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 toggleAvailabilityAndSnmp(show) { if (show) { $('#row_override_permitted').show(); $('#row_availability_header').show(); $('#row_availability_method').show(); $('#row_ping_method').show(); $('#row_ping_port').show(); $('#row_ping_timeout').show(); $('#row_ping_retries').show(); $('#row_snmp_spacer').show(); $('#row_snmp_version').show(); $('#row_snmp_username').show(); $('#row_snmp_password').show(); $('#row_snmp_community').show(); $('#row_snmp_auth_protocol').show(); $('#row_snmp_priv_passphrase').show(); $('#row_snmp_priv_protocol').show(); $('#row_snmp_context').show(); $('#row_snmp_port').show(); $('#row_snmp_timeout').show(); $('#row_max_oids').show(); $('#row_device_threads').show(); changeHostForm(); }else{ $('#row_override_permitted').hide(); $('#row_availability_header').hide(); $('#row_availability_method').hide(); $('#row_ping_method').hide(); $('#row_ping_port').hide(); $('#row_ping_timeout').hide(); $('#row_ping_retries').hide(); $('#row_snmp_spacer').hide(); $('#row_snmp_version').hide(); $('#row_snmp_username').hide(); $('#row_snmp_password').hide(); $('#row_snmp_community').hide(); $('#row_snmp_auth_protocol').hide(); $('#row_snmp_priv_passphrase').hide(); $('#row_snmp_priv_protocol').hide(); $('#row_snmp_context').hide(); $('#row_snmp_port').hide(); $('#row_snmp_timeout').hide() $('#row_max_oids').hide(); $('#row_device_threads').hide(); } } /* jQuery stuff */ $().ready(function() { toggleAvailabilityAndSnmp(document.getElementById('override_defaults').checked); /* Hide options when override is turned off */ $("#override_defaults").change(function () { toggleAvailabilityAndSnmp(this.checked); }); /* Hide "Uptime Goes Backwards" if snmp_version has been set to "None" */ $("#snmp_version").change(function () { /* get PHP constants into javascript namespace */ var reindex_none = <?php print DATA_QUERY_AUTOINDEX_NONE;?>; var reindex_reboot = <?php print DATA_QUERY_AUTOINDEX_BACKWARDS_UPTIME;?>; /* we require numeric values for comparison */ var current_reindex = parseInt($(this).val()); switch (current_reindex) { case reindex_none: /* now that SNMP is disabled, select reindex method "None" */ $("#reindex_method option[value=" + reindex_none + "]").attr('selected', 'true'); /* disable SNMP options: "Uptime Goes Backwards" never works with pure Script Data Queries */ $("#reindex_method option[value=" + reindex_reboot + "]").attr('disabled', 'true'); $("#reindex_method option[value=" + reindex_reboot + "]").attr('title', '<?php print __("Disabled due to SNMP settings");?>'); break; default: /* "Uptime Goes Backwards" is allowed again */ $("#reindex_method option[value=" + reindex_reboot + "]").removeAttr("disabled"); $("#reindex_method option[value=" + reindex_reboot + "]").attr('title', ''); /* select this again as default reindex method */ /* TODO: this ignores the default reindex method of the associated Device Template to get it, an AJAX call is required */ $("#reindex_method option[value=" + reindex_reboot + "]").attr('selected', 'true'); } }); }); //--> </script> <?php form_save_button_alt("url!device_templates.php"); }