Ejemplo n.º 1
0
Archivo: host.php Proyecto: MrWnn/cacti
function form_save()
{
    if (!empty($_POST['add_dq_x']) && !empty($_POST['snmp_query_id'])) {
        /* ================= input validation ================= */
        input_validate_input_number(get_request_var_post('id'));
        input_validate_input_number(get_request_var_post('snmp_query_id'));
        input_validate_input_number(get_request_var_post('reindex_method'));
        /* ==================================================== */
        db_execute_prepared('REPLACE INTO host_snmp_query (host_id, snmp_query_id, reindex_method) VALUES (?, ?, ?)', array($_POST['id'], $_POST['snmp_query_id'], $_POST['reindex_method']));
        /* recache snmp data */
        run_data_query($_POST['id'], $_POST['snmp_query_id']);
        header('Location: host.php?action=edit&id=' . $_POST['id']);
        exit;
    }
    if (!empty($_POST['add_gt_x']) && !empty($_POST['graph_template_id'])) {
        /* ================= input validation ================= */
        input_validate_input_number(get_request_var_post('id'));
        input_validate_input_number(get_request_var_post('graph_template_id'));
        /* ==================================================== */
        db_execute_prepared('REPLACE INTO host_graph (host_id, graph_template_id) VALUES (?, ?)', array($_POST['id'], $_POST['graph_template_id']));
        api_plugin_hook_function('add_graph_template_to_host', array('host_id' => $_POST['id'], 'graph_template_id' => $_POST['graph_template_id']));
        header('Location: host.php?action=edit&id=' . $_POST['id']);
        exit;
    }
    if (isset($_POST['save_component_host']) && empty($_POST['add_dq_x'])) {
        if ($_POST['snmp_version'] == 3 && $_POST['snmp_password'] != $_POST['snmp_password_confirm']) {
            raise_message(4);
        } else {
            input_validate_input_number(get_request_var_post('id'));
            input_validate_input_number(get_request_var_post('host_template_id'));
            $host_id = api_device_save($_POST['id'], $_POST['host_template_id'], $_POST['description'], trim($_POST['hostname']), $_POST['snmp_community'], $_POST['snmp_version'], $_POST['snmp_username'], $_POST['snmp_password'], $_POST['snmp_port'], $_POST['snmp_timeout'], isset($_POST['disabled']) ? $_POST['disabled'] : '', $_POST['availability_method'], $_POST['ping_method'], $_POST['ping_port'], $_POST['ping_timeout'], $_POST['ping_retries'], $_POST['notes'], $_POST['snmp_auth_protocol'], $_POST['snmp_priv_passphrase'], $_POST['snmp_priv_protocol'], $_POST['snmp_context'], $_POST['max_oids'], $_POST['device_threads']);
        }
        header('Location: host.php?action=edit&id=' . (empty($host_id) ? $_POST['id'] : $host_id));
    }
}
Ejemplo n.º 2
0
function form_save() {
	if ((!empty($_POST["add_dq_y"])) && (!empty($_POST["snmp_query_id"]))) {
		db_execute("replace into host_snmp_query (host_id,snmp_query_id,reindex_method) values (" . $_POST["id"] . "," . $_POST["snmp_query_id"] . "," . $_POST["reindex_method"] . ")");

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

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

	if ((!empty($_POST["add_gt_y"])) && (!empty($_POST["graph_template_id"]))) {
		db_execute("replace into host_graph (host_id,graph_template_id) values (" . $_POST["id"] . "," . $_POST["graph_template_id"] . ")");

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

	if ((isset($_POST["save_component_host"])) && (empty($_POST["add_dq_y"]))) {
		$host_id = api_device_save($_POST["id"], $_POST["host_template_id"], $_POST["description"], $_POST["hostname"],
			$_POST["snmp_community"], $_POST["snmp_version"], $_POST["snmp_username"], $_POST["snmp_password"],
			$_POST["snmp_port"], $_POST["snmp_timeout"], (isset($_POST["disabled"]) ? $_POST["disabled"] : ""));

		if ((is_error_message()) || ($_POST["host_template_id"] != $_POST["_host_template_id"])) {
			header("Location: host.php?action=edit&id=" . (empty($host_id) ? $_POST["id"] : $host_id));
		}else{
			header("Location: host.php");
		}
	}
}
Ejemplo n.º 3
0
function sync_mactrack_to_cacti($mt_device)
{
    global $config;
    include_once $config['base_path'] . '/lib/functions.php';
    include_once $config['base_path'] . '/lib/api_device.php';
    include_once $config['base_path'] . '/lib/utility.php';
    # required due to missing include in lib/api_device.php
    /* do we want to 'Sync MacTrack Device to Cacti Device'
     * AND has the device already been assigned a 'valid' host_id
     * (aka: has the device been saved successfully) */
    if (read_config_option('mt_update_policy', true) == 3 && $mt_device['host_id'] > 0) {
        if (!isset($mt_device['snmp_engine_id'])) {
            $mt_device['snmp_engine_id'] = '';
        }
        # fetch current data for cacti device
        $cacti_device = db_fetch_row('SELECT * FROM host WHERE id=' . $mt_device['host_id']);
        if (sizeof($cacti_device)) {
            # update cacti device
            api_device_save($cacti_device['id'], $cacti_device['host_template_id'], $cacti_device['description'], $cacti_device['hostname'], $mt_device['snmp_readstring'], $mt_device['snmp_version'], $mt_device['snmp_username'], $mt_device['snmp_password'], $mt_device['snmp_port'], $mt_device['snmp_timeout'], $cacti_device['disabled'], $cacti_device['availability_method'], $cacti_device['ping_method'], $cacti_device['ping_port'], $cacti_device['ping_timeout'], $cacti_device['ping_retries'], $cacti_device['notes'], $mt_device['snmp_auth_protocol'], $mt_device['snmp_priv_passphrase'], $mt_device['snmp_priv_protocol'], $mt_device['snmp_context'], $mt_device['snmp_engine_id'], $mt_device['max_oids']);
            mactrack_debug('Cacti Device: (' . $cacti_device['id'] . ') successfully updated');
        }
    }
}
Ejemplo n.º 4
0
 } else {
     $disable = "on";
 }
 $notes = "netdot_id:" . $netdot_id;
 /* ----------------------------------------------------------------------------------------------------- */
 /* Add or Update Device */
 if ($hostId) {
     debug("{$description}: Updating device id {$hostId} ({$description}) template \"" . $hostTemplates[$template_id] . "\" using SNMP v{$snmp_ver} with community \"{$community}\"");
 } else {
     /* Do not bother creating device if it is disabled */
     if ($disable == "on") {
         continue;
     }
     echo "{$description}: Adding device ({$description}) template \"" . $hostTemplates[$template_id] . "\" using SNMP v{$snmp_ver} with community \"{$community}\"\n";
 }
 $hostId = api_device_save($hostId, $template_id, $description, $ip, $community, $snmp_ver, $snmp_username, $snmp_password, $snmp_port, $snmp_timeout, $disable, $avail, $ping_method, $ping_port, $ping_timeout, $ping_retries, $notes, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $max_oids, 1);
 if (is_error_message()) {
     echo "ERROR: {$description}: Failed device save\n";
     exit(1);
 } else {
     debug("{$description}: device saved: {$hostId}");
 }
 /* ----------------------------------------------------------------------------------------------------- */
 /* Add node to tree */
 $nodeId = 0;
 if (isset($hostNodes[$hostId])) {
     $nodeId = $hostNodes[$hostId];
     unset($hostNodes[$hostId]);
 }
 if ($nodeId) {
     debug("{$description}: host node already exists - id: ({$nodeId})");
Ejemplo n.º 5
0
function form_save()
{
    if (!empty($_POST["add_dq_y"]) && !empty($_POST["snmp_query_id"])) {
        /* ================= input validation ================= */
        input_validate_input_number(get_request_var_post("id"));
        input_validate_input_number(get_request_var_post("snmp_query_id"));
        input_validate_input_number(get_request_var_post("reindex_method"));
        /* ==================================================== */
        db_execute("replace into host_snmp_query (host_id,snmp_query_id,reindex_method) values (" . $_POST["id"] . "," . $_POST["snmp_query_id"] . "," . $_POST["reindex_method"] . ")");
        /* recache snmp data */
        run_data_query($_POST["id"], $_POST["snmp_query_id"]);
        header("Location: host.php?action=edit&id=" . $_POST["id"]);
        exit;
    }
    if (!empty($_POST["add_gt_y"]) && !empty($_POST["graph_template_id"])) {
        /* ================= input validation ================= */
        input_validate_input_number(get_request_var_post("id"));
        input_validate_input_number(get_request_var_post("graph_template_id"));
        /* ==================================================== */
        db_execute("replace into host_graph (host_id,graph_template_id) values (" . $_POST["id"] . "," . $_POST["graph_template_id"] . ")");
        header("Location: host.php?action=edit&id=" . $_POST["id"]);
        exit;
    }
    if (isset($_POST["save_component_host"]) && empty($_POST["add_dq_y"])) {
        if ($_POST["snmp_version"] == 3 && $_POST["snmp_password"] != $_POST["snmp_password_confirm"]) {
            raise_message(4);
        } else {
            $host_id = api_device_save($_POST["id"], $_POST["host_template_id"], $_POST["description"], trim($_POST["hostname"]), $_POST["snmp_community"], $_POST["snmp_version"], $_POST["snmp_username"], $_POST["snmp_password"], $_POST["snmp_port"], $_POST["snmp_timeout"], isset($_POST["disabled"]) ? $_POST["disabled"] : "", $_POST["availability_method"], $_POST["ping_method"], $_POST["ping_port"], $_POST["ping_timeout"], $_POST["ping_retries"], $_POST["notes"], $_POST["snmp_auth_protocol"], $_POST["snmp_priv_passphrase"], $_POST["snmp_priv_protocol"], $_POST["snmp_context"], $_POST["max_oids"]);
        }
        if (is_error_message() || $_POST["host_template_id"] != $_POST["_host_template_id"]) {
            header("Location: host.php?action=edit&id=" . (empty($host_id) ? $_POST["id"] : $host_id));
        } else {
            header("Location: host.php");
        }
    }
}
Ejemplo n.º 6
0
function form_save()
{
    /* modify for multi user start */
    if (!empty($_POST["id"])) {
        if (!check_host($_POST["id"])) {
            access_denied();
        }
    } else {
        if (!check_resource_count(RESOURCE_HOST)) {
            access_denied();
        }
    }
    /* modify for multi user end */
    if (!empty($_POST["add_dq_x"]) && !empty($_POST["snmp_query_id"])) {
        /* ================= input validation ================= */
        input_validate_input_number(get_request_var_post("id"));
        input_validate_input_number(get_request_var_post("snmp_query_id"));
        input_validate_input_number(get_request_var_post("reindex_method"));
        /* ==================================================== */
        db_execute("replace into host_snmp_query (host_id,snmp_query_id,reindex_method) values (" . $_POST["id"] . "," . $_POST["snmp_query_id"] . "," . $_POST["reindex_method"] . ")");
        /* recache snmp data */
        run_data_query($_POST["id"], $_POST["snmp_query_id"]);
        header("Location: host.php?action=edit&id=" . $_POST["id"]);
        exit;
    }
    if (!empty($_POST["add_gt_x"]) && !empty($_POST["graph_template_id"])) {
        /* ================= input validation ================= */
        input_validate_input_number(get_request_var_post("id"));
        input_validate_input_number(get_request_var_post("graph_template_id"));
        /* ==================================================== */
        db_execute("replace into host_graph (host_id,graph_template_id) values (" . $_POST["id"] . "," . $_POST["graph_template_id"] . ")");
        api_plugin_hook_function('add_graph_template_to_host', array("host_id" => $_POST["id"], "graph_template_id" => $_POST["graph_template_id"]));
        header("Location: host.php?action=edit&id=" . $_POST["id"]);
        exit;
    }
    if (isset($_POST["save_component_host"]) && empty($_POST["add_dq_x"])) {
        if ($_POST["snmp_version"] == 3 && $_POST["snmp_password"] != $_POST["snmp_password_confirm"]) {
            raise_message(4);
        } else {
            $host_id = api_device_save($_POST["id"], $_POST["host_template_id"], $_POST["description"], trim($_POST["hostname"]), $_POST["snmp_community"], $_POST["snmp_version"], $_POST["snmp_username"], $_POST["snmp_password"], $_POST["snmp_port"], $_POST["snmp_timeout"], isset($_POST["disabled"]) ? $_POST["disabled"] : "", $_POST["availability_method"], $_POST["ping_method"], $_POST["ping_port"], $_POST["ping_timeout"], $_POST["ping_retries"], $_POST["notes"], $_POST["snmp_auth_protocol"], $_POST["snmp_priv_passphrase"], $_POST["snmp_priv_protocol"], $_POST["snmp_context"], $_POST["max_oids"], $_POST["device_threads"]);
            /* modify for multi user start */
            if ($_SESSION["permission"] <= ACCESS_ADMINISTRATOR) {
                if (!db_fetch_cell("SELECT graph_tree_items.id FROM graph_tree_items WHERE graph_tree_items.host_id = '" . $host_id . "'")) {
                    exec("php ./cli/add_tree.php --type=node --node-type=host --tree-id=" . $_SESSION["private_tree_id"] . " --host-id=" . $host_id . " --host-group-style=1");
                    exec("php ./cli/add_perms.php --user-id=" . $_SESSION["sess_user_id"] . " --item-type=host --item-id=" . $host_id);
                }
                /* clear graph tree cache on save - affects current user only, other users should see changes in <5 minutes */
                if (isset($_SESSION['dhtml_tree'])) {
                    unset($_SESSION['dhtml_tree']);
                }
            }
            /* modify for multi user end */
        }
        header("Location: host.php?action=edit&id=" . (empty($host_id) ? $_POST["id"] : $host_id));
    }
}
Ejemplo n.º 7
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}");
            }
        }
    }
}
Ejemplo n.º 8
0
function sync_mactrack_to_cacti($mt_device) {
	global $config;
	include_once($config["base_path"] . "/lib/functions.php");
	include_once($config["base_path"] . "/lib/api_device.php");
	include_once($config["base_path"] . "/lib/utility.php"); # required due to missing include in lib/api_device.php

	/* do we want to "Sync MacTrack Device to Cacti Device"
	 * AND has the device already been assigned a "valid" host_id 
	 * (aka: has the device been saved successfully) */
	if ((read_config_option("mt_update_policy", true) == 3) &&
		($mt_device["host_id"] > 0)) {

		# fetch current data for cacti device
		$cacti_device = db_fetch_row("SELECT * FROM host WHERE id=" . $mt_device["host_id"]);

		if(sizeof($cacti_device)) {

			# update cacti device
			api_device_save($cacti_device["id"], $cacti_device["host_template_id"],
			$cacti_device["description"], $cacti_device["hostname"],
			$mt_device["snmp_readstring"], $mt_device["snmp_version"], $mt_device["snmp_username"],
			$mt_device["snmp_password"], $mt_device["snmp_port"], $mt_device["snmp_timeout"],
			$cacti_device["disabled"], $cacti_device["availability_method"], $cacti_device["ping_method"], $cacti_device["ping_port"],
			$cacti_device["ping_timeout"], $cacti_device["ping_retries"], $cacti_device["notes"],
			$mt_device["snmp_auth_protocol"], $mt_device["snmp_priv_passphrase"], $mt_device["snmp_priv_protocol"],
			$mt_device["snmp_context"], $mt_device["max_oids"]);

			mactrack_debug("Cacti Device: (" . $cacti_device["id"] . ") successfully updated");
		}
	}

}
Ejemplo n.º 9
0
function api_device_form_save() {
	/*
	 * loop for all possible changes of reindex_method
	 * post variable is build like this
	 * 		reindex_method_device_<device_id>_query_<snmp_query_id>_method_<old_reindex_method>
	 * if values of this variable differs from <old_reindex_method>, we will have to update
	 */
	$reindex_performed = false;
	while (list($var,$val) = each($_POST)) {
		if (preg_match("/^reindex_method_device_([0-9]+)_query_([0-9]+)_method_([0-9]+)$/", $var, $matches)) {
			/* ================= input validation ================= */
			input_validate_input_number(get_request_var_post("id"));
			input_validate_input_number($matches[1]); # device
			input_validate_input_number($matches[2]); # snmp_query_id
			input_validate_input_number($matches[3]); # old reindex method
			$reindex_method = $val;
			input_validate_input_number($reindex_method); # new reindex_method
			/* ==================================================== */

			# change reindex method of this very item
			if ( $reindex_method != $matches[3]) {
				db_execute("replace into device_snmp_query (device_id,snmp_query_id,reindex_method) values (" . $matches[1] . "," . $matches[2] . "," . $reindex_method . ")");

				/* recache snmp data */
				run_data_query($matches[1], $matches[2]);
				$reindex_performed = true;
			}
		}
	}

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

		db_execute("replace into device_snmp_query (device_id,snmp_query_id,reindex_method) values (" . get_request_var_post("id") . "," . get_request_var_post("snmp_query_id") . "," . get_request_var_post("reindex_method") . ")");

		/* recache snmp data */
		run_data_query(get_request_var_post("id"), get_request_var_post("snmp_query_id"));

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

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

		db_execute("replace into device_graph (device_id,graph_template_id) values (" . get_request_var_post("id") . "," . get_request_var_post("graph_template_id") . ")");

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

	/* save basic device information during first run, device_template should have bee selected */
	if (isset($_POST["save_basic_device"])) {
		/* device template was given, so fetch defaults from it */
		$use_template = false;
		if ($_POST["device_template_id"] != 0) {
			$device_template = db_fetch_row("SELECT *
				FROM device_template
				WHERE id=" . $_POST["device_template_id"]);
			if (($device_template["override_defaults"] == CHECKED) &&
				(($device_template["override_permitted"] == CHECKED) &&
				($_POST["template_enabled"] == CHECKED)) || ($device_template["override_permitted"] != CHECKED)) {
				$use_template = true;
				$device_template["template_enabled"] = CHECKED;
			}
		}

		if (!$use_template) {
			$device_template["snmp_community"]        = get_request_var_post("snmp_community");
			$device_template["snmp_version"]          = get_request_var_post("snmp_version");
			$device_template["snmp_username"]         = get_request_var_post("snmp_username");
			$device_template["snmp_password"]         = get_request_var_post("snmp_password");
			$device_template["snmp_port"]             = get_request_var_post("snmp_port");
			$device_template["snmp_timeout"]          = get_request_var_post("snmp_timeout");
			$device_template["availability_method"]   = get_request_var_post("availability_method");
			$device_template["ping_method"]           = get_request_var_post("ping_method");
			$device_template["ping_port"]             = get_request_var_post("ping_port");
			$device_template["ping_timeout"]          = get_request_var_post("ping_timeout");
			$device_template["ping_retries"]          = get_request_var_post("ping_retries");
			$device_template["snmp_auth_protocol"]    = get_request_var_post("snmp_auth_protocol");
			$device_template["snmp_priv_passphrase"]  = get_request_var_post("snmp_priv_passphrase");
			$device_template["snmp_priv_protocol"]    = get_request_var_post("snmp_priv_protocol");
			$device_template["snmp_context"]          = get_request_var_post("snmp_context");
			$device_template["max_oids"]              = get_request_var_post("max_oids");
			$device_template["device_threads"]        = get_request_var_post("device_threads");
			$device_template["template_enabled"]      = "";
		}

		$device_template["notes"]    = ""; /* no support for notes in a device template */
		$device_template["disabled"] = ""; /* no support for disabling in a device template */
		$device_id = api_device_save($_POST["id"], $_POST["site_id"], $_POST["poller_id"], $_POST["device_template_id"], $_POST["description"],
			get_request_var_post("hostname"), $device_template["snmp_community"], $device_template["snmp_version"],
			$device_template["snmp_username"], $device_template["snmp_password"],
			$device_template["snmp_port"], $device_template["snmp_timeout"],
			$device_template["disabled"],
			$device_template["availability_method"], $device_template["ping_method"],
			$device_template["ping_port"], $device_template["ping_timeout"],
			$device_template["ping_retries"], $device_template["notes"],
			$device_template["snmp_auth_protocol"], $device_template["snmp_priv_passphrase"],
			$device_template["snmp_priv_protocol"], $device_template["snmp_context"], $device_template["max_oids"],
			$device_template["device_threads"], $device_template["template_enabled"]);

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

	if ((isset($_POST["save_component_device"])) && (empty($_POST["add_dq_y"]))) {
		if (get_request_var_post("snmp_version") == 3 && (get_request_var_post("snmp_password") != get_request_var_post("snmp_password_confirm"))) {
			raise_message(4);
		}else{
			$device_id = api_device_save($_POST["id"], $_POST["site_id"], $_POST["poller_id"], $_POST["device_template_id"], $_POST["description"],
				trim(get_request_var_post("hostname")), get_request_var_post("snmp_community"), get_request_var_post("snmp_version"),
				get_request_var_post("snmp_username"), get_request_var_post("snmp_password"),
				get_request_var_post("snmp_port"), get_request_var_post("snmp_timeout"),
				(isset($_POST["disabled"]) ? get_request_var_post("disabled") : ""),
				get_request_var_post("availability_method"), get_request_var_post("ping_method"),
				get_request_var_post("ping_port"), get_request_var_post("ping_timeout"),
				get_request_var_post("ping_retries"), get_request_var_post("notes"),
				get_request_var_post("snmp_auth_protocol"), get_request_var_post("snmp_priv_passphrase"),
				get_request_var_post("snmp_priv_protocol"), get_request_var_post("snmp_context"),
				get_request_var_post("max_oids"), get_request_var_post("device_threads"),
				(isset($_POST["template_enabled"]) ? get_request_var_post("template_enabled") : ""));
		}

		if ((is_error_message()) || ($_POST["device_template_id"] != $_POST["hidden_device_template_id"]) || $reindex_performed) {
			header("Location: devices.php?action=edit&id=" . (empty($device_id) ? $_POST["id"] : $device_id));
		}else{
			header("Location: devices.php");
		}
		exit;
	}
}
Ejemplo n.º 10
0
		$device['description'].", ".$device['hostname'].", ".$device_template['snmp_community'].", ".
		$device_template['snmp_version'].", ". $device_template['snmp_username'].", ".
		$device_template['snmp_password'].", ".	$device_template['snmp_port'].", ".
		$device_template['snmp_timeout'].", ". $device_template['disabled'].", ".
		$device_template['availability_method'].", ". $device_template['ping_method'].", ".
		$device_template['ping_port'].", ". $device_template['ping_timeout'].", ".
		$device_template['ping_retries'].", ". $device_template['notes'].", ".
		$device_template['snmp_auth_protocol'].", ". $device_template['snmp_priv_passphrase'].", ".
		$device_template['snmp_priv_protocol'].", ". $device_template['snmp_context'].", ". $device_template['max_oids']. ", ". $device_template['device_threads'].")\n");
	} else {
		$device_id = api_device_save(0, $device["site_id"], $device["poller_id"], $device["device_template_id"],
		$device["description"], $device["hostname"],
		$device_template["snmp_community"], $device_template["snmp_version"],
		$device_template["snmp_username"], $device_template["snmp_password"],
		$device_template["snmp_port"], $device_template["snmp_timeout"],
		$device_template["disabled"],
		$device_template["availability_method"], $device_template["ping_method"],
		$device_template["ping_port"], $device_template["ping_timeout"],
		$device_template["ping_retries"], $device_template["notes"],
		$device_template["snmp_auth_protocol"], $device_template["snmp_priv_passphrase"],
		$device_template["snmp_priv_protocol"], $device_template["snmp_context"], $device_template["max_oids"], $device_template["device_threads"]);

		if (is_error_message()) {
			echo __("ERROR: Failed to add this device") . "\n";
			print_r($_SESSION["sess_messages"]); global $messages;
			foreach (array_keys($_SESSION["sess_messages"]) as $current_message_id) {
				if (isset($messages[$current_message_id])) {
					print_r($messages[$current_message_id]);
				}
			}
			exit(1);