function __set($name, $value)
 {
     switch ($name) {
         case 'quick_print':
             snmp_set_quick_print($value);
             break;
         case 'oid_output_format':
             /* needs php >= 5.2.0 */
             snmp_set_oid_output_format($value);
             break;
         case 'enum_print':
             snmp_set_enum_print($value);
             break;
         case 'valueretrieval':
             snmp_set_valueretrieval($value);
             break;
         default:
             $trace = debug_backtrace();
             trigger_error('Undefined property via __set(): ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_NOTICE);
             return null;
     }
 }
Example #2
0
include 'functions.php';
// Переводим время для snmp - функций из секунд в микросекунды
$timeout = $timeout * 1000000;
$writetimeout = $writetimeout * 1000000;
// Для модели DGS-3100-24TG увеличиваем время ожидания вдвое
if ($ModelType == 'DGS-3100-24TG') {
    $timeout = $timeout * 2;
    $max_exec_time = $max_exec_time * 2;
}
// Устанавливаем максимальное время исполнения скрипта
ini_set('max_execution_time', $max_exec_time);
// Устанавливаем сокращенный вывод для snmp-запросов
snmp_set_quick_print(1);
// Устанавливаем числовой вывод для snmp-запросов если версия PHP старше 5.2
if (substr(phpversion(), 0, 3) > 5.2) {
    @snmp_set_enum_print(1);
}
// Устанавливаем тип вывода для snmp-запросов
snmp_set_valueretrieval(0);
// По умолчанию ошибок не обнаружено, о чем сообщаем в значении переменной
$noerrors = "true";
// Определяем значение версии модуля на случай, если оно не определено в самом модуле
$modulever = '0.00';
// Текущая версия скрипта
$current_version = '0.99b';
// Подключаем блок c информацией о коммутаторе
include 'infosw.php';
// Подключаем основной модуль
@(include './modules/' . $module . '_mod.php');
//<--Начало блока:'Формирование верхнего меню со вкладками'--
// Говорим, что по дефолту у нас как минимум 1 колонка (модуль)
Example #3
0
function cacti_snmp_walk($hostname, $community, $oid, $version, $username, $password, $auth_proto, $priv_pass, $priv_proto, $context, $port = 161, $timeout = 500, $retries = 0, $max_oids = 10, $method = SNMP_VALUE_LIBRARY, $environ = SNMP_POLLER)
{
    global $config, $banned_snmp_strings, $php_errormsg;
    $snmp_oid_included = true;
    $snmp_auth = '';
    $snmp_array = array();
    $temp_array = array();
    /* determine default retries */
    if ($retries == 0 || !is_numeric($retries)) {
        $retries = read_config_option('snmp_retries');
        if ($retries == '') {
            $retries = 3;
        }
    }
    /* do not attempt to poll invalid combinations */
    if ($version == 0 || !is_numeric($version) || !is_numeric($max_oids) || !is_numeric($port) || !is_numeric($retries) || !is_numeric($timeout) || $community == '' && $version != 3) {
        return array();
    }
    $path_snmpbulkwalk = read_config_option('path_snmpbulkwalk');
    if (snmp_get_method($version) == SNMP_METHOD_PHP || $version == 3 && strlen($context) == 0) {
        /* make sure snmp* is verbose so we can see what types of data
        		we are getting back */
        snmp_set_quick_print(0);
        /* set the output format to numeric */
        snmp_set_valueretrieval($method);
        snmp_set_enum_print(true);
        /* force php to return numeric oid's */
        cacti_oid_numeric_format();
        $track_errors = ini_get('track_errors');
        if ($track_errors != '1') {
            ini_set('track_errors', 1);
        }
        if ($version == '1') {
            $temp_array = @snmprealwalk("{$hostname}:{$port}", "{$community}", "{$oid}", $timeout * 1000, $retries);
        } elseif ($version == '2') {
            $temp_array = @snmp2_real_walk("{$hostname}:{$port}", "{$community}", "{$oid}", $timeout * 1000, $retries);
        } else {
            if ($priv_proto == '[None]') {
                $proto = 'authNoPriv';
                $priv_proto = '';
            } else {
                $proto = 'authPriv';
            }
            $temp_array = @snmp3_real_walk("{$hostname}:{$port}", "{$username}", $proto, $auth_proto, "{$password}", $priv_proto, "{$priv_pass}", "{$oid}", $timeout * 1000, $retries);
        }
        if ($temp_array === false && stripos($php_errormsg, 'no response') !== false) {
            cacti_log("WARNING: SNMP Walk Timeout for Host:'{$hostname}', and OID:'{$oid}'", false);
        }
        ini_set('track_errors', $track_errors);
        /* check for bad entries */
        if (is_array($temp_array) && sizeof($temp_array)) {
            foreach ($temp_array as $key => $value) {
                foreach ($banned_snmp_strings as $item) {
                    if (strstr($value, $item) != '') {
                        unset($temp_array[$key]);
                        continue 2;
                    }
                }
            }
        }
        $o = 0;
        if (is_array($temp_array) && sizeof($temp_array)) {
            for (@reset($temp_array); $i = @key($temp_array); next($temp_array)) {
                if ($temp_array[$i] != 'NULL') {
                    $snmp_array[$o]['oid'] = preg_replace('/^\\./', '', $i);
                    $snmp_array[$o]['value'] = format_snmp_string($temp_array[$i], $snmp_oid_included);
                }
                $o++;
            }
        }
    } else {
        /* ucd/net snmp want the timeout in seconds */
        $timeout = ceil($timeout / 1000);
        if ($version == '1') {
            $snmp_auth = read_config_option('snmp_version') == 'ucd-snmp' ? snmp_escape_string($community) : '-c ' . snmp_escape_string($community);
            /* v1/v2 - community string */
        } elseif ($version == '2') {
            $snmp_auth = read_config_option('snmp_version') == 'ucd-snmp' ? snmp_escape_string($community) : '-c ' . snmp_escape_string($community);
            /* v1/v2 - community string */
            $version = '2c';
            /* ucd/net snmp prefers this over '2' */
        } elseif ($version == '3') {
            if ($priv_proto == '[None]') {
                $proto = 'authNoPriv';
                $priv_proto = '';
            } else {
                $proto = 'authPriv';
            }
            if (strlen($priv_pass)) {
                $priv_pass = '******' . snmp_escape_string($priv_pass) . ' -x ' . snmp_escape_string($priv_proto);
            } else {
                $priv_pass = '';
            }
            if (strlen($context)) {
                $context = '-n ' . snmp_escape_string($context);
            } else {
                $context = '';
            }
            $snmp_auth = trim('-u ' . snmp_escape_string($username) . ' -l ' . snmp_escape_string($proto) . ' -a ' . snmp_escape_string($auth_proto) . ' -A ' . snmp_escape_string($password) . ' ' . $priv_pass . ' ' . $context);
            /* v3 - username/password */
        }
        if (read_config_option('snmp_version') == 'ucd-snmp') {
            /* escape the command to be executed and vulnerable parameters
             * numeric parameters are not subject to command injection
             * snmp_auth is treated seperately, see above */
            $temp_array = exec_into_array(cacti_escapeshellcmd(read_config_option('path_snmpwalk')) . " -v{$version} -t {$timeout} -r {$retries} " . cacti_escapeshellarg($hostname) . ":{$port} {$snmp_auth} " . cacti_escapeshellarg($oid));
        } else {
            if (file_exists($path_snmpbulkwalk) && $version > 1 && $max_oids > 1) {
                $temp_array = exec_into_array(cacti_escapeshellcmd($path_snmpbulkwalk) . " -O Qn {$snmp_auth} -v {$version} -t {$timeout} -r {$retries} -Cr{$max_oids} " . cacti_escapeshellarg($hostname) . ":{$port} " . cacti_escapeshellarg($oid));
            } else {
                $temp_array = exec_into_array(cacti_escapeshellcmd(read_config_option('path_snmpwalk')) . " -O Qn {$snmp_auth} -v {$version} -t {$timeout} -r {$retries} " . cacti_escapeshellarg($hostname) . ":{$port} " . cacti_escapeshellarg($oid));
            }
        }
        if (substr_count(implode(' ', $temp_array), 'Timeout:')) {
            cacti_log("WARNING: SNMP Walk Timeout for Host:'{$hostname}', and OID:'{$oid}'", false);
        }
        /* check for bad entries */
        if (is_array($temp_array) && sizeof($temp_array)) {
            foreach ($temp_array as $key => $value) {
                foreach ($banned_snmp_strings as $item) {
                    if (strstr($value, $item) != '') {
                        unset($temp_array[$key]);
                        continue 2;
                    }
                }
            }
        }
        if (is_array($temp_array) && sizeof($temp_array)) {
            for ($i = 0; $i < count($temp_array); $i++) {
                if ($temp_array[$i] != 'NULL') {
                    $snmp_array[$i]['oid'] = trim(preg_replace('/(.*) =.*/', "\\1", $temp_array[$i]));
                    $snmp_array[$i]['value'] = format_snmp_string($temp_array[$i], true);
                }
            }
        }
    }
    return $snmp_array;
}
Example #4
0
function snmptable($host, $community, $oid)
{
    # This handy function was bought to you by scot at indievisible dot org
    # Found on the PHP.net documentation page for snmprealwalk.
    # The important thing about this function is that it fills in the blanks.
    # Regular SNMP walks leave out items so you can't blindly prod things into arrays any more.
    snmp_set_oid_numeric_print(TRUE);
    snmp_set_quick_print(TRUE);
    snmp_set_enum_print(TRUE);
    $retval = array();
    if (!($raw = snmp2_real_walk($host, $community, $oid))) {
        return false;
    }
    if (count($raw) == 0) {
        return false;
    }
    // no data
    $prefix_length = 0;
    $largest = 0;
    foreach ($raw as $key => $value) {
        if ($prefix_length == 0) {
            // don't just use $oid's length since it may be non-numeric
            $prefix_elements = count(explode('.', $oid));
            $tmp = '.' . strtok($key, '.');
            while ($prefix_elements > 1) {
                $tmp .= '.' . strtok('.');
                $prefix_elements--;
            }
            $tmp .= '.';
            $prefix_length = strlen($tmp);
        }
        $key = substr($key, $prefix_length);
        $index = explode('.', $key, 2);
        isset($retval[$index[1]]) or $retval[$index[1]] = array();
        if ($largest < $index[0]) {
            $largest = $index[0];
        }
        $retval[$index[1]][$index[0]] = $value;
    }
    if (count($retval) == 0) {
        return false;
    }
    // no data
    // fill in holes and blanks the agent may "give" you
    foreach ($retval as $k => $x) {
        for ($i = 1; $i <= $largest; $i++) {
            if (!isset($retval[$k][$i])) {
                $retval[$k][$i] = '';
            }
        }
        ksort($retval[$k]);
    }
    return $retval;
}
Example #5
0
 function WIFI_GetSignal($ip, $mac_node, $community)
 {
     $devices = array('mac' => $mac_node, 'rssi' => NULL, 'tx' => NULL, 'rx' => NULL);
     $mac = explode(':', $mac_node);
     $oid_rssi = '.1.3.6.1.4.1.14988.1.1.1.2.1.3';
     $oid_tx = '.1.3.6.1.4.1.14988.1.1.1.2.1.8';
     $oid_rx = '.1.3.6.1.4.1.14988.1.1.1.2.1.9';
     for ($x = 0; $x < 6; $x++) {
         $oid_rssi .= '.' . hexdec($mac[$x]);
         $oid_tx .= '.' . hexdec($mac[$x]);
         $oid_rx .= '.' . hexdec($mac[$x]);
     }
     @snmp_set_oid_numeric_print(TRUE);
     @snmp_set_quick_print(TRUE);
     @snmp_set_enum_print(TRUE);
     if ($sn = @snmpwalk($ip, $community, $oid_rssi)) {
         foreach ($sn as $a => $x) {
             $devices['rssi'] = $x;
         }
         $sntx = @snmpwalk($ip, $community, $oid_tx);
         foreach ($sntx as $a => $x) {
             $devices['tx'] = $x / 1000000;
         }
         $snrx = @snmpwalk($ip, $community, $oid_rx);
         foreach ($snrx as $a => $x) {
             $devices['rx'] = $x / 1000000;
         }
     }
     return $devices;
 }
Example #6
0
    $community = "tceo";
}
if (empty($refresh)) {
    $refresh = "10";
}
// Change seconds to Milliseconds for setInterval loop
$chartloop = $refresh * 1000;
// Set Bandwidth OID's by Numerical Interface Choice
if (!empty($interface)) {
    $oid0 = "1.3.6.1.2.1.2.2.1.10.{$interface}";
    $oid1 = "1.3.6.1.2.1.2.2.1.16.{$interface}";
}
// Set PHP-SNMP Default Variables
snmp_set_oid_numeric_print(1);
snmp_set_quick_print(TRUE);
snmp_set_enum_print(TRUE);
snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
// Get OID Data if Requested
if (!empty($oid0)) {
    $output0 = snmpget($ip, $community, $oid0);
}
if (!empty($oid1)) {
    $output1 = snmpget($ip, $community, $oid1);
}
// Generate HTML Head Function
function head()
{
    echo "<!DOCTYPE html>\r\n    <html>\r\n    <head>\r\n      <meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">\r\n      <title>Jordan's Live Bandwidth Grapher</title>\r\n      <style>\r\n      body {\r\n        background-color: #F5F5F5;\r\n        font-family: Monaco, Menlo, Consolas, \"Courier New\", monospace;\r\n      }\r\n      </style>\r\n    </head>";
}
// Generate Menu Function
function menu()
<?php

