示例#1
0
文件: graphs.php 项目: songchin/Cacti
function graph_edit()
{
    global $colors;
    if (!empty($_GET["id"])) {
        $graph = db_fetch_row("select * from graph where id=" . $_GET["id"]);
        if (!empty($graph["graph_template_id"])) {
            $graph_template = db_fetch_row("select * from graph_template where id=" . $graph["graph_template_id"]);
        }
        $header_label = _("[edit: ") . $graph["title_cache"] . "]";
    } else {
        $header_label = _("[new]");
    }
    /* handle debug mode */
    if (isset($_GET["debug"])) {
        if ($_GET["debug"] == "0") {
            kill_session_var("graph_debug_mode");
        } elseif ($_GET["debug"] == "1") {
            $_SESSION["graph_debug_mode"] = true;
        }
    }
    if (!empty($_GET["id"])) {
        ?>
		<table width="98%" align="center">
			<tr>
				<td class="textInfo" colspan="2" valign="top">
					<?php 
        echo $graph["title_cache"];
        ?>
				</td>
				<td class="textInfo" align="right" valign="top">
					<span style="color: #c16921;">*<a href='graphs.php?action=edit&id=<?php 
        print isset($_GET["id"]) ? $_GET["id"] : 0;
        ?>
&debug=<?php 
        print isset($_SESSION["graph_debug_mode"]) ? "0" : "1";
        ?>
'>Turn <strong><?php 
        print isset($_SESSION["graph_debug_mode"]) ? "Off" : "On";
        ?>
</strong> Graph Debug Mode.</a>
				</td>
			</tr>
		</table>
		<br>
		<?php 
    }
    /* ==================== Box: Device/Template Selection ==================== */
    $form_array = array("graph_template_id" => array("method" => "drop_sql", "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."), "value" => isset($graph) ? $graph["graph_template_id"] : "0", "none_value" => _("None"), "sql" => "select graph_template.id,graph_template.template_name as name from graph_template order by template_name"), "host_id" => array("method" => "drop_sql", "friendly_name" => _("Host"), "description" => _("Choose the host that this graph belongs to."), "value" => isset($_GET["host_id"]) ? $_GET["host_id"] : $graph["host_id"], "none_value" => _("None"), "sql" => "select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"), "id" => array("method" => "hidden", "value" => isset($graph) ? $graph["id"] : "0"));
    html_start_box("<strong>" . _("Device/Template Selection") . "</strong> {$header_label}", "98%", $colors["header_background"], "3", "center", "");
    draw_edit_form(array("config" => array(), "fields" => $form_array));
    html_end_box();
    /* ==================== Box: Supplemental Template Data ==================== */
    /* only display the "inputs" area if we are using a graph template for this graph */
    if (!empty($graph["graph_template_id"])) {
        ob_start();
        html_start_box("<strong>" . _("Supplemental Template Data") . "</strong>", "98%", $colors["header_background"], "3", "center", "");
        $num_output_fields = draw_nontemplated_fields_graph($graph["graph_template_id"], $graph, "g||field|", "<strong>" . _("Graph Fields") . "</strong>", true);
        $num_output_fields += draw_nontemplated_fields_graph_item($graph["graph_template_id"], array_rekey(db_fetch_assoc("select * from graph_item where graph_id = " . $graph["id"]), "graph_template_item_id", array("id", "data_source_item_id", "color", "graph_item_type", "cdef", "consolidation_function", "gprint_format", "legend_format", "legend_value", "hard_return")), "gip||field|||id|", "<strong>" . _("Graph Item Fields") . "</strong>", true);
        html_end_box();
        if ($num_output_fields == 0) {
            ob_end_clean();
        } else {
            ob_end_flush();
        }
    }
    /* graph item list goes here */
    if (!empty($_GET["id"]) && empty($graph["graph_template_id"])) {
        $graph_items = db_fetch_assoc("select\n\t\t\tgraph_item.id\n\t\t\tfrom graph_item\n\t\t\twhere graph_item.graph_id = " . $_GET["id"] . "\n\t\t\torder by graph_item.sequence");
        /* ==================== Box: Graph Items ==================== */
        html_start_box("<strong>" . _("Graph Items") . "</strong>", "98%", $colors["header_background"], "3", "center", "graphs_items.php?action=edit&graph_id=" . $_GET["id"]);
        draw_graph_item_editor($_GET["id"], "graph", false);
        html_end_box();
    }
    /* display sample graph, or graph source in debug mode */
    if (!empty($_GET["id"])) {
        ?>
		<table width="98%" align="center">
			<tr>
				<td align="center" class="textInfo" colspan="2">
					<img src="graph_image.php?graph_id=<?php 
        print $_GET["id"];
        ?>
&rra_id=1" alt="">
				</td>
				<?php 
        if (isset($_SESSION["graph_debug_mode"]) && isset($_GET["id"])) {
            $graph_data_array["output_flag"] = RRDTOOL_OUTPUT_STDERR;
            ?>
					<td>
						<span class="textInfo"><?php 
            echo _("RRDTool Says:");
            ?>
</span><br>
						<pre><?php 
            print rrdtool_function_graph($_GET["id"], 1, $graph_data_array);
            ?>
</pre>
					</td>
					<?php 
        }
        ?>
			</tr>
		</table>
		<br>
		<?php 
    }
    if (empty($graph["graph_template_id"]) && (isset($_GET["id"]) && is_numeric($_GET["id"]) || isset($_GET["host_id"]) && isset($_GET["graph_template_id"]))) {
        /* ==================== Box: Graph ==================== */
        html_start_box("<strong>" . _("Graph") . "</strong>", "98%", $colors["header_background"], "3", "center", "");
        field_row_header("General Options");
        _graph_field__title("g|title", false, empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__vertical_label("g|vertical_label", false, isset($graph["vertical_label"]) ? $graph["vertical_label"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__image_format("g|image_format", false, isset($graph["image_format"]) ? $graph["image_format"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__export("g|export", false, isset($graph["export"]) ? $graph["export"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__force_rules_legend("g|force_rules_legend", false, isset($graph["force_rules_legend"]) ? $graph["force_rules_legend"] : "");
        field_row_header("Image Size Options");
        _graph_field__height("g|height", false, isset($graph["height"]) ? $graph["height"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__width("g|width", false, isset($graph["width"]) ? $graph["width"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        field_row_header("Grid Options");
        _graph_field__x_grid("g|x_grid", false, isset($graph["x_grid"]) ? $graph["x_grid"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__y_grid("g|y_grid", false, isset($graph["y_grid"]) ? $graph["y_grid"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__y_grid_alt("g|y_grid_alt", false, isset($graph["y_grid_alt"]) ? $graph["y_grid_alt"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__no_minor("g|no_minor", false, isset($graph["no_minor"]) ? $graph["no_minor"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        field_row_header("Auto Scaling Options");
        _graph_field__auto_scale("g|auto_scale", false, isset($graph["auto_scale"]) ? $graph["auto_scale"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__auto_scale_opts("g|auto_scale_opts", false, isset($graph["auto_scale_opts"]) ? $graph["auto_scale_opts"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__auto_scale_log("g|auto_scale_log", false, isset($graph["auto_scale_log"]) ? $graph["auto_scale_log"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__auto_scale_rigid("g|auto_scale_rigid", false, isset($graph["auto_scale_rigid"]) ? $graph["auto_scale_rigid"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        _graph_field__auto_padding("g|auto_padding", false, isset($graph["auto_padding"]) ? $graph["auto_padding"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_auto_padding");
        field_row_header("Fixed Scaling Options");
        _graph_field__upper_limit("g|upper_limit", false, isset($graph["upper_limit"]) ? $graph["upper_limit"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_upper_limit");
        _graph_field__lower_limit("g|lower_limit", false, isset($graph["lower_limit"]) ? $graph["lower_limit"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_lower_limit");
        _graph_field__base_value("g|base_value", false, isset($graph["base_value"]) ? $graph["base_value"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_base_value");
        field_row_header("Units Display Options");
        _graph_field__unit_value("g|unit_value", false, isset($graph["unit_value"]) ? $graph["unit_value"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_unit_value");
        _graph_field__unit_length("g|unit_length", false, isset($graph["unit_length"]) ? $graph["unit_length"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_unit_length");
        _graph_field__unit_exponent_value("g|unit_exponent_value", false, isset($graph["unit_exponent_value"]) ? $graph["unit_exponent_value"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
        html_end_box();
    }
    form_hidden_box("action_post", "graph_edit");
    form_save_button("graphs.php");
}
示例#2
0
文件: graphs.php 项目: songchin/Cacti
function graph_edit() {
	global $colors, $struct_graph, $image_types, $consolidation_functions, $graph_item_types, $struct_graph_item;

	/* ================= 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["id"]);

		$graphs = db_fetch_row("select * from graph_templates_graph where local_graph_id=" . $_GET["id"]);
		$graphs_template = db_fetch_row("select * from graph_templates_graph where id=$local_graph_template_graph_id");

		$host_id = db_fetch_cell("select host_id from graph_local where id=" . $_GET["id"]);
		$header_label = "[edit: " . get_graph_title($_GET["id"]) . "]";

		if ($graphs["graph_template_id"] == "0") {
			$use_graph_template = false;
		}
	}else{
		$header_label = "[new]";
		$use_graph_template = false;
	}

	/* handle debug mode */
	if (isset($_GET["debug"])) {
		if ($_GET["debug"] == "0") {
			kill_session_var("graph_debug_mode");
		}elseif ($_GET["debug"] == "1") {
			$_SESSION["graph_debug_mode"] = true;
		}
	}

	if (!empty($_GET["id"])) {
		?>
		<table width="100%" align="center">
			<tr>
				<td class="textInfo" colspan="2" valign="top">
					<?php print get_graph_title($_GET["id"]);?>
				</td>
				<td class="textInfo" align="right" valign="top">
					<span style="color: #c16921;">*<a href='graphs.php?action=graph_edit&id=<?php print (isset($_GET["id"]) ? $_GET["id"] : 0);?>&debug=<?php print (isset($_SESSION["graph_debug_mode"]) ? "0" : "1");?>'>Turn <strong><?php print (isset($_SESSION["graph_debug_mode"]) ? "Off" : "On");?></strong> Graph Debug Mode.</a><br>
					<?php
						if (!empty($graphs["graph_template_id"])) {
							?><span style="color: #c16921;">*<a href='graph_templates.php?action=template_edit&id=<?php print (isset($graphs["graph_template_id"]) ? $graphs["graph_template_id"] : "0");?>'>Edit Graph Template.</a><br><?php
						}
						if (!empty($_GET["host_id"]) || !empty($host_id)) {
							?><span style="color: #c16921;">*<a href='host.php?action=edit&id=<?php print (isset($_GET["host_id"]) ? $_GET["host_id"] : $host_id);?>'>Edit Host.</a><br><?php
						}
					?>
				</td>
			</tr>
		</table>
		<br>
		<?php
	}

	html_start_box("<strong>Graph Template Selection</strong> $header_label", "100%", $colors["header"], "3", "center", "");

	$form_array = array(
		"graph_template_id" => array(
			"method" => "drop_sql",
			"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.",
			"value" => (isset($graphs) ? $graphs["graph_template_id"] : "0"),
			"none_value" => "None",
			"sql" => "select graph_templates.id,graph_templates.name from graph_templates order by name"
			),
		"host_id" => array(
			"method" => "drop_sql",
			"friendly_name" => "Host",
			"description" => "Choose the host that this graph belongs to.",
			"value" => (isset($_GET["host_id"]) ? $_GET["host_id"] : $host_id),
			"none_value" => "None",
			"sql" => "select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"
			),
		"graph_template_graph_id" => array(
			"method" => "hidden",
			"value" => (isset($graphs) ? $graphs["id"] : "0")
			),
		"local_graph_id" => array(
			"method" => "hidden",
			"value" => (isset($graphs) ? $graphs["local_graph_id"] : "0")
			),
		"local_graph_template_graph_id" => array(
			"method" => "hidden",
			"value" => (isset($graphs) ? $graphs["local_graph_template_graph_id"] : "0")
			),
		"_graph_template_id" => array(
			"method" => "hidden",
			"value" => (isset($graphs) ? $graphs["graph_template_id"] : "0")
			),
		"_host_id" => array(
			"method" => "hidden",
			"value" => (isset($host_id) ? $host_id : "0")
			)
		);

	draw_edit_form(
		array(
			"config" => array(),
			"fields" => $form_array
			)
		);

	html_end_box();

	/* 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"], "3", "center", "");

		print "<form method='post' action='graphs.php'>\n";

		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["id"], "|field|_|id|", "<strong>Graph Item Fields</strong>", true);

		html_end_box();
	}

	/* graph item list goes here */
	if ((!empty($_GET["id"])) && (empty($graphs["graph_template_id"]))) {
		item();
	}

	if (!empty($_GET["id"])) {
		?>
		<table width="100%" align="center">
			<tr>
				<td align="center" class="textInfo" colspan="2">
					<img src="graph_image.php?action=edit&local_graph_id=<?php print $_GET["id"];?>&rra_id=<?php print read_graph_config_option("default_rra_id");?>" alt="">
				</td>
				<?php
				if ((isset($_SESSION["graph_debug_mode"])) && (isset($_GET["id"]))) {
					$graph_data_array["output_flag"] = RRDTOOL_OUTPUT_STDERR;
					$graph_data_array["print_source"] = 1;
					?>
					<td>
						<span class="textInfo">RRDTool Command:</span><br>
						<pre><?php print rrdtool_function_graph($_GET["id"], 1, $graph_data_array);?></pre>
						<span class="textInfo">RRDTool Says:</span><br>
						<?php unset($graph_data_array["print_source"]);?>
						<pre><?php print rrdtool_function_graph($_GET["id"], 1, $graph_data_array);?></pre>
					</td>
					<?php
				}
				?>
			</tr>
		</table>
		<br>
		<?php
	}

	if (((isset($_GET["id"])) || (isset($_GET["new"]))) && (empty($graphs["graph_template_id"]))) {
		html_start_box("<strong>Graph Configuration</strong>", "100%", $colors["header"], "3", "center", "");

		$form_array = array();

		while (list($field_name, $field_array) = each($struct_graph)) {
			$form_array += array($field_name => $struct_graph[$field_name]);

			$form_array[$field_name]["value"] = (isset($graphs) ? $graphs[$field_name] : "");
			$form_array[$field_name]["form_id"] = (isset($graphs) ? $graphs["id"] : "0");

			if (!(($use_graph_template == false) || ($graphs_template{"t_" . $field_name} == "on"))) {
				$form_array[$field_name]["method"] = "template_" . $form_array[$field_name]["method"];
				$form_array[$field_name]["description"] = "";
			}
		}

		draw_edit_form(
			array(
				"config" => array(
					"no_form_tag" => true
					),
				"fields" => $form_array
				)
			);

		html_end_box();
	}

	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("rrdtool_version", read_config_option("rrdtool_version"), "");
	form_save_button("graphs.php");

//Now we need some javascript to make it dynamic
?>
<script language="JavaScript">

dynamic();

function dynamic() {
	//alert("RRDTool Version is '" + document.getElementById('rrdtool_version').value + "'");
	//alert("Log is '" + document.getElementById('auto_scale_log').checked + "'");
	if (document.getElementById('scale_log_units')) {
		document.getElementById('scale_log_units').disabled=true;
		if ((document.getElementById('rrdtool_version').value != 'rrd-1.0.x') &&
			(document.getElementById('auto_scale_log').checked)) {
			document.getElementById('scale_log_units').disabled=false;
		}
	}
}

function changeScaleLog() {
	//alert("Log changed to '" + document.getElementById('auto_scale_log').checked + "'");
	if (document.getElementById('scale_log_units')) {
		document.getElementById('scale_log_units').disabled=true;
		if ((document.getElementById('rrdtool_version').value != 'rrd-1.0.x') &&
			(document.getElementById('auto_scale_log').checked)) {
			document.getElementById('scale_log_units').disabled=false;
		}
	}
}
</script>
<?php

}
示例#3
0
function graphs()
{
    global $item_rows;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request('host_id'));
    input_validate_input_number(get_request_var_request('graph_type'));
    input_validate_input_number(get_request_var_request('rows'));
    /* ==================================================== */
    /* clean up search string */
    if (isset($_REQUEST['filter'])) {
        $_REQUEST['filter'] = sanitize_search_string(get_request_var_request('filter'));
    }
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST['clear_x'])) {
        kill_session_var('sess_graphs_new_filter');
        kill_session_var('sess_default_rows');
        unset($_REQUEST['filter']);
        unset($_REQUEST['rows']);
        $changed = true;
    } else {
        /* if any of the settings changed, reset the page number */
        $changed = false;
        $changed += check_changed('host_id', 'sess_graphs_new_host_id');
        $changed += check_changed('graph_type', 'sess_graphs_new_graph_type');
        $changed += check_changed('filter', 'sess_graphs_new_filter');
        $changed += check_changed('rows', 'sess_default_rows');
    }
    load_current_session_value('host_id', 'sess_graphs_new_host_id', db_fetch_cell('SELECT id FROM host ORDER BY description, hostname LIMIT 1'));
    load_current_session_value('graph_type', 'sess_graphs_new_graph_type', read_config_option('default_graphs_new_dropdown'));
    load_current_session_value('filter', 'sess_graphs_new_filter', '');
    load_current_session_value('rows', 'sess_default_rows', read_config_option('num_rows_table'));
    if (!empty($_REQUEST['host_id'])) {
        $host = db_fetch_row_prepared('SELECT id, description, hostname, host_template_id FROM host WHERE id = ?', array($_REQUEST['host_id']));
        $header = ' [ ' . htmlspecialchars($host['description']) . ' (' . htmlspecialchars($host['hostname']) . ') ' . (!empty($host['host_template_id']) ? htmlspecialchars(db_fetch_cell_prepared('SELECT name FROM host_template WHERE id = ?', array($host['host_template_id']))) : '') . ' ]';
    } else {
        $host = array();
        $header = 'None Host Type';
    }
    $row_limit = get_request_var_request('rows');
    html_start_box("<strong>New Graphs for</strong> {$header}", '100%', '', '3', 'center', '');
    form_alternate_row();
    print '<td class="even">';
    ?>
	<script type='text/javascript'>
	<!--

	function applyFilter() {
		strURL = '?graph_type=' + $('#graph_type').val();
		strURL = strURL + '&host_id=' + $('#host_id').val();
		strURL = strURL + '&filter=' + $('#filter').val();;
		strURL = strURL + '&rows=' + $('#rows').val();;
		document.location = strURL;
	}

	-->
	</script>
	<form name='form_graphs_new' action='graphs_new.php'>
	<table width='100%' cellpadding='2' cellspacing='0' border='0' align='left'>
		<tr>
			<?php 
    print html_host_filter($_REQUEST['host_id']);
    ?>
			<td style='white-space:nowrap;' width='1'>
				Graph Types
			</td>
			<td width='1'>
				<select id='graph_type' name='graph_type' onChange='applyFilter()'>
					<option value='-2'<?php 
    if ($_REQUEST['graph_type'] == '-2') {
        ?>
 selected<?php 
    }
    ?>
>All</option>
					<option value='-1'<?php 
    if ($_REQUEST['graph_type'] == '-1') {
        ?>
 selected<?php 
    }
    ?>
>Graph Template Based</option>
					<?php 
    $snmp_queries = db_fetch_assoc_prepared('SELECT
						snmp_query.id,
						snmp_query.name,
						snmp_query.xml_path
						FROM (snmp_query, host_snmp_query)
						WHERE host_snmp_query.snmp_query_id = snmp_query.id
						AND host_snmp_query.host_id = ?
						ORDER BY snmp_query.name', array($host['id']));
    if (sizeof($snmp_queries) > 0) {
        foreach ($snmp_queries as $query) {
            print "<option value='" . $query['id'] . "'";
            if ($_REQUEST['graph_type'] == $query['id']) {
                print ' selected';
            }
            print '>' . $query['name'] . "</option>\n";
        }
    }
    ?>
				</select>
			</td>
			<td width='50'>
				Rows
			</td>
			<td>
				<select id='rows' name='rows' onChange='applyFilter()'>
					<?php 
    if (sizeof($item_rows) > 0) {
        foreach ($item_rows as $key => $value) {
            print "<option value='" . $key . "'";
            if (get_request_var_request('rows') == $key) {
                print ' selected';
            }
            print '>' . htmlspecialchars($value) . "</option>\n";
        }
    }
    ?>
				</select>
			</td>
			<td rowspan='3' class='textInfo' align='right' valign='top'>
				<span class='linkMarker'>*</span><a class='hyperLink' href='<?php 
    print htmlspecialchars('host.php?action=edit&id=' . $_REQUEST['host_id']);
    ?>
'>Edit this Device</a><br>
				<span class='linkMarker'>*</span><a class='hyperLink' href='<?php 
    print htmlspecialchars('host.php?action=edit');
    ?>
'>Create New Device</a><br>
				<?php 
    api_plugin_hook('graphs_new_top_links');
    ?>
			</td>
		</tr>
		<tr style='<?php 
    if ($_REQUEST['graph_type'] <= 0) {
        ?>
display:none;<?php 
    }
    ?>
'>
			<td width='50'>
				Search
			</td>
			<td style='white-space:nowrap;'>
				<input id='filter' type='text' name='filter' size='25' value='<?php 
    print htmlspecialchars(get_request_var_request('filter'));
    ?>
'>
			</td>
			<td colspan='3' style='white-space:nowrap;'>
				<input type='submit' value='Go' title='Set/Refresh Filters'>
				<input type='submit' name='clear_x' value='Clear' title='Clear Filters'>
			</td>
		</tr>
	</table>
	</form>
	</td>
	</tr>

	<?php 
    html_end_box();
    ?>

	<form name='chk' method='post' action='graphs_new.php'>
	<?php 
    $total_rows = sizeof(db_fetch_assoc_prepared('SELECT graph_template_id FROM host_graph WHERE host_id = ?', array($_REQUEST['host_id'])));
    $i = 0;
    if ($changed) {
        foreach ($snmp_queries as $query) {
            kill_session_var('sess_graphs_new_page' . $query['id']);
            unset($_REQUEST['page' . $query['id']]);
            load_current_session_value('page' . $query['id'], 'sess_graphs_new_page' . $query['id'], '1');
        }
    }
    if ($_REQUEST['graph_type'] > 0) {
        load_current_session_value('page' . $_REQUEST['graph_type'], 'sess_graphs_new_page' . $_REQUEST['graph_type'], '1');
    } else {
        if ($_REQUEST['graph_type'] == -2) {
            foreach ($snmp_queries as $query) {
                load_current_session_value('page' . $query['id'], 'sess_graphs_new_page' . $query['id'], '1');
            }
        }
    }
    $script = "<script type='text/javascript'>\nvar gt_created_graphs = new Array();\nvar created_graphs = new Array()\n";
    if ($_REQUEST['graph_type'] < 0) {
        html_start_box('<strong>Graph Templates</strong>', '100%', '', '3', 'center', '');
        print "<tr class='tableHeader'>\n\t\t\t\t<td class='tableSubHeaderColumn'>Graph Template Name</td>\n\t\t\t\t<td width='1%' align='center' class='tableSubHeaderCheckbox' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_cg' title='Select All' onClick='SelectAll(\"sg\",this.checked);'></td>\n\n\t\t\t</tr>\n";
        $graph_templates = db_fetch_assoc_prepared('SELECT
			graph_templates.id AS graph_template_id,
			graph_templates.name AS graph_template_name
			FROM (host_graph, graph_templates)
			WHERE host_graph.graph_template_id = graph_templates.id
			AND host_graph.host_id = ?
			ORDER BY graph_templates.name', array($_REQUEST['host_id']));
        if (!empty($_REQUEST['host_id'])) {
            $template_graphs = db_fetch_assoc_prepared('SELECT
				graph_local.graph_template_id
				FROM (graph_local, host_graph)
				WHERE graph_local.graph_template_id = host_graph.graph_template_id
				AND graph_local.host_id = host_graph.host_id
				AND graph_local.host_id = ?
				GROUP BY graph_local.graph_template_id', array($host['id']));
            if (sizeof($template_graphs) > 0) {
                $script .= 'var gt_created_graphs = new Array(';
                $cg_ctr = 0;
                foreach ($template_graphs as $template_graph) {
                    $script .= ($cg_ctr > 0 ? ',' : '') . "'" . $template_graph['graph_template_id'] . "'";
                    $cg_ctr++;
                }
                $script .= ")\n";
            }
        }
        /* create a row for each graph template associated with the host template */
        if (sizeof($graph_templates) > 0) {
            foreach ($graph_templates as $graph_template) {
                $query_row = $graph_template['graph_template_id'];
                print "<tr id='gt_line{$query_row}' class='selectable " . ($i % 2 == 0 ? 'odd' : 'even') . "'>";
                $i++;
                print "<td>\n\t\t\t\t\t\t<span id='gt_text{$query_row}" . "_0'>" . htmlspecialchars($graph_template['graph_template_name']) . "</span>\n\t\t\t\t\t</td>\n\t\t\t\t\t<td align='right' class='checkbox'>\n\t\t\t\t\t\t<input type='checkbox' name='cg_{$query_row}' id='cg_{$query_row}'>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>";
            }
        }
        html_end_box();
        html_start_box('', '100%', '', '3', 'center', '');
        $available_graph_templates = db_fetch_assoc('SELECT
			graph_templates.id, graph_templates.name
			FROM snmp_query_graph RIGHT JOIN graph_templates
			ON (snmp_query_graph.graph_template_id = graph_templates.id)
			WHERE (((snmp_query_graph.name) Is Null)) ORDER BY graph_templates.name');
        /* create a row at the bottom that lets the user create any graph they choose */
        print "\t<tr class='even'>\n\t\t\t\t<td width='1'><i>Create</i></td>\n\t\t\t\t<td align='left'>";
        form_dropdown('cg_g', $available_graph_templates, 'name', 'id', '', '(Select a graph type to create)', '', 'textArea');
        print '</td>
			</tr>';
        html_end_box();
    }
    if ($_REQUEST['graph_type'] != -1 && !empty($_REQUEST['host_id'])) {
        $snmp_queries = db_fetch_assoc('SELECT
			snmp_query.id,
			snmp_query.name,
			snmp_query.xml_path
			FROM (snmp_query,host_snmp_query)
			WHERE host_snmp_query.snmp_query_id=snmp_query.id
			AND host_snmp_query.host_id=' . $host['id'] . ($_REQUEST['graph_type'] != -2 ? ' AND snmp_query.id=' . $_REQUEST['graph_type'] : '') . '
			ORDER BY snmp_query.name');
        if (sizeof($snmp_queries) > 0) {
            foreach ($snmp_queries as $snmp_query) {
                unset($total_rows);
                if (!$changed) {
                    $page = $_REQUEST['page' . $snmp_query['id']];
                } else {
                    $page = 1;
                }
                $xml_array = get_data_query_array($snmp_query['id']);
                $num_input_fields = 0;
                $num_visible_fields = 0;
                if ($xml_array != false) {
                    /* loop through once so we can find out how many input fields there are */
                    reset($xml_array['fields']);
                    while (list($field_name, $field_array) = each($xml_array['fields'])) {
                        if ($field_array['direction'] == 'input') {
                            $num_input_fields++;
                            if (!isset($total_rows)) {
                                $total_rows = db_fetch_cell_prepared('SELECT count(*) FROM host_snmp_cache WHERE host_id = ? AND snmp_query_id = ? AND field_name = ?', array($host['id'], $snmp_query['id'], $field_name));
                            }
                        }
                    }
                }
                if (!isset($total_rows)) {
                    $total_rows = 0;
                }
                $snmp_query_graphs = db_fetch_assoc_prepared('SELECT snmp_query_graph.id,snmp_query_graph.name FROM snmp_query_graph WHERE snmp_query_graph.snmp_query_id = ? ORDER BY snmp_query_graph.name', array($snmp_query['id']));
                if (sizeof($snmp_query_graphs) > 0) {
                    foreach ($snmp_query_graphs as $snmp_query_graph) {
                        $created_graphs = db_fetch_assoc_prepared("SELECT DISTINCT\n\t\t\t\t\t\tdata_local. snmp_index\n\t\t\t\t\t\tFROM (data_local, data_template_data)\n\t\t\t\t\t\tLEFT JOIN data_input_data ON (data_template_data.id = data_input_data.data_template_data_id)\n\t\t\t\t\t\tLEFT JOIN data_input_fields ON (data_input_data.data_input_field_id = data_input_fields.id)\n\t\t\t\t\t\tWHERE data_local.id = data_template_data.local_data_id\n\t\t\t\t\t\tAND data_input_fields.type_code = 'output_type'\n\t\t\t\t\t\tAND data_input_data.value = ?\n\t\t\t\t\t\tAND data_local.host_id = ?", array($snmp_query_graph['id'], $host['id']));
                        $script .= 'created_graphs[' . $snmp_query_graph['id'] . '] = new Array(';
                        $cg_ctr = 0;
                        if (sizeof($created_graphs) > 0) {
                            foreach ($created_graphs as $created_graph) {
                                $script .= ($cg_ctr > 0 ? ',' : '') . "'" . encode_data_query_index($created_graph['snmp_index']) . "'";
                                $cg_ctr++;
                            }
                        }
                        $script .= ")\n";
                    }
                }
                print "\t<table width='100%' class='cactiTable' align='center' cellpadding='3' cellspacing='0'>\n\n\t\t\t\t\t<tr class='cactiTableTitle'>\n\t\t\t\t\t\t<td colspan='" . ($num_input_fields + 1) . "'>\n\t\t\t\t\t\t\t<table  cellspacing='0' cellpadding='0' width='100%' >\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td class='textHeaderDark'>\n\t\t\t\t\t\t\t\t\t\t<strong>Data Query</strong> [" . $snmp_query['name'] . "]\n\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t<td align='right' nowrap>\n\t\t\t\t\t\t\t\t\t\t<a href='" . htmlspecialchars('graphs_new.php?action=query_reload&id=' . $snmp_query['id'] . '&host_id=' . $host['id']) . "'><img src='images/reload_icon_small.gif' title='Reload Associated Query' alt='' border='0' align='absmiddle'></a>\n\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>";
                if ($xml_array != false) {
                    $html_dq_header = '';
                    $snmp_query_indexes = array();
                    reset($xml_array['fields']);
                    /* if there is a where clause, get the matching snmp_indexes */
                    $sql_where = '';
                    if (strlen($_REQUEST['filter'])) {
                        $sql_where = '';
                        $indexes = db_fetch_assoc("SELECT DISTINCT snmp_index\n\t\t\t\t\t\tFROM host_snmp_cache\n\t\t\t\t\t\tWHERE field_value LIKE '%%" . $_REQUEST['filter'] . "%%'\n\t\t\t\t\t\tAND snmp_query_id=" . $snmp_query['id'] . "\n\t\t\t\t\t\tAND host_id=" . $host['id']);
                        if (sizeof($indexes)) {
                            foreach ($indexes as $index) {
                                if (strlen($sql_where)) {
                                    $sql_where .= ", '" . $index['snmp_index'] . "'";
                                } else {
                                    $sql_where .= " AND snmp_index IN('" . $index['snmp_index'] . "'";
                                }
                            }
                            $sql_where .= ')';
                        }
                    }
                    if (strlen($_REQUEST['filter']) == 0 || strlen($_REQUEST['filter']) && sizeof($indexes)) {
                        /* determine the sort order */
                        if (isset($xml_array['index_order_type'])) {
                            if ($xml_array['index_order_type'] == 'numeric') {
                                $sql_order = 'ORDER BY CAST(snmp_index AS unsigned)';
                            } else {
                                if ($xml_array['index_order_type'] == 'alphabetic') {
                                    $sql_order = 'ORDER BY snmp_index';
                                } else {
                                    if ($xml_array['index_order_type'] == 'natural') {
                                        $sql_order = 'ORDER BY INET_ATON(snmp_index)';
                                    } else {
                                        $sql_order = '';
                                    }
                                }
                            }
                        } else {
                            $sql_order = '';
                        }
                        /* get the unique field values from the database */
                        $field_names = db_fetch_assoc_prepared('SELECT DISTINCT field_name
						FROM host_snmp_cache
						WHERE host_id = ?
						AND snmp_query_id = ?', array($host['id'], $snmp_query['id']));
                        /* build magic query */
                        $sql_query = 'SELECT host_id, snmp_query_id, snmp_index';
                        $num_visible_fields = sizeof($field_names);
                        $i = 0;
                        if (sizeof($field_names) > 0) {
                            foreach ($field_names as $column) {
                                $field_name = $column['field_name'];
                                $sql_query .= ", MAX(CASE WHEN field_name='{$field_name}' THEN field_value ELSE NULL END) AS '{$field_name}'";
                                $i++;
                            }
                        }
                        $sql_query .= ' FROM host_snmp_cache
						WHERE host_id=' . $host['id'] . '
						AND snmp_query_id=' . $snmp_query['id'] . "\n\t\t\t\t\t\t{$sql_where}\n\t\t\t\t\t\tGROUP BY host_id, snmp_query_id, snmp_index\n\t\t\t\t\t\t{$sql_order}\n\t\t\t\t\t\tLIMIT " . $row_limit * ($page - 1) . ',' . $row_limit;
                        $rows_query = 'SELECT host_id, snmp_query_id, snmp_index
						FROM host_snmp_cache
						WHERE host_id=' . $host['id'] . '
						AND snmp_query_id=' . $snmp_query['id'] . "\n\t\t\t\t\t\t{$sql_where}\n\t\t\t\t\t\tGROUP BY host_id, snmp_query_id, snmp_index";
                        $snmp_query_indexes = db_fetch_assoc($sql_query);
                        $total_rows = sizeof(db_fetch_assoc($rows_query));
                        if (($page - 1) * $row_limit > $total_rows) {
                            $page = 1;
                            $_REQUEST['page' . $query['id']] = $page;
                            load_current_session_value('page' . $query['id'], 'sess_graphs_new_page' . $query['id'], '1');
                        }
                        $nav = html_nav_bar('graphs_new.php', MAX_DISPLAY_PAGES, $page, $row_limit, $total_rows, 15, 'Items', 'page' . $snmp_query['id']);
                        print $nav;
                        while (list($field_name, $field_array) = each($xml_array['fields'])) {
                            if ($field_array['direction'] == 'input' && sizeof($field_names)) {
                                foreach ($field_names as $row) {
                                    if ($row['field_name'] == $field_name) {
                                        $html_dq_header .= "<td class='tableSubHeaderColumn'>" . $field_array['name'] . "</td>\n";
                                        break;
                                    }
                                }
                            }
                        }
                        if (!sizeof($snmp_query_indexes)) {
                            print "<tr class='odd'><td>This Data Query returned 0 rows, perhaps there was a problem executing this\n\t\t\t\t\t\t\tData Query. You can <a href='" . htmlspecialchars('host.php?action=query_verbose&id=' . $snmp_query['id'] . '&host_id=' . $host['id']) . "'>run this Data Query in debug mode</a> to get more information.</td></tr>\n";
                        } else {
                            print "<tr class='tableHeader'>\n\t\t\t\t\t\t\t\t{$html_dq_header}\n\t\t\t\t\t\t\t\t<td width='1%' align='center' class='tableSubHeaderCheckbox' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_" . $snmp_query['id'] . "' title='Select All' onClick='SelectAll(\"sg_" . $snmp_query['id'] . "\",this.checked)'></td>\n\n\t\t\t\t\t\t\t</tr>\n";
                        }
                        $row_counter = 0;
                        $column_counter = 0;
                        $fields = array_rekey($field_names, 'field_name', 'field_name');
                        if (sizeof($snmp_query_indexes) > 0) {
                            foreach ($snmp_query_indexes as $row) {
                                $query_row = $snmp_query['id'] . '_' . encode_data_query_index($row['snmp_index']);
                                print "<tr id='line{$query_row}' class='selectable " . ($row_counter % 2 == 0 ? 'odd' : 'even') . "'>";
                                $i++;
                                $column_counter = 0;
                                reset($xml_array['fields']);
                                while (list($field_name, $field_array) = each($xml_array['fields'])) {
                                    if ($field_array['direction'] == 'input') {
                                        if (in_array($field_name, $fields)) {
                                            if (isset($row[$field_name])) {
                                                print "<td><span id='text{$query_row}" . '_' . $column_counter . "'>" . (strlen($_REQUEST['filter']) ? preg_replace('/(' . preg_quote($_REQUEST['filter']) . ')/i', "<span class='filteredValue'>\\1</span>", $row[$field_name]) : $row[$field_name]) . '</span></td>';
                                            } else {
                                                print "<td><span id='text{$query_row}" . '_' . $column_counter . "'></span></td>";
                                            }
                                            $column_counter++;
                                        }
                                    }
                                }
                                print "<td class='checkbox' align='right'>";
                                print "<input type='checkbox' name='sg_{$query_row}' id='sg_{$query_row}'>";
                                print '</td>';
                                print "</tr>\n";
                                $row_counter++;
                            }
                        }
                        if ($total_rows > $row_limit) {
                            print $nav;
                        }
                    } else {
                        print "<tr class='odd'><td class='textError'>Search Returned no Rows.</td></tr>\n";
                    }
                } else {
                    print "<tr class='odd'><td class='textError'>Error in data query.</td></tr>\n";
                }
                print '</table>';
                /* draw the graph template drop down here */
                $data_query_graphs = db_fetch_assoc_prepared('SELECT snmp_query_graph.id, snmp_query_graph.name FROM snmp_query_graph WHERE snmp_query_graph.snmp_query_id = ? ORDER BY snmp_query_graph.name', array($snmp_query['id']));
                if (sizeof($data_query_graphs) == 1) {
                    echo "<input type='hidden' id='sgg_" . $snmp_query['id'] . "' name='sgg_" . $snmp_query['id'] . "' value='" . $data_query_graphs[0]['id'] . "'>\n";
                } elseif (sizeof($data_query_graphs) > 1) {
                    print "\t<table align='center' width='100%'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td width='100%' valign='middle'>\n\t\t\t\t\t\t\t\t<img src='images/arrow.gif' align='absmiddle' alt=''>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td style='white-space:nowrap;font-style: italic;'' align='right'>\n\t\t\t\t\t\t\t\tSelect a Graph Type to Create\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td align='right'>\n\t\t\t\t\t\t\t\t<select name='sgg_" . $snmp_query['id'] . "' id='sgg_" . $snmp_query['id'] . "' onChange='dqUpdateDeps(" . $snmp_query['id'] . ',' . (isset($column_counter) ? $column_counter : '') . ");'>\n\t\t\t\t\t\t\t\t\t";
                    html_create_list($data_query_graphs, 'name', 'id', '0');
                    print "\n\t\t\t\t\t\t\t\t</select>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n";
                }
                print '<br>';
                $script .= 'dqUpdateDeps(' . $snmp_query['id'] . ',' . $num_visible_fields . ");\n";
            }
        }
    }
    if (strlen($script)) {
        $script .= "</script>\n";
        print $script;
    }
    form_hidden_box('save_component_graph', '1', '');
    if (!empty($_REQUEST['host_id'])) {
        form_hidden_box('host_id', $host['id'], '0');
        form_hidden_box('host_template_id', $host['host_template_id'], '0');
    }
    if (isset($_SERVER['HTTP_REFERER']) && !substr_count($_SERVER['HTTP_REFERER'], 'graphs_new')) {
        $_REQUEST['returnto'] = basename($_SERVER['HTTP_REFERER']);
    }
    load_current_session_value('returnto', 'sess_graphs_new_returnto', '');
    form_save_button($_REQUEST['returnto']);
}
示例#4
0
function template_edit()
{
    global $struct_data_source, $struct_data_source_item, $data_source_types, $fields_data_template_template_edit;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var("id"));
    input_validate_input_number(get_request_var("view_rrd"));
    /* ==================================================== */
    if (!empty($_GET["id"])) {
        $template_data = db_fetch_row("select * from data_template_data where data_template_id=" . $_GET["id"] . " and local_data_id=0");
        $template = db_fetch_row("select * from data_template where id=" . $_GET["id"]);
        $header_label = "[edit: " . $template["name"] . "]";
    } else {
        $header_label = "[new]";
    }
    html_start_box("<strong>Data Templates</strong> " . htmlspecialchars($header_label), "100%", "", "3", "center", "");
    draw_edit_form(array("config" => array(), "fields" => inject_form_variables($fields_data_template_template_edit, isset($template) ? $template : array(), isset($template_data) ? $template_data : array(), $_GET)));
    html_end_box();
    html_start_box("<strong>Data Source</strong>", "100%", "", "3", "center", "");
    /* make sure 'data source path' doesn't show up for a template... we should NEVER template this field */
    unset($struct_data_source["data_source_path"]);
    $form_array = array();
    while (list($field_name, $field_array) = each($struct_data_source)) {
        $form_array += array($field_name => $struct_data_source[$field_name]);
        if ($field_array["flags"] == "ALWAYSTEMPLATE") {
            $form_array[$field_name]["description"] = "<em>This field is always templated.</em>";
        } else {
            $form_array[$field_name]["description"] = "";
            $form_array[$field_name]["sub_checkbox"] = array("name" => "t_" . $field_name, "friendly_name" => "Use Per-Data Source Value (Ignore this Value)", "value" => isset($template_data["t_" . $field_name]) ? $template_data["t_" . $field_name] : "");
        }
        $form_array[$field_name]["value"] = isset($template_data[$field_name]) ? $template_data[$field_name] : "";
        $form_array[$field_name]["form_id"] = isset($template_data) ? $template_data["data_template_id"] : "0";
    }
    draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => inject_form_variables($form_array, isset($template_data) ? $template_data : array())));
    html_end_box();
    /* fetch ALL rrd's for this data source */
    if (!empty($_GET["id"])) {
        $template_data_rrds = db_fetch_assoc("select id,data_source_name from data_template_rrd where data_template_id=" . $_GET["id"] . " and local_data_id=0 order by data_source_name");
    }
    /* select the first "rrd" of this data source by default */
    if (empty($_GET["view_rrd"])) {
        $_GET["view_rrd"] = isset($template_data_rrds[0]["id"]) ? $template_data_rrds[0]["id"] : "0";
    }
    /* get more information about the rrd we chose */
    if (!empty($_GET["view_rrd"])) {
        $template_rrd = db_fetch_row("select * from data_template_rrd where id=" . $_GET["view_rrd"]);
    }
    $i = 0;
    if (isset($template_data_rrds)) {
        if (sizeof($template_data_rrds) > 1) {
            /* draw the data source tabs on the top of the page */
            print "\t<table class='tabs' width='100%' cellspacing='0' cellpadding='3' align='center'>\n\t\t\t\t<tr>\n";
            foreach ($template_data_rrds as $template_data_rrd) {
                $i++;
                print "\t<td " . ($template_data_rrd["id"] == $_GET["view_rrd"] ? "class='tabSelected tab'" : "class='tabNotSelected tab'") . " width='" . (strlen($template_data_rrd["data_source_name"]) * 9 + 50) . "' align='center'>\n\t\t\t\t\t\t\t<span class='textHeader'><a href='" . htmlspecialchars("data_templates.php?action=template_edit&id=" . $_GET["id"] . "&view_rrd=" . $template_data_rrd["id"]) . "'>{$i}: " . htmlspecialchars($template_data_rrd["data_source_name"]) . "</a> <a href='" . htmlspecialchars("data_templates.php?action=rrd_remove&id=" . $template_data_rrd["id"] . "&data_template_id=" . $_GET["id"]) . "'><img src='images/delete_icon.gif' border='0' alt='Delete'></a></span>\n\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t<td width='1'></td>\n";
            }
            print "\n\t\t\t\t<td></td>\n\n\t\t\t\t</tr>\n\t\t\t</table>\n";
        } elseif (sizeof($template_data_rrds) == 1) {
            $_GET["view_rrd"] = $template_data_rrds[0]["id"];
        }
    }
    html_start_box("", "100%", "", "3", "center", "");
    print "\t<tr class='cactiTableTitle'>\n\t\t\t<td class='textHeaderDark'>\n\t\t\t\t<strong>Data Source Item</strong> [" . (isset($template_rrd) ? htmlspecialchars($template_rrd["data_source_name"]) : "") . "]\n\t\t\t</td>\n\t\t\t<td class='textHeaderDark' align='right'>\n\t\t\t\t" . (!empty($_GET["id"]) ? "<strong><a class='linkOverDark' href='" . htmlspecialchars("data_templates.php?action=rrd_add&id=" . $_GET["id"]) . "'>New</a>&nbsp;</strong>" : "") . "\n\t\t\t</td>\n\t\t</tr>\n";
    /* data input fields list */
    if (empty($template_data["data_input_id"]) || db_fetch_cell("select type_id from data_input where id=" . $template_data["data_input_id"]) != "1" && db_fetch_cell("select type_id from data_input where id=" . $template_data["data_input_id"]) != "5") {
        unset($struct_data_source_item["data_input_field_id"]);
    } else {
        $struct_data_source_item["data_input_field_id"]["sql"] = "select id,CONCAT(data_name,' - ',name) as name from data_input_fields where data_input_id=" . $template_data["data_input_id"] . " and input_output='out' and update_rra='on' order by data_name,name";
    }
    $form_array = array();
    while (list($field_name, $field_array) = each($struct_data_source_item)) {
        $form_array += array($field_name => $struct_data_source_item[$field_name]);
        $form_array[$field_name]["description"] = "";
        $form_array[$field_name]["value"] = isset($template_rrd) ? $template_rrd[$field_name] : "";
        $form_array[$field_name]["sub_checkbox"] = array("name" => "t_" . $field_name, "friendly_name" => "Use Per-Data Source Value (Ignore this Value)", "value" => isset($template_rrd) ? $template_rrd["t_" . $field_name] : "");
    }
    draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => $form_array + array("data_template_rrd_id" => array("method" => "hidden", "value" => isset($template_rrd) ? $template_rrd["id"] : "0"))));
    html_end_box();
    $i = 0;
    if (!empty($_GET["id"])) {
        /* get each INPUT field for this data input source */
        $fields = db_fetch_assoc("select * from data_input_fields where data_input_id=" . $template_data["data_input_id"] . " and input_output='in' order by name");
        html_start_box("<strong>Custom Data</strong> [data input: " . htmlspecialchars(db_fetch_cell("select name from data_input where id=" . $template_data["data_input_id"])) . "]", "100%", "", "3", "center", "");
        /* loop through each field found */
        if (sizeof($fields) > 0) {
            foreach ($fields as $field) {
                $data_input_data = db_fetch_row("select t_value,value from data_input_data where data_template_data_id=" . $template_data["id"] . " and data_input_field_id=" . $field["id"]);
                if (sizeof($data_input_data) > 0) {
                    $old_value = $data_input_data["value"];
                } else {
                    $old_value = "";
                }
                form_alternate_row();
                ?>
				<td width="50%">
					<strong><?php 
                print $field["name"];
                ?>
</strong><br>
					<?php 
                form_checkbox("t_value_" . $field["data_name"], $data_input_data["t_value"], "Use Per-Data Source Value (Ignore this Value)", "", "", $_GET["id"]);
                ?>
				</td>
				<td>
					<?php 
                form_text_box("value_" . $field["data_name"], $old_value, "", "");
                ?>
					<?php 
                if (preg_match('/^' . VALID_HOST_FIELDS . '$/i', $field["type_code"]) && $data_input_data["t_value"] == "") {
                    print "<br><em>Value will be derived from the host if this field is left empty.</em>\n";
                }
                ?>
				</td>
			</tr>
			<?php 
                $i++;
            }
        } else {
            print "<tr><td><em>No Input Fields for the Selected Data Input Source</em></td></tr>";
        }
        html_end_box();
    }
    form_save_button("data_templates.php", "return");
}
function import()
{
    global $colors, $hash_type_names;
    ?>
	<form method="post" action="templates_import.php" enctype="multipart/form-data">
	<?php 
    if (isset($_SESSION["import_debug_info"]) && is_array($_SESSION["import_debug_info"])) {
        html_start_box("<strong>Import Results</strong>", "100%", "aaaaaa", "3", "center", "");
        print "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td><p class='textArea'>Cacti has imported the following items:</p>";
        while (list($type, $type_array) = each($_SESSION["import_debug_info"])) {
            print "<p><strong>" . $hash_type_names[$type] . "</strong></p>";
            while (list($index, $vals) = each($type_array)) {
                if ($vals["result"] == "success") {
                    $result_text = "<span style='color: green;'>[success]</span>";
                } else {
                    $result_text = "<span style='color: red;'>[fail]</span>";
                }
                if ($vals["type"] == "update") {
                    $type_text = "<span style='color: gray;'>[update]</span>";
                } else {
                    $type_text = "<span style='color: blue;'>[new]</span>";
                }
                print "<span style='font-family: monospace;'>{$result_text} " . $vals["title"] . " {$type_text}</span><br>\n";
                $dep_text = "";
                $there_are_dep_errors = false;
                if (isset($vals["dep"]) && sizeof($vals["dep"]) > 0) {
                    while (list($dep_hash, $dep_status) = each($vals["dep"])) {
                        if ($dep_status == "met") {
                            $dep_status_text = "<span style='color: navy;'>Found Dependency:</span>";
                        } else {
                            $dep_status_text = "<span style='color: red;'>Unmet Dependency:</span>";
                            $there_are_dep_errors = true;
                        }
                        $dep_text .= "<span style='font-family: monospace;'>&nbsp;&nbsp;&nbsp;+ {$dep_status_text} " . hash_to_friendly_name($dep_hash, true) . "</span><br>\n";
                    }
                }
                /* only print out dependency details if they contain errors; otherwise it would get too long */
                if ($there_are_dep_errors == true) {
                    print $dep_text;
                }
            }
        }
        print "</td></tr>";
        html_end_box();
        kill_session_var("import_debug_info");
    }
    html_start_box("<strong>Import Templates</strong>", "100%", $colors["header"], "3", "center", "");
    form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], 0);
    ?>
		<td width="50%">
			<font class="textEditTitle">Import Template from Local File</font><br>
			If the XML file containing template data is located on your local machine, select it here.
		</td>
		<td>
			<input type="file" name="import_file">
		</td>
	</tr>

	<?php 
    form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], 1);
    ?>
		<td width="50%">
			<font class="textEditTitle">Import Template from Text</font><br>
			If you have the XML file containing template data as text, you can paste it into this box to
			import it.
		</td>
		<td>
			<?php 
    form_text_area("import_text", "", "10\t", "50", "");
    ?>
		</td>
	</tr>

	<?php 
    form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], 0);
    ?>
		<td width="50%">
			<font class="textEditTitle">Import RRA Settings</font><br>
			Choose whether to allow Cacti to import custom RRA settings from imported templates or whether to use the defaults for this installation.
		</td>
		<td>
			<?php 
    form_radio_button("import_rra", 1, 1, "Use defaults for this installation (Recommended)", 1);
    echo "<br />";
    form_radio_button("import_rra", 1, 2, "Use custom RRA settings from the template", 1);
    ?>
		</td>
	</tr>

	<?php 
    form_hidden_box("save_component_import", "1", "");
    html_end_box();
    form_save_button("templates_import.php", "save");
}
示例#6
0
function mactrack_site_edit()
{
    global $fields_mactrack_site_edit;
    /* ================= input validation ================= */
    get_filter_request_var('site_id');
    /* ==================================================== */
    display_output_messages();
    if (!isempty_request_var('site_id')) {
        $site = db_fetch_row('SELECT * FROM mac_track_sites WHERE site_id=' . get_request_var('site_id'));
        $header_label = __('MacTrack Site [edit: %s]', $site['site_name']);
    } else {
        $header_label = __('MacTrack Site [new]');
    }
    form_start('mactrack_sites.php');
    html_start_box($header_label, '100%', '', '3', 'center', '');
    draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => inject_form_variables($fields_mactrack_site_edit, isset($site) ? $site : array())));
    html_end_box();
    form_save_button('mactrack_sites.php', 'return', 'site_id');
}
示例#7
0
文件: host.php 项目: MrWnn/cacti
function host_edit()
{
    global $fields_host_edit, $reindex_types;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request('id'));
    /* ==================================================== */
    api_plugin_hook('host_edit_top');
    if (!empty($_REQUEST['id'])) {
        $host = db_fetch_row_prepared('SELECT * FROM host WHERE id = ?', array($_REQUEST['id']));
        $header_label = '[edit: ' . htmlspecialchars($host['description']) . ']';
    } else {
        $header_label = '[new]';
    }
    if (!empty($host['id'])) {
        ?>
		<table width='100%' align='center'>
			<tr>
				<td class='textInfo' colspan='2'>
					<?php 
        print htmlspecialchars($host['description']);
        ?>
 (<?php 
        print htmlspecialchars($host['hostname']);
        ?>
)
				</td>
				<td rowspan='2' class='textInfo' valign='top' align='right'>
					<span class='linkMarker'>*</span><a class='hyperLink' href='<?php 
        print htmlspecialchars('graphs_new.php?host_id=' . $host['id']);
        ?>
'>Create Graphs for this Device</a><br>
					<span class='linkMarker'>*</span><a class='hyperLink' href='<?php 
        print htmlspecialchars('data_sources.php?host_id=' . $host['id'] . '&ds_rows=30&filter=&template_id=-1&method_id=-1&page=1');
        ?>
'>Data Source List</a><br>
					<span class='linkMarker'>*</span><a class='hyperLink' href='<?php 
        print htmlspecialchars('graphs.php?host_id=' . $host['id'] . '&graph_rows=30&filter=&template_id=-1&page=1');
        ?>
'>Graph List</a>
					<?php 
        api_plugin_hook('device_edit_top_links');
        ?>
				</td>
			</tr>
			<tr>
				<td valign='top' class='textHeader'>
					<div id='ping_results'>Pinging Device&nbsp;<i style='font-size:12px;' class='fa fa-spin fa-spinner'></i><br><br></div>
				</td>
			</tr>
		</table>
		<?php 
    }
    html_start_box("<strong>Device</strong> {$header_label}", '100%', '', '3', 'center', '');
    /* preserve the host template id if passed in via a GET variable */
    if (!empty($_REQUEST['host_template_id'])) {
        $fields_host_edit['host_template_id']['value'] = $_REQUEST['host_template_id'];
    }
    draw_edit_form(array('config' => array('form_name' => 'chk'), 'fields' => inject_form_variables($fields_host_edit, isset($host) ? $host : array())));
    /* we have to hide this button to make a form change in the main form trigger the correct
     * submit action */
    echo "<div style='display:none;'><input type='submit' value='Default Submit Button'></div>";
    html_end_box();
    ?>
	<script type="text/javascript">
	<!--

	// default snmp information
	var snmp_community       = $('#snmp_community').val();
	var snmp_username        = $('#snmp_username').val();
	var snmp_password        = $('#snmp_password').val();
	var snmp_auth_protocol   = $('#snmp_auth_protocol').val();
	var snmp_priv_passphrase = $('#snmp_priv_passphrase').val();
	var snmp_priv_protocol   = $('#snmp_priv_protocol').val();
	var snmp_context         = $('#snmp_context').val();
	var snmp_port            = $('#snmp_port').val();
	var snmp_timeout         = $('#snmp_timeout').val();
	var max_oids             = $('#max_oids').val();

	// default ping methods
	var ping_method    = $('#ping_method').val();
	var ping_port      = $('#ping_port').val();
	var ping_timeout   = $('#ping_timeout').val();
	var ping_retries   = $('#ping_retries').val();

	function setPing() {
		availability_method = $('#availability_method').val();
		ping_method         = $('#ping_method').val();

		switch(availability_method) {
		case '0': // none
			$('#row_ping_method').css('display', 'none');
			$('#row_ping_port').css('display', 'none');
			$('#row_ping_timeout').css('display', 'none');
			$('#row_ping_retries').css('display', 'none');

			break;
		case '2': // snmp
		case '5': // snmp sysDesc
		case '6': // snmp getNext
			$('#row_ping_method').css('display', 'none');
			$('#row_ping_port').css('display', 'none');
			$('#row_ping_timeout').css('display', '');
			$('#row_ping_retries').css('display', '');

			break;
		default: // ping ok
			switch(ping_method) {
			case '1': // ping icmp
				$('#row_ping_method').css('display', '');
				$('#row_ping_port').css('display', 'none');
				$('#row_ping_timeout').css('display', '');
				$('#row_ping_retries').css('display', '');

				break;
			case '2': // ping udp
			case '3': // ping tcp
				$('#row_ping_method').css('display', '');
				$('#row_ping_port').css('display', '');
				$('#row_ping_timeout').css('display', '');
				$('#row_ping_retries').css('display', '');

				break;
			}

			break;
		}
	}

	function setAvailability() {
		if ($('#snmp_version').val() == '0') {
			methods = [ 
				{ value: '0', text: 'None' }, 
				{ value: '3', text: 'Ping' }
			];

			if ($('#availability_method').val() != '3' && $('#availability_method').val() != '0') {
				$('#availability_method').val('3');
			}

			$('#availability_method').replaceOptions(methods, $('#availability_method').val());
		}else{
			methods = [
				{ value: '0', text: 'None' }, 
				{ value: '1', text: 'Ping and SNMP Uptime' }, 
				{ value: '2', text: 'SNMP Uptime' }, 
				{ value: '3', text: 'Ping' }, 
				{ value: '4', text: 'Ping or SNMP Uptime' }, 
				{ value: '5', text: 'SNMP Desc' }, 
				{ value: '6', text: 'SNMP GetNext' }
			];

			$('#availability_method').replaceOptions(methods, $('#availability_method').val());
		}

		switch($('#availibility_method').val()) {
			case '0': // availability none
				$('#row_ping_method').hide();
				$('#ping_method').val(0);
				$('#row_ping_timeout').hide();
				$('#row_ping_port').hide();
				$('#row_ping_timeout').hide();
				$('#row_ping_retrie').hide();

				break;
			case '1': // ping and snmp sysUptime
			case '3': // ping
			case '4': // ping or snmp sysUptime
				if (($('#row_ping_method').css('display', 'none')) ||
					($('#row_ping_method').css('display') == undefined)) {
					$('#ping_method').val(ping_method);
					$('#row_ping_method').css('display', '');
				}

				break;
			case '2': // snmp sysUptime
			case '5': // snmp sysDesc
			case '6': // snmp getNext
				$('#row_ping_method').css('display', 'none');
				$('#ping_method').val(0);

				break;
		}

		if ($('#availability_method-button').length) {
			$('#availability_method').selectmenu('refresh');
		}
	}

	function changeHostForm() {
		setSNMP();
		setAvailability();
		setPing();
	}

	function setSNMP() {
		snmp_version = $('#snmp_version').val();
		switch(snmp_version) {
		case '0': // No SNMP
			$('#row_snmp_username').hide();
			$('#row_snmp_password').hide();
			$('#row_snmp_community').hide();
			$('#row_snmp_auth_protocol').hide();
			$('#row_snmp_priv_passphrase').hide();
			$('#row_snmp_priv_protocol').hide();
			$('#row_snmp_context').hide();
			$('#row_snmp_port').hide();
			$('#row_snmp_timeout').hide();
			$('#row_max_oids').hide();
			break;
		case '1': // SNMP v1
		case '2': // SNMP v2c
			$('#row_snmp_username').hide();
			$('#row_snmp_password').hide();
			$('#row_snmp_community').show();
			$('#row_snmp_auth_protocol').hide();
			$('#row_snmp_priv_passphrase').hide();
			$('#row_snmp_priv_protocol').hide();
			$('#row_snmp_context').hide();
			$('#row_snmp_port').show();
			$('#row_snmp_timeout').show();
			$('#row_max_oids').show();
			break;
		case '3': // SNMP v3
			$('#row_snmp_username').show();
			$('#row_snmp_password').show();
			$('#row_snmp_community').hide();
			$('#row_snmp_auth_protocol').show();
			$('#row_snmp_priv_passphrase').show();
			$('#row_snmp_priv_protocol').show();
			$('#row_snmp_context').show();
			$('#row_snmp_port').show();
			$('#row_snmp_timeout').show();
			$('#row_max_oids').show();
			break;
		}
	}

	$(function() {
		changeHostForm();
		$('#dbghide').click(function(data) {
			$('#dqdebug').fadeOut('fast');
		});

		$.get('host.php?action=ping_host&id='+$('#id').val(), function(data) {
			$('#ping_results').html(data);
		});
	});

	-->
	</script>
	<?php 
    if (isset($_REQUEST['display_dq_details']) && isset($_SESSION['debug_log']['data_query'])) {
        print "<table id='dqdebug' width='100%' class='cactiDebugTable' cellpadding='0' cellspacing='0' border='0' align='center'><tr><td>\n";
        print "<table width='100%' class='cactiTableTitle' cellspacing='0' cellpadding='3' border='0'>\n";
        print "<tr><td class='textHeaderDark'><a name='dqdbg'></a><strong>Data Query Debug Information</strong></td><td class='textHeaderDark' align='right'><a style='cursor:pointer;' id='dbghide' class='linkOverDark'>Hide</a></td></tr>\n";
        print "</table>\n";
        print "<table width='100%' class='cactiTable' cellspacing='0' cellpadding='3' border='0'>\n";
        print "<tr><td class='odd'><span style='font-family: monospace;'>" . debug_log_return('data_query') . "</span></td></tr>";
        print "</table>\n";
        print "</table>\n";
    }
    if (!empty($host['id'])) {
        html_start_box('<strong>Associated Graph Templates</strong>', '100%', '', '3', 'center', '');
        html_header(array('Graph Template Name', 'Status'), 2);
        $selected_graph_templates = db_fetch_assoc_prepared('SELECT
			graph_templates.id,
			graph_templates.name
			FROM (graph_templates, host_graph)
			WHERE graph_templates.id = host_graph.graph_template_id
			AND host_graph.host_id = ?
			ORDER BY graph_templates.name', array($_REQUEST['id']));
        $available_graph_templates = db_fetch_assoc('SELECT
			graph_templates.id, graph_templates.name
			FROM snmp_query_graph RIGHT JOIN graph_templates
			ON (snmp_query_graph.graph_template_id = graph_templates.id)
			WHERE (((snmp_query_graph.name) Is Null)) ORDER BY graph_templates.name');
        $i = 0;
        if (sizeof($selected_graph_templates) > 0) {
            foreach ($selected_graph_templates as $item) {
                form_alternate_row('', true);
                /* get status information for this graph template */
                $is_being_graphed = sizeof(db_fetch_assoc_prepared('SELECT id FROM graph_local WHERE graph_template_id = ? AND host_id = ?', array($item['id'], $_REQUEST['id']))) > 0 ? true : false;
                ?>
					<td style="padding: 4px;">
						<strong><?php 
                print $i;
                ?>
)</strong> <?php 
                print htmlspecialchars($item['name']);
                ?>
					</td>
					<td>
						<?php 
                print $is_being_graphed == true ? "<span style='color: green;'>Is Being Graphed</span> (<a href='" . htmlspecialchars('graphs.php?action=graph_edit&id=' . db_fetch_cell_prepared('SELECT id FROM graph_local WHERE graph_template_id = ? AND host_id = ? LIMIT 0,1', array($item['id'], $_REQUEST['id']))) . "'>Edit</a>)" : "<span style='color: #484848;'>Not Being Graphed</span>";
                ?>
					</td>
					<td align='right' nowrap>
						<a href='<?php 
                print htmlspecialchars('host.php?action=gt_remove&id=' . $item['id'] . '&host_id=' . $_REQUEST['id']);
                ?>
'><img src='images/delete_icon_large.gif' title='Delete Graph Template Association' alt='Delete Graph Template Association' border='0' align='middle'></a>
					</td>
				<?php 
                form_end_row();
                $i++;
            }
        } else {
            print "<tr class='tableRow'><td colspan='2'><em>No associated graph templates.</em></td></tr>";
        }
        ?>
		<tr class='odd'>
			<td class='saveRow' colspan="4">
				<table cellspacing="0" cellpadding="1" width="100%">
					<td nowrap>Add Graph Template:&nbsp;
						<?php 
        form_dropdown('graph_template_id', $available_graph_templates, 'name', 'id', '', '', '');
        ?>
					</td>
					<td align="right">
						&nbsp;<input type="submit" value="Add" name="add_gt_x" title="Add Graph Template to Device">
					</td>
				</table>
			</td>
		</tr>

		<?php 
        html_end_box();
        html_start_box('<strong>Associated Data Queries</strong>', '100%', '', '3', 'center', '');
        html_header(array('Data Query Name', 'Debugging', 'Re-Index Method', 'Status'), 2);
        $selected_data_queries = db_fetch_assoc_prepared('SELECT
			snmp_query.id,
			snmp_query.name,
			host_snmp_query.reindex_method
			FROM (snmp_query, host_snmp_query)
			WHERE snmp_query.id = host_snmp_query.snmp_query_id
			AND host_snmp_query.host_id = ?
			ORDER BY snmp_query.name', array($_REQUEST['id']));
        $available_data_queries = db_fetch_assoc('SELECT
			snmp_query.id,
			snmp_query.name
			FROM snmp_query
			ORDER BY snmp_query.name');
        $keeper = array();
        foreach ($available_data_queries as $item) {
            if (sizeof(db_fetch_assoc_prepared('SELECT snmp_query_id FROM host_snmp_query WHERE host_id = ? AND snmp_query_id = ?', array($_REQUEST['id'], $item['id']))) > 0) {
                /* do nothing */
            } else {
                array_push($keeper, $item);
            }
        }
        $available_data_queries = $keeper;
        $i = 0;
        if (sizeof($selected_data_queries) > 0) {
            foreach ($selected_data_queries as $item) {
                form_alternate_row('', true);
                /* get status information for this data query */
                $num_dq_items = sizeof(db_fetch_assoc_prepared('SELECT snmp_index FROM host_snmp_cache WHERE host_id = ? AND snmp_query_id = ?', array($_REQUEST['id'], $item['id'])));
                $num_dq_rows = sizeof(db_fetch_assoc_prepared('SELECT snmp_index FROM host_snmp_cache WHERE host_id = ? AND snmp_query_id = ? GROUP BY snmp_index', array($_REQUEST['id'], $item['id'])));
                $status = 'success';
                ?>
					<td style="padding: 4px;">
						<strong><?php 
                print $i;
                ?>
)</strong> <?php 
                print htmlspecialchars($item['name']);
                ?>
					</td>
					<td>
						(<a href="<?php 
                print htmlspecialchars('host.php?action=query_verbose&id=' . $item['id'] . '&host_id=' . $_REQUEST['id']);
                ?>
">Verbose Query</a>)
					</td>
					<td>
					<?php 
                print $reindex_types[$item['reindex_method']];
                ?>
					</td>
					<td>
						<?php 
                print $status == 'success' ? "<span style='color: green;'>Success</span>" : "<span style='color: green;'>Fail</span>";
                ?>
 [<?php 
                print $num_dq_items;
                ?>
 Item<?php 
                print $num_dq_items == 1 ? '' : 's';
                ?>
, <?php 
                print $num_dq_rows;
                ?>
 Row<?php 
                print $num_dq_rows == 1 ? '' : 's';
                ?>
]
					</td>
					<td align='right' nowrap>
						<a href='<?php 
                print htmlspecialchars('host.php?action=query_reload&id=' . $item['id'] . '&host_id=' . $_REQUEST['id']);
                ?>
'><img src='images/reload_icon_small.gif' title='Reload Data Query' alt='Reload Data Query' border='0' align='middle'></a>&nbsp;
						<a href='<?php 
                print htmlspecialchars('host.php?action=query_remove&id=' . $item['id'] . '&host_id=' . $_REQUEST['id']);
                ?>
'><img src='images/delete_icon_large.gif' title='Delete Data Query Association' alt='Delete Data Query Association' border='0' align='middle'></a>
					</td>
				<?php 
                form_end_row();
                $i++;
            }
        } else {
            print "<tr class='tableRow'><td colspan='4'><em>No associated data queries.</em></td></tr>";
        }
        ?>
		<tr class='odd'>
			<td class='saveRow' colspan="5">
				<table cellspacing="0" cellpadding="1" width="100%">
					<td nowrap>Add Data Query:&nbsp;
						<?php 
        form_dropdown('snmp_query_id', $available_data_queries, 'name', 'id', '', '', '');
        ?>
					</td>
					<td nowrap>Re-Index Method:&nbsp;
						<?php 
        form_dropdown('reindex_method', $reindex_types, '', '', read_config_option('reindex_method'), '', '');
        ?>
					</td>
					<td align="right">
						&nbsp;<input type="submit" value="Add" name="add_dq_x" title="Add Data Query to Device">
					</td>
				</table>
				<a name='dqtop'></a>
			</td>
		</tr>

		<?php 
        html_end_box();
    }
    form_save_button('host.php', 'return');
    api_plugin_hook('host_edit_bottom');
}
示例#8
0
function data_query_edit() {
	global $colors, $fields_data_query_edit, $config;

	if (!empty($_GET["id"])) {
		$snmp_query = db_fetch_row("select * from snmp_query where id=" . $_GET["id"]);
		$header_label = "[edit: " . $snmp_query["name"] . "]";
	}else{
		$header_label = "[new]";
	}

	html_start_box("<strong>Data Queries</strong> $header_label", "98%", $colors["header"], "3", "center", "");

	draw_edit_form(array(
		"config" => array(),
		"fields" => inject_form_variables($fields_data_query_edit, (isset($snmp_query) ? $snmp_query : array()))
		));

	html_end_box();

	if (!empty($snmp_query["id"])) {
		$xml_filename = str_replace("<path_cacti>", $config["base_path"], $snmp_query["xml_path"]);

		if ((file_exists($xml_filename)) && (is_file($xml_filename))) {
			$text = "<font color='#0d7c09'><strong>Successfully located XML file</strong></font>";
			$xml_file_exists = true;
		}else{
			$text = "<font color='#ff0000'><strong>Could not locate XML file.</strong></font>";
			$xml_file_exists = false;
		}

		html_start_box("", "98%", "aaaaaa", "3", "center", "");
		print "<tr bgcolor='#f5f5f5'><td>$text</td></tr>";
		html_end_box();

		if ($xml_file_exists == true) {
			html_start_box("<strong>Associated Graph Templates</strong>", "98%", $colors["header"], "3", "center", "data_queries.php?action=item_edit&snmp_query_id=" . $snmp_query["id"]);

			print "	<tr bgcolor='#" . $colors["header_panel"] . "'>
					<td><span style='color: white; font-weight: bold;'>Name</span></td>
					<td><span style='color: white; font-weight: bold;'>Graph Template Name</span></td>
					<td></td>
				</tr>";

			$snmp_query_graphs = db_fetch_assoc("select
				snmp_query_graph.id,
				graph_templates.name as graph_template_name,
				snmp_query_graph.name
				from snmp_query_graph
				left join graph_templates on snmp_query_graph.graph_template_id=graph_templates.id
				where snmp_query_graph.snmp_query_id=" . $snmp_query["id"] . "
				order by snmp_query_graph.name");

			$i = 0;
			if (sizeof($snmp_query_graphs) > 0) {
			foreach ($snmp_query_graphs as $snmp_query_graph) {
				form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],$i); $i++;
				?>
					<td>
						<strong><a href="data_queries.php?action=item_edit&id=<?php print $snmp_query_graph["id"];?>&snmp_query_id=<?php print $snmp_query["id"];?>"><?php print $snmp_query_graph["name"];?></a></strong>
					</td>
					<td>
						<?php print $snmp_query_graph["graph_template_name"];?>
					</td>
					<td align="right">
						<a href="data_queries.php?action=item_remove&id=<?php print $snmp_query_graph["id"];?>&snmp_query_id=<?php print $snmp_query["id"];?>"><img src="images/delete_icon.gif" width="10" height="10" border="0" alt="Delete"></a>
					</td>
				</tr>
				<?php
			}
			}else{
				print "<tr><td><em>No Graph Templates Defined.</em></td></tr>";
			}

			html_end_box();
		}
	}

	form_save_button("data_queries.php");
}
示例#9
0
function input_edit() {
	global $colors, $consolidation_functions, $graph_item_types, $struct_graph_item, $fields_graph_template_input_edit;

	$header_label = "[edit graph: " . db_fetch_cell("select name from graph_templates where id=" . $_GET["graph_template_id"]) . "]";

	/* get a list of all graph item field names and populate an array for user display */
	while (list($field_name, $field_array) = each($struct_graph_item)) {
		if ($field_array["method"] != "view") {
			$graph_template_items[$field_name] = $field_array["friendly_name"];
		}
	}

	if (!empty($_GET["id"])) {
		$graph_template_input = db_fetch_row("select * from graph_template_input where id=" . $_GET["id"]);
	}

	html_start_box("<strong>Graph Item Inputs</strong> $header_label", "98%", $colors["header"], "3", "center", "");

	draw_edit_form(array(
		"config" => array(),
		"fields" => inject_form_variables($fields_graph_template_input_edit, (isset($graph_template_input) ? $graph_template_input : array()), (isset($graph_template_items) ? $graph_template_items : array()), $_GET)
		));

	if (!(isset($_GET["id"]))) { $_GET["id"] = 0; }

	$item_list = db_fetch_assoc("select
		CONCAT_WS(' - ',data_template_data.name,data_template_rrd.data_source_name) as data_source_name,
		graph_templates_item.text_format,
		graph_templates_item.id as graph_templates_item_id,
		graph_templates_item.graph_type_id,
		graph_templates_item.consolidation_function_id,
		graph_template_input_defs.graph_template_input_id
		from graph_templates_item
		left join graph_template_input_defs on (graph_template_input_defs.graph_template_item_id=graph_templates_item.id and graph_template_input_defs.graph_template_input_id=" . $_GET["id"] . ")
		left join data_template_rrd on graph_templates_item.task_item_id=data_template_rrd.id
		left join data_local on data_template_rrd.local_data_id=data_local.id
		left join data_template_data on data_local.id=data_template_data.local_data_id
		where graph_templates_item.local_graph_id=0
		and graph_templates_item.graph_template_id=" . $_GET["graph_template_id"] . "
		order by graph_templates_item.sequence");

	form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],1); ?>
		<td width="50%">
			<font class="textEditTitle">Associated Graph Items</font><br>
			Select the graph items that you want to accept user input for.
		</td>
		<td>
		<?php
		$i = 0; $any_selected_item = "";
		if (sizeof($item_list) > 0) {
		foreach ($item_list as $item) {
			if ($item["graph_template_input_id"] == "") {
				$old_value = "";
			}else{
				$old_value = "on";
				$any_selected_item = $item["graph_templates_item_id"];
			}

			if ($graph_item_types{$item["graph_type_id"]} == "GPRINT") {
				$start_bold = "";
				$end_bold = "";
			}else{
				$start_bold = "<strong>";
				$end_bold = "</strong>";
			}

			$name = "$start_bold Item #" . ($i+1) . ": " . $graph_item_types{$item["graph_type_id"]} . " (" . $consolidation_functions{$item["consolidation_function_id"]} . ")$end_bold";
			form_checkbox("i_" . $item["graph_templates_item_id"], $old_value, $name,"",$_GET["graph_template_id"],true); print "<br>";

			$i++;
		}
		}else{
			print "<em>No Items</em>";
		}
		?>
		</td>
	</tr>

	<?php
	html_end_box();

	form_hidden_box("any_selected_item", $any_selected_item, "");

	form_save_button("graph_templates.php?action=template_edit&id=" . $_GET["graph_template_id"]);
}
示例#10
0
function gprint_edit() {
	$_gprint_preset_id = get_get_var_number("id");

	if (empty($_gprint_preset_id)) {
		$header_label = "[new]";
	}else{
		$gprint = api_data_preset_gprint_get($_gprint_preset_id);

		$header_label = "[edit: " . $gprint["name"] . "]";
	}

	form_start("presets_gprint.php", "form_gprint");

	/* ==================== Box: Colors ==================== */

	html_start_box("<strong>" . _("GPRINT Presets") . "</strong> $header_label");
	_data_preset_gprint__name("name", (isset($gprint["name"]) ? $gprint["name"] : ""), (isset($gprint["id"]) ? $gprint["id"] : "0"));
	_data_preset_gprint__gprint_text("gprint_text", (isset($gprint["gprint_text"]) ? $gprint["gprint_text"] : ""), (isset($gprint["id"]) ? $gprint["id"] : "0"));
	html_end_box();

	form_hidden_box("preset_gprint_id", $_gprint_preset_id);
	form_hidden_box("action_post", "gprint_preset_edit");

	form_save_button("presets.php?action=view_gprint", "save_gprint");
}
示例#11
0
文件: host.php 项目: songchin/Cacti
function host_edit()
{
    global $colors, $fields_host_edit, $reindex_types;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var("id"));
    /* ==================================================== */
    display_output_messages();
    if (!empty($_GET["id"])) {
        $host = db_fetch_row("select * from host where id=" . $_GET["id"]);
        $header_label = "[edit: " . $host["description"] . "]";
    } else {
        $header_label = "[new]";
    }
    if (!empty($host["id"])) {
        ?>
		<table width="100%" align="center">
			<tr>
				<td class="textInfo" colspan="2">
					<?php 
        print $host["description"];
        ?>
 (<?php 
        print $host["hostname"];
        ?>
)
				</td>
			</tr>
			<tr>
				<td class="textHeader">
				<?php 
        if ($host["availability_method"] == AVAIL_SNMP || $host["availability_method"] == AVAIL_SNMP_AND_PING || $host["availability_method"] == AVAIL_SNMP_OR_PING) {
            ?>
					SNMP Information<br>

					<span style="font-size: 10px; font-weight: normal; font-family: monospace;">
					<?php 
            if ($host["snmp_community"] == "" && $host["snmp_username"] == "" || $host["snmp_version"] == 0) {
                print "<span style='color: #ab3f1e; font-weight: bold;'>SNMP not in use</span>\n";
            } else {
                $snmp_system = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.1.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"], $host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI);
                /* modify for some system descriptions */
                /* 0000937: System output in hosts.php poor for Alcatel */
                if (substr_count($snmp_system, "00:")) {
                    $snmp_system = str_replace("00:", "", $snmp_system);
                    $snmp_system = str_replace(":", " ", $snmp_system);
                }
                if ($snmp_system == "") {
                    print "<span style='color: #ff0000; font-weight: bold;'>SNMP error</span>\n";
                } else {
                    $snmp_uptime = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.3.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"], $host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI);
                    $snmp_hostname = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.5.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"], $host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI);
                    $snmp_location = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.6.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"], $host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI);
                    $snmp_contact = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.4.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"], $host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI);
                    print "<strong>System:</strong>" . html_split_string($snmp_system) . "<br>\n";
                    $days = intval($snmp_uptime / (60 * 60 * 24 * 100));
                    $remainder = $snmp_uptime % (60 * 60 * 24 * 100);
                    $hours = intval($remainder / (60 * 60 * 100));
                    $remainder = $remainder % (60 * 60 * 100);
                    $minutes = intval($remainder / (60 * 100));
                    print "<strong>Uptime:</strong> {$snmp_uptime}";
                    print "&nbsp;({$days} days, {$hours} hours, {$minutes} minutes)<br>\n";
                    print "<strong>Hostname:</strong> {$snmp_hostname}<br>\n";
                    print "<strong>Location:</strong> {$snmp_location}<br>\n";
                    print "<strong>Contact:</strong> {$snmp_contact}<br>\n";
                }
            }
            ?>
					</span>
				<?php 
        }
        if ($host["availability_method"] == AVAIL_PING || $host["availability_method"] == AVAIL_SNMP_AND_PING || $host["availability_method"] == AVAIL_SNMP_OR_PING) {
            /* create new ping socket for host pinging */
            $ping = new Net_Ping();
            $ping->host = $host;
            $ping->port = $host["ping_port"];
            /* perform the appropriate ping check of the host */
            if ($ping->ping($host["availability_method"], $host["ping_method"], $host["ping_timeout"], $host["ping_retries"])) {
                $host_down = false;
                $color = "#000000";
            } else {
                $host_down = true;
                $color = "#ff0000";
            }
            ?>
					<br>Ping Results<br>
					<span style="font-size: 10px; font-weight: normal; color: <?php 
            print $color;
            ?>
; font-family: monospace;">
					<?php 
            print $ping->ping_response;
            ?>
					</span>
				<?php 
        } else {
            if ($host["availability_method"] == AVAIL_NONE) {
                ?>
					No Availability Check In Use<br>
				<?php 
            }
        }
        ?>
				</td>
				<td class="textInfo" valign="top">
					<span style="color: #c16921;">*</span><a href="graphs_new.php?host_id=<?php 
        print $host["id"];
        ?>
">Create Graphs for this Host</a><br>
					<span style="color: #c16921;">*</span><a href="data_sources.php?host_id=<?php 
        print $host["id"];
        ?>
&ds_rows=30&filter=&template_id=-1&method_id=-1&page=1">Data Source List</a><br>
					<span style="color: #c16921;">*</span><a href="graphs.php?host_id=<?php 
        print $host["id"];
        ?>
&graph_rows=30&filter=&template_id=-1&page=1">Graph List</a>
				</td>
			</tr>
		</table>
		<?php 
    }
    html_start_box("<strong>Devices</strong> {$header_label}", "100%", $colors["header"], "3", "center", "");
    /* preserve the host template id if passed in via a GET variable */
    if (!empty($_GET["host_template_id"])) {
        $fields_host_edit["host_template_id"]["value"] = $_GET["host_template_id"];
    }
    draw_edit_form(array("config" => array("form_name" => "chk"), "fields" => inject_form_variables($fields_host_edit, isset($host) ? $host : array())));
    html_end_box();
    ?>
	<script type="text/javascript">
	<!--

	// default snmp information
	var snmp_community       = document.getElementById('snmp_community').value;
	var snmp_username        = document.getElementById('snmp_username').value;
	var snmp_password        = document.getElementById('snmp_password').value;
	var snmp_auth_protocol   = document.getElementById('snmp_auth_protocol').value;
	var snmp_priv_passphrase = document.getElementById('snmp_priv_passphrase').value;
	var snmp_priv_protocol   = document.getElementById('snmp_priv_protocol').value;
	var snmp_context         = document.getElementById('snmp_context').value;
	var snmp_port            = document.getElementById('snmp_port').value;
	var snmp_timeout         = document.getElementById('snmp_timeout').value;
	var max_oids             = document.getElementById('max_oids').value;

	// default ping methods
	var ping_method    = document.getElementById('ping_method').value;
	var ping_port      = document.getElementById('ping_port').value;
	var ping_timeout   = document.getElementById('ping_timeout').value;
	var ping_retries   = document.getElementById('ping_retries').value;

	var availability_methods = document.getElementById('availability_method').options;
	var num_methods          = document.getElementById('availability_method').length;
	var selectedIndex        = document.getElementById('availability_method').selectedIndex;

	var agent = navigator.userAgent;
	agent = agent.match("MSIE");

	function setPingVisibility() {
		availability_method = document.getElementById('availability_method').value;
		ping_method         = document.getElementById('ping_method').value;

		/* debugging, uncomment as required */
		//alert("The availability method is '" + availability_method + "'");
		//alert("The ping method is '" + ping_method + "'");

		switch(availability_method) {
		case "0": // none
			document.getElementById('row_ping_method').style.display  = "none";
			document.getElementById('row_ping_port').style.display    = "none";
			document.getElementById('row_ping_timeout').style.display = "none";
			document.getElementById('row_ping_retries').style.display = "none";

			break;
		case "2": // snmp
			document.getElementById('row_ping_method').style.display  = "none";
			document.getElementById('row_ping_port').style.display    = "none";
			document.getElementById('row_ping_timeout').style.display = "";
			document.getElementById('row_ping_retries').style.display = "";

			break;
		default: // ping ok
			switch(ping_method) {
			case "1": // ping icmp
				document.getElementById('row_ping_method').style.display  = "";
				document.getElementById('row_ping_port').style.display    = "none";
				document.getElementById('row_ping_timeout').style.display = "";
				document.getElementById('row_ping_retries').style.display = "";

				break;
			case "2": // ping udp
			case "3": // ping tcp
				document.getElementById('row_ping_method').style.display  = "";
				document.getElementById('row_ping_port').style.display    = "";
				document.getElementById('row_ping_timeout').style.display = "";
				document.getElementById('row_ping_retries').style.display = "";

				break;
			}

			break;
		}
	}

	function addSelectItem(item, formObj) {
		if (agent != "MSIE") {
			formObj.add(item,null); // standards compliant
		}else{
			formObj.add(item);      // IE only
		}
	}

	function setAvailability(type) {
		/* get the availability structure */
		var am=document.getElementById('availability_method');

		/* get current selectedIndex */
		selectedIndex = document.getElementById('availability_method').selectedIndex;

		/* debugging uncomment as required */
		//alert("The selectedIndex is '" + selectedIndex + "'");
		//alert("The array length is '" + am.length + "'");

		switch(type) {
		case "NoSNMP":
			/* remove snmp options */
			if (am.length == 5) {
				am.remove(1);
				am.remove(1);
				am.remove(1);
			}

			/* set the index to something valid, like "ping" */
			if (selectedIndex > 1) {
				am.selectedIndex=1;
			}

			break;
		case "All":
			/* restore all options */
			if (am.length == 2) {
				am.remove(0);
				am.remove(0);

				var a=document.createElement('option');
				var b=document.createElement('option');
				var c=document.createElement('option');
				var d=document.createElement('option');
				var e=document.createElement('option');

				a.value="0";
				a.text="None";
				addSelectItem(a,am);

				b.value="1";
				b.text="Ping and SNMP";
				addSelectItem(b,am);

				e.value="4";
				e.text="Ping or SNMP";
				addSelectItem(e,am);

				c.value="2";
				c.text="SNMP";
				addSelectItem(c,am);

				d.value="3";
				d.text="Ping";
				addSelectItem(d,am);

				/* restore the correct index number */
				if (selectedIndex == 0) {
					am.selectedIndex = 0;
				}else{
					am.selectedIndex = 3;
				}
			}

			break;
		}

		setAvailabilityVisibility(type, am.selectedIndex);
		setPingVisibility();
	}

	function setAvailabilityVisibility(type, selectedIndex) {
		switch(type) {
		case "NoSNMP":
			switch(selectedIndex) {
			case "0": // availability none
				document.getElementById('row_ping_method').style.display="none";
				document.getElementById('ping_method').value=0;

				break;
			case "1": // ping
				document.getElementById('row_ping_method').style.display="";
				document.getElementById('ping_method').value=ping_method;

				break;
			}
		case "All":
			switch(selectedIndex) {
			case "0": // availability none
				document.getElementById('row_ping_method').style.display="none";
				document.getElementById('ping_method').value=0;

				break;
			case "1": // ping and snmp
			case "3": // ping
			case "4": // ping or snmp
				if ((document.getElementById('row_ping_method').style.display == "none") ||
					(document.getElementById('row_ping_method').style.display == undefined)) {
					document.getElementById('ping_method').value=ping_method;
					document.getElementById('row_ping_method').style.display="";
				}

				break;
			case "2": // snmp
				document.getElementById('row_ping_method').style.display="none";
				document.getElementById('ping_method').value="0";

				break;
			}
		}
	}

	function changeHostForm() {
		snmp_version        = document.getElementById('snmp_version').value;

		switch(snmp_version) {
		case "0":
			setAvailability("NoSNMP");
			setSNMP("None");

			break;
		case "1":
		case "2":
			setAvailability("All");
			setSNMP("v1v2");

			break;
		case "3":
			setAvailability("All");
			setSNMP("v3");

			break;
		}
	}

	function setSNMP(snmp_type) {
		switch(snmp_type) {
		case "None":
			document.getElementById('row_snmp_username').style.display        = "none";
			document.getElementById('row_snmp_password').style.display        = "none";
			document.getElementById('row_snmp_community').style.display       = "none";
			document.getElementById('row_snmp_auth_protocol').style.display   = "none";
			document.getElementById('row_snmp_priv_passphrase').style.display = "none";
			document.getElementById('row_snmp_priv_protocol').style.display   = "none";
			document.getElementById('row_snmp_context').style.display         = "none";
			document.getElementById('row_snmp_port').style.display            = "none";
			document.getElementById('row_snmp_timeout').style.display         = "none";
			document.getElementById('row_max_oids').style.display             = "none";

			break;
		case "v1v2":
			document.getElementById('row_snmp_username').style.display        = "none";
			document.getElementById('row_snmp_password').style.display        = "none";
			document.getElementById('row_snmp_community').style.display       = "";
			document.getElementById('row_snmp_auth_protocol').style.display   = "none";
			document.getElementById('row_snmp_priv_passphrase').style.display = "none";
			document.getElementById('row_snmp_priv_protocol').style.display   = "none";
			document.getElementById('row_snmp_context').style.display         = "none";
			document.getElementById('row_snmp_port').style.display            = "";
			document.getElementById('row_snmp_timeout').style.display         = "";
			document.getElementById('row_max_oids').style.display             = "";

			break;
		case "v3":
			document.getElementById('row_snmp_username').style.display        = "";
			document.getElementById('row_snmp_password').style.display        = "";
			document.getElementById('row_snmp_community').style.display       = "none";
			document.getElementById('row_snmp_auth_protocol').style.display   = "";
			document.getElementById('row_snmp_priv_passphrase').style.display = "";
			document.getElementById('row_snmp_priv_protocol').style.display   = "";
			document.getElementById('row_snmp_context').style.display         = "";
			document.getElementById('row_snmp_port').style.display            = "";
			document.getElementById('row_snmp_timeout').style.display         = "";
			document.getElementById('row_max_oids').style.display             = "";

			break;
		}
	}

	function addLoadEvent(func) {
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
				if (oldonload) {
					oldonload();
				}
				func();
			}
		}
	}

	addLoadEvent(changeHostForm);

	-->
	</script>
	<?php 
    if (isset($_GET["display_dq_details"]) && isset($_SESSION["debug_log"]["data_query"])) {
        html_start_box("<strong>Data Query Debug Information</strong>", "100%", $colors["header"], "3", "center", "");
        print "<tr><td><span style='font-family: monospace;'>" . debug_log_return("data_query") . "</span></td></tr>";
        html_end_box();
    }
    if (!empty($host["id"])) {
        html_start_box("<strong>Associated Graph Templates</strong>", "100%", $colors["header"], "3", "center", "");
        html_header(array("Graph Template Name", "Status"), 2);
        $selected_graph_templates = db_fetch_assoc("select\n\t\t\tgraph_templates.id,\n\t\t\tgraph_templates.name\n\t\t\tfrom (graph_templates,host_graph)\n\t\t\twhere graph_templates.id=host_graph.graph_template_id\n\t\t\tand host_graph.host_id=" . $_GET["id"] . "\n\t\t\torder by graph_templates.name");
        $available_graph_templates = db_fetch_assoc("SELECT\n\t\t\tgraph_templates.id, graph_templates.name\n\t\t\tFROM snmp_query_graph RIGHT JOIN graph_templates\n\t\t\tON (snmp_query_graph.graph_template_id = graph_templates.id)\n\t\t\tWHERE (((snmp_query_graph.name) Is Null)) ORDER BY graph_templates.name");
        $i = 0;
        if (sizeof($selected_graph_templates) > 0) {
            foreach ($selected_graph_templates as $item) {
                $i++;
                /* get status information for this graph template */
                $is_being_graphed = sizeof(db_fetch_assoc("select id from graph_local where graph_template_id=" . $item["id"] . " and host_id=" . $_GET["id"])) > 0 ? true : false;
                ?>
			<tr>
				<td style="padding: 4px;">
					<strong><?php 
                print $i;
                ?>
)</strong> <?php 
                print $item["name"];
                ?>
				</td>
				<td>
					<?php 
                print $is_being_graphed == true ? "<span style='color: green;'>Is Being Graphed</span> (<a href='graphs.php?action=graph_edit&id=" . db_fetch_cell("select id from graph_local where graph_template_id=" . $item["id"] . " and host_id=" . $_GET["id"] . " limit 0,1") . "'>Edit</a>)" : "<span style='color: #484848;'>Not Being Graphed</span>";
                ?>
				</td>
				<td align='right' nowrap>
					<a href='host.php?action=gt_remove&id=<?php 
                print $item["id"];
                ?>
&host_id=<?php 
                print $_GET["id"];
                ?>
'><img src='images/delete_icon_large.gif' title='Delete Graph Template Association' alt='Delete Graph Template Association' border='0' align='absmiddle'></a>
				</td>
			</tr>
			<?php 
            }
        } else {
            print "<tr><td><em>No associated graph templates.</em></td></tr>";
        }
        ?>
		<tr bgcolor="#<?php 
        print $colors["form_alternate1"];
        ?>
">
			<td colspan="4">
				<table cellspacing="0" cellpadding="1" width="100%">
					<td nowrap>Add Graph Template:&nbsp;
						<?php 
        form_dropdown("graph_template_id", $available_graph_templates, "name", "id", "", "", "");
        ?>
					</td>
					<td align="right">
						&nbsp;<input type="image" src="images/button_add.gif" alt="Add" name="add_gt" align="absmiddle">
					</td>
				</table>
			</td>
		</tr>

		<?php 
        html_end_box();
        html_start_box("<strong>Associated Data Queries</strong>", "100%", $colors["header"], "3", "center", "");
        html_header(array("Data Query Name", "Debugging", "Re-Index Method", "Status"), 2);
        $selected_data_queries = db_fetch_assoc("select\n\t\t\tsnmp_query.id,\n\t\t\tsnmp_query.name,\n\t\t\thost_snmp_query.reindex_method\n\t\t\tfrom (snmp_query,host_snmp_query)\n\t\t\twhere snmp_query.id=host_snmp_query.snmp_query_id\n\t\t\tand host_snmp_query.host_id=" . $_GET["id"] . "\n\t\t\torder by snmp_query.name");
        $available_data_queries = db_fetch_assoc("select\n\t\t\tsnmp_query.id,\n\t\t\tsnmp_query.name\n\t\t\tfrom snmp_query\n\t\t\torder by snmp_query.name");
        $keeper = array();
        foreach ($available_data_queries as $item) {
            if (sizeof(db_fetch_assoc("SELECT snmp_query_id FROM host_snmp_query " . " WHERE ((host_id=" . $_GET["id"] . ")" . " and (snmp_query_id=" . $item["id"] . "))")) > 0) {
                /* do nothing */
            } else {
                array_push($keeper, $item);
            }
        }
        $available_data_queries = $keeper;
        $i = 0;
        if (sizeof($selected_data_queries) > 0) {
            foreach ($selected_data_queries as $item) {
                $i++;
                /* get status information for this data query */
                $num_dq_items = sizeof(db_fetch_assoc("select snmp_index from host_snmp_cache where host_id=" . $_GET["id"] . " and snmp_query_id=" . $item["id"]));
                $num_dq_rows = sizeof(db_fetch_assoc("select snmp_index from host_snmp_cache where host_id=" . $_GET["id"] . " and snmp_query_id=" . $item["id"] . " group by snmp_index"));
                $status = "success";
                ?>
			<tr>
				<td style="padding: 4px;">
					<strong><?php 
                print $i;
                ?>
)</strong> <?php 
                print $item["name"];
                ?>
				</td>
				<td>
					(<a href="host.php?action=query_verbose&id=<?php 
                print $item["id"];
                ?>
&host_id=<?php 
                print $_GET["id"];
                ?>
">Verbose Query</a>)
				</td>
				<td>
					<?php 
                print $reindex_types[$item["reindex_method"]];
                ?>
				</td>
				<td>
					<?php 
                print $status == "success" ? "<span style='color: green;'>Success</span>" : "<span style='color: green;'>Fail</span>";
                ?>
 [<?php 
                print $num_dq_items;
                ?>
 Item<?php 
                print $num_dq_items == 1 ? "" : "s";
                ?>
, <?php 
                print $num_dq_rows;
                ?>
 Row<?php 
                print $num_dq_rows == 1 ? "" : "s";
                ?>
]
				</td>
				<td align='right' nowrap>
					<a href='host.php?action=query_reload&id=<?php 
                print $item["id"];
                ?>
&host_id=<?php 
                print $_GET["id"];
                ?>
'><img src='images/reload_icon_small.gif' title='Reload Data Query' alt='Reload Data Query' border='0' align='absmiddle'></a>&nbsp;
					<a href='host.php?action=query_remove&id=<?php 
                print $item["id"];
                ?>
&host_id=<?php 
                print $_GET["id"];
                ?>
'><img src='images/delete_icon_large.gif' title='Delete Data Query Association' alt='Delete Data Query Association' border='0' align='absmiddle'></a>
				</td>
			</tr>
			<?php 
            }
        } else {
            print "<tr><td><em>No associated data queries.</em></td></tr>";
        }
        ?>
		<tr bgcolor="#<?php 
        print $colors["form_alternate1"];
        ?>
">
			<td colspan="5">
				<table cellspacing="0" cellpadding="1" width="100%">
					<td nowrap>Add Data Query:&nbsp;
						<?php 
        form_dropdown("snmp_query_id", $available_data_queries, "name", "id", "", "", "");
        ?>
					</td>
					<td nowrap>Re-Index Method:&nbsp;
						<?php 
        form_dropdown("reindex_method", $reindex_types, "", "", read_config_option("reindex_method"), "", "");
        ?>
					</td>
					<td align="right">
						&nbsp;<input type="image" src="images/button_add.gif" alt="Add" name="add_dq" align="absmiddle">
					</td>
				</table>
			</td>
		</tr>

		<?php 
        html_end_box();
    }
    form_save_button("host.php");
}
示例#12
0
function template_edit()
{
    global $colors, $struct_graph, $image_types, $fields_graph_template_template_edit;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var("id"));
    /* ==================================================== */
    /* graph item list goes here */
    if (!empty($_GET["id"])) {
        item();
    }
    if (!empty($_GET["id"])) {
        $template = db_fetch_row("select * from graph_templates where id=" . $_GET["id"]);
        $template_graph = db_fetch_row("select * from graph_templates_graph where graph_template_id=" . $_GET["id"] . " and local_graph_id=0");
        $header_label = "[edit: " . $template["name"] . "]";
    } else {
        $header_label = "[new]";
    }
    html_start_box("<strong>Template</strong> {$header_label}", "100%", $colors["header"], "3", "center", "");
    draw_edit_form(array("config" => array(), "fields" => inject_form_variables($fields_graph_template_template_edit, isset($template) ? $template : array(), isset($template_graph) ? $template_graph : array())));
    html_end_box();
    html_start_box("<strong>Graph Template</strong>", "100%", $colors["header"], "3", "center", "");
    $form_array = array();
    while (list($field_name, $field_array) = each($struct_graph)) {
        $form_array += array($field_name => $struct_graph[$field_name]);
        $form_array[$field_name]["value"] = isset($template_graph) ? $template_graph[$field_name] : "";
        $form_array[$field_name]["form_id"] = isset($template_graph) ? $template_graph["id"] : "0";
        $form_array[$field_name]["description"] = "";
        $form_array[$field_name]["sub_checkbox"] = array("name" => "t_" . $field_name, "friendly_name" => "Use Per-Graph Value (Ignore this Value)", "value" => isset($template_graph) ? $template_graph["t_" . $field_name] : "");
    }
    draw_edit_form(array("config" => array(), "fields" => $form_array));
    form_hidden_box("rrdtool_version", read_config_option("rrdtool_version"), "");
    html_end_box();
    form_save_button("graph_templates.php");
    //Now we need some javascript to make it dynamic
    ?>
<script language="JavaScript">

dynamic();

function dynamic() {
	//alert("RRDTool Version is '" + document.getElementById('rrdtool_version').value + "'");
	//alert("Log is '" + document.getElementById('auto_scale_log').checked + "'");
	document.getElementById('t_scale_log_units').disabled=true;
	document.getElementById('scale_log_units').disabled=true;
	if ((document.getElementById('rrdtool_version').value != 'rrd-1.0.x') &&
		(document.getElementById('auto_scale_log').checked)) {
		document.getElementById('t_scale_log_units').disabled=false;
		document.getElementById('scale_log_units').disabled=false;
	}
}

function changeScaleLog() {
	//alert("Log changed to '" + document.getElementById('auto_scale_log').checked + "'");
	document.getElementById('t_scale_log_units').disabled=true;
	document.getElementById('scale_log_units').disabled=true;
	if ((document.getElementById('rrdtool_version').value != 'rrd-1.0.x') &&
		(document.getElementById('auto_scale_log').checked)) {
		document.getElementById('t_scale_log_units').disabled=false;
		document.getElementById('scale_log_units').disabled=false;
	}
}
</script>
<?php 
}
示例#13
0
function graph_edit()
{
    global $colors, $struct_graph, $image_types, $consolidation_functions, $graph_item_types, $struct_graph_item;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var("id"));
    /* ==================================================== */
    /* modify for multi user start */
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        // graph add
        if ($_GET["id"] == "") {
            if ($_GET["host_id"] != -1) {
                input_validate_input_number(get_request_var("host_id"));
                if (!check_host($_GET["host_id"])) {
                    access_denied();
                }
            }
            // graph edit
        } else {
            $permission = check_graph($_GET["id"]);
            if ($permission != GRAPH_PRIVATE && $permission != GRAPH_PRIVATE + GRAPH_PUBLIC) {
                access_denied();
            }
        }
    }
    /* modify for multi user end */
    $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["id"]);
        $graphs = db_fetch_row("select * from graph_templates_graph where local_graph_id=" . $_GET["id"]);
        $graphs_template = db_fetch_row("select * from graph_templates_graph where id={$local_graph_template_graph_id}");
        $host_id = db_fetch_cell("select host_id from graph_local where id=" . $_GET["id"]);
        $header_label = "[edit: " . htmlspecialchars(get_graph_title($_GET["id"])) . "]";
        if ($graphs["graph_template_id"] == "0") {
            $use_graph_template = false;
        }
    } else {
        $header_label = "[new]";
        $use_graph_template = false;
    }
    /* modify for multi user start */
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        unset($_GET["debug"]);
    }
    /* modify for multi user end */
    /* handle debug mode */
    if (isset($_GET["debug"])) {
        if ($_GET["debug"] == "0") {
            kill_session_var("graph_debug_mode");
        } elseif ($_GET["debug"] == "1") {
            $_SESSION["graph_debug_mode"] = true;
        }
    }
    if (!empty($_GET["id"])) {
        ?>
		<table width="100%" align="center">
			<tr>
				<td class="textInfo" colspan="2" valign="top">
					<?php 
        print htmlspecialchars(get_graph_title($_GET["id"]));
        ?>
				</td>
				<td class="textInfo" align="right" valign="top">
                    <?php 
        /* modify for multi user start */
        if ($_SESSION["permission"] == ACCESS_ADMINISTRATOR) {
            ?>
					<span style="color: #c16921;">*<a href='<?php 
            print htmlspecialchars("graphs.php?action=graph_edit&id=" . (isset($_GET["id"]) ? $_GET["id"] : "0") . "&debug=" . (isset($_SESSION["graph_debug_mode"]) ? "0" : "1"));
            ?>
'>Turn <strong><?php 
            print isset($_SESSION["graph_debug_mode"]) ? "Off" : "On";
            ?>
</strong> Graph Debug Mode.</a></span><br>
					<?php 
        }
        if (!empty($graphs["graph_template_id"]) && $_SESSION["permission"] == ACCESS_ADMINISTRATOR) {
            ?>
<span style="color: #c16921;">*<a href='<?php 
            print htmlspecialchars("graph_templates.php?action=template_edit&id=" . (isset($graphs["graph_template_id"]) ? $graphs["graph_template_id"] : "0"));
            ?>
'>Edit Graph Template.</a></span><br><?php 
        }
        /* modify for multi user end */
        if (!empty($_GET["host_id"]) || !empty($host_id)) {
            ?>
<span style="color: #c16921;">*<a href='<?php 
            print htmlspecialchars("host.php?action=edit&id=" . (isset($_GET["host_id"]) ? $_GET["host_id"] : $host_id));
            ?>
'>Edit Host.</a></span><br><?php 
        }
        ?>
				</td>
			</tr>
		</table>
		<br>
		<?php 
    }
    html_start_box("<strong>Graph Template Selection</strong> {$header_label}", "100%", $colors["header"], "3", "center", "");
    $form_array = array("graph_template_id" => array("method" => "drop_sql", "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.", "value" => isset($graphs) ? $graphs["graph_template_id"] : "0", "none_value" => "None", "sql" => "select graph_templates.id,graph_templates.name from graph_templates order by name"), "host_id" => array("method" => "drop_sql", "friendly_name" => "Host", "description" => "Choose the host that this graph belongs to.", "value" => isset($_GET["host_id"]) ? $_GET["host_id"] : $host_id, "none_value" => "None", "sql" => "select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"), "graph_template_graph_id" => array("method" => "hidden", "value" => isset($graphs) ? $graphs["id"] : "0"), "local_graph_id" => array("method" => "hidden", "value" => isset($graphs) ? $graphs["local_graph_id"] : "0"), "local_graph_template_graph_id" => array("method" => "hidden", "value" => isset($graphs) ? $graphs["local_graph_template_graph_id"] : "0"), "_graph_template_id" => array("method" => "hidden", "value" => isset($graphs) ? $graphs["graph_template_id"] : "0"), "_host_id" => array("method" => "hidden", "value" => isset($host_id) ? $host_id : "0"));
    /* modify for multi user start */
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        unset($form_array["graph_template_id"]["none_value"]);
        $form_array["graph_template_id"]["sql"] = "SELECT graph_templates.id,graph_templates.name FROM graph_templates WHERE name NOT LIKE '%@system' ORDER BY name";
        unset($form_array["host_id"]["none_value"]);
        $form_array["host_id"]["sql"] = "\r\n            SELECT host.id,CONCAT_WS('',host.description,' (',host.hostname,')') AS name FROM host \r\n                INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3' \r\n            ORDER BY host.description,host.hostname";
    }
    /* modify for multi user end */
    draw_edit_form(array("config" => array(), "fields" => $form_array));
    html_end_box();
    /* 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"], "3", "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["id"], "|field|_|id|", "<strong>Graph Item Fields</strong>", true);
        html_end_box();
    }
    /* graph item list goes here */
    if (!empty($_GET["id"]) && empty($graphs["graph_template_id"])) {
        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["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["output_flag"] = RRDTOOL_OUTPUT_STDERR;
            $graph_data_array["print_source"] = 1;
            ?>
					<td>
						<span class="textInfo">RRDTool Command:</span><br>
						<pre><?php 
            print @rrdtool_function_graph($_GET["id"], 1, $graph_data_array);
            ?>
</pre>
						<span class="textInfo">RRDTool Says:</span><br>
						<?php 
            unset($graph_data_array["print_source"]);
            ?>
						<pre><?php 
            print @rrdtool_function_graph($_GET["id"], 1, $graph_data_array);
            ?>
</pre>
					</td>
					<?php 
        }
        ?>
			</tr>
		</table>
		<br>
		<?php 
    }
    if ((isset($_GET["id"]) || isset($_GET["new"])) && empty($graphs["graph_template_id"])) {
        html_start_box("<strong>Graph Configuration</strong>", "100%", $colors["header"], "3", "center", "");
        $form_array = array();
        while (list($field_name, $field_array) = each($struct_graph)) {
            $form_array += array($field_name => $struct_graph[$field_name]);
            $form_array[$field_name]["value"] = isset($graphs) ? $graphs[$field_name] : "";
            $form_array[$field_name]["form_id"] = isset($graphs) ? $graphs["id"] : "0";
            if (!($use_graph_template == false || $graphs_template["t_" . $field_name] == "on")) {
                $form_array[$field_name]["method"] = "template_" . $form_array[$field_name]["method"];
                $form_array[$field_name]["description"] = "";
            }
        }
        draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => $form_array));
        html_end_box();
    }
    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("rrdtool_version", read_config_option("rrdtool_version"), "");
    form_save_button("graphs.php");
    //Now we need some javascript to make it dynamic
    ?>
<script language="JavaScript">

dynamic();

function dynamic() {
	//alert("RRDTool Version is '" + document.getElementById('rrdtool_version').value + "'");
	//alert("Log is '" + document.getElementById('auto_scale_log').checked + "'");
	if (document.getElementById('scale_log_units')) {
		document.getElementById('scale_log_units').disabled=true;
		if ((document.getElementById('rrdtool_version').value != 'rrd-1.0.x') &&
			(document.getElementById('auto_scale_log').checked)) {
			document.getElementById('scale_log_units').disabled=false;
		}
	}
}

function changeScaleLog() {
	//alert("Log changed to '" + document.getElementById('auto_scale_log').checked + "'");
	if (document.getElementById('scale_log_units')) {
		document.getElementById('scale_log_units').disabled=true;
		if ((document.getElementById('rrdtool_version').value != 'rrd-1.0.x') &&
			(document.getElementById('auto_scale_log').checked)) {
			document.getElementById('scale_log_units').disabled=false;
		}
	}
}
</script>
<?php 
}
示例#14
0
function user_edit() {
	global $colors, $fields_user_user_edit_host;

	if (!empty($_GET["id"])) {
		$user = db_fetch_row("select * from user_auth where id=" . $_GET["id"]);
		$header_label = "[edit: " . $user["username"] . "]";
	}else{
		$header_label = "[new]";
	}

	html_start_box("<strong>User Management</strong> $header_label", "98%", $colors["header"], "3", "center", "");

	draw_edit_form(array(
		"config" => array("form_name" => "chk"),
		"fields" => inject_form_variables($fields_user_user_edit_host, (isset($user) ? $user : array()))
		));

	html_end_box();

	if (!empty($_GET["id"])) {
		/* draw user admin nav tabs */
		?>
		<table class='tabs' width='98%' cellspacing='0' cellpadding='3' align='center'>
			<tr>
				<td width='1'></td>
				<td <?php print ((($_GET["action"] == "user_realms_edit") || ($_GET["action"] == "user_edit")) ? "bgcolor='silver'" : "bgcolor='#DFDFDF'");?> nowrap='nowrap' width='150' align='center' class='tab'>
					<span class='textHeader'><a href='user_admin.php?action=user_realms_edit&id=<?php print $_GET["id"];?>'>Realm Permissions</a></span>
				</td>
				<td width='1'></td>
				<td <?php print (($_GET["action"] == "graph_perms_edit") ? "bgcolor='silver'" : "bgcolor='#DFDFDF'");?> nowrap='nowrap' width='150' align='center' class='tab'>
					<span class='textHeader'><a href='user_admin.php?action=graph_perms_edit&id=<?php print $_GET["id"];?>'>Graph Permissions</a></span>
				</td>
				<td width='1'></td>
				<td <?php print (($_GET["action"] == "graph_settings_edit") ? "bgcolor='silver'" : "bgcolor='#DFDFDF'");?> nowrap='nowrap' width='130' align='center' class='tab'>
					<span class='textHeader'><a href='user_admin.php?action=graph_settings_edit&id=<?php print $_GET["id"];?>'>Graph Settings</a></span>
				</td>
				<td></td>
			</tr>
		</table>
		<?php
	}

	if ($_GET["action"] == "graph_settings_edit") {
		graph_settings_edit();
	}elseif ($_GET["action"] == "user_realms_edit") {
		user_realms_edit();
	}elseif ($_GET["action"] == "graph_perms_edit") {
		graph_perms_edit();
	}else{
		user_realms_edit();
	}

	form_save_button("user_admin.php");
}
示例#15
0
function item_edit() {
	global $colors, $struct_graph_item, $graph_item_types, $consolidation_functions;

	/* ================= input validation ================= */
	input_validate_input_number(get_request_var("id"));
	input_validate_input_number(get_request_var("graph_template_id"));
	/* ==================================================== */

	$header_label = "[edit graph: " . db_fetch_cell("select name from graph_templates where id=" . $_GET["graph_template_id"]) . "]";

	html_start_box("<strong>Graph Template Items</strong> $header_label", "100%", $colors["header"], "3", "center", "");

	if (!empty($_GET["id"])) {
		$template_item = db_fetch_row("select * from graph_templates_item where id=" . $_GET["id"]);
	}

	/* by default, select the LAST DS chosen to make everyone's lives easier */
	if (!empty($_GET["graph_template_id"])) {
		$default = db_fetch_row("select task_item_id from graph_templates_item where graph_template_id=" . $_GET["graph_template_id"] . " and local_graph_id=0 order by sequence DESC");

		if (sizeof($default) > 0) {
			$struct_graph_item["task_item_id"]["default"] = $default["task_item_id"];
		}else{
			$struct_graph_item["task_item_id"]["default"] = 0;
		}
	}

	/* modifications to the default graph items array */
	$struct_graph_item["task_item_id"]["sql"] = "select
		CONCAT_WS('',data_template.name,' - ',' (',data_template_rrd.data_source_name,')') as name,
		data_template_rrd.id
		from (data_template_data,data_template_rrd,data_template)
		where data_template_rrd.data_template_id=data_template.id
		and data_template_data.data_template_id=data_template.id
		and data_template_data.local_data_id=0
		and data_template_rrd.local_data_id=0
		order by data_template.name,data_template_rrd.data_source_name";

	$form_array = array();

	while (list($field_name, $field_array) = each($struct_graph_item)) {
		$form_array += array($field_name => $struct_graph_item[$field_name]);

		$form_array[$field_name]["value"] = (isset($template_item) ? $template_item[$field_name] : "");
		$form_array[$field_name]["form_id"] = (isset($template_item) ? $template_item["id"] : "0");

	}

	if (!empty($_GET["id"])) {
		/* we want to mark the fields that are associated with a graph item input */
		$graph_item_input_fields = db_fetch_assoc("select
			graph_template_input.id,
			graph_template_input.column_name
			from (graph_template_input,graph_template_input_defs)
			where graph_template_input.id=graph_template_input_defs.graph_template_input_id
			and graph_template_input.graph_template_id=" . $_GET["graph_template_id"] . "
			and graph_template_input_defs.graph_template_item_id=" . $_GET["id"] . "
			group by graph_template_input.column_name");

		if (sizeof($graph_item_input_fields) > 0) {
		foreach ($graph_item_input_fields as $field) {
			$form_array{$field["column_name"]}["friendly_name"] .= " [<a href='graph_templates_inputs.php?action=input_edit&id=" . $field["id"] . "&graph_template_id=" . $_GET["graph_template_id"] . "'>Field Not Templated</a>]";
		}
		}
	}

	draw_edit_form(
		array(
			"config" => array(
				),
			"fields" => $form_array
			)
		);

	html_end_box();

	form_hidden_box("graph_template_item_id", (isset($template_item) ? $template_item["id"] : "0"), "");
	form_hidden_box("graph_template_id", $_GET["graph_template_id"], "0");
	form_hidden_box("sequence", (isset($template_item) ? $template_item["sequence"] : "0"), "");
	form_hidden_box("_graph_type_id", (isset($template_item) ? $template_item["graph_type_id"] : "0"), "");
	form_hidden_box("_task_item_id", (isset($template_item) ? $template_item["task_item_id"] : "0"), "");
	form_hidden_box("save_component_item", "1", "");
	form_hidden_box("invisible_alpha", $form_array["alpha"]["value"], "FF");
	form_hidden_box("rrdtool_version", read_config_option("rrdtool_version"), "");

	form_save_button("graph_templates.php?action=template_edit&id=" . $_GET["graph_template_id"]);

//Now we need some javascript to make it dynamic
?>
<script language="JavaScript">

dynamic();

function dynamic() {
	//alert("RRDTool Version is '" + document.getElementById('rrdtool_version').value + "'");
	//alert("Color is '" + document.getElementById('color_id').value + "'");
	document.getElementById('alpha').disabled=true;
	if ((document.getElementById('rrdtool_version').value != 'rrd-1.0.x') &&
		(document.getElementById('color_id').value != 0)) {
		document.getElementById('alpha').disabled=false;
	}
}

function changeColorId() {
	//alert("Selected Color Index is '" + document.getElementById('color_id').selectedIndex + "'");
	if ((document.getElementById('rrdtool_version').value != 'rrd-1.0.x') &&
		(document.getElementById('color_id').selectedIndex != 0)) {
		document.getElementById('alpha').disabled=false;
	}
}
</script>
<?php

}
示例#16
0
function syslog_action_edit()
{
    global $colors, $message_types, $severities;
    include dirname(__FILE__) . "/config.php";
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var("id"));
    input_validate_input_number(get_request_var("type"));
    /* ==================================================== */
    if (isset($_GET["id"]) && $_GET["action"] == "edit") {
        $alert = syslog_db_fetch_row("SELECT *\n\t\t\tFROM `" . $syslogdb_default . "`.`syslog_alert`\n\t\t\tWHERE id=" . $_GET["id"]);
        $header_label = "[edit: " . $alert["name"] . "]";
    } else {
        if (isset($_GET["id"]) && $_GET["action"] == "newedit") {
            $syslog_rec = syslog_db_fetch_row("SELECT * FROM `" . $syslogdb_default . "`.`syslog` WHERE seq=" . $_GET["id"] . " AND logtime='" . $_GET["date"] . "'");
            $header_label = "[new]";
            if (sizeof($syslog_rec)) {
                $alert["message"] = $syslog_rec["message"];
            }
            $alert["name"] = "New Alert Rule";
        } else {
            $header_label = "[new]";
            $alert["name"] = "New Alert Rule";
        }
    }
    $alert_retention = read_config_option("syslog_alert_retention");
    if ($alert_retention != '' && $alert_retention > 0 && $alert_retention < 365) {
        $repeat_end = $alert_retention * 24 * 60 / 5;
    }
    $repeatarray = array(0 => 'Not Set', 1 => '5 Minutes', 2 => '10 Minutes', 3 => '15 Minutes', 4 => '20 Minutes', 6 => '30 Minutes', 8 => '45 Minutes', 12 => '1 Hour', 24 => '2 Hours', 36 => '3 Hours', 48 => '4 Hours', 72 => '6 Hours', 96 => '8 Hours', 144 => '12 Hours', 288 => '1 Day', 576 => '2 Days', 2016 => '1 Week', 4032 => '2 Weeks', 8640 => 'Month');
    if ($repeat_end) {
        foreach ($repeatarray as $i => $value) {
            if ($i > $repeat_end) {
                unset($repeatarray[$i]);
            }
        }
    }
    html_start_box("<strong>Alert Edit</strong> {$header_label}", "100%", $colors["header"], "3", "center", "");
    $fields_syslog_alert_edit = array("spacer0" => array("method" => "spacer", "friendly_name" => "Alert Details"), "name" => array("method" => "textbox", "friendly_name" => "Alert Name", "description" => "Please describe this Alert.", "value" => "|arg1:name|", "max_length" => "250", "size" => 80), "severity" => array("method" => "drop_array", "friendly_name" => "Severity", "description" => "What is the Severity Level of this Alert?", "value" => "|arg1:severity|", "array" => $severities, "default" => "1"), "method" => array("method" => "drop_array", "friendly_name" => "Reporting Method", "description" => "Define how to Alert on the syslog messages.", "value" => "|arg1:method|", "array" => array("0" => "Individual", "1" => "Threshold"), "default" => "0"), "num" => array("method" => "textbox", "friendly_name" => "Threshold", "description" => "For the 'Threshold' method, If the number seen is above this value\n\t\tan Alert will be triggered.", "value" => "|arg1:num|", "size" => "4", "max_length" => "10", "default" => "1"), "type" => array("method" => "drop_array", "friendly_name" => "String Match Type", "description" => "Define how you would like this string matched.  If using the SQL Expression type you may use any valid SQL expression\n\t\tto generate the alarm.  Available fields include 'message', 'facility', 'priority', and 'host'.", "value" => "|arg1:type|", "array" => $message_types, "on_change" => "changeTypes()", "default" => "matchesc"), "message" => array("friendly_name" => "Syslog Message Match String", "description" => "The matching component of the syslog message.", "textarea_rows" => "2", "textarea_cols" => "70", "method" => "textarea", "class" => "textAreaNotes", "value" => "|arg1:message|", "default" => ""), "enabled" => array("method" => "drop_array", "friendly_name" => "Alert Enabled", "description" => "Is this Alert Enabled?", "value" => "|arg1:enabled|", "array" => array("on" => "Enabled", "" => "Disabled"), "default" => "on"), "repeat_alert" => array("friendly_name" => "Re-Alert Cycle", "method" => "drop_array", "array" => $repeatarray, "default" => "0", "description" => "Do not resend this alert again for the same host, until this amount of time has elapsed. For threshold\n\t\tbased alarms, this applies to all hosts.", "value" => "|arg1:repeat_alert|"), "notes" => array("friendly_name" => "Alert Notes", "textarea_rows" => "5", "textarea_cols" => "70", "description" => "Space for Notes on the Alert", "method" => "textarea", "class" => "textAreaNotes", "value" => "|arg1:notes|", "default" => ""), "spacer1" => array("method" => "spacer", "friendly_name" => "Alert Actions"), "open_ticket" => array("method" => "drop_array", "friendly_name" => "Open Ticket", "description" => "Should a Help Desk Ticket be opened for this Alert", "value" => "|arg1:open_ticket|", "array" => array("on" => "Yes", "" => "No"), "default" => ""), "email" => array("method" => "textarea", "friendly_name" => "E-Mails to Notify", "textarea_rows" => "5", "textarea_cols" => "70", "description" => "Please enter a comma delimited list of e-mail addresses to inform.  If you\n\t\twish to send out e-mail to a recipient in SMS format, please prefix that recipient's e-mail address\n\t\twith <b>'sms@'</b>.  For example, if the recipients SMS address is <b>'*****@*****.**'</b>, you would\n\t\tenter it as <b>'sms@2485551212@mycarrier.net'</b> and it will be formatted as an SMS message.", "class" => "textAreaNotes", "value" => "|arg1:email|", "max_length" => "255"), "command" => array("friendly_name" => "Alert Command", "textarea_rows" => "5", "textarea_cols" => "70", "description" => "When an Alert is triggered, run the following command.  The following replacement variables\n\t\tare available <b>'&lt;HOSTNAME&gt;'</b>, <b>'&lt;ALERTID&gt;'</b>, <b>'&lt;MESSAGE&gt;'</b>,\n\t\t<b>'&lt;FACILITY&gt;'</b>, <b>'&lt;PRIORITY&gt;'</b>, <b>'&lt;SEVERITY&gt;'</b>.  Please\n\t\tnote that <b>'&lt;HOSTNAME&gt;'</b> is only available on individual thresholds.", "method" => "textarea", "class" => "textAreaNotes", "value" => "|arg1:command|", "default" => ""), "id" => array("method" => "hidden_zero", "value" => "|arg1:id|"), "_id" => array("method" => "hidden_zero", "value" => "|arg1:id|"), "save_component_alert" => array("method" => "hidden", "value" => "1"));
    echo "<form method='post' autocomplete='off' onsubmit='changeTypes()' action='syslog_alerts.php' name='chk'>";
    draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => inject_form_variables($fields_syslog_alert_edit, isset($alert) ? $alert : array())));
    html_end_box();
    form_save_button("syslog_alerts.php", "", "id");
    ?>
	<script type='text/javascript'>
	function changeTypes() {
		if (document.getElementById('type').value == 'sql') {
			document.getElementById('message').rows = 6;
		}else{
			document.getElementById('message').rows = 2;
		}
	}
	</script>
	<?php 
}
示例#17
0
文件: tree.php 项目: songchin/Cacti
function tree_edit() {
	global $colors, $fields_tree_edit;

	/* ================= input validation ================= */
	input_validate_input_number(get_request_var("id"));
	/* ==================================================== */

	/* clean up subaction */
	if (isset($_REQUEST["subaction"])) {
		$_REQUEST["subaction"] = sanitize_search_string(get_request_var("subaction"));
	}

	if (!empty($_GET["id"])) {
		$tree = db_fetch_row("select * from graph_tree where id=" . $_GET["id"]);
		$header_label = "[edit: " . $tree["name"] . "]";
	}else{
		$header_label = "[new]";
	}

	html_start_box("<strong>Graph Trees</strong> $header_label", "100%", $colors["header"], "3", "center", "");

	draw_edit_form(array(
		"config" => array(),
		"fields" => inject_form_variables($fields_tree_edit, (isset($tree) ? $tree : array()))
		));

	html_end_box();

	if (!empty($_GET["id"])) {
		html_start_box("<strong>Tree Items</strong>", "100%", $colors["header"], "3", "center", "tree.php?action=item_edit&tree_id=" . $tree["id"] . "&parent_id=0");

		?>
		<td>
		<a href='tree.php?action=edit&id=<?php print $_GET["id"];?>&subaction=expand_all'><img src='images/button_expand_all.gif' border='0' alt='Expand All'></a>
		<a href='tree.php?action=edit&id=<?php print $_GET["id"];?>&subaction=colapse_all'><img src='images/button_colapse_all.gif' border='0' alt='Colapse All'></a>
		</td>
		<?php

		print "<tr bgcolor='#" . $colors["header_panel"] . "'>";
			DrawMatrixHeaderItem("Item",$colors["header_text"],1);
			DrawMatrixHeaderItem("Value",$colors["header_text"],1);
			DrawMatrixHeaderItem("&nbsp;",$colors["header_text"],2);
		print "</tr>";

		grow_edit_graph_tree($_GET["id"], "", "");
		html_end_box();
	}

	form_save_button("tree.php");
}
示例#18
0
文件: host.php 项目: songchin/Cacti
function host_edit() {
	global $colors, $fields_host_edit, $reindex_types;

	display_output_messages();

	if (!empty($_GET["id"])) {
		$host = db_fetch_row("select * from host where id=" . $_GET["id"]);
		$header_label = "[edit: " . $host["description"] . "]";
	}else{
		$header_label = "[new]";
	}

	if (!empty($host["id"])) {
		?>
		<table width="98%" align="center">
			<tr>
				<td class="textInfo" colspan="2">
					<?php print $host["description"];?> (<?php print $host["hostname"];?>)
				</td>
			</tr>
			<tr>
				<td class="textHeader">
					SNMP Information<br>

					<span style="font-size: 10px; font-weight: normal; font-family: monospace;">
					<?php
					if (($host["snmp_community"] == "") && ($host["snmp_username"] == "")) {
						print "<span style='color: #ab3f1e; font-weight: bold;'>SNMP not in use</span>\n";
					}else{
						$snmp_system = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.1.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_port"], $host["snmp_timeout"], SNMP_WEBUI);

						if ($snmp_system == "") {
							print "<span style='color: #ff0000; font-weight: bold;'>SNMP error</span>\n";
						}else{
							$snmp_uptime = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.3.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_port"], $host["snmp_timeout"], SNMP_WEBUI);
							$snmp_hostname = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.5.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_port"], $host["snmp_timeout"], SNMP_WEBUI);

							print "<strong>System:</strong> $snmp_system<br>\n";
							print "<strong>Uptime:</strong> $snmp_uptime<br>\n";
							print "<strong>Hostname:</strong> $snmp_hostname<br>\n";
						}
					}
					?>
					</span>
				</td>
				<td class="textInfo" valign="top">
					<span style="color: #c16921;">*</span><a href="graphs_new.php?host_id=<?php print $host["id"];?>">Create Graphs for this Host</a>
				</td>
			</tr>
		</table>
		<br>
		<?php
	}

	html_start_box("<strong>Devices</strong> $header_label", "98%", $colors["header"], "3", "center", "");

	/* preserve the host template id if passed in via a GET variable */
	if (!empty($_GET["host_template_id"])) {
		$fields_host_edit["host_template_id"]["value"] = $_GET["host_template_id"];
	}

	draw_edit_form(array(
		"config" => array("form_name" => "chk"),
		"fields" => inject_form_variables($fields_host_edit, (isset($host) ? $host : array()))
		));

	html_end_box();

	if ((isset($_GET["display_dq_details"])) && (isset($_SESSION["debug_log"]["data_query"]))) {
		html_start_box("<strong>Data Query Debug Information</strong>", "98%", $colors["header"], "3", "center", "");

		print "<tr><td><span style='font-family: monospace;'>" . debug_log_return("data_query") . "</span></td></tr>";

		html_end_box();
	}

	if (!empty($host["id"])) {
		html_start_box("<strong>Associated Graph Templates</strong>", "98%", $colors["header"], "3", "center", "");

		html_header(array("Graph Template Name", "Status"), 2);

		$selected_graph_templates = db_fetch_assoc("select
			graph_templates.id,
			graph_templates.name
			from graph_templates,host_graph
			where graph_templates.id=host_graph.graph_template_id
			and host_graph.host_id=" . $_GET["id"] . "
			order by graph_templates.name");

		$available_graph_templates = db_fetch_assoc("SELECT
			graph_templates.id, graph_templates.name
			FROM snmp_query_graph RIGHT JOIN graph_templates
			ON snmp_query_graph.graph_template_id = graph_templates.id
			WHERE (((snmp_query_graph.name) Is Null)) ORDER BY graph_templates.name");

		$i = 0;
		if (sizeof($selected_graph_templates) > 0) {
		foreach ($selected_graph_templates as $item) {
			$i++;

			/* get status information for this graph template */
			$is_being_graphed = (sizeof(db_fetch_assoc("select id from graph_local where graph_template_id=" . $item["id"] . " and host_id=" . $_GET["id"])) > 0) ? true : false;

			?>
			<tr>
				<td style="padding: 4px;">
					<strong><?php print $i;?>)</strong> <?php print $item["name"];?>
				</td>
				<td>
					<?php print (($is_being_graphed == true) ? "<span style='color: green;'>Is Being Graphed</span> (<a href='graphs.php?action=graph_edit&id=" . db_fetch_cell("select id from graph_local where graph_template_id=" . $item["id"] . " and host_id=" . $_GET["id"] . " limit 0,1") . "'>Edit</a>)" : "<span style='color: #484848;'>Not Being Graphed</span>");?>
				</td>
				<td align='right' nowrap>
					<a href='host.php?action=gt_remove&id=<?php print $item["id"];?>&host_id=<?php print $_GET["id"];?>'><img src='images/delete_icon_large.gif' alt='Delete Graph Template Association' border='0' align='absmiddle'></a>
				</td>
			</tr>
			<?php
		}
		}else{ print "<tr><td><em>No associated graph templates.</em></td></tr>"; }

		?>
		<tr bgcolor="#<?php print $colors["form_alternate1"];?>">
			<td colspan="4">
				<table cellspacing="0" cellpadding="1" width="100%">
					<td nowrap>Add Graph Template:&nbsp;
						<?php form_dropdown("graph_template_id",$available_graph_templates,"name","id","","","");?>
					</td>
					<td align="right">
						&nbsp;<input type="image" src="images/button_add.gif" alt="Add" name="add_gt" align="absmiddle">
					</td>
				</table>
			</td>
		</tr>

		<?php
		html_end_box();

		html_start_box("<strong>Associated Data Queries</strong>", "98%", $colors["header"], "3", "center", "");

		html_header(array("Data Query Name", "Debugging", "Re-Index Method", "Status"), 2);

		$selected_data_queries = db_fetch_assoc("select
			snmp_query.id,
			snmp_query.name,
			host_snmp_query.reindex_method
			from snmp_query,host_snmp_query
			where snmp_query.id=host_snmp_query.snmp_query_id
			and host_snmp_query.host_id=" . $_GET["id"] . "
			order by snmp_query.name");

		$available_data_queries = db_fetch_assoc("select
							snmp_query.id,
							snmp_query.name
							from snmp_query
							order by snmp_query.name");

		$keeper = array();
		foreach ($available_data_queries as $item) {
			if (sizeof(db_fetch_assoc("SELECT snmp_query_id FROM host_snmp_query " .
					" WHERE ((host_id=" . $_GET["id"] . ")" .
					" and (snmp_query_id=" . $item["id"] ."))")) > 0) {
				/* do nothing */
			} else {
				array_push($keeper, $item);
			}
		}

		$available_data_queries = $keeper;

		$i = 0;
		if (sizeof($selected_data_queries) > 0) {
		foreach ($selected_data_queries as $item) {
			$i++;

			/* get status information for this data query */
			$num_dq_items = sizeof(db_fetch_assoc("select snmp_index from host_snmp_cache where host_id=" . $_GET["id"] . " and snmp_query_id=" . $item["id"]));
			$num_dq_rows = sizeof(db_fetch_assoc("select snmp_index from host_snmp_cache where host_id=" . $_GET["id"] . " and snmp_query_id=" . $item["id"] . " group by snmp_index"));

			$status = "success";

			?>
			<tr>
				<td style="padding: 4px;">
					<strong><?php print $i;?>)</strong> <?php print $item["name"];?>
				</td>
				<td>
					(<a href="host.php?action=query_verbose&id=<?php print $item["id"];?>&host_id=<?php print $_GET["id"];?>">Verbose Query</a>)
				</td>
				<td>
					<?php print $reindex_types{$item["reindex_method"]};?>
				</td>
				<td>
					<?php print (($status == "success") ? "<span style='color: green;'>Success</span>" : "<span style='color: green;'>Fail</span>");?> [<?php print $num_dq_items;?> Item<?php print ($num_dq_items == 1 ? "" : "s");?>, <?php print $num_dq_rows;?> Row<?php print ($num_dq_rows == 1 ? "" : "s");?>]
				</td>
				<td align='right' nowrap>
					<a href='host.php?action=query_reload&id=<?php print $item["id"];?>&host_id=<?php print $_GET["id"];?>'><img src='images/reload_icon_small.gif' alt='Reload Data Query' border='0' align='absmiddle'></a>&nbsp;
					<a href='host.php?action=query_remove&id=<?php print $item["id"];?>&host_id=<?php print $_GET["id"];?>'><img src='images/delete_icon_large.gif' alt='Delete Data Query Association' border='0' align='absmiddle'></a>
				</td>
			</tr>
			<?php
		}
		}else{ print "<tr><td><em>No associated data queries.</em></td></tr>"; }

		?>
		<tr bgcolor="#<?php print $colors["form_alternate1"];?>">
			<td colspan="5">
				<table cellspacing="0" cellpadding="1" width="100%">
					<td nowrap>Add Data Query:&nbsp;
						<?php form_dropdown("snmp_query_id",$available_data_queries,"name","id","","","");?>
					</td>
					<td nowrap>Re-Index Method:&nbsp;
						<?php form_dropdown("reindex_method",$reindex_types,"","","1","","");?>
					</td>
					<td align="right">
						&nbsp;<input type="image" src="images/button_add.gif" alt="Add" name="add_dq" align="absmiddle">
					</td>
				</table>
			</td>
		</tr>

		<?php
		html_end_box();
	}

	form_save_button("host.php");
}
示例#19
0
function template_edit()
{
    global $fields_host_template_edit;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request('id'));
    /* ==================================================== */
    if (!empty($_REQUEST['id'])) {
        $host_template = db_fetch_row_prepared('SELECT * FROM host_template WHERE id = ?', array(get_request_var_request('id')));
        $header_label = '[edit: ' . $host_template['name'] . ']';
    } else {
        $header_label = '[new]';
        $_REQUEST['id'] = 0;
    }
    html_start_box('<strong>Device Templates</strong> ' . htmlspecialchars($header_label), '100%', '', '3', 'center', '');
    draw_edit_form(array('config' => array('form_name' => 'chk'), 'fields' => inject_form_variables($fields_host_template_edit, isset($host_template) ? $host_template : array())));
    /* we have to hide this button to make a form change in the main form trigger the correct
     * submit action */
    echo "<div style='display:none;'><input type='submit' value='Default Submit Button'></div>";
    html_end_box();
    if (!empty($_REQUEST['id'])) {
        html_start_box('<strong>Associated Graph Templates</strong>', '100%', '', '3', 'center', '');
        $selected_graph_templates = db_fetch_assoc_prepared('SELECT
			graph_templates.id,
			graph_templates.name
			FROM (graph_templates,host_template_graph)
			WHERE graph_templates.id = host_template_graph.graph_template_id
			AND host_template_graph.host_template_id = ?
			ORDER BY graph_templates.name', array(get_request_var_request('id')));
        $i = 0;
        if (sizeof($selected_graph_templates) > 0) {
            foreach ($selected_graph_templates as $item) {
                form_alternate_row('', true);
                ?>
					<td style="padding: 4px;">
						<strong><?php 
                print $i;
                ?>
)</strong> <?php 
                print htmlspecialchars($item['name']);
                ?>
					</td>
					<td align="right">
						<a href='<?php 
                print htmlspecialchars('host_templates.php?action=item_remove_gt&id=' . $item['id'] . '&host_template_id=' . $_REQUEST['id']);
                ?>
'><img src='images/delete_icon.gif' style="height:10px;width:10px;" border='0' alt='Delete'></a>
					</td>
				<?php 
                form_end_row();
                $i++;
            }
        } else {
            print '<tr><td><em>No associated graph templates.</em></td></tr>';
        }
        ?>
		<tr class='odd'>
			<td colspan="2">
				<table cellspacing="0" cellpadding="1" width="100%">
					<td nowrap>Add Graph Template:&nbsp;
						<?php 
        form_dropdown('graph_template_id', db_fetch_assoc_prepared('SELECT
							graph_templates.id,
							graph_templates.name
							FROM graph_templates LEFT JOIN host_template_graph
							ON (graph_templates.id = host_template_graph.graph_template_id AND host_template_graph.host_template_id = ?)
							WHERE host_template_graph.host_template_id is null
							ORDER BY graph_templates.name', array(get_request_var_request('id'))), 'name', 'id', '', '', '');
        ?>
					</td>
					<td align="right">
						&nbsp;<input type="submit" value="Add" name="add_gt_x" title="Add Graph Template to Device Template">
					</td>
				</table>
			</td>
		</tr>

		<?php 
        html_end_box();
        html_start_box('<strong>Associated Data Queries</strong>', '100%', '', '3', 'center', '');
        $selected_data_queries = db_fetch_assoc_prepared('SELECT
			snmp_query.id,
			snmp_query.name
			FROM (snmp_query, host_template_snmp_query)
			WHERE snmp_query.id = host_template_snmp_query.snmp_query_id
			AND host_template_snmp_query.host_template_id = ?
			ORDER BY snmp_query.name', array(get_request_var_request('id')));
        $i = 0;
        if (sizeof($selected_data_queries) > 0) {
            foreach ($selected_data_queries as $item) {
                form_alternate_row('', true);
                ?>
					<td style="padding: 4px;">
						<strong><?php 
                print $i;
                ?>
)</strong> <?php 
                print htmlspecialchars($item['name']);
                ?>
					</td>
					<td align='right'>
						<a href='<?php 
                print htmlspecialchars('host_templates.php?action=item_remove_dq&id=' . $item['id'] . '&host_template_id=' . $_REQUEST['id']);
                ?>
'><img src='images/delete_icon.gif' style="height:10px;width:10px;" border='0' alt='Delete'></a>
					</td>
				<?php 
                form_end_row();
                $i++;
            }
        } else {
            print '<tr><td><em>No associated data queries.</em></td></tr>';
        }
        ?>
		<tr class='odd'>
			<td colspan="2">
				<table cellspacing="0" cellpadding="1" width="100%">
					<td nowrap>Add Data Query:&nbsp;
						<?php 
        form_dropdown('snmp_query_id', db_fetch_assoc_prepared('SELECT
							snmp_query.id,
							snmp_query.name
							FROM snmp_query LEFT JOIN host_template_snmp_query
							ON (snmp_query.id = host_template_snmp_query.snmp_query_id AND host_template_snmp_query.host_template_id = ?)
							WHERE host_template_snmp_query.host_template_id is null
							ORDER BY snmp_query.name', array(get_request_var_request('id'))), 'name', 'id', '', '', '');
        ?>
					</td>
					<td align="right">
						&nbsp;<input type="submit" value="Add" name="add_dq_x" title="Add Data Query to Device Template">
					</td>
				</table>
			</td>
		</tr>

		<?php 
        html_end_box();
    }
    form_save_button('host_templates.php', 'return');
}
示例#20
0
function schedule_edit()
{
    global $plugins, $config, $tabs, $maint_types, $maint_intervals;
    /* ================= input validation ================= */
    get_filter_request_var('id');
    /* ==================================================== */
    maint_tabs();
    if (isset_request_var('id')) {
        $id = get_request_var('id');
        $maint_item_data = db_fetch_row('SELECT * FROM plugin_maint_schedules WHERE id = ' . $id);
    } else {
        $id = 0;
        $maint_item_data = array('id' => 0, 'name' => __('New Maintenance Schedule'), 'enabled' => 'on', 'mtype' => 1, 'stime' => time(), 'etime' => time() + 3600, 'minterval' => 0);
    }
    $header_label = get_header_label();
    if (get_request_var('tab') == 'general') {
        form_start('maint.php', 'maint');
        html_start_box(htmlspecialchars($header_label), '100%', '', '3', 'center', '');
        $form_array = array('general_header' => array('friendly_name' => __('Schedule'), 'method' => 'spacer'), 'name' => array('friendly_name' => __('Schedule Name'), 'method' => 'textbox', 'max_length' => 100, 'default' => $maint_item_data['name'], 'description' => __('Provide the Maintenance Schedule a meaningful name'), 'value' => isset($maint_item_data['name']) ? $maint_item_data['name'] : ''), 'enabled' => array('friendly_name' => __('Enabled'), 'method' => 'checkbox', 'default' => 'on', 'description' => __('Whether or not this threshold will be checked and alerted upon.'), 'value' => isset($maint_item_data['enabled']) ? $maint_item_data['enabled'] : ''), 'mtype' => array('friendly_name' => __('Schedule Type'), 'method' => 'drop_array', 'on_change' => 'changemaintType()', 'array' => $maint_types, 'description' => __('The type of Threshold that will be monitored.'), 'value' => isset($maint_item_data['mtype']) ? $maint_item_data['mtype'] : ''), 'minterval' => array('friendly_name' => __('Interval'), 'method' => 'drop_array', 'array' => $maint_intervals, 'default' => 86400, 'description' => __('This is the interval in which the start / end time will repeat.'), 'value' => isset($maint_item_data['minterval']) ? $maint_item_data['minterval'] : '1'), 'stime' => array('friendly_name' => __('Start Time'), 'method' => 'textbox', 'max_length' => 100, 'description' => __('The start date / time for this schedule. Most date / time formats accepted.'), 'default' => date('F j, Y, G:i', time()), 'value' => isset($maint_item_data['stime']) ? date('F j, Y,  G:i', $maint_item_data['stime']) : ''), 'etime' => array('friendly_name' => __('End Time'), 'method' => 'textbox', 'max_length' => 100, 'default' => date('F j, Y, G:i', time() + 3600), 'description' => __('The end date / time for this schedule. Most date / time formats accepted.'), 'value' => isset($maint_item_data['etime']) ? date('F j, Y,  G:i', $maint_item_data['etime']) : ''), 'save_component' => array('method' => 'hidden', 'value' => '1'), 'save' => array('method' => 'hidden', 'value' => 'edit'), 'id' => array('method' => 'hidden', 'value' => $id));
        draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => $form_array));
        html_end_box();
        form_save_button('maint.php', 'return');
        ?>
		<script type='text/javascript'>

		var date1Open = false;
		var date2Open = false;

		function changemaintType () {
			type = $('#mtype').val();
			switch(type) {
			case '1':
				$('#row_minterval').hide();
				break;
			case '2':
				$('#row_minterval').show();
				break;
			}
		}
	
		$(function() {
			$('#stime').after('<i id="startDate" class="calendar fa fa-calendar" title="<?php 
        print __('Start Date/Time Selector');
        ?>
"></i>');
			$('#etime').after('<i id="endDate" class="calendar fa fa-calendar" title="<?php 
        print __('End Date/Time Selector');
        ?>
"></i>');
			$('#startDate').click(function() {
				if (date1Open) {
					date1Open = false;
					$('#stime').datetimepicker('hide');
				}else{
					date1Open = true;
					$('#stime').datetimepicker('show');
				}
			});

			$('#endDate').click(function() {
				if (date2Open) {
					date2Open = false;
					$('#etime').datetimepicker('hide');
				}else{
					date2Open = true;
					$('#etime').datetimepicker('show');
				}
			});

			changemaintType ();

			$('#stime').datetimepicker({
				minuteGrid: 10,
				stepMinute: 1,
				showAnim: 'slideDown',
				numberOfMonths: 1,
				timeFormat: 'HH:mm',
				dateFormat: 'MM d, yy, ',
				showButtonPanel: false
			});

			$('#etime').datetimepicker({
				minuteGrid: 10,
				stepMinute: 1,
				showAnim: 'slideDown',
				numberOfMonths: 1,
				timeFormat: 'HH:mm',
				dateFormat: 'MM d, yy, ',
				showButtonPanel: false
			});
		});
		</script>
		<?php 
    } elseif (get_request_var('tab') == 'hosts') {
        thold_hosts($header_label);
    } elseif (get_request_var('tab') == 'webseer') {
        webseer_urls($header_label);
    } else {
        api_plugin_hook_function('maint_show_tab', $header_label);
    }
}
示例#21
0
function gprint_presets_edit() {
	global $colors, $fields_grprint_presets_edit;

	/* ================= input validation ================= */
	input_validate_input_number(get_request_var("id"));
	/* ==================================================== */

	if (!empty($_GET["id"])) {
		$gprint_preset = db_fetch_row("select * from graph_templates_gprint where id=" . $_GET["id"]);
		$header_label = "[edit: " . $gprint_preset["name"] . "]";
	}else{
		$header_label = "[new]";
	}

	html_start_box("<strong>GPRINT Presets</strong> $header_label", "100%", $colors["header"], "3", "center", "");

	draw_edit_form(array(
		"config" => array(),
		"fields" => inject_form_variables($fields_grprint_presets_edit, (isset($gprint_preset) ? $gprint_preset : array()))
		));

	html_end_box();

	form_save_button("gprint_presets.php");
}
示例#22
0
function item_edit()
{
    global $colors;
    if (!empty($_GET["id"])) {
        $graph_template_item = db_fetch_row("select * from graph_template_item where id=" . $_GET["id"]);
    }
    /* by default, select the LAST DS chosen to make everyone's lives easier */
    $default = db_fetch_row("select data_template_item_id from graph_template_item where graph_template_id=" . $_GET["graph_template_id"] . " order by sequence DESC");
    if (sizeof($default) > 0) {
        $graph_template_item["data_template_item_id"] = $default["data_template_item_id"];
    } else {
        $graph_template_item["data_template_item_id"] = 0;
    }
    form_start("graph_templates_items.php", "form_graph_template");
    /* ==================== Box: Graph Item ==================== */
    html_start_box("<strong>" . _("Graph Item") . "</strong> [" . _("Graph Template: ") . db_fetch_cell("select template_name from graph_template where id=" . $_GET["graph_template_id"]) . "]", "98%", $colors["header_background"], "3", "center", "");
    _graph_item_field__data_template_item_id("data_template_item_id", isset($graph_template_item["data_template_item_id"]) ? $graph_template_item["data_template_item_id"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
    _graph_item_field__color("color", isset($graph_template_item["color"]) ? $graph_template_item["color"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
    _graph_item_field__graph_item_type("graph_item_type", isset($graph_template_item["graph_item_type"]) ? $graph_template_item["graph_item_type"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
    _graph_item_field__consolidation_function("consolidation_function", isset($graph_template_item["consolidation_function"]) ? $graph_template_item["consolidation_function"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
    _graph_item_field__cdef("cdef", isset($graph_template_item["cdef"]) ? $graph_template_item["cdef"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
    _graph_item_field__gprint_format("gprint_format", isset($graph_template_item["gprint_format"]) ? $graph_template_item["gprint_format"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
    _graph_item_field__legend_value("legend_value", isset($graph_template_item["legend_value"]) ? $graph_template_item["legend_value"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
    _graph_item_field__legend_format("legend_format", isset($graph_template_item["legend_format"]) ? $graph_template_item["legend_format"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
    _graph_item_field__hard_return("hard_return", isset($graph_template_item["hard_return"]) ? $graph_template_item["hard_return"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
    html_end_box();
    form_hidden_box("graph_template_item_id", !empty($graph_template_item["id"]) ? $graph_template_item["id"] : "0", "");
    form_hidden_box("graph_template_id", $_GET["graph_template_id"], "0");
    form_hidden_box("save_component_item", "1", "");
    form_save_button("graph_templates.php?action=edit&id=" . $_GET["graph_template_id"]);
}
示例#23
0
function item_edit() {
	global $colors, $struct_graph_item, $graph_item_types, $consolidation_functions;

	/* ================= input validation ================= */
	input_validate_input_number(get_request_var_request("id"));
	input_validate_input_number(get_request_var_request("local_graph_id"));
	input_validate_input_number(get_request_var_request("host_id"));
	/* ==================================================== */

	/* if the user pushed the 'clear' button */
	if (isset($_REQUEST["clear_x"])) {
		kill_session_var("sess_ds_host_id");

		unset($_REQUEST["host_id"]);
	}

	/* remember these search fields in session vars so we don't have to keep passing them around */
	load_current_session_value("filter", "sess_ds_filter", "");
	load_current_session_value("host_id", "sess_ds_host_id", "-1");

	$host = db_fetch_row("select hostname from host where id=" . $_REQUEST["host_id"]);

	html_start_box("<strong>Data Source by Host</strong> [host: " . (empty($host["hostname"]) ? "No Host" : $host["hostname"]) . "]", "98%", $colors["header"], "3", "center", "");

	include("./include/html/inc_graph_items_filter_table.php");

	html_end_box();

	if ($_REQUEST["host_id"] == "-1") {
		$sql_where = "";
	}elseif ($_REQUEST["host_id"] == "0") {
		$sql_where = " and data_local.host_id=0";
	}elseif (!empty($_REQUEST["host_id"])) {
		$sql_where = " and data_local.host_id=" . $_REQUEST["host_id"];
	}

	if (!empty($_REQUEST["id"])) {
		$template_item = db_fetch_row("select * from graph_templates_item where id=" . $_REQUEST["id"]);
		$host_id = db_fetch_cell("select host_id from graph_local where id=" . $_REQUEST["local_graph_id"]);
	}

	$header_label = "[edit graph: " . db_fetch_cell("select title_cache from graph_templates_graph where local_graph_id=" . $_REQUEST["local_graph_id"]) . "]";

	html_start_box("<strong>Graph Items</strong> $header_label", "98%", $colors["header"], "3", "center", "");

	/* by default, select the LAST DS chosen to make everyone's lives easier */
	if (!empty($_REQUEST["local_graph_id"])) {
		$default = db_fetch_row("select task_item_id from graph_templates_item where local_graph_id=" . $_REQUEST["local_graph_id"] . " order by sequence DESC");

		if (sizeof($default) > 0) {
			$struct_graph_item["task_item_id"]["default"] = $default["task_item_id"];
		}else{
			$struct_graph_item["task_item_id"]["default"] = 0;
		}

		/* modifications to the default graph items array */
		$struct_graph_item["task_item_id"]["sql"] = "select
			CONCAT_WS('',data_template_data.name_cache,' (',data_template_rrd.data_source_name,')') as name,
			data_template_rrd.id
			from data_template_data,data_template_rrd,data_local
			left join host on data_local.host_id=host.id
			where data_template_rrd.local_data_id=data_local.id
			and data_template_data.local_data_id=data_local.id
			" . (((!empty($host_id)) || (!empty($_REQUEST["host_id"]))) ? (!empty($host_id) ? " and data_local.host_id=$host_id" : " and data_local.host_id=" . $_REQUEST["host_id"]) : "") . "
			order by name";
	}

	$form_array = array();

	while (list($field_name, $field_array) = each($struct_graph_item)) {
		$form_array += array($field_name => $struct_graph_item[$field_name]);

		$form_array[$field_name]["value"] = (isset($template_item) ? $template_item[$field_name] : "");
		$form_array[$field_name]["form_id"] = (isset($template_item) ? $template_item["id"] : "0");

	}

	draw_edit_form(
		array(
			"config" => array(
				),
			"fields" => $form_array
			)
		);

	form_hidden_box("local_graph_id", $_REQUEST["local_graph_id"], "0");
	form_hidden_box("graph_template_item_id", (isset($template_item) ? $template_item["id"] : "0"), "");
	form_hidden_box("local_graph_template_item_id", (isset($template_item) ? $template_item["local_graph_template_item_id"] : "0"), "");
	form_hidden_box("graph_template_id", (isset($template_item) ? $template_item["graph_template_id"] : "0"), "");
	form_hidden_box("sequence", (isset($template_item) ? $template_item["sequence"] : "0"), "");
	form_hidden_box("_graph_type_id", (isset($template_item) ? $template_item["graph_type_id"] : "0"), "");
	form_hidden_box("save_component_item", "1", "");

	html_end_box();

	form_save_button("graphs.php?action=graph_edit&id=" . $_REQUEST["local_graph_id"]);
}
示例#24
0
function ds_edit()
{
    global $colors, $struct_data_source, $struct_data_source_item, $data_source_types;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var("id"));
    /* ==================================================== */
    $use_data_template = true;
    $host_id = 0;
    if (!empty($_GET["id"])) {
        $data_local = db_fetch_row("select host_id,data_template_id from data_local where id='" . $_GET["id"] . "'");
        $data = db_fetch_row("select * from data_template_data where local_data_id='" . $_GET["id"] . "'");
        if (isset($data_local["data_template_id"]) && $data_local["data_template_id"] >= 0) {
            $data_template = db_fetch_row("select id,name from data_template where id='" . $data_local["data_template_id"] . "'");
            $data_template_data = db_fetch_row("select * from data_template_data where data_template_id='" . $data_local["data_template_id"] . "' and local_data_id=0");
        } else {
            $_SESSION["sess_messages"] = 'Data Source "' . $_GET["id"] . '" does not exist.';
            header("Location: data_sources.php");
            exit;
        }
        $header_label = "[edit: " . get_data_source_title($_GET["id"]) . "]";
        if (empty($data_local["data_template_id"])) {
            $use_data_template = false;
        }
    } else {
        $header_label = "[new]";
        $use_data_template = false;
    }
    /* handle debug mode */
    if (isset($_GET["debug"])) {
        if ($_GET["debug"] == "0") {
            kill_session_var("ds_debug_mode");
        } elseif ($_GET["debug"] == "1") {
            $_SESSION["ds_debug_mode"] = true;
        }
    }
    include_once "./include/top_header.php";
    if (!empty($_GET["id"])) {
        ?>
		<table width="100%" align="center">
			<tr>
				<td class="textInfo" colspan="2" valign="top">
					<?php 
        print get_data_source_title($_GET["id"]);
        ?>
				</td>
				<td class="textInfo" align="right" valign="top">
					<span style="color: #c16921;">*<a href='data_sources.php?action=ds_edit&id=<?php 
        print isset($_GET["id"]) ? $_GET["id"] : 0;
        ?>
&debug=<?php 
        print isset($_SESSION["ds_debug_mode"]) ? "0" : "1";
        ?>
'>Turn <strong><?php 
        print isset($_SESSION["ds_debug_mode"]) ? "Off" : "On";
        ?>
</strong> Data Source Debug Mode.</a>
				</td>
			</tr>
		</table>
		<br>
		<?php 
    }
    html_start_box("<strong>Data Template Selection</strong> {$header_label}", "100%", $colors["header"], "3", "center", "");
    $form_array = array("data_template_id" => array("method" => "drop_sql", "friendly_name" => "Selected Data Template", "description" => "The name given to this data template.", "value" => isset($data_template) ? $data_template["id"] : "0", "none_value" => "None", "sql" => "select id,name from data_template order by name"), "host_id" => array("method" => "drop_sql", "friendly_name" => "Host", "description" => "Choose the host that this graph belongs to.", "value" => isset($_GET["host_id"]) ? $_GET["host_id"] : $data_local["host_id"], "none_value" => "None", "sql" => "select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"), "_data_template_id" => array("method" => "hidden", "value" => isset($data_template) ? $data_template["id"] : "0"), "_host_id" => array("method" => "hidden", "value" => empty($data_local["host_id"]) ? isset($_GET["host_id"]) ? $_GET["host_id"] : "0" : $data_local["host_id"]), "_data_input_id" => array("method" => "hidden", "value" => isset($data["data_input_id"]) ? $data["data_input_id"] : "0"), "data_template_data_id" => array("method" => "hidden", "value" => isset($data) ? $data["id"] : "0"), "local_data_template_data_id" => array("method" => "hidden", "value" => isset($data) ? $data["local_data_template_data_id"] : "0"), "local_data_id" => array("method" => "hidden", "value" => isset($data) ? $data["local_data_id"] : "0"));
    draw_edit_form(array("config" => array(), "fields" => $form_array));
    html_end_box();
    /* only display the "inputs" area if we are using a data template for this data source */
    if (!empty($data["data_template_id"])) {
        $template_data_rrds = db_fetch_assoc("select * from data_template_rrd where local_data_id=" . $_GET["id"] . " order by data_source_name");
        html_start_box("<strong>Supplemental Data Template Data</strong>", "100%", $colors["header"], "3", "center", "");
        draw_nontemplated_fields_data_source($data["data_template_id"], $data["local_data_id"], $data, "|field|", "<strong>Data Source Fields</strong>", true, true, 0);
        draw_nontemplated_fields_data_source_item($data["data_template_id"], $template_data_rrds, "|field|_|id|", "<strong>Data Source Item Fields</strong>", true, true, true, 0);
        draw_nontemplated_fields_custom_data($data["id"], "value_|id|", "<strong>Custom Data</strong>", true, true, 0);
        form_hidden_box("save_component_data", "1", "");
        html_end_box();
    }
    if ((isset($_GET["id"]) || isset($_GET["new"])) && empty($data["data_template_id"])) {
        html_start_box("<strong>Data Source</strong>", "100%", $colors["header"], "3", "center", "");
        $form_array = array();
        while (list($field_name, $field_array) = each($struct_data_source)) {
            $form_array += array($field_name => $struct_data_source[$field_name]);
            if (!($use_data_template == false || !empty($data_template_data["t_" . $field_name]) || $field_array["flags"] == "NOTEMPLATE")) {
                $form_array[$field_name]["description"] = "";
            }
            $form_array[$field_name]["value"] = isset($data[$field_name]) ? $data[$field_name] : "";
            $form_array[$field_name]["form_id"] = empty($data["id"]) ? "0" : $data["id"];
            if (!($use_data_template == false || !empty($data_template_data["t_" . $field_name]) || $field_array["flags"] == "NOTEMPLATE")) {
                $form_array[$field_name]["method"] = "template_" . $form_array[$field_name]["method"];
            }
        }
        draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => inject_form_variables($form_array, isset($data) ? $data : array())));
        html_end_box();
        /* fetch ALL rrd's for this data source */
        if (!empty($_GET["id"])) {
            $template_data_rrds = db_fetch_assoc("select id,data_source_name from data_template_rrd where local_data_id=" . $_GET["id"] . " order by data_source_name");
        }
        /* select the first "rrd" of this data source by default */
        if (empty($_GET["view_rrd"])) {
            $_GET["view_rrd"] = isset($template_data_rrds[0]["id"]) ? $template_data_rrds[0]["id"] : "0";
        }
        /* get more information about the rrd we chose */
        if (!empty($_GET["view_rrd"])) {
            $local_data_template_rrd_id = db_fetch_cell("select local_data_template_rrd_id from data_template_rrd where id=" . $_GET["view_rrd"]);
            $rrd = db_fetch_row("select * from data_template_rrd where id=" . $_GET["view_rrd"]);
            $rrd_template = db_fetch_row("select * from data_template_rrd where id={$local_data_template_rrd_id}");
            $header_label = "[edit: " . $rrd["data_source_name"] . "]";
        } else {
            $header_label = "";
        }
        $i = 0;
        if (isset($template_data_rrds)) {
            if (sizeof($template_data_rrds) > 1) {
                /* draw the data source tabs on the top of the page */
                print "\t<table class='tabs' width='100%' cellspacing='0' cellpadding='3' align='center'>\n\t\t\t\t\t<tr>\n";
                foreach ($template_data_rrds as $template_data_rrd) {
                    $i++;
                    print "\t<td " . ($template_data_rrd["id"] == $_GET["view_rrd"] ? "bgcolor='silver'" : "bgcolor='#DFDFDF'") . " nowrap='nowrap' width='" . (strlen($template_data_rrd["data_source_name"]) * 9 + 50) . "' align='center' class='tab'>\n\t\t\t\t\t\t\t\t<span class='textHeader'><a href='data_sources.php?action=ds_edit&id=" . $_GET["id"] . "&view_rrd=" . $template_data_rrd["id"] . "'>{$i}: " . $template_data_rrd["data_source_name"] . "</a>" . ($use_data_template == false ? " <a href='data_sources.php?action=rrd_remove&id=" . $template_data_rrd["id"] . "&local_data_id=" . $_GET["id"] . "'><img src='images/delete_icon.gif' border='0' alt='Delete'></a>" : "") . "</span>\n\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t\t<td width='1'></td>\n";
                }
                print "\n\t\t\t\t\t<td></td>\n\n\t\t\t\t\t</tr>\n\t\t\t\t</table>\n";
            } elseif (sizeof($template_data_rrds) == 1) {
                $_GET["view_rrd"] = $template_data_rrds[0]["id"];
            }
        }
        html_start_box("", "100%", $colors["header"], "3", "center", "");
        print "\t<tr>\n\t\t\t\t<td bgcolor='#" . $colors["header"] . "' class='textHeaderDark'>\n\t\t\t\t\t<strong>Data Source Item</strong> {$header_label}\n\t\t\t\t</td>\n\t\t\t\t<td class='textHeaderDark' align='right' bgcolor='" . $colors["header"] . "'>\n\t\t\t\t\t" . (!empty($_GET["id"]) && empty($data_template["id"]) ? "<strong><a class='linkOverDark' href='data_sources.php?action=rrd_add&id=" . $_GET["id"] . "'>New</a>&nbsp;</strong>" : "") . "\n\t\t\t\t</td>\n\t\t\t</tr>\n";
        /* data input fields list */
        if (empty($data["data_input_id"]) || db_fetch_cell("select type_id from data_input where id=" . $data["data_input_id"]) > "1") {
            unset($struct_data_source_item["data_input_field_id"]);
        } else {
            $struct_data_source_item["data_input_field_id"]["sql"] = "select id,CONCAT(data_name,' - ',name) as name from data_input_fields where data_input_id=" . $data["data_input_id"] . " and input_output='out' and update_rra='on' order by data_name,name";
        }
        $form_array = array();
        while (list($field_name, $field_array) = each($struct_data_source_item)) {
            $form_array += array($field_name => $struct_data_source_item[$field_name]);
            if (!($use_data_template == false || $rrd_template["t_" . $field_name] == "on")) {
                $form_array[$field_name]["description"] = "";
            }
            $form_array[$field_name]["value"] = isset($rrd) ? $rrd[$field_name] : "";
            if (!($use_data_template == false || $rrd_template["t_" . $field_name] == "on")) {
                $form_array[$field_name]["method"] = "template_" . $form_array[$field_name]["method"];
            }
        }
        draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => array("data_template_rrd_id" => array("method" => "hidden", "value" => isset($rrd) ? $rrd["id"] : "0"), "local_data_template_rrd_id" => array("method" => "hidden", "value" => isset($rrd) ? $rrd["local_data_template_rrd_id"] : "0")) + $form_array));
        html_end_box();
        /* data source data goes here */
        data_edit();
        form_hidden_box("current_rrd", $_GET["view_rrd"], "0");
    }
    /* display the debug mode box if the user wants it */
    if (isset($_SESSION["ds_debug_mode"]) && isset($_GET["id"])) {
        ?>
		<table width="100%" align="center">
			<tr>
				<td>
					<span class="textInfo">Data Source Debug</span><br>
					<pre><?php 
        print rrdtool_function_create($_GET["id"], true, array());
        ?>
</pre>
				</td>
			</tr>
		</table>
		<?php 
    }
    if (isset($_GET["id"]) || isset($_GET["new"])) {
        form_hidden_box("save_component_data_source", "1", "");
    } else {
        form_hidden_box("save_component_data_source_new", "1", "");
    }
    form_save_button("data_sources.php");
    include_once "./include/bottom_footer.php";
}
示例#25
0
function package_edit() {
	$_package_id = get_get_var_number("id");

	if (empty($_package_id)) {
		$header_label = "[new]";
	}else{
		$package = api_package_get($_package_id);

		/* get a list of each graph template that is associated with this package */
		$graph_templates = api_package_graph_template_list($_package_id);

		/* get a list of all of the metadata associated with a particular package */
		$metadata_items = api_package_metadata_list($_package_id);

		$header_label = "[edit: " . $package["name"] . "]";
	}

	form_start("packages.php", "form_package");

	/* ==================== Box: Template Packages ==================== */

	html_start_box("<strong>" . _("Template Packages") . "</strong> $header_label");

	_package_field__name("name", (isset($package["name"]) ? $package["name"] : ""), "0");
	_package_field__description("description", (isset($package["description"]) ? $package["description"] : ""), "0");
	_package_field__description_install("description_install", (isset($package["description_install"]) ? $package["description_install"] : ""), "0");
	_package_field__category("category", (isset($package["category"]) ? $package["category"] : ""), "0");
	_package_field__subcategory("subcategory", (isset($package["subcategory"]) ? $package["subcategory"] : ""), "0");
	_package_field__vendor("vendor", (isset($package["vendor"]) ? $package["vendor"] : ""), "0");
	_package_field__model("model", (isset($package["model"]) ? $package["model"] : ""), "0");
	_package_field__author_hdr();
	_package_field__author_type("author_type", (isset($package) ? "existing" : "new"), "0");
	_package_author_field__name("author_name", (isset($package["author_name"]) ? $package["author_name"] : ""), "0");
	_package_author_field__email("author_email", (isset($package["author_email"]) ? $package["author_email"] : ""), "0");
	_package_author_field__user_forum("author_user_forum", (isset($package["author_user_forum"]) ? $package["author_user_forum"] : ""), "0");
	_package_author_field__user_repository("author_user_repository", (isset($package["author_user_repository"]) ? $package["author_user_repository"] : ""), "0");
	_package_author_type_js();

	html_end_box();

	if (!empty($_package_id)) {
		/* ==================== Box: Associated Graph Templates ==================== */

		html_start_box("<strong>" . _("Associated Graph Templates") . "</strong>");
		html_header(array(_("Template Title")), 2);

		if (sizeof($graph_templates) > 0) {
			foreach ($graph_templates as $graph_template) {
				?>
				<tr class="item">
					<td style="padding: 4px;">
						<?php echo $graph_template["template_name"];?>
					</td>
					<td align="right" style="padding: 4px;">
						<a href="packages.php?action=remove_graph_template&id=<?php echo $_package_id;?>&graph_template_id=<?php echo $graph_template["id"];?>"><img src="<?php echo html_get_theme_images_path("delete_icon_large.gif");?>" alt="<?php echo _("Delete Graph Template Association");?>" border="0" align="absmiddle"></a>
					</td>
				</tr>
				<?php
			}
		}else{
			?>
			<tr class="empty">
				<td colspan="2">
					No graph templates have been associated with this package.
				</td>
			</tr>
			<?php
		}

		?>
		<tr>
			<td style="border-top: 1px solid #b5b5b5; padding: 1px;" colspan="2">
				<table width="100%" cellpadding="2" cellspacing="0">
					<tr>
						<td>
							Add graph template:
							<?php form_dropdown("assoc_graph_template_id", api_graph_template_list(), "template_name", "id", "", "", "");?>
						</td>
						<td align="right">
							&nbsp;<input type="image" src="<?php echo html_get_theme_images_path('button_add.gif');?>" alt="<?php echo _('Add');?>" name="assoc_graph_template_add" align="absmiddle">
						</td>
					</tr>
				</table>
			</td>
		</tr>

		<?php

		html_end_box();

		/* ==================== Box: Associated Meta Data ==================== */

		html_start_box("<strong>" . _("Associated Meta Data") . "</strong>", "packages.php?action=edit_metadata&package_id=$_package_id");
		html_header(array(_("Name"), _("Type")), 2);

		if (sizeof($metadata_items) > 0) {
			$metadata_types = api_package_metadata_type_list();

			foreach ($metadata_items as $metadata_item) {
				?>
				<tr class="content-row">
					<td class="content-row" style="padding: 4px;">
						<a class="linkEditMain" href="packages.php?action=edit_metadata&id=<?php echo $metadata_item["id"];?>&package_id=<?php echo $_package_id;?>"><?php echo $metadata_item["name"];?></a>
					</td>
					<td class="content-row" style="padding: 4px;">
						<?php echo $metadata_types{$metadata_item["type"]};?>
					</td>
					<td class="content-row" align="right" style="padding: 4px;">
						<a href="packages.php?action=remove_metadata&id=<?php echo $_package_id;?>&package_metadata_id=<?php echo $metadata_item["id"];?>"><img src="<?php echo html_get_theme_images_path("delete_icon_large.gif");?>" alt="<?php echo _("Delete Package Metadata Item");?>" border="0" align="absmiddle"></a>
					</td>
				</tr>
				<?php
			}
		}else{
			?>
			<tr>
				<td class="content-list-empty" colspan="2">
					No metadata items have been associated with this package.
				</td>
			</tr>
			<?php
		}

		html_end_box();
	}

	form_hidden_box("action_post", "package_edit");
	form_hidden_box("package_id", $_package_id);

	form_save_button("packages.php", "save_package");
}
示例#26
0
function template_edit()
{
    global $colors, $data_source_types;
    if (!empty($_GET["id"])) {
        $data_template = db_fetch_row("select * from data_template where id=" . $_GET["id"]);
        $data_template_items = db_fetch_assoc("select * from data_template_item where data_template_id=" . $_GET["id"]);
        $header_label = _("[edit: ") . $data_template["template_name"] . "]";
    } else {
        $header_label = _("[new]");
    }
    form_start("data_templates.php", "form_data_template");
    /* ==================== Box: Data Template ==================== */
    html_start_box("<strong>" . _("Data Template") . "</strong> {$header_label}");
    _data_template_field__template_name("template_name", isset($data_template) ? $data_template["template_name"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
    html_end_box();
    /* ==================== Box: Data Input ==================== */
    /* determine current value for 'data_input_type' */
    if (isset($_GET["data_input_type"])) {
        $_data_input_type = $_GET["data_input_type"];
    } else {
        if (isset($data_template["data_input_type"])) {
            $_data_input_type = $data_template["data_input_type"];
        } else {
            $_data_input_type = DATA_INPUT_TYPE_SCRIPT;
        }
    }
    /* get a list of all data input type fields for this data template */
    if (isset($data_template)) {
        $data_input_type_fields = array_rekey(db_fetch_assoc("select name,t_value,value from data_template_field where data_template_id = " . $data_template["id"]), "name", array("t_value", "value"));
    } else {
        $data_input_type_fields = array();
    }
    html_start_box("<strong>" . _("Data Input") . "</strong>");
    _data_source_input_field__data_input_type("data_input_type", true, $_data_input_type, empty($_GET["id"]) ? 0 : $_GET["id"]);
    /* grab the appropriate data input type form array */
    if ($_data_input_type == DATA_INPUT_TYPE_SCRIPT) {
        $scripts = api_script_list();
        if (sizeof($scripts) > 0) {
            /* determine current value for 'script_id' */
            if (isset($_GET["script_id"]) && is_numeric($_GET["script_id"])) {
                $_script_id = $_GET["script_id"];
            } else {
                if (isset($data_input_type_fields["script_id"])) {
                    $_script_id = $data_input_type_fields["script_id"]["value"];
                } else {
                    /* default to the first item in the script list */
                    $_script_id = $scripts[0]["id"];
                }
            }
            field_row_header(_("External Script"));
            _data_source_input_field__script_id("dif_script_id", "data_templates.php?action=edit" . (!empty($_GET["id"]) ? "&id=" . $_GET["id"] : "") . "&data_input_type={$_data_input_type}&script_id=|dropdown_value|", $_script_id);
            /* get each INPUT field for this script */
            $script_input_fields = db_fetch_assoc("select * from data_input_fields where data_input_id = {$_script_id} and input_output='in' order by name");
            if (sizeof($script_input_fields) > 0) {
                field_row_header(_("Custom Input Fields"));
                foreach ($script_input_fields as $field) {
                    _data_source_input_field__script("dif_" . $field["data_name"], $field["name"], true, isset($data_input_type_fields[$field["data_name"]]) ? $data_input_type_fields[$field["data_name"]]["value"] : "", "t_dif_" . $field["data_name"], isset($data_input_type_fields[$field["data_name"]]) ? $data_input_type_fields[$field["data_name"]]["t_value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0);
                }
            }
        }
    } else {
        if ($_data_input_type == DATA_INPUT_TYPE_DATA_QUERY) {
            /* since the "sql" key is not executed until draw_edit_form(), we have fetch the list of
             * data queries here as well */
            $data_queries = api_data_query_list();
            if (sizeof($data_queries) > 0) {
                /* determine current value for 'data_query_id' */
                if (isset($_GET["data_query_id"]) && is_numeric($_GET["data_query_id"])) {
                    $_data_query_id = $_GET["data_query_id"];
                } else {
                    if (isset($data_input_type_fields["data_query_id"])) {
                        $_data_query_id = $data_input_type_fields["data_query_id"]["value"];
                    } else {
                        /* default to the first item in the data query list */
                        $_data_query_id = $data_queries[0]["id"];
                    }
                }
                field_row_header(_("Data Query"));
                _data_source_input_field__data_query_id("dif_data_query_id", "data_templates.php?action=edit" . (!empty($_GET["id"]) ? "&id=" . $_GET["id"] : "") . "&data_input_type={$_data_input_type}&data_query_id=|dropdown_value|", $_data_query_id);
            }
        } else {
            if ($_data_input_type == DATA_INPUT_TYPE_SNMP) {
                _data_source_input_field__device_hdr_generic();
                _data_source_input_field__device_snmp_port("dif_snmp_port", true, isset($data_input_type_fields["snmp_port"]) ? $data_input_type_fields["snmp_port"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmp_port"]) ? $data_input_type_fields["snmp_port"]["t_value"] : "0", isset($data_input_type_fields["snmp_port"]) ? "on" : "");
                _data_source_input_field__device_snmp_timeout("dif_snmp_timeout", true, isset($data_input_type_fields["snmp_timeout"]) ? $data_input_type_fields["snmp_timeout"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmp_timeout"]) ? $data_input_type_fields["snmp_timeout"]["t_value"] : "0", isset($data_input_type_fields["snmp_timeout"]) ? "on" : "");
                _data_source_input_field__device_snmp_version("dif_snmp_version", true, isset($data_input_type_fields["snmp_version"]) ? $data_input_type_fields["snmp_version"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmp_version"]) ? $data_input_type_fields["snmp_version"]["t_value"] : "0", isset($data_input_type_fields["snmp_version"]) ? "on" : "");
                _data_source_input_field__device_hdr_snmpv12();
                _data_source_input_field__device_snmp_community("dif_snmp_community", true, isset($data_input_type_fields["snmp_community"]) ? $data_input_type_fields["snmp_community"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmp_community"]) ? $data_input_type_fields["snmp_community"]["t_value"] : "0", isset($data_input_type_fields["snmp_community"]) ? "on" : "");
                _data_source_input_field__device_hdr_snmpv3();
                _data_source_input_field__device_snmpv3_auth_username("dif_snmpv3_auth_username", true, isset($data_input_type_fields["snmpv3_auth_username"]) ? $data_input_type_fields["snmpv3_auth_username"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmpv3_auth_username"]) ? $data_input_type_fields["snmpv3_auth_username"]["t_value"] : "0", isset($data_input_type_fields["snmpv3_auth_username"]) ? "on" : "");
                _data_source_input_field__device_snmpv3_auth_password("dif_snmpv3_auth_password", true, isset($data_input_type_fields["snmpv3_auth_password"]) ? $data_input_type_fields["snmpv3_auth_password"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmpv3_auth_password"]) ? $data_input_type_fields["snmpv3_auth_password"]["t_value"] : "0", isset($data_input_type_fields["snmpv3_auth_password"]) ? "on" : "");
                _data_source_input_field__device_snmpv3_auth_protocol("dif_snmpv3_auth_protocol", true, isset($data_input_type_fields["snmpv3_auth_protocol"]) ? $data_input_type_fields["snmpv3_auth_protocol"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmpv3_auth_protocol"]) ? $data_input_type_fields["snmpv3_auth_protocol"]["t_value"] : "0", isset($data_input_type_fields["snmpv3_auth_protocol"]) ? "on" : "");
                _data_source_input_field__device_snmpv3_priv_passphrase("dif_snmpv3_priv_passphrase", true, isset($data_input_type_fields["snmpv3_priv_passphrase"]) ? $data_input_type_fields["snmpv3_priv_passphrase"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmpv3_priv_passphrase"]) ? $data_input_type_fields["snmpv3_priv_passphrase"]["t_value"] : "0", isset($data_input_type_fields["snmpv3_priv_passphrase"]) ? "on" : "");
                _data_source_input_field__device_snmpv3_priv_protocol("dif_snmpv3_priv_protocol", true, isset($data_input_type_fields["snmpv3_priv_protocol"]) ? $data_input_type_fields["snmpv3_priv_protocol"]["value"] : "", isset($_GET["id"]) ? $_GET["id"] : 0, isset($data_input_type_fields["snmpv3_priv_protocol"]) ? $data_input_type_fields["snmpv3_priv_protocol"]["t_value"] : "0", isset($data_input_type_fields["snmpv3_priv_protocol"]) ? "on" : "");
            }
        }
    }
    html_end_box();
    /* ==================== Box: Data Source ==================== */
    $rra_items = api_data_template_rra_item_list($data_template["id"]);
    /* the user clicked the "add item" link. we need to make sure they get redirected back to
     * this page if an error occurs */
    if ($_GET["action"] == "sv_add") {
        form_hidden_box("redirect_sv_add", "x", "");
    }
    html_start_box("<strong>" . _("Data Source") . "</strong>");
    _data_source_field__name("name", true, empty($_GET["id"]) ? 0 : $_GET["id"], "t_name", isset($data_template["t_name"]) ? $data_template["t_name"] : "");
    _data_source_field__rra("preset_rra_id", true, isset($data_template["preset_rra_id"]) ? $data_template["preset_rra_id"] : "", empty($_GET["id"]) ? 0 : $_GET["id"]);
    _data_source_field__polling_interval("polling_interval", true, isset($data_template["polling_interval"]) ? $data_template["polling_interval"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_polling_interval", isset($data_template["t_polling_interval"]) ? $data_template["t_polling_interval"] : "");
    _data_source_field__active("active", true, isset($data_template["active"]) ? $data_template["active"] : "", empty($_GET["id"]) ? 0 : $_GET["id"], "t_active", isset($data_template["t_active"]) ? $data_template["t_active"] : "");
    html_end_box();
    /* ==================== Box: Data Source Item ==================== */
    html_start_box("<strong>" . _("Data Source Item") . "</strong>", empty($_GET["id"]) ? "" : "javascript:document.forms[0].action.value='item_add';submit_redirect(0, '" . htmlspecialchars("data_templates.php?action=item_add&id=" . $_GET["id"]) . "', '')");
    /* the user clicked the "add item" link. we need to make sure they get redirected back to
     * this page if an error occurs */
    if ($_GET["action"] == "item_add") {
        form_hidden_box("redirect_item_add", "x", "");
    }
    /* this allows a "blank" data template item to be displayed when the user wants to create
     * a new one */
    if (!isset($data_template_items) || sizeof($data_template_items) == 0 || $_GET["action"] == "item_add") {
        if (isset($data_template_items)) {
            $next_index = sizeof($data_template_items);
        } else {
            $next_index = 0;
        }
        $data_template_items[$next_index] = array();
    }
    if (sizeof($data_template_items) > 0) {
        if ($_data_input_type == DATA_INPUT_TYPE_SCRIPT) {
            $script_output_fields = db_fetch_assoc("select * from data_input_fields where data_input_id = {$_script_id} and input_output='out' order by name");
            $field_input_description = _("Script Output Field");
        } else {
            if ($_data_input_type == DATA_INPUT_TYPE_DATA_QUERY) {
                $field_list = api_data_query_field_list($_data_query_id, DATA_QUERY_FIELD_TYPE_OUTPUT);
                $data_query_output_fields = array();
                if (sizeof($field_list) > 0) {
                    foreach ($field_list as $field) {
                        $data_query_output_fields[$field["name"]] = $field["name"] . " (" . $field["name_desc"] . ")";
                    }
                }
                $field_input_description = _("Data Query Output Field");
            } else {
                if ($_data_input_type == DATA_INPUT_TYPE_SNMP) {
                    $field_input_description = _("SNMP OID");
                }
            }
        }
        foreach ($data_template_items as $item) {
            if ($_data_input_type != DATA_INPUT_TYPE_NONE) {
                ?>
				<tr bgcolor="<?php 
                print $colors["header_panel_background"];
                ?>
">
					<td class='textSubHeaderDark' colspan="2">
						<?php 
                print isset($item["data_source_name"]) ? $item["data_source_name"] : "(" . _("New Data Template Item") . ")";
                ?>
					</td>
					<td class='textSubHeaderDark' align='right'>
						<?php 
                if (isset($item["id"]) && sizeof($data_template_items) > 1) {
                    print "[<a href='data_templates.php?action=item_remove&id=" . $item["id"] . "&data_template_id=" . $item["data_template_id"] . "' class='linkOverDark'>remove</a>]\n";
                }
                ?>
					</td>
				</tr>
				<tr bgcolor="#e1e1e1">
					<td width="50%" style="border-bottom: 1px solid #a1a1a1;">
						<font class='textEditTitle'>Field Input: <?php 
                print $field_input_description;
                ?>
</font><br>
					</td>
					<td style="border-bottom: 1px solid #a1a1a1;" colspan="2">
						<?php 
                if ($_data_input_type == DATA_INPUT_TYPE_SCRIPT) {
                    form_dropdown("dsi|field_input_value|" . (isset($item["id"]) ? $item["id"] : "0"), $script_output_fields, "name", "data_name", isset($item["field_input_value"]) ? $item["field_input_value"] : "", "", "");
                } else {
                    if ($_data_input_type == DATA_INPUT_TYPE_DATA_QUERY) {
                        form_dropdown("dsi|field_input_value|" . (isset($item["id"]) ? $item["id"] : "0"), $data_query_output_fields, "", "", isset($item["field_input_value"]) ? $item["field_input_value"] : "", "", "");
                    } else {
                        if ($_data_input_type == DATA_INPUT_TYPE_SNMP) {
                            form_text_box("dsi|field_input_value|" . (isset($item["id"]) ? $item["id"] : "0"), isset($item["field_input_value"]) ? $item["field_input_value"] : "", "", "100", 40, "text", 0);
                        }
                    }
                }
                ?>
					</td>
				</tr>
				<?php 
            }
            $_field_id = isset($item["id"]) ? $item["id"] : 0;
            field_reset_row_color();
            field_increment_row_color();
            _data_source_item_field__data_source_name("dsi|data_source_name|{$_field_id}", true, isset($item["data_source_name"]) ? $item["data_source_name"] : "", $_field_id);
            _data_source_item_field__rrd_minimum("dsi|rrd_minimum|{$_field_id}", true, isset($item["rrd_minimum"]) ? $item["rrd_minimum"] : "", $_field_id, "dsi|t_rrd_minimum|{$_field_id}", isset($item["t_rrd_minimum"]) ? $item["t_rrd_minimum"] : "");
            _data_source_item_field__rrd_maximum("dsi|rrd_maximum|{$_field_id}", true, isset($item["rrd_maximum"]) ? $item["rrd_maximum"] : "", $_field_id, "dsi|t_rrd_maximum|{$_field_id}", isset($item["t_rrd_maximum"]) ? $item["t_rrd_maximum"] : "");
            _data_source_item_field__data_source_type("dsi|data_source_type|{$_field_id}", true, isset($item["data_source_type"]) ? $item["data_source_type"] : "", $_field_id, "dsi|t_data_source_type|{$_field_id}", isset($item["t_data_source_type"]) ? $item["t_data_source_type"] : "");
            _data_source_item_field__rrd_heartbeat("dsi|rrd_heartbeat|{$_field_id}", true, isset($item["rrd_heartbeat"]) ? $item["rrd_heartbeat"] : "", $_field_id, "dsi|t_rrd_heartbeat|{$_field_id}", isset($item["t_rrd_heartbeat"]) ? $item["t_rrd_heartbeat"] : "");
        }
    }
    html_end_box();
    form_hidden_box("data_template_id", empty($_GET["id"]) ? 0 : $_GET["id"], "");
    form_hidden_box("action_post", "data_template_edit");
    form_save_button("data_templates.php");
}
示例#27
0
function settings() {
	global $colors, $themes;

	$themes["default"] = _("System Default (Global Setting)");

	/* you cannot have per-user settings if cacti's user management is not turned on */
	if (read_config_option("auth_method") == "0") {
		raise_message(6);
		display_output_messages();
		return;
	}

	/* get user settings */
	$user = api_user_info( array( "id" => $_SESSION["sess_user_id"] ) );

	print "<form method='post'>\n";

	html_start_box("<strong>" . _("User Settings") . "</strong>", "98%", $colors["header_background"], "3", "center", "");

	?>
	<tr bgcolor='<?php print $colors["header_panel_background"];?>'>
		<td colspan='2' class='textSubHeaderDark' style='padding: 3px;'>General</td>
	</tr>
		<?php

	$form_array = array(
		"current_theme" => array(
			"friendly_name" => _("Visual Theme"),
			"description" => _("The Cacti theme to use. Changes the look of Cacti."),
			"method" => "drop_array",
			"array" => $themes,
			"value" => api_user_theme($_SESSION["sess_user_id"]),
			"default" => "default"
			)
		);

	draw_edit_form(
		array(
			"config" => array(
				"no_form_tag" => true
				),
			"fields" => $form_array
			)
		);

	html_end_box();


	form_hidden_box("save_component_user","1","");
	form_save_button((isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : "index.php"), "save");

}
示例#28
0
function graphs()
{
    global $colors;
    /* use the first host in the list as the default */
    if (!isset($_SESSION["sess_graphs_new_host_id"]) && empty($_REQUEST["host_id"])) {
        $_REQUEST["host_id"] = db_fetch_cell("select id from host order by description,hostname limit 1");
    }
    /* remember these search fields in session vars so we don't have to keep passing them around */
    if (isset($_REQUEST["host_id"])) {
        $_SESSION["sess_graphs_new_host_id"] = $_REQUEST["host_id"];
    } else {
        $_REQUEST["host_id"] = $_SESSION["sess_graphs_new_host_id"];
    }
    $host = db_fetch_row("select id,description,hostname,host_template_id from host where id=" . $_REQUEST["host_id"]);
    ?>

	<table width="98%" align="center">
		<form name="form_graph_id">
		<tr>
			<td class="textInfo" colspan="2">
				<?php 
    print $host["description"];
    ?>
 (<?php 
    print $host["hostname"];
    ?>
)
			</td>
			<td align="right" class="textInfo" style="color: #aaaaaa;">
				<?php 
    if (!empty($host["host_template_id"])) {
        print db_fetch_cell("select name from host_template where id=" . $host["host_template_id"]);
    }
    ?>
			</td>
		</tr>
		<tr>
			<td>
			</td>
		</tr>

		<tr>
			<td class="textArea" style="padding: 3px;" width="300" nowrap>
				<?php 
    echo _("Create new graphs for the following host:");
    ?>
			</td>
			<td class="textInfo" rowspan="2" valign="top">
				<span style="color: #c16921;">*</span><a href="devices.php?action=edit&id=<?php 
    print $_REQUEST["host_id"];
    ?>
"><?php 
    echo _("Edit this Host");
    ?>
</a><br>
				<span style="color: #c16921;">*</span><a href="devices.php?action=edit"><?php 
    echo _("Create New Host");
    ?>
</a>
			</td>
		</tr>
			<td>
				<select name="cbo_graph_id" onChange="window.location=document.form_graph_id.cbo_graph_id.options[document.form_graph_id.cbo_graph_id.selectedIndex].value">
					<?php 
    $hosts = db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname");
    if (sizeof($hosts) > 0) {
        foreach ($hosts as $item) {
            print "<option value='graphs_new.php?host_id=" . $item["id"] . "'";
            if ($_REQUEST["host_id"] == $item["id"]) {
                print " selected";
            }
            print ">" . $item["name"] . "</option>\n";
        }
    }
    ?>
				</select>
			</td>
		</tr>
		</form>
	</table>

	<br>

	<form name="chk" method="post" action="graphs_new.php">
	<?php 
    $total_rows = sizeof(db_fetch_assoc("select graph_template_id from host_graph where host_id=" . $_REQUEST["host_id"]));
    /* we give users the option to turn off the javascript features for data queries with lots of rows */
    if (read_config_option("max_data_query_javascript_rows") >= $total_rows) {
        $use_javascript = true;
    } else {
        $use_javascript = false;
    }
    /* ==================== Box: Graph Templates ==================== */
    html_start_box("<strong>" . _("Graph Templates") . "</strong>", "98%", $colors["header_background"], "3", "center", "");
    print "\t<tr bgcolor='#" . $colors["header_panel"] . "'>\n\t\t\t<td class='textSubHeaderDark'>" . _("Name") . "</td>\n\t\t\t<td width='1%' align='center' bgcolor='#819bc0' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_cg' title='" . _("Select All") . "' onClick='SelectAll(\"cg\",this.checked);gt_update_selection_indicators();'></td>\n\n\t\t</tr>\n";
    $ht_graph_templates = db_fetch_assoc("select\n\t\tgraph_template.id,\n\t\tgraph_template.template_name\n\t\tfrom host_graph,graph_template\n\t\twhere host_graph.graph_template_id=graph_template.id\n\t\tand host_graph.host_id = " . $_REQUEST["host_id"] . "\n\t\torder by graph_template.template_name");
    $ht_created_graph_templates = db_fetch_assoc("select\n\t\tgraph.graph_template_id\n\t\tfrom graph,host_graph\n\t\twhere graph.graph_template_id=host_graph.graph_template_id\n\t\tand graph.host_id = " . $host["id"] . "\n\t\tgroup by graph.graph_template_id");
    print "<script type='text/javascript'>\nvar gt_created_graphs = new Array()\n</script>\n";
    if (sizeof($ht_created_graph_templates) > 0 && $use_javascript == true) {
        print "<script type='text/javascript'>\n<!--\n";
        print "var gt_created_graphs = new Array(";
        $cg_ctr = 0;
        foreach ($ht_created_graph_templates as $item) {
            print ($cg_ctr > 0 ? "," : "") . "'" . $item["graph_template_id"] . "'";
            $cg_ctr++;
        }
        print ")\n";
        print "//-->\n</script>\n";
    }
    /* create a row for each graph template associated with the host template */
    $i = 0;
    if (sizeof($ht_graph_templates) > 0) {
        foreach ($ht_graph_templates as $item) {
            $query_row = $item["id"];
            print "<tr id='gt_line{$query_row}' bgcolor='#" . ($i % 2 == 0 ? $colors["form_alternate1"] : $colors["form_alternate2"]) . "'>";
            $i++;
            print "\t\t<td" . ($use_javascript == true ? " onClick='gt_select_line(" . $item["id"] . ");'" : "") . "><span id='gt_text{$query_row}" . "_0'>\n\t\t\t\t\t\t<span id='gt_text{$query_row}" . "_0'><strong>" . _("Create:") . "</strong> " . $item["template_name"] . "</span>\n\t\t\t\t\t</td>\n\t\t\t\t\t<td align='right'>\n\t\t\t\t\t\t<input type='checkbox' name='cg_{$query_row}' id='cg_{$query_row}'" . ($use_javascript == true ? " onClick='gt_update_selection_indicators();'" : "") . ">\n\t\t\t\t\t</td>\n\t\t\t\t</tr>";
        }
    } else {
        print "<tr><td bgcolor='#" . $colors["form_alternate1"] . "' colspan=7><em>" . _("No graph templates specified for this host template.") . "</em></td></tr>";
    }
    if ($use_javascript == true) {
        print "<script type='text/javascript'>gt_update_deps(1);</script>\n";
    }
    $available_graph_templates = db_fetch_assoc("SELECT\n\t\tgraph_template.id,\n\t\tgraph_template.template_name as name\n\t\tFROM snmp_query_graph RIGHT JOIN graph_template\n\t\tON (snmp_query_graph.graph_template_id = graph_template.id)\n\t\tWHERE (((snmp_query_graph.name) Is Null))\n\t\tORDER BY graph_template.template_name");
    /* create a row at the bottom that lets the user create any graph they choose */
    print "\t<tr bgcolor='#" . ($i % 2 == 0 ? $colors["form_alternate1"] : $colors["form_alternate2"]) . "'>\n\t\t\t<td colspan='2' width='60' nowrap>\n\t\t\t\t<strong>Create:</strong>&nbsp;";
    form_dropdown("cg_g", $available_graph_templates, "name", "id", "", "(" . _("Select a graph type to create") . ")", "", "font-size: 10px;");
    print "\t\t</td>\n\t\t</tr>";
    html_end_box();
    /* get a list of all data queries that are assigned to this device */
    $data_queries = api_data_query_device_assigned_list($host["id"]);
    echo "<script type='text/javascript'>\nvar created_graphs = new Array()\n</script>\n";
    if (sizeof($data_queries) > 0) {
        foreach ($data_queries as $data_query) {
            /* we give users the option to turn off the javascript features for data queries with lots of rows */
            if (read_config_option("max_data_query_javascript_rows") >= api_data_query_cache_num_rows_get($data_query["id"], $host["id"])) {
                $use_javascript = true;
            } else {
                $use_javascript = false;
            }
            /* get a list of all graph templates that reference this data query */
            $attached_graph_templates = api_data_query_attached_graphs_list($data_query["id"]);
            /* build a javascript array that keeps tracks of which graphs have already been created */
            if (sizeof($attached_graph_templates) > 0 && $use_javascript == true) {
                echo "<script type='text/javascript'>\n<!--\n";
                foreach ($attached_graph_templates as $graph_template) {
                    /* get a list of all data query indexes that have been created as graphs using this graph template */
                    $created_graphs = api_data_query_graphed_indexes_list($graph_template["id"], $host["id"]);
                    echo "created_graphs[" . $graph_template["id"] . "] = new Array(";
                    $cg_ctr = 0;
                    if (sizeof($created_graphs) > 0) {
                        foreach ($created_graphs as $created_graph) {
                            echo ($cg_ctr > 0 ? "," : "") . "'" . encode_data_query_index($created_graph["data_query_index"]) . "'";
                            $cg_ctr++;
                        }
                    }
                    echo ")\n";
                }
                echo "//-->\n</script>\n";
            }
            $data_query_indexes = array();
            $data_query_field_names = array();
            $data_query_field_desc = array();
            $num_visible_columns = 0;
            $data_query_fields = api_data_query_field_list($data_query["id"], DATA_QUERY_FIELD_TYPE_INPUT);
            /* retrieve a list of values for each data query field from the cache */
            if (sizeof($data_query_fields) > 0) {
                foreach ($data_query_fields as $field) {
                    $cache_data = api_data_query_cache_field_get($data_query["id"], $host["id"], $field["name"]);
                    /* be sure to ignore the fields which contain no data */
                    if (sizeof($cache_data) > 0) {
                        foreach ($cache_data as $row) {
                            $data_query_data[$row["index_value"]][$field["name"]] = $row["field_value"];
                            if (!in_array($row["index_value"], $data_query_indexes, true)) {
                                $data_query_indexes[] = $row["index_value"];
                            }
                        }
                        /* always make sure that the index field is the first column */
                        if ($data_query["index_field_id"] == $field["id"] && sizeof($data_query_field_names) > 0) {
                            $data_query_field_names[] = $data_query_field_names[0];
                            $data_query_field_names[0] = $field["name"];
                        } else {
                            $data_query_field_names[] = $field["name"];
                        }
                        /* keep a hash of field name->desc mappings for the row headings */
                        $data_query_field_desc[$field["name"]] = $field["name_desc"];
                        $num_visible_columns++;
                    }
                }
            }
            /* if the user specified a prefered sort order; sort the list of indexes before displaying them */
            if ($data_query["index_order_type"] == DATA_QUERY_INDEX_SORT_TYPE_ALPHABETIC) {
                usort($data_query_indexes, "usort_alphabetic");
            } else {
                if ($data_query["index_order_type"] == DATA_QUERY_INDEX_SORT_TYPE_NATURAL) {
                    usort($data_query_indexes, "usort_natural");
                } else {
                    if ($data_query["index_order_type"] == DATA_QUERY_INDEX_SORT_TYPE_NUMERIC) {
                        usort($data_query_indexes, "usort_numeric");
                    }
                }
            }
            ?>
			<table width='98%' style='background-color: #<?php 
            echo $colors["form_alternate2"];
            ?>
; border: 1px solid #<?php 
            echo $colors["header_background"];
            ?>
;' align='center' cellpadding='3' cellspacing='0'>
				<tr>
					<td bgcolor='#<?php 
            echo $colors["header_background"];
            ?>
' colspan='<?php 
            echo sizeof($data_query_field_names) + 1;
            ?>
'>
						<table  cellspacing='0' cellpadding='0' width='100%' >
							<tr>
								<td class='textHeaderDark'>
									<strong><?php 
            echo _("Data Query");
            ?>
</strong> [<?php 
            echo $data_query["name"];
            ?>
]
								</td>
								<td align='right' nowrap>
									<a href='graphs_new.php?action=query_reload&id=<?php 
            echo $data_query["id"];
            ?>
&host_id=<?php 
            echo $host["id"];
            ?>
'><img src='<?php 
            echo html_get_theme_images_path("reload_icon_small.gif");
            ?>
' alt='<?php 
            echo _("Reload Associated Query");
            ?>
' border='0' align='absmiddle'></a>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<?php 
            if (sizeof($attached_graph_templates) == 0) {
                echo "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td>" . _("This data query is not being used by any graph templates. You must create at least one graph template that references to a data template using this data query.") . "</td></tr>\n";
            } else {
                if (sizeof($data_query_field_names) == 0) {
                    echo "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td>" . _("This data query returned 0 rows, perhaps there was a problem executing this data query. You can") . " <a href='devices.php?action=query_verbose&id=" . $data_query["id"] . "&host_id=" . $host["id"] . "'>" . _("run this data query in debug mode</a> to get more information.") . "</td></tr>\n";
                } else {
                    echo "<tr bgcolor='#" . $colors["header_panel_background"] . "'>\n";
                    foreach ($data_query_field_names as $field_name) {
                        echo "<td height='1'><strong><font color='#" . $colors["header_text"] . "'>" . $data_query_field_desc[$field_name] . "</font></strong></td>\n";
                    }
                    echo "<td width='1%' align='center' bgcolor='#" . $colors["header_panel_background"] . "' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_" . $data_query["id"] . "' title='Select All' onClick='" . _("SelectAll") . "(\"sg_" . $data_query["id"] . "\",this.checked);" . ($use_javascript == true ? "dq_update_selection_indicators();" : "") . "'></td>\n</tr>\n";
                }
            }
            $row_counter = 0;
            foreach ($data_query_indexes as $index_value) {
                $query_row = $data_query["id"] . "_" . encode_data_query_index($index_value);
                echo "<tr id='line{$query_row}' bgcolor='#" . ($row_counter % 2 == 0 ? $colors["form_alternate1"] : $colors["form_alternate2"]) . "'>";
                $i++;
                $column_counter = 0;
                foreach ($data_query_field_names as $field_name) {
                    echo "<td " . ($use_javascript == true ? "onClick='dq_select_line(" . $data_query["id"] . ",\"" . encode_data_query_index($index_value) . "\");'" : "") . "><span id='text{$query_row}" . "_" . $column_counter . "'>" . (isset($data_query_data[$index_value][$field_name]) ? $data_query_data[$index_value][$field_name] : "") . "</span></td>";
                    $column_counter++;
                }
                echo "<td align='right'>";
                echo "<input type='checkbox' name='sg_{$query_row}' id='sg_{$query_row}' " . ($use_javascript == true ? "onClick='dq_update_selection_indicators();'" : "") . ">";
                echo "</td>";
                echo "</tr>\n";
                $row_counter++;
            }
            echo "</table>";
            if (sizeof($attached_graph_templates) == 1) {
                form_hidden_box("sgg_" . $data_query["id"] . "' id='sgg_" . $data_query["id"], $attached_graph_templates[0]["id"], "");
            } elseif (sizeof($attached_graph_templates) > 1) {
                print "\t<table align='center' width='98%'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td width='1' valign='top'>\n\t\t\t\t\t\t\t\t<img src='" . html_get_theme_images_path("arrow.gif") . "' alt='' align='absmiddle'>&nbsp;\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td align='right'>\n\t\t\t\t\t\t\t\t<span style='font-size: 12px; font-style: italic;'>" . _("Select a graph type:") . "</span>&nbsp;\n\t\t\t\t\t\t\t\t<select name='sgg_" . $data_query["id"] . "' id='sgg_" . $data_query["id"] . "' " . ($use_javascript == true ? "onChange='dq_update_deps(" . $data_query["id"] . "," . $num_visible_columns . ");'" : "") . ">\n\t\t\t\t\t\t\t\t\t";
                html_create_list($attached_graph_templates, "template_name", "id", "0");
                print "\n\t\t\t\t\t\t\t\t</select>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>";
            }
            print "<br>";
            if ($use_javascript == true) {
                print "<script type='text/javascript'>dq_update_deps(" . $data_query["id"] . "," . $num_visible_columns . ");</script>\n";
            }
        }
    }
    form_hidden_box("save_component_graph", "1", "");
    form_hidden_box("host_id", $host["id"], "0");
    form_save_button("graphs_new.php");
    print "<script type='text/javascript'>dq_update_selection_indicators();</script>\n";
    print "<script type='text/javascript'>gt_update_selection_indicators();</script>\n";
}
示例#29
0
function item_edit() {
	global $colors, $struct_graph_item, $graph_item_types, $consolidation_functions;

	if (!empty($_GET["id"])) {
		$template_item = db_fetch_row("select * from graph_templates_item where id=" . $_GET["id"]);
		$host_id = db_fetch_cell("select host_id from graph_local where id=" . $_GET["local_graph_id"]);
	}

	$header_label = "[edit graph: " . db_fetch_cell("select title_cache from graph_templates_graph where local_graph_id=" . $_GET["local_graph_id"]) . "]";

	html_start_box("<strong>Graph Items</strong> $header_label", "98%", $colors["header"], "3", "center", "");

	/* by default, select the LAST DS chosen to make everyone's lives easier */
	if (!empty($_GET["local_graph_id"])) {
		$default = db_fetch_row("select task_item_id from graph_templates_item where local_graph_id=" . $_GET["local_graph_id"] . " order by sequence DESC");

		if (sizeof($default) > 0) {
			$struct_graph_item["task_item_id"]["default"] = $default["task_item_id"];
		}else{
			$struct_graph_item["task_item_id"]["default"] = 0;
		}

		/* modifications to the default graph items array */
		$struct_graph_item["task_item_id"]["sql"] = "select
			CONCAT_WS('',case when host.description is null then 'No Host' when host.description is not null then host.description end,' - ',data_template_data.name_cache,' (',data_template_rrd.data_source_name,')') as name,
			data_template_rrd.id
			from data_template_data,data_template_rrd,data_local
			left join host on data_local.host_id=host.id
			where data_template_rrd.local_data_id=data_local.id
			and data_template_data.local_data_id=data_local.id
			" . (((!empty($host_id)) || (!empty($_GET["host_id"]))) ? (!empty($host_id) ? " and data_local.host_id=$host_id" : " and data_local.host_id=" . $_GET["host_id"]) : "") . "
			order by name";
	}

	$form_array = array();

	while (list($field_name, $field_array) = each($struct_graph_item)) {
		$form_array += array($field_name => $struct_graph_item[$field_name]);

		$form_array[$field_name]["value"] = (isset($template_item) ? $template_item[$field_name] : "");
		$form_array[$field_name]["form_id"] = (isset($template_item) ? $template_item["id"] : "0");

	}

	draw_edit_form(
		array(
			"config" => array(
				),
			"fields" => $form_array
			)
		);

	form_hidden_box("local_graph_id", $_GET["local_graph_id"], "0");
	form_hidden_box("graph_template_item_id", (isset($template_item) ? $template_item["id"] : "0"), "");
	form_hidden_box("local_graph_template_item_id", (isset($template_item) ? $template_item["local_graph_template_item_id"] : "0"), "");
	form_hidden_box("graph_template_id", (isset($template_item) ? $template_item["graph_template_id"] : "0"), "");
	form_hidden_box("sequence", (isset($template_item) ? $template_item["sequence"] : "0"), "");
	form_hidden_box("_graph_type_id", (isset($template_item) ? $template_item["graph_type_id"] : "0"), "");
	form_hidden_box("save_component_item", "1", "");

	html_end_box();

	form_save_button("graphs.php?action=graph_edit&id=" . $_GET["local_graph_id"]);
}
示例#30
0
function template_edit() {
	global $colors, $struct_graph, $image_types, $fields_graph_template_template_edit;

	/* graph item list goes here */
	if (!empty($_GET["id"])) {
		item();
	}

	if (!empty($_GET["id"])) {
		$template = db_fetch_row("select * from graph_templates where id=" . $_GET["id"]);
		$template_graph = db_fetch_row("select * from graph_templates_graph where graph_template_id=" . $_GET["id"] . " and local_graph_id=0");

		$header_label = "[edit: " . $template["name"] . "]";
	}else{
		$header_label = "[new]";
	}

	html_start_box("<strong>Template</strong> $header_label", "98%", $colors["header"], "3", "center", "");

	draw_edit_form(array(
		"config" => array(),
		"fields" => inject_form_variables($fields_graph_template_template_edit, (isset($template) ? $template : array()), (isset($template_graph) ? $template_graph : array()))
		));

	html_end_box();

	html_start_box("<strong>Graph Template</strong>", "98%", $colors["header"], "3", "center", "");

	$form_array = array();

	while (list($field_name, $field_array) = each($struct_graph)) {
		$form_array += array($field_name => $struct_graph[$field_name]);

		$form_array[$field_name]["value"] = (isset($template_graph) ? $template_graph[$field_name] : "");
		$form_array[$field_name]["form_id"] = (isset($template_graph) ? $template_graph["id"] : "0");
		$form_array[$field_name]["description"] = "";
		$form_array[$field_name]["sub_checkbox"] = array(
			"name" => "t_" . $field_name,
			"friendly_name" => "Use Per-Graph Value (Ignore this Value)",
			"value" => (isset($template_graph) ? $template_graph{"t_" . $field_name} : "")
			);
	}

	draw_edit_form(
		array(
			"config" => array(
				),
			"fields" => $form_array
			)
		);

	html_end_box();

	form_save_button("graph_templates.php");
}