Esempio n. 1
0
function api_device_total_get($filter_array = "") {
	require_once(CACTI_BASE_PATH . "/lib/device/device_form.php");

	$sql_where = "";
	/* validation and setup for the WHERE clause */
	if ((is_array($filter_array)) && (sizeof($filter_array) > 0)) {
		/* validate each field against the known master field list */
		$field_errors = api_device_field_validate(sql_filter_array_to_field_array($filter_array), "|field|");

		/* if a field input error has occured, register the error in the session and return */
		if (sizeof($field_errors) > 0) {
			field_register_error($field_errors);
			return false;
		/* otherwise, form an SQL WHERE string using the filter fields */
		}else{
			$sql_where = sql_filter_array_to_where_string($filter_array, api_device_form_list(), true);
		}
	}

	return db_fetch_cell("select count(*) from host $sql_where");
}
Esempio n. 2
0
function form_post()
{
    if ($_POST["action_post"] == "device_edit") {
        /* the "Add" assigned package button was pressed */
        if (isset($_POST["assoc_package_add_y"])) {
            api_device_package_add($_POST["id"], $_POST["assoc_package_id"]);
            header("Location: devices.php?action=edit&id=" . $_POST["id"]);
            exit;
        }
        /* cache all post field values */
        init_post_field_cache();
        /* field validation */
        $form_device["id"] = $_POST["id"];
        $form_device["description"] = $_POST["description"];
        $form_device["hostname"] = $_POST["hostname"];
        $form_device["host_template_id"] = $_POST["host_template_id"];
        $form_device["poller_id"] = $_POST["poller_id"];
        $form_device["disabled"] = html_boolean(isset($_POST["disabled"]) ? $_POST["disabled"] : "");
        $form_device["snmp_version"] = $_POST["snmp_version"];
        $form_device["snmp_community"] = $_POST["snmp_community"];
        $form_device["snmp_port"] = $_POST["snmp_port"];
        $form_device["snmp_timeout"] = $_POST["snmp_timeout"];
        $form_device["snmpv3_auth_username"] = $_POST["snmpv3_auth_username"];
        $form_device["snmpv3_auth_password"] = $_POST["snmpv3_auth_password"];
        $form_device["snmpv3_auth_protocol"] = $_POST["snmpv3_auth_protocol"];
        $form_device["snmpv3_priv_passphrase"] = $_POST["snmpv3_priv_passphrase"];
        $form_device["snmpv3_priv_protocol"] = $_POST["snmpv3_priv_protocol"];
        field_register_error(api_device_field_validate($form_device, "|field|"));
        /* field save */
        $device_id = false;
        if (is_error_message()) {
            log_save("User input validation error for device [ID#" . $_POST["id"] . "]", SEV_DEBUG);
        } else {
            $device_id = api_device_save($_POST["id"], $form_device);
            if ($device_id === false) {
                log_save("Save error for device [ID#" . $_POST["id"] . "]", SEV_ERROR);
            }
        }
        if ($device_id === false || empty($_POST["id"])) {
            header("Location: devices.php?action=edit" . (empty($_POST["id"]) ? "" : "&id=" . $_POST["id"]));
        } else {
            header("Location: devices.php");
        }
        /* submit button on the actions area page */
    } else {
        if ($_POST["action_post"] == "box-1") {
            $selected_rows = explode(":", $_POST["box-1-action-area-selected-rows"]);
            if ($_POST["box-1-action-area-type"] == "search") {
                $get_string = "";
                if ($_POST["box-1-search_device_template"] != "-1") {
                    $get_string .= ($get_string == "" ? "?" : "&") . "search_device_template=" . urlencode($_POST["box-1-search_device_template"]);
                }
                if ($_POST["box-1-search_status"] != "-1") {
                    $get_string .= ($get_string == "" ? "?" : "&") . "search_status=" . urlencode($_POST["box-1-search_status"]);
                }
                if (trim($_POST["box-1-search_filter"]) != "") {
                    $get_string .= ($get_string == "" ? "?" : "&") . "search_filter=" . urlencode($_POST["box-1-search_filter"]);
                }
                header("Location: devices.php{$get_string}");
                exit;
            } else {
                if ($_POST["box-1-action-area-type"] == "remove") {
                    foreach ($selected_rows as $host_id) {
                        api_device_remove($host_id, $_POST["box-1-remove_type"] == "2" ? true : false);
                    }
                } else {
                    if ($_POST["box-1-action-area-type"] == "enable") {
                        foreach ($selected_rows as $host_id) {
                            api_device_enable($host_id);
                        }
                    } else {
                        if ($_POST["box-1-action-area-type"] == "disable") {
                            foreach ($selected_rows as $host_id) {
                                api_device_disable($host_id);
                            }
                        } else {
                            if ($_POST["box-1-action-area-type"] == "clear_stats") {
                                foreach ($selected_rows as $host_id) {
                                    api_device_statistics_clear($host_id);
                                }
                            } else {
                                if ($_POST["box-1-action-area-type"] == "change_snmp_opts") {
                                    // not yet implemented
                                } else {
                                    if ($_POST["box-1-action-area-type"] == "change_avail_opts") {
                                        // not yet implemented
                                    } else {
                                        if ($_POST["box-1-action-area-type"] == "change_poller") {
                                            // not yet implemented
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            header("Location: devices.php");
            /* 'filter' area at the bottom of the box */
        } else {
            if ($_POST["action_post"] == "device_list") {
                $get_string = "";
                /* the 'clear' button wasn't pressed, so we should filter */
                if (!isset($_POST["box-1-action-clear-button"])) {
                    if (trim($_POST["box-1-search_filter"]) != "") {
                        $get_string = ($get_string == "" ? "?" : "&") . "search_filter=" . urlencode($_POST["box-1-search_filter"]);
                    }
                }
                header("Location: devices.php{$get_string}");
            }
        }
    }
}