require_once dirname(__FILE__) . '/snmp_include.inc';
echo "Checking error handling\n";
var_dump(snmp_set_enum_print());
echo "Checking working\n";
var_dump(snmp_set_enum_print(0));
var_dump(snmp_set_enum_print(1));
<?php

require_once dirname(__FILE__) . '/snmp_include.inc';
//EXPECTF format is quickprint OFF
snmp_set_enum_print(false);
snmp_set_quick_print(false);
snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
snmp_set_oid_output_format(SNMP_OID_OUTPUT_FULL);
echo "SNMPv1\n";
$session = new SNMP(SNMP::VERSION_1, $hostname, $community, $timeout, $retries);
$session->valueretrieval = SNMP_VALUE_LIBRARY;
var_dump($session->get('.1.3.6.1.2.1.1.1.0'));
var_dump($session->get(array('.1.3.6.1.2.1.1.1.0', '.1.3.6.1.2.1.1.3.0')));
var_dump($session->getnext('.1.3.6.1.2.1.1.1.0'));
var_dump($session->close());
echo "SNMPv2\n";
$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);
var_dump($session->get('.1.3.6.1.2.1.1.1.0'));
var_dump($session->getnext('.1.3.6.1.2.1.1.1.0'));
var_dump($session->close());
echo "GET with preserving original OID names\n";
$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);
$orig = array('.1.3.6.1.2.1.1.1.0', '.1.3.6.1.2.1.1.5.0');
$result = $session->get($orig, TRUE);
foreach ($orig as $oid) {
    var_dump($result[$oid]);
}
var_dump($session->close());
echo "WALK multiple on single OID\n";
$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);
$z = $session->walk('.1.3.6.1.2.1.1');