コード例 #1
0
ファイル: notify_lists.php プロジェクト: resmon/resmon-cacti
function form_save()
{
    /* modify for multi user start */
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_post("id"));
    /* ==================================================== */
    if (!check_notification($_REQUEST['id'])) {
        access_denied();
    }
    /* modify for multi user end */
    if (isset($_POST["save_component"])) {
        $save["id"] = $_POST["id"];
        $save["name"] = form_input_validate($_POST["name"], "name", "", false, 3);
        $save["description"] = form_input_validate($_POST["description"], "description", "", false, 3);
        $save["emails"] = form_input_validate($_POST["emails"], "emails", "", false, 3);
        if (!is_error_message()) {
            $id = sql_save($save, "plugin_notification_lists");
            if ($id) {
                raise_message(1);
            } else {
                raise_message(2);
            }
        }
    }
    header("Location: notify_lists.php?action=edit&id=" . (empty($id) ? $_POST["id"] : $id));
}
コード例 #2
0
ファイル: host_templates.php プロジェクト: MrWnn/cacti
function form_save()
{
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_post('host_template_id'));
    input_validate_input_number(get_request_var_post('snmp_query_id'));
    input_validate_input_number(get_request_var_post('graph_template_id'));
    /* ==================================================== */
    if (isset($_POST['save_component_template'])) {
        $redirect_back = false;
        $save['id'] = $_POST['id'];
        $save['hash'] = get_hash_host_template($_POST['id']);
        $save['name'] = form_input_validate($_POST['name'], 'name', '', false, 3);
        if (!is_error_message()) {
            $host_template_id = sql_save($save, 'host_template');
            if ($host_template_id) {
                raise_message(1);
                if (isset($_POST['add_gt_x'])) {
                    db_execute_prepared('REPLACE INTO host_template_graph (host_template_id, graph_template_id) VALUES (?, ?)', array($host_template_id, $_POST['graph_template_id']));
                    $redirect_back = true;
                } elseif (isset($_POST['add_dq_x'])) {
                    db_execute_prepared('REPLACE INTO host_template_snmp_query (host_template_id, snmp_query_id) VALUES (?, ?)', array($host_template_id, $_POST['snmp_query_id']));
                    $redirect_back = true;
                }
            } else {
                raise_message(2);
            }
        }
        header('Location: host_templates.php?action=edit&id=' . (empty($host_template_id) ? $_POST['id'] : $host_template_id));
    }
}
コード例 #3
0
ファイル: host_templates.php プロジェクト: teddywen/cacti
function form_save()
{
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_post("id"));
    input_validate_input_number(get_request_var_post("host_template_id"));
    input_validate_input_number(get_request_var_post("snmp_query_id"));
    input_validate_input_number(get_request_var_post("graph_template_id"));
    /* ==================================================== */
    if (isset($_POST["save_component_template"])) {
        $redirect_back = false;
        $save["id"] = $_POST["id"];
        $save["hash"] = get_hash_host_template($_POST["id"]);
        $save["name"] = form_input_validate($_POST["name"], "name", "", false, 3);
        if (!is_error_message()) {
            $host_template_id = sql_save($save, "host_template");
            if ($host_template_id) {
                raise_message(1);
                if (isset($_POST["add_gt_x"])) {
                    db_execute("replace into host_template_graph (host_template_id,graph_template_id) values({$host_template_id}," . $_POST["graph_template_id"] . ")");
                    $redirect_back = true;
                } elseif (isset($_POST["add_dq_x"])) {
                    db_execute("replace into host_template_snmp_query (host_template_id,snmp_query_id) values({$host_template_id}," . $_POST["snmp_query_id"] . ")");
                    $redirect_back = true;
                }
            } else {
                raise_message(2);
            }
        }
        header("Location: host_templates.php?action=edit&id=" . (empty($host_template_id) ? $_POST["id"] : $host_template_id));
    }
}
コード例 #4
0
ファイル: device_templates.php プロジェクト: songchin/Cacti
function form_save()
{
    if (isset($_POST["save_component_template"])) {
        $redirect_back = false;
        $save["id"] = $_POST["id"];
        $save["name"] = form_input_validate($_POST["name"], "name", "", false, 3);
        if (!is_error_message()) {
            $host_template_id = sql_save($save, "host_template");
            if ($host_template_id) {
                raise_message(1);
                if (isset($_POST["add_gt_x"])) {
                    db_execute("replace into host_template_graph (host_template_id,graph_template_id) values({$host_template_id}," . $_POST["graph_template_id"] . ")");
                    $redirect_back = true;
                } elseif (isset($_POST["add_dq_x"])) {
                    db_execute("replace into host_template_data_query (host_template_id,data_query_id) values({$host_template_id}," . $_POST["snmp_query_id"] . ")");
                    $redirect_back = true;
                }
            } else {
                raise_message(2);
            }
        }
        if (is_error_message() || empty($_POST["id"]) || $redirect_back == true) {
            header("Location: device_templates.php?action=edit&id=" . (empty($host_template_id) ? $_POST["id"] : $host_template_id));
        } else {
            header("Location: device_templates.php");
        }
    }
}
コード例 #5
0
ファイル: gprint_presets.php プロジェクト: songchin/Cacti
function form_save() {
	if (isset($_POST["save_component_gprint_presets"])) {
		$save["id"] = $_POST["id"];
		$save["hash"] = get_hash_gprint($_POST["id"]);
		$save["name"] = form_input_validate($_POST["name"], "name", "", false, 3);
		$save["gprint_text"] = form_input_validate($_POST["gprint_text"], "gprint_text", "", false, 3);

		if (!is_error_message()) {
			$gprint_preset_id = sql_save($save, "graph_templates_gprint");

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

		if (is_error_message()) {
			header("Location: gprint_presets.php?action=edit&id=" . (empty($gprint_preset_id) ? $_POST["id"] : $gprint_preset_id));
			exit;
		}else{
			header("Location: gprint_presets.php");
			exit;
		}
	}
}
コード例 #6
0
ファイル: rra.php プロジェクト: BackupTheBerlios/odp-svn
function form_save()
{
    if (isset($_POST["save_component_rra"])) {
        $save["id"] = $_POST["id"];
        $save["hash"] = get_hash_round_robin_archive($_POST["id"]);
        $save["name"] = form_input_validate($_POST["name"], "name", "", false, 3);
        $save["x_files_factor"] = form_input_validate($_POST["x_files_factor"], "x_files_factor", "^[0-9]+(\\.[0-9])?\$", false, 3);
        $save["steps"] = form_input_validate($_POST["steps"], "steps", "^[0-9]*\$", false, 3);
        $save["rows"] = form_input_validate($_POST["rows"], "rows", "^[0-9]*\$", false, 3);
        $save["timespan"] = form_input_validate($_POST["timespan"], "timespan", "^[0-9]*\$", false, 3);
        if (!is_error_message()) {
            $rra_id = sql_save($save, "rra");
            if ($rra_id) {
                raise_message(1);
                db_execute("delete from rra_cf where rra_id={$rra_id}");
                if (isset($_POST["consolidation_function_id"])) {
                    for ($i = 0; $i < count($_POST["consolidation_function_id"]); $i++) {
                        /* ================= input validation ================= */
                        input_validate_input_number($_POST["consolidation_function_id"][$i]);
                        /* ==================================================== */
                        db_execute("insert into rra_cf (rra_id,consolidation_function_id)\n\t\t\t\t\t\t\tvalues ({$rra_id}," . $_POST["consolidation_function_id"][$i] . ")");
                    }
                }
            } else {
                raise_message(2);
            }
        }
        if (is_error_message()) {
            header("Location: rra.php?action=edit&id=" . (empty($rra_id) ? $_POST["id"] : $rra_id));
        } else {
            header("Location: rra.php");
        }
    }
}
コード例 #7
0
ファイル: message.php プロジェクト: songchin/Cacti
function display_output_messages() {
	global $messages, $colors;

	if (isset($_SESSION["sess_messages"])) {
		$error_message = is_error_message();

		if (is_array($_SESSION["sess_messages"])) {
			foreach (array_keys($_SESSION["sess_messages"]) as $current_message_id) {
				eval ('$message = "' . $messages[$current_message_id]["message"] . '";');

				switch ($messages[$current_message_id]["type"]) {
				case 'info':
					if ($error_message == false) {
						print "<table align='center' width='98%' style='background-color: #" . $colors['messagebar_background'] . "; border: 1px solid #" . $colors['messagebar_border'] . ";'>";
						print "<tr><td bgcolor='#" . $colors["messagebar_background"] . "'><p class='textInfo'>$message</p></td></tr>";
						print "</table><br>";
					}
					break;
				case 'error':
					print "<table align='center' width='98%' style='background-color: #" . $colors['messagebar_background'] . "; border: 1px solid #ff0000;'>";
					print "<tr><td bgcolor='#" . $colors["messagebar_background"] . "'><p class='textError'>Error: $message</p></td></tr>";
					print "</table><br>";
					break;
				}
			}
		}
	}

	kill_session_var("sess_messages");
}
コード例 #8
0
ファイル: graphs_items.php プロジェクト: songchin/Cacti
function form_save()
{
    if (isset($_POST["save_component_item"])) {
        /* cache all post field values */
        init_post_field_cache();
        /* step #1: field validation */
        $form_graph_item["id"] = $_POST["graph_item_id"];
        $form_graph_item["graph_id"] = $_POST["graph_id"];
        $form_graph_item["data_source_item_id"] = $_POST["data_source_item_id"];
        $form_graph_item["color"] = $_POST["color"];
        $form_graph_item["graph_item_type"] = $_POST["graph_item_type"];
        $form_graph_item["consolidation_function"] = $_POST["consolidation_function"];
        $form_graph_item["cdef"] = $_POST["cdef"];
        $form_graph_item["gprint_format"] = $_POST["gprint_format"];
        $form_graph_item["legend_value"] = $_POST["legend_value"];
        $form_graph_item["legend_format"] = $_POST["legend_format"];
        $form_graph_item["hard_return"] = html_boolean(isset($_POST["hard_return"]) ? $_POST["hard_return"] : "");
        field_register_error(api_graph_item_fields_validate($form_graph_item, "|field|"));
        /* step #2: field save */
        if (!is_error_message()) {
            $graph_item_id = api_graph_item_save($_POST["graph_item_id"], $form_graph_item);
        }
        if (is_error_message()) {
            header("Location: graph_items.php?action=edit" . (empty($graph_item_id) ? "" : "&id=" . $graph_item_id) . "&graph_id=" . $_POST["graph_id"]);
        } else {
            header("Location: graphs.php?action=edit&id=" . $_POST["graph_id"]);
        }
    }
}
コード例 #9
0
ファイル: xaxis_form.php プロジェクト: songchin/Cacti
function xaxis_form_save() {

	if (isset($_POST["save_component_xaxis"])) {
		$save["id"]   = $_POST["id"];
		$save["hash"] = get_hash_xaxis($_POST["id"]);
		$save["name"] = form_input_validate($_POST["name"], "name", "", false, 3);

		if (!is_error_message()) {
			$xaxis_id = sql_save($save, "graph_templates_xaxis");

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

		if ((is_error_message()) || (empty($_POST["id"]))) {
			header("Location: xaxis_presets.php?action=edit&id=" . (empty($xaxis_id) ? $_POST["id"] : $xaxis_id));
		}else{
			header("Location: xaxis_presets.php");
		}
		exit;
	}

	if ((isset($_POST["save_component_item"]))) {
		$save["id"]   = $_POST["id"];
		$save["hash"] = get_hash_xaxis($_POST["id"], "xaxis_item");
		$save["item_name"] = form_input_validate($_POST["item_name"], "item_name", "", true, 3);
		$save["xaxis_id"] = form_input_validate($_POST["xaxis_id"], "xaxis_id", "^[0-9]+$", false, 3);
		$save["timespan"] = form_input_validate($_POST["timespan"], "timespan", "^[0-9]+$", false, 3);
		$save["gtm"] = form_input_validate($_POST["gtm"], "gtm", "", false, 3);
		$save["gst"] = form_input_validate($_POST["gst"], "gst", "^[0-9]+$", false, 3);
		$save["mtm"] = form_input_validate($_POST["mtm"], "mtm", "", false, 3);
		$save["mst"] = form_input_validate($_POST["mst"], "mst", "^[0-9]+$", false, 3);
		$save["ltm"] = form_input_validate($_POST["ltm"], "ltm", "", false, 3);
		$save["lst"] = form_input_validate($_POST["lst"], "lst", "^[0-9]+$", false, 3);
		$save["lpr"] = form_input_validate($_POST["lpr"], "lpr", "^[0-9]+$", false, 3);
		$save["lfm"] = form_input_validate($_POST["lfm"], "lfm", "", true, 3);

		if (!is_error_message()) {
			$xaxis_item_id = sql_save($save, "graph_templates_xaxis_items");

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

		if ((is_error_message()) || (empty($_POST["id"]))) {
			header("Location: xaxis_presets.php?action=item_edit&xaxis_id=" . $_POST["xaxis_id"] . "&id=" . (empty($xaxis_item_id) ? $_POST["id"] : $xaxis_item_id));
		}else{
			header("Location: xaxis_presets.php?action=edit&id=" . (!empty($_POST["xaxis_id"]) ? $_POST["xaxis_id"] : 0));
		}
		exit;
	}
}
コード例 #10
0
ファイル: api_device.php プロジェクト: songchin/Cacti
function api_device_save($id, $host_template_id, $description, $hostname, $snmp_community, $snmp_version, $snmp_username, $snmp_password, $snmp_port, $snmp_timeout, $disabled)
{
    /* fetch some cache variables */
    if (empty($id)) {
        $_host_template_id = 0;
    } else {
        $_host_template_id = db_fetch_cell("select host_template_id from host where id={$id}");
    }
    $save["id"] = $id;
    $save["host_template_id"] = form_input_validate($host_template_id, "host_template_id", "^[0-9]+\$", false, 3);
    $save["description"] = form_input_validate($description, "description", "", false, 3);
    $save["hostname"] = form_input_validate($hostname, "hostname", "", false, 3);
    $save["snmp_community"] = form_input_validate($snmp_community, "snmp_community", "", true, 3);
    $save["snmp_version"] = form_input_validate($snmp_version, "snmp_version", "", true, 3);
    $save["snmp_username"] = form_input_validate($snmp_username, "snmp_username", "", true, 3);
    $save["snmp_password"] = form_input_validate($snmp_password, "snmp_password", "", true, 3);
    $save["snmp_port"] = form_input_validate($snmp_port, "snmp_port", "^[0-9]+\$", false, 3);
    $save["snmp_timeout"] = form_input_validate($snmp_timeout, "snmp_timeout", "^[0-9]+\$", false, 3);
    $save["disabled"] = form_input_validate($disabled, "disabled", "", true, 3);
    $host_id = 0;
    if (!is_error_message()) {
        $host_id = sql_save($save, "host");
        if ($host_id) {
            raise_message(1);
            /* push out relavant fields to data sources using this host */
            push_out_host($host_id, 0);
            /* the host substitution cache is now stale; purge it */
            kill_session_var("sess_host_cache_array");
            /* update title cache for graph and data source */
            update_data_source_title_cache_from_host($host_id);
            update_graph_title_cache_from_host($host_id);
        } else {
            raise_message(2);
        }
        /* if the user changes the host template, add each snmp query associated with it */
        if ($host_template_id != $_host_template_id && !empty($host_template_id)) {
            $snmp_queries = db_fetch_assoc("select snmp_query_id from host_template_snmp_query where host_template_id={$host_template_id}");
            if (sizeof($snmp_queries) > 0) {
                foreach ($snmp_queries as $snmp_query) {
                    db_execute("replace into host_snmp_query (host_id,snmp_query_id,reindex_method) values ({$host_id}," . $snmp_query["snmp_query_id"] . "," . DATA_QUERY_AUTOINDEX_BACKWARDS_UPTIME . ")");
                    /* recache snmp data */
                    run_data_query($host_id, $snmp_query["snmp_query_id"]);
                }
            }
            $graph_templates = db_fetch_assoc("select graph_template_id from host_template_graph where host_template_id={$host_template_id}");
            if (sizeof($graph_templates) > 0) {
                foreach ($graph_templates as $graph_template) {
                    db_execute("replace into host_graph (host_id,graph_template_id) values ({$host_id}," . $graph_template["graph_template_id"] . ")");
                }
            }
        }
    }
    return $host_id;
}
コード例 #11
0
function api_mactrack_device_save($device_id, $host_id, $site_id, $hostname,
	$device_name, $scan_type, $snmp_options, $snmp_readstring,
	$snmp_version, $snmp_username, $snmp_password, $snmp_auth_protocol,
	$snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context,
	$snmp_port, $snmp_timeout, $snmp_retries, $max_oids,
	$ignorePorts, $notes, $user_name, $user_password, $term_type,
	$private_key_path, $disabled) {
	global $config;
	include_once($config["base_path"] . "/plugins/mactrack/lib/mactrack_functions.php");

	$save["device_id"] = $device_id;
	$save["host_id"] = $host_id;
	$save["site_id"] = $site_id;
	$save["hostname"] = form_input_validate($hostname, "hostname", "", false, 3);
	$save["device_name"] = form_input_validate($device_name, "device_name", "", false, 3);
	$save["notes"] = form_input_validate($notes, "notes", "", true, 3);
	$save["scan_type"] = form_input_validate($scan_type, "scan_type", "", false, 3);
	$save["snmp_options"] = form_input_validate($snmp_options, "snmp_options", "^[0-9]+$", true, 3);
	$save["snmp_readstring"] = form_input_validate($snmp_readstring, "snmp_readstring", "", true, 3); # for SNMP V3, this is optional
	$save["snmp_version"] = form_input_validate($snmp_version, "snmp_version", "", false, 3);
	$save["snmp_username"]        = form_input_validate($snmp_username, "snmp_username", "", true, 3);
	$save["snmp_password"]        = form_input_validate($snmp_password, "snmp_password", "", true, 3);
	$save["snmp_auth_protocol"]   = form_input_validate($snmp_auth_protocol, "snmp_auth_protocol", "", true, 3);
	$save["snmp_priv_passphrase"] = form_input_validate($snmp_priv_passphrase, "snmp_priv_passphrase", "", true, 3);
	$save["snmp_priv_protocol"]   = form_input_validate($snmp_priv_protocol, "snmp_priv_protocol", "", true, 3);
	$save["snmp_context"]         = form_input_validate($snmp_context, "snmp_context", "", true, 3);
	$save["snmp_port"] = form_input_validate($snmp_port, "snmp_port", "^[0-9]+$", false, 3);
	$save["snmp_timeout"] = form_input_validate($snmp_timeout, "snmp_timeout", "^[0-9]+$", false, 3);
	$save["snmp_retries"] = form_input_validate($snmp_retries, "snmp_retries", "^[0-9]+$", false, 3);
	$save["max_oids"] = form_input_validate($max_oids, "max_oids", "^[0-9]+$", false, 3);
	$save["user_name"] = form_input_validate($user_name, "user_name", "", true, 3);
	$save["user_password"] = form_input_validate($user_password, "user_password", "", true, 3);
	$save["ignorePorts"] = form_input_validate($ignorePorts, "ignorePorts", "", true, 3);
	$save["term_type"] = form_input_validate($term_type, "term_type", "", true, 3);
	$save["private_key_path"] = form_input_validate($private_key_path, "private_key_path", "", true, 3);
	$save["disabled"] = form_input_validate($disabled, "disabled", "", true, 3);

	$device_id = 0;
	if (!is_error_message()) {
		$device_id = sql_save($save, "mac_track_devices", "device_id");

		if ($device_id) {
			raise_message(1);
			sync_mactrack_to_cacti($save);
		}else{
			raise_message(2);
			mactrack_debug("ERROR: Cacti Device: ($device_id/$host_id): $hostname, error on save: " . serialize($save));
		}
	} else {
		mactrack_debug("ERROR: Cacti Device: ($device_id/$host_id): $hostname, error on verify: " . serialize($save));
	}

	return $device_id;
}
コード例 #12
0
ファイル: pollers.php プロジェクト: songchin/Cacti
function form_post() {
	global $registered_cacti_names;

	if (isset($_POST["save_component_data_poller"])) {
		$poller_id = api_poller_save($_POST["poller_id"], (isset($_POST["active"]) ? $_POST["active"] : ""), $_POST["hostname"], $_POST["name"]);

		if ((is_error_message()) || (empty($_POST["poller_id"]))) {
			header("Location: pollers.php?action=edit&poller_id=" . (empty($poller_id) ? $_POST["poller_id"] : $poller_id));
		}else{
			header("Location: pollers.php");
		}
	}
}
コード例 #13
0
ファイル: scripts.php プロジェクト: songchin/Cacti
function form_save() {
	if ($_POST["action_post"] == "script_edit") {
		/* cache all post field values */
		init_post_field_cache();

		$form_script["name"] = $_POST["name"];
		$form_script["input_string"] = $_POST["input_string"];
		$form_script["type_id"] = $_POST["type_id"];

		field_register_error(api_script_field_validate($form_script, "|field|"));

		/* if the validation passes, save the row to the database */
		if (!is_error_message()) {
			$script_id = api_script_save($_POST["id"], $form_script);
		}

		if ((is_error_message()) || (empty($_POST["id"]))) {
			header("Location: scripts.php?action=edit&id=" . (empty($script_id) ? $_POST["id"] : $script_id));
		}else{
			header("Location: scripts.php");
		}
	/* submit button on the actions area page */
	}else if ($_POST["action_post"] == "box-1") {
		$selected_rows = explode(":", $_POST["box-1-action-area-selected-rows"]);

		if ($_POST["box-1-action-area-type"] == "remove") {
			foreach ($selected_rows as $script_id) {
				api_script_remove($script_id);
			}
		}else if ($_POST["box-1-action-area-type"] == "duplicate") {
			// yet yet coded
		}

		header("Location: scripts.php");
	/* 'filter' area at the bottom of the box */
	}else if ($_POST["action_post"] == "script_list") {
		$get_string = "";

		/* the 'clear' button wasn't pressed, so we should filter */
		if (!isset($_POST["box-1-action-clear-button"])) {
			if (trim($_POST["box-1-search_filter"]) != "") {
				$get_string = ($get_string == "" ? "?" : "&") . "search_filter=" . urlencode($_POST["box-1-search_filter"]);
			}
		}

		header("Location: scripts.php$get_string");
	}
}
コード例 #14
0
ファイル: graph_trees.php プロジェクト: songchin/Cacti
function form_save()
{
    if ($_POST["action_post"] == "graph_tree_edit") {
        /* cache all post field values */
        init_post_field_cache();
        $form_graph_tree["name"] = $_POST["name"];
        $form_graph_tree["sort_type"] = $_POST["sort_type"];
        /* validate graph tree preset fields */
        field_register_error(api_graph_tree_fields_validate($form_graph_tree, "|field|"));
        if (!is_error_message()) {
            $graph_tree_id = api_graph_tree_save($_POST["id"], $form_graph_tree);
        }
        if (is_error_message()) {
            header("Location: graph_trees.php?action=edit" . (empty($graph_tree_id) ? "" : "&id={$graph_tree_id}"));
        } else {
            header("Location: graph_trees.php");
        }
        /* submit button on the actions area page */
    } else {
        if ($_POST["action_post"] == "box-1") {
            $selected_rows = explode(":", $_POST["box-1-action-area-selected-rows"]);
            if ($_POST["box-1-action-area-type"] == "remove") {
                foreach ($selected_rows as $graph_tree_id) {
                    api_graph_tree_remove($graph_tree_id);
                }
            } else {
                if ($_POST["box-1-action-area-type"] == "duplicate") {
                    // yet yet coded
                }
            }
            header("Location: graph_trees.php");
            /* 'filter' area at the bottom of the box */
        } else {
            if ($_POST["action_post"] == "graph_tree_list") {
                $get_string = "";
                /* the 'clear' button wasn't pressed, so we should filter */
                if (!isset($_POST["box-1-action-clear-button"])) {
                    if (trim($_POST["box-1-search_filter"]) != "") {
                        $get_string = ($get_string == "" ? "?" : "&") . "search_filter=" . urlencode($_POST["box-1-search_filter"]);
                    }
                }
                header("Location: graph_trees.php{$get_string}");
            }
        }
    }
}
コード例 #15
0
ファイル: notify_lists.php プロジェクト: Cacti/plugin_thold
function form_save()
{
    if (isset_request_var('save_component')) {
        $save['id'] = get_filter_request_var('id');
        $save['name'] = form_input_validate(get_nfilter_request_var('name'), 'name', '', false, 3);
        $save['description'] = form_input_validate(get_nfilter_request_var('description'), 'description', '', false, 3);
        $save['emails'] = form_input_validate(get_nfilter_request_var('emails'), 'emails', '', false, 3);
        if (!is_error_message()) {
            $id = sql_save($save, 'plugin_notification_lists');
            if ($id) {
                raise_message(1);
            } else {
                raise_message(2);
            }
        }
    }
    header('Location: notify_lists.php?header=false&action=edit&id=' . (empty($id) ? get_request_var('id') : $id));
}
コード例 #16
0
ファイル: notify_lists.php プロジェクト: teddywen/cacti
function form_save()
{
    if (isset($_POST["save_component"])) {
        $save["id"] = $_POST["id"];
        $save["name"] = form_input_validate($_POST["name"], "name", "", false, 3);
        $save["description"] = form_input_validate($_POST["description"], "description", "", false, 3);
        $save["emails"] = form_input_validate($_POST["emails"], "emails", "", false, 3);
        if (!is_error_message()) {
            $id = sql_save($save, "plugin_notification_lists");
            if ($id) {
                raise_message(1);
            } else {
                raise_message(2);
            }
        }
    }
    header("Location: notify_lists.php?action=edit&id=" . (empty($id) ? $_POST["id"] : $id));
}
コード例 #17
0
ファイル: api_rra_templates.php プロジェクト: songchin/Cacti
function api_rra_template_save($id, $name, $description) {
	$save["id"] = $id;
	$save["name"] = form_input_validate($name, "name", "", true, 3);
	$save["description"] = form_input_validate($description, "description", "", false, 3);

	$rra_template_id = 0;

	if (!is_error_message()) {
		$rra_template_id = sql_save($save, "rra_template");

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

	return $rra_template_id;
}
コード例 #18
0
function form_save()
{
    if (isset($_POST["save_component_input"])) {
        $form_selected_graph_item = array();
        /* list all selected graph items on the form */
        reset($_POST);
        while (list($var, $val) = each($_POST)) {
            if (substr($var, 0, 2) == "i_") {
                $matches = explode("_", $var);
                $form_selected_graph_item[] = $matches[1];
            }
        }
        $graph_template_item_input_id = api_graph_template_item_input_save($_POST["id"], $form_selected_graph_item, $_POST["graph_template_id"], $_POST["field_name"], $_POST["name"]);
        if (is_error_message()) {
            header("Location: graph_templates_inputs.php?action=edit" . (empty($graph_template_item_input_id) ? "" : "&id=" . $graph_template_item_input_id) . "&graph_template_id=" . $_POST["graph_template_id"]);
        } else {
            header("Location: graph_templates.php?action=edit&id=" . $_POST["graph_template_id"]);
        }
    }
}
コード例 #19
0
ファイル: color.php プロジェクト: MrWnn/cacti
function form_save()
{
    if (isset($_POST['save_component_color'])) {
        $save['id'] = $_POST['id'];
        $save['hex'] = form_input_validate($_POST['hex'], 'hex', '^[a-fA-F0-9]+$', false, 3);
        if (!is_error_message()) {
            $color_id = sql_save($save, 'colors');
            if ($color_id) {
                raise_message(1);
            } else {
                raise_message(2);
            }
        }
        if (is_error_message()) {
            header('Location: color.php?action=edit&id=' . (empty($color_id) ? $_POST['id'] : $color_id));
        } else {
            header('Location: color.php');
        }
    }
}
コード例 #20
0
ファイル: poller_update.php プロジェクト: songchin/Cacti
function api_poller_save($poller_id, $active, $hostname, $description) {
	$save["id"] = $poller_id;
	$save["name"] = form_input_validate($description, "name", "", true, 3);
	$save["hostname"] = form_input_validate($hostname, "hostname", "", true, 3);
	$save["active"] = form_input_validate($active, "active", "", true, 3);

	$poller_id = 0;

	if (!is_error_message()) {
		$poller_id = sql_save($save, "poller");

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

	return $poller_id;
}
コード例 #21
0
ファイル: color.php プロジェクト: songchin/Cacti
function form_save()
{
    if (isset($_POST["save_component_color"])) {
        $save["id"] = $_POST["id"];
        $save["hex"] = form_input_validate($_POST["hex"], "hex", "^[a-fA-F0-9]+\$", false, 3);
        if (!is_error_message()) {
            $color_id = sql_save($save, "colors");
            if ($color_id) {
                raise_message(1);
            } else {
                raise_message(2);
            }
        }
        if (is_error_message()) {
            header("Location: color.php?action=edit&id=" . (empty($color_id) ? $_POST["id"] : $color_id));
        } else {
            header("Location: color.php");
        }
    }
}
コード例 #22
0
ファイル: color.php プロジェクト: songchin/Cacti
function form_save() {
	if (isset($_POST["save_component_color"])) {
		$save["id"] = $_POST["id"];
		$save["hex"] = form_input_validate($_POST["hex"], "hex", "^[a-fA-F0-9]+$", false, 3);

		if (!is_error_message()) {
			$color_id = sql_save($save, "colors");

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

		if (is_error_message()) {
			header("Location: color.php?action=edit&id=" . (empty($color_id) ? $_POST["id"] : $color_id));
		}else{
			header("Location: color.php");
		}
	}

	if (isset($_POST["save_component_import"])) {
		if (($_FILES["import_file"]["tmp_name"] != "none") && ($_FILES["import_file"]["tmp_name"] != "")) {
			/* file upload */
			$csv_data = file($_FILES["import_file"]["tmp_name"]);

			/* obtain debug information if it's set */
			$debug_data = import_processor($csv_data);
			if(sizeof($debug_data) > 0) {
				$_SESSION["import_debug_info"] = $debug_data;
			}
		}else{
			header("Location: color.php?import_x");
		}

		header("Location: color.php?import_x");
	}

	exit;
}
コード例 #23
0
ファイル: rra.php プロジェクト: MrWnn/cacti
function form_save()
{
    if (isset($_POST['save_component_rra'])) {
        $save['id'] = $_POST['id'];
        $save['hash'] = get_hash_round_robin_archive($_POST['id']);
        $save['name'] = form_input_validate($_POST['name'], 'name', '', false, 3);
        $dummy = form_input_validate(count($_POST['consolidation_function_id']), 'consolidation_function_id', '^[0-9]*$', false, 3);
        $save['x_files_factor'] = form_input_validate($_POST['x_files_factor'], 'x_files_factor', "^[01]?(\\.[0-9]+)?\$", false, 3);
        $save['steps'] = form_input_validate($_POST['steps'], 'steps', '^[0-9]*$', false, 3);
        $save['rows'] = form_input_validate($_POST['rows'], 'rows', '^[0-9]*$', false, 3);
        $save['timespan'] = form_input_validate($_POST['timespan'], 'timespan', '^[0-9]*$', false, 3);
        if (!is_error_message()) {
            $rra_id = sql_save($save, 'rra');
            if ($rra_id) {
                raise_message(1);
                db_execute_prepared('DELETE FROM rra_cf WHERE rra_id = ?', array($rra_id));
                if (isset($_POST['consolidation_function_id'])) {
                    for ($i = 0; $i < count($_POST['consolidation_function_id']); $i++) {
                        /* ================= input validation ================= */
                        input_validate_input_number($_POST['consolidation_function_id'][$i]);
                        /* ==================================================== */
                        db_execute_prepared('INSERT INTO rra_cf (rra_id, consolidation_function_id) VALUES (?, ?)', array($rra_id, $_POST['consolidation_function_id'][$i]));
                    }
                } else {
                    raise_message(2);
                }
            } else {
                raise_message(2);
            }
        }
        if (is_error_message()) {
            header('Location: rra.php?action=edit&id=' . (empty($rra_id) ? $_POST['id'] : $rra_id));
        } else {
            header('Location: rra.php');
        }
        exit;
    }
}
コード例 #24
0
ファイル: user_settings.php プロジェクト: songchin/Cacti
function save() {

	$save = array();

	$save["id"] = array("type" => DB_TYPE_INTEGER, "value" => $_SESSION["sess_user_id"]);
	$save["current_theme"] = array("type" => DB_TYPE_STRING, "value" => form_input_validate($_POST["current_theme"], "current_theme", "", true, 3));

	if (!is_error_message()) {
		$user_id = api_user_save($save);

		if ($user_id) {
			/* user saved */
			raise_message(1);
			/* reset local settings cache so the user sees the new settings */
			kill_session_var("sess_current_theme");
		}else{
			/* error saving */
			raise_message(2);
		}
	}

	header("Location: user_settings.php");

}
コード例 #25
0
ファイル: gprint_presets.php プロジェクト: MrWnn/cacti
function form_save()
{
    if (isset($_POST['save_component_gprint_presets'])) {
        $save['id'] = $_POST['id'];
        $save['hash'] = get_hash_gprint($_POST['id']);
        $save['name'] = form_input_validate($_POST['name'], 'name', '', false, 3);
        $save['gprint_text'] = form_input_validate($_POST['gprint_text'], 'gprint_text', '', false, 3);
        if (!is_error_message()) {
            $gprint_preset_id = sql_save($save, 'graph_templates_gprint');
            if ($gprint_preset_id) {
                raise_message(1);
            } else {
                raise_message(2);
            }
        }
        if (is_error_message()) {
            header('Location: gprint_presets.php?action=edit&id=' . (empty($gprint_preset_id) ? $_POST['id'] : $gprint_preset_id));
            exit;
        } else {
            header('Location: gprint_presets.php');
            exit;
        }
    }
}
コード例 #26
0
ファイル: presets_gprint.php プロジェクト: songchin/Cacti
function form_save() {
	if ($_POST["action_post"] == "gprint_preset_edit") {
		/* cache all post field values */
		init_post_field_cache();

		$form_gprint["name"] = $_POST["name"];
		$form_gprint["gprint_text"] = $_POST["gprint_text"];

		/* validate base gprint preset fields */
		field_register_error(api_data_preset_gprint_field_validate($form_gprint, "|field|"));

		if (!is_error_message()) {
			$preset_gprint_id = api_data_preset_gprint_save($_POST["preset_gprint_id"], $form_gprint);

			if (empty($preset_gprint_id)) {
				raise_message(2);
			}
		}

		if (is_error_message()) {
			header("Location: presets_gprint.php?action=edit" . (empty($preset_gprint_id) ? "" : "&id=$preset_gprint_id"));
		}else{
			header("Location: presets.php?action=view_gprint");
		}
	}else if (isset($_POST["box-1-action-area-button"])) {
		$selected_rows = explode(":", $_POST["box-1-action-area-selected-rows"]);

		if ($_POST["box-1-action-area-type"] == "remove") {
			foreach ($selected_rows as $preset_gprint_id) {
				api_data_preset_gprint_remove($preset_gprint_id);
			}
		}

		header("Location: presets.php?action=view_gprint");
	}
}
コード例 #27
0
ファイル: functions.php プロジェクト: songchin/Cacti
function display_output_messages() {
	global $config, $messages;

	if (isset($_SESSION["sess_messages"])) {
		$error_message = is_error_message();

		if (is_array($_SESSION["sess_messages"])) {
			foreach (array_keys($_SESSION["sess_messages"]) as $current_message_id) {
				eval ('$message = "' . $messages[$current_message_id]["message"] . '";');

				switch ($messages[$current_message_id]["type"]) {
				case 'info':
					if ($error_message == false) {
						print "<table align='center' width='98%' style='background-color: #ffffff; border: 1px solid #bbbbbb;'>";
						print "<tr><td bgcolor='#f5f5f5'><p class='textInfo'>$message</p></td></tr>";
						print "</table><br>";

						/* we don't need these if there are no error messages */
						kill_session_var("sess_field_values");
					}
					break;
				case 'error':
					print "<table align='center' width='98%' style='background-color: #ffffff; border: 1px solid #ff0000;'>";
					print "<tr><td bgcolor='#f5f5f5'><p class='textError'>Error: $message</p></td></tr>";
					print "</table><br>";
					break;
				}
			}
		}
	}

	kill_session_var("sess_messages");
}
コード例 #28
0
ファイル: graphs_items.php プロジェクト: songchin/Cacti
function form_save() {
	if (isset($_POST["save_component_item"])) {
		global $graph_item_types;

		$items[0] = array();

		if ($graph_item_types{$_POST["graph_type_id"]} == "LEGEND") {
			/* this can be a major time saver when creating lots of graphs with the typical
			GPRINT LAST/AVERAGE/MAX legends */
			$items = array(
				0 => array(
					"color_id" => "0",
					"graph_type_id" => "9",
					"consolidation_function_id" => "4",
					"text_format" => "Current:",
					"hard_return" => ""
					),
				1 => array(
					"color_id" => "0",
					"graph_type_id" => "9",
					"consolidation_function_id" => "1",
					"text_format" => "Average:",
					"hard_return" => ""
					),
				2 => array(
					"color_id" => "0",
					"graph_type_id" => "9",
					"consolidation_function_id" => "3",
					"text_format" => "Maximum:",
					"hard_return" => "on"
					));
		}

		foreach ($items as $item) {
			/* generate a new sequence if needed */
			if (empty($_POST["sequence"])) {
				$_POST["sequence"] = get_sequence($_POST["sequence"], "sequence", "graph_templates_item", "local_graph_id=" . $_POST["local_graph_id"]);
			}

			$save["id"] = $_POST["graph_template_item_id"];
			$save["graph_template_id"] = $_POST["graph_template_id"];
			$save["local_graph_template_item_id"] = $_POST["local_graph_template_item_id"];
			$save["local_graph_id"] = $_POST["local_graph_id"];
			$save["task_item_id"] = form_input_validate($_POST["task_item_id"], "task_item_id", "", true, 3);
			$save["color_id"] = form_input_validate((isset($item["color_id"]) ? $item["color_id"] : $_POST["color_id"]), "color_id", "", true, 3);
			$save["graph_type_id"] = form_input_validate((isset($item["graph_type_id"]) ? $item["graph_type_id"] : $_POST["graph_type_id"]), "graph_type_id", "", true, 3);
			$save["cdef_id"] = form_input_validate($_POST["cdef_id"], "cdef_id", "", true, 3);
			$save["consolidation_function_id"] = form_input_validate((isset($item["consolidation_function_id"]) ? $item["consolidation_function_id"] : $_POST["consolidation_function_id"]), "consolidation_function_id", "", true, 3);
			$save["text_format"] = form_input_validate((isset($item["text_format"]) ? $item["text_format"] : $_POST["text_format"]), "text_format", "", true, 3);
			$save["value"] = form_input_validate($_POST["value"], "value", "", true, 3);
			$save["hard_return"] = form_input_validate(((isset($item["hard_return"]) ? $item["hard_return"] : (isset($_POST["hard_return"]) ? $_POST["hard_return"] : ""))), "hard_return", "", true, 3);
			$save["gprint_id"] = form_input_validate($_POST["gprint_id"], "gprint_id", "", true, 3);
			$save["sequence"] = $_POST["sequence"];

			if (!is_error_message()) {
				$graph_template_item_id = sql_save($save, "graph_templates_item");

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

			$_POST["sequence"] = 0;
		}

		if (is_error_message()) {
			header("Location: graphs.php?action=item_edit&graph_template_item_id=" . (empty($graph_template_item_id) ? $_POST["graph_template_item_id"] : $graph_template_item_id) . "&id=" . $_POST["local_graph_id"]);
			exit;
		}else{
			header("Location: graphs.php?action=graph_edit&id=" . $_POST["local_graph_id"]);
			exit;
		}
	}
}
コード例 #29
0
ファイル: graphs.php プロジェクト: songchin/Cacti
function form_save() {
	if ((isset($_POST["save_component_graph_new"])) && (!empty($_POST["graph_template_id"]))) {
		/* ================= input validation ================= */
		input_validate_input_number(get_request_var_post("graph_template_id"));
		/* ==================================================== */

		$save["id"] = $_POST["local_graph_id"];
		$save["graph_template_id"] = $_POST["graph_template_id"];
		$save["host_id"] = $_POST["host_id"];

		$local_graph_id = sql_save($save, "graph_local");

		change_graph_template($local_graph_id, $_POST["graph_template_id"], true);

		/* update the title cache */
		update_graph_title_cache($local_graph_id);
	}

	if (isset($_POST["save_component_graph"])) {
		/* ================= input validation ================= */
		input_validate_input_number(get_request_var_post("graph_template_id"));
		input_validate_input_number(get_request_var_post("_graph_template_id"));
		/* ==================================================== */

		$save1["id"] = $_POST["local_graph_id"];
		$save1["host_id"] = $_POST["host_id"];
		$save1["graph_template_id"] = $_POST["graph_template_id"];

		$save2["id"] = $_POST["graph_template_graph_id"];
		$save2["local_graph_template_graph_id"] = $_POST["local_graph_template_graph_id"];
		$save2["graph_template_id"] = $_POST["graph_template_id"];
		$save2["image_format_id"] = form_input_validate($_POST["image_format_id"], "image_format_id", "", true, 3);
		$save2["title"] = form_input_validate($_POST["title"], "title", "", false, 3);
		$save2["height"] = form_input_validate($_POST["height"], "height", "^[0-9]+$", false, 3);
		$save2["width"] = form_input_validate($_POST["width"], "width", "^[0-9]+$", false, 3);
		$save2["upper_limit"] = form_input_validate($_POST["upper_limit"], "upper_limit", "^(-?([0-9]+(\.[0-9]*)?|[0-9]*\.[0-9]+)([eE][+\-]?[0-9]+)?)|U$", false, 3);
		$save2["lower_limit"] = form_input_validate($_POST["lower_limit"], "lower_limit", "^(-?([0-9]+(\.[0-9]*)?|[0-9]*\.[0-9]+)([eE][+\-]?[0-9]+)?)|U$", false, 3);
		$save2["vertical_label"] = form_input_validate($_POST["vertical_label"], "vertical_label", "", true, 3);
		$save2["slope_mode"] = form_input_validate((isset($_POST["slope_mode"]) ? $_POST["slope_mode"] : ""), "slope_mode", "", true, 3);
		$save2["auto_scale"] = form_input_validate((isset($_POST["auto_scale"]) ? $_POST["auto_scale"] : ""), "auto_scale", "", true, 3);
		$save2["auto_scale_opts"] = form_input_validate($_POST["auto_scale_opts"], "auto_scale_opts", "", true, 3);
		$save2["auto_scale_log"] = form_input_validate((isset($_POST["auto_scale_log"]) ? $_POST["auto_scale_log"] : ""), "auto_scale_log", "", true, 3);
		$save2["scale_log_units"] = form_input_validate((isset($_POST["scale_log_units"]) ? $_POST["scale_log_units"] : ""), "scale_log_units", "", true, 3);
		$save2["auto_scale_rigid"] = form_input_validate((isset($_POST["auto_scale_rigid"]) ? $_POST["auto_scale_rigid"] : ""), "auto_scale_rigid", "", true, 3);
		$save2["auto_padding"] = form_input_validate((isset($_POST["auto_padding"]) ? $_POST["auto_padding"] : ""), "auto_padding", "", true, 3);
		$save2["base_value"] = form_input_validate($_POST["base_value"], "base_value", "^[0-9]+$", false, 3);
		$save2["export"] = form_input_validate((isset($_POST["export"]) ? $_POST["export"] : ""), "export", "", true, 3);
		$save2["unit_value"] = form_input_validate($_POST["unit_value"], "unit_value", "", true, 3);
		$save2["unit_exponent_value"] = form_input_validate($_POST["unit_exponent_value"], "unit_exponent_value", "^-?[0-9]+$", true, 3);

		if (!is_error_message()) {
			$local_graph_id = sql_save($save1, "graph_local");
		}

		if (!is_error_message()) {
			$save2["local_graph_id"] = $local_graph_id;
			$graph_templates_graph_id = sql_save($save2, "graph_templates_graph");

			if ($graph_templates_graph_id) {
				raise_message(1);

				/* if template information chanegd, update all necessary template information */
				if ($_POST["graph_template_id"] != $_POST["_graph_template_id"]) {
					/* check to see if the number of graph items differs, if it does; we need user input */
					if ((!empty($_POST["graph_template_id"])) && (!empty($_POST["local_graph_id"])) && (sizeof(db_fetch_assoc("select id from graph_templates_item where local_graph_id=$local_graph_id")) != sizeof(db_fetch_assoc("select id from graph_templates_item where local_graph_id=0 and graph_template_id=" . $_POST["graph_template_id"])))) {
						/* set the template back, since the user may choose not to go through with the change
						at this point */
						db_execute("update graph_local set graph_template_id=" . $_POST["_graph_template_id"] . " where id=$local_graph_id");
						db_execute("update graph_templates_graph set graph_template_id=" . $_POST["_graph_template_id"] . " where local_graph_id=$local_graph_id");

						header("Location: graphs.php?action=graph_diff&id=$local_graph_id&graph_template_id=" . $_POST["graph_template_id"]);
						exit;
					}
				}
			}else{
				raise_message(2);
			}

			/* update the title cache */
			update_graph_title_cache($local_graph_id);
		}

		if ((!is_error_message()) && ($_POST["graph_template_id"] != $_POST["_graph_template_id"])) {
			change_graph_template($local_graph_id, $_POST["graph_template_id"], true);
		}elseif (!empty($_POST["graph_template_id"])) {
			update_graph_data_query_cache($local_graph_id);
		}
	}

	if (isset($_POST["save_component_input"])) {
		/* ================= input validation ================= */
		input_validate_input_number(get_request_var_post("local_graph_id"));
		/* ==================================================== */

		/* first; get the current graph template id */
		$graph_template_id = db_fetch_cell("select graph_template_id from graph_local where id=" . $_POST["local_graph_id"]);

		/* get all inputs that go along with this graph template */
		$input_list = db_fetch_assoc("select id,column_name from graph_template_input where graph_template_id=$graph_template_id");

		if (sizeof($input_list) > 0) {
		foreach ($input_list as $input) {
			/* we need to find out which graph items will be affected by saving this particular item */
			$item_list = db_fetch_assoc("select
				graph_templates_item.id
				from (graph_template_input_defs,graph_templates_item)
				where graph_template_input_defs.graph_template_item_id=graph_templates_item.local_graph_template_item_id
				and graph_templates_item.local_graph_id=" . $_POST["local_graph_id"] . "
				and graph_template_input_defs.graph_template_input_id=" . $input["id"]);

			/* loop through each item affected and update column data */
			if (sizeof($item_list) > 0) {
			foreach ($item_list as $item) {
				/* if we are changing templates, the POST vars we are searching for here will not exist.
				this is because the db and form are out of sync here, but it is ok to just skip over saving
				the inputs in this case. */
				if (isset($_POST{$input["column_name"] . "_" . $input["id"]})) {
					db_execute("update graph_templates_item set " . $input["column_name"] . "='" . $_POST{$input["column_name"] . "_" . $input["id"]} . "' where id=" . $item["id"]);
				}
			}
			}
		}
		}
	}

	if (isset($_POST["save_component_graph_diff"])) {
		if ($_POST["type"] == "1") {
			$intrusive = true;
		}elseif ($_POST["type"] == "2") {
			$intrusive = false;
		}

		change_graph_template($_POST["local_graph_id"], $_POST["graph_template_id"], $intrusive);
	}

	if ((isset($_POST["save_component_graph_new"])) && (empty($_POST["graph_template_id"]))) {
		header("Location: graphs.php?action=graph_edit&host_id=" . $_POST["host_id"] . "&new=1");
	}elseif ((is_error_message()) || (empty($_POST["local_graph_id"])) || (isset($_POST["save_component_graph_diff"])) || ($_POST["graph_template_id"] != $_POST["_graph_template_id"]) || ($_POST["host_id"] != $_POST["_host_id"])) {
		header("Location: graphs.php?action=graph_edit&id=" . (empty($local_graph_id) ? $_POST["local_graph_id"] : $local_graph_id) . (isset($_POST["host_id"]) ? "&host_id=" . $_POST["host_id"] : ""));
	}else{
		header("Location: graphs.php");
	}
}
コード例 #30
0
ファイル: packages.php プロジェクト: songchin/Cacti
function form_save() {
	if ($_POST["action_post"] == "package_new") {
		header("Location: packages.php?action=edit");
	}else if ($_POST["action_post"] == "package_edit") {
		/* the "Add" associated graph template button was pressed */
		if (isset($_POST["assoc_graph_template_add_y"])) {
			api_package_package_template_add($_POST["package_id"], $_POST["assoc_graph_template_id"]);
			header("Location: packages.php?action=edit&id=" . $_POST["package_id"]);
			exit;
		}

		/* cache all post field values */
		init_post_field_cache();

		/* step #2: field validation */
		$form_package["id"] = $_POST["package_id"];
		$form_package["name"] = $_POST["name"];
		$form_package["description"] = $_POST["description"];
		$form_package["description_install"] = $_POST["description_install"];
		$form_package["category"] = ($_POST["category"] == "new" ? $_POST["category_txt"] : api_data_preset_package_category_get($_POST["category_drp"]));
		$form_package["subcategory"] = ($_POST["subcategory"] == "new" ? $_POST["subcategory_txt"] : api_data_preset_package_subcategory_get($_POST["subcategory_drp"]));
		$form_package["vendor"] = ($_POST["vendor"] == "new" ? $_POST["vendor_txt"] : api_data_preset_package_vendor_get($_POST["vendor_drp"]));
		$form_package["model"] = $_POST["model"];

		/* the author field values may either come from the form or from the database */
		if ($_POST["author_type"] == "new") {
			$form_package["author_name"] = $_POST["author_name"];
			$form_package["author_email"] = $_POST["author_email"];
			$form_package["author_user_repository"] = $_POST["author_user_repository"];
			$form_package["author_user_forum"] = $_POST["author_user_forum"];
		}else if ($_POST["author_type"] == "existing") {
			$package_author = api_package_author_get($_POST["author_type_drp"]);

			$form_package["author_name"] = $package_author["name"];
			$form_package["author_email"] = $package_author["email"];
			$form_package["author_user_repository"] = $package_author["user_repository"];
			$form_package["author_user_forum"] = $package_author["user_forum"];
		}

		field_register_error(api_package_field_validate($form_package, "|field|"));

		/* the custom category textbox goes by a different name on the form */
		if (field_error_isset("category")) {
			field_register_error("category_txt");
		}

		/* the custom subcategory textbox goes by a different name on the form */
		if (field_error_isset("subcategory")) {
			field_register_error("subcategory_txt");
		}

		/* step #3: field save */
		$package_id = false;
		if (is_error_message()) {
			log_save("User input validation error for package [ID#" . $_POST["package_id"] . "]", SEV_DEBUG);
		}else{
			$package_id = api_package_save($_POST["package_id"], $form_package);

			if ($package_id === false) {
				log_save("Save error for package [ID#" . $_POST["package_id"] . "]", SEV_ERROR);
			}
		}

		if (($package_id === false) || (empty($_POST["package_id"]))) {
			header("Location: packages.php?action=edit" . (empty($_POST["package_id"]) ? "" : "&id=" . $_POST["package_id"]));
		}else{
			header("Location: packages.php");
		}
	}else if ($_POST["action_post"] == "package_edit_metadata") {
		/* cache all post field values */
		init_post_field_cache();

		/* step #2: field validation */
		$form_package_metadata["id"] = $_POST["package_metadata_id"];
		$form_package_metadata["package_id"] = $_POST["package_id"];
		$form_package_metadata["type"] = $_POST["type"];
		$form_package_metadata["name"] = $_POST["name"];
		$form_package_metadata["description"] = $_POST["description"];

		if ($_POST["type"] == PACKAGE_METADATA_TYPE_SCREENSHOT) {
			/* make sure there is a valid file that was uploaded via an HTTP POST */
			if ((isset($_FILES["payload_upl"])) && (is_uploaded_file($_FILES["payload_upl"]["tmp_name"]))) {
				$fp = fopen($_FILES["payload_upl"]["tmp_name"], "r");
				$raw_data = fread($fp, $_FILES["payload_upl"]["size"]);
				fclose($fp);

				$form_package_metadata["mime_type"] = $_FILES["payload_upl"]["type"];
				$form_package_metadata["payload"] = $raw_data;
			}
		}else if ($_POST["type"] == PACKAGE_METADATA_TYPE_SCRIPT) {
			$form_package_metadata["description_install"] = $_POST["description_install"];
			$form_package_metadata["required"] = html_boolean(isset($_POST["required"]) ? $_POST["required"] : "");
			$form_package_metadata["mime_type"] = "text/plain";
			$form_package_metadata["payload"] = $_POST["payload_txt"];
		}

		field_register_error(api_package_field_validate($form_package_metadata, "|field|"));

		/* step #3: field save */
		$package_metadata_id = false;
		if (is_error_message()) {
			log_save("User input validation error for package metadata [ID#" . $_POST["package_metadata_id"] . "], package [ID#" . $_POST["package_id"] . "]", SEV_DEBUG);
		}else{
			$package_metadata_id = api_package_metadata_save($_POST["package_metadata_id"], $form_package_metadata);

			if ($package_metadata_id === false) {
				log_save("Save error for package metadata [ID#" . $_POST["package_metadata_id"] . "], package [ID#" . $_POST["package_id"] . "]", SEV_ERROR);
			}
		}

		if ($package_metadata_id === false) {
			header("Location: packages.php?action=edit_metadata&package_id=" . $_POST["package_id"] . (empty($_POST["package_metadata_id"]) ? "" : "&id=" . $_POST["package_metadata_id"]));
		}else{
			/* the cache will not be purged in time unless to do it here */
			kill_post_field_cache();

			header("Location: packages.php?action=edit&id=" . $_POST["package_id"]);
		}
	}else if ($_POST["action_post"] == "package_import") {
		/* first, see if there is any XML in the textbox */
		if (trim($_POST["import_package_text"] != "")) {
			$xml_data = $_POST["import_package_text"];
		/* next, check if the user uploaded a file */
		}else if ((isset($_FILES["import_package_file"])) && (is_uploaded_file($_FILES["import_package_file"]["tmp_name"]))) {
			$fp = fopen($_FILES["import_package_file"]["tmp_name"], "r");
			$xml_data = fread($fp, $_FILES["import_package_file"]["size"]);
			fclose($fp);
		}

		package_import($xml_data);
	}
}