Beispiel #1
0
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");
        }
    }
}
Beispiel #2
0
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;
		}
	}
}
Beispiel #3
0
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));
}
Beispiel #4
0
function form_save() {
	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);
			}
		}

		if ((is_error_message()) || (empty($_POST["id"])) || ($redirect_back == true)) {
			header("Location: host_templates.php?action=edit&id=" . (empty($host_template_id) ? $_POST["id"] : $host_template_id));
		}else{
			header("Location: host_templates.php");
		}
	}
}
Beispiel #5
0
/**
 * Insert an event including all parameters
 *
 * This function if used by plugins to insert events to be processed
 *
 * @param string $handler Handler Name
 * @param array $params array of parameters, field => value elements
 * @param string $message Event Message
 * @param int $plugin_id ID of plugin that is inserting the event
 * @return int row number of insert (false if unsuccessful)
 */
function event_save ($handler, $params, $message = '', $plugin_id = 0) {
	$save['id'] = '';
	$save["handler"] = $handler;
	$save['created'] = time();
	$save["plugin_id"] = $plugin_id;
	$save["message"] = $message;

	$control_id = sql_save($save, "event_queue_control");

	if ($control_id) {
		$save = array();
		$save['id'] = '';
		$save["control_id"] = $control_id;
		$save["plugin_id"] = $plugin_id;
		if (is_array($params)) {
			foreach($params as $par => $text) {
				$save = array();
				$save['id'] = '';
				$save["control_id"] = $control_id;
				$save["plugin_id"] = $plugin_id;
				$save['name'] = $par;
				$save['value'] = $text;
				$param_id = sql_save($save, "event_queue_param");
			}
		}
	}
	return $control_id;
}
Beispiel #6
0
function user_copy($template_user, $new_user, $new_realm = 0)
{
    $user_auth = db_fetch_row("select * from user_auth where username = '******'");
    $user_auth['username'] = $new_user;
    $user_auth['realm'] = $new_realm;
    $old_id = $user_auth['id'];
    $user_auth['id'] = 0;
    $new_id = sql_save($user_auth, 'user_auth');
    $user_auth_perms = db_fetch_assoc("select * from user_auth_perms where user_id = '{$old_id}'");
    foreach ($user_auth_perms as $row) {
        $row['user_id'] = $new_id;
        sql_save($row, 'user_auth_perms', array('user_id', 'item_id', 'type'), false);
    }
    $user_auth_realm = db_fetch_assoc("select * from user_auth_realm where user_id = '{$old_id}'");
    foreach ($user_auth_realm as $row) {
        $row['user_id'] = $new_id;
        sql_save($row, 'user_auth_realm', array('realm_id', 'user_id'), false);
    }
    $settings_graphs = db_fetch_assoc("select * from settings_graphs where user_id = '{$old_id}'");
    foreach ($settings_graphs as $row) {
        $row['user_id'] = $new_id;
        sql_save($row, 'settings_graphs', array('user_id', 'name'), false);
    }
    $settings_tree = db_fetch_assoc("select * from settings_tree where user_id = '{$old_id}'");
    foreach ($settings_tree as $row) {
        $row['user_id'] = $new_id;
        sql_save($row, 'settings_tree', array('user_id', 'graph_tree_item_id'), false);
    }
}
Beispiel #7
0
function form_save()
{
    if (isset($_POST["save_component_tree"])) {
        $save["id"] = $_POST["id"];
        $save["name"] = form_input_validate($_POST["name"], "name", "", false, 3);
        $save["sort_type"] = form_input_validate($_POST["sort_type"], "sort_type", "", true, 3);
        if (!is_error_message()) {
            $tree_id = sql_save($save, "graph_tree");
            if ($tree_id) {
                raise_message(1);
                /* sort the tree using the algorithm chosen by the user */
                sort_tree(SORT_TYPE_TREE, $tree_id, $_POST["sort_type"]);
            } else {
                raise_message(2);
            }
        }
        if (is_error_message() || empty($_POST["id"])) {
            header("Location: tree.php?action=edit&id=" . (empty($tree_id) ? $_POST["id"] : $tree_id));
        } else {
            header("Location: tree.php");
        }
    } elseif (isset($_POST["save_component_tree_item"])) {
        $tree_item_id = api_tree_item_save($_POST["id"], $_POST["graph_tree_id"], $_POST["type"], $_POST["parent_item_id"], isset($_POST["title"]) ? $_POST["title"] : "", isset($_POST["local_graph_id"]) ? $_POST["local_graph_id"] : "0", isset($_POST["rra_id"]) ? $_POST["rra_id"] : "0", isset($_POST["host_id"]) ? $_POST["host_id"] : "0", isset($_POST["host_grouping_type"]) ? $_POST["host_grouping_type"] : "1", isset($_POST["sort_children_type"]) ? $_POST["sort_children_type"] : "1", isset($_POST["propagate_changes"]) ? true : false);
        if (is_error_message()) {
            header("Location: tree.php?action=item_edit&tree_item_id=" . (empty($tree_item_id) ? $_POST["id"] : $tree_item_id) . "&tree_id=" . $_POST["graph_tree_id"] . "&parent_id=" . $_POST["parent_item_id"]);
        } else {
            header("Location: tree.php?action=edit&id=" . $_POST["graph_tree_id"]);
        }
    }
}
Beispiel #8
0
function form_save() {
	/* save the poller */
	if (isset($_POST["save_component_poller"])) {
		$save["id"]          = $_POST["id"];

		$save["disabled"]    = form_input_validate((isset($_POST["disabled"]) ? get_request_var_post("disabled"):""), "disabled", "", true, 3);
		$save["description"] = form_input_validate(get_request_var_post("description"), "description", "", false, 3);
		$save["hostname"]    = form_input_validate(get_request_var_post("hostname"), "hostname", "", true, 3);
		$save["ip_address"]  = form_input_validate(get_request_var_post("ip_address"), "ip_address", "", true, 3);

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

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

		if (is_error_message()) {
			header("Location: pollers.php?action=edit&id=" . (empty($poller_id) ? $_POST["id"] : $poller_id));
		}else{
			header("Location: pollers.php");
		}
		exit;
	}
}
Beispiel #9
0
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));
    }
}
Beispiel #10
0
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;
	}
}
function form_save()
{
    if (isset($_POST["save_component_input"]) && !is_error_message()) {
        $graph_input_values = array();
        $selected_graph_items = array();
        $save["id"] = $_POST["graph_template_input_id"];
        $save["hash"] = get_hash_graph_template($_POST["graph_template_input_id"], "graph_template_input");
        $save["graph_template_id"] = $_POST["graph_template_id"];
        $save["name"] = form_input_validate($_POST["name"], "name", "", false, 3);
        $save["description"] = form_input_validate($_POST["description"], "description", "", true, 3);
        $save["column_name"] = form_input_validate($_POST["column_name"], "column_name", "", true, 3);
        if (!is_error_message()) {
            $graph_template_input_id = sql_save($save, "graph_template_input");
            if ($graph_template_input_id) {
                raise_message(1);
                /* list all graph items from the db so we can compare them with the current form */
                $db_selected_graph_item = array_rekey(db_fetch_assoc("select graph_template_item_id from graph_template_input_defs where graph_template_input_id={$graph_template_input_id}"), "graph_template_item_id", "graph_template_item_id");
                /* list all select graph items for use down below */
                while (list($var, $val) = each($_POST)) {
                    if (preg_match("/^i_(\\d+)\$/", $var, $matches)) {
                        /* ================= input validation ================= */
                        input_validate_input_number($matches[1]);
                        /* ==================================================== */
                        $selected_graph_items[$matches[1]] = $matches[1];
                        if (isset($db_selected_graph_item[$matches[1]])) {
                            /* is selected and exists in the db; old item */
                            $old_members[$matches[1]] = $matches[1];
                        } else {
                            /* is selected and does not exist the db; new item */
                            $new_members[$matches[1]] = $matches[1];
                        }
                    }
                }
                if (isset($new_members) && sizeof($new_members) > 0) {
                    while (list($item_id, $item_id) = each($new_members)) {
                        push_out_graph_input($graph_template_input_id, $item_id, isset($new_members) ? $new_members : array());
                    }
                }
                db_execute("delete from graph_template_input_defs where graph_template_input_id={$graph_template_input_id}");
                if (sizeof($selected_graph_items) > 0) {
                    foreach ($selected_graph_items as $graph_template_item_id) {
                        db_execute("insert into graph_template_input_defs (graph_template_input_id,graph_template_item_id)\n\t\t\t\t\t\tvalues ({$graph_template_input_id},{$graph_template_item_id})");
                    }
                }
            } else {
                raise_message(2);
            }
        }
        if (is_error_message()) {
            header("Location: graph_templates_inputs.php?action=input_edit&graph_template_input_id=" . (empty($graph_template_input_id) ? $_POST["graph_template_input_id"] : $graph_template_input_id) . "&graph_template_id=" . $_POST["graph_template_id"]);
            exit;
        } else {
            header("Location: graph_templates.php?action=template_edit&id=" . $_POST["graph_template_id"]);
            exit;
        }
    }
}
Beispiel #12
0
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;
}
Beispiel #13
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;
}
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;
        }
    }
}
Beispiel #15
0
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));
}
Beispiel #16
0
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));
}
Beispiel #17
0
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;
}
Beispiel #18
0
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;
}
Beispiel #19
0
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");
        }
    }
}
Beispiel #20
0
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');
        }
    }
}
Beispiel #21
0
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;
}
Beispiel #22
0
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;
    }
}
Beispiel #23
0
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;
        }
    }
}
Beispiel #24
0
/** create_complete_graph_from_template - creates a graph and all necessary data sources based on a
	graph template
   @param int $graph_template_id 			- the id of the graph template that will be used to create the new	graph
   @param int $device_id 					- the id of the device to associate the new graph and data sources with
   @param array $snmp_query_array 			- if the new data sources are to be based on a data query, specify the
	necessary data query information here. it must contain the following information:
	  $snmp_query_array["snmp_query_id"]
	  $snmp_query_array["snmp_index_on"]
	  $snmp_query_array["snmp_query_graph_id"]
	  $snmp_query_array["snmp_index"]
   @param array $suggested_values_array 	- any additional information to be included in the new graphs or
	data sources must be included in the array. data is to be included in the following format:
	  $values["cg"][graph_template_id]["graph_template"][field_name] = $value  // graph template
	  $values["cg"][graph_template_id]["graph_template_item"][graph_template_item_id][field_name] = $value  // graph template item
	  $values["cg"][data_template_id]["data_template"][field_name] = $value  // data template
	  $values["cg"][data_template_id]["data_template_item"][data_template_item_id][field_name] = $value  // data template item
	  $values["sg"][data_query_id][graph_template_id]["graph_template"][field_name] = $value  // graph template (w/ data query)
	  $values["sg"][data_query_id][graph_template_id]["graph_template_item"][graph_template_item_id][field_name] = $value  // graph template item (w/ data query)
	  $values["sg"][data_query_id][data_template_id]["data_template"][field_name] = $value  // data template (w/ data query)
	  $values["sg"][data_query_id][data_template_id]["data_template_item"][data_template_item_id][field_name] = $value  // data template item (w/ data query) */
function create_complete_graph_from_template($graph_template_id, $device_id, $snmp_query_array, &$suggested_values_array) {
	global $config;

	include_once(CACTI_BASE_PATH . "/lib/data_query.php");

	/* create the graph */
	$save["id"] = 0;
	$save["graph_template_id"] = $graph_template_id;
	$save["device_id"] = $device_id;

	$cache_array["local_graph_id"] = sql_save($save, "graph_local");
	change_graph_template($cache_array["local_graph_id"], $graph_template_id, true);

	if (is_array($snmp_query_array)) {
		/* suggested values for snmp query code */
		$suggested_values = db_fetch_assoc("select text,field_name from snmp_query_graph_sv where snmp_query_graph_id=" . $snmp_query_array["snmp_query_graph_id"] . " order by sequence");

		if (sizeof($suggested_values) > 0) {
		foreach ($suggested_values as $suggested_value) {
			/* once we find a match; don't try to find more */
			if (!isset($suggested_values_graph[$graph_template_id]{$suggested_value["field_name"]})) {
				$subs_string = substitute_snmp_query_data($suggested_value["text"], $device_id, $snmp_query_array["snmp_query_id"], $snmp_query_array["snmp_index"], read_config_option("max_data_query_field_length"), false);
				/* if there are no '|' characters, all of the substitutions were successful */
				if (!strstr($subs_string, "|query")) {
					db_execute("update graph_templates_graph set " . $suggested_value["field_name"] . "='" . addslashes($subs_string) . "' where local_graph_id=" . $cache_array["local_graph_id"]);

					/* once we find a working value, stop */
					$suggested_values_graph[$graph_template_id]{$suggested_value["field_name"]} = true;
				}
			}
		}
		}
	}

	/* suggested values: graph */
	if (isset($suggested_values_array[$graph_template_id]["graph_template"])) {
		while (list($field_name, $field_value) = each($suggested_values_array[$graph_template_id]["graph_template"])) {
			db_execute("update graph_templates_graph set $field_name='$field_value' where local_graph_id=" . $cache_array["local_graph_id"]);
		}
	}

	/* suggested values: graph item */
	if (isset($suggested_values_array[$graph_template_id]["graph_template_item"])) {
		while (list($graph_template_item_id, $field_array) = each($suggested_values_array[$graph_template_id]["graph_template_item"])) {
			while (list($field_name, $field_value) = each($field_array)) {
				$graph_item_id = db_fetch_cell("select id from graph_templates_item where local_graph_template_item_id=$graph_template_item_id and local_graph_id=" . $cache_array["local_graph_id"]);
				db_execute("update graph_templates_item set $field_name='$field_value' where id=$graph_item_id");
			}
		}
	}

	update_graph_title_cache($cache_array["local_graph_id"]);

	/* create each data source */
	$data_templates = db_fetch_assoc("select
		data_template.id,
		data_template.name,
		data_template_rrd.data_source_name
		from (data_template, data_template_rrd, graph_templates_item)
		where graph_templates_item.task_item_id=data_template_rrd.id
		and data_template_rrd.data_template_id=data_template.id
		and data_template_rrd.local_data_id=0
		and graph_templates_item.local_graph_id=0
		and graph_templates_item.graph_template_id=" . $graph_template_id . "
		group by data_template.id
		order by data_template.name");

	if (sizeof($data_templates) > 0) {
	foreach ($data_templates as $data_template) {
		unset($save);

		$save["id"] = 0;
		$save["data_template_id"] = $data_template["id"];
		$save["device_id"] = $device_id;

		$cache_array["local_data_id"]{$data_template["id"]} = sql_save($save, "data_local");
		change_data_template($cache_array["local_data_id"]{$data_template["id"]}, $data_template["id"]);

		$data_template_data_id = db_fetch_cell("select id from data_template_data where local_data_id=" . $cache_array["local_data_id"]{$data_template["id"]});

		if (is_array($snmp_query_array)) {
			/* suggested values for snmp query code */
			$suggested_values = db_fetch_assoc("select text,field_name from snmp_query_graph_rrd_sv where snmp_query_graph_id=" . $snmp_query_array["snmp_query_graph_id"] . " and data_template_id=" . $data_template["id"] . " order by sequence");

			if (sizeof($suggested_values) > 0) {
			foreach ($suggested_values as $suggested_value) {
				/* once we find a match; don't try to find more */
				if (!isset($suggested_values_ds{$data_template["id"]}{$suggested_value["field_name"]})) {
					$subs_string = substitute_snmp_query_data($suggested_value["text"], $device_id, $snmp_query_array["snmp_query_id"], $snmp_query_array["snmp_index"], read_config_option("max_data_query_field_length"), false);

					/* if there are no '|' characters, all of the substitutions were successful */
					if (!strstr($subs_string, "|query")) {
						if (sizeof(db_fetch_row("show columns from data_template_data like '" . $suggested_value["field_name"] . "'"))) {
							db_execute("update data_template_data set " . $suggested_value["field_name"] . "='" . addslashes($subs_string) . "' where local_data_id=" . $cache_array["local_data_id"]{$data_template["id"]});
						}

						/* once we find a working value, stop */
						$suggested_values_ds{$data_template["id"]}{$suggested_value["field_name"]} = true;

						if ((sizeof(db_fetch_row("show columns from data_template_rrd like '" . $suggested_value["field_name"] . "'"))) &&
							(!substr_count($subs_string, "|"))) {
							db_execute("update data_template_rrd set " . $suggested_value["field_name"] . "='" . $subs_string . "' where local_data_id=" . $cache_array["local_data_id"]{$data_template["id"]});
						}
					}
				}
			}
			}
		}

		if (is_array($snmp_query_array)) {
			$data_input_field = array_rekey(db_fetch_assoc("SELECT
				data_input_fields.id,
				data_input_fields.type_code
				FROM (snmp_query,data_input,data_input_fields)
				WHERE snmp_query.data_input_id=data_input.id
				AND data_input.id=data_input_fields.data_input_id
				AND (data_input_fields.type_code='index_type'
					OR data_input_fields.type_code='index_value'
					OR data_input_fields.type_code='output_type')
				AND snmp_query.id=" . $snmp_query_array["snmp_query_id"]), "type_code", "id");

			$snmp_cache_value = db_fetch_cell("SELECT field_value
				FROM device_snmp_cache
				WHERE device_id='$device_id'
				AND snmp_query_id='" . $snmp_query_array["snmp_query_id"] . "'
				AND field_name='" . $snmp_query_array["snmp_index_on"] . "'
				AND snmp_index='" . $snmp_query_array["snmp_index"] . "'");

			/* save the value to index on (ie. ifindex, ifip, etc) */
			db_execute("REPLACE INTO data_input_data
				(data_input_field_id, data_template_data_id, t_value, value)
				VALUES (" . $data_input_field["index_type"] . ", $data_template_data_id, '', '" . $snmp_query_array["snmp_index_on"] . "')");

			/* save the actual value (ie. 3, 192.168.1.101, etc) */
			db_execute("REPLACE INTO data_input_data
				(data_input_field_id,data_template_data_id,t_value,value)
				VALUES (" . $data_input_field["index_value"] . ",$data_template_data_id,'','" . addslashes($snmp_cache_value) . "')");

			/* set the expected output type (ie. bytes, errors, packets) */
			db_execute("REPLACE INTO data_input_data
				(data_input_field_id,data_template_data_id,t_value,value)
				VALUES (" . $data_input_field["output_type"] . ",$data_template_data_id,'','" . $snmp_query_array["snmp_query_graph_id"] . "')");

			/* now that we have put data into the 'data_input_data' table, update the snmp cache for ds's */
			update_data_source_data_query_cache($cache_array["local_data_id"]{$data_template["id"]});
		}

		/* suggested values: data source */
		if (isset($suggested_values_array[$graph_template_id]["data_template"]{$data_template["id"]})) {
			reset($suggested_values_array[$graph_template_id]["data_template"]{$data_template["id"]});
			while (list($field_name, $field_value) = each($suggested_values_array[$graph_template_id]["data_template"]{$data_template["id"]})) {
				db_execute("UPDATE data_template_data
					SET $field_name='$field_value'
					WHERE local_data_id=" . $cache_array["local_data_id"]{$data_template["id"]});
			}
		}

		/* suggested values: data source item */
		if (isset($suggested_values_array[$graph_template_id]["data_template_item"])) {
			reset($suggested_values_array[$graph_template_id]["data_template_item"]);
			while (list($data_template_item_id, $field_array) = each($suggested_values_array[$graph_template_id]["data_template_item"])) {
				while (list($field_name, $field_value) = each($field_array)) {
					$data_source_item_id = db_fetch_cell("select id from data_template_rrd where local_data_template_rrd_id=$data_template_item_id and local_data_id=" . $cache_array["local_data_id"]{$data_template["id"]});
					db_execute("UPDATE data_template_rrd
						SET $field_name='$field_value'
						WHERE id=$data_source_item_id");
				}
			}
		}

		/* suggested values: custom data */
		if (isset($suggested_values_array[$graph_template_id]["custom_data"]{$data_template["id"]})) {
			reset($suggested_values_array[$graph_template_id]["custom_data"]{$data_template["id"]});
			while (list($data_input_field_id, $field_value) = each($suggested_values_array[$graph_template_id]["custom_data"]{$data_template["id"]})) {
				db_execute("replace into data_input_data (data_input_field_id,data_template_data_id,t_value,value) values ($data_input_field_id,$data_template_data_id,'','$field_value')");
			}
		}

		update_data_source_title_cache($cache_array["local_data_id"]{$data_template["id"]});
	}
	}

	/* connect the dots: graph -> data source(s) */
	$template_item_list = db_fetch_assoc("select
		graph_templates_item.id,
		data_template_rrd.id as data_template_rrd_id,
		data_template_rrd.data_template_id
		from (graph_templates_item,data_template_rrd)
		where graph_templates_item.task_item_id=data_template_rrd.id
		and graph_templates_item.graph_template_id=$graph_template_id
		and local_graph_id=0
		and task_item_id>0");

	/* loop through each item affected and update column data */
	if (sizeof($template_item_list) > 0) {
	foreach ($template_item_list as $template_item) {
		$local_data_id = $cache_array["local_data_id"]{$template_item["data_template_id"]};

		$graph_template_item_id = db_fetch_cell("select id from graph_templates_item where local_graph_template_item_id=" . $template_item["id"] . " and local_graph_id=" . $cache_array["local_graph_id"]);
		$data_template_rrd_id = db_fetch_cell("select id from data_template_rrd where local_data_template_rrd_id=" . $template_item["data_template_rrd_id"] . " and local_data_id=$local_data_id");

		if (!empty($data_template_rrd_id)) {
			db_execute("update graph_templates_item set task_item_id='$data_template_rrd_id' where id=$graph_template_item_id");
		}
	}
	}

	/* this will not work until the ds->graph dots are connected */
	if (is_array($snmp_query_array)) {
		update_graph_data_query_cache($cache_array["local_graph_id"]);
	}

	# now that we have the id of the new host, we may plugin postprocessing code
	$save["id"] = $cache_array["local_graph_id"];
	$save["graph_template_id"] = $graph_template_id;	// attention: unset!
	if (is_array($snmp_query_array)) {
		$save["snmp_query_id"] = $snmp_query_array["snmp_query_id"];
		$save["snmp_index"] = $snmp_query_array["snmp_index"];
	} else {
		$save["snmp_query_id"] = 0;
		$save["snmp_index"] = 0;
	}
	api_plugin_hook_function('create_complete_graph_from_template', $save);

	return $cache_array;
}
Beispiel #25
0
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");
	}
}
Beispiel #26
0
function &xml_to_data_input_method($hash, &$xml_array, &$hash_cache)
{
    global $fields_data_input_edit, $fields_data_input_field_edit, $fields_data_input_field_edit_1;
    /* aggregate field arrays */
    $fields_data_input_field_edit += $fields_data_input_field_edit_1;
    /* import into: data_input */
    $_data_input_id = db_fetch_cell("select id from data_input where hash='{$hash}'");
    $save["id"] = empty($_data_input_id) ? "0" : $_data_input_id;
    $save["hash"] = $hash;
    reset($fields_data_input_edit);
    while (list($field_name, $field_array) = each($fields_data_input_edit)) {
        /* make sure this field exists in the xml array first */
        if (isset($xml_array[$field_name])) {
            /* fix issue with data input method importing and white spaces */
            if ($field_name == "input_string") {
                $xml_array[$field_name] = str_replace("><", "> <", $xml_array[$field_name]);
            }
            $save[$field_name] = addslashes(xml_character_decode($xml_array[$field_name]));
        }
    }
    $data_input_id = sql_save($save, "data_input");
    $hash_cache["data_input_method"][$hash] = $data_input_id;
    /* import into: data_input_fields */
    if (is_array($xml_array["fields"])) {
        while (list($item_hash, $item_array) = each($xml_array["fields"])) {
            /* parse information from the hash */
            $parsed_hash = parse_xml_hash($item_hash);
            /* invalid/wrong hash */
            if ($parsed_hash == false) {
                return false;
            }
            unset($save);
            $_data_input_field_id = db_fetch_cell("select id from data_input_fields where hash='" . $parsed_hash["hash"] . "' and data_input_id={$data_input_id}");
            $save["id"] = empty($_data_input_field_id) ? "0" : $_data_input_field_id;
            $save["hash"] = $parsed_hash["hash"];
            $save["data_input_id"] = $data_input_id;
            reset($fields_data_input_field_edit);
            while (list($field_name, $field_array) = each($fields_data_input_field_edit)) {
                /* make sure this field exists in the xml array first */
                if (isset($item_array[$field_name])) {
                    $save[$field_name] = addslashes(xml_character_decode($item_array[$field_name]));
                }
            }
            $data_input_field_id = sql_save($save, "data_input_fields");
            $hash_cache["data_input_field"][$parsed_hash["hash"]] = $data_input_field_id;
        }
    }
    /* update field use counter cache if possible */
    if (isset($xml_array["input_string"]) && !empty($data_input_id)) {
        generate_data_input_field_sequences($xml_array["input_string"], $data_input_id);
    }
    /* status information that will be presented to the user */
    $_SESSION["import_debug_info"]["type"] = empty($_data_input_id) ? "new" : "update";
    $_SESSION["import_debug_info"]["title"] = $xml_array["name"];
    $_SESSION["import_debug_info"]["result"] = empty($data_input_id) ? "fail" : "success";
    return $hash_cache;
}
Beispiel #27
0
function convert_readstrings() {
	global $config;

	if (defined('CACTI_BASE_PATH')) {
		$config["base_path"] = CACTI_BASE_PATH;
	}

	include_once($config["base_path"] . "/lib/functions.php");

	$sql = "SELECT DISTINCT " .
		"snmp_readstrings, " .
		"snmp_version, " .
		"snmp_port, " .
		"snmp_timeout, " .
		"snmp_retries " .
		"FROM mac_track_devices";
	cacti_log($sql, false, "MACTRACK");
	$devices = db_fetch_assoc($sql);
	cacti_log(serialize($devices), false, "MACTRACK");

	if (sizeof($devices)) {
		$i = 0;
		foreach($devices as $device) {
			# create new SNMP Option Set
			unset($save);
			$save["id"] = 0;
			$save["name"] = "Custom_" . $i++;
			$snmp_id = sql_save($save, "mac_track_snmp");
			cacti_log("new option entry: " . $snmp_id, false, "MACTRACK");

			# add each single option derived from readstrings
			$read_strings = explode(":",$device["snmp_readstrings"]);
			if (sizeof($read_strings)) {
				foreach($read_strings as $snmp_readstring) {
					unset($save);
					$save["id"]						= 0;
					$save["snmp_id"] 				= $snmp_id;
					$save["sequence"] 				= get_sequence('', 'sequence', 'mac_track_snmp_items', 'snmp_id=' . $snmp_id);

					$save["snmp_readstring"] 		= $snmp_readstring;
					$save["snmp_version"] 			= $device["snmp_version"];
					$save["snmp_port"]				= $device["snmp_port"];
					$save["snmp_timeout"]			= $device["snmp_timeout"];
					$save["snmp_retries"]			= $device["snmp_retries"];
					$save["snmp_username"]			= "";
					$save["snmp_password"]			= "";
					$save["snmp_auth_protocol"]		= "";
					$save["snmp_priv_passphrase"]	= "";
					$save["snmp_priv_protocol"]		= "";
					$save["snmp_context"]			= "";
					$save["max_oids"]				= "";

					$item_id = sql_save($save, "mac_track_snmp_items");
					cacti_log("new option item entry: " . $item_id, false, "MACTRACK");
				}
			} # each readstring added as SNMP Option item

			# now, let's find all devices, that used this snmp_readstrings
			$sql = "UPDATE mac_track_devices SET snmp_options=" . $snmp_id .
					" WHERE snmp_readstrings='" . $device["snmp_readstrings"] .
					"' AND snmp_version=" . $device["snmp_version"] .
					" AND snmp_port=" . $device["snmp_port"] .
					" AND snmp_timeout=" . $device["snmp_timeout"] .
					" AND snmp_retries=" . $device["snmp_retries"];
			cacti_log($sql, false, "MACTRACK");
			$ok = db_execute($sql);
		}
	}
	db_execute("replace into settings (name,value) values ('mt_convert_readstrings', 'on')");
	# we keep the field:snmp_readstrings in mac_track_devices, it should be deprecated first
	# next mactrack release may delete that field, then
}
Beispiel #28
0
function form_save()
{
    global $cnn_id;
    if (isset($_POST["save_component_template"])) {
        /* ================= input validation ================= */
        input_validate_input_number(get_request_var_post("data_input_id"));
        input_validate_input_number(get_request_var_post("data_template_id"));
        input_validate_input_number(get_request_var_post("data_template_data_id"));
        input_validate_input_number(get_request_var_post("data_template_rrd_id"));
        /* ==================================================== */
        /* save: data_template */
        $save1["id"] = $_POST["data_template_id"];
        $save1["hash"] = get_hash_data_template($_POST["data_template_id"]);
        $save1["name"] = form_input_validate($_POST["template_name"], "template_name", "", false, 3);
        /* save: data_template_data */
        $save2["id"] = $_POST["data_template_data_id"];
        $save2["local_data_template_data_id"] = 0;
        $save2["local_data_id"] = 0;
        $save2["data_input_id"] = form_input_validate($_POST["data_input_id"], "data_input_id", "^[0-9]+\$", true, 3);
        $save2["t_name"] = form_input_validate(isset($_POST["t_name"]) ? $_POST["t_name"] : "", "t_name", "", true, 3);
        $save2["name"] = form_input_validate($_POST["name"], "name", "", isset($_POST["t_name"]) ? true : false, 3);
        $save2["t_active"] = form_input_validate(isset($_POST["t_active"]) ? $_POST["t_active"] : "", "t_active", "", true, 3);
        $save2["active"] = form_input_validate(isset($_POST["active"]) ? $_POST["active"] : "", "active", "", true, 3);
        $save2["t_rrd_step"] = form_input_validate(isset($_POST["t_rrd_step"]) ? $_POST["t_rrd_step"] : "", "t_rrd_step", "", true, 3);
        $save2["rrd_step"] = form_input_validate($_POST["rrd_step"], "rrd_step", "^[0-9]+\$", isset($_POST["t_rrd_step"]) ? true : false, 3);
        $save2["t_rra_id"] = form_input_validate(isset($_POST["t_rra_id"]) ? $_POST["t_rra_id"] : "", "t_rra_id", "", true, 3);
        /* save: data_template_rrd */
        $save3["id"] = $_POST["data_template_rrd_id"];
        $save3["hash"] = get_hash_data_template($_POST["data_template_rrd_id"], "data_template_item");
        $save3["local_data_template_rrd_id"] = 0;
        $save3["local_data_id"] = 0;
        $save3["t_rrd_maximum"] = form_input_validate(isset($_POST["t_rrd_maximum"]) ? $_POST["t_rrd_maximum"] : "", "t_rrd_maximum", "", true, 3);
        $save3["rrd_maximum"] = form_input_validate($_POST["rrd_maximum"], "rrd_maximum", "^(-?([0-9]+(\\.[0-9]*)?|[0-9]*\\.[0-9]+)([eE][+\\-]?[0-9]+)?)|U\$", isset($_POST["t_rrd_maximum"]) ? true : false, 3);
        $save3["t_rrd_minimum"] = form_input_validate(isset($_POST["t_rrd_minimum"]) ? $_POST["t_rrd_minimum"] : "", "t_rrd_minimum", "", true, 3);
        $save3["rrd_minimum"] = form_input_validate($_POST["rrd_minimum"], "rrd_minimum", "^(-?([0-9]+(\\.[0-9]*)?|[0-9]*\\.[0-9]+)([eE][+\\-]?[0-9]+)?)|U\$", isset($_POST["t_rrd_minimum"]) ? true : false, 3);
        $save3["t_rrd_heartbeat"] = form_input_validate(isset($_POST["t_rrd_heartbeat"]) ? $_POST["t_rrd_heartbeat"] : "", "t_rrd_heartbeat", "", true, 3);
        $save3["rrd_heartbeat"] = form_input_validate($_POST["rrd_heartbeat"], "rrd_heartbeat", "^[0-9]+\$", isset($_POST["t_rrd_heartbeat"]) ? true : false, 3);
        $save3["t_data_source_type_id"] = form_input_validate(isset($_POST["t_data_source_type_id"]) ? $_POST["t_data_source_type_id"] : "", "t_data_source_type_id", "", true, 3);
        $save3["data_source_type_id"] = form_input_validate($_POST["data_source_type_id"], "data_source_type_id", "^[0-9]+\$", true, 3);
        $save3["t_data_source_name"] = form_input_validate(isset($_POST["t_data_source_name"]) ? $_POST["t_data_source_name"] : "", "t_data_source_name", "", true, 3);
        $save3["data_source_name"] = form_input_validate($_POST["data_source_name"], "data_source_name", "^[a-zA-Z0-9_]{1,19}\$", isset($_POST["t_data_source_name"]) ? true : false, 3);
        $save3["t_data_input_field_id"] = form_input_validate(isset($_POST["t_data_input_field_id"]) ? $_POST["t_data_input_field_id"] : "", "t_data_input_field_id", "", true, 3);
        $save3["data_input_field_id"] = form_input_validate(isset($_POST["data_input_field_id"]) ? $_POST["data_input_field_id"] : "0", "data_input_field_id", "^[0-9]+\$", true, 3);
        /* ok, first pull out all 'input' values so we know how much to save */
        $input_fields = db_fetch_assoc("select\n\t\t\tid,\n\t\t\tinput_output,\n\t\t\tregexp_match,\n\t\t\tallow_nulls,\n\t\t\ttype_code,\n\t\t\tdata_name\n\t\t\tfrom data_input_fields\n\t\t\twhere data_input_id=" . $_POST["data_input_id"] . "\n\t\t\tand input_output='in'");
        /* pass 1 for validation */
        if (sizeof($input_fields) > 0) {
            foreach ($input_fields as $input_field) {
                $form_value = "value_" . $input_field["data_name"];
                if (isset($_POST[$form_value]) && $input_field["type_code"] == "") {
                    if (isset($_POST["t_" . $form_value]) && $_POST["t_" . $form_value] == "on") {
                        $not_required = true;
                    } else {
                        if ($input_field["allow_nulls"] == "on") {
                            $not_required = true;
                        } else {
                            $not_required = false;
                        }
                    }
                    form_input_validate($_POST[$form_value], "value_" . $input_field["data_name"], $input_field["regexp_match"], $not_required, 3);
                }
            }
        }
        if (!is_error_message()) {
            $data_template_id = sql_save($save1, "data_template");
            if ($data_template_id) {
                raise_message(1);
            } else {
                raise_message(2);
            }
        }
        if (!is_error_message()) {
            $save2["data_template_id"] = $data_template_id;
            $data_template_data_id = sql_save($save2, "data_template_data");
            if ($data_template_data_id) {
                raise_message(1);
            } else {
                raise_message(2);
            }
        }
        /* update actual host template information for live hosts */
        if (!is_error_message() && $save2["id"] > 0) {
            db_execute("update data_template_data set data_input_id = " . $_POST["data_input_id"] . " where data_template_id = " . $_POST["data_template_id"] . ";");
        }
        if (!is_error_message()) {
            $save3["data_template_id"] = $data_template_id;
            $data_template_rrd_id = sql_save($save3, "data_template_rrd");
            if ($data_template_rrd_id) {
                raise_message(1);
            } else {
                raise_message(2);
            }
        }
        if (!is_error_message()) {
            /* save entries in 'selected rras' field */
            db_execute("delete from data_template_data_rra where data_template_data_id={$data_template_data_id}");
            if (isset($_POST["rra_id"])) {
                for ($i = 0; $i < count($_POST["rra_id"]); $i++) {
                    /* ================= input validation ================= */
                    input_validate_input_number($_POST["rra_id"][$i]);
                    /* ==================================================== */
                    db_execute("insert into data_template_data_rra (rra_id,data_template_data_id)\n\t\t\t\t\t\tvalues (" . $_POST["rra_id"][$i] . ",{$data_template_data_id})");
                }
            }
            if (!empty($_POST["data_template_id"])) {
                /* push out all data source settings to child data source using this template */
                push_out_data_source($data_template_data_id);
                push_out_data_source_item($data_template_rrd_id);
                db_execute("delete from data_input_data where data_template_data_id={$data_template_data_id}");
                reset($input_fields);
                if (sizeof($input_fields) > 0) {
                    foreach ($input_fields as $input_field) {
                        $form_value = "value_" . $input_field["data_name"];
                        if (isset($_POST[$form_value])) {
                            /* save the data into the 'host_template_data' table */
                            if (isset($_POST["t_value_" . $input_field["data_name"]])) {
                                $template_this_item = "on";
                            } else {
                                $template_this_item = "";
                            }
                            if (!empty($form_value) || !empty($_POST["t_value_" . $input_field["data_name"]])) {
                                db_execute("insert into data_input_data (data_input_field_id,data_template_data_id,t_value,value)\n\t\t\t\t\t\t\t\tvalues (" . $input_field["id"] . ",{$data_template_data_id}," . $cnn_id->qstr($template_this_item) . "," . $cnn_id->qstr(trim($_POST[$form_value])) . ")");
                            }
                        }
                    }
                }
                /* push out all "custom data" for this data source template */
                push_out_data_source_custom_data($data_template_id);
                push_out_host(0, 0, $data_template_id);
            }
        }
        header("Location: data_templates.php?action=template_edit&id=" . (empty($data_template_id) ? $_POST["data_template_id"] : $data_template_id) . (empty($_POST["current_rrd"]) ? "" : "&view_rrd=" . ($_POST["current_rrd"] ? $_POST["current_rrd"] : $data_template_rrd_id)));
    }
}
Beispiel #29
0
function thold_graphs_action_execute($action)
{
    global $config, $form_array;
    include_once $config['base_path'] . '/plugins/thold/thold_functions.php';
    if ($action == 'plugin_thold_create') {
        $selected_items = unserialize(stripslashes($_POST["selected_items"]));
        $message = "";
        input_validate_input_number($_POST["thold_template_id"]);
        $template = db_fetch_row("SELECT * FROM thold_template WHERE id=" . $_POST["thold_template_id"]);
        for ($i = 0; $i < count($selected_items); $i++) {
            /* ================= input validation ================= */
            input_validate_input_number($selected_items[$i]);
            /* ==================================================== */
            $graph = $selected_items[$i];
            $temp = db_fetch_row("SELECT dtr.*\r\n\t\t\t\t FROM data_template_rrd AS dtr\r\n\t\t\t\t LEFT JOIN graph_templates_item AS gti\r\n\t\t\t\t ON gti.task_item_id=dtr.id\r\n\t\t\t\t LEFT JOIN graph_local AS gl\r\n\t\t\t\t ON gl.id=gti.local_graph_id\r\n\t\t\t\t WHERE gl.id={$graph}");
            $data_template_id = $temp['data_template_id'];
            $local_data_id = $temp['local_data_id'];
            $data_source = db_fetch_row("SELECT * FROM data_local WHERE id=" . $local_data_id);
            $data_template_id = $data_source['data_template_id'];
            $existing = db_fetch_assoc('SELECT id FROM thold_data WHERE rra_id=' . $local_data_id . ' AND data_id=' . $data_template_id);
            if (count($existing) == 0 && count($template)) {
                if ($graph) {
                    $rrdlookup = db_fetch_cell("SELECT id FROM data_template_rrd\r\n\t\t\t\t\t\tWHERE local_data_id={$local_data_id}\r\n\t\t\t\t\t\tORDER BY id\r\n\t\t\t\t\t\tLIMIT 1");
                    $grapharr = db_fetch_row("SELECT graph_template_id\r\n\t\t\t\t\t\tFROM graph_templates_item\r\n\t\t\t\t\t\tWHERE task_item_id={$rrdlookup}\r\n\t\t\t\t\t\tAND local_graph_id={$graph}");
                    $data_source_name = $template['data_source_name'];
                    $insert = array();
                    $name = thold_format_name($template, $graph, $local_data_id, $data_source_name);
                    $insert['name'] = $name;
                    $insert['host_id'] = $data_source['host_id'];
                    $insert['rra_id'] = $local_data_id;
                    $insert['graph_id'] = $graph;
                    $insert['data_template'] = $data_template_id;
                    $insert['graph_template'] = $grapharr['graph_template_id'];
                    $insert['thold_hi'] = $template['thold_hi'];
                    $insert['thold_low'] = $template['thold_low'];
                    $insert['thold_fail_trigger'] = $template['thold_fail_trigger'];
                    $insert['thold_enabled'] = $template['thold_enabled'];
                    $insert['bl_ref_time_range'] = $template['bl_ref_time_range'];
                    $insert['bl_pct_down'] = $template['bl_pct_down'];
                    $insert['bl_pct_up'] = $template['bl_pct_up'];
                    $insert['bl_fail_trigger'] = $template['bl_fail_trigger'];
                    $insert['bl_alert'] = $template['bl_alert'];
                    $insert['repeat_alert'] = $template['repeat_alert'];
                    $insert['notify_extra'] = $template['notify_extra'];
                    $insert['alert_phones_extra'] = $template['alert_phones_extra'];
                    $insert['cdef'] = $template['cdef'];
                    $insert['template'] = $template['id'];
                    $insert['template_enabled'] = 'on';
                    $rrdlist = db_fetch_assoc("SELECT id, data_input_field_id FROM data_template_rrd where local_data_id='{$local_data_id}' and data_source_name='{$data_source_name}'");
                    $int = array('id', 'data_template_id', 'data_source_id', 'thold_fail_trigger', 'bl_ref_time_range', 'bl_pct_down', 'bl_pct_up', 'bl_fail_trigger', 'bl_alert', 'repeat_alert', 'cdef');
                    foreach ($rrdlist as $rrdrow) {
                        $data_rrd_id = $rrdrow['id'];
                        $insert['data_id'] = $data_rrd_id;
                        $existing = db_fetch_assoc("SELECT id FROM thold_data WHERE rra_id='{$local_data_id}' AND data_id='{$data_rrd_id}'");
                        if (count($existing) == 0) {
                            $insert['id'] = 0;
                            $id = sql_save($insert, 'thold_data');
                            if ($id) {
                                thold_template_update_threshold($id, $insert['template']);
                                $l = db_fetch_assoc("SELECT name FROM data_template where id={$data_template_id}");
                                $tname = $l[0]['name'];
                                $name = $data_source_name;
                                if ($rrdrow['data_input_field_id'] != 0) {
                                    $l = db_fetch_assoc('SELECT name FROM data_input_fields where id=' . $rrdrow['data_input_field_id']);
                                    $name = $l[0]['name'];
                                }
                                plugin_thold_log_changes($id, 'created', " {$tname} [{$name}]");
                                $message .= "Created threshold for the Graph '<i>{$tname}</i>' using the Data Source '<i>{$name}</i>'<br>";
                            }
                        }
                    }
                }
            }
        }
        if (strlen($message)) {
            $_SESSION['thold_message'] = "<font size=-2>{$message}</font>";
        } else {
            $_SESSION['thold_message'] = "<font size=-2>Threshold(s) Already Exist - No Thresholds Created</font>";
        }
        raise_message('thold_created');
    } else {
        return $action;
    }
}
function api_mactrack_site_save($site_id, $site_name, $customer_contact, $netops_contact, $facilities_contact, $site_info)
{
    $save['site_id'] = $site_id;
    $save['site_name'] = form_input_validate($site_name, 'site_name', '', false, 3);
    $save['site_info'] = form_input_validate($site_info, 'site_info', '', true, 3);
    $save['customer_contact'] = form_input_validate($customer_contact, 'customer_contact', '', true, 3);
    $save['netops_contact'] = form_input_validate($netops_contact, 'netops_contact', '', true, 3);
    $save['facilities_contact'] = form_input_validate($facilities_contact, 'facilities_contact', '', true, 3);
    $site_id = 0;
    if (!is_error_message()) {
        $site_id = sql_save($save, 'mac_track_sites', 'site_id');
        if ($site_id) {
            raise_message(1);
        } else {
            raise_message(2);
        }
    }
    return $site_id;
}