Beispiel #1
0
function update_poller_cache_from_query($host_id, $data_query_id) {
	require_once(CACTI_BASE_PATH . "/include/data_source/data_source_constants.php");

	$data_sources = db_fetch_assoc("select
		data_source.id
		from data_source,data_source_field
		where data_source.id=data_source_field.data_source_id
		and data_source.data_input_type = " . DATA_INPUT_TYPE_DATA_QUERY . "
		and data_source_field.name = 'data_query_id'");

	if (sizeof($data_sources) > 0) {
		foreach ($data_sources as $data_source) {
			update_poller_cache($data_source["id"]);
		}
	}
}
Beispiel #2
0
function push_out_device($device_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 device.
	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 device */
	/* setup the poller items array */
	$poller_items   = array();
	$local_data_ids = array();
	$devices          = array();
	$sql_where      = "";

	/* setup the sql where, and if using a device, get it's device information */
	if ($device_id != 0) {
		/* get all information about this device so we can write it to the data source */
		$devices[$device_id] = db_fetch_row("select * from device where id=$device_id");

		$sql_where .= " AND data_local.device_id=$device_id";
	}

	/* sql where fom local_data_id */
	if ($local_data_id != 0) {
		$sql_where .= " AND data_local.id=$local_data_id";
	}

	/* sql where fom data_template_id */
	if ($data_template_id != 0) {
		$sql_where .= " AND data_template_data.data_template_id=$data_template_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,
		data_local.device_id
		FROM (data_local, data_template_data)
		WHERE data_local.id=data_template_data.local_data_id
		AND data_template_data.data_input_id>0
		$sql_where");

	/* loop through each matching data source */
	if (sizeof($data_sources) > 0) {
	foreach ($data_sources as $data_source) {
		/* set the device information */
		if (!isset($devices[$data_source["device_id"]])) {
			$devices[$data_source["device_id"]] = db_fetch_row("select * from device where id=" . $data_source["device_id"]);
		}
		$device = $devices[$data_source["device_id"]];

		/* 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 device value if:
		 - the field is a valid "device 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 ((preg_match('/^' . VALID_HOST_FIELDS . '$/i', $template_field["type_code"])) && ($template_field["value"] == "") && ($template_field["t_value"] == "")) {
				db_execute("replace into data_input_data (data_input_field_id,data_template_data_id,value) values (" . $template_field["id"] . "," . $data_source["id"] . ",'" . $device{$template_field["type_code"]} . "')");
			}
		}
		}

		/* flag an update to the poller cache as well */
		$local_data_ids[] = $data_source["local_data_id"];
		$poller_items     = array_merge($poller_items, update_poller_cache($data_source["local_data_id"]));
	}
	}

	if (sizeof($local_data_ids)) {
		poller_update_poller_cache_from_buffer($local_data_ids, $poller_items);
	}
}
Beispiel #3
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)) {
		$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_execute("replace into data_input_data (data_input_field_id,data_template_data_id,value) values (" . $template_field["id"] . "," . $data_source["id"] . ",'" . $host{$template_field["type_code"]} . "')");
				}
			}
		}

		/* make sure to update the poller cache as well */
		update_poller_cache($data_source["local_data_id"], false);
	}
	}
}
Beispiel #4
0
function api_data_source_enable($local_data_id)
{
    db_execute("UPDATE data_template_data SET active='on' WHERE local_data_id={$local_data_id}");
    update_poller_cache($local_data_id, false);
}
Beispiel #5
0
$current_ds = 1;
$total_ds = sizeof($poller_data);
/* setting local_data_ids to an empty array saves time during updates */
$local_data_ids = array();
$poller_items = array();
/* issue warnings and start message if applicable */
print "WARNING: Do not interrupt this script.  Rebuilding the Poller Cache can take quite some time\n";
debug("There are '" . sizeof($poller_data) . "' data source elements to update.");
/* start rebuilding the poller cache */
if (sizeof($poller_data) > 0) {
    foreach ($poller_data as $data) {
        if (!$debug) {
            print ".";
        }
        $local_data_ids[] = $data["id"];
        $poller_items = array_merge($poller_items, update_poller_cache($data["id"]));
        debug("Data Source Item '{$current_ds}' of '{$total_ds}' updated");
        $current_ds++;
    }
    if (sizeof($local_data_ids)) {
        poller_update_poller_cache_from_buffer($local_data_ids, $poller_items);
    }
}
if (!$debug) {
    print "\n";
}
/* poller cache rebuilt, restore runtime parameters */
ini_set("max_execution_time", $max_execution);
/*	display_help - displays the usage of the function */
function display_help()
{
Beispiel #6
0
function update_host_disabled($host_id, $disabled)
{
    db_execute("UPDATE host SET disabled = '{$disabled}' WHERE id = '{$host_id}'");
    /* update poller cache */
    if ($disabled === "") {
        $data_sources = db_fetch_assoc("SELECT id FROM data_local WHERE host_id = '{$host_id}'");
        $poller_items = array();
        include dirname(__FILE__) . "/include/global.php";
        include_once $config["base_path"] . "/lib/utility.php";
        if (sizeof($data_sources) > 0) {
            foreach ($data_sources as $data_source) {
                $local_data_ids[] = $data_source["id"];
                $poller_items = array_merge($poller_items, update_poller_cache($data_source["id"]));
            }
        }
        poller_update_poller_cache_from_buffer($local_data_ids, $poller_items);
    } else {
        db_execute("DELETE FROM poller_item WHERE host_id = '{$host_id}'");
        db_execute("DELETE FROM poller_reindex WHERE host_id = '{$host_id}'");
    }
}
/* get the data_local Id's for the poller cache */
$poller_data = db_fetch_assoc("select id from data_local");

/* initialize some variables */
$current_ds = 1;
$total_ds = sizeof($poller_data);

/* issue warnings and start message if applicable */
print "WARNING: Do not interrupt this script.  Rebuilding the Poller Cache can take quite some time\n";
debug("There are '" . sizeof($poller_data) . "' data source elements to update.");

/* start rebuilding the poller cache */
if (sizeof($poller_data) > 0) {
	foreach ($poller_data as $data) {
		if (!$debug) print ".";
		update_poller_cache($data["id"], true);
		debug("Data Source Item '$current_ds' of '$total_ds' updated");
		$current_ds++;
	}
}

/* poller cache rebuilt, restore runtime parameters */
ini_set("max_execution_time", $max_execution);
ini_set("memory_limit", $max_memory);

/*	display_help - displays the usage of the function */
function display_help () {
	print "Cacti Rebuild Poller Cache Script 1.0, Copyright 2005 - The Cacti Group\n\n";
	print "usage: rebuild_poller_cache.php [-d] [-h] [--help] [-v] [--version]\n\n";
	print "-d            - Display verbose output during execution\n";
	print "-v --version  - Display this help message\n";
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\n\t\t\tdata_template_data.data_input_id,\n\t\t\tdata_local.host_id,\n\t\t\tdata_input_fields.id,\n\t\t\tdata_input_fields.input_output,\n\t\t\tdata_input_fields.data_name,\n\t\t\tdata_input_fields.regexp_match,\n\t\t\tdata_input_fields.allow_nulls,\n\t\t\tdata_input_fields.type_code\n\t\t\tfrom data_template_data\n\t\t\tleft join data_input_fields on (data_input_fields.data_input_id=data_template_data.data_input_id)\n\t\t\tleft join data_local on (data_template_data.local_data_id=data_local.id)\n\t\t\twhere data_template_data.id=" . $_POST["data_template_data_id"] . "\n\t\t\tand 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_execute("replace into data_input_data (data_input_field_id,data_template_data_id,t_value,value) values\n\t\t\t\t\t\t(" . $input_field["id"] . "," . $_POST["data_template_data_id"] . ",'','{$form_value}')");
                    }
                }
            }
        }
    }
    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)\n\t\t\t\t\t\tvalues (" . $_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 #9
0
function form_actions()
{
    global $colors, $device_actions, $fields_host_edit;
    /* if we are to save this form, instead of display it */
    if (isset($_POST["selected_items"])) {
        $selected_items = unserialize(stripslashes($_POST["selected_items"]));
        if ($_POST["drp_action"] == "2") {
            /* Enable Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                db_execute("update host set disabled='' where id='" . $selected_items[$i] . "'");
                /* update poller cache */
                $data_sources = db_fetch_assoc("select id from data_local where host_id='" . $selected_items[$i] . "'");
                if (sizeof($data_sources) > 0) {
                    foreach ($data_sources as $data_source) {
                        update_poller_cache($data_source["id"], false);
                    }
                }
            }
        } elseif ($_POST["drp_action"] == "3") {
            /* Disable Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                db_execute("update host set disabled='on' where id='" . $selected_items[$i] . "'");
                /* update poller cache */
                db_execute("delete from poller_item where host_id='" . $selected_items[$i] . "'");
                db_execute("delete from poller_reindex where host_id='" . $selected_items[$i] . "'");
            }
        } elseif ($_POST["drp_action"] == "4") {
            /* change snmp options */
            for ($i = 0; $i < count($selected_items); $i++) {
                reset($fields_host_edit);
                while (list($field_name, $field_array) = each($fields_host_edit)) {
                    if (isset($_POST["t_{$field_name}"])) {
                        db_execute("update host set {$field_name} = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'");
                    }
                }
                push_out_host($selected_items[$i]);
            }
        } elseif ($_POST["drp_action"] == "6") {
            /* change poller */
            for ($i = 0; $i < count($selected_items); $i++) {
                reset($fields_host_edit);
                while (list($field_name, $field_array) = each($fields_host_edit)) {
                    if (isset($_POST["t_{$field_name}"])) {
                        db_execute("update host set {$field_name} = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'");
                    }
                }
                push_out_host($selected_items[$i]);
            }
        } elseif ($_POST["drp_action"] == "7") {
            /* change availability options */
            for ($i = 0; $i < count($selected_items); $i++) {
                reset($fields_host_edit);
                while (list($field_name, $field_array) = each($fields_host_edit)) {
                    if (isset($_POST["t_{$field_name}"])) {
                        db_execute("update host set {$field_name} = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'");
                    }
                }
                push_out_host($selected_items[$i]);
            }
        } elseif ($_POST["drp_action"] == "5") {
            /* Clear Statisitics for Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                db_execute("update host set min_time = '9.99999', max_time = '0', cur_time = '0',\tavg_time = '0',\n\t\t\t\t\t\ttotal_polls = '0', failed_polls = '0',\tavailability = '100.00'\n\t\t\t\t\t\twhere id = '" . $selected_items[$i] . "'");
            }
        } elseif ($_POST["drp_action"] == "1") {
            /* delete */
            for ($i = 0; $i < count($selected_items); $i++) {
                if (!isset($_POST["delete_type"])) {
                    $_POST["delete_type"] = 2;
                }
                switch ($_POST["delete_type"]) {
                    case '1':
                        /* leave graphs and data_sources in place, but disable the data sources */
                        $data_sources = db_fetch_assoc("select id from data_source where " . array_to_sql_or($selected_items, "host_id"));
                        if (sizeof($data_sources) > 0) {
                            foreach ($data_sources as $data_source) {
                                api_data_source_disable($data_source["id"]);
                            }
                        }
                        break;
                    case '2':
                        /* delete graphs/data sources tied to this device */
                        $data_sources = db_fetch_assoc("select id from data_source where " . array_to_sql_or($selected_items, "host_id"));
                        if (sizeof($data_sources) > 0) {
                            foreach ($data_sources as $data_source) {
                                api_data_source_remove($data_source["id"]);
                            }
                        }
                        $graphs = db_fetch_assoc("select id from graph where " . array_to_sql_or($selected_items, "host_id"));
                        if (sizeof($graphs) > 0) {
                            foreach ($graphs as $graph) {
                                api_graph_remove($graph["id"]);
                            }
                        }
                        break;
                }
                api_device_remove($selected_items[$i]);
            }
        }
        header("Location: devices.php");
        exit;
    }
    /* setup some variables */
    $host_list = "";
    $i = 0;
    /* loop through each of the host templates selected on the previous page and get more info about them */
    while (list($var, $val) = each($_POST)) {
        if (ereg("^chk_([0-9]+)\$", $var, $matches)) {
            $host_list .= "<li>" . db_fetch_cell("select description from host where id=" . $matches[1]) . "<br>";
            $host_array[$i] = $matches[1];
        }
        $i++;
    }
    require_once CACTI_BASE_PATH . "/include/top_header.php";
    html_start_box("<strong>" . $device_actions[$_POST["drp_action"]] . "</strong>", "60%", $colors["header_panel_background"], "3", "center", "");
    print "<form action='devices.php' method='post'>\n";
    if ($_POST["drp_action"] == "2") {
        /* Enable Devices */
        print "\t<tr>\n\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>" . _("To enable the following devices, press the \"yes\" button below.") . "</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t</td>\n\t\t\t\t</tr>";
    } elseif ($_POST["drp_action"] == "3") {
        /* Disable Devices */
        print "\t<tr>\n\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>" . _("To disable the following devices, press the \"yes\" button below.") . "</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t</td>\n\t\t\t\t</tr>";
    } elseif ($_POST["drp_action"] == "4") {
        /* change snmp options */
        print "\t<tr>\n\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>" . _("To change SNMP parameters for the following devices, check the box next to the fields\n\t\t\t\t\tyou want to update, fill in the new value, and click Save.") . "</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t</td>\n\t\t\t\t</tr>";
        $form_array = array();
        while (list($field_name, $field_array) = each($fields_host_edit)) {
            if (ereg("^snmp_", $field_name) || ereg("^snmpv3_", $field_name)) {
                $form_array += array($field_name => $fields_host_edit[$field_name]);
                $form_array[$field_name]["value"] = "";
                $form_array[$field_name]["description"] = "";
                $form_array[$field_name]["form_id"] = 0;
                $form_array[$field_name]["sub_checkbox"] = array("name" => "t_" . $field_name, "friendly_name" => _("Update this Field"), "value" => "");
            }
        }
        draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => $form_array));
    } elseif ($_POST["drp_action"] == "6") {
        /* change poller */
        print "\t<tr>\n\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>" . _("To change the poller that will, by default handle the processing for the selected host(s)\n\t\t\t\t\tsimply select the host from the list, toggle the checkbox and select yes.") . "</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t</td>\n\t\t\t\t</tr>";
        $form_array = array();
        while (list($field_name, $field_array) = each($fields_host_edit)) {
            if (ereg("^poller_", $field_name)) {
                $form_array += array($field_name => $fields_host_edit[$field_name]);
                $form_array[$field_name]["value"] = "";
                $form_array[$field_name]["description"] = "";
                $form_array[$field_name]["form_id"] = 0;
                $form_array[$field_name]["sub_checkbox"] = array("name" => "t_" . $field_name, "friendly_name" => _("Update this Field"), "value" => "");
            }
        }
        draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => $form_array));
    } elseif ($_POST["drp_action"] == "7") {
        /* change availability options */
        print "\t<tr>\n\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>" . _("To change the availability detection for your hosts will use by default\n\t\t\t\t\tsimply select the host from the list, make the changes you require and select yes.") . "</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t</td>\n\t\t\t\t</tr>";
        $form_array = array();
        while (list($field_name, $field_array) = each($fields_host_edit)) {
            if (ereg("^availability_", $field_name) || ereg("^ping_", $field_name)) {
                $form_array += array($field_name => $fields_host_edit[$field_name]);
                $form_array[$field_name]["value"] = "";
                $form_array[$field_name]["description"] = "";
                $form_array[$field_name]["form_id"] = 0;
                $form_array[$field_name]["sub_checkbox"] = array("name" => "t_" . $field_name, "friendly_name" => _("Update this Field"), "value" => "");
            }
        }
        draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => $form_array));
    } elseif ($_POST["drp_action"] == "5") {
        /* Clear Statisitics for Selected Devices */
        print "\t<tr>\n\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>" . _("To clear the counters for the following devices, press the \"yes\" button below.") . "</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t</td>\n\t\t\t\t</tr>";
    } elseif ($_POST["drp_action"] == "1") {
        /* delete */
        print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>" . _("Are you sure you want to delete the following devices?") . "</p>\n\t\t\t\t\t<p>{$host_list}</p>";
        form_radio_button("delete_type", "2", "1", _("Leave all graphs and data sources untouched.  Data sources will be disabled however."), "1");
        print "<br>";
        form_radio_button("delete_type", "2", "2", _("Delete all associated <strong>graphs</strong> and <strong>data sources</strong>."), "1");
        print "<br>";
        print "</td></tr>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t";
    }
    if (!isset($host_array)) {
        print "<tr><td bgcolor='#" . $colors["form_alternate1"] . "'><span class='textError'>" . _("You must select at least one device.") . "</span></td></tr>\n";
        $save_html = "";
    } else {
        $save_html = "<input type='image' src='" . html_get_theme_images_path("button_yes.gif") . "' alt='" . _("Save") . "' align='absmiddle'>";
    }
    print "\t<tr>\n\t\t\t<td colspan='2' align='right' bgcolor='#" . $colors["buttonbar_background"] . "'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($host_array) ? serialize($host_array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST["drp_action"] . "'>\n\t\t\t\t<a href='devices.php'><img src='" . html_get_theme_images_path("button_no.gif") . "' alt='" . _("Cancel") . "' align='absmiddle' border='0'></a>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n\t\t";
    html_end_box();
    require_once CACTI_BASE_PATH . "/include/bottom_footer.php";
}
Beispiel #10
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_prepared("SELECT\n\t\t\tdata_template_data.data_input_id,\n\t\t\tdata_local.host_id,\n\t\t\tdata_input_fields.id,\n\t\t\tdata_input_fields.input_output,\n\t\t\tdata_input_fields.data_name,\n\t\t\tdata_input_fields.regexp_match,\n\t\t\tdata_input_fields.allow_nulls,\n\t\t\tdata_input_fields.type_code\n\t\t\tFROM data_template_data\n\t\t\tLEFT JOIN data_input_fields ON (data_input_fields.data_input_id = data_template_data.data_input_id)\n\t\t\tLEFT JOIN data_local ON (data_template_data.local_data_id = data_local.id)\n\t\t\tWHERE data_template_data.id = ?\n\t\t\tAND data_input_fields.input_output='in'", array($_POST['data_template_data_id']));
        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_prepared('SELECT local_data_template_data_id FROM data_template_data WHERE id = ?', array($_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_execute_prepared("REPLACE INTO data_input_data (data_input_field_id, data_template_data_id, t_value, value) VALUES (?, ?, '', ?)", array($input_field['id'], $_POST['data_template_data_id'], $form_value));
                    }
                }
            }
        }
    }
    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_prepared('SELECT id FROM data_template_rrd WHERE local_data_id = ?', array($_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_prepared('SELECT local_data_template_rrd_id FROM data_template_rrd WHERE id = ?', array($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]+(\\.[0-9]*)?|[0-9]*\\.[0-9]+)([eE][+\\-]?[0-9]+)?)|U\$", false, 3);
                        $save3['rrd_minimum'] = form_input_validate($_POST["rrd_minimum{$name_modifier}"], "rrd_minimum{$name_modifier}", "^(-?([0-9]+(\\.[0-9]*)?|[0-9]*\\.[0-9]+)([eE][+\\-]?[0-9]+)?)|U\$", 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_prepared('DELETE FROM data_template_data_rra WHERE data_template_data_id = ?', array($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_prepared('INSERT INTO data_template_data_rra (rra_id, data_template_data_id)
						VALUES (?, ?)', array($_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, true);
    }
    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 #11
0
function api_data_source_enable($data_source_id) {
	/* sanity checks */
	validate_id_die($data_source_id, "data_source_id");

	db_execute("UPDATE data_source SET active = 1 WHERE id = " . sql_sanitize($data_source_id));
	update_poller_cache($data_source_id, false);
}
Beispiel #12
0
/** for a given data template, update all input data and the poller cache
 * @param int $host_id - id of host, if any
 * @param int $local_data_id - id of a single data source, if any
 * @param int $data_template_id - id of data template
 * works on table data_input_data and poller cache
 */
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 */
    /* setup the poller items array */
    $poller_items = array();
    $local_data_ids = array();
    $hosts = array();
    $sql_where = "";
    /* setup the sql where, and if using a host, get it's host information */
    if ($host_id != 0) {
        /* get all information about this host so we can write it to the data source */
        $hosts[$host_id] = db_fetch_row("SELECT id AS host_id, host.* FROM host WHERE id={$host_id}");
        $sql_where .= " AND data_local.host_id={$host_id}";
    }
    /* sql WHERE for local_data_id */
    if ($local_data_id != 0) {
        $sql_where .= " AND data_local.id={$local_data_id}";
    }
    /* sql WHERE for data_template_id */
    if ($data_template_id != 0) {
        $sql_where .= " AND data_template_data.data_template_id={$data_template_id}";
    }
    $data_sources = db_fetch_assoc("SELECT\n\t\tdata_template_data.id,\n\t\tdata_template_data.data_input_id,\n\t\tdata_template_data.local_data_id,\n\t\tdata_template_data.local_data_template_data_id,\n\t\tdata_local.host_id\n\t\tFROM (data_local, data_template_data)\n\t\tWHERE data_local.id=data_template_data.local_data_id\n\t\tAND data_template_data.data_input_id>0\n\t\t{$sql_where}");
    /* loop through each matching data source */
    if (sizeof($data_sources) > 0) {
        foreach ($data_sources as $data_source) {
            /* set the host information */
            if (!isset($hosts[$data_source["host_id"]])) {
                $hosts[$data_source["host_id"]] = db_fetch_row("SELECT * FROM host WHERE id=" . $data_source["host_id"]);
            }
            $host = $hosts[$data_source["host_id"]];
            /* 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\n\t\t\t\tdata_input_data.value,\n\t\t\t\tdata_input_data.t_value,\n\t\t\t\tdata_input_fields.id,\n\t\t\t\tdata_input_fields.type_code\n                FROM data_input_fields \n                LEFT JOIN data_input_data\n\t\t\t\tON (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"] . ")\n\t\t\t\tWHERE data_input_fields.data_input_id=" . $data_source["data_input_id"] . "\n\t\t\t\tAND (data_input_data.t_value='' OR data_input_data.t_value is null)\n\t\t\t\tAND 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 (preg_match('/^' . VALID_HOST_FIELDS . '$/i', $template_field["type_code"]) && $template_field["value"] == "" && $template_field["t_value"] == "") {
                        db_execute_prepared('REPLACE INTO data_input_data (data_input_field_id, data_template_data_id, value) VALUES (?, ?, ?)', array($template_field['id'], $data_source['id'], $host[$template_field['type_code']]));
                    }
                }
            }
            /* flag an update to the poller cache as well */
            $local_data_ids[] = $data_source["local_data_id"];
            $poller_items = array_merge($poller_items, update_poller_cache($data_source["local_data_id"]));
        }
    }
    if (sizeof($local_data_ids)) {
        poller_update_poller_cache_from_buffer($local_data_ids, $poller_items);
    }
}
Beispiel #13
0
function api_device_enable($device_id) {
	require_once(CACTI_BASE_PATH . "/lib/data_source/data_source_info.php");

	db_update("host",
		array(
			"disabled" => array("type" => DB_TYPE_STRING, "value" => ""),
			"id" => array("type" => DB_TYPE_INTEGER, "value" => $device_id)
			),
		array("id"));

	/* obtain a list of all data sources associated with this device */
	$data_sources = api_data_source_list(array("host_id" => $device_id));

	if (sizeof($data_sources) > 0) {
		foreach ($data_sources as $data_source) {
			update_poller_cache($data_source["id"], false);
		}
	}
}
Beispiel #14
0
function form_actions()
{
    global $colors, $device_actions, $fields_host_edit;
    /* if we are to save this form, instead of display it */
    if (isset($_POST["selected_items"])) {
        $selected_items = unserialize(stripslashes($_POST["selected_items"]));
        if ($_POST["drp_action"] == "2") {
            /* Enable Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute("update host set disabled='' where id='" . $selected_items[$i] . "'");
                /* update poller cache */
                $data_sources = db_fetch_assoc("select id from data_local where host_id='" . $selected_items[$i] . "'");
                if (sizeof($data_sources) > 0) {
                    foreach ($data_sources as $data_source) {
                        update_poller_cache($data_source["id"], false);
                    }
                }
            }
        } elseif ($_POST["drp_action"] == "3") {
            /* Disable Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute("update host set disabled='on' where id='" . $selected_items[$i] . "'");
                /* update poller cache */
                db_execute("delete from poller_item where host_id='" . $selected_items[$i] . "'");
                db_execute("delete from poller_reindex where host_id='" . $selected_items[$i] . "'");
            }
        } elseif ($_POST["drp_action"] == "4") {
            /* change snmp options */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                reset($fields_host_edit);
                while (list($field_name, $field_array) = each($fields_host_edit)) {
                    if (isset($_POST["t_{$field_name}"])) {
                        db_execute("update host set {$field_name} = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'");
                    }
                }
                push_out_host($selected_items[$i]);
            }
        } elseif ($_POST["drp_action"] == "5") {
            /* Clear Statisitics for Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute("update host set min_time = '9.99999', max_time = '0', cur_time = '0',\tavg_time = '0',\n\t\t\t\t\t\ttotal_polls = '0', failed_polls = '0',\tavailability = '100.00'\n\t\t\t\t\t\twhere id = '" . $selected_items[$i] . "'");
            }
        } elseif ($_POST["drp_action"] == "6") {
            /* change availability options */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                reset($fields_host_edit);
                while (list($field_name, $field_array) = each($fields_host_edit)) {
                    if (isset($_POST["t_{$field_name}"])) {
                        db_execute("update host set {$field_name} = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'");
                    }
                }
                push_out_host($selected_items[$i]);
            }
        } elseif ($_POST["drp_action"] == "1") {
            /* delete */
            if (!isset($_POST["delete_type"])) {
                $_POST["delete_type"] = 2;
            }
            $data_sources_to_act_on = array();
            $graphs_to_act_on = array();
            $devices_to_act_on = array();
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                $data_sources = db_fetch_assoc("select\n\t\t\t\t\tdata_local.id as local_data_id\n\t\t\t\t\tfrom data_local\n\t\t\t\t\twhere " . array_to_sql_or($selected_items, "data_local.host_id"));
                if (sizeof($data_sources) > 0) {
                    foreach ($data_sources as $data_source) {
                        $data_sources_to_act_on[] = $data_source["local_data_id"];
                    }
                }
                if ($_POST["delete_type"] == 2) {
                    $graphs = db_fetch_assoc("select\n\t\t\t\t\t\tgraph_local.id as local_graph_id\n\t\t\t\t\t\tfrom graph_local\n\t\t\t\t\t\twhere " . array_to_sql_or($selected_items, "graph_local.host_id"));
                    if (sizeof($graphs) > 0) {
                        foreach ($graphs as $graph) {
                            $graphs_to_act_on[] = $graph["local_graph_id"];
                        }
                    }
                }
                $devices_to_act_on[] = $selected_items[$i];
            }
            switch ($_POST["delete_type"]) {
                case '1':
                    /* leave graphs and data_sources in place, but disable the data sources */
                    api_data_source_disable_multi($data_sources_to_act_on);
                    break;
                case '2':
                    /* delete graphs/data sources tied to this device */
                    api_data_source_remove_multi($data_sources_to_act_on);
                    api_graph_remove_multi($graphs_to_act_on);
                    break;
            }
            api_device_remove_multi($devices_to_act_on);
        } elseif (ereg("^tr_([0-9]+)\$", $_POST["drp_action"], $matches)) {
            /* place on tree */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                input_validate_input_number(get_request_var_post("tree_id"));
                input_validate_input_number(get_request_var_post("tree_item_id"));
                /* ==================================================== */
                api_tree_item_save(0, $_POST["tree_id"], TREE_ITEM_TYPE_HOST, $_POST["tree_item_id"], "", 0, read_graph_config_option("default_rra_id"), $selected_items[$i], 1, 1, false);
            }
        }
        header("Location: host.php");
        exit;
    }
    /* setup some variables */
    $host_list = "";
    $i = 0;
    /* loop through each of the host templates selected on the previous page and get more info about them */
    while (list($var, $val) = each($_POST)) {
        if (ereg("^chk_([0-9]+)\$", $var, $matches)) {
            /* ================= input validation ================= */
            input_validate_input_number($matches[1]);
            /* ==================================================== */
            $host_list .= "<li>" . db_fetch_cell("select description from host where id=" . $matches[1]) . "<br>";
            $host_array[$i] = $matches[1];
        }
        $i++;
    }
    include_once "./include/top_header.php";
    /* add a list of tree names to the actions dropdown */
    add_tree_names_to_actions_array();
    html_start_box("<strong>" . $device_actions[$_POST["drp_action"]] . "</strong>", "60%", $colors["header_panel"], "3", "center", "");
    print "<form action='host.php' method='post'>\n";
    if ($_POST["drp_action"] == "2") {
        /* Enable Devices */
        print "\t<tr>\n\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>To enable the following devices, press the \"yes\" button below.</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t</td>\n\t\t\t\t</tr>";
    } elseif ($_POST["drp_action"] == "3") {
        /* Disable Devices */
        print "\t<tr>\n\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>To disable the following devices, press the \"yes\" button below.</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t</td>\n\t\t\t\t</tr>";
    } elseif ($_POST["drp_action"] == "4") {
        /* change snmp options */
        print "\t<tr>\n\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>To change SNMP parameters for the following devices, check the box next to the fields\n\t\t\t\t\tyou want to update, fill in the new value, and click \"yes\".</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t</td>\n\t\t\t\t</tr>";
        $form_array = array();
        while (list($field_name, $field_array) = each($fields_host_edit)) {
            if (ereg("^snmp_", $field_name) || $field_name == "max_oids") {
                $form_array += array($field_name => $fields_host_edit[$field_name]);
                $form_array[$field_name]["value"] = "";
                $form_array[$field_name]["description"] = "";
                $form_array[$field_name]["form_id"] = 0;
                $form_array[$field_name]["sub_checkbox"] = array("name" => "t_" . $field_name, "friendly_name" => "Update this Field", "value" => "");
            }
        }
        draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => $form_array));
    } elseif ($_POST["drp_action"] == "6") {
        /* change availability options */
        print "\t<tr>\n\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>To change SNMP parameters for the following devices, check the box next to the fields\n\t\t\t\t\tyou want to update, fill in the new value, and click \"yes\".</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t</td>\n\t\t\t\t</tr>";
        $form_array = array();
        while (list($field_name, $field_array) = each($fields_host_edit)) {
            if (ereg("(availability_method|ping_method|ping_port)", $field_name)) {
                $form_array += array($field_name => $fields_host_edit[$field_name]);
                $form_array[$field_name]["value"] = "";
                $form_array[$field_name]["description"] = "";
                $form_array[$field_name]["form_id"] = 0;
                $form_array[$field_name]["sub_checkbox"] = array("name" => "t_" . $field_name, "friendly_name" => "Update this Field", "value" => "");
            }
        }
        draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => $form_array));
    } elseif ($_POST["drp_action"] == "5") {
        /* Clear Statisitics for Selected Devices */
        print "\t<tr>\n\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>To clear the counters for the following devices, press the \"yes\" button below.</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t</td>\n\t\t\t\t</tr>";
    } elseif ($_POST["drp_action"] == "1") {
        /* delete */
        print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>Are you sure you want to delete the following devices?</p>\n\t\t\t\t\t<p>{$host_list}</p>";
        form_radio_button("delete_type", "2", "1", "Leave all graphs and data sources untouched.  Data sources will be disabled however.", "1");
        print "<br>";
        form_radio_button("delete_type", "2", "2", "Delete all associated <strong>graphs</strong> and <strong>data sources</strong>.", "1");
        print "<br>";
        print "</td></tr>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t";
    } elseif (ereg("^tr_([0-9]+)\$", $_POST["drp_action"], $matches)) {
        /* place on tree */
        print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>When you click save, the following hosts will be placed under the branch selected\n\t\t\t\t\tbelow.</p>\n\t\t\t\t\t<p>{$host_list}</p>\n\t\t\t\t\t<p><strong>Destination Branch:</strong><br>";
        grow_dropdown_tree($matches[1], "tree_item_id", "0");
        print "</p>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t<input type='hidden' name='tree_id' value='" . $matches[1] . "'>\n\n\t\t\t";
    }
    if (!isset($host_array)) {
        print "<tr><td bgcolor='#" . $colors["form_alternate1"] . "'><span class='textError'>You must select at least one device.</span></td></tr>\n";
        $save_html = "";
    } else {
        $save_html = "<input type='image' src='images/button_yes.gif' alt='Save' align='absmiddle'>";
    }
    print "\t<tr>\n\t\t\t<td colspan='2' align='right' bgcolor='#eaeaea'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($host_array) ? serialize($host_array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST["drp_action"] . "'>\n\t\t\t\t<a href='host.php'><img src='images/button_no.gif' alt='Cancel' align='absmiddle' border='0'></a>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n\t\t";
    html_end_box();
    include_once "./include/bottom_footer.php";
}
Beispiel #15
0
function form_actions()
{
    /* modify for multi user start */
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        $rows = db_fetch_assoc("\r\n            SELECT host.id FROM host\r\n                INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'");
        foreach ($rows as $row) {
            $hosts[] = $row["id"];
        }
    }
    /* modify for multi user end */
    global $colors, $device_actions, $fields_host_edit;
    /* if we are to save this form, instead of display it */
    if (isset($_POST["selected_items"])) {
        $selected_items = unserialize(stripslashes($_POST["selected_items"]));
        /* modify for multi user start */
        if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
            for ($i = 0; $i < count($selected_items); $i++) {
                if (!in_array($selected_items[$i], $hosts)) {
                    access_denied();
                }
            }
        }
        /* modify for multi user end */
        if ($_POST["drp_action"] == "2") {
            /* Enable Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                /* modify for multi user start */
                if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
                    if (db_fetch_cell("SELECT id FROM host WHERE id = '" . $selected_items[$i] . "' AND disabled = 'ps'")) {
                        continue;
                    }
                }
                /* modify for multi user end */
                db_execute("update host set disabled='' where id='" . $selected_items[$i] . "'");
                /* update poller cache */
                $data_sources = db_fetch_assoc("select id from data_local where host_id='" . $selected_items[$i] . "'");
                $poller_items = array();
                if (sizeof($data_sources) > 0) {
                    foreach ($data_sources as $data_source) {
                        $local_data_ids[] = $data_source["id"];
                        $poller_items = array_merge($poller_items, update_poller_cache($data_source["id"]));
                    }
                }
                poller_update_poller_cache_from_buffer($local_data_ids, $poller_items);
            }
        } elseif ($_POST["drp_action"] == "3") {
            /* Disable Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                /* modify for multi user start */
                if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
                    if (db_fetch_cell("SELECT id FROM host WHERE id = '" . $selected_items[$i] . "' AND disabled = 'ps'")) {
                        continue;
                    }
                }
                /* modify for multi user end */
                db_execute("update host set disabled='on' where id='" . $selected_items[$i] . "'");
                /* update poller cache */
                db_execute("delete from poller_item where host_id='" . $selected_items[$i] . "'");
                db_execute("delete from poller_reindex where host_id='" . $selected_items[$i] . "'");
            }
        } elseif ($_POST["drp_action"] == "4") {
            /* change snmp options */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                reset($fields_host_edit);
                while (list($field_name, $field_array) = each($fields_host_edit)) {
                    if (isset($_POST["t_{$field_name}"])) {
                        db_execute("update host set {$field_name} = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'");
                    }
                }
                push_out_host($selected_items[$i]);
            }
        } elseif ($_POST["drp_action"] == "5") {
            /* Clear Statisitics for Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute("update host set min_time = '9.99999', max_time = '0', cur_time = '0',\tavg_time = '0',\r\n\t\t\t\t\t\ttotal_polls = '0', failed_polls = '0',\tavailability = '100.00'\r\n\t\t\t\t\t\twhere id = '" . $selected_items[$i] . "'");
            }
        } elseif ($_POST["drp_action"] == "6") {
            /* change availability options */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                reset($fields_host_edit);
                while (list($field_name, $field_array) = each($fields_host_edit)) {
                    if (isset($_POST["t_{$field_name}"])) {
                        db_execute("update host set {$field_name} = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'");
                    }
                }
                push_out_host($selected_items[$i]);
            }
        } elseif ($_POST["drp_action"] == "1") {
            /* delete */
            if (!isset($_POST["delete_type"])) {
                $_POST["delete_type"] = 2;
            }
            $data_sources_to_act_on = array();
            $graphs_to_act_on = array();
            $devices_to_act_on = array();
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                $data_sources = db_fetch_assoc("select\r\n\t\t\t\t\tdata_local.id as local_data_id\r\n\t\t\t\t\tfrom data_local\r\n\t\t\t\t\twhere " . array_to_sql_or($selected_items, "data_local.host_id"));
                if (sizeof($data_sources) > 0) {
                    foreach ($data_sources as $data_source) {
                        $data_sources_to_act_on[] = $data_source["local_data_id"];
                    }
                }
                if ($_POST["delete_type"] == 2) {
                    $graphs = db_fetch_assoc("select\r\n\t\t\t\t\t\tgraph_local.id as local_graph_id\r\n\t\t\t\t\t\tfrom graph_local\r\n\t\t\t\t\t\twhere " . array_to_sql_or($selected_items, "graph_local.host_id"));
                    if (sizeof($graphs) > 0) {
                        foreach ($graphs as $graph) {
                            $graphs_to_act_on[] = $graph["local_graph_id"];
                        }
                    }
                }
                $devices_to_act_on[] = $selected_items[$i];
            }
            switch ($_POST["delete_type"]) {
                case '1':
                    /* leave graphs and data_sources in place, but disable the data sources */
                    api_data_source_disable_multi($data_sources_to_act_on);
                    api_plugin_hook_function('data_source_remove', $data_sources_to_act_on);
                    break;
                case '2':
                    /* delete graphs/data sources tied to this device */
                    api_data_source_remove_multi($data_sources_to_act_on);
                    api_graph_remove_multi($graphs_to_act_on);
                    api_plugin_hook_function('graphs_remove', $graphs_to_act_on);
                    break;
            }
            api_device_remove_multi($devices_to_act_on);
            /* modify for multi user start */
            if ($_SESSION["permission"] <= ACCESS_ADMINISTRATOR) {
                foreach ($devices_to_act_on as $device_id) {
                    db_execute("DELETE FROM user_auth_perms WHERE type = 3 AND user_id = '" . $_SESSION["sess_user_id"] . "' AND item_id = '{$device_id}'");
                }
            }
            /* modify for multi user end */
            api_plugin_hook_function('device_remove', $devices_to_act_on);
        } elseif (preg_match("/^tr_([0-9]+)\$/", $_POST["drp_action"], $matches)) {
            /* place on tree */
            /* modify for multi user start */
            if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
                input_validate_input_number(get_request_var_post("tree_id"));
                if ($_POST["tree_id"] != $_SESSION["public_tree_id"]) {
                    access_denied();
                }
            }
            /* modify for multi user end */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                input_validate_input_number(get_request_var_post("tree_id"));
                input_validate_input_number(get_request_var_post("tree_item_id"));
                /* ==================================================== */
                api_tree_item_save(0, $_POST["tree_id"], TREE_ITEM_TYPE_HOST, $_POST["tree_item_id"], "", 0, read_graph_config_option("default_rra_id"), $selected_items[$i], 1, 1, false);
            }
            /* modify for multi user start */
            if (isset($_SESSION['dhtml_tree'])) {
                unset($_SESSION['dhtml_tree']);
            }
            /* modify for multi user end */
        } else {
            api_plugin_hook_function('device_action_execute', $_POST['drp_action']);
        }
        header("Location: host.php");
        exit;
    }
    /* setup some variables */
    $host_list = "";
    $i = 0;
    /* loop through each of the host templates selected on the previous page and get more info about them */
    while (list($var, $val) = each($_POST)) {
        if (preg_match("/^chk_([0-9]+)\$/", $var, $matches)) {
            /* ================= input validation ================= */
            input_validate_input_number($matches[1]);
            /* ==================================================== */
            /* modify for multi user start */
            if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
                if (!in_array($matches[1], $hosts)) {
                    access_denied();
                }
            }
            /* modify for multi user start */
            $host_list .= "<li>" . htmlspecialchars(db_fetch_cell("select description from host where id=" . $matches[1])) . "<br>";
            $host_array[$i] = $matches[1];
            $i++;
        }
    }
    include_once "./include/top_header.php";
    /* add a list of tree names to the actions dropdown */
    add_tree_names_to_actions_array();
    html_start_box("<strong>" . $device_actions[get_request_var_post("drp_action")] . "</strong>", "60%", $colors["header_panel"], "3", "center", "");
    print "<form action='host.php' autocomplete='off' method='post'>\n";
    if (isset($host_array) && sizeof($host_array)) {
        if ($_POST["drp_action"] == "2") {
            /* Enable Devices */
            print "\t<tr>\r\n\t\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>To enable the following Device(s), click \"Continue\".</p>\r\n\t\t\t\t\t\t<p><ul>" . $host_list . "</ul></p>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t\t</tr>";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Enable Device(s)'>";
        } elseif ($_POST["drp_action"] == "3") {
            /* Disable Devices */
            print "\t<tr>\r\n\t\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>To disable the following Device(s), click \"Continue\".</p>\r\n\t\t\t\t\t\t<p><ul>" . $host_list . "</ul></p>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t\t</tr>";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Disable Device(s)'>";
        } elseif ($_POST["drp_action"] == "4") {
            /* change snmp options */
            print "\t<tr>\r\n\t\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>To change SNMP parameters for the following Device(s), check the box next to the fields\r\n\t\t\t\t\t\tyou want to update, fill in the new value, and click \"Continue\".</p>\r\n\t\t\t\t\t\t<p><ul>" . $host_list . "</ul></p>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t\t</tr>";
            $form_array = array();
            while (list($field_name, $field_array) = each($fields_host_edit)) {
                if (preg_match("/^snmp_/", $field_name) || $field_name == "max_oids") {
                    $form_array += array($field_name => $fields_host_edit[$field_name]);
                    $form_array[$field_name]["value"] = "";
                    $form_array[$field_name]["description"] = "";
                    $form_array[$field_name]["form_id"] = 0;
                    $form_array[$field_name]["sub_checkbox"] = array("name" => "t_" . $field_name, "friendly_name" => "Update this Field", "value" => "");
                }
            }
            /* modify for multi user start */
            if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
                $form_array["snmp_timeout"]["method"] = "hidden";
                $form_array["max_oids"]["method"] = "hidden";
            }
            /* modify for multi user end */
            draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => $form_array));
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Change Device(s) SNMP Options'>";
        } elseif ($_POST["drp_action"] == "6") {
            /* change availability options */
            print "\t<tr>\r\n\t\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>To change Availability parameters for the following Device(s), check the box next to the fields\r\n\t\t\t\t\t\tyou want to update, fill in the new value, and click \"Continue\".</p>\r\n\t\t\t\t\t\t<p><ul>" . $host_list . "</ul></p>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t\t</tr>";
            $form_array = array();
            while (list($field_name, $field_array) = each($fields_host_edit)) {
                if (preg_match("/(availability_method|ping_method|ping_port)/", $field_name)) {
                    $form_array += array($field_name => $fields_host_edit[$field_name]);
                    $form_array[$field_name]["value"] = "";
                    $form_array[$field_name]["description"] = "";
                    $form_array[$field_name]["form_id"] = 0;
                    $form_array[$field_name]["sub_checkbox"] = array("name" => "t_" . $field_name, "friendly_name" => "Update this Field", "value" => "");
                }
            }
            draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => $form_array));
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Change Device(s) Availability Options'>";
        } elseif ($_POST["drp_action"] == "5") {
            /* Clear Statisitics for Selected Devices */
            print "\t<tr>\r\n\t\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>To clear the counters for the following Device(s), press the \"Continue\" button below.</p>\r\n\t\t\t\t\t\t<p><ul>" . $host_list . "</ul></p>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t\t</tr>";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Clear Statistics on Device(s)'>";
        } elseif ($_POST["drp_action"] == "1") {
            /* delete */
            print "\t<tr>\r\n\t\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>When you click \"Continue\" the following Device(s) will be deleted.</p>\r\n\t\t\t\t\t\t<p><ul>" . $host_list . "</ul></p>";
            /* modify for multi user start */
            if ($_SESSION["permission"] == ACCESS_ADMINISTRATOR) {
                form_radio_button("delete_type", "2", "1", "Leave all Graph(s) and Data Source(s) untouched.  Data Source(s) will be disabled however.", "1");
                print "<br>";
            }
            /* modify for multi user end */
            form_radio_button("delete_type", "2", "2", "Delete all associated <strong>Graph(s)</strong> and <strong>Data Source(s)</strong>.", "1");
            print "<br>";
            print "</td></tr>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t</tr>\n\r\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Delete Device(s)'>";
        } elseif (preg_match("/^tr_([0-9]+)\$/", $_POST["drp_action"], $matches)) {
            /* place on tree */
            print "\t<tr>\r\n\t\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\r\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Device(s) will be placed under the branch selected\r\n\t\t\t\t\t\tbelow.</p>\r\n\t\t\t\t\t\t<p><ul>" . $host_list . "</ul></p>\r\n\t\t\t\t\t\t<p><strong>Destination Branch:</strong><br>";
            grow_dropdown_tree($matches[1], "tree_item_id", "0");
            print "</p>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t</tr>\n\r\n\t\t\t\t<input type='hidden' name='tree_id' value='" . $matches[1] . "'>\n\r\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Place Device(s) on Tree'>";
        } else {
            $save['drp_action'] = $_POST['drp_action'];
            $save['host_list'] = $host_list;
            $save['host_array'] = isset($host_array) ? $host_array : array();
            api_plugin_hook_function('device_action_prepare', $save);
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue'>";
        }
    } else {
        print "<tr><td bgcolor='#" . $colors["form_alternate1"] . "'><span class='textError'>You must select at least one device.</span></td></tr>\n";
        $save_html = "<input type='button' value='Return' onClick='window.history.back()'>";
    }
    print "\t<tr>\r\n\t\t\t<td colspan='2' align='right' bgcolor='#eaeaea'>\r\n\t\t\t\t<input type='hidden' name='action' value='actions'>\r\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($host_array) ? serialize($host_array) : '') . "'>\r\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST["drp_action"] . "'>\r\n\t\t\t\t{$save_html}\r\n\t\t\t</td>\r\n\t\t</tr>\r\n\t\t";
    html_end_box();
    include_once "./include/bottom_footer.php";
}
Beispiel #16
0
function form_actions() {
	global $colors, $device_actions, $fields_host_edit;

	/* if we are to save this form, instead of display it */
	if (isset($_POST["selected_items"])) {
		$selected_items = unserialize(stripslashes($_POST["selected_items"]));

		if ($_POST["drp_action"] == "2") { /* Enable Selected Devices */
			for ($i=0;($i<count($selected_items));$i++) {
				db_execute("update host set disabled='' where id='" . $selected_items[$i] . "'");

				/* update poller cache */
				$data_sources = db_fetch_assoc("select id from data_local where host_id='" . $selected_items[$i] . "'");

				if (sizeof($data_sources) > 0) {
					foreach ($data_sources as $data_source) {
						update_poller_cache($data_source["id"], false);
					}
				}
			}
		}elseif ($_POST["drp_action"] == "3") { /* Disable Selected Devices */
			for ($i=0;($i<count($selected_items));$i++) {
				db_execute("update host set disabled='on' where id='" . $selected_items[$i] . "'");

				/* update poller cache */
				db_execute("delete from poller_item where host_id='" . $selected_items[$i] . "'");
				db_execute("delete from poller_reindex where host_id='" . $selected_items[$i] . "'");
			}
		}elseif ($_POST["drp_action"] == "4") { /* change snmp options */
			for ($i=0;($i<count($selected_items));$i++) {
				reset($fields_host_edit);
				while (list($field_name, $field_array) = each($fields_host_edit)) {
					if (isset($_POST["t_$field_name"])) {
						db_execute("update host set $field_name = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'");
					}
				}

				push_out_host($selected_items[$i]);
			}
		}elseif ($_POST["drp_action"] == "5") { /* Clear Statisitics for Selected Devices */
			for ($i=0;($i<count($selected_items));$i++) {
				db_execute("update host set min_time = '9.99999', max_time = '0', cur_time = '0',	avg_time = '0',
						total_polls = '0', failed_polls = '0',	availability = '100.00'
						where id = '" . $selected_items[$i] . "'");
			}
		}elseif ($_POST["drp_action"] == "1") { /* delete */
			for ($i=0; $i<count($selected_items); $i++) {
				if (!isset($_POST["delete_type"])) { $_POST["delete_type"] = 2; }

				switch ($_POST["delete_type"]) {
					case '2': /* delete graphs/data sources tied to this device */
						$data_sources = db_fetch_assoc("select
							data_local.id as local_data_id
							from data_local
							where " . array_to_sql_or($selected_items, "data_local.host_id"));

						if (sizeof($data_sources) > 0) {
							foreach ($data_sources as $data_source) {
								api_data_source_remove($data_source["local_data_id"]);
							}
						}

						$graphs = db_fetch_assoc("select
							graph_local.id as local_graph_id
							from graph_local
							where " . array_to_sql_or($selected_items, "graph_local.host_id"));

						if (sizeof($graphs) > 0) {
							foreach ($graphs as $graph) {
								api_graph_remove($graph["local_graph_id"]);
							}
						}

						break;
				}

				api_device_remove($selected_items[$i]);
			}
		}

		header("Location: host.php");
		exit;
	}

	/* setup some variables */
	$host_list = ""; $i = 0;

	/* loop through each of the host templates selected on the previous page and get more info about them */
	while (list($var,$val) = each($_POST)) {
		if (ereg("^chk_([0-9]+)$", $var, $matches)) {
			$host_list .= "<li>" . db_fetch_cell("select description from host where id=" . $matches[1]) . "<br>";
			$host_array[$i] = $matches[1];
		}

		$i++;
	}

	include_once("./include/top_header.php");

	html_start_box("<strong>" . $device_actions{$_POST["drp_action"]} . "</strong>", "60%", $colors["header_panel"], "3", "center", "");

	print "<form action='host.php' method='post'>\n";

	if ($_POST["drp_action"] == "2") { /* Enable Devices */
		print "	<tr>
				<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
					<p>To enable the following devices, press the \"yes\" button below.</p>
					<p>$host_list</p>
				</td>
				</tr>";
	}elseif ($_POST["drp_action"] == "3") { /* Disable Devices */
		print "	<tr>
				<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
					<p>To disable the following devices, press the \"yes\" button below.</p>
					<p>$host_list</p>
				</td>
				</tr>";
	}elseif ($_POST["drp_action"] == "4") { /* change snmp options */
		print "	<tr>
				<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
					<p>To change SNMP parameters for the following devices, check the box next to the fields
					you want to update, fill in the new value, and click Save.</p>
					<p>$host_list</p>
				</td>
				</tr>";
				$form_array = array();
				while (list($field_name, $field_array) = each($fields_host_edit)) {
					if (ereg("^snmp_", $field_name)) {
						$form_array += array($field_name => $fields_host_edit[$field_name]);

						$form_array[$field_name]["value"] = "";
						$form_array[$field_name]["description"] = "";
						$form_array[$field_name]["form_id"] = 0;
						$form_array[$field_name]["sub_checkbox"] = array(
							"name" => "t_" . $field_name,
							"friendly_name" => "Update this Field",
							"value" => ""
							);
					}
				}

				draw_edit_form(
					array(
						"config" => array("no_form_tag" => true),
						"fields" => $form_array
						)
					);
	}elseif ($_POST["drp_action"] == "5") { /* Clear Statisitics for Selected Devices */
		print "	<tr>
				<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
					<p>To clear the counters for the following devices, press the \"yes\" button below.</p>
					<p>$host_list</p>
				</td>
				</tr>";
	}elseif ($_POST["drp_action"] == "1") { /* delete */
		print "	<tr>
				<td class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
					<p>Are you sure you want to delete the following devices?</p>
					<p>$host_list</p>";
					form_radio_button("delete_type", "2", "1", "Leave all graphs and data sources untouched.", "1"); print "<br>";
					form_radio_button("delete_type", "2", "2", "Delete all associated <strong>graphs</strong> and <strong>data sources</strong>.", "1"); print "<br>";
					print "</td></tr>
				</td>
			</tr>\n
			";
	}

	if (!isset($host_array)) {
		print "<tr><td bgcolor='#" . $colors["form_alternate1"]. "'><span class='textError'>You must select at least one device.</span></td></tr>\n";
		$save_html = "";
	}else{
		$save_html = "<input type='image' src='images/button_yes.gif' alt='Save' align='absmiddle'>";
	}

	print "	<tr>
			<td colspan='2' align='right' bgcolor='#eaeaea'>
				<input type='hidden' name='action' value='actions'>
				<input type='hidden' name='selected_items' value='" . (isset($host_array) ? serialize($host_array) : '') . "'>
				<input type='hidden' name='drp_action' value='" . $_POST["drp_action"] . "'>
				<a href='host.php'><img src='images/button_no.gif' alt='Cancel' align='absmiddle' border='0'></a>
				$save_html
			</td>
		</tr>
		";

	html_end_box();

	include_once("./include/bottom_footer.php");
}
Beispiel #17
0
function api_data_source_enable($local_data_id)
{
    db_execute_prepared("UPDATE data_template_data SET active = 'on' WHERE local_data_id = ?", array($local_data_id));
    update_poller_cache($local_data_id, true);
}
Beispiel #18
0
function host_new_graphs_save()
{
    $validation_array = array();
    $selected_graphs_array = unserialize(stripslashes($_POST["selected_graphs_array"]));
    $map_id_to_index_array = unserialize(stripslashes($_POST["map_id_to_index_array"]));
    /* form an array that contains all of the data on the previous form */
    while (list($var, $val) = each($_POST)) {
        if (preg_match("/^g_(\\d+)_(\\d+)_(\\w+)/", $var, $matches)) {
            /* 1: data_query_id, 2: graph_template_id, 3: field_name */
            foreach ($map_id_to_index_array[empty($matches[1]) ? "gt" : "dq"][empty($matches[1]) ? $matches[2] : $matches[1]] as $uniq_id) {
                $selected_graphs_array[$uniq_id]["graph_template"][$matches[3]] = $val;
            }
            $validation_array["graph_template"][$matches[3]][$var] = $val;
        } elseif (preg_match("/^gi_(\\d+)_(\\d+)_(\\d+)_(\\w+)/", $var, $matches)) {
            /* 1: data_query_id, 2: graph_template_id, 3: graph_template_input_id, 4: field_name */
            foreach ($map_id_to_index_array[empty($matches[1]) ? "gt" : "dq"][empty($matches[1]) ? $matches[2] : $matches[1]] as $uniq_id) {
                $selected_graphs_array[$uniq_id]["graph_template_item"][$matches[2]][$matches[3]] = $val;
            }
            $validation_array["graph_template_item"][$matches[4]][$var] = $val;
        } elseif (preg_match("/^d_(\\d+)_(\\d+)_(\\d+)_(\\w+)/", $var, $matches)) {
            /* 1: data_query_id, 2: graph_template_id, 3: data_template_id, 4: field_name */
            foreach ($map_id_to_index_array[empty($matches[1]) ? "gt" : "dq"][empty($matches[1]) ? $matches[2] : $matches[1]] as $uniq_id) {
                $selected_graphs_array[$uniq_id]["data_template"][$matches[3]][$matches[4]] = $val;
            }
            $validation_array["data_template"][$matches[4]][$var] = $val;
        } elseif (preg_match("/^c_(\\d+)_(\\d+)_(\\d+)_(\\d+)/", $var, $matches)) {
            /* 1: data_query_id, 2: graph_template_id, 3: data_template_id, 4: data_input_field_name */
            foreach ($map_id_to_index_array[empty($matches[1]) ? "gt" : "dq"][empty($matches[1]) ? $matches[2] : $matches[1]] as $uniq_id) {
                $selected_graphs_array[$uniq_id]["custom_data"][$matches[3]][$matches[4]] = $val;
            }
            $validation_array["custom_data"][$matches[4]][$var] = $val;
        } elseif (preg_match("/^di_(\\d+)_(\\d+)_(\\d+)_(\\d+)_(\\w+)/", $var, $matches)) {
            /* 1: data_query_id, 2: graph_template_id, 3: data_template_id, 4: data_template_item_id, 5: field_name */
            foreach ($map_id_to_index_array[empty($matches[1]) ? "gt" : "dq"][empty($matches[1]) ? $matches[2] : $matches[1]] as $uniq_id) {
                $selected_graphs_array[$uniq_id]["data_template_item"][$matches[3]][$matches[4]][$matches[5]] = $val;
            }
            $validation_array["data_template_item"][$matches[5]][$var] = $val;
        }
    }
    /* first pass: form validation */
    while (list($type, $type_array) = each($validation_array)) {
        while (list($field_name, $field_array) = each($type_array)) {
            while (list($form_field_name, $value) = each($field_array)) {
                $_v_arr = array($field_name => $value);
                if ($type == "data_template") {
                    $_sv_arr = array();
                    field_register_error(api_data_source_fields_validate($_v_arr, $_sv_arr, $form_field_name, ""));
                } else {
                    if ($type == "custom_data") {
                        field_register_error(api_data_source_input_fields_validate($_v_arr, $form_field_name));
                    } else {
                        if ($type == "data_template_item") {
                            $_v_arr["id"] = 0;
                            field_register_error(api_data_source_item_fields_validate($_v_arr, $form_field_name));
                        } else {
                            if ($type == "graph_template") {
                                $_sv_arr = array();
                                field_register_error(api_graph_fields_validate($_v_arr, $_sv_arr, $form_field_name, ""));
                            } else {
                                if ($type == "graph_template_item") {
                                    field_register_error(api_graph_item_fields_validate($_v_arr, $form_field_name));
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    /* form validation failed: redirect back */
    if (is_error_message()) {
        /* cache all post field values */
        init_post_field_cache();
        host_new_graphs($selected_graphs_array, $map_id_to_index_array);
        /* form validation passed: save the data on the form */
    } else {
        debug_log_clear("new_graphs");
        foreach ($selected_graphs_array as $uniq_id => $skel) {
            if (isset($skel["custom_data"]["all_dq"])) {
                $is_data_query_graph = true;
                $data_query_id = isset($skel["custom_data"]["all_dq"]["data_query_id"]) ? $skel["custom_data"]["all_dq"]["data_query_id"] : 0;
                /* decode the data query index into its literal form */
                $data_query_index = decode_data_query_index(isset($skel["custom_data"]["all_dq"]["data_query_index"]) ? $skel["custom_data"]["all_dq"]["data_query_index"] : 0, get_data_query_indexes($data_query_id, $_POST["host_id"]));
            } else {
                $is_data_query_graph = false;
                $data_query_id = 0;
                $data_query_index = "";
            }
            $create_info = generate_complete_graph($skel["graph_template_id"], $_POST["host_id"], $data_query_id, $data_query_index);
            /* set the appropriate 'custom_data' keys */
            if ($is_data_query_graph == true) {
                /* pick the data query field name to index on */
                $data_query_field_name = get_best_data_query_index_type($_POST["host_id"], $data_query_id);
                /* get a list of all data templates associated with this graph template that are of type DATA_INPUT_TYPE_DATA_QUERY */
                $dq_data_templates = get_data_templates_from_graph_template($skel["graph_template_id"], DATA_INPUT_TYPE_DATA_QUERY);
                if (sizeof($dq_data_templates) > 0) {
                    foreach ($dq_data_templates as $data_template) {
                        $skel["custom_data"][$data_template["id"]]["data_query_id"] = $data_query_id;
                        $skel["custom_data"][$data_template["id"]]["data_query_index"] = $data_query_index;
                        $skel["custom_data"][$data_template["id"]]["data_query_field_name"] = $data_query_field_name;
                        $skel["custom_data"][$data_template["id"]]["data_query_field_value"] = get_data_query_row_value($data_query_id, $_POST["host_id"], $data_query_field_name, $data_query_index);
                    }
                }
            }
            /* update user specified data: data source-specific fields */
            foreach (array_keys($create_info["data_source"]) as $data_template_id) {
                if (isset($skel["data_template"][$data_template_id])) {
                    if (!api_data_source_save($create_info["data_source"][$data_template_id], $skel["data_template"][$data_template_id])) {
                        log_save("Problems updating new data source [ID#" . $create_info["data_source"][$data_template_id] . "], data template [ID#{$data_template_id}] from user data", SEV_ERROR);
                    }
                }
                if (isset($skel["data_template_item"][$data_template_id])) {
                    foreach ($skel["data_template_item"][$data_template_id] as $data_source_item_id => $data_template_item_array) {
                        if (!api_data_source_item_save($data_source_item_id, $data_template_item_array)) {
                            log_save("Problems updating new data source [item] [ID#" . $create_info["data_source"][$data_template_id] . "], data template [ID#{$data_template_id}] from user data", SEV_ERROR);
                        }
                    }
                }
                if (isset($skel["custom_data"][$data_template_id])) {
                    if (!api_data_source_fields_save($create_info["data_source"][$data_template_id], $skel["custom_data"][$data_template_id])) {
                        log_save("Problems updating new data source (fields) [ID#" . $create_info["data_source"][$data_template_id] . "], data template [ID#{$data_template_id}] from user data", SEV_ERROR);
                    }
                }
                /* update the title cache */
                api_data_source_title_cache_update($create_info["data_source"][$data_template_id]);
                /* update poller cache */
                update_poller_cache($create_info["data_source"][$data_template_id]);
            }
            /* update user specified data: graph-specific fields */
            foreach (array_keys($create_info["graph"]) as $graph_template_id) {
                if (isset($skel["graph_template"][$graph_template_id])) {
                    if (!api_graph_save($create_info["graph"][$graph_template_id], $skel["graph_template"][$graph_template_id])) {
                        log_save("Problems updating new graph [ID#" . $create_info["graph"][$graph_template_id] . "], graph template [ID#{$graph_template_id}] from user data", SEV_ERROR);
                    }
                }
                if (isset($skel["graph_template_item"][$graph_template_id])) {
                    foreach ($skel["graph_template_item"][$graph_template_id] as $graph_template_item_input_id => $value) {
                        if (!api_graph_template_item_input_propagate($graph_template_item_input_id, $value)) {
                            log_save("Problems updating new graph [item] [ID#" . $create_info["graph"][$graph_template_id] . "], graph template [ID#{$graph_template_id}] from user data", SEV_ERROR);
                        }
                    }
                }
                /* update the title cache */
                api_graph_title_cache_update($create_info["graph"][$graph_template_id]);
            }
            debug_log_insert("new_graphs", _("Created graph: ") . api_graph_title_get($create_info["graph"][$skel["graph_template_id"]]));
        }
        /* lastly push host-specific information to our data sources */
        //push_out_host($_POST["host_id"], 0);
    }
}
Beispiel #19
0
function data_source_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("device_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["device_id"] = $_POST["device_id"];

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

		change_data_template($local_data_id, get_request_var_post("data_template_id"));

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

		/* update device data */
		if (!empty($_POST["device_id"])) {
			push_out_device(get_request_var_post("device_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.device_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"] == CHECKED) {
					$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_execute("replace into data_input_data (data_input_field_id,data_template_data_id,t_value,value) values
						(" . $input_field["id"] . "," . get_request_var_post("data_template_data_id") . ",'','$form_value')");
				}
			}
		}
		}
	}

	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("device_id"));
		/* ==================================================== */

		$save1["id"] = $_POST["local_data_id"];
		$save1["data_template_id"] = $_POST["data_template_id"];
		$save1["device_id"] = $_POST["device_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["hidden_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["hidden_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]+(\.[0-9]*)?|[0-9]*\.[0-9]+)([eE][+\-]?[0-9]+)?)|U$", false, 3);
#					$save3["rrd_minimum"] = form_input_validate($_POST["rrd_minimum$name_modifier"], "rrd_minimum$name_modifier", "^(-?([0-9]+(\.[0-9]*)?|[0-9]*\.[0-9]+)([eE][+\-]?[0-9]+)?)|U$", 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["hidden_data_template_id"]) {
				/* update all necessary template information */
				change_data_template($local_data_id, get_request_var_post("data_template_id"));
			}elseif (!empty($_POST["data_template_id"])) {
				update_data_source_data_query_cache($local_data_id);
			}

			if ($_POST["device_id"] != $_POST["hidden_device_id"]) {
				/* push out all necessary device information */
				push_out_device(get_request_var_post("device_id"), $local_data_id);

				/* reset current device for display purposes */
				$_SESSION["sess_data_source_currenthidden_device_id"] = $_POST["device_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, true);
	}

	if ((isset($_POST["save_component_data_source_new"])) && (empty($_POST["data_template_id"]))) {
		header("Location: data_sources.php?action=data_source_edit&device_id=" . $_POST["device_id"] . "&new=1");
	}elseif ((is_error_message()) || ($_POST["data_template_id"] != $_POST["hidden_data_template_id"]) || ($_POST["data_input_id"] != $_POST["hidden_data_input_id"]) || ($_POST["device_id"] != $_POST["hidden_device_id"])) {
		header("Location: data_sources.php?action=data_source_edit&id=" . (empty($local_data_id) ? $_POST["local_data_id"] : $local_data_id) . "&device_id=" . $_POST["device_id"] . "&view_rrd=" . (isset($_POST["current_rrd"]) ? $_POST["current_rrd"] : "0"));
	}else{
		header("Location: data_sources.php");
	}
	exit;
}
Beispiel #20
0
function form_actions()
{
    global $device_actions, $fields_host_edit;
    /* ================= input validation ================= */
    input_validate_input_regex(get_request_var_post('drp_action'), '^([a-zA-Z0-9_]+)$');
    /* ==================================================== */
    /* if we are to save this form, instead of display it */
    if (isset($_POST['selected_items'])) {
        $selected_items = unserialize(stripslashes($_POST['selected_items']));
        if ($_POST['drp_action'] == '2') {
            /* Enable Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute_prepared("UPDATE host SET disabled = '' WHERE id = ?", array($selected_items[$i]));
                /* update poller cache */
                $data_sources = db_fetch_assoc_prepared('SELECT id FROM data_local WHERE host_id = ?', array($selected_items[$i]));
                $poller_items = $local_data_ids = array();
                if (sizeof($data_sources) > 0) {
                    foreach ($data_sources as $data_source) {
                        $local_data_ids[] = $data_source['id'];
                        $poller_items = array_merge($poller_items, update_poller_cache($data_source['id']));
                    }
                }
                if (sizeof($local_data_ids)) {
                    poller_update_poller_cache_from_buffer($local_data_ids, $poller_items);
                }
            }
        } elseif ($_POST['drp_action'] == '3') {
            /* Disable Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute_prepared("UPDATE host SET disabled='on' WHERE id = ?", array($selected_items[$i]));
                /* update poller cache */
                db_execute_prepared('DELETE FROM poller_item WHERE host_id = ?', array($selected_items[$i]));
                db_execute_prepared('DELETE FROM poller_reindex WHERE host_id = ?', array($selected_items[$i]));
            }
        } elseif ($_POST['drp_action'] == '4') {
            /* change snmp options */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                reset($fields_host_edit);
                while (list($field_name, $field_array) = each($fields_host_edit)) {
                    if (isset($_POST["t_{$field_name}"])) {
                        db_execute_prepared("UPDATE host SET {$field_name} = ? WHERE id = ?", array($_POST[$field_name], $selected_items[$i]));
                    }
                }
                push_out_host($selected_items[$i]);
            }
        } elseif ($_POST['drp_action'] == '5') {
            /* Clear Statisitics for Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute_prepared("UPDATE host SET min_time = '9.99999', max_time = '0', cur_time = '0', avg_time = '0',\n\t\t\t\t\t\ttotal_polls = '0', failed_polls = '0',\tavailability = '100.00'\n\t\t\t\t\t\twhere id = ?", array($selected_items[$i]));
            }
        } elseif ($_POST['drp_action'] == '6') {
            /* change availability options */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                reset($fields_host_edit);
                while (list($field_name, $field_array) = each($fields_host_edit)) {
                    if (isset($_POST["t_{$field_name}"])) {
                        db_execute_prepared("UPDATE host SET {$field_name} = ? WHERE id = ?", array($_POST[$field_name], $selected_items[$i]));
                    }
                }
                push_out_host($selected_items[$i]);
            }
        } elseif ($_POST['drp_action'] == '1') {
            /* delete */
            if (!isset($_POST['delete_type'])) {
                $_POST['delete_type'] = 2;
            }
            $data_sources_to_act_on = array();
            $graphs_to_act_on = array();
            $devices_to_act_on = array();
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                $data_sources = db_fetch_assoc('SELECT
					data_local.id AS local_data_id
					FROM data_local
					WHERE ' . array_to_sql_or($selected_items, 'data_local.host_id'));
                if (sizeof($data_sources) > 0) {
                    foreach ($data_sources as $data_source) {
                        $data_sources_to_act_on[] = $data_source['local_data_id'];
                    }
                }
                if ($_POST['delete_type'] == 2) {
                    $graphs = db_fetch_assoc('SELECT
						graph_local.id AS local_graph_id
						FROM graph_local
						WHERE ' . array_to_sql_or($selected_items, 'graph_local.host_id'));
                    if (sizeof($graphs) > 0) {
                        foreach ($graphs as $graph) {
                            $graphs_to_act_on[] = $graph['local_graph_id'];
                        }
                    }
                }
                $devices_to_act_on[] = $selected_items[$i];
            }
            switch ($_POST['delete_type']) {
                case '1':
                    /* leave graphs and data_sources in place, but disable the data sources */
                    api_data_source_disable_multi($data_sources_to_act_on);
                    api_plugin_hook_function('data_source_remove', $data_sources_to_act_on);
                    break;
                case '2':
                    /* delete graphs/data sources tied to this device */
                    api_data_source_remove_multi($data_sources_to_act_on);
                    api_graph_remove_multi($graphs_to_act_on);
                    api_plugin_hook_function('graphs_remove', $graphs_to_act_on);
                    break;
            }
            api_device_remove_multi($devices_to_act_on);
            api_plugin_hook_function('device_remove', $devices_to_act_on);
        } elseif (preg_match('/^tr_([0-9]+)$/', $_POST['drp_action'], $matches)) {
            /* place on tree */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                input_validate_input_number(get_request_var_post('tree_id'));
                input_validate_input_number(get_request_var_post('tree_item_id'));
                /* ==================================================== */
                api_tree_item_save(0, $_POST['tree_id'], TREE_ITEM_TYPE_HOST, $_POST['tree_item_id'], '', 0, read_graph_config_option('default_rra_id'), $selected_items[$i], 1, 1, false);
            }
        } else {
            api_plugin_hook_function('device_action_execute', $_POST['drp_action']);
        }
        /* update snmpcache */
        snmpagent_device_action_bottom(array($_POST['drp_action'], $selected_items));
        api_plugin_hook_function('device_action_bottom', array($_POST['drp_action'], $selected_items));
        header('Location: host.php');
        exit;
    }
    /* setup some variables */
    $host_list = '';
    $i = 0;
    /* loop through each of the host templates selected on the previous page and get more info about them */
    while (list($var, $val) = each($_POST)) {
        if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
            /* ================= input validation ================= */
            input_validate_input_number($matches[1]);
            /* ==================================================== */
            $host_list .= '<li>' . htmlspecialchars(db_fetch_cell_prepared('SELECT description FROM host WHERE id = ?', array($matches[1]))) . '<br>';
            $host_array[$i] = $matches[1];
            $i++;
        }
    }
    top_header();
    /* add a list of tree names to the actions dropdown */
    add_tree_names_to_actions_array();
    html_start_box('<strong>' . $device_actions[get_request_var_post('drp_action')] . '</strong>', '60%', '', '3', 'center', '');
    print "<form action='host.php' autocomplete='off' method='post'>\n";
    if (isset($host_array) && sizeof($host_array)) {
        if ($_POST['drp_action'] == '2') {
            /* Enable Devices */
            print "\t<tr>\n\t\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t\t<p>To enable the following Device(s), click \"Continue\".</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . "</ul></p>\n\t\t\t\t\t</td>\n\t\t\t\t\t</tr>";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Enable Device(s)'>";
        } elseif ($_POST['drp_action'] == '3') {
            /* Disable Devices */
            print "\t<tr>\n\t\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t\t<p>To disable the following Device(s), click \"Continue\".</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p>
					</td>
					</tr>';
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Disable Device(s)'>";
        } elseif ($_POST['drp_action'] == '4') {
            /* change snmp options */
            print "\t<tr>\n\t\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t\t<p>To change SNMP parameters for the following Device(s), check the box next to the fields\n\t\t\t\t\t\tyou want to update, fill in the new value, and click \"Continue\".</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p>
					</td>
					</tr>';
            $form_array = array();
            while (list($field_name, $field_array) = each($fields_host_edit)) {
                if (preg_match('/^snmp_/', $field_name) || $field_name == 'max_oids') {
                    $form_array += array($field_name => $fields_host_edit[$field_name]);
                    $form_array[$field_name]['value'] = '';
                    $form_array[$field_name]['description'] = '';
                    $form_array[$field_name]['form_id'] = 0;
                    $form_array[$field_name]['sub_checkbox'] = array('name' => 't_' . $field_name, 'friendly_name' => 'Update this Field', 'value' => '');
                }
            }
            draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => $form_array));
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Change Device(s) SNMP Options'>";
        } elseif ($_POST['drp_action'] == '6') {
            /* change availability options */
            print "\t<tr>\n\t\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t\t<p>To change Availability parameters for the following Device(s), check the box next to the fields\n\t\t\t\t\t\tyou want to update, fill in the new value, and click \"Continue\".</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p>
					</td>
					</tr>';
            $form_array = array();
            while (list($field_name, $field_array) = each($fields_host_edit)) {
                if (preg_match('/(availability_method|ping_method|ping_port)/', $field_name)) {
                    $form_array += array($field_name => $fields_host_edit[$field_name]);
                    $form_array[$field_name]['value'] = '';
                    $form_array[$field_name]['description'] = '';
                    $form_array[$field_name]['form_id'] = 0;
                    $form_array[$field_name]['sub_checkbox'] = array('name' => 't_' . $field_name, 'friendly_name' => 'Update this Field', 'value' => '');
                }
            }
            draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => $form_array));
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Change Device(s) Availability Options'>";
        } elseif ($_POST['drp_action'] == '5') {
            /* Clear Statisitics for Selected Devices */
            print "\t<tr>\n\t\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t\t<p>To clear the counters for the following Device(s), press the \"Continue\" button below.</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p>
					</td>
					</tr>';
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Clear Statistics on Device(s)'>";
        } elseif ($_POST['drp_action'] == '1') {
            /* delete */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\" the following Device(s) will be deleted.</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p>';
            form_radio_button('delete_type', '2', '1', 'Leave all Graph(s) and Data Source(s) untouched.  Data Source(s) will be disabled however.', '1');
            print '<br>';
            form_radio_button('delete_type', '2', '2', 'Delete all associated <strong>Graph(s)</strong> and <strong>Data Source(s)</strong>.', '1');
            print '<br>';
            print "</td></tr>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Delete Device(s)'>";
        } elseif (preg_match('/^tr_([0-9]+)$/', $_POST['drp_action'], $matches)) {
            /* place on tree */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Device(s) will be placed under the branch selected\n\t\t\t\t\t\tbelow.</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p>
						<p><strong>Destination Branch:</strong><br>';
            grow_dropdown_tree($matches[1], '0', 'tree_item_id', '0');
            print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t<input type='hidden' name='tree_id' value='" . $matches[1] . "'>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Place Device(s) on Tree'>";
        } else {
            $save['drp_action'] = $_POST['drp_action'];
            $save['host_list'] = $host_list;
            $save['host_array'] = isset($host_array) ? $host_array : array();
            api_plugin_hook_function('device_action_prepare', $save);
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue'>";
        }
    } else {
        print "<tr><td class='even'><span class='textError'>You must select at least one device.</span></td></tr>\n";
        $save_html = "<input type='button' value='Return' onClick='window.history.back()'>";
    }
    print "\t<tr>\n\t\t\t<td colspan='2' align='right' class='saveRow'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($host_array) ? serialize($host_array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST['drp_action'] . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n\t\t";
    html_end_box();
    bottom_footer();
}
Beispiel #21
0
function api_device_form_actions() {
	global $colors;
	require_once(CACTI_BASE_PATH . "/lib/device/device_info.php");
	require(CACTI_BASE_PATH . "/include/graph_tree/graph_tree_arrays.php");

	$fields_device_edit = device_form_list();
	$fields_device_edit_availability = device_availability_form_list();
	/* if we are to save this form, instead of display it */
	if (isset($_POST["selected_items"])) {
		$selected_items = unserialize(stripslashes($_POST["selected_items"]));

		if (get_request_var_post("drp_action") === DEVICE_ACTION_ENABLE) { /* Enable Selected Devices */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */

				db_execute("update device set disabled='' where id='" . $selected_items[$i] . "'");

				/* update poller cache */
				$data_sources = db_fetch_assoc("select id from data_local where device_id='" . $selected_items[$i] . "'");
				$poller_items = array();

				if (sizeof($data_sources) > 0) {
					foreach ($data_sources as $data_source) {
						$local_data_ids[] = $data_source["id"];
						$poller_items     = array_merge($poller_items, update_poller_cache($data_source["id"]));
					}
				}

				poller_update_poller_cache_from_buffer($local_data_ids, $poller_items);
			}
		}elseif (get_request_var_post("drp_action") === DEVICE_ACTION_DISABLE) { /* Disable Selected Devices */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */

				db_execute("update device set disabled='on' where id='" . $selected_items[$i] . "'");

				/* update poller cache */
				db_execute("delete from poller_item where device_id='" . $selected_items[$i] . "'");
				db_execute("delete from poller_reindex where device_id='" . $selected_items[$i] . "'");
			}
		}elseif (get_request_var_post("drp_action") === DEVICE_ACTION_CHANGE_SNMP_OPTIONS) { /* change snmp options */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */

				reset($fields_device_edit);
				while (list($field_name, $field_array) = each($fields_device_edit)) {
					if (isset($_POST["t_$field_name"])) {
						db_execute("update device set $field_name = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'");
					}
				}

				push_out_device($selected_items[$i]);
			}
		}elseif (get_request_var_post("drp_action") === DEVICE_ACTION_CLEAR_STATISTICS) { /* Clear Statisitics for Selected Devices */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */

				db_execute("update device set min_time = '9.99999', max_time = '0', cur_time = '0',	avg_time = '0',
						total_polls = '0', failed_polls = '0',	availability = '100.00'
						where id = '" . $selected_items[$i] . "'");
			}
		}elseif (get_request_var_post("drp_action") === DEVICE_ACTION_CHANGE_AVAILABILITY_OPTIONS) { /* change availability options */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */

				reset($fields_device_edit);
				while (list($field_name, $field_array) = each($fields_device_edit)) {
					if (isset($_POST["t_$field_name"])) {
						db_execute("update device set $field_name = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'");
					}
				}

				push_out_device($selected_items[$i]);
			}
		}elseif (get_request_var_post("drp_action") === DEVICE_ACTION_CHANGE_POLLER) { /* change poller */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */

				reset($fields_device_edit);
				while (list($field_name, $field_array) = each($fields_device_edit)) {
					if (isset($_POST["$field_name"])) {
						db_execute("update device set $field_name = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'");
					}
				}

				push_out_device($selected_items[$i]);
			}
		}elseif (get_request_var_post("drp_action") === DEVICE_ACTION_CHANGE_SITE) { /* change site */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */

				reset($fields_device_edit);
				while (list($field_name, $field_array) = each($fields_device_edit)) {
					if (isset($_POST["$field_name"])) {
						db_execute("update device set $field_name = '" . $_POST[$field_name] . "' where id='" . $selected_items[$i] . "'");
					}
				}

				push_out_device($selected_items[$i]);
			}
		}elseif (get_request_var_post("drp_action") === DEVICE_ACTION_DELETE) { /* delete */
			if (!isset($_POST["delete_type"])) { $_POST["delete_type"] = 2; }

			$data_sources_to_act_on = array();
			$graphs_to_act_on       = array();
			$devices_to_act_on      = array();

			for ($i=0; $i<count($selected_items); $i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				/* ==================================================== */

				$data_sources = db_fetch_assoc("select
					data_local.id as local_data_id
					from data_local
					where " . array_to_sql_or($selected_items, "data_local.device_id"));

				if (sizeof($data_sources) > 0) {
				foreach ($data_sources as $data_source) {
					$data_sources_to_act_on[] = $data_source["local_data_id"];
				}
				}

				if (get_request_var_post("delete_type") == 2) {
					$graphs = db_fetch_assoc("select
						graph_local.id as local_graph_id
						from graph_local
						where " . array_to_sql_or($selected_items, "graph_local.device_id"));

					if (sizeof($graphs) > 0) {
					foreach ($graphs as $graph) {
						$graphs_to_act_on[] = $graph["local_graph_id"];
					}
					}
				}

				$devices_to_act_on[] = $selected_items[$i];
			}

			switch (get_request_var_post("delete_type")) {
				case '1': /* leave graphs and data_sources in place, but disable the data sources */
					api_data_source_disable_multi($data_sources_to_act_on);

					break;
				case '2': /* delete graphs/data sources tied to this device */
					api_data_source_remove_multi($data_sources_to_act_on);

					api_graph_remove_multi($graphs_to_act_on);

					break;
			}

			api_device_remove_multi($devices_to_act_on);
		}elseif (preg_match("/^tr_([0-9]+)$/", get_request_var_post("drp_action"), $matches)) { /* place on tree */
			for ($i=0;($i<count($selected_items));$i++) {
				/* ================= input validation ================= */
				input_validate_input_number($selected_items[$i]);
				input_validate_input_number(get_request_var_post("tree_id"));
				input_validate_input_number(get_request_var_post("tree_item_id"));
				/* ==================================================== */

				api_tree_item_save(0, get_request_var_post("tree_id"), TREE_ITEM_TYPE_DEVICE, get_request_var_post("tree_item_id"), "", 0, read_graph_config_option("default_rra_id"), $selected_items[$i], 1, 1, false);
			}
		} else {
			api_plugin_hook_function('device_action_execute', get_request_var_post('drp_action'));
		}

		header("Location: devices.php");
		exit;
	}

	/* setup some variables */
	$device_list = ""; $i = 0; $device_array = array();

	/* loop through each of the device templates selected on the previous page and get more info about them */
	while (list($var,$val) = each($_POST)) {
		if (preg_match("/^chk_([0-9]+)$/", $var, $matches)) {
			/* ================= input validation ================= */
			input_validate_input_number($matches[1]);
			/* ==================================================== */

			$device_list .= "<li>" . db_fetch_cell("select description from device where id=" . $matches[1]) . "<br>";
			$device_array[$i] = $matches[1];
		}

		$i++;
	}

	include_once(CACTI_BASE_PATH . "/include/top_header.php");

	/* add a list of tree names to the actions dropdown */
	$device_actions = array_merge($device_actions, api_tree_add_tree_names_to_actions_array());

	$device_actions[ACTION_NONE] = __("None");

	print "<form method='post' action='" .  basename($_SERVER["PHP_SELF"]) . "' name='device_edit_actions'>\n";
	html_start_box("<strong>" . $device_actions{get_request_var_post("drp_action")} . "</strong>", "60", $colors["header_panel"], "3", "center", "");

	if (sizeof($device_array)) {
		if (get_request_var_post("drp_action") === ACTION_NONE) { /* NONE */
			print "	<tr>
						<td class='textArea'>
							<p>" . __("You did not select a valid action. Please select 'Return' to return to the previous menu.") . "</p>
						</td>
					</tr>\n";
		}elseif (get_request_var_post("drp_action") === DEVICE_ACTION_ENABLE) { /* Enable Devices */
			print "	<tr>
					<td colspan='2' class='textArea'>
						<p>" . __("To enable the following devices, press the \"yes\" button below.") . "</p>
						<p>$device_list</p>
					</td>
					</tr>";
		}elseif (get_request_var_post("drp_action") === DEVICE_ACTION_DISABLE) { /* Disable Devices */
			print "	<tr>
					<td colspan='2' class='textArea'>
						<p>" . __("To disable the following devices, press the \"yes\" button below.") . "</p>
						<p>$device_list</p>
					</td>
					</tr>";
		}elseif (get_request_var_post("drp_action") === DEVICE_ACTION_CHANGE_SNMP_OPTIONS) { /* change snmp options */
			print "	<tr>
					<td colspan='2' class='textArea'>
						<p>" . __("To change SNMP parameters for the following devices, check the box next to the fields you want to update, fill in the new value, and click \"yes\".") . "</p>
						<p>$device_list</p>
					</td>
					</tr>";

			$form_array = array();
			while (list($field_name, $field_array) = each($fields_device_edit_availability)) {
				if (preg_match("/(^snmp_|max_oids)/", $field_name)) {
					$form_array += array($field_name => $fields_device_edit_availability[$field_name]);

					$form_array[$field_name]["value"] = "";
					$form_array[$field_name]["form_id"] = 0;
					$form_array[$field_name]["sub_checkbox"] = array(
						"name" => "t_" . $field_name,
						"friendly_name" => __("Update this Field"),
						"value" => ""
						);
				}
			}

			draw_edit_form(
				array(
					"config" => array("no_form_tag" => true),
					"fields" => $form_array
					)
				);
		}elseif (get_request_var_post("drp_action") === DEVICE_ACTION_CHANGE_AVAILABILITY_OPTIONS) { /* change availability options */
			print "	<tr>
					<td colspan='2' class='textArea'>
						<p>" . __("To change availability parameters for the following devices, check the box next to the fields you want to update, fill in the new value, and click yes.") . "</p>
						<p>$device_list</p>
					</td>
					</tr>";

			$form_array = array();
			while (list($field_name, $field_array) = each($fields_device_edit_availability)) {
				if (!preg_match("/(^snmp_|max_oids)/", $field_name)) {
					$form_array += array($field_name => $fields_device_edit_availability[$field_name]);

					$form_array[$field_name]["value"] = "";
					$form_array[$field_name]["form_id"] = 0;
					$form_array[$field_name]["sub_checkbox"] = array(
						"name" => "t_" . $field_name,
						"friendly_name" => __("Update this Field"),
						"value" => ""
						);
				}
			}

			draw_edit_form(
				array(
					"config" => array("no_form_tag" => true),
					"fields" => $form_array
					)
				);
		}elseif (get_request_var_post("drp_action") === DEVICE_ACTION_CLEAR_STATISTICS) { /* Clear Statisitics for Selected Devices */
			print "	<tr>
					<td colspan='2' class='textArea'>
						<p>" . __("To clear the counters for the following devices, press the \"yes\" button below.") . "</p>
						<p>$device_list</p>
					</td>
					</tr>";
		}elseif (get_request_var_post("drp_action") === DEVICE_ACTION_DELETE) { /* delete */
			print "	<tr>
					<td class='textArea'>
						<p>" . __("Are you sure you want to delete the following devices?") . "</p>
						<p>$device_list</p>";
						form_radio_button("delete_type", "2", "1", __("Leave all graphs and data sources untouched.  Data sources will be disabled however."), "1"); print "<br>";
						form_radio_button("delete_type", "2", "2", __("Delete all associated <strong>graphs</strong> and <strong>data sources</strong>."), "1"); print "<br>";
						print "</td></tr>
					</td>
				</tr>\n
				";
		}elseif (get_request_var_post("drp_action") === DEVICE_ACTION_CHANGE_POLLER) { /* Change Poller */
			print "	<tr>
					<td colspan='2' class='textArea'>
						<p>" . __("Select the new poller below for the devices(s) below and select 'yes' to continue, or 'no' to return.") . "</p>
						<p>$device_list</p>
					</td>
					</tr>";

			$form_array = array();
			$field_name = "poller_id";
			$form_array += array($field_name => $fields_device_edit["poller_id"]);
			$form_array[$field_name]["description"] = __("Please select the new poller for the selected device(s).");

			draw_edit_form(
				array(
					"config" => array("no_form_tag" => true),
					"fields" => $form_array
					)
				);
		}elseif (get_request_var_post("drp_action") === DEVICE_ACTION_CHANGE_SITE) { /* Change Site */
			print "	<tr>
					<td colspan='2' class='textArea'>
						<p>" . __("Select the new site for the devices(s) below and select 'yes' to continue, or 'no' to return.") . "</p>
						<p>$device_list</p>
					</td>
					</tr>";

			$form_array = array();
			$field_name = "site_id";
			$form_array += array($field_name => $fields_device_edit["site_id"]);
			$form_array[$field_name]["description"] = __("Please select the new site for the selected device(s).");

			draw_edit_form(
				array(
					"config" => array("no_form_tag" => true),
					"fields" => $form_array
					)
				);
		}elseif (preg_match("/^tr_([0-9]+)$/", get_request_var_post("drp_action"), $matches)) { /* place on tree */
			print "	<tr>
					<td class='textArea'>
						<p>" . __("When you click save, the following devices will be placed under the branch selected below.") . "</p>
						<p>$device_list</p>
						<p><strong>" . __("Destination Branch:") . "</strong><br>"; grow_dropdown_tree($matches[1], "tree_item_id", "0"); print "</p>
					</td>
				</tr>\n
				<input type='hidden' name='tree_id' value='" . $matches[1] . "'>\n
				";
		} else {
			$save['drp_action'] = $_POST['drp_action'];
			$save['device_list'] = $device_list;
			$save['device_array'] = (isset($device_array)? $device_array : array());
			api_plugin_hook_function('device_action_prepare', $save);
		}
	} else {
		print "	<tr>
				<td class='textArea'>
					<p>" . __("You must first select a Device.  Please select 'Return' to return to the previous menu.") . "</p>
				</td>
			</tr>\n";
	}

	if (!sizeof($device_array) || get_request_var_post("drp_action") === ACTION_NONE) {
		form_return_button_alt();
	}else{
		form_yesno_button_alt(serialize($device_array), get_request_var_post("drp_action"));
	}

	html_end_box();

	include_once(CACTI_BASE_PATH . "/include/bottom_footer.php");
}