示例#1
0
            $params = array('port_id' => $port_id, 'mac_address' => $clean_mac, 'ip_address' => $ip, 'ip_version' => $ip_version);
            dbInsert($params, 'ip_mac');
            print_debug("Added MAC address " . format_mac($clean_mac) . " for {$ip}");
            //log_event("MAC added: $ip : " . format_mac($clean_mac), $device, "port", $port_id);
            echo "+";
        }
    }
}
// Remove expired ARP/NDP entries
$remove_mac_ids = array();
foreach ($cache_arp as $entry) {
    $entry_mac_id = $entry['mac_id'];
    $entry_mac = $entry['mac_address'];
    $entry_ip = $entry['ip_address'];
    $entry_version = $entry['ip_version'];
    $entry_if = $entry['ifIndex'];
    $entry_port_id = $interface[$entry_if];
    if (!isset($mac_table[$entry_if][$entry_version][$entry_ip])) {
        $remove_mac_ids[] = $entry_mac_id;
        //dbDelete('ip_mac', 'mac_id = ?', array($entry_mac_id));
        print_debug("Removed MAC address " . format_mac($entry_mac) . " for {$entry_ip}");
        //log_event("MAC removed: $entry_ip : " . format_mac($entry_mac), $device, "port", $entry['port_id']);
        echo "-";
    }
}
if (count($remove_mac_ids)) {
    dbDelete('ip_mac', '1' . generate_query_values($remove_mac_ids, 'mac_id'));
}
echo PHP_EOL;
unset($interface, $remove_mac_ids);
// EOF
示例#2
0
        $sql .= "v_domains as d2 ";
        $sql .= "where ";
        $sql .= "d1.domain_uuid = d2.domain_uuid and ";
        $sql .= "d1.device_username = '******' ";
        if ($_GET['domain_uuid'] != '') {
            $sql .= "and d2.domain_uuid = '" . check_str($_GET['domain_uuid']) . "' ";
        }
        if ($_GET['device_uuid'] != '') {
            $sql .= "and d1.device_uuid <> '" . check_str($_GET["device_uuid"]) . "' ";
        }
        $prep_statement = $db->prepare($sql);
        if ($prep_statement) {
            $prep_statement->execute();
            $row = $prep_statement->fetch(PDO::FETCH_ASSOC);
            if ($row['domain_name'] != '') {
                echo $text['message-duplicate_username'] . (if_group("superadmin") ? ": " . format_mac($row['device_mac_address']) . ($_SESSION["domain_name"] != $row["domain_name"] ? " (" . $row["domain_name"] . ")" : null) : null);
            }
        }
        unset($prep_statement);
    }
    exit;
}
//include the device class
require_once "app/devices/resources/classes/device.php";
//action add or update
if (isset($_REQUEST["id"])) {
    $action = "update";
    $device_uuid = check_str($_REQUEST["id"]);
} else {
    $action = "add";
}
    } elseif ($sort == "out") {
        $sort = "bytes_output_rate";
    } else {
        $sort = "bps";
    }
}
$mas = dbFetchRows("SELECT *, (bytes_input_rate + bytes_output_rate) AS bps,\n        (pkts_input_rate + pkts_output_rate) AS pps\n        FROM `mac_accounting`\n        LEFT JOIN  `mac_accounting-state` ON  `mac_accounting`.ma_id =  `mac_accounting-state`.ma_id\n        WHERE `mac_accounting`.port_id = ?\n        ORDER BY {$sort} DESC LIMIT 0," . $topn, array($port));
$port = get_port_by_id($port);
$device = device_by_id_cache($port['device_id']);
$pluses = "";
$iter = '0';
$rrd_options .= " COMMENT:'                                     In\\: Current     Maximum      Total      Out\\: Current     Maximum     Total\\\\n'";
foreach ($mas as $ma) {
    $this_rrd = get_rrd_path($device, "mac_acc-" . $port['ifIndex'] . "-" . $ma['vlan_id'] . "-" . $ma['mac'] . ".rrd");
    if (is_file($this_rrd)) {
        $mac = format_mac($ma['mac']);
        $name = $mac;
        $addy = dbFetchRow("SELECT * FROM ipv4_mac where mac_address = ? AND port_id = ?", array($ma['mac'], $ma['port_id']));
        if ($addy) {
            $name = $addy['ipv4_address'] . " (" . $mac . ")";
            $peer = dbFetchRow("SELECT * FROM ipv4_addresses AS A, ports AS I, devices AS D\n              WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND D.device_id = I.device_id", array($addy['ipv4_address']));
            if ($peer) {
                $name = $peer['hostname'] . " " . short_ifname($port['ifDescr'], NULL, FALSE) . " (" . $mac . ")";
            }
            if (dbFetchCell("SELECT COUNT(*) FROM bgpPeers WHERE device_id = ? AND bgpPeerIdentifier = ?", array($ma['device_id'], $addy['ipv4_address']))) {
                $peer_info = dbFetchRow("SELECT * FROM bgpPeers WHERE device_id = ? AND bgpPeerIdentifier = ?", array($ma['device_id'], $addy['ipv4_address']));
                $name .= " - AS" . $peer_info['bgpPeerRemoteAs'];
            }
            if ($peer_info) {
                $asn = "AS" . $peer_info['bgpPeerRemoteAs'];
                $astext = $peer_info['astext'];
示例#4
0
 function snmp_audit($ip, $credentials, $display)
 {
     error_reporting(E_ALL);
     $CI =& get_instance();
     $log = new stdClass();
     $log->file = 'system';
     $log->severity = 7;
     if ($display == 'y') {
         $log->display = 'y';
     } else {
         $log->display = 'n';
     }
     if (!extension_loaded('snmp')) {
         $log->message = 'SNMP PHP function not loaded hence not attempting to run snmp_helper::snmp_audit function';
         $log->severity = 5;
         stdlog($log);
         unset($log);
         return false;
     } else {
         $log->message = 'SNMP PHP function loaded and attempting to run snmp_helper::snmp_audit function';
         stdlog($log);
     }
     # we need an ip address
     if (empty($ip)) {
         $log->message = 'SNMP command received no ip address';
         $log->severity = 5;
         stdlog($log);
         unset($log);
         return false;
     } elseif (!filter_var($ip, FILTER_VALIDATE_IP)) {
         $log->message = 'SNMP command received invalid ip address';
         $log->severity = 5;
         stdlog($log);
         unset($log);
         return false;
     } else {
         $log->message = 'snmp_helper::snmp_audit function received ip ' . $ip;
         stdlog($log);
     }
     if (empty($credentials) or !is_object($credentials)) {
         $log->message = 'SNMP snmp_helper::snmp_audit received no credentials for ' . $ip;
         $log->severity = 5;
         stdlog($log);
         unset($log);
         return false;
     } else {
         $log->message = 'snmp_helper::snmp_audit function received credentials for ip ' . $ip;
         stdlog($log);
     }
     # new in 1.5 - remove the type from the returned SNMP query.
     # this affects the snmp_clean function in this file
     snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
     snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC);
     $details = new stdClass();
     $module = new stdclass();
     $return_ips = new stdClass();
     $return_ips->item = array();
     $details->ip = (string) $ip;
     $details->manufacturer = '';
     $details->serial = '';
     $details->model = '';
     $details->type = '';
     $details->sysDescr = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.1.1.0");
     $details->description = $details->sysDescr;
     $details->sysContact = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.1.4.0");
     $details->contact = $details->sysContact;
     $details->sysName = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.1.5.0");
     $details->hostname = $details->sysName;
     $details->name = $details->sysName;
     $details->sysLocation = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.1.6.0");
     $details->location = $details->sysLocation;
     // uptime
     $details->sysUpTime = intval(my_snmp_get($ip, $credentials, "1.3.6.1.6.3.10.2.1.3.0")) * 100;
     if (empty($details->sysUpTime)) {
         $details->sysUpTime = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.1.3.0");
     }
     if (empty($details->sysUpTime)) {
         $i = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.1.3.0");
         if ($i > '' and strpos($i, ")") !== false) {
             $j = explode(")", $i);
             $details->uptime = intval(trim($j[1]) * 24 * 60 * 60);
         } else {
             $details->uptime = '';
         }
     }
     // OID
     $details->sysObjectID = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.1.2.0");
     $details->snmp_oid = $details->sysObjectID;
     if ($details->snmp_oid > '') {
         $details->manufacturer = get_oid($details->snmp_oid);
         if ($details->manufacturer == 'net-snmp') {
             $details->manufacturer = (string) '';
         }
     }
     # sometimes we get an OID, but not enough to specify a manufacturer
     $explode = explode(".", $details->snmp_oid);
     if (!isset($explode[6])) {
         $vendor_oid = 0;
         if (strpos($details->sysDescr, "ZyXEL") !== false) {
             # we have a Zyxel device
             $vendor_oid = 890;
         }
     } else {
         $vendor_oid = intval($explode[6]);
     }
     if (file_exists(BASEPATH . '../application/helpers/snmp_' . $vendor_oid . '_helper.php')) {
         $log->message = 'snmp_helper::snmp_audit is loading the snmp helper for ' . $vendor_oid . ' when scanning ' . $ip;
         stdlog($log);
         unset($get_oid_details);
         include 'snmp_' . $vendor_oid . "_helper.php";
         $new_details = $get_oid_details($ip, $credentials, $details->snmp_oid);
         foreach ($new_details as $key => $value) {
             $details->{$key} = $value;
         }
         unset($new_details);
     } else {
         $log->message = 'snmp_helper::snmp_audit could not load the snmp helper for ' . $vendor_oid . ' when scanning ' . $ip;
         $log->severity = 6;
         stdlog($log);
         $log->severity = 7;
     }
     if (!empty($details->sysDescr) and stripos($details->sysDescr, 'dd-wrt') !== false) {
         $details->os_group = 'Linux';
         $details->os_name = 'DD-WRT';
         $details->type = 'router';
     }
     if (!empty($details->sysDescr) and stripos($details->sysDescr, "Darwin Kernel Version 12") !== false) {
         $details->manufacturer = "Apple Inc";
         $details->os_family = 'Apple OSX';
     }
     if (!empty($details->manufacturer) and (stripos($details->manufacturer, 'tplink') !== false or stripos($details->manufacturer, 'tp-link') !== false)) {
         $details->manufacturer = 'TP-Link Technology Co.,Ltd';
     }
     if (!empty($details->sysDescr) and stripos($details->sysDescr, 'buffalo terastation') !== false) {
         $details->manufacturer = 'Buffalo';
         $details->model = 'TeraStation';
         $details->type = 'nas';
     }
     if (!empty($details->sysDescr) and (stripos($details->sysDescr, 'synology') !== false or stripos($details->sysDescr, 'diskstation') !== false)) {
         $details->manufacturer = 'Synology';
         $temp = my_snmp_get($ip, $credentials, "1.3.6.1.4.1.6574.1.5.1.0");
         $details->model = trim('DiskStation ' . $temp);
         $details->serial = my_snmp_get($ip, $credentials, "1.3.6.1.4.1.6574.1.5.2.0");
         $details->type = 'nas';
         $details->os_group = 'Linux';
         $details->os_family = 'Synology DSM';
         $details->os_name = 'Synology ' . my_snmp_get($ip, $credentials, "1.3.6.1.4.1.6574.1.5.3.0");
     }
     // guess at manufacturer using entity mib
     if (empty($details->manufacturer)) {
         $details->manufacturer = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.47.1.1.1.1.12.1");
     }
     // guess at model using entity mib
     if (empty($details->model)) {
         $details->model = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.47.1.1.1.1.13");
     }
     // guess at model using host resources mib
     if (empty($details->model)) {
         $details->model = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.25.3.2.1.3.1");
     }
     // serial
     if (empty($details->serial)) {
         $details->serial = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.47.1.1.1.1.11");
     }
     if (empty($details->serial)) {
         $details->serial = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.47.1.1.1.1.11.1");
     }
     if (empty($details->serial)) {
         $details->serial = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.47.1.1.1.1.11.1.0");
     }
     # generic snmp
     if (empty($details->serial)) {
         $details->serial = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.43.5.1.1.17.1");
     }
     # below is another generic attempt - works for my NetGear Cable Modem
     if (empty($details->serial)) {
         $details->serial = my_snmp_get($ip, $credentials, "1.3.6.1.4.1.4491.2.4.1.1.1.3.0");
     }
     $log->message = 'snmp_helper::snmp_audit thinks ' . $ip . ' is a type:' . $details->type . ' model:' . $details->model . ' serial:' . $details->serial;
     stdlog($log);
     // subnet
     if (empty($details->subnet)) {
         $details->subnet = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.4.20.1.3." . $details->ip);
     }
     // mac address
     if (empty($details->mac_address)) {
         $interface_number = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.4.20.1.2." . $ip);
         snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);
         $details->mac_address = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.2.2.1.6." . $interface_number);
         snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
         $details->mac_address = format_mac($details->mac_address);
     }
     // last attempt at a MAC - just use whatever's in the first interface MAC
     if (empty($details->mac_address)) {
         snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);
         $details->mac_address = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.2.2.1.6.1");
         snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
         $details->mac_address = format_mac($details->mac_address);
     }
     $log->message = 'snmp_helper::snmp_audit MAC Address for ' . $ip . ' is ' . $details->mac_address;
     stdlog($log);
     // type
     if (empty($details->type) or $details->type == 'network printer') {
         $h = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.25.3.2.1.2.1");
         if ($h == '1.3.6.1.2.1.25.3.1.5') {
             # we have a printer
             $details->type = 'network printer';
             $i = my_snmp_walk($ip, $credentials, "1.3.6.1.2.1.43.13.4.1.10.1");
             if (count($i) > 0) {
                 $details->printer_duplex = 'n';
                 for ($k = 0; $k < count($i); $k++) {
                     if (mb_strpos($i[$k], "Duplex") !== false) {
                         $details->printer_duplex = 'y';
                     }
                 }
             }
             if (empty($details->manufacturer)) {
                 $hex = my_snmp_walk($ip, $credentials, "1.3.6.1.2.1.43.8.2.1.14.1");
                 if (count($hex) > 0) {
                     if (isset($hex[1])) {
                         if (mb_strpos($hex[1], "Hex-STRING: ") !== false) {
                             $hex[1] = str_replace("Hex-STRING: ", "", $hex[1]);
                             for ($i = 0; $i < strlen($hex[1]); $i++) {
                                 $details->manufacturer .= chr(hexdec(substr($hex[1], $i, 2)));
                             }
                         } else {
                             $details->manufacturer = str_replace("STRING: ", "", $hex[1]);
                             $details->manufacturer = str_replace('"', '', $details->manufacturer);
                         }
                     }
                 }
             }
             $details->printer_color = 'n';
             $i = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.43.11.1.1.6.1.2");
             if (strpos(strtolower($i), "cartridge") !== false) {
                 # it's likely this is a colour printer
                 $details->printer_color = 'y';
             }
         } else {
             # If the device is a Switch, the OID 1.3.6.1.2.1.17.1.2.0 is an integer and
             #                                OID 1.3.6.1.2.1.4.1.0    should have a value of 2
             $i = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.17.1.2.0");
             $j = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.4.1.0");
             if ($i == intval($i) and $j == '2') {
                 $details->type = 'switch';
             }
             # If the device is a Router, the OID 1.3.6.1.2.1.4.1.0 should have a value of 1 (already read above)
             if (empty($details->type)) {
                 if ($i == '1') {
                     $details->type = 'router';
                 }
             }
             # If the device is a Printer, the OID 1.3.6.1.2.1.43.5.1.1.1.1 should have a value
             #if (!isset($details->type) or $details->type == '') {
             $i = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.43.5.1.1.1.1");
             if (strpos(strtolower($i), "counter32") !== false) {
                 $details->type = 'network printer';
                 // printer duplex
                 $details->printer_duplex = '';
                 $i = my_snmp_walk($ip, $credentials, "1.3.6.1.2.1.43.13.4.1.10.1");
                 if (count($i) > 0) {
                     $details->printer_duplex = 'n';
                     for ($k = 0; $k < count($i); $k++) {
                         if (mb_strpos($i[$k], "Duplex") !== false) {
                             $details->printer_duplex = 'y';
                         }
                     }
                 }
                 if (empty($details->manufacturer)) {
                     $hex = my_snmp_walk($ip, $credentials, "1.3.6.1.2.1.43.8.2.1.14.1");
                     if (count($hex) > 0) {
                         if (isset($hex[1])) {
                             if (mb_strpos($hex[1], "Hex-STRING: ") !== false) {
                                 $hex[1] = str_replace("Hex-STRING: ", "", $hex[1]);
                                 for ($i = 0; $i < strlen($hex[1]); $i++) {
                                     $details->manufacturer .= chr(hexdec(substr($hex[1], $i, 2)));
                                 }
                             } else {
                                 $details->manufacturer = str_replace("STRING: ", "", $hex[1]);
                                 $details->manufacturer = str_replace('"', '', $details->manufacturer);
                             }
                         }
                     }
                 }
                 $details->printer_color = 'n';
                 $i = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.43.11.1.1.6.1.2");
                 if (strpos(strtolower($i), "cartridge") !== false) {
                     # it's likely this is a colour printer
                     $details->printer_color = 'y';
                 }
             }
         }
     }
     // modules - NOTE, we call these 'entities' in the web interface
     $log->message = 'snmp_helper::snmp_audit module retrieval for ' . $ip . ' starting';
     stdlog($log);
     $modules = array();
     $modules_list = my_snmp_real_walk($ip, $credentials, "1.3.6.1.2.1.47.1.1.1.1.2");
     if (isset($modules_list) and is_array($modules_list) and count($modules_list) > 0) {
         $log->message = 'snmp_helper::snmp_audit module count for ' . $ip . ' is ' . count($modules_list);
         stdlog($log);
         $log->message = 'snmp_helper::snmp_audit object_id retrieval for ' . $ip . ' starting';
         stdlog($log);
         $temp_object_id = my_snmp_real_walk($ip, $credentials, '1.3.6.1.2.1.47.1.1.1.1.3');
         $log->message = 'snmp_helper::snmp_audit contained_in retrieval for ' . $ip . ' starting';
         stdlog($log);
         $temp_contained_in = my_snmp_real_walk($ip, $credentials, '1.3.6.1.2.1.47.1.1.1.1.4');
         $log->message = 'snmp_helper::snmp_audit class retrieval for ' . $ip . ' starting';
         stdlog($log);
         $temp_class = my_snmp_real_walk($ip, $credentials, '1.3.6.1.2.1.47.1.1.1.1.5');
         $log->message = 'snmp_helper::snmp_audit hardware_revision retrieval for ' . $ip . ' starting';
         stdlog($log);
         $temp_hardware_revision = my_snmp_real_walk($ip, $credentials, '1.3.6.1.2.1.47.1.1.1.1.8');
         $log->message = 'snmp_helper::snmp_audit firmware_revision retrieval for ' . $ip . ' starting';
         stdlog($log);
         $temp_firmware_revision = my_snmp_real_walk($ip, $credentials, '1.3.6.1.2.1.47.1.1.1.1.9');
         $log->message = 'snmp_helper::snmp_audit software_revision retrieval for ' . $ip . ' starting';
         stdlog($log);
         $temp_software_revision = my_snmp_real_walk($ip, $credentials, '1.3.6.1.2.1.47.1.1.1.1.10');
         $log->message = 'snmp_helper::snmp_audit serial_number retrieval for ' . $ip . ' starting';
         stdlog($log);
         $temp_serial_number = my_snmp_real_walk($ip, $credentials, '1.3.6.1.2.1.47.1.1.1.1.11');
         $log->message = 'snmp_helper::snmp_audit asset_id retrieval for ' . $ip . ' starting';
         stdlog($log);
         $temp_asset_id = my_snmp_real_walk($ip, $credentials, '1.3.6.1.2.1.47.1.1.1.1.15');
         $log->message = 'snmp_helper::snmp_audit is_fru retrieval for ' . $ip . ' starting';
         stdlog($log);
         $temp_is_fru = my_snmp_real_walk($ip, $credentials, '1.3.6.1.2.1.47.1.1.1.1.16');
         foreach ($modules_list as $key => $value) {
             $log->message = 'snmp_helper::snmp_audit processing module ' . $value . ' for ' . $ip . ' starting';
             stdlog($log);
             $module = new stdClass();
             $module->description = $value;
             $module->module_index = str_replace('.1.3.6.1.2.1.47.1.1.1.1.2.', '', $key);
             $module->object_ident = $temp_object_id['.1.3.6.1.2.1.47.1.1.1.1.3.' . $module->module_index];
             $module->contained_in = $temp_contained_in['.1.3.6.1.2.1.47.1.1.1.1.4.' . $module->module_index];
             $module->class = $temp_class['.1.3.6.1.2.1.47.1.1.1.1.5.' . $module->module_index];
             $module->hardware_revision = $temp_hardware_revision['.1.3.6.1.2.1.47.1.1.1.1.8.' . $module->module_index];
             $module->firmware_revision = $temp_firmware_revision['.1.3.6.1.2.1.47.1.1.1.1.9.' . $module->module_index];
             $module->software_revision = $temp_software_revision['.1.3.6.1.2.1.47.1.1.1.1.10.' . $module->module_index];
             $module->serial = $temp_serial_number['.1.3.6.1.2.1.47.1.1.1.1.11.' . $module->module_index];
             $module->asset_ident = $temp_asset_id['.1.3.6.1.2.1.47.1.1.1.1.15.' . $module->module_index];
             $module->is_fru = $temp_is_fru['.1.3.6.1.2.1.47.1.1.1.1.16.' . $module->module_index];
             if ((string) $module->is_fru == '1') {
                 $module->is_fru = 'y';
             } else {
                 $module->is_fru = 'n';
             }
             $module->class_text = 'unknown';
             if ($module->class == '1') {
                 $module->class_text = 'other';
             }
             if ($module->class == '2') {
                 $module->class_text = 'unknown';
             }
             if ($module->class == '3') {
                 $module->class_text = 'chassis';
             }
             if ($module->class == '4') {
                 $module->class_text = 'backplane';
             }
             if ($module->class == '5') {
                 $module->class_text = 'container';
             }
             if ($module->class == '6') {
                 $module->class_text = 'powerSupply';
             }
             if ($module->class == '7') {
                 $module->class_text = 'fan';
             }
             if ($module->class == '8') {
                 $module->class_text = 'sensor';
             }
             if ($module->class == '9') {
                 $module->class_text = 'module';
             }
             if ($module->class == '10') {
                 $module->class_text = 'port';
             }
             if ($module->class == '11') {
                 $module->class_text = 'stack';
             }
             if ($module->class == '12') {
                 $module->class_text = 'cpu';
             }
             $modules[] = $module;
         }
     }
     $log->message = 'snmp_helper::snmp_audit module retrieval for ' . $ip . ' complete';
     stdlog($log);
     // network intereface details
     $interfaces = array();
     $interfaces_filtered = array();
     $interfaces = my_snmp_walk($ip, $credentials, "1.3.6.1.2.1.2.2.1.1");
     $log->message = 'snmp_helper::snmp_audit interface count for ' . $ip . ' is ' . count($interfaces);
     stdlog($log);
     if (is_array($interfaces) and count($interfaces) > 0) {
         $log->message = 'snmp_helper::snmp_audit models retrieval for ' . $ip . ' starting';
         stdlog($log);
         $models = my_snmp_real_walk($ip, $credentials, "1.3.6.1.2.1.2.2.1.2");
         $log->message = 'snmp_helper::snmp_audit types retrieval for ' . $ip . ' starting';
         stdlog($log);
         $types = my_snmp_real_walk($ip, $credentials, "1.3.6.1.2.1.2.2.1.3");
         $log->message = 'snmp_helper::snmp_audit speeds retrieval for ' . $ip . ' starting';
         stdlog($log);
         $speeds = my_snmp_real_walk($ip, $credentials, "1.3.6.1.2.1.2.2.1.5");
         $log->message = 'snmp_helper::snmp_audit mac_addresses retrieval for ' . $ip . ' starting';
         stdlog($log);
         $mac_addresses = my_snmp_real_walk($ip, $credentials, "1.3.6.1.2.1.2.2.1.6");
         $log->message = 'snmp_helper::snmp_audit ip_enableds retrieval for ' . $ip . ' starting';
         stdlog($log);
         $ip_enableds = my_snmp_real_walk($ip, $credentials, "1.3.6.1.2.1.2.2.1.8");
         $log->message = 'snmp_helper::snmp_audit ip_addresses retrieval for ' . $ip . ' starting';
         stdlog($log);
         $ip_addresses = my_snmp_real_walk($ip, $credentials, "1.3.6.1.2.1.4.20.1.2");
         $log->message = 'snmp_helper::snmp_audit ifAdminStatus retrieval for ' . $ip . ' starting';
         stdlog($log);
         $ifAdminStatus = my_snmp_real_walk($ip, $credentials, "1.3.6.1.2.1.2.2.1.7");
         $log->message = 'snmp_helper::snmp_audit ifLastChange retrieval for ' . $ip . ' starting';
         stdlog($log);
         $ifLastChange = my_snmp_real_walk($ip, $credentials, "1.3.6.1.2.1.2.2.1.9");
         if (isset($details->os_group) and $details->os_group == "VMware") {
             $log->message = 'snmp_helper::snmp_audit ip_addresses_2 retrieval for ' . $ip . ' starting';
             stdlog($log);
             $ip_addresses_2 = my_snmp_real_walk($ip, $credentials, "1.3.6.1.2.1.4.34.1.3.1.4");
         }
         $log->message = 'snmp_helper::snmp_audit subnets retrieval for ' . $ip . ' starting';
         stdlog($log);
         $subnets = my_snmp_real_walk($ip, $credentials, "1.3.6.1.2.1.4.20.1.3");
         $log->message = 'snmp_helper::snmp_audit connection_ids retrieval for ' . $ip . ' starting';
         stdlog($log);
         $connection_ids = my_snmp_real_walk($ip, $credentials, "1.3.6.1.2.1.31.1.1.1.1");
         $log->message = 'snmp_helper::snmp_audit aliases retrieval for ' . $ip . ' starting';
         stdlog($log);
         $aliases = my_snmp_real_walk($ip, $credentials, "1.3.6.1.2.1.31.1.1.1.18");
         foreach ($interfaces as $key => $value) {
             $log->message = 'snmp_helper::snmp_audit processing interface ' . $value . ' for ' . $ip . ' starting';
             stdlog($log);
             $interface = new stdclass();
             $interface->net_index = $value;
             snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);
             $interface->mac = format_mac(my_snmp_get($ip, $credentials, "1.3.6.1.2.1.2.2.1.6." . $interface->net_index));
             snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
             if (!isset($interface->mac)) {
                 $interface->mac = (string) '';
             }
             $interface->model = @$models[".1.3.6.1.2.1.2.2.1.2." . $interface->net_index];
             $interface->description = $interface->model;
             $interface->connection = @$connection_ids[".1.3.6.1.2.1.31.1.1.1.1." . $interface->net_index];
             $interface->alias = @$aliases[".1.3.6.1.2.1.31.1.1.1.18." . $interface->net_index];
             $interface->type = @interface_type(@$types[".1.3.6.1.2.1.2.2.1.3." . $interface->net_index]);
             $interface->ip_enabled = @ip_enabled($ip_enableds[".1.3.6.1.2.1.2.2.1.8." . $interface->net_index]);
             $interface->ifadminstatus = @if_admin_status($ifAdminStatus[".1.3.6.1.2.1.2.2.1.7." . $interface->net_index]);
             $interface->iflastchange = @$ifLastChange[".1.3.6.1.2.1.2.2.1.9." . $interface->net_index];
             $interface->speed = @$speeds[".1.3.6.1.2.1.2.2.1.5." . $interface->net_index];
             $interface->manufacturer = '';
             $interface->connection_status = '';
             $interface->dhcp_enabled = '';
             $interface->dhcp_server = '';
             $interface->dhcp_lease_obtained = '';
             $interface->dhcp_lease_expires = '';
             $interface->dns_host_name = '';
             $interface->dns_domain = '';
             $interface->dns_domain_reg_enabled = '';
             $interface->dns_server = '';
             if (is_array($ip_addresses) and count($ip_addresses > 0)) {
                 foreach ($ip_addresses as $each_key => $each_value) {
                     if ($each_value == $interface->net_index) {
                         $new_ip = new stdclass();
                         $new_ip->net_index = $interface->net_index;
                         $new_ip->ip = str_replace(".1.3.6.1.2.1.4.20.1.2.", "", $each_key);
                         $new_ip->mac = $interface->mac;
                         $new_ip->netmask = @$subnets[".1.3.6.1.2.1.4.20.1.3." . $new_ip->ip];
                         $new_ip->version = '4';
                         if ($new_ip->ip != '127.0.0.1' and $new_ip->ip != '127.0.1.1') {
                             $return_ips->item[] = $new_ip;
                         }
                         $new_ip = null;
                     }
                 }
             }
             if (isset($ip_addresses_2) and is_array($ip_addresses_2) and isset($details->os_group) and $details->os_group == "VMware") {
                 // likely we have a VMware ESX box - get what we can
                 foreach ($ip_addresses_2 as $each_key => $each_value) {
                     $new_ip = new stdClass();
                     $new_ip->net_index = $each_value;
                     $new_ip->ip = str_replace(".1.3.6.1.2.1.4.34.1.3.1.4.", "", $each_key);
                     $new_ip->netmask = '';
                     $new_ip->version = '4';
                     if ($new_ip->net_index == $interface->net_index) {
                         $new_ip->mac = $interface->mac;
                         if ($new_ip->ip != '127.0.0.1' and $new_ip->ip != '127.0.1.1') {
                             $return_ips->item[] = $new_ip;
                         }
                     }
                     $new_ip = null;
                 }
             }
             if (isset($details->os_group) and $details->os_group == 'Windows') {
                 if (isset($interface->ip_addresses) and count($interface->ip_addresses) > 0) {
                     if (strpos(strtolower($interface->type), 'loopback') === false) {
                         $interfaces_filtered[] = $interface;
                     }
                 }
             } else {
                 if (strtolower($interface->type != 'software loopback')) {
                     $interfaces_filtered[] = $interface;
                 }
             }
         }
     }
     // end of network interfaces
     // Virtual Guests
     $guests = array();
     if ($vendor_oid == 6876) {
         if (file_exists(BASEPATH . '../application/helpers/snmp_6876_2_helper.php')) {
             $log->message = 'snmp_helper::snmp_audit is loading the model helper for VMware virtual guests';
             stdlog($log);
             include 'snmp_6876_2_helper.php';
         }
     }
     $return_array = array('details' => $details, 'interfaces' => $interfaces_filtered, 'guests' => $guests, 'modules' => $modules, 'ip' => $return_ips);
     return $return_array;
 }
