Beispiel #1
0
function api_device_save($device_id, &$_fields_device) {
	require_once(CACTI_BASE_PATH . "/lib/device/device_info.php");

	/* sanity checks */
	validate_id_die($device_id, "device_id", true);

	/* field: id */
	$_fields["id"] = array("type" => DB_TYPE_INTEGER, "value" => $device_id);

	/* convert the input array into something that is compatible with db_replace() */
	$_fields += sql_get_database_field_array($_fields_device, api_device_form_list());

	/* check for an empty field list */
	if (sizeof($_fields) == 1) {
		return true;
	}

	if (db_replace("host", $_fields, array("id"))) {
		if (empty($device_id)) {
			return db_fetch_insert_id();
		}else{
			return $device_id;
		}
	}else{
		return false;
	}
}
function api_data_preset_gprint_save($data_preset_gprint_id, $_fields_data_preset_gprint) {
	require_once(CACTI_BASE_PATH . "/lib/data_preset/data_preset_gprint_info.php");

	/* sanity checks */
	validate_id_die($data_preset_gprint_id, "data_preset_gprint_id", true);

	/* make sure that there is at least one field to save */
	if (sizeof($_fields_data_preset_gprint) == 0) {
		return false;
	}

	/* field: id */
	$_fields["id"] = array("type" => DB_TYPE_INTEGER, "value" => $data_preset_gprint_id);

	/* convert the input array into something that is compatible with db_replace() */
	$_fields += sql_get_database_field_array($_fields_data_preset_gprint, api_data_preset_gprint_form_list());

	if (db_replace("preset_gprint", $_fields, array("id"))) {
		if (empty($data_preset_gprint_id)) {
			$data_preset_gprint_id = db_fetch_insert_id();
		}

		return $data_preset_gprint_id;
	}else{
		return false;
	}
}
Beispiel #3
0
function form_save() {
	global $settings_graphs;

	while (list($tab_short_name, $tab_fields) = each($settings_graphs)) {
		while (list($field_name, $field_array) = each($tab_fields)) {
			if ((isset($field_array["items"])) && (is_array($field_array["items"]))) {
				while (list($sub_field_name, $sub_field_array) = each($field_array["items"])) {
					db_replace("settings_graphs",array("user_id"=>$_SESSION["sess_user_id"],"name"=>$sub_field_name,"value"=>(isset($_POST[$sub_field_name]) ? $_POST[$sub_field_name] : "")),array("user_id","name"),true);
				}
			}else{
				db_replace("settings_graphs",array("user_id"=>$_SESSION["sess_user_id"],"name"=>$field_name,"value"=>(isset($_POST[$field_name]) ? $_POST[$field_name] : "")),array("user_id","name"),true);
			}
		}
	}

	/* reset local settings cache so the user sees the new settings */
	kill_session_var("sess_graph_config_array");

	header("Location: " . $_POST["referer"]);
}
Beispiel #4
0
function api_user_save($array) {

	if (db_replace("user_auth", $array)) {

		/* logging */
		if (empty($array["id"])) {
			/* New user */
			$user_id = db_fetch_insert_id();
			log_save(sprintf(_("USER_ADMIN: User id '%s' added"), $user_id), SEV_NOTICE, FACIL_AUTH);
		}else{
			/* existing user */
			$user_id = $array["id"]["value"];
			log_save(sprintf(_("USER_ADMIN: User id '%s' updated"), $user_id), SEV_NOTICE, FACIL_AUTH);
		}
		return $user_id;
	} else {
		log_save(sprintf(_("USER_ADMIN: Error saving user id '%s' "), $user_id), SEV_ERROR, FACIL_AUTH);
		return 0;
	}

}
Beispiel #5
0
function api_package_metadata_save($package_metadata_id, &$_fields_package_metadata) {
	require_once(CACTI_BASE_PATH . "/lib/package/package_info.php");

	/* sanity checks */
	validate_id_die($package_metadata_id, "package_metadata_id", true);

	/* sanity check for $package_id */
	if ((empty($package_metadata_id)) && (empty($_fields_package_metadata["package_id"]))) {
		log_save("Required package_id when package_metadata_id = 0", SEV_ERROR);
		return false;
	} else if ((isset($_fields_package_metadata["package_id"])) && (!is_numeric($_fields_package_metadata["package_id"]))) {
		return false;
	}

	/* field: id */
	$_fields["id"] = array("type" => DB_TYPE_INTEGER, "value" => $package_metadata_id);

	/* field: package_id */
	if (!empty($_fields_package_metadata["package_id"])) {
		$_fields["package_id"] = array("type" => DB_TYPE_INTEGER, "value" => $_fields_package_metadata["package_id"]);
	}

	/* convert the input array into something that is compatible with db_replace() */
	$_fields += sql_get_database_field_array($_fields_package_metadata, api_package_metadata_form_list());

	/* check for an empty field list */
	if (sizeof($_fields) == 1) {
		return true;
	}

	if (db_replace("package_metadata", $_fields, array("id"))) {
		if (empty($package_metadata_id)) {
			return db_fetch_insert_id();
		}else{
			return $package_metadata_id;
		}
	}else{
		return false;
	}
}
function api_data_preset_rra_item_save($data_preset_rra_item_id, $_fields_data_preset_rra_item) {
	require_once(CACTI_BASE_PATH . "/lib/data_preset/data_preset_rra_info.php");

	/* sanity checks */
	validate_id_die($data_preset_rra_item_id, "data_preset_rra_item_id", true);

	/* make sure that there is at least one field to save */
	if (sizeof($_fields_data_preset_rra_item) == 0) {
		return false;
	}

	/* sanity check for $preset_rra_id */
	if ((empty($data_preset_rra_item_id)) && (empty($_fields_data_preset_rra_item["preset_rra_id"]))) {
		log_save("Required preset_rra_id when data_preset_rra_item_id = 0", SEV_ERROR);
		return false;
	} else if ((isset($_fields_data_preset_rra_item["preset_rra_id"])) && (!db_integer_validate($_fields_data_preset_rra_item["preset_rra_id"]))) {
		return false;
	}

	/* field: id */
	$_fields["id"] = array("type" => DB_TYPE_INTEGER, "value" => $data_preset_rra_item_id);

	/* field: preset_rra_id */
	if (!empty($_fields_data_preset_rra_item["preset_rra_id"])) {
		$_fields["preset_rra_id"] = array("type" => DB_TYPE_INTEGER, "value" => $_fields_data_preset_rra_item["preset_rra_id"]);
	}

	/* convert the input array into something that is compatible with db_replace() */
	$_fields += sql_get_database_field_array($_fields_data_preset_rra_item, api_data_preset_rra_item_form_list());

	if (db_replace("preset_rra_item", $_fields, array("id"))) {
		if (empty($data_preset_rra_item_id)) {
			$data_preset_rra_item_id = db_fetch_insert_id();
		}

		return $data_preset_rra_item_id;
	}else{
		return false;
	}
}
Beispiel #7
0
function sql_save($fields, $table_name, $keys = "") {
	global $cnn_id;

	/* default primary key */
	if (!is_array($keys)) {
		$keys = array("id");
	}

	if (sizeof($fields) > 0) {
		foreach ($fields as $db_field_name => $db_field_value) {
			$new_fields[$db_field_name] = array("type" => DB_TYPE_STRING, "value" => $db_field_value);
		}
	}

	if (db_replace($table_name, $new_fields, $keys)) {
		if (empty($fields["id"])) {
			return $cnn_id->Insert_ID();
		}else{
			return $fields["id"];
		}
	}else{
		return false;
	}
}
Beispiel #8
0
    echo $OUTPUT->notification(get_string('notimplemented', 'tool_replace'));
    echo $OUTPUT->footer();
    die;
}
if (!data_submitted() or !$search or !$replace or !confirm_sesskey() or !$sure) {
    /// Print a form
    echo $OUTPUT->notification(get_string('notsupported', 'tool_replace'));
    echo $OUTPUT->notification(get_string('excludedtables', 'tool_replace'));
    echo $OUTPUT->box_start();
    echo '<div class="mdl-align">';
    echo '<form action="index.php" method="post"><div>';
    echo '<input type="hidden" name="sesskey" value="' . sesskey() . '" />';
    echo '<div><label for="search">' . get_string('searchwholedb', 'tool_replace') . ' </label><input id="search" type="text" name="search" size="40" /> (' . get_string('searchwholedbhelp', 'tool_replace') . ')</div>';
    echo '<div><label for="replace">' . get_string('replacewith', 'tool_replace') . ' </label><input type="text" id="replace" name="replace" size="40" /> (' . get_string('replacewithhelp', 'tool_replace') . ')</div>';
    echo '<div><label for="sure">' . get_string('disclaimer', 'tool_replace') . ' </label><input type="checkbox" id="sure" name="sure" value="1" /></div>';
    echo '<div class="buttons"><input type="submit" class="singlebutton" value="Yes, do it now" /></div>';
    echo '</div></form>';
    echo '</div>';
    echo $OUTPUT->box_end();
    echo $OUTPUT->footer();
    die;
}
echo $OUTPUT->box_start();
db_replace($search, $replace);
echo $OUTPUT->box_end();
/// Rebuild course cache which might be incorrect now
echo $OUTPUT->notification(get_string('notifyrebuilding', 'tool_replace'), 'notifysuccess');
rebuild_course_cache();
echo $OUTPUT->notification(get_string('notifyfinished', 'tool_replace'), 'notifysuccess');
echo $OUTPUT->continue_button(new moodle_url('/admin/index.php'));
echo $OUTPUT->footer();
Beispiel #9
0
		$_REQUEST["step"] = "3";
	}elseif ($_REQUEST["step"] == "3") {
		$_REQUEST["step"] = "4";
	}
}

if ($_REQUEST["step"] == "4") {
	include_once("../lib/data_query.php");
	include_once("../lib/utility.php");

	$i = 0;

	/* get all items on the form and write values for them  */
	while (list($name, $array) = each($input)) {
		if (isset($_POST[$name])) {
			db_replace("settings", array("name"=>"$name","value"=>"$_POST[$name]"), "name", true);
		}
	}

	setcookie(session_name(),"",time() - 3600,"/");

	kill_session_var("sess_config_array");
	kill_session_var("sess_host_cache_array");

	/* just in case we have hard drive graphs to deal with */
	$host_id = db_fetch_cell("select id from host where hostname='127.0.0.1'");

	if (!empty($host_id)) {
		run_data_query($host_id, 6);
	}
Beispiel #10
0
$search = optional_param('search', '', PARAM_RAW);
$replace = optional_param('replace', '', PARAM_RAW);
###################################################################
admin_externalpage_print_header();
print_heading('Search and replace text throughout the whole database');
if (!data_submitted() or !$search or !$replace or !confirm_sesskey()) {
    /// Print a form
    print_simple_box_start('center');
    echo '<div align="center">';
    echo '<form action="replace.php" method="post">';
    echo '<input type="hidden" name="sesskey" value="' . $USER->sesskey . '" />';
    echo 'Search whole database for: <input type="text" name="search" /><br />';
    echo 'Replace with this string: <input type="text" name="replace" /><br />';
    echo '<input type="submit" value="Yes, do it now" /><br />';
    echo '</form>';
    echo '</div>';
    print_simple_box_end();
    admin_externalpage_print_footer();
    die;
}
print_simple_box_start('center');
if (!db_replace($search, $replace)) {
    error('An error has occured during this process');
}
print_simple_box_end();
/// Rebuild course cache which might be incorrect now
notify('Rebuilding course cache...');
rebuild_course_cache();
notify('...finished');
print_continue('index.php');
admin_externalpage_print_footer();
Beispiel #11
0
function api_device_save($id, $host_template_id, $description, $hostname, $snmp_community, $snmp_version,
	$snmp_username, $snmp_password, $snmp_port, $snmp_timeout, $disabled,
	$availability_method, $ping_method, $ping_port, $ping_timeout, $ping_retries,
	$notes, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context) {

	/* 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["notes"]                = form_input_validate($notes, "notes", "", true, 3);

	$save["snmp_version"]         = form_input_validate($snmp_version, "snmp_version", "", true, 3);
	$save["snmp_community"]       = form_input_validate($snmp_community, "snmp_community", "", 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_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["disabled"]             = form_input_validate($disabled, "disabled", "", true, 3);

	$save["availability_method"]  = form_input_validate($availability_method, "availability_method", "^[0-9]+$", false, 3);
	$save["ping_method"]          = form_input_validate($ping_method, "ping_method", "^[0-9]+$", false, 3);
	$save["ping_port"]            = form_input_validate($ping_port, "ping_port", "^[0-9]+$", true, 3);
	$save["ping_timeout"]         = form_input_validate($ping_timeout, "ping_timeout", "^[0-9]+$", true, 3);
	$save["ping_retries"]         = form_input_validate($ping_retries, "ping_retries", "^[0-9]+$", 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_replace("host_snmp_query",array("host_id"=>$host_id,"snmp_query_id"=>$snmp_query["snmp_query_id"],"reindex_method"=>DATA_QUERY_AUTOINDEX_BACKWARDS_UPTIME),array("host_id","snmp_query_id"),true);

				/* 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_replace("host_graph",array("host_id"=>$host_id,"graph_template_id"=>$graph_template["graph_template_id"]),array("host_id","graph_template_id"),true);
			}
			}
		}
	}

	return $host_id;
}
Beispiel #12
0
 */
define('NO_OUTPUT_BUFFERING', true);
require_once '../../../config.php';
require_once $CFG->dirroot . '/course/lib.php';
require_once $CFG->libdir . '/adminlib.php';
admin_externalpage_setup('toolreplace');
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('pageheader', 'tool_replace'));
if (!$DB->replace_all_text_supported()) {
    echo $OUTPUT->notification(get_string('notimplemented', 'tool_replace'));
    echo $OUTPUT->footer();
    die;
}
echo $OUTPUT->box_start();
echo $OUTPUT->notification(get_string('notsupported', 'tool_replace'));
echo $OUTPUT->notification(get_string('excludedtables', 'tool_replace'));
echo $OUTPUT->box_end();
$form = new tool_replace_form();
if (!($data = $form->get_data())) {
    $form->display();
    echo $OUTPUT->footer();
    die;
}
// Scroll to the end when finished.
$PAGE->requires->js_init_code("window.scrollTo(0, 5000000);");
echo $OUTPUT->box_start();
db_replace($data->search, $data->replace);
echo $OUTPUT->box_end();
// Course caches are now rebuilt on the fly.
echo $OUTPUT->continue_button(new moodle_url('/admin/index.php'));
echo $OUTPUT->footer();
Beispiel #13
0
function api_graph_tree_item_save($graph_tree_item_id, &$_fields_graph_tree_item) {
	require_once(CACTI_BASE_PATH . "/include/graph_tree/graph_tree_constants.php");
	require_once(CACTI_BASE_PATH . "/lib/graph_tree/graph_tree_utility.php");
	require_once(CACTI_BASE_PATH . "/lib/graph_tree/graph_tree_info.php");

	/* sanity checks */
	validate_id_die($graph_tree_item_id, "graph_tree_item_id", true);

	/* sanity check for $graph_tree_id */
	if ((empty($graph_tree_item_id)) && (empty($_fields_graph_tree_item["graph_tree_id"]))) {
		log_save("Required graph_tree_id when graph_tree_item_id = 0", SEV_ERROR);
		return false;
	}else if ((isset($_fields_graph_tree_item["graph_tree_id"])) && (!db_integer_validate($_fields_graph_tree_item["graph_tree_id"]))) {
		return false;
	}

	/* sanity check for $item_type */
	if ((!isset($_fields_graph_tree_item["item_type"])) || (!db_integer_validate($_fields_graph_tree_item["item_type"]))) {
		log_save("Missing required item_type", SEV_ERROR);
		return false;
	}

	/* sanity check for $item_value */
	if ((empty($graph_tree_item_id)) && (empty($_fields_graph_tree_item["item_value"]))) {
		log_save("Required item_value when graph_tree_item_id = 0", SEV_ERROR);
		return false;
	}else if ((isset($_fields_graph_tree_item["item_value"])) && ( (($_fields_graph_tree_item["item_type"] == TREE_ITEM_TYPE_GRAPH) || ($_fields_graph_tree_item["item_type"] == TREE_ITEM_TYPE_HOST)) && (!db_integer_validate($_fields_graph_tree_item["item_value"])) )) {
		return false;
	}

	/* sanity check for $parent_item_id */
	if ((!isset($_fields_graph_tree_item["parent_item_id"])) || (!db_integer_validate($_fields_graph_tree_item["parent_item_id"], true))) {
		log_save("Missing required parent_item_id", SEV_ERROR);
		return false;
	}

	/* field: id */
	$_fields["id"] = array("type" => DB_TYPE_INTEGER, "value" => $graph_tree_item_id);

	/* field: graph_tree_id */
	if (isset($_fields_graph_tree_item["graph_tree_id"])) {
		$_fields["graph_tree_id"] = array("type" => DB_TYPE_INTEGER, "value" => $_fields_graph_tree_item["graph_tree_id"]);
	}

	/* get a copy of the parent tree item id */
	if ($_fields_graph_tree_item["parent_item_id"] == "0") {
		$parent_order_key = "";
		$parent_sort_type = TREE_ORDERING_NONE;
	}else{
		$parent_graph_tree_item = api_graph_tree_item_get($_fields_graph_tree_item["parent_item_id"]);
		$parent_order_key = $parent_graph_tree_item["order_key"];
		$parent_sort_type = $parent_graph_tree_item["sort_children_type"];
	}

	/* generate a new order key if this is a new graph tree item */
	if (empty($graph_tree_item_id)) {
		$_fields["order_key"] = array("type" => DB_TYPE_STRING, "value" => api_graph_tree_item_available_order_key_get($_fields_graph_tree_item["graph_tree_id"], $parent_order_key));
	}else{
		$graph_tree_item = api_graph_tree_item_get($graph_tree_item_id);
		$_fields["order_key"] = array("type" => DB_TYPE_STRING, "value" => $graph_tree_item["order_key"]);
	}

	/* if this item is a graph, make sure it is not being added to the same branch twice */
	$search_key = substr($parent_order_key, 0, (api_graph_tree_item_depth_get($parent_order_key) * CHARS_PER_TIER));
	if (($_fields_graph_tree_item["item_type"] == TREE_ITEM_TYPE_GRAPH) && (sizeof(db_fetch_assoc("select id from graph_tree_items where item_value = " . $_fields_graph_tree_item["item_value"] . " and item_type = " . TREE_ITEM_TYPE_GRAPH . " and graph_tree_id = " . $_fields_graph_tree_item["graph_tree_id"] . " and order_key like '$search_key" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', (MAX_TREE_DEPTH * CHARS_PER_TIER) - (strlen($search_key) + CHARS_PER_TIER)) . "'")) > 0)) {
		return true;
	}

	/* convert the input array into something that is compatible with db_replace() */
	$_fields += sql_get_database_field_array($_fields_graph_tree_item, api_graph_tree_item_form_list());

	/* check for an empty field list */
	if (sizeof($_fields) == 1) {
		return true;
	}

	if (db_replace("graph_tree_items", $_fields, array("id"))) {
		if (empty($graph_tree_item_id)) {
			$graph_tree_item_id = db_fetch_insert_id();
		}

		/* re-parent the branch if the parent item has changed */
		if ($_fields_graph_tree_item["parent_item_id"] != api_graph_tree_item_parent_get_bykey($_fields["order_key"]["value"], $_fields_graph_tree_item["graph_tree_id"])) {
			api_graph_tree_item_reparent($graph_tree_item_id, $_fields_graph_tree_item["parent_item_id"]);
		}

		$parent_tree = api_graph_tree_get($_fields_graph_tree_item["graph_tree_id"]);

		/* tree item ordering */
		if ($parent_tree["sort_type"] == TREE_ORDERING_NONE) {
			/* resort our parent */
			if ($parent_sort_type != TREE_ORDERING_NONE) {
				echo $parent_sort_type;
				api_graph_tree_item_sort(SORT_TYPE_TREE_ITEM, $_fields_graph_tree_item["parent_item_id"], $parent_sort_type);
			}

			/* if this is a header, sort direct children */
			if (($_fields_graph_tree_item["item_type"] == TREE_ITEM_TYPE_HEADER) && ($parent_sort_type != TREE_ORDERING_NONE)) {
				api_graph_tree_item_sort(SORT_TYPE_TREE_ITEM, $graph_tree_item_id, $parent_sort_type);
			}
		/* tree ordering */
		}else{
			/* potential speed savings for large trees */
			if (api_graph_tree_item_depth_get($_fields["order_key"]["value"]) == 1) {
				api_graph_tree_item_sort(SORT_TYPE_TREE, $_fields_graph_tree_item["graph_tree_id"], $parent_tree["sort_type"]);
			}else{
				api_graph_tree_item_sort(SORT_TYPE_TREE_ITEM, $_fields_graph_tree_item["parent_item_id"], $parent_tree["sort_type"]);
			}
		}

		/* if the user checked the 'Propagate Changes' box */
		if (($_fields_graph_tree_item["item_type"] == TREE_ITEM_TYPE_HEADER) && (isset($_fields_graph_tree_item["sort_children_type"])) && (!empty($_fields_graph_tree_item["propagate_changes"]))) {
			$graph_tree_items = api_graph_tree_item_list($_fields_graph_tree_item["graph_tree_id"], array("item_type" => TREE_ITEM_TYPE_HEADER), $graph_tree_item_id, false, false);

			if (is_array($graph_tree_items) > 0) {
				foreach ($graph_tree_items as $graph_tree_item) {
					db_update("graph_tree_items",
						array(
							"id" => array("type" => DB_TYPE_INTEGER, "value" => $graph_tree_item["id"]),
							"sort_children_type" => array("type" => DB_TYPE_INTEGER, "value" => $_fields_graph_tree_item["sort_children_type"])
							),
						array("id"));

					if ($_fields_graph_tree_item["sort_children_type"] != TREE_ORDERING_NONE) {
						api_graph_tree_item_sort(SORT_TYPE_TREE_ITEM, $graph_tree_item["id"], $_fields_graph_tree_item["sort_children_type"]);
					}
				}
			}
		}

		return $graph_tree_item_id;
	}else{
		return false;
	}
}
function form_save() {
	if (isset($_POST["save_component_item"])) {
		/* ================= input validation ================= */
		input_validate_input_number(get_request_var_post("graph_template_id"));
		input_validate_input_number(get_request_var_post("task_item_id"));
		/* ==================================================== */

		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", "graph_template_id=" . $_POST["graph_template_id"] . " and local_graph_id=0");
			}

			$save["id"] = $_POST["graph_template_item_id"];
			$save["hash"] = get_hash_graph_template($_POST["graph_template_item_id"], "graph_template_item");
			$save["graph_template_id"] = $_POST["graph_template_id"];
			$save["local_graph_id"] = 0;
			$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()) {
				/* Before we save the item, let's get a look at task_item_id <-> input associations */
				$orig_data_source_graph_inputs = db_fetch_assoc("select
					graph_template_input.id,
					graph_template_input.name,
					graph_templates_item.task_item_id
					from graph_template_input, graph_template_input_defs, graph_templates_item
					where graph_template_input.id=graph_template_input_defs.graph_template_input_id
					and graph_template_input_defs.graph_template_item_id=graph_templates_item.id
					and graph_template_input.graph_template_id=" . $save["graph_template_id"] . "
					and graph_template_input.column_name='task_item_id'
					group by graph_templates_item.task_item_id,graph_template_input.id,graph_template_input.name");

				$orig_data_source_to_input = array_rekey($orig_data_source_graph_inputs, "task_item_id", "id");

				$graph_template_item_id = sql_save($save, "graph_templates_item");

				if ($graph_template_item_id) {
					raise_message(1);

					if (!empty($save["task_item_id"])) {
						/* old item clean-up.  Don't delete anything if the item <-> task_item_id association remains the same. */
						if ($_POST["_task_item_id"] != $_POST["task_item_id"]) {
							/* It changed.  Delete any old associations */
							db_execute("delete from graph_template_input_defs where graph_template_item_id=$graph_template_item_id");

							/* Input for current data source exists and has changed.  Update the association */
							if (isset($orig_data_source_to_input{$save["task_item_id"]})) {
								db_replace("graph_template_input_defs",array("graph_template_input_id"=>$orig_data_source_to_input{$save["task_item_id"]},"graph_template_item_id"=>$graph_template_item_id),array("graph_template_input_id","graph_template_item_id"),true);
							}
						}

						/* an input for the current data source does NOT currently exist, let's create one */
						if (!isset($orig_data_source_to_input{$save["task_item_id"]})) {
							$ds_name = db_fetch_cell("select data_source_name from data_template_rrd where id=" . $_POST["task_item_id"]);

							/* db_replace() won't work since an insert_id is needed */
							db_execute("delete from graph_template_input where graph_template_id = " . $save["graph_template_id"] . " and name = 'Data Source [$ds_name]' and column_name = 'task_item_id'");
							$graph_template_input_id = db_fetch_cell("select max(id)+1 from graph_template_input");
							db_execute("insert into graph_template_input (id,hash,graph_template_id,name,column_name) values ($graph_template_input_id,'" . get_hash_graph_template(0, "graph_template_input") . "',". $save["graph_template_id"].",'Data Source [$ds_name]','task_item_id')");

							$graph_items = db_fetch_assoc("select id from graph_templates_item where graph_template_id=" . $save["graph_template_id"] . " and task_item_id=" . $_POST["task_item_id"]);

							if (sizeof($graph_items) > 0) {
							foreach ($graph_items as $graph_item) {
								db_replace("graph_template_input_defs",array("graph_template_input_id"=>$graph_template_input_id,"graph_template_item_id"=>$graph_item["id"]),array("graph_template_input_id","graph_template_item_id"),true);
							}
							}
						}
					}

					push_out_graph_item($graph_template_item_id);

					if (isset($orig_data_source_to_input{$_POST["task_item_id"]})) {
						/* make sure all current graphs using this graph input are aware of this change */
						push_out_graph_input($orig_data_source_to_input{$_POST["task_item_id"]}, $graph_template_item_id, array($graph_template_item_id => $graph_template_item_id));
					}
				}else{
					raise_message(2);
				}
			}

			$_POST["sequence"] = 0;
		}

		if (is_error_message()) {
			header("Location: graph_templates_items.php?action=item_edit&graph_template_item_id=" . (empty($graph_template_item_id) ? $_POST["graph_template_item_id"] : $graph_template_item_id) . "&id=" . $_POST["graph_template_id"]);
			exit;
		}else{
			header("Location: graph_templates.php?action=template_edit&id=" . $_POST["graph_template_id"]);
			exit;
		}
	}
}
Beispiel #15
0
function update_link_payment($pid, $data, $success, $raw)
{
    global $db, $tables;
    $pdata = $db->GetRow("SELECT * FROM `{$tables['payment']['name']}` WHERE `ID` = " . $db->qstr($pid));
    if (!$pdata['ID']) {
        return false;
    }
    $pdata['NAME'] = $data['name'];
    $pdata['EMAIL'] = $data['email'];
    $pdata['PAYED_TOTAL'] = (int) $data['total'];
    $pdata['PAYED_QUANTITY'] = (double) $data['quantity'];
    $pdata['CONFIRMED'] = $success ? 1 : 0;
    $pdata['CONFIRM_DATE'] = gmdate('Y-m-d H:i:s');
    $pdate['RAW_LOG'] = $raw;
    if ((double) $pdata['PAYED_TOTAL'] < (double) $pdata['TOTAL']) {
        $pdata['CONFIRMED'] = -1;
    }
    db_replace('payment', $pdata, 'ID');
    $ldata = $db->GetRow("SELECT * FROM `{$tables['link']['name']}` WHERE `ID` = " . $db->qstr($pdata['LINK_ID']));
    send_payment_notifications($pdata, $ldata);
    //Take no action if link not found
    if (!$ldata['ID']) {
        return false;
    }
    $ldata['EXPIRY_DATE'] = '';
    if ($pdata['CONFIRMED'] != 1 || (double) $pdata['PAYED_TOTAL'] < (double) $pdata['TOTAL']) {
        $ldata['PAYED'] = 0;
    } else {
        $ldata['PAYED'] = $pdata['ID'];
        if (PAY_AUTO_ACCEPT) {
            $ldata['STATUS'] = 2;
            $exp_date = calculate_expiry_date(time(), $pdata['QUANTITY'], $pdata['UM']);
            if ($exp_date != 0) {
                $ldata['EXPIRY_DATE'] = gmdate('Y-m-d H:i:s', $exp_date);
            }
        }
    }
    db_replace('link', $ldata, 'ID');
}
Beispiel #16
0
        SmartyValidate::register_validator('v_quantity', 'quantity', 'isInt', false, false, 'trim', 'pay_link');
    } else {
        SmartyValidate::connect($tpl);
        if (SmartyValidate::is_valid($_REQUEST, 'pay_link')) {
            $pay_data = array();
            $pay_id = $db->GenID($tables['payment']['name'] . '_SEQ');
            $pay_data['ID'] = $pay_id;
            $pay_data['LINK_ID'] = $data['ID'];
            $pay_data['IPADDRESS'] = get_client_ip();
            $pay_data['QUANTITY'] = $_REQUEST['quantity'];
            $pay_data['AMOUNT'] = $price[$data['LINK_TYPE']];
            $pay_data['TOTAL'] = (int) $pay_data['QUANTITY'] * (double) $pay_data['AMOUNT'];
            $pay_data['UM'] = PAY_UM;
            $pay_data['PAY_DATE'] = gmdate('Y-m-d H:i:s');
            $pay_data['CONFIRMED'] = -1;
            if (db_replace('payment', $pay_data, 'ID') > 0) {
                $action = 'paypal';
                $tpl->assign('PAYMENT', $pay_data);
            } else {
                $tpl->assign('error', true);
            }
        }
    }
    $quantity = !empty($_REQUEST['quantity']) && preg_match('`^[\\d]+$`', $_REQUEST['quantity']) ? intval($_REQUEST['quantity']) : 1;
}
$tpl->assign('quantity', $quantity);
$tpl->assign('price', $price);
$tpl->assign('action', $action);
$path = array();
$path[] = array('ID' => '0', 'TITLE' => _L(SITE_NAME), 'TITLE_URL' => DOC_ROOT, 'DESCRIPTION' => SITE_DESC);
$path[] = array('ID' => '0', 'TITLE' => _L('Link Payment'), 'TITLE_URL' => '', 'DESCRIPTION' => _L('Submit a new link to the directory '));
 if ($data['FEATURED'] == '1') {
     $AllowedFeat = check_allowed_feat($data['CATEGORY_ID']);
     $tpl->assign('AllowedFeat', $AllowedFeat);
 }
 if (ENABLE_PAGERANK) {
     require_once 'include/pagerank.php';
     $data['PAGERANK'] = get_page_rank($data['URL']);
     if (!empty($data['RECPR_URL'])) {
         $data['RECPR_PAGERANK'] = get_page_rank($data['RECPR_URL']);
     }
 }
 $data['ID'] = $id;
 if (!isset($data['RECPR_REQUIRED'])) {
     $data['RECPR_REQUIRED'] = 0;
 }
 if (db_replace('link', $data, 'ID') > 0) {
     $tpl->assign('posted', true);
     if ($action == 'N') {
         $cid = $data['CATEGORY_ID'];
         $data = array();
         $data['STATUS'] = 2;
         $data['CATEGORY_ID'] = $cid;
     } else {
         send_status_notifications($id);
         if (isset($_SESSION['return'])) {
             @header('Location: ' . $_SESSION['return']);
             @exit;
         }
     }
 } else {
     $tpl->assign('sql_error', $db->ErrorMsg());
Beispiel #18
0
function create_complete_graph_from_template($graph_template_id, $host_id, $snmp_query_array, &$suggested_values_array) {
	global $config;

	include_once($config["library_path"] . "/data_query.php");

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

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

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

	/* This next block is simply designed to find the best suggested template
     * name for our new graph. The suggested values are held in 
	 * snmp_query_graph_sv and the graph is updated in graph_templates_graph.
	 */
	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"], $host_id, $snmp_query_array["snmp_query_id"], $snmp_query_array["snmp_index"], read_config_option("max_data_query_field_length"));
				/* 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($suggested_value["text"]) . "' 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 */
	/* FIXED: group by */
	$data_templates = db_fetch_assoc("select
		data_template.id,
		data_template.name,
		max(data_template_rrd.data_source_name) as data_source_name
		from (data_template 
		cross join data_template_rrd 
		cross join 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,
		data_template.name
		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["host_id"] = $host_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"], $host_id, $snmp_query_array["snmp_query_id"], $snmp_query_array["snmp_index"], read_config_option("max_data_query_field_length"));

					/* if there are no '|' characters, all of the substitutions were successful */
					if (!strstr($subs_string, "|query")) {
						if (sql_column_exists("data_template_data", $suggested_value["field_name"])) {
							db_execute("update data_template_data set " . $suggested_value["field_name"] . "='" . addslashes($suggested_value["text"]) . "' 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 (sql_column_exists("data_template_data", $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 
					cross join data_input 
					cross join 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 host_snmp_cache where host_id='$host_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_replace("data_input_data",array("data_input_field_id"=>$data_input_field["index_type"],"data_template_data_id"=>$data_template_data_id,"t_value"=>"","value"=>$snmp_query_array["snmp_index_on"]),array("data_input_field_id","data_template_data_id"),true);

			/* save the actual value (ie. 3, 192.168.1.101, etc) */
			db_replace("data_input_data",array("data_input_field_id"=>$data_input_field["index_value"],"data_template_data_id"=>$data_template_data_id,"t_value"=>"","value"=>addslashes($snmp_cache_value)),array("data_input_field_id","data_template_data_id"),true);

			/* set the expected output type (ie. bytes, errors, packets) */
			db_replace("data_input_data",array("data_input_field_id"=>$data_input_field["output_type"],"data_template_data_id"=>$data_template_data_id,"t_value"=>"","value"=>$snmp_query_array["snmp_query_graph_id"]),array("data_input_field_id","data_template_data_id"),true);

			/* 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_replace("data_input_data",array("data_input_field_id"=>$data_input_field_id,"data_template_data_id"=>$data_template_data_id,"t_value"=>"","value"=>$field_value),array("data_input_field_id","data_template_data_id"),true);
			}
		}

		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 cross join 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"]);
	}

	return $cache_array;
}
Beispiel #19
0
	while (list($field_name, $field_array) = each($settings{$_POST["tab"]})) {
		if (($field_array["method"] == "header") || ($field_array["method"] == "spacer" )){
				/* do nothing */
		}elseif ($field_array["method"] == "textbox_password") {
			if ($_POST[$field_name] != $_POST[$field_name."_confirm"]) {
				raise_message(4);
				break;
			}else{
				db_replace("settings", array("name"=>$field_name,"value"=>(isset($_POST[$field_name]) ? $_POST[$field_name] : "")),"name",true);
			}
		}elseif ((isset($field_array["items"])) && (is_array($field_array["items"]))) {
			while (list($sub_field_name, $sub_field_array) = each($field_array["items"])) {
				db_replace("settings",array("name"=>$sub_field_name,"value"=>(isset($_POST[$sub_field_name]) ? $_POST[$sub_field_name] : "")),"name",true);
			}
		}else{
			db_replace("settings",array("name"=>$field_name,"value"=>(isset($_POST[$field_name]) ? $_POST[$field_name] : "")),"name",true);
		}
	}

	raise_message(1);

	/* reset local settings cache so the user sees the new settings */
	kill_session_var("sess_config_array");

	header("Location: settings.php?tab=" . $_POST["tab"]);
	break;
default:
	include("./include/top_header.php");

	/* set the default settings category */
	if (!isset($_GET["tab"])) {
Beispiel #20
0
							$output = exec_poll($index_item["arg1"]);
							break;
						}

						/* assert the result with the expected value in the db; recache if the assert fails */
						if (($index_item["op"] == "=") && ($index_item["assert_value"] != trim($output))) {
							cacti_log("ASSERT: '" . $index_item["assert_value"] . "=" . trim($output) . "' failed. Recaching host '" . $item["hostname"] . "', data query #" . $index_item["data_query_id"], $print_data_to_stdout);
							db_replace("poller_command", array("poller_id"=>0, "time"=>sql_function_timestamp(), "action"=>POLLER_COMMAND_REINDEX, "command"=>$item["host_id"] . ":" . $index_item["data_query_id"]), array("poller_id", "action", "command"), true);
							$assert_fail = true;
						}else if (($index_item["op"] == ">") && ($index_item["assert_value"] < trim($output))) {
							cacti_log("ASSERT: '" . $index_item["assert_value"] . ">" . trim($output) . "' failed. Recaching host '" . $item["hostname"] . "', data query #" . $index_item["data_query_id"], $print_data_to_stdout);
							db_replace("poller_command", array("poller_id"=>0, "time"=>sql_function_timestamp(), "action"=>POLLER_COMMAND_REINDEX, "command"=>$item["host_id"] . ":" . $index_item["data_query_id"]), array("poller_id", "action", "command"), true);
							$assert_fail = true;
						}else if (($index_item["op"] == "<") && ($index_item["assert_value"] > trim($output))) {
							cacti_log("ASSERT: '" . $index_item["assert_value"] . "<" . trim($output) . "' failed. Recaching host '" . $item["hostname"] . "', data query #" . $index_item["data_query_id"], $print_data_to_stdout);
							db_replace("poller_command", array("poller_id"=>0, "time"=>sql_function_timestamp(), "action"=>POLLER_COMMAND_REINDEX, "command"=>$item["host_id"] . ":" . $index_item["data_query_id"]), array("poller_id", "action", "command"), true);
							$assert_fail = true;
						}

						/* update 'poller_reindex' with the correct information if:
						 * 1) the assert fails
						 * 2) the OP code is > or < meaning the current value could have changed without causing
						 *     the assert to fail */
						if (($assert_fail == true) || ($index_item["op"] == ">") || ($index_item["op"] == "<")) {
							db_execute("update poller_reindex set assert_value='$output' where host_id='$host_id' and data_query_id='" . $index_item["data_query_id"] . "' and arg1='" . $index_item["arg1"] . "'");

							/* spike kill logic */
							if (($assert_fail) &&
								(($index_item["op"] == "<") || ($index_item["arg1"] == ".1.3.6.1.2.1.1.3.0"))) {
								/* don't spike kill unless we are certain */
								if (!empty($output)) {
Beispiel #21
0
/**
 * Update any references from alfresco or elis_files to elisfiles in the database.
 *
 * @return boolean True upon success
 */
function elis_files_update_references_in_database() {
    $result = db_replace('/repository/alfresco/openfile', '/repository/elisfiles/openfile');
    $result &= db_replace('/repository/elis_files/', '/repository/elisfiles/');
    return $result;
}
Beispiel #22
0
						"HostsPerProcess:%s " .
						"DataSources:%s " .
						"RRDsProcessed:%s",
						round($loop_end-$loop_start,4),
						$method,
						$concurrent_processes,
						$max_threads,
						sizeof($polling_hosts),
						$hosts_per_file,
						$num_polling_items,
						$rrds_processed);

					cacti_log("STATS: " . $cacti_stats ,true,"SYSTEM");

					/* insert poller stats into the settings table */
					db_replace("settings",array("name"=>"stats_poller","value"=>$cacti_stats),"name", true);

					break;
				}

				sleep(1);
			}
		}

		rrd_close($rrdtool_pipe);

		/* process poller commands */
		if (db_fetch_cell("select count(*) from poller_command") > 0) {
			$command_string = read_config_option("path_php_binary");
			$extra_args = "-q " . $config["base_path"] . "/poller_commands.php";
			exec_background($command_string, "$extra_args");
Beispiel #23
0
function syslog_db_replace($table_name, $array_items, $keyCols)
{
    return db_replace($table_name, $array_items, $keyCols);
}
Beispiel #24
0
function form_save() {
	if ((isset($_POST["save_component_data_source_new"])) && (!empty($_POST["data_template_id"]))) {
		/* ================= input validation ================= */
		input_validate_input_number(get_request_var_post("host_id"));
		input_validate_input_number(get_request_var_post("data_template_id"));
		/* ==================================================== */

		$save["id"] = $_POST["local_data_id"];
		$save["data_template_id"] = $_POST["data_template_id"];
		$save["host_id"] = $_POST["host_id"];

		$local_data_id = sql_save($save, "data_local");

		change_data_template($local_data_id, $_POST["data_template_id"]);

		/* update the title cache */
		update_data_source_title_cache($local_data_id);

		/* update host data */
		if (!empty($_POST["host_id"])) {
			push_out_host($_POST["host_id"], $local_data_id);
		}
	}

	if ((isset($_POST["save_component_data"])) && (!is_error_message())) {
		/* ================= input validation ================= */
		input_validate_input_number(get_request_var_post("data_template_data_id"));
		/* ==================================================== */

		/* ok, first pull out all 'input' values so we know how much to save */
		$input_fields = db_fetch_assoc("select
			data_template_data.data_input_id,
			data_local.host_id,
			data_input_fields.id,
			data_input_fields.input_output,
			data_input_fields.data_name,
			data_input_fields.regexp_match,
			data_input_fields.allow_nulls,
			data_input_fields.type_code
			from data_template_data
			left join data_input_fields on (data_input_fields.data_input_id=data_template_data.data_input_id)
			left join data_local on (data_template_data.local_data_id=data_local.id)
			where data_template_data.id=" . $_POST["data_template_data_id"] . "
			and data_input_fields.input_output='in'");

		if (sizeof($input_fields) > 0) {
		foreach ($input_fields as $input_field) {
			if (isset($_POST{"value_" . $input_field["id"]})) {
				/* save the data into the 'data_input_data' table */
				$form_value = $_POST{"value_" . $input_field["id"]};

				/* we shouldn't enforce rules on fields the user cannot see (ie. templated ones) */
				$is_templated = db_fetch_cell("select t_value from data_input_data where data_input_field_id=" . $input_field["id"] . " and data_template_data_id=" . db_fetch_cell("select local_data_template_data_id from data_template_data where id=" . $_POST["data_template_data_id"]));

				if ($is_templated == "") {
					$allow_nulls = true;
				}elseif ($input_field["allow_nulls"] == "on") {
					$allow_nulls = true;
				}elseif (empty($input_field["allow_nulls"])) {
					$allow_nulls = false;
				}

				/* run regexp match on input string */
				$form_value = form_input_validate($form_value, "value_" . $input_field["id"], $input_field["regexp_match"], $allow_nulls, 3);

				if (!is_error_message()) {
					db_replace("data_input_data",array("data_input_field_id"=>$input_field["id"],"data_template_data_id"=>$_POST["data_template_data_id"],"t_value"=>"","value"=>$form_value),array("data_input_field_id","data_template_data_id"),true);
				}
			}
		}
		}
	}

	if ((isset($_POST["save_component_data_source"])) && (!is_error_message())) {
		/* ================= input validation ================= */
		input_validate_input_number(get_request_var_post("local_data_id"));
		input_validate_input_number(get_request_var_post("current_rrd"));
		input_validate_input_number(get_request_var_post("data_template_id"));
		input_validate_input_number(get_request_var_post("host_id"));
		/* ==================================================== */

		$save1["id"] = $_POST["local_data_id"];
		$save1["data_template_id"] = $_POST["data_template_id"];
		$save1["host_id"] = $_POST["host_id"];

		$save2["id"] = $_POST["data_template_data_id"];
		$save2["local_data_template_data_id"] = $_POST["local_data_template_data_id"];
		$save2["data_template_id"] = $_POST["data_template_id"];
		$save2["data_input_id"] = form_input_validate($_POST["data_input_id"], "data_input_id", "", true, 3);
		$save2["name"] = form_input_validate($_POST["name"], "name", "", false, 3);
		$save2["data_source_path"] = form_input_validate($_POST["data_source_path"], "data_source_path", "", true, 3);
		$save2["active"] = form_input_validate((isset($_POST["active"]) ? $_POST["active"] : ""), "active", "", true, 3);
		$save2["rrd_step"] = form_input_validate($_POST["rrd_step"], "rrd_step", "^[0-9]+$", false, 3);

		if (!is_error_message()) {
			$local_data_id = sql_save($save1, "data_local");

			$save2["local_data_id"] = $local_data_id;
			$data_template_data_id = sql_save($save2, "data_template_data");

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

		if (!is_error_message()) {
			/* if this is a new data source and a template has been selected, skip item creation this time
			otherwise it throws off the templatate creation because of the NULL data */
			if ((!empty($_POST["local_data_id"])) || (empty($_POST["data_template_id"]))) {
				/* if no template was set before the save, there will be only one data source item to save;
				otherwise there might be >1 */
				if (empty($_POST["_data_template_id"])) {
					$rrds[0]["id"] = $_POST["current_rrd"];
				}else{
					$rrds = db_fetch_assoc("select id from data_template_rrd where local_data_id=" . $_POST["local_data_id"]);
				}

				if (sizeof($rrds) > 0) {
				foreach ($rrds as $rrd) {
					if (empty($_POST["_data_template_id"])) {
						$name_modifier = "";
					}else{
						$name_modifier = "_" . $rrd["id"];
					}

					$save3["id"] = $rrd["id"];
					$save3["local_data_id"] = $local_data_id;
					$save3["local_data_template_rrd_id"] = db_fetch_cell("select local_data_template_rrd_id from data_template_rrd where id=" . $rrd["id"]);
					$save3["data_template_id"] = $_POST["data_template_id"];
					$save3["rrd_maximum"] = form_input_validate($_POST["rrd_maximum$name_modifier"], "rrd_maximum$name_modifier", "^-?[0-9]+$", false, 3);
					$save3["rrd_minimum"] = form_input_validate($_POST["rrd_minimum$name_modifier"], "rrd_minimum$name_modifier", "^-?[0-9]+$", false, 3);
					$save3["rrd_heartbeat"] = form_input_validate($_POST["rrd_heartbeat$name_modifier"], "rrd_heartbeat$name_modifier", "^[0-9]+$", false, 3);
					$save3["data_source_type_id"] = $_POST["data_source_type_id$name_modifier"];
					$save3["data_source_name"] = form_input_validate($_POST["data_source_name$name_modifier"], "data_source_name$name_modifier", "^[a-zA-Z0-9_-]{1,19}$", false, 3);
					$save3["data_input_field_id"] = form_input_validate((isset($_POST["data_input_field_id$name_modifier"]) ? $_POST["data_input_field_id$name_modifier"] : "0"), "data_input_field_id$name_modifier", "", true, 3);

					$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()) {
			if (!empty($_POST["rra_id"])) {
				/* save entries in 'selected rras' field */
				db_execute("delete from data_template_data_rra where data_template_data_id=$data_template_data_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)
						values (" . $_POST["rra_id"][$i] . ",$data_template_data_id)");
				}
			}

			if ($_POST["data_template_id"] != $_POST["_data_template_id"]) {
				/* update all necessary template information */
				change_data_template($local_data_id, $_POST["data_template_id"]);
			}elseif (!empty($_POST["data_template_id"])) {
				update_data_source_data_query_cache($local_data_id);
			}

			if ($_POST["host_id"] != $_POST["_host_id"]) {
				/* push out all necessary host information */
				push_out_host($_POST["host_id"], $local_data_id);

				/* reset current host for display purposes */
				$_SESSION["sess_data_source_current_host_id"] = $_POST["host_id"];
			}

			/* if no data source path has been entered, generate one */
			if (empty($_POST["data_source_path"])) {
				generate_data_source_path($local_data_id);
			}

			/* update the title cache */
			update_data_source_title_cache($local_data_id);
		}
	}

	/* update the poller cache last to make sure everything is fresh */
	if ((!is_error_message()) && (!empty($local_data_id))) {
		update_poller_cache($local_data_id, false);
	}

	if ((isset($_POST["save_component_data_source_new"])) && (empty($_POST["data_template_id"]))) {
		header("Location: data_sources.php?action=ds_edit&host_id=" . $_POST["host_id"] . "&new=1");
	}elseif ((is_error_message()) || ($_POST["data_template_id"] != $_POST["_data_template_id"]) || ($_POST["data_input_id"] != $_POST["_data_input_id"]) || ($_POST["host_id"] != $_POST["_host_id"])) {
		header("Location: data_sources.php?action=ds_edit&id=" . (empty($local_data_id) ? $_POST["local_data_id"] : $local_data_id) . "&host_id=" . $_POST["host_id"] . "&view_rrd=" . (isset($_POST["current_rrd"]) ? $_POST["current_rrd"] : "0"));
	}else{
		header("Location: data_sources.php");
	}
}
Beispiel #25
0
function form_save() {
	if (isset($_POST["save_component_snmp_query"])) {
		$save["id"] = $_POST["id"];
		$save["hash"] = get_hash_data_query($_POST["id"]);
		$save["name"] = form_input_validate($_POST["name"], "name", "", false, 3);
		$save["description"] = form_input_validate($_POST["description"], "description", "", true, 3);
		$save["xml_path"] = form_input_validate($_POST["xml_path"], "xml_path", "", false, 3);
		$save["data_input_id"] = $_POST["data_input_id"];

		if (!is_error_message()) {
			$snmp_query_id = sql_save($save, "snmp_query");

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

		if ((is_error_message()) || (empty($_POST["id"]))) {
			header("Location: data_queries.php?action=edit&id=" . (empty($snmp_query_id) ? $_POST["id"] : $snmp_query_id));
		}else{
			header("Location: data_queries.php");
		}
	}elseif (isset($_POST["save_component_snmp_query_item"])) {
		/* ================= input validation ================= */
		input_validate_input_number(get_request_var_post("id"));
		/* ==================================================== */

		$redirect_back = false;

		$save["id"] = $_POST["id"];
		$save["hash"] = get_hash_data_query($_POST["id"], "data_query_graph");
		$save["snmp_query_id"] = $_POST["snmp_query_id"];
		$save["name"] = form_input_validate($_POST["name"], "name", "", false, 3);
		$save["graph_template_id"] = $_POST["graph_template_id"];

		if (!is_error_message()) {
			$snmp_query_graph_id = sql_save($save, "snmp_query_graph");

			if ($snmp_query_graph_id) {
				raise_message(1);

				/* if the user changed the graph template, go through and delete everything that
				was associated with the old graph template */
				if ($_POST["graph_template_id"] != $_POST["_graph_template_id"]) {
					db_execute("delete from snmp_query_graph_rrd_sv where snmp_query_graph_id=$snmp_query_graph_id");
					db_execute("delete from snmp_query_graph_sv where snmp_query_graph_id=$snmp_query_graph_id");
					$redirect_back = true;
				}

				db_execute("delete from snmp_query_graph_rrd where snmp_query_graph_id=$snmp_query_graph_id");

				while (list($var, $val) = each($_POST)) {
					if (eregi("^dsdt_([0-9]+)_([0-9]+)_check", $var)) {
						$data_template_id = ereg_replace("^dsdt_([0-9]+)_([0-9]+).+", "\\1", $var);
						$data_template_rrd_id = ereg_replace("^dsdt_([0-9]+)_([0-9]+).+", "\\2", $var);

						db_replace("snmp_query_graph_rrd", array("snmp_query_graph_id"=>"$snmp_query_graph_id", "data_template_id"=>"$data_template_id","data_template_rrd_id"=>"$data_template_rrd_id","snmp_field_name"=>$_POST{"dsdt_" . $data_template_id . "_" . $data_template_rrd_id . "_snmp_field_output"}), array("snmp_query_graph_id","data_template_id"), true);
					}elseif ((eregi("^svds_([0-9]+)_x", $var, $matches)) && (!empty($_POST{"svds_" . $matches[1] . "_text"})) && (!empty($_POST{"svds_" . $matches[1] . "_field"}))) {
						/* suggested values -- data templates */
						$sequence = get_sequence(0, "sequence", "snmp_query_graph_rrd_sv", "snmp_query_graph_id=" . $_POST["id"]  . " and data_template_id=" . $matches[1] . " and field_name='" . $_POST{"svds_" . $matches[1] . "_field"} . "'");
						$hash = get_hash_data_query(0, "data_query_sv_data_source");
						db_execute("insert into snmp_query_graph_rrd_sv (hash,snmp_query_graph_id,data_template_id,sequence,field_name,text) values ('$hash'," . $_POST["id"] . "," . $matches[1] . ",$sequence,'" . $_POST{"svds_" . $matches[1] . "_field"} . "','" . $_POST{"svds_" . $matches[1] . "_text"} . "')");

						$redirect_back = true;
						clear_messages();
					}elseif ((eregi("^svg_x", $var)) && (!empty($_POST{"svg_text"})) && (!empty($_POST{"svg_field"}))) {
						/* suggested values -- graph templates */
						$sequence = get_sequence(0, "sequence", "snmp_query_graph_sv", "snmp_query_graph_id=" . $_POST["id"] . " and field_name='" . $_POST{"svg_field"} . "'");
						$hash = get_hash_data_query(0, "data_query_sv_graph");
						db_execute("insert into snmp_query_graph_sv (hash,snmp_query_graph_id,sequence,field_name,text) values ('$hash'," . $_POST["id"] . ",$sequence,'" . $_POST{"svg_field"} . "','" . $_POST{"svg_text"} . "')");

						$redirect_back = true;
						clear_messages();
					}
				}
			}else{
				raise_message(2);
			}
		}

		if ((is_error_message()) || (empty($_POST["id"])) || ($redirect_back == true)) {
			header("Location: data_queries.php?action=item_edit&id=" . (empty($snmp_query_graph_id) ? $_POST["id"] : $snmp_query_graph_id) . "&snmp_query_id=" . $_POST["snmp_query_id"]);
		}else{
			header("Location: data_queries.php?action=edit&id=" . $_POST["snmp_query_id"]);
		}
	}
}
Beispiel #26
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_replace("host_template_graph",array("host_template_id"=>$host_template_id,"graph_template_id"=>$_POST["graph_template_id"]),array("host_template_id","graph_template_id"),true);
					$redirect_back = true;
				}elseif (isset($_POST["add_dq_x"])) {
					db_replace("host_template_snmp_query",array("host_template_id"=>$host_template_id,"snmp_query_id"=>$_POST["snmp_query_id"]),array("host_template_id","snmp_query_id"),true);
					$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");
		}
	}
}
        } else {
            SmartyValidate::connect($tpl);
            $data = get_table_data('user_permission');
            $data['USER_ID'] = $u;
            if (SmartyValidate::is_valid($data, 'conf_user_permissions')) {
                // Check if category is parent to existing categories.
                $child_categories = find_child_categories();
                if ($child_categories > 0) {
                    $tpl->assign('CHILD_CATEGORIES', $child_categories);
                    $tpl->assign('WARN', true);
                    $category = $db->GetOne("SELECT `TITLE` FROM `{$tables['category']['name']}` WHERE `ID` = " . $db->qstr($data['CATEGORY_ID']));
                    $tpl->assign('CATEGORY', $category);
                } else {
                    $id = $db->GenID($tables['user_permission']['name'] . '_SEQ');
                    $data['ID'] = $id;
                    if (db_replace('user_permission', $data, 'ID') > 0) {
                        $tpl->assign('posted', 'Permission granted.');
                    } else {
                        $tpl->assign('sql_error', $db->ErrorMsg());
                    }
                }
            }
            $tpl->assign('CATEGORY_ID', $data['CATEGORY_ID']);
        }
}
if ($_SESSION['is_admin']) {
    $list_total = $db->GetOne("SELECT COUNT(*) FROM `{$tables['user_permission']['name']}` {$where}");
    $page = get_page($list_total);
    $tpl->assign('list_limit', LINKS_PER_PAGE);
    $tpl->assign('list_total', $list_total);
    $sql = "SELECT U.*, " . $db->IfNull('C.TITLE', "'Top'") . " AS CATEGORY FROM `{$tables['user_permission']['name']}` AS U LEFT OUTER JOIN `{$tables['category']['name']}` AS C ON U.CATEGORY_ID = C.ID {$where} {$orderBy}";
Beispiel #28
0
function form_save() {
	if ((!empty($_POST["add_dq_y"])) && (!empty($_POST["snmp_query_id"]))) {
		/* ================= input validation ================= */
		input_validate_input_number(get_request_var_post("id"));
		input_validate_input_number(get_request_var_post("snmp_query_id"));
		input_validate_input_number(get_request_var_post("reindex_method"));
		/* ==================================================== */

		db_replace("host_snmp_query",array("host_id"=>$_POST["id"],"snmp_query_id"=>$_POST["snmp_query_id"],"reindex_method"=>$_POST["reindex_method"]),array("host_id","snmp_query_id"),true);

		/* recache snmp data */
		run_data_query($_POST["id"], $_POST["snmp_query_id"]);

		header("Location: host.php?action=edit&id=" . $_POST["id"]);
		exit;
	}

	if ((!empty($_POST["add_gt_y"])) && (!empty($_POST["graph_template_id"]))) {
		/* ================= input validation ================= */
		input_validate_input_number(get_request_var_post("id"));
		input_validate_input_number(get_request_var_post("graph_template_id"));
		/* ==================================================== */

		db_replace("host_graph",array("host_id"=>$_POST["id"],"graph_template_id"=>$_POST["graph_template_id"]),array("host_id","graph_template_id"),true);

		header("Location: host.php?action=edit&id=" . $_POST["id"]);
		exit;
	}

	if ((isset($_POST["save_component_host"])) && (empty($_POST["add_dq_y"]))) {
		if ($_POST["snmp_password"] != $_POST["snmp_password_confirm"]) {
			raise_message(4);
		}else{
			$host_id = api_device_save($_POST["id"], $_POST["host_template_id"], $_POST["description"],
				$_POST["hostname"], $_POST["snmp_community"], $_POST["snmp_version"],
				$_POST["snmp_username"], $_POST["snmp_password"],
				$_POST["snmp_port"], $_POST["snmp_timeout"],
				(isset($_POST["disabled"]) ? $_POST["disabled"] : ""),
				$_POST["availability_method"], $_POST["ping_method"],
				$_POST["ping_port"], $_POST["ping_timeout"],
				$_POST["ping_retries"], $_POST["notes"],
				$_POST["snmp_auth_protocol"], $_POST["snmp_priv_passphrase"],
				$_POST["snmp_priv_protocol"], $_POST["snmp_context"]);
		}

		if ((is_error_message()) || ($_POST["host_template_id"] != $_POST["_host_template_id"])) {
			header("Location: host.php?action=edit&id=" . (empty($host_id) ? $_POST["id"] : $host_id));
		}else{
			header("Location: host.php");
		}
	}
}
Beispiel #29
0
function push_out_host($host_id, $local_data_id = 0, $data_template_id = 0) {
	/* ok here's the deal: first we need to find every data source that uses this host.
	then we go through each of those data sources, finding each one using a data input method
	with "special fields". if we find one, fill it will the data here from this host */

	if (!empty($data_template_id)) {
		/* OK: group by */
		$hosts = db_fetch_assoc("select host_id from data_local where data_template_id=$data_template_id group by host_id");

		if (sizeof($hosts) > 0) {
		foreach ($hosts as $host) {
			push_out_host($host["host_id"]);
		}
		}
	}

	if (empty($host_id)) { return 0; }

	/* get all information about this host so we can write it to the data source */
	$host = db_fetch_row("select * from host where id=$host_id");

	$data_sources = db_fetch_assoc("select
		data_template_data.id,
		data_template_data.data_input_id,
		data_template_data.local_data_id,
		data_template_data.local_data_template_data_id
		from data_local, data_template_data
		where " . (empty($local_data_id) ? "data_local.host_id=$host_id" : "data_local.id=$local_data_id") . "
		and data_local.id=data_template_data.local_data_id
		and data_template_data.data_input_id>0");

	/* loop through each matching data source */
	if (sizeof($data_sources) > 0) {
	foreach ($data_sources as $data_source) {
		/* get field information from the data template */
		if (!isset($template_fields{$data_source["local_data_template_data_id"]})) {
			$template_fields{$data_source["local_data_template_data_id"]} = db_fetch_assoc("select
				data_input_data.value,
				data_input_data.t_value,
				data_input_fields.id,
				data_input_fields.type_code
				from data_input_fields left join data_input_data
				on (data_input_fields.id=data_input_data.data_input_field_id and data_input_data.data_template_data_id=" . $data_source["local_data_template_data_id"] . ")
				where data_input_fields.data_input_id=" . $data_source["data_input_id"] . "
				and (data_input_data.t_value='' or data_input_data.t_value is null)
				and data_input_fields.input_output='in'");
		}

		reset($template_fields{$data_source["local_data_template_data_id"]});

		/* loop through each field contained in the data template and push out a host value if:
		 - the field is a valid "host field"
		 - the value of the field is empty
		 - the field is set to 'templated' */
		if (sizeof($template_fields{$data_source["local_data_template_data_id"]})) {
		foreach ($template_fields{$data_source["local_data_template_data_id"]} as $template_field) {
			if ((eregi('^' . VALID_HOST_FIELDS . '$', $template_field["type_code"])) && ($template_field["value"] == "") && ($template_field["t_value"] == "")) {
				db_replace("data_input_data",array("data_input_field_id"=>$template_field["id"],"data_template_data_id"=>$data_source["id"],"value"=>$host{$template_field["type_code"]}),array("data_input_field_id","data_template_data_id"),true);
			}
		}
		}

		/* make sure to update the poller cache as well */
		update_poller_cache($data_source["local_data_id"], false);
	}
	}
}
Beispiel #30
0
function syslog_db_replace($table_name, $array_items, $keyCols)
{
    global $syslog_cnn, $cnn_id;
    /* use cacti function if using Cacti db */
    if ($syslog_cnn == $cnn_id) {
        return db_replace($table_name, $array_items, $keyCols);
    }
    $syslog_cnn->Replace($table_name, $array_items, $keyCols);
    return $syslog_cnn->Insert_ID();
}