示例#1
0
文件: export.php 项目: songchin/Cacti
function device_template_to_xml($device_template_id) {
	require_once(CACTI_BASE_PATH . "/lib/device_template/device_template_info.php");

	$hash = get_hash_version("device_template") . get_hash_device_template($device_template_id);
	$xml_text = "";

	$device_template = db_fetch_row("select * from device_template where id=$device_template_id");
	$device_template_graph = db_fetch_assoc("select * from device_template_graph where device_template_id=$device_template_id");
	$device_template_snmp_query = db_fetch_assoc("select * from device_template_snmp_query where device_template_id=$device_template_id");

	if (empty($device_template["id"])) {
		$err_msg = "Invalid Device Template.";
		return $err_msg;
	}

	$xml_text .= "<hash_$hash>\n";

	/* XML Branch: <> */
	$fields_device_template_edit = device_template_form_list();
	reset($fields_device_template_edit);
	while (list($field_name, $field_array) = each($fields_device_template_edit)) {
		if (($field_array["method"] != "hidden_zero") && ($field_array["method"] != "hidden") && ($field_array["method"] != "spacer")) {
			$xml_text .= "\t<$field_name>" . xml_character_encode($device_template{$field_name}) . "</$field_name>\n";
		}
	}

	/* XML Branch: <graph_templates> */
	$xml_text .= "\t<graph_templates>";

	$j = 0;
	if (sizeof($device_template_graph) > 0) {
	foreach ($device_template_graph as $item) {
		$xml_text .= "hash_" . get_hash_version("graph_template") . get_hash_graph_template($item["graph_template_id"]);

		if (($j+1) < sizeof($device_template_graph)) {
			$xml_text .= "|";
		}

		$j++;
	}
	}

	$xml_text .= "</graph_templates>\n";

	/* XML Branch: <data_queries> */
	$xml_text .= "\t<data_queries>";

	$j = 0;
	if (sizeof($device_template_snmp_query) > 0) {
	foreach ($device_template_snmp_query as $item) {
		$xml_text .= "hash_" . get_hash_version("data_query") . get_hash_data_query($item["snmp_query_id"]);

		if (($j+1) < sizeof($device_template_snmp_query)) {
			$xml_text .= "|";
		}

		$j++;
	}
	}

	$xml_text .= "</data_queries>\n";

	$xml_text .= "</hash_$hash>";

	return $xml_text;
}
示例#2
0
function duplicate_device_template($_device_template_id, $device_template_title) {
	require_once(CACTI_BASE_PATH . "/lib/device_template/device_template_info.php");

	$device_template = db_fetch_row("select * from device_template where id=$_device_template_id");
	$device_template_graphs = db_fetch_assoc("select * from device_template_graph where device_template_id=$_device_template_id");
	$device_template_data_queries = db_fetch_assoc("select * from device_template_snmp_query where device_template_id=$_device_template_id");

	/* substitute the title variable */
	$device_template["name"] = str_replace(__("<template_title>"), $device_template["name"], $device_template_title);

	/* create new entry: device_template */
	$save["id"] = 0;
	$save["hash"] = get_hash_device_template(0);

	$fields_device_template_edit = device_template_form_list();
	reset($fields_device_template_edit);
	while (list($field, $array) = each($fields_device_template_edit)) {
		if (!preg_match("/^hidden/", $array["method"])) {
			$save[$field] = $device_template[$field];
		}
	}

	$device_template_id = sql_save($save, "device_template");

	/* create new entry(s): device_template_graph */
	if (sizeof($device_template_graphs) > 0) {
	foreach ($device_template_graphs as $device_template_graph) {
		db_execute("insert into device_template_graph (device_template_id,graph_template_id) values ($device_template_id," . $device_template_graph["graph_template_id"] . ")");
	}
	}

	/* create new entry(s): device_template_snmp_query */
	if (sizeof($device_template_data_queries) > 0) {
	foreach ($device_template_data_queries as $device_template_data_query) {
		db_execute("insert into device_template_snmp_query (device_template_id,snmp_query_id) values ($device_template_id," . $device_template_data_query["snmp_query_id"] . ")");
	}
	}
}
示例#3
0
function device_template_form_save() {

	if (isset($_POST["save_component_template"])) {
		/* ================= input validation ================= */
		input_validate_input_number(get_request_var_post("id"));
		/* ==================================================== */
		$redirect_back = false;
		$tab = "&tab=general";

		$save["id"] 					= get_request_var_post("id");
		$save["hash"]					= get_hash_device_template($_POST["id"]);
		$save["name"]					= form_input_validate($_POST["name"], "name", "", false, 3);
		$save["description"]			= form_input_validate($_POST["description"], "description", "", true, 3);
		$save["image"]					= form_input_validate($_POST["image"], "image", "", true, 3);
		$save["override_defaults"]		= form_input_validate((isset($_POST["override_defaults"]) ? "on":""), "override_defaults", "", true, 3);
		$save["override_permitted"]		= form_input_validate((isset($_POST["override_permitted"]) ? "on":""), "override_permitted", "", true, 3);
		$save["snmp_version"]			= form_input_validate($_POST["snmp_version"], "snmp_version", "", true, 3);
		$save["snmp_version"]			= form_input_validate($_POST["snmp_version"], "snmp_version", "", true, 3);
		$save["snmp_community"]			= form_input_validate($_POST["snmp_community"], "snmp_community", "", true, 3);
		$save["snmp_username"]			= form_input_validate($_POST["snmp_username"], "snmp_username", "", true, 3);
		$save["snmp_password"]			= form_input_validate($_POST["snmp_password"], "snmp_password", "", true, 3);
		$save["snmp_auth_protocol"]		= form_input_validate($_POST["snmp_auth_protocol"], "snmp_auth_protocol", "", true, 3);
		$save["snmp_priv_passphrase"]	= form_input_validate($_POST["snmp_priv_passphrase"], "snmp_priv_passphrase", "", true, 3);
		$save["snmp_priv_protocol"]		= form_input_validate($_POST["snmp_priv_protocol"], "snmp_priv_protocol", "", true, 3);
		$save["snmp_context"]			= form_input_validate($_POST["snmp_context"], "snmp_context", "", true, 3);
		$save["snmp_port"]				= form_input_validate($_POST["snmp_port"], "snmp_port", "^[0-9]+$", false, 3);
		$save["snmp_timeout"]			= form_input_validate($_POST["snmp_timeout"], "snmp_timeout", "^[0-9]+$", false, 3);
		$save["availability_method"]	= form_input_validate($_POST["availability_method"], "availability_method", "^[0-9]+$", false, 3);
		$save["ping_method"]			= form_input_validate($_POST["ping_method"], "ping_method", "^[0-9]+$", false, 3);
		$save["ping_port"]				= form_input_validate($_POST["ping_port"], "ping_port", "^[0-9]+$", true, 3);
		$save["ping_timeout"]			= form_input_validate($_POST["ping_timeout"], "ping_timeout", "^[0-9]+$", true, 3);
		$save["ping_retries"]			= form_input_validate($_POST["ping_retries"], "ping_retries", "^[0-9]+$", true, 3);
		$save["max_oids"]				= form_input_validate($_POST["max_oids"], "max_oids", "^[0-9]+$", true, 3);
		$save["device_threads"]			= form_input_validate($_POST["device_threads"], "device_threads", "^[0-9]+$", true, 3);

		if (!is_error_message()) {
			$device_template_id = sql_save($save, "device_template");

			if ($device_template_id) {
				raise_message(1);
			}else{
				raise_message(2);
			}
		}
	}

	header("Location: device_templates.php?action=edit&tab=general&id=" . (empty($device_template_id) ? $_POST["id"] : $device_template_id));
	exit;
}