Ejemplo n.º 1
0
function api_mactrack_device_save($device_id, $host_id, $site_id, $hostname,
	$device_name, $scan_type, $snmp_options, $snmp_readstring,
	$snmp_version, $snmp_username, $snmp_password, $snmp_auth_protocol,
	$snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context,
	$snmp_port, $snmp_timeout, $snmp_retries, $max_oids,
	$ignorePorts, $notes, $user_name, $user_password, $term_type,
	$private_key_path, $disabled) {
	global $config;
	include_once($config["base_path"] . "/plugins/mactrack/lib/mactrack_functions.php");

	$save["device_id"] = $device_id;
	$save["host_id"] = $host_id;
	$save["site_id"] = $site_id;
	$save["hostname"] = form_input_validate($hostname, "hostname", "", false, 3);
	$save["device_name"] = form_input_validate($device_name, "device_name", "", false, 3);
	$save["notes"] = form_input_validate($notes, "notes", "", true, 3);
	$save["scan_type"] = form_input_validate($scan_type, "scan_type", "", false, 3);
	$save["snmp_options"] = form_input_validate($snmp_options, "snmp_options", "^[0-9]+$", true, 3);
	$save["snmp_readstring"] = form_input_validate($snmp_readstring, "snmp_readstring", "", true, 3); # for SNMP V3, this is optional
	$save["snmp_version"] = form_input_validate($snmp_version, "snmp_version", "", false, 3);
	$save["snmp_username"]        = form_input_validate($snmp_username, "snmp_username", "", true, 3);
	$save["snmp_password"]        = form_input_validate($snmp_password, "snmp_password", "", true, 3);
	$save["snmp_auth_protocol"]   = form_input_validate($snmp_auth_protocol, "snmp_auth_protocol", "", true, 3);
	$save["snmp_priv_passphrase"] = form_input_validate($snmp_priv_passphrase, "snmp_priv_passphrase", "", true, 3);
	$save["snmp_priv_protocol"]   = form_input_validate($snmp_priv_protocol, "snmp_priv_protocol", "", true, 3);
	$save["snmp_context"]         = form_input_validate($snmp_context, "snmp_context", "", true, 3);
	$save["snmp_port"] = form_input_validate($snmp_port, "snmp_port", "^[0-9]+$", false, 3);
	$save["snmp_timeout"] = form_input_validate($snmp_timeout, "snmp_timeout", "^[0-9]+$", false, 3);
	$save["snmp_retries"] = form_input_validate($snmp_retries, "snmp_retries", "^[0-9]+$", false, 3);
	$save["max_oids"] = form_input_validate($max_oids, "max_oids", "^[0-9]+$", false, 3);
	$save["user_name"] = form_input_validate($user_name, "user_name", "", true, 3);
	$save["user_password"] = form_input_validate($user_password, "user_password", "", true, 3);
	$save["ignorePorts"] = form_input_validate($ignorePorts, "ignorePorts", "", true, 3);
	$save["term_type"] = form_input_validate($term_type, "term_type", "", true, 3);
	$save["private_key_path"] = form_input_validate($private_key_path, "private_key_path", "", true, 3);
	$save["disabled"] = form_input_validate($disabled, "disabled", "", true, 3);

	$device_id = 0;
	if (!is_error_message()) {
		$device_id = sql_save($save, "mac_track_devices", "device_id");

		if ($device_id) {
			raise_message(1);
			sync_mactrack_to_cacti($save);
		}else{
			raise_message(2);
			mactrack_debug("ERROR: Cacti Device: ($device_id/$host_id): $hostname, error on save: " . serialize($save));
		}
	} else {
		mactrack_debug("ERROR: Cacti Device: ($device_id/$host_id): $hostname, error on verify: " . serialize($save));
	}

	return $device_id;
}
Ejemplo n.º 2
0
function api_mactrack_device_save($device_id, $host_id, $site_id, $hostname, $device_name, $scan_type, $snmp_options, $snmp_readstring, $snmp_version, $snmp_username, $snmp_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_engine_id, $snmp_port, $snmp_timeout, $snmp_retries, $max_oids, $ignorePorts, $notes, $user_name, $user_password, $term_type, $private_key_path, $disabled)
{
    global $config;
    include_once $config['base_path'] . '/plugins/mactrack/lib/mactrack_functions.php';
    $save['device_id'] = $device_id;
    $save['host_id'] = $host_id;
    $save['site_id'] = $site_id;
    $save['hostname'] = form_input_validate($hostname, 'hostname', '', false, 3);
    $save['device_name'] = form_input_validate($device_name, 'device_name', '', false, 3);
    $save['notes'] = form_input_validate($notes, 'notes', '', true, 3);
    $save['scan_type'] = form_input_validate($scan_type, 'scan_type', '', false, 3);
    $save['snmp_options'] = form_input_validate($snmp_options, 'snmp_options', '^[0-9]+$', true, 3);
    $save['snmp_readstring'] = form_input_validate($snmp_readstring, 'snmp_readstring', '', true, 3);
    # for SNMP V3, this is optional
    $save['snmp_version'] = form_input_validate($snmp_version, 'snmp_version', '', false, 3);
    $save['snmp_username'] = form_input_validate($snmp_username, 'snmp_username', '', true, 3);
    $save['snmp_password'] = form_input_validate($snmp_password, 'snmp_password', '', true, 3);
    $save['snmp_auth_protocol'] = form_input_validate($snmp_auth_protocol, 'snmp_auth_protocol', '', true, 3);
    $save['snmp_priv_passphrase'] = form_input_validate($snmp_priv_passphrase, 'snmp_priv_passphrase', '', true, 3);
    $save['snmp_priv_protocol'] = form_input_validate($snmp_priv_protocol, 'snmp_priv_protocol', '', true, 3);
    $save['snmp_context'] = form_input_validate($snmp_context, 'snmp_context', '', true, 3);
    $save['snmp_engine_id'] = form_input_validate($snmp_engine_id, 'snmp_engine_id', '', true, 3);
    $save['snmp_port'] = form_input_validate($snmp_port, 'snmp_port', '^[0-9]+$', false, 3);
    $save['snmp_timeout'] = form_input_validate($snmp_timeout, 'snmp_timeout', '^[0-9]+$', false, 3);
    $save['snmp_retries'] = form_input_validate($snmp_retries, 'snmp_retries', '^[0-9]+$', false, 3);
    $save['max_oids'] = form_input_validate($max_oids, 'max_oids', '^[0-9]+$', false, 3);
    $save['user_name'] = form_input_validate($user_name, 'user_name', '', true, 3);
    $save['user_password'] = form_input_validate($user_password, 'user_password', '', true, 3);
    $save['ignorePorts'] = form_input_validate($ignorePorts, 'ignorePorts', '', true, 3);
    $save['term_type'] = form_input_validate($term_type, 'term_type', '', true, 3);
    $save['private_key_path'] = form_input_validate($private_key_path, 'private_key_path', '', true, 3);
    $save['disabled'] = form_input_validate($disabled, 'disabled', '', true, 3);
    $device_id = 0;
    if (!is_error_message()) {
        $device_id = sql_save($save, 'mac_track_devices', 'device_id');
        if ($device_id) {
            raise_message(1);
            sync_mactrack_to_cacti($save);
        } else {
            raise_message(2);
            mactrack_debug("ERROR: Cacti Device: ({$device_id}/{$host_id}): {$hostname}, error on save: " . serialize($save));
        }
    } else {
        mactrack_debug("ERROR: Cacti Device: ({$device_id}/{$host_id}): {$hostname}, error on verify: " . serialize($save));
    }
    return $device_id;
}
Ejemplo n.º 3
0
function valid_snmp_device(&$device)
{
    global $config;
    include_once $config["base_path"] . "/plugins/mactrack/mactrack_actions.php";
    /* initialize variable */
    $host_up = FALSE;
    $device["snmp_status"] = HOST_DOWN;
    /* force php to return numeric oid's */
    if (function_exists("snmp_set_oid_numeric_print")) {
        snmp_set_oid_numeric_print(TRUE);
    }
    /* if the first read did not work, loop until found */
    $snmp_sysObjectID = @cacti_snmp_get($device["hostname"], $device["snmp_readstring"], ".1.3.6.1.2.1.1.2.0", $device["snmp_version"], $device["snmp_username"], $device["snmp_password"], $device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"], $device["snmp_context"], $device["snmp_port"], $device["snmp_timeout"], $device["snmp_retries"]);
    $snmp_sysObjectID = str_replace("enterprises", ".1.3.6.1.4.1", $snmp_sysObjectID);
    $snmp_sysObjectID = str_replace("OID: ", "", $snmp_sysObjectID);
    $snmp_sysObjectID = str_replace(".iso", ".1", $snmp_sysObjectID);
    if (strlen($snmp_sysObjectID) > 0 && !substr_count($snmp_sysObjectID, "No Such Object") && !substr_count($snmp_sysObjectID, "Error In")) {
        $snmp_sysObjectID = trim(str_replace("\"", "", $snmp_sysObjectID));
        $host_up = TRUE;
        $device["snmp_status"] = HOST_UP;
    } else {
        /* loop through the default and then other common for the correct answer */
        $snmp_options = db_fetch_assoc("SELECT * from mac_track_snmp_items WHERE snmp_id=" . $device["snmp_options"] . " ORDER BY sequence");
        if (sizeof($snmp_options)) {
            foreach ($snmp_options as $snmp_option) {
                # update $device for later db update via db_update_device_status
                $device["snmp_readstring"] = $snmp_option["snmp_readstring"];
                $device["snmp_version"] = $snmp_option["snmp_version"];
                $device["snmp_username"] = $snmp_option["snmp_username"];
                $device["snmp_password"] = $snmp_option["snmp_password"];
                $device["snmp_auth_protocol"] = $snmp_option["snmp_auth_protocol"];
                $device["snmp_priv_passphrase"] = $snmp_option["snmp_priv_passphrase"];
                $device["snmp_priv_protocol"] = $snmp_option["snmp_priv_protocol"];
                $device["snmp_context"] = $snmp_option["snmp_context"];
                $device["snmp_port"] = $snmp_option["snmp_port"];
                $device["snmp_timeout"] = $snmp_option["snmp_timeout"];
                $device["snmp_retries"] = $snmp_option["snmp_retries"];
                $snmp_sysObjectID = @cacti_snmp_get($device["hostname"], $device["snmp_readstring"], ".1.3.6.1.2.1.1.2.0", $device["snmp_version"], $device["snmp_username"], $device["snmp_password"], $device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"], $device["snmp_context"], $device["snmp_port"], $device["snmp_timeout"], $device["snmp_retries"]);
                $snmp_sysObjectID = str_replace("enterprises", ".1.3.6.1.4.1", $snmp_sysObjectID);
                $snmp_sysObjectID = str_replace("OID: ", "", $snmp_sysObjectID);
                $snmp_sysObjectID = str_replace(".iso", ".1", $snmp_sysObjectID);
                if (strlen($snmp_sysObjectID) > 0 && !substr_count($snmp_sysObjectID, "No Such Object") && !substr_count($snmp_sysObjectID, "Error In")) {
                    $snmp_sysObjectID = trim(str_replace("\"", "", $snmp_sysObjectID));
                    $device["snmp_readstring"] = $snmp_option["snmp_readstring"];
                    $device["snmp_status"] = HOST_UP;
                    $host_up = TRUE;
                    # update cacti device, if required
                    sync_mactrack_to_cacti($device);
                    # update to mactrack itself is done by db_update_device_status in mactrack_scanner.php
                    # TODO: if db_update_device_status would use api_mactrack_device_save, there would be no need to call sync_mactrack_to_cacti here
                    # but currently the parameter set doesn't match
                    mactrack_debug("Result found on Option Set (" . $snmp_option["snmp_id"] . ") Sequence (" . $snmp_option["sequence"] . "): " . $snmp_sysObjectID);
                    break;
                    # no need to continue if we have a match
                } else {
                    $device["snmp_status"] = HOST_DOWN;
                    $host_up = FALSE;
                }
            }
        }
    }
    if ($host_up) {
        $device["snmp_sysObjectID"] = $snmp_sysObjectID;
        /* get system name */
        $snmp_sysName = @cacti_snmp_get($device["hostname"], $device["snmp_readstring"], ".1.3.6.1.2.1.1.5.0", $device["snmp_version"], $device["snmp_username"], $device["snmp_password"], $device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"], $device["snmp_context"], $device["snmp_port"], $device["snmp_timeout"], $device["snmp_retries"]);
        if (strlen($snmp_sysName) > 0) {
            $snmp_sysName = trim(strtr($snmp_sysName, "\"", " "));
            $device["snmp_sysName"] = $snmp_sysName;
        }
        /* get system location */
        $snmp_sysLocation = @cacti_snmp_get($device["hostname"], $device["snmp_readstring"], ".1.3.6.1.2.1.1.6.0", $device["snmp_version"], $device["snmp_username"], $device["snmp_password"], $device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"], $device["snmp_context"], $device["snmp_port"], $device["snmp_timeout"], $device["snmp_retries"]);
        if (strlen($snmp_sysLocation) > 0) {
            $snmp_sysLocation = trim(strtr($snmp_sysLocation, "\"", " "));
            $device["snmp_sysLocation"] = $snmp_sysLocation;
        }
        /* get system contact */
        $snmp_sysContact = @cacti_snmp_get($device["hostname"], $device["snmp_readstring"], ".1.3.6.1.2.1.1.4.0", $device["snmp_version"], $device["snmp_username"], $device["snmp_password"], $device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"], $device["snmp_context"], $device["snmp_port"], $device["snmp_timeout"], $device["snmp_retries"]);
        if (strlen($snmp_sysContact) > 0) {
            $snmp_sysContact = trim(strtr($snmp_sysContact, "\"", " "));
            $device["snmp_sysContact"] = $snmp_sysContact;
        }
        /* get system description */
        $snmp_sysDescr = @cacti_snmp_get($device["hostname"], $device["snmp_readstring"], ".1.3.6.1.2.1.1.1.0", $device["snmp_version"], $device["snmp_username"], $device["snmp_password"], $device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"], $device["snmp_context"], $device["snmp_port"], $device["snmp_timeout"], $device["snmp_retries"]);
        if (strlen($snmp_sysDescr) > 0) {
            $snmp_sysDescr = trim(strtr($snmp_sysDescr, "\"", " "));
            $device["snmp_sysDescr"] = $snmp_sysDescr;
        }
        /* get system uptime */
        $snmp_sysUptime = @cacti_snmp_get($device["hostname"], $device["snmp_readstring"], ".1.3.6.1.2.1.1.3.0", $device["snmp_version"], $device["snmp_username"], $device["snmp_password"], $device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"], $device["snmp_context"], $device["snmp_port"], $device["snmp_timeout"], $device["snmp_retries"]);
        if (strlen($snmp_sysUptime) > 0) {
            $snmp_sysUptime = trim(strtr($snmp_sysUptime, "\"", " "));
            $device["snmp_sysUptime"] = $snmp_sysUptime;
        }
    }
    return $host_up;
}
Ejemplo n.º 4
0
function valid_snmp_device(&$device)
{
    global $config;
    include_once $config['base_path'] . '/plugins/mactrack/mactrack_actions.php';
    /* initialize variable */
    $host_up = FALSE;
    $device['snmp_status'] = HOST_DOWN;
    /* force php to return numeric oid's */
    cacti_oid_numeric_format();
    /* if the first read did not work, loop until found */
    $snmp_sysObjectID = @cacti_snmp_get($device['hostname'], $device['snmp_readstring'], '.1.3.6.1.2.1.1.2.0', $device['snmp_version'], $device['snmp_username'], $device['snmp_password'], $device['snmp_auth_protocol'], $device['snmp_priv_passphrase'], $device['snmp_priv_protocol'], $device['snmp_context'], $device['snmp_port'], $device['snmp_timeout'], $device['snmp_retries']);
    $snmp_sysObjectID = str_replace('enterprises', '.1.3.6.1.4.1', $snmp_sysObjectID);
    $snmp_sysObjectID = str_replace('OID: ', '', $snmp_sysObjectID);
    $snmp_sysObjectID = str_replace('.iso', '.1', $snmp_sysObjectID);
    if (strlen($snmp_sysObjectID) > 0 && !substr_count($snmp_sysObjectID, 'No Such Object') && !substr_count($snmp_sysObjectID, 'Error In')) {
        $snmp_sysObjectID = trim(str_replace('"', '', $snmp_sysObjectID));
        $host_up = TRUE;
        $device['snmp_status'] = HOST_UP;
    } else {
        /* loop through the default and then other common for the correct answer */
        $snmp_options = db_fetch_assoc_prepared('SELECT * from mac_track_snmp_items WHERE snmp_id = ? ORDER BY sequence', array($device['snmp_options']));
        if (sizeof($snmp_options)) {
            foreach ($snmp_options as $snmp_option) {
                # update $device for later db update via db_update_device_status
                $device['snmp_readstring'] = $snmp_option['snmp_readstring'];
                $device['snmp_version'] = $snmp_option['snmp_version'];
                $device['snmp_username'] = $snmp_option['snmp_username'];
                $device['snmp_password'] = $snmp_option['snmp_password'];
                $device['snmp_auth_protocol'] = $snmp_option['snmp_auth_protocol'];
                $device['snmp_priv_passphrase'] = $snmp_option['snmp_priv_passphrase'];
                $device['snmp_priv_protocol'] = $snmp_option['snmp_priv_protocol'];
                $device['snmp_context'] = $snmp_option['snmp_context'];
                $device['snmp_port'] = $snmp_option['snmp_port'];
                $device['snmp_timeout'] = $snmp_option['snmp_timeout'];
                $device['snmp_retries'] = $snmp_option['snmp_retries'];
                $snmp_sysObjectID = @cacti_snmp_get($device['hostname'], $device['snmp_readstring'], '.1.3.6.1.2.1.1.2.0', $device['snmp_version'], $device['snmp_username'], $device['snmp_password'], $device['snmp_auth_protocol'], $device['snmp_priv_passphrase'], $device['snmp_priv_protocol'], $device['snmp_context'], $device['snmp_port'], $device['snmp_timeout'], $device['snmp_retries']);
                $snmp_sysObjectID = str_replace('enterprises', '.1.3.6.1.4.1', $snmp_sysObjectID);
                $snmp_sysObjectID = str_replace('OID: ', '', $snmp_sysObjectID);
                $snmp_sysObjectID = str_replace('.iso', '.1', $snmp_sysObjectID);
                if (strlen($snmp_sysObjectID) > 0 && !substr_count($snmp_sysObjectID, 'No Such Object') && !substr_count($snmp_sysObjectID, 'Error In')) {
                    $snmp_sysObjectID = trim(str_replace("'", '', $snmp_sysObjectID));
                    $device['snmp_readstring'] = $snmp_option['snmp_readstring'];
                    $device['snmp_status'] = HOST_UP;
                    $host_up = TRUE;
                    # update cacti device, if required
                    sync_mactrack_to_cacti($device);
                    # update to mactrack itself is done by db_update_device_status in mactrack_scanner.php
                    # TODO: if db_update_device_status would use api_mactrack_device_save, there would be no need to call sync_mactrack_to_cacti here
                    # but currently the parameter set doesn't match
                    mactrack_debug('Result found on Option Set (' . $snmp_option['snmp_id'] . ') Sequence (' . $snmp_option['sequence'] . '): ' . $snmp_sysObjectID);
                    break;
                    # no need to continue if we have a match
                } else {
                    $device['snmp_status'] = HOST_DOWN;
                    $host_up = FALSE;
                }
            }
        }
    }
    if ($host_up) {
        $device['snmp_sysObjectID'] = $snmp_sysObjectID;
        /* get system name */
        $snmp_sysName = @cacti_snmp_get($device['hostname'], $device['snmp_readstring'], '.1.3.6.1.2.1.1.5.0', $device['snmp_version'], $device['snmp_username'], $device['snmp_password'], $device['snmp_auth_protocol'], $device['snmp_priv_passphrase'], $device['snmp_priv_protocol'], $device['snmp_context'], $device['snmp_port'], $device['snmp_timeout'], $device['snmp_retries']);
        if (strlen($snmp_sysName) > 0) {
            $snmp_sysName = trim(strtr($snmp_sysName, '"', ' '));
            $device['snmp_sysName'] = $snmp_sysName;
        }
        /* get system location */
        $snmp_sysLocation = @cacti_snmp_get($device['hostname'], $device['snmp_readstring'], '.1.3.6.1.2.1.1.6.0', $device['snmp_version'], $device['snmp_username'], $device['snmp_password'], $device['snmp_auth_protocol'], $device['snmp_priv_passphrase'], $device['snmp_priv_protocol'], $device['snmp_context'], $device['snmp_port'], $device['snmp_timeout'], $device['snmp_retries']);
        if (strlen($snmp_sysLocation) > 0) {
            $snmp_sysLocation = trim(strtr($snmp_sysLocation, '"', ' '));
            $device['snmp_sysLocation'] = $snmp_sysLocation;
        }
        /* get system contact */
        $snmp_sysContact = @cacti_snmp_get($device['hostname'], $device['snmp_readstring'], '.1.3.6.1.2.1.1.4.0', $device['snmp_version'], $device['snmp_username'], $device['snmp_password'], $device['snmp_auth_protocol'], $device['snmp_priv_passphrase'], $device['snmp_priv_protocol'], $device['snmp_context'], $device['snmp_port'], $device['snmp_timeout'], $device['snmp_retries']);
        if (strlen($snmp_sysContact) > 0) {
            $snmp_sysContact = trim(strtr($snmp_sysContact, '"', ' '));
            $device['snmp_sysContact'] = $snmp_sysContact;
        }
        /* get system description */
        $snmp_sysDescr = @cacti_snmp_get($device['hostname'], $device['snmp_readstring'], '.1.3.6.1.2.1.1.1.0', $device['snmp_version'], $device['snmp_username'], $device['snmp_password'], $device['snmp_auth_protocol'], $device['snmp_priv_passphrase'], $device['snmp_priv_protocol'], $device['snmp_context'], $device['snmp_port'], $device['snmp_timeout'], $device['snmp_retries']);
        if (strlen($snmp_sysDescr) > 0) {
            $snmp_sysDescr = trim(strtr($snmp_sysDescr, '"', ' '));
            $device['snmp_sysDescr'] = $snmp_sysDescr;
        }
        /* get system uptime */
        $snmp_sysUptime = @cacti_snmp_get($device['hostname'], $device['snmp_readstring'], '.1.3.6.1.2.1.1.3.0', $device['snmp_version'], $device['snmp_username'], $device['snmp_password'], $device['snmp_auth_protocol'], $device['snmp_priv_passphrase'], $device['snmp_priv_protocol'], $device['snmp_context'], $device['snmp_port'], $device['snmp_timeout'], $device['snmp_retries']);
        if (strlen($snmp_sysUptime) > 0) {
            $snmp_sysUptime = trim(strtr($snmp_sysUptime, '"', ' '));
            $device['snmp_sysUptime'] = $snmp_sysUptime;
        }
    }
    return $host_up;
}