示例#5
0
            $matches[3] = 'ff';
            $matches[4] = 'fe';
        }
        $mac = zeropad($matches[3]);
        for ($i = 4; $i <= 8; $i++) {
            $mac .= ':' . zeropad($matches[$i]);
        }
        $clean_mac = str_replace(':', '', $mac);
        $mac_table[$if][$ip_version][$ip] = $clean_mac;
        if (isset($old_table[$if][$ip_version][$ip])) {
            $old_mac = $old_table[$if][$ip_version][$ip];
            if ($clean_mac != $old_mac && $clean_mac != '' && $old_mac != '') {
                if ($debug) {
                    echo "Changed MAC address for {$ip} from {$old_mac} to {$clean_mac}\n";
                }
                log_event("MAC changed: {$ip} : " . format_mac($old_mac) . " -> " . format_mac($clean_mac), $device, "port", $port_id);
                dbUpdate(array('mac_address' => $clean_mac), 'ip_mac', 'port_id = ? AND ip_address = ?', array($port_id, $ip));
                echo ".";
            }
        } else {
            $params = array('port_id' => $port_id, 'mac_address' => $clean_mac, 'ip_address' => $ip, 'ip_version' => $ip_version);
            dbInsert($params, 'ip_mac');
            if ($debug) {
                echo "Add MAC {$clean_mac}\n";
            }
            //log_event("MAC added: $ip : " . format_mac($clean_mac), $device, "port", $port_id);
            echo "+";
        }
    }
}
// Remove expired ARP/NDP entries
示例#6
0
        echo "</pre>";
    }
    if (is_array($ma)) {
        if ($auth || port_permitted($ma['port_id'])) {
            $rrd_filename = get_rrd_path($device, "mac_acc-" . $ma['ifIndex'] . "-" . $ma['vlan_id'] . "-" . $ma['mac'] . ".rrd");
            if ($debug) {
                echo $rrd_filename;
            }
            if (is_file($rrd_filename)) {
                if ($debug) {
                    echo "exists";
                }
                $port = get_port_by_id($ma['port_id']);
                $device = device_by_id_cache($port['device_id']);
                $title = generate_device_link($device);
                $title .= " :: Port  " . generate_port_link($port);
                $title .= " :: Mac Accounting";
                $title .= " :: " . format_mac($ma['mac']);
                $auth = TRUE;
            } else {
                #     graph_error("file not found");
            }
        } else {
            #    graph_error("unauthenticated");
        }
    } else {
        #   graph_error("entry not found");
    }
} else {
    #  graph_error("invalid id");
}
示例#7
0
/**
 * Display ARP/NDP table addresses.
 *
 * Display pages with ARP/NDP tables addresses from devices.
 *
 * @param array $vars
 * @return none
 *
 */
function print_arptable($vars)
{
    // With pagination? (display page numbers in header)
    $pagination = isset($vars['pagination']) && $vars['pagination'];
    pagination($vars, 0, TRUE);
    // Get default pagesize/pageno
    $pageno = $vars['pageno'];
    $pagesize = $vars['pagesize'];
    $start = $pagesize * $pageno - $pagesize;
    $param = array();
    $where = ' WHERE 1 ';
    foreach ($vars as $var => $value) {
        if ($value != '') {
            switch ($var) {
                case 'device':
                case 'device_id':
                    $where .= generate_query_values($value, 'device_id');
                    break;
                case 'port':
                case 'port_id':
                    $where .= generate_query_values($value, 'I.port_id');
                    break;
                case 'ip_version':
                    $where .= generate_query_values($value, 'ip_version');
                    break;
                case 'address':
                    if (isset($vars['searchby']) && $vars['searchby'] == 'ip') {
                        $value = trim($value);
                        if (strpos($value, ':') !== FALSE) {
                            if (Net_IPv6::checkIPv6($value)) {
                                $value = Net_IPv6::uncompress($value, TRUE);
                            } else {
                                // FIXME. Need another conversion ("2001:b08:b08" -> "2001:0b08:0b08") -- mike
                            }
                        }
                        $where .= generate_query_values($value, 'ip_address', '%LIKE%');
                    } else {
                        // MAC Addresses
                        $value = str_replace(array(':', ' ', '-', '.', '0x'), '', $value);
                        $where .= generate_query_values($value, 'mac_address', '%LIKE%');
                    }
                    break;
            }
        }
    }
    if (isset($vars['sort'])) {
        switch ($vars['sort']) {
            case "port":
                $sort = " ORDER BY `I`.`port_label`";
                break;
            case "ip_version":
                $sort = " ORDER BY `ip_version`";
                break;
            case "ip":
            case "address":
                $sort = " ORDER BY `ip_address`";
                break;
            case "mac":
            default:
                $sort = " ORDER BY `mac_address`";
        }
    }
    // Show ARP tables only for permitted ports
    $query_permitted = generate_query_permitted(array('port'), array('port_table' => 'I'));
    $query = 'FROM `ip_mac` AS M ';
    $query .= 'LEFT JOIN `ports` AS I ON I.`port_id` = M.`port_id` ';
    $query .= $where . $query_permitted;
    $query_count = 'SELECT COUNT(`mac_id`) ' . $query;
    $query = 'SELECT * ' . $query;
    $query .= $sort;
    $query .= " LIMIT {$start},{$pagesize}";
    // Query ARP/NDP table addresses
    $entries = dbFetchRows($query, $param);
    // Query ARP/NDP table address count
    if ($pagination) {
        $count = dbFetchCell($query_count, $param);
    }
    $list = array('device' => FALSE, 'port' => FALSE);
    if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'search') {
        $list['device'] = TRUE;
    }
    if (!isset($vars['port']) || empty($vars['port']) || $vars['page'] == 'search') {
        $list['port'] = TRUE;
    }
    $string = generate_box_open();
    $string .= '<table class="table  table-striped table-hover table-condensed">' . PHP_EOL;
    $cols = array('mac' => 'MAC Address', 'ip' => 'IP Address', 'device' => 'Device', 'port' => 'Port', '!remote_device' => 'Remote Device', '!remote_port' => 'Remote Port');
    if (!$list['device']) {
        unset($cols['device']);
    }
    if (!$list['port']) {
        unset($cols['port']);
    }
    if (!$short) {
        $string .= get_table_header($cols, $vars);
        // Currently sorting is not available
    }
    foreach ($entries as $entry) {
        humanize_port($entry);
        $ip_version = $entry['ip_version'];
        $ip_address = $ip_version == 6 ? Net_IPv6::compress($entry['ip_address']) : $entry['ip_address'];
        $arp_host = dbFetchRow('SELECT * FROM `ipv' . $ip_version . '_addresses` AS A
                           LEFT JOIN `ports` AS I ON A.`port_id` = I.`port_id`
                           LEFT JOIN `devices` AS D ON D.`device_id` = I.`device_id`
                           WHERE A.`ipv' . $ip_version . '_address` = ?', array($ip_address));
        $arp_name = $arp_host ? generate_device_link($arp_host) : '';
        $arp_if = $arp_host ? generate_port_link($arp_host) : '';
        if ($arp_host['device_id'] == $entry['device_id']) {
            $arp_name = 'Self Device';
        }
        if ($arp_host['port_id'] == $entry['port_id']) {
            $arp_if = 'Self Port';
        }
        $string .= '  <tr>' . PHP_EOL;
        $string .= '    <td style="width: 160px;" class="entity">' . generate_popup_link('mac', format_mac($entry['mac_address'])) . '</td>' . PHP_EOL;
        $string .= '    <td style="width: 140px;">' . generate_popup_link('ip', $ip_address) . '</td>' . PHP_EOL;
        if ($list['device']) {
            $dev = device_by_id_cache($entry['device_id']);
            $string .= '    <td class="entity" style="white-space: nowrap;">' . generate_device_link($dev) . '</td>' . PHP_EOL;
        }
        if ($list['port']) {
            if ($entry['ifInErrors_delta'] > 0 || $entry['ifOutErrors_delta'] > 0) {
                $port_error = generate_port_link($entry, '<span class="label label-important">Errors</span>', 'port_errors');
            }
            $string .= '    <td class="entity">' . generate_port_link($entry, $entry['port_label_short']) . ' ' . $port_error . '</td>' . PHP_EOL;
        }
        $string .= '    <td class="entity" style="width: 200px;">' . $arp_name . '</td>' . PHP_EOL;
        $string .= '    <td class="entity">' . $arp_if . '</td>' . PHP_EOL;
        $string .= '  </tr>' . PHP_EOL;
    }
    $string .= '  </tbody>' . PHP_EOL;
    $string .= '</table>';
    $string .= generate_box_close();
    // Print pagination header
    if ($pagination) {
        $string = pagination($vars, $count) . $string . pagination($vars, $count);
    }
    // Print ARP/NDP table
    echo $string;
}
示例#8
0
/**
 * Display FDB table.
 *
 * @param array $vars
 * @return none
 *
 */
function print_fdbtable($vars)
{
    // With pagination? (display page numbers in header)
    $pagination = isset($vars['pagination']) && $vars['pagination'];
    pagination($vars, 0, TRUE);
    // Get default pagesize/pageno
    $pageno = $vars['pageno'];
    $pagesize = $vars['pagesize'];
    $start = $pagesize * $pageno - $pagesize;
    $param = array();
    $where = ' WHERE 1 ';
    foreach ($vars as $var => $value) {
        if ($value != '') {
            $cond = array();
            switch ($var) {
                case 'device':
                case 'device_id':
                    $where .= generate_query_values($value, 'I.device_id');
                    break;
                case 'port':
                case 'port_id':
                    $where .= ' AND I.`port_id` = ?';
                    $param[] = $value;
                    break;
                case 'interface':
                    $where .= ' AND I.`ifDescr` LIKE ?';
                    $param[] = $value;
                    break;
                case 'vlan_id':
                    $where .= generate_query_values($value, 'F.vlan_id');
                    break;
                case 'vlan_name':
                    $where .= generate_query_values($value, 'V.vlan_name');
                    break;
                case 'address':
                    $where .= ' AND F.`mac_address` LIKE ?';
                    # FIXME hm? mres in a dbFacile parameter?
                    $param[] = '%' . str_replace(array(':', ' ', '-', '.', '0x'), '', mres($value)) . '%';
                    break;
            }
        }
    }
    // Show FDB tables only for permitted ports
    $query_permitted = generate_query_permitted(array('port'), array('port_table' => 'I'));
    $query = 'FROM `vlans_fdb` AS F ';
    $query .= 'LEFT JOIN `vlans` as V ON V.`vlan_vlan` = F.`vlan_id` AND V.`device_id` = F.`device_id` ';
    $query .= 'LEFT JOIN `ports` AS I ON I.`port_id` = F.`port_id` ';
    $query .= $where . $query_permitted;
    $query_count = 'SELECT COUNT(*) ' . $query;
    $query = 'SELECT * ' . $query;
    $query .= ' ORDER BY F.`mac_address`';
    $query .= " LIMIT {$start},{$pagesize}";
    // Query addresses
    $entries = dbFetchRows($query, $param);
    // Query address count
    if ($pagination) {
        $count = dbFetchCell($query_count, $param);
    }
    $list = array('device' => FALSE);
    if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'search') {
        $list['device'] = TRUE;
    }
    $string = '<table class="table table-bordered table-striped table-hover table-condensed">' . PHP_EOL;
    if (!$short) {
        $string .= '  <thead>' . PHP_EOL;
        $string .= '    <tr>' . PHP_EOL;
        $string .= '      <th>MAC Address</th>' . PHP_EOL;
        if ($list['device']) {
            $string .= '      <th>Device</th>' . PHP_EOL;
        }
        $string .= '      <th>Interface</th>' . PHP_EOL;
        $string .= '      <th>VLAN ID</th>' . PHP_EOL;
        $string .= '      <th>VLAN Name</th>' . PHP_EOL;
        $string .= '    </tr>' . PHP_EOL;
        $string .= '  </thead>' . PHP_EOL;
    }
    $string .= '  <tbody>' . PHP_EOL;
    foreach ($entries as $entry) {
        humanize_port($entry);
        $string .= '  <tr>' . PHP_EOL;
        $string .= '    <td style="width: 160px;">' . format_mac($entry['mac_address']) . '</td>' . PHP_EOL;
        if ($list['device']) {
            $dev = device_by_id_cache($entry['device_id']);
            $string .= '    <td class="entity" style="white-space: nowrap;">' . generate_device_link($dev) . '</td>' . PHP_EOL;
        }
        if ($entry['ifInErrors_delta'] > 0 || $entry['ifOutErrors_delta'] > 0) {
            $port_error = generate_port_link($entry, '<span class="label label-important">Errors</span>', 'port_errors');
        }
        $string .= '    <td class="entity">' . generate_port_link($entry, short_ifname($entry['label'])) . ' ' . $port_error . '</td>' . PHP_EOL;
        $string .= '    <td>Vlan' . $entry['vlan_vlan'] . '</td>' . PHP_EOL;
        $string .= '    <td>' . $entry['vlan_name'] . '</td>' . PHP_EOL;
        $string .= '  </tr>' . PHP_EOL;
    }
    $string .= '  </tbody>' . PHP_EOL;
    $string .= '</table>';
    // Print pagination header
    if ($pagination) {
        $string = pagination($vars, $count) . $string . pagination($vars, $count);
    }
    // Print FDB table
    echo $string;
}
示例#9
0
        echo "\t<a href='device_edit.php' alt='" . $text['button-add'] . "'>" . $v_link_label_add . "</a>\n";
    }
} else {
    echo "\t&nbsp;\n";
}
echo "</td>\n";
echo "<tr>\n";
if (count($devices) > 0) {
    foreach ($devices as $row) {
        $tr_link = permission_exists('device_edit') ? "href='device_edit.php?id=" . $row['device_uuid'] . "'" : null;
        echo "<tr " . $tr_link . ">\n";
        if ($_GET['showall'] && permission_exists('device_all')) {
            echo "\t<td valign='top' class='" . $row_style[$c] . "'>" . $_SESSION['domains'][$row['domain_uuid']]['domain_name'] . "</td>\n";
        }
        echo "\t<td valign='top' class='" . $row_style[$c] . "'>";
        echo permission_exists('device_edit') ? "<a href='device_edit.php?id=" . $row['device_uuid'] . "'>" . format_mac($row['device_mac_address']) . "</a>" : format_mac($row['device_mac_address']);
        echo "\t</td>\n";
        echo "\t<td valign='top' class='" . $row_style[$c] . "'>" . $row['device_label'] . "&nbsp;</td>\n";
        if ($device_alternate) {
            echo "\t<td valign='top' class='" . $row_style[$c] . "'>\n";
            if (strlen($row['device_uuid_alternate']) > 0) {
                echo "\t\t<a href='device_edit.php?id=" . $row['device_uuid_alternate'] . "' alt=''>" . $row['alternate_label'] . "</a>\n";
            }
            echo "\t</td>\n";
        }
        echo "\t<td valign='top' class='" . $row_style[$c] . "'>" . $row['device_vendor'] . "&nbsp;</td>\n";
        echo "\t<td valign='top' class='" . $row_style[$c] . "'>" . $row['device_template'] . "&nbsp;</td>\n";
        echo "\t<td valign='top' class='" . $row_style[$c] . "'>" . $text['label-' . $row['device_enabled']] . "&nbsp;</td>\n";
        echo "\t<td valign='top' class='row_stylebg'>" . $row['device_description'] . "&nbsp;</td>\n";
        echo "\t<td class='list_control_icons'>";
        if (permission_exists('device_edit')) {
示例#10
0
function humanize_port(&$port)
{
    global $config, $cache;
    // Exit if already humanized
    if ($port['humanized']) {
        return;
    }
    // Process port data to make it pretty for printing. EVOLUTION, BITCHES.
    // Lots of hacky shit will end up here with if (os);
    // If we can get the device data from the global cache, do it, else pull it from the db (mostly for external scripts)
    if (is_array($GLOBALS['cache']['devices']['id'][$port['device_id']])) {
        $device =& $GLOBALS['cache']['devices']['id'][$port['device_id']];
    } else {
        $device = device_by_id_cache($port['device_id']);
    }
    $os = $device['os'];
    $port['human_speed'] = humanspeed($port['ifSpeed']);
    $port['human_type'] = rewrite_iftype($port['ifType']);
    $port['html_class'] = ifclass($port['ifOperStatus'], $port['ifAdminStatus']);
    $port['human_mac'] = format_mac($port['ifPhysAddress']);
    // Here definition override for ifDescr, because Calix switch ifDescr <> ifName since fw 2.2
    // Note, only for 'calix' os now
    if ($os == 'calix') {
        unset($config['os'][$os]['ifname']);
        $version_parts = explode('.', $device['version']);
        if ($version_parts[0] > 2 || $version_parts[0] == 2 && $version_parts[1] > 1) {
            $config['os'][$os]['ifname'] = 1;
        }
    }
    if (isset($config['os'][$os]['ifname'])) {
        if ($port['ifName'] == "") {
            $port['label'] = $port['ifDescr'];
        } else {
            $port['label'] = $port['ifName'];
        }
    } elseif (isset($config['os'][$os]['ifalias'])) {
        $port['label'] = $port['ifAlias'];
    } else {
        $port['label'] = $port['ifDescr'];
        if (isset($config['os'][$os]['ifindex'])) {
            $port['label'] .= ' ' . $port['ifIndex'];
        } else {
            $port['label'] = $port['ifDescr'];
        }
    }
    // Set entity variables for use by code which uses entities
    $port['entity_name'] = $port['label'];
    $port['entity_shortname'] = $port['label'];
    $port['entity_descr'] = $port['ifAlias'];
    if ($device['os'] == "speedtouch") {
        list($port['label']) = explode("thomson", $port['label']);
    }
    $port['table_tab_colour'] = "#aaaaaa";
    $port['row_class'] = "";
    // Default
    $port['admin_status'] = $port['ifAdminStatus'];
    if ($port['ifAdminStatus'] == "down") {
        $port['admin_status'] = 'disabled';
        $port['row_class'] = "warning";
        $port['icon'] = 'port-disabled';
    } elseif ($port['ifAdminStatus'] == "up") {
        $port['admin_status'] = 'enabled';
        switch ($port['ifOperStatus']) {
            case 'down':
                $port['table_tab_colour'] = "#cc0000";
                $port['row_class'] = "error";
                $port['icon'] = 'port-down';
                break;
            case 'monitoring':
                // This is monitoring ([e|r]span) ports
                $port['table_tab_colour'] = "#008C00";
                $port['row_class'] = "success";
                $port['icon'] = 'port-up';
                break;
            case 'lowerLayerDown':
                $port['table_tab_colour'] = "#ff6600";
                $port['row_class'] = "warning";
                $port['icon'] = 'port-down';
                break;
            case 'testing':
                $port['table_tab_colour'] = "#85004b";
                $port['row_class'] = "info";
                $port['icon'] = 'port-ignored';
                break;
            case 'up':
                $port['table_tab_colour'] = "#194B7F";
                $port['row_class'] = "";
                $port['icon'] = 'port-up';
                break;
        }
    }
    // If the device is down, colour the row/tab as 'warning' meaning that the entity is down because of something below it.
    if ($device['status'] == '0') {
        $port['table_tab_colour'] = "#ff6600";
        $port['row_class'] = "warning";
        $port['icon'] = 'port-ignored';
    }
    $port['in_rate'] = $port['ifInOctets_rate'] * 8;
    $port['out_rate'] = $port['ifOutOctets_rate'] * 8;
    // Colour in bps based on speed if > 50, else by UI convention.
    $in_perc = round($port['in_rate'] / $port['ifSpeed'] * 100);
    if ($port['in_rate'] == 0) {
        $port['bps_in_style'] = '';
    } elseif ($in_perc < '50') {
        $port['bps_in_style'] = 'color: #008C00;';
    } else {
        $port['bps_in_style'] = 'color: ' . percent_colour($in_perc) . '; ';
    }
    // Colour out bps based on speed if > 50, else by UI convention.
    $out_perc = round($port['out_rate'] / $port['ifSpeed'] * 100);
    if ($port['out_rate'] == 0) {
        $port['bps_out_style'] = '';
    } elseif ($out_perc < '50') {
        $port['bps_out_style'] = 'color: #394182;';
    } else {
        $port['bps_out_style'] = 'color: ' . percent_colour($out_perc) . '; ';
    }
    // Colour in and out pps based on UI convention
    $port['pps_in_style'] = $port['ifInUcastPkts_rate'] == 0 ? '' : 'color: #740074;';
    $port['pps_out_style'] = $port['ifOutUcastPkts_rate'] == 0 ? '' : 'color: #FF7400;';
    $port['humanized'] = TRUE;
    /// Set this so we can check it later.
}
/**
 * Display ARP/NDP table addresses.
 *
 * Display pages with ARP/NDP tables addresses from devices.
 *
 * @param array $vars
 * @return none
 *
 */
function print_arptable($vars)
{
    // With pagination? (display page numbers in header)
    $pagination = isset($vars['pagination']) && $vars['pagination'];
    pagination($vars, 0, TRUE);
    // Get default pagesize/pageno
    $pageno = $vars['pageno'];
    $pagesize = $vars['pagesize'];
    $start = $pagesize * $pageno - $pagesize;
    $param = array();
    $where = ' WHERE 1 ';
    foreach ($vars as $var => $value) {
        if ($value != '') {
            switch ($var) {
                case 'device':
                case 'device_id':
                    $where .= generate_query_values($value, 'device_id');
                    break;
                case 'port':
                case 'port_id':
                    $where .= ' AND I.`port_id` = ?';
                    $param[] = $value;
                    break;
                case 'ip_version':
                    $where .= ' AND `ip_version` = ?';
                    $param[] = $value;
                    break;
                case 'address':
                    if (isset($vars['searchby']) && $vars['searchby'] == 'ip') {
                        $where .= ' AND `ip_address` LIKE ?';
                        $value = trim($value);
                        // FIXME. Need another conversion ("2001:b08:b08" -> "2001:0b08:0b08") -- mike
                        if (Net_IPv6::checkIPv6($value)) {
                            $value = Net_IPv6::uncompress($value, true);
                        }
                        $param[] = '%' . $value . '%';
                    } else {
                        $where .= ' AND `mac_address` LIKE ?';
                        $param[] = '%' . str_replace(array(':', ' ', '-', '.', '0x'), '', $value) . '%';
                    }
                    break;
            }
        }
    }
    // Show ARP tables only for permitted ports
    $query_permitted = generate_query_permitted(array('port'), array('port_table' => 'I'));
    $query = 'FROM `ip_mac` AS M ';
    $query .= 'LEFT JOIN `ports` AS I ON I.`port_id` = M.`port_id` ';
    $query .= $where . $query_permitted;
    $query_count = 'SELECT COUNT(`mac_id`) ' . $query;
    $query = 'SELECT * ' . $query;
    $query .= ' ORDER BY M.`mac_address`';
    $query .= " LIMIT {$start},{$pagesize}";
    // Query ARP/NDP table addresses
    $entries = dbFetchRows($query, $param);
    // Query ARP/NDP table address count
    if ($pagination) {
        $count = dbFetchCell($query_count, $param);
    }
    $list = array('device' => FALSE, 'port' => FALSE);
    if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'search') {
        $list['device'] = TRUE;
    }
    if (!isset($vars['port']) || empty($vars['port']) || $vars['page'] == 'search') {
        $list['port'] = TRUE;
    }
    $string = '<table class="table table-bordered table-striped table-hover table-condensed">' . PHP_EOL;
    if (!$short) {
        $string .= '  <thead>' . PHP_EOL;
        $string .= '    <tr>' . PHP_EOL;
        $string .= '      <th>MAC地址</th>' . PHP_EOL;
        $string .= '      <th>IP地址</th>' . PHP_EOL;
        if ($list['device']) {
            $string .= '      <th>设备</th>' . PHP_EOL;
        }
        if ($list['port']) {
            $string .= '      <th>接口</th>' . PHP_EOL;
        }
        $string .= '      <th>远程设备</th>' . PHP_EOL;
        $string .= '      <th>远程接口</th>' . PHP_EOL;
        $string .= '    </tr>' . PHP_EOL;
        $string .= '  </thead>' . PHP_EOL;
    }
    $string .= '  <tbody>' . PHP_EOL;
    foreach ($entries as $entry) {
        humanize_port($entry);
        $ip_version = $entry['ip_version'];
        $ip_address = $ip_version == 6 ? Net_IPv6::compress($entry['ip_address']) : $entry['ip_address'];
        $arp_host = dbFetchRow('SELECT * FROM `ipv' . $ip_version . '_addresses` AS A
                           LEFT JOIN `ports` AS I ON A.`port_id` = I.`port_id`
                           LEFT JOIN `devices` AS D ON D.`device_id` = I.`device_id`
                           WHERE A.`ipv' . $ip_version . '_address` = ?', array($ip_address));
        $arp_name = $arp_host ? generate_device_link($arp_host) : '';
        $arp_if = $arp_host ? generate_port_link($arp_host) : '';
        if ($arp_host['device_id'] == $entry['device_id']) {
            $arp_name = '自设备';
        }
        if ($arp_host['port_id'] == $entry['port_id']) {
            $arp_if = '自端口';
        }
        $string .= '  <tr>' . PHP_EOL;
        $string .= '    <td style="width: 160px;">' . generate_popup_link('mac', format_mac($entry['mac_address'])) . '</td>' . PHP_EOL;
        $string .= '    <td style="width: 140px;">' . $ip_address . '</td>' . PHP_EOL;
        if ($list['device']) {
            $dev = device_by_id_cache($entry['device_id']);
            $string .= '    <td class="entity" style="white-space: nowrap;">' . generate_device_link($dev) . '</td>' . PHP_EOL;
        }
        if ($list['port']) {
            if ($entry['ifInErrors_delta'] > 0 || $entry['ifOutErrors_delta'] > 0) {
                $port_error = generate_port_link($entry, '<span class="label label-important">错误</span>', 'port_errors');
            }
            $string .= '    <td class="entity">' . generate_port_link($entry, short_ifname($entry['label'])) . ' ' . $port_error . '</td>' . PHP_EOL;
        }
        $string .= '    <td class="entity" style="width: 200px;">' . $arp_name . '</td>' . PHP_EOL;
        $string .= '    <td class="entity">' . $arp_if . '</td>' . PHP_EOL;
        $string .= '  </tr>' . PHP_EOL;
    }
    $string .= '  </tbody>' . PHP_EOL;
    $string .= '</table>';
    // Print pagination header
    if ($pagination) {
        $string = pagination($vars, $count) . $string . pagination($vars, $count);
    }
    // Print ARP/NDP table
    echo $string;
}
示例#12
0
/**
 * Display FDB table.
 *
 * @param array $vars
 * @return none
 *
 */
function print_fdbtable($vars)
{
    // With pagination? (display page numbers in header)
    $pagination = isset($vars['pagination']) && $vars['pagination'];
    pagination($vars, 0, TRUE);
    // Get default pagesize/pageno
    $pageno = $vars['pageno'];
    $pagesize = $vars['pagesize'];
    $start = $pagesize * $pageno - $pagesize;
    $param = array();
    $where = ' WHERE 1 ';
    foreach ($vars as $var => $value) {
        if ($value != '') {
            switch ($var) {
                case 'device':
                case 'device_id':
                    $where .= generate_query_values($value, 'I.device_id');
                    break;
                case 'port':
                case 'port_id':
                    $where .= generate_query_values($value, 'I.port_id');
                    break;
                case 'interface':
                case 'port_name':
                    $where .= generate_query_values($value, 'I.ifDescr', 'LIKE%');
                    break;
                case 'vlan_id':
                    $where .= generate_query_values($value, 'F.vlan_id');
                    break;
                case 'vlan_name':
                    $where .= generate_query_values($value, 'V.vlan_name');
                    break;
                case 'address':
                    $where .= generate_query_values(str_replace(array(':', ' ', '-', '.', '0x'), '', $value), 'F.mac_address', '%LIKE%');
                    break;
            }
        }
    }
    if (isset($vars['sort'])) {
        switch ($vars['sort']) {
            case "vlan_id":
                $sort = " ORDER BY `V`.`vlan_vlan`";
                break;
            case "vlan_name":
                $sort = " ORDER BY `V`.`vlan_name`";
                break;
            case "port":
                $sort = " ORDER BY `I`.`port_label`";
                break;
            case "mac":
            default:
                $sort = " ORDER BY `mac_address`";
        }
    }
    // Show FDB tables only for permitted ports
    $query_permitted = generate_query_permitted(array('port'), array('port_table' => 'I'));
    $query = 'FROM `vlans_fdb` AS F ';
    $query .= 'LEFT JOIN `vlans` as V ON V.`vlan_vlan` = F.`vlan_id` AND V.`device_id` = F.`device_id` ';
    $query .= 'LEFT JOIN `ports` AS I ON I.`port_id` = F.`port_id` ';
    $query .= $where . $query_permitted;
    $query_count = 'SELECT COUNT(*) ' . $query;
    $query = 'SELECT * ' . $query;
    $query .= $sort;
    $query .= " LIMIT {$start},{$pagesize}";
    // Query addresses
    $entries = dbFetchRows($query, $param);
    // Query address count
    if ($pagination) {
        $count = dbFetchCell($query_count, $param);
    }
    $list = array('device' => FALSE, 'port' => FALSE);
    if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'search') {
        $list['device'] = TRUE;
    }
    if (!isset($vars['port']) || empty($vars['port']) || $vars['page'] == 'search') {
        $list['port'] = TRUE;
    }
    $string = generate_box_open();
    $string .= '<table class="table  table-striped table-hover table-condensed">' . PHP_EOL;
    $cols = array('device' => 'Device', 'mac' => array('MAC Address', 'style="width: 160px;"'), 'status' => array('Status', 'style="width: 100px;"'), 'port' => 'Port', 'vlan_id' => 'VLAN ID', 'vlan_name' => 'VLAN NAME');
    if (!$list['device']) {
        unset($cols['device']);
    }
    if (!$list['port']) {
        unset($cols['port']);
    }
    if (!$short) {
        $string .= get_table_header($cols, $vars);
        // Currently sorting is not available
    }
    foreach ($entries as $entry) {
        humanize_port($entry);
        $string .= '  <tr>' . PHP_EOL;
        if ($list['device']) {
            $dev = device_by_id_cache($entry['device_id']);
            $string .= '    <td class="entity" style="white-space: nowrap;">' . generate_device_link($dev) . '</td>' . PHP_EOL;
        }
        $string .= '    <td>' . generate_popup_link('mac', format_mac($entry['mac_address'])) . '</td>' . PHP_EOL;
        $string .= '    <td>' . $entry['fdb_status'] . '</td>' . PHP_EOL;
        if ($list['port']) {
            $string .= '    <td class="entity">' . generate_port_link($entry, $entry['port_label_short']) . ' ' . $port_error . '</td>' . PHP_EOL;
        }
        $string .= '    <td>Vlan' . $entry['vlan_vlan'] . '</td>' . PHP_EOL;
        $string .= '    <td>' . $entry['vlan_name'] . '</td>' . PHP_EOL;
        $string .= '  </tr>' . PHP_EOL;
    }
    $string .= '  </tbody>' . PHP_EOL;
    $string .= '</table>';
    $string .= generate_box_close();
    // Print pagination header
    if ($pagination) {
        $string = pagination($vars, $count) . $string . pagination($vars, $count);
    }
    // Print FDB table
    echo $string;
}
示例#13
0
 function fdb_info(&$irc, &$data)
 {
     global $config;
     $hostname = $data->messageex[1];
     if (count($data->messageex) >= 3) {
         $ifname = $data->messageex[2];
     } else {
         $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Error: Missing port name");
     }
     mysql_connect($config['db_host'], $config['db_user'], $config['db_pass']);
     mysql_select_db($config['db_name']);
     $device = dbFetchRow("SELECT * FROM `devices` WHERE `hostname` = ?", array($hostname));
     if (!$device) {
         $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Error: Bad or Missing hostname, use .listdevices to show all devices.");
     } else {
         $sql = "SELECT `vlans_fdb`.mac_address AS mac_address, GROUP_CONCAT(`vlans_fdb`.vlan_id SEPARATOR '|') AS vlan_id FROM `vlans_fdb`";
         $sql .= " LEFT JOIN `ports` ON `ports`.port_id = `vlans_fdb`.port_id AND ports.device_id = `vlans_fdb`.device_id";
         $sql .= " WHERE (ports.`ifName` = ? OR ports.`ifDescr` = ?) AND `vlans_fdb`.device_id = ?";
         $sql .= " GROUP BY mac_address";
         $fdb = dbFetchRows($sql, array($ifname, $ifname, $device['device_id']));
         foreach ($fdb as $mac) {
             $message .= $sep . format_mac($mac["mac_address"]) . "(vlans [{$mac['vlan_id']}])";
             $sep = ", ";
         }
         $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $message);
         echo "FDB\t\t{$hostname}\t{$ifname}\n";
     }
     mysql_close();
 }
示例#14
0
 /**
  * @dataProvider providerFormatMac
  */
 public function testFormatMac($value, $result)
 {
     $this->assertSame($result, format_mac($value));
 }
示例#15
0
/**
 * Display dot1x sessions
 *
 * @param array $vars
 * @return none
 *
 */
function print_dot1xtable($vars)
{
    // With pagination? (display page numbers in header)
    $pagination = isset($vars['pagination']) && $vars['pagination'];
    pagination($vars, 0, TRUE);
    // Get default pagesize/pageno
    $pageno = $vars['pageno'];
    $pagesize = $vars['pagesize'];
    $start = $pagesize * $pageno - $pagesize;
    $param = array();
    $where = ' WHERE 1 ';
    foreach ($vars as $var => $value) {
        if ($value != '') {
            switch ($var) {
                case 'device':
                case 'device_id':
                    $where .= generate_query_values($value, 'device_id');
                    break;
                case 'address':
                    if (isset($vars['searchby']) && $vars['searchby'] == 'ip') {
                        $value = trim($value);
                        $where .= generate_query_values($value, 'ipv4_addr', '%LIKE%');
                    } else {
                        if (isset($vars['searchby']) && $vars['searchby'] == 'mac') {
                            $value = str_replace(array(':', ' ', '-', '.', '0x'), '', $value);
                            $where .= generate_query_values($value, 'M.mac_addr', '%LIKE%');
                        } else {
                            $value = trim($value);
                            $where .= generate_query_values($value, 'username', '%LIKE%');
                        }
                    }
                    break;
            }
        }
    }
    // Check permissions
    $query_permitted = generate_query_permitted(array('device'), array('device_table' => 'M'));
    $query = 'FROM `wifi_sessions` AS M ';
    $query .= 'LEFT JOIN `wifi_radios` AS I ON I.`wifi_radio_id` = M.`radio_id` ';
    $query .= $where . $query_permitted;
    $query_count = 'SELECT COUNT(`wifi_session_id`) ' . $query;
    $query = 'SELECT *, M.`mac_addr` AS `session_mac` ' . $query;
    $query .= ' ORDER BY M.`timestamp` DESC';
    $query .= " LIMIT {$start},{$pagesize}";
    // Query wireless  sessions table
    $entries = dbFetchRows($query, $param);
    // Query wireless  sessions table count
    if ($pagination) {
        $count = dbFetchCell($query_count, $param);
    }
    $aps_db = dbFetchRows("SELECT `wifi_accesspoint_id`, `name`, `ap_number`  FROM `wifi_accesspoints`");
    foreach ($aps_db as $ap_db) {
        $aps_sorted_db[$ap_db['wifi_accesspoint_id']] = $ap_db;
    }
    $list = array('device' => FALSE, 'port' => FALSE);
    // A radio is like a port
    if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'search') {
        $list['device'] = TRUE;
    }
    if (!isset($vars['port']) || empty($vars['port']) || $vars['page'] == 'search') {
        $list['port'] = TRUE;
    }
    $string = generate_box_open();
    $string .= '<table class="table  table-striped table-hover table-condensed">' . PHP_EOL;
    if (!$short) {
        $string .= '  <thead>' . PHP_EOL;
        $string .= '    <tr>' . PHP_EOL;
        $string .= '      <th>MAC Address</th>' . PHP_EOL;
        $string .= '      <th>IP Address</th>' . PHP_EOL;
        $string .= '      <th>Username</th>' . PHP_EOL;
        $string .= '      <th>SSID/VLAN</th>' . PHP_EOL;
        $string .= '      <th>Last Seen</th>' . PHP_EOL;
        if ($list['device']) {
            $string .= '      <th>Device</th>' . PHP_EOL;
        }
        if ($list['port']) {
            $string .= '      <th>Interface/AP</th>' . PHP_EOL;
        }
        $string .= '    </tr>' . PHP_EOL;
        $string .= '  </thead>' . PHP_EOL;
    }
    $string .= '  <tbody>' . PHP_EOL;
    foreach ($entries as $entry) {
        $ap_id = $entry['accesspoint_id'];
        $interface = $aps_sorted_db[$ap_id]['name'];
        $string .= '  <tr>' . PHP_EOL;
        $string .= '    <td style="width: 140px;">' . generate_popup_link('mac', format_mac($entry['session_mac'])) . '</td>' . PHP_EOL;
        $string .= '    <td style="width: 140px;">' . generate_popup_link('ip', $entry['ipv4_addr']) . '</td>' . PHP_EOL;
        $string .= '    <td style="white-space: nowrap;">' . $entry['username'] . '</td>' . PHP_EOL;
        $string .= '    <td style="width: 140px;">' . $entry['ssid'] . '</td>' . PHP_EOL;
        $string .= '    <td style="white-space: nowrap;">' . $entry['timestamp'] . '</td>' . PHP_EOL;
        if ($list['device']) {
            $dev = device_by_id_cache($entry['device_id']);
            $string .= '    <td class="entity" style="white-space: nowrap;">' . generate_device_link($dev) . '</td>' . PHP_EOL;
        }
        if ($list['port']) {
            $string .= '    <td class="entity"><a href="' . generate_url(array('page' => 'device', 'device' => $entry['device_id'], 'tab' => 'wifi', 'view' => 'accesspoint', 'accesspoint' => $ap_id)) . '">' . $interface . '</a></td>' . PHP_EOL;
        }
        $string .= '  </tr>' . PHP_EOL;
    }
    $string .= '  </tbody>' . PHP_EOL;
    $string .= '</table>';
    $string .= generate_box_close();
    // Print pagination header
    if ($pagination) {
        $string = pagination($vars, $count) . $string . pagination($vars, $count);
    }
    // Print wireless sessions
    echo $string;
}
        } else {
            unset($as);
            unset($astext);
            unset($asn);
        }
        if (!isset($vars['graph'])) {
            $vars['graph'] = "bits";
        }
        $graph_type = "macaccounting_" . $vars['graph'];
        if ($vars['subview'] == "minigraphs") {
            if (!$asn) {
                $asn = "无会话";
            }
            echo "<div style='display: block; padding: 3px; margin: 3px; min-width: 221px; max-width:221px; min-height:90px; max-height:90px; text-align: center; float: left; background-color: #e5e5e5;'>\n      " . $addy['ipv4_address'] . " - " . $asn . "\n          <a href='#' onmouseover=\"return overlib('\\\n     <div style=\\'font-size: 16px; padding:5px; font-weight: bold; color: #555555;\\'>" . $name . " - " . $addy['ipv4_address'] . " - " . $asn . "</div>\\\n     <img src=\\'graph.php?id=" . $acc['ma_id'] . "&amp;type={$graph_type}&amp;from=" . $config['time']['twoday'] . "&amp;to=" . $config['time']['now'] . "&amp;width=450&amp;height=150\\'>\\\n     ', CENTER, LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 150);\" onmouseout=\"return nd();\" >\n          <img src='graph.php?id=" . $acc['ma_id'] . "&amp;type={$graph_type}&amp;from=" . $config['time']['twoday'] . "&amp;to=" . $config['time']['now'] . "&amp;width=213&amp;height=45'></a>\n\n          <span style='font-size: 10px;'>" . $name . "</span>\n         </div>";
        } else {
            echo "\n        <tr>\n          <td width=20></td>\n          <td width=200><bold>" . format_mac($acc['mac']) . "</bold></td>\n          <td width=200>" . implode($ips, "<br />") . "</td>\n          <td width=500>" . $name . " " . $arp_name . "</td>\n          <td width=100>" . formatRates($acc['bytes_input_rate'] / 8) . "</td>\n          <td width=100>" . formatRates($acc['bytes_output_rate'] / 8) . "</td>\n          <td width=100>" . format_number($acc['pkts_input_rate'] / 8) . "pps</td>\n          <td width=100>" . format_number($acc['pkts_output_rate'] / 8) . "pps</td>\n        </tr>\n    ";
            $peer_info['astext'];
            if ($vars['subview'] == "graphs") {
                $graph_array['type'] = $graph_type;
                $graph_array['id'] = $acc['ma_id'];
                $graph_array['height'] = "100";
                $graph_array['to'] = $config['time']['now'];
                echo '<tr><td colspan="8">';
                print_graph_row($graph_array);
                echo "</td></tr>";
                $i++;
            }
        }
    }
    echo "</table>";
}
示例#17
0
function humanize_port(&$port)
{
    global $config, $cache;
    // Exit if already humanized
    if ($port['humanized']) {
        return;
    }
    // If we can get the device data from the global cache, do it, else pull it from the db (mostly for external scripts)
    if (is_array($GLOBALS['cache']['devices']['id'][$port['device_id']])) {
        $device =& $GLOBALS['cache']['devices']['id'][$port['device_id']];
    } else {
        $device = device_by_id_cache($port['device_id']);
    }
    // Workaround for devices/ports who long time not updated and have empty port_label
    if (empty($port['port_label']) || strlen($port['port_label_base'] . $port['port_label_num']) == 0) {
        process_port_label($port, $device);
    }
    // Set humanised values for use in UI
    $port['human_speed'] = humanspeed($port['ifSpeed']);
    $port['human_type'] = rewrite_iftype($port['ifType']);
    $port['html_class'] = port_html_class($port['ifOperStatus'], $port['ifAdminStatus'], $port['encrypted']);
    $port['human_mac'] = format_mac($port['ifPhysAddress']);
    // Set entity_* values for code which expects them.
    $port['entity_name'] = $port['port_label'];
    $port['entity_shortname'] = $port['port_label_short'];
    $port['entity_descr'] = $port['ifAlias'];
    $port['table_tab_colour'] = "#aaaaaa";
    $port['row_class'] = "";
    $port['icon'] = 'port-ignored';
    // Default
    $port['admin_status'] = $port['ifAdminStatus'];
    if ($port['ifAdminStatus'] == "down") {
        $port['admin_status'] = 'disabled';
        $port['row_class'] = "disabled";
        $port['icon'] = 'port-disabled';
    } elseif ($port['ifAdminStatus'] == "up") {
        $port['admin_status'] = 'enabled';
        switch ($port['ifOperStatus']) {
            case 'up':
                $port['table_tab_colour'] = "#194B7F";
                $port['row_class'] = "up";
                $port['icon'] = 'port-up';
                break;
            case 'monitoring':
                // This is monitoring ([e|r]span) ports
                $port['table_tab_colour'] = "#008C00";
                $port['row_class'] = "success";
                $port['icon'] = 'port-up';
                break;
            case 'down':
                $port['table_tab_colour'] = "#cc0000";
                $port['row_class'] = "error";
                $port['icon'] = 'port-down';
                break;
            case 'lowerLayerDown':
                $port['table_tab_colour'] = "#ff6600";
                $port['row_class'] = "warning";
                $port['icon'] = 'port-down';
                break;
            case 'testing':
            case 'unknown':
            case 'dormant':
            case 'notPresent':
                $port['table_tab_colour'] = "#85004b";
                $port['row_class'] = "info";
                $port['icon'] = 'port-ignored';
                break;
        }
    }
    // If the device is down, colour the row/tab as 'warning' meaning that the entity is down because of something below it.
    if ($device['status'] == '0') {
        $port['table_tab_colour'] = "#ff6600";
        $port['row_class'] = "warning";
        $port['icon'] = 'port-ignored';
    }
    $port['in_rate'] = $port['ifInOctets_rate'] * 8;
    $port['out_rate'] = $port['ifOutOctets_rate'] * 8;
    // Colour in bps based on speed if > 50, else by UI convention.
    if ($port['ifSpeed'] > 0) {
        $in_perc = round($port['in_rate'] / $port['ifSpeed'] * 100);
        $out_perc = round($port['out_rate'] / $port['ifSpeed'] * 100);
    } else {
        // exclude division by zero error
        $in_perc = 0;
        $out_perc = 0;
    }
    if ($port['in_rate'] == 0) {
        $port['bps_in_style'] = '';
    } elseif ($in_perc < '50') {
        $port['bps_in_style'] = 'color: #008C00;';
    } else {
        $port['bps_in_style'] = 'color: ' . percent_colour($in_perc) . '; ';
    }
    // Colour out bps based on speed if > 50, else by UI convention.
    if ($port['out_rate'] == 0) {
        $port['bps_out_style'] = '';
    } elseif ($out_perc < '50') {
        $port['bps_out_style'] = 'color: #394182;';
    } else {
        $port['bps_out_style'] = 'color: ' . percent_colour($out_perc) . '; ';
    }
    // Colour in and out pps based on UI convention
    $port['pps_in_style'] = $port['ifInUcastPkts_rate'] == 0 ? '' : 'color: #740074;';
    $port['pps_out_style'] = $port['ifOutUcastPkts_rate'] == 0 ? '' : 'color: #FF7400;';
    $port['humanized'] = TRUE;
    /// Set this so we can check it later.
}