Example #1
0
function register_field_errors($error_fields) {
	/* mark this field with an input error */
	$_SESSION["sess_error_fields"][$field_name] = 1;

	/* raise the error message */
	raise_message(3);
}
Example #2
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("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));
    }
}
Example #3
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"]);
        }
    }
}
Example #4
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));
    }
}
Example #5
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;
		}
	}
}
Example #6
0
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");
        }
    }
}
Example #7
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");
        }
    }
}
Example #8
0
function flowview_delete_filter()
{
    global $config, $colors;
    db_execute("DELETE FROM plugin_flowview_queries WHERE id=" . get_request_var_request('query'));
    raise_message('flow_deleted');
    header("Location: flowview.php");
    exit;
}
Example #9
0
function flowview_delete_filter()
{
    db_execute('DELETE FROM plugin_flowview_queries WHERE id=' . get_request_var_request('query'));
    db_execute('DELETE FROM plugin_flowview_schedules WHERE savedquery=' . get_request_var_request('query'));
    raise_message('flow_deleted');
    header('Location: flowview.php?tab=filters&header=false');
    exit;
}
Example #10
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;
}
Example #11
0
function settings() {
	global $colors, $themes;

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

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

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

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

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

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

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

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

	html_end_box();


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

}
Example #12
0
function package_import(&$xml) {
	$xml_array = xml_array_get($xml);

	if (sizeof($xml_array) == 0) {
		raise_message(7); /* xml parse error */
		return;
	}

	/* first, import the header which consists of the actual package data */
	$package_id = package_header_import($xml_array["header"]);

	/* next, import the full payload of the package including all of the templates */
	package_payload_import($xml_array["payload"], $package_id);

	/* last, tie the knot by adding the completed graph template references to the package */
	package_header_items_import($xml_array["header"], $package_id);
}
Example #13
0
function change_password() {
	global $colors;

	$change_result = 1;

	$user_realms = api_user_realms_list($_SESSION["sess_user_id"]);

	/* check if authorized */
	if ($user_realms["18"]["value"] == "1") {
		/* check passwords */
		if ((!empty($_POST["password_old"])) && (!empty($_POST["password_new"])) && (!empty($_POST["password_new_confirm"]))) {
			if ($_POST["password_new"] != $_POST["password_new_confirm"]) {
				/* New passwords do not match */
				raise_message(4);
			}else{
				$change_result = api_user_changepassword($_SESSION["sess_user_id"],$_POST["password_new"],$_POST["password_old"]);
				if ($change_result == "0") {
					/* Password changed successfully */
					raise_message(11);
					/* Log password change */
					$username = db_fetch_cell("select username from user_auth where id=" . $_SESSION["sess_user_id"]);
					log_save(_("CHANGEPASSWORD: Password change successful"), SEV_INFO, FACIL_AUTH);
				}elseif ($change_result == "2") {
					/* Authentication failure for old password */
					raise_message(8);
					log_save(_("CHANGEPASSWORD: Authenication failure on old password"), SEV_WARNING, FACIL_AUTH);
				}else{
					/* General error changing password */
					raise_message(9);
					log_save(_("CHANGEPASSWORD: General Error unable to change password"), SEV_ERROR, FACIL_AUTH);
				}
			}
		}else{
			/* error empty fields */
			raise_message(10);
		}
	}

	require_once(CACTI_BASE_PATH . "/include/top_header.php");
	if ($user_realms["18"]["value"] != "1") {
		/* Access Denied */
		display_custom_error_message("Access Denied.");
	}
	require_once(CACTI_BASE_PATH . "/include/bottom_footer.php");

}
Example #14
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));
}
Example #15
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));
}
Example #16
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;
}
Example #17
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;
}
Example #18
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');
        }
    }
}
Example #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");
        }
    }
}
Example #20
0
function clog_purge_logfile()
{
    global $config;
    $logfile = read_config_option('path_cactilog');
    if ($logfile == '') {
        $logfile = './log/cacti.log';
    }
    if (file_exists($logfile)) {
        if (is_writable($logfile)) {
            $timestamp = date('m/d/Y h:i:s A');
            $log_fh = fopen($logfile, 'w');
            fwrite($log_fh, $timestamp . " - WEBUI: Cacti Log Cleared from Web Management Interface\n");
            fclose($log_fh);
            raise_message('clog_purged');
        } else {
            raise_message('clog_permissions');
        }
    } else {
        raise_message('clog_missing');
    }
}
Example #21
0
File: rra.php Project: 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;
    }
}
Example #22
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;
        }
    }
}
Example #23
0
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");
	}
}
Example #24
0
function form_input_validate($field_value, $field_name, $regexp_match, $allow_nulls, $custom_message = 3) {
	/* write current values to the "field_values" array so we can retain them */
	$_SESSION["sess_field_values"][$field_name] = $field_value;

	if (($allow_nulls == true) && ($field_value == "")) {
		return $field_value;
	}

	/* php 4.2+ complains about empty regexps */
	if (empty($regexp_match)) { $regexp_match = ".*"; }

	if ((!ereg($regexp_match, $field_value) || (($allow_nulls == false) && ($field_value == "")))) {
		raise_message($custom_message);

		$_SESSION["sess_error_fields"][$field_name] = $field_name;
	}else{
		$_SESSION["sess_field_values"][$field_name] = $field_value;
	}

	return $field_value;
}
Example #25
0
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;
		}
	}
}
Example #26
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");
	}
}
Example #27
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;
}
Example #28
0
function check_hash_version($hash_version)
{
    global $hash_version_codes, $config;
    $i = 0;
    reset($hash_version_codes);
    while (list($version, $code) = each($hash_version_codes)) {
        if ($version == $config["cacti_version"]) {
            $current_version_index = $i;
        }
        if ($code == $hash_version) {
            $hash_version_index = $i;
            $current_version = $version;
        }
        $i++;
    }
    if (!isset($current_version_index)) {
        raise_message(15);
        /* error: current cacti version does not exist! */
        return false;
    } elseif (!isset($hash_version_index)) {
        raise_message(16);
        /* error: hash version does not exist! */
        return false;
    } elseif ($hash_version_index > $current_version_index) {
        raise_message(17);
        /* error: hash made with a newer version of cacti */
        return false;
    }
    return $current_version;
}
Example #29
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)));
    }
}
Example #30
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;
    }
}