$Database = new Database_PDO(); $Result = new Result(); $User = new User($Database); $Subnets = new Subnets($Database); $Sections = new Sections($Database); $Tools = new Tools($Database); $Addresses = new Addresses($Database); # verify that user is logged in $User->check_user_session(); # fetch search term $search_term = $_REQUEST['search_term']; //initialize Pear IPv6 object require_once dirname(__FILE__) . '/../../../functions/PEAR/Net/IPv6.php'; $Net_IPv6 = new Net_IPv6(); // ipv6 ? if ($Net_IPv6->checkIPv6($search_term) != false) { $type = "IPv6"; } elseif (strlen($search_term) == 17 && substr_count($search_term, ":") == 5) { $type = "mac"; //count : -> must be 5 } else { if (strlen($search_term) == 12 && substr_count($search_term, ":") == 0 && substr_count($search_term, ".") == 0) { $type = "mac"; //no dots or : -> mac without : } else { $type = $Addresses->identify_address($search_term); //identify address type } } # reformat if IP address for search if ($type == "IPv4") {
<dd><strong>' . highlight_search(htmlentities($name)) . '</h5> <small>' . $result['hostname'] . '<br /> ' . htmlentities($result['location'], 0, 'UTF-8') . ' | Accesspoint</small></strong></dd> </dl>'; } echo "</a></li>"; } /// SEARCH IP ADDRESSES list($addr, $mask) = explode('/', $queryString); $address_type = "ipv4"; if (is_numeric(stripos($queryString, ':abcdef'))) { $address_type = 'ipv6'; } switch ($address_type) { case 'ipv6': $ip_valid = Net_IPv6::checkIPv6($addr); break; case 'ipv4': $ip_valid = Net_IPv4::validateIP($addr); break; } # if ($ip_valid) # { # // If address valid -> seek occurrence in network # if (!$mask) { $mask = ($address_type === 'ipv4') ? '32' : '128'; }# # } else { // If address not valid -> seek LIKE $where .= ' AND A.`ipv4_address` LIKE ?'; $param[] = '%' . $addr . '%'; # } // FIXME no v6 yet.
/** * 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']; $pageno = isset($vars['pageno']) && !empty($vars['pageno']) ? $vars['pageno'] : 1; $pagesize = isset($vars['pagesize']) && !empty($vars['pagesize']) ? $vars['pagesize'] : 10; $start = $pagesize * $pageno - $pagesize; $param = array(); $where = ' WHERE 1 '; foreach ($vars as $var => $value) { if ($value != '') { switch ($var) { case 'device': case 'device_id': $where .= ' AND I.`device_id` = ?'; $param[] = $value; 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'), '', mres($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 Address</th>' . PHP_EOL; $string .= ' <th>IP Address</th>' . PHP_EOL; if ($list['device']) { $string .= ' <th>Device</th>' . PHP_EOL; } if ($list['port']) { $string .= ' <th>Interface</th>' . PHP_EOL; } $string .= ' <th>Remote Device</th>' . PHP_EOL; $string .= ' <th>Remote Interface</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 = 'Self Device'; } if ($arp_host['port_id'] == $entry['port_id']) { $arp_if = 'Self Port'; } $string .= ' <tr>' . PHP_EOL; $string .= ' <td width="160">' . formatMac($entry['mac_address']) . '</td>' . PHP_EOL; $string .= ' <td width="140">' . $ip_address . '</td>' . PHP_EOL; if ($list['device']) { $dev = device_by_id_cache($entry['device_id']); $string .= ' <td class="entity" 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, short_ifname($entry['label'])) . ' ' . $port_error . '</td>' . PHP_EOL; } $string .= ' <td class="entity" width="200">' . $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; }
include "../config.php"; include_once "../includes/definitions.inc.php"; include "includes/functions.inc.php"; include "../includes/functions.inc.php"; include "includes/authenticate.inc.php"; if (!$_SESSION['authenticated']) { echo "unauthenticated"; exit; } if ($_GET['query'] && $_GET['cmd']) { $host = $_GET['query']; $ip = ''; if (Net_IPv4::validateIP($host)) { $ip = $host; $ip_version = 4; } elseif (Net_IPv6::checkIPv6($host)) { $ip = $host; $ip_version = 6; } else { $ip = gethostbyname($host); if ($ip && $ip != $host) { $ip_version = 4; } else { $ip = gethostbyname6($host, FALSE); if ($ip) { $ip_version = 6; } } } if ($ip) { switch ($_GET['cmd']) {
// hardcode auth for all with config function print_debug('认证旁路 $config[\'allow_unauth_graphs\'].'); } elseif (isset($config['allow_unauth_graphs_cidr']) && count($config['allow_unauth_graphs_cidr'])) { foreach ($config['allow_unauth_graphs_cidr'] as $range) { list($net, $mask) = explode('/', trim($range)); if (Net_IPv4::validateIP($net)) { // IPv4 $mask = $mask != NULL ? $mask : '32'; $range = $net . '/' . $mask; if ($mask >= 0 && $mask <= 32 && Net_IPv4::ipInNetwork($_SERVER['REMOTE_ADDR'], $range)) { $auth = TRUE; // hardcode authenticated for matched subnet print_debug("认证的CIDR匹配IPv4 {$range}."); break; } } elseif (Net_IPv6::checkIPv6($net)) { // IPv6 $mask = $mask != NULL ? $mask : '128'; $range = $net . '/' . $mask; if ($mask >= 0 && $mask <= 128 && Net_IPv6::isInNetmask($_SERVER['REMOTE_ADDR'], $range)) { $auth = TRUE; // hardcode authenticated for matched subnet print_debug("认证的CIDR匹配IPv6 {$range}"); break; } } } } if (!$auth) { // Normal auth include $config['html_dir'] . "/includes/authenticate.inc.php";
function generate_entity_link($type, $entity, $text = NULL, $graph_type = NULL) { global $config, $entity_cache; if (is_numeric($entity)) { $entity = get_entity_by_id_cache($type, $entity); } switch ($type) { case "mempool": if (empty($text)) { $text = $entity['mempool_descr']; } $link = generate_link($text, array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'health', 'metric' => 'mempool')); break; case "processor": if (empty($text)) { $text = $entity['processor_descr']; } $link = generate_link($text, array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'health', 'metric' => 'processor')); break; case "sensor": if (empty($text)) { $text = $entity['sensor_descr']; } $link = generate_link($text, array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'health', 'metric' => $entity['sensor_class'])); break; case "toner": if (empty($text)) { $text = $entity['toner_descr']; } $link = generate_link($text, array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'printing')); break; case "port": $link = generate_port_link($entity, $text, $graph_type); break; case "storage": if (empty($text)) { $text = $entity['storage_descr']; } $link = generate_link($text, array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'health', 'metric' => 'storage')); break; case "bgp_peer": if (Net_IPv6::checkIPv6($entity['bgpPeerRemoteAddr'])) { $addr = Net_IPv6::compress($entity['bgpPeerRemoteAddr']); } else { $addr = $entity['bgpPeerRemoteAddr']; } if (empty($text)) { $text = $addr . " (AS" . $entity['bgpPeerRemoteAs'] . ")"; } $link = generate_link($text, array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'routing', 'proto' => 'bgp')); break; case "netscaler_vsvr": if (empty($text)) { $text = $entity['vsvr_label']; } $link = generate_link($text, array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'loadbalancer', 'type' => 'netscaler_vsvr', 'vsvr' => $entity['vsvr_id'])); break; case "netscaler_svc": if (empty($text)) { $text = $entity['svc_label']; } $link = generate_link($text, array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'loadbalancer', 'type' => 'netscaler_services', 'svc' => $entity['svc_id'])); break; default: $link = $entity[$type . '_id']; } return $link; }
/** * Set the host. Returns true on success, false on failure (if there are * any invalid characters). * * @access public * @param string $host * @return bool */ public function set_host($host) { if ($host === null || $host === '') { $this->host = null; $this->valid[__FUNCTION__] = true; return true; } elseif ($host[0] === '[' && substr($host, -1) === ']') { if (Net_IPv6::checkIPv6(substr($host, 1, -1))) { $this->host = $host; $this->valid[__FUNCTION__] = true; return true; } else { $this->host = null; $this->valid[__FUNCTION__] = false; return false; } } else { $this->host = $this->replace_invalid_with_pct_encoding($host, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~!$&\'()*+,;=', SIMPLEPIE_LOWERCASE); $this->valid[__FUNCTION__] = true; return true; } }
/** * 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; }
function get_mx($dnsname) { $resolver = new Net_DNS_Resolver(); $response = $resolver->query($dnsname, 'MX'); global $res_array; if ($response) { foreach ($response->answer as $rr) { $ipaddr = ""; $ip_type = ""; $ipaddr = get_ip_for_a($rr->exchange); if (Net_CheckIP::check_ip($ipaddr)) { $ip_type = "ipv4"; } if (Net_IPv6::checkIPv6($ipaddr)) { $ip_type = "ipv6"; } array_push($res_array, array('prio' => $rr->preference, 'dnsname' => $rr->exchange, 'ipaddr' => $ipaddr, 'iptype' => $ip_type)); } asort($res_array); return true; } else { return false; } }
ini_set('error_reporting', E_ALL); } require '../includes/defaults.inc.php'; require '../config.php'; require_once '../includes/definitions.inc.php'; require 'includes/functions.inc.php'; require '../includes/functions.php'; require 'includes/authenticate.inc.php'; if (!$_SESSION['authenticated']) { echo 'unauthenticated'; exit; } $output = ''; if ($_GET['query'] && $_GET['cmd']) { $host = $_GET['query']; if (Net_IPv6::checkIPv6($host) || Net_IPv4::validateip($host) || preg_match('/^[a-zA-Z0-9.-]*$/', $host)) { switch ($_GET['cmd']) { case 'whois': $cmd = $config['whois'] . " {$host} | grep -v \\%"; break; case 'ping': $cmd = $config['ping'] . " -c 5 {$host}"; break; case 'tracert': $cmd = $config['mtr'] . " -r -c 5 {$host}"; break; case 'nmap': if ($_SESSION['userlevel'] != '10') { echo 'insufficient privileges'; } else { $cmd = $config['nmap'] . " {$host}";
ini_set('error_reporting', E_ALL); } require '../includes/defaults.inc.php'; require '../config.php'; require_once '../includes/definitions.inc.php'; require 'includes/functions.inc.php'; require '../includes/functions.php'; require 'includes/authenticate.inc.php'; if (!$_SESSION['authenticated']) { echo 'unauthenticated'; exit; } $output = ''; if ($_GET['query'] && $_GET['cmd']) { $host = $_GET['query']; if (Net_IPv6::checkIPv6($host) || Net_IPv4::validateip($host) || filter_var('http://' . $host, FILTER_VALIDATE_URL)) { switch ($_GET['cmd']) { case 'whois': $cmd = $config['whois'] . " {$host} | grep -v \\%"; break; case 'ping': $cmd = $config['ping'] . " -c 5 {$host}"; break; case 'tracert': $cmd = $config['mtr'] . " -r -c 5 {$host}"; break; case 'nmap': if ($_SESSION['userlevel'] != '10') { echo 'insufficient privileges'; } else { $cmd = $config['nmap'] . " {$host}";
/** * verify ip address /mask 10.10.10.10./24 - CIDR * * if subnet == 0 we dont check if IP is subnet -> needed for ipCalc */ function verifyCidr($cidr, $issubnet = 1) { /* split it to network and subnet */ $temp = explode("/", $cidr); $network = $temp[0]; $netmask = $temp[1]; //if one part is missing die if (empty($network) || empty($netmask)) { $errors[] = _("Invalid CIDR format!"); } /* Identify address type */ $type = IdentifyAddress($network); /* IPv4 verification */ if ($type == 'IPv4') { require_once 'PEAR/Net/IPv4.php'; $Net_IPv4 = new Net_IPv4(); if ($net = $Net_IPv4->parseAddress($cidr)) { //validate IP if (!$Net_IPv4->validateIP($net->ip)) { $errors[] = _("Invalid IP address!"); } elseif ($net->network != $net->ip && $issubnet == 1) { $errors[] = _("IP address cannot be subnet! (Consider using") . " " . $net->network . ")"; } elseif (!$Net_IPv4->validateNetmask($net->netmask)) { $errors[] = _('Invalid netmask') . ' ' . $net->netmask; } } else { $errors[] = _('Invalid CIDR format!'); } } else { require_once 'PEAR/Net/IPv6.php'; $Net_IPv6 = new Net_IPv6(); //validate IPv6 if (!$Net_IPv6->checkIPv6($cidr)) { $errors[] = _("Invalid IPv6 address!"); } else { //validate subnet $subnet = $Net_IPv6->getNetmask($cidr); $subnet = $Net_IPv6->compress($subnet); //get subnet part $subnetParse = explode("/", $cidr); $subnetMask = $subnetParse[1]; $subnetNet = $subnetParse[0]; if ($subnetNet != $subnet && $issubnet == 1) { $errors[] = _("IP address cannot be subnet! (Consider using") . " " . $subnet . "/" . $subnetMask . ")"; } } } /* return array of errors */ return $errors; }
/** * Display IPv4/IPv6 addresses. * * Display pages with IP addresses from device Interfaces. * * @param array $vars * @return none * */ function print_addresses($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; if (in_array($vars['search'], array('6', 'v6', 'ipv6')) || in_array($vars['view'], array('6', 'v6', 'ipv6'))) { $address_type = 'ipv6'; } else { $address_type = 'ipv4'; } $ip_array = array(); $param = array(); $where = ' WHERE 1 '; $param_netscaler = array(); $where_netscaler = " WHERE `vsvr_ip` != '0.0.0.0' AND `vsvr_ip` != '' "; foreach ($vars as $var => $value) { if ($value != '') { switch ($var) { case 'device': case 'device_id': $where .= generate_query_values($value, 'I.device_id'); $where_netscaler .= generate_query_values($value, 'N.device_id'); break; case 'interface': $where .= generate_query_values($value, 'I.ifDescr', 'LIKE%'); break; case 'network': list($net, $mask) = explode('/', $value); if (is_numeric(stripos($net, ':abcdef'))) { $address_type = 'ipv6'; } $where .= generate_query_values($value, 'N.ip_network', 'LIKE%'); break; case 'address': list($addr, $mask) = explode('/', $value); if (is_numeric(stripos($addr, ':abcdef'))) { $address_type = 'ipv6'; } switch ($address_type) { case 'ipv6': $ip_valid = Net_IPv6::checkIPv6($addr); break; case 'ipv4': $ip_valid = Net_IPv4::validateIP($addr); break; } if ($ip_valid) { // If address valid -> seek occurrence in network if (!$mask) { $mask = $address_type === 'ipv4' ? '32' : '128'; } $where_netscaler .= generate_query_values($addr, 'N.vsvr_ip'); } else { // If address not valid -> seek LIKE $where .= generate_query_values($addr, 'A.ip_address', '%LIKE%'); $where_netscaler .= generate_query_values($addr, 'N.vsvr_ip', '%LIKE%'); } break; } } } $query_device_permitted = generate_query_permitted(array('device'), array('device_table' => 'D')); $query_port_permitted = generate_query_permitted(array('port'), array('port_table' => 'I')); // Also search netscaler Vserver IPs $query_netscaler = 'FROM `netscaler_vservers` AS N '; $query_netscaler .= 'LEFT JOIN `devices` AS D ON N.`device_id` = D.`device_id` '; $query_netscaler .= $where_netscaler . $query_device_permitted; //$query_netscaler_count = 'SELECT COUNT(`vsvr_id`) ' . $query_netscaler; $query_netscaler = 'SELECT * ' . $query_netscaler; $query_netscaler .= ' ORDER BY N.`vsvr_ip`'; // Override by address type if ($address_type == 'ipv6') { $query_netscaler = str_replace(array('vsvr_ip', '0.0.0.0'), array('vsvr_ipv6', '0:0:0:0:0:0:0:0'), $query_netscaler); //$query_netscaler_count = str_replace(array('vsvr_ip', '0.0.0.0'), array('vsvr_ipv6', '0:0:0:0:0:0:0:0'), $query_netscaler_count); } $entries = dbFetchRows($query_netscaler, $param_netscaler); // Rewrite netscaler addresses foreach ($entries as $entry) { $ip_address = $address_type == 'ipv4' ? $entry['vsvr_ip'] : $entry['vsvr_' . $address_type]; $ip_network = $address_type == 'ipv4' ? $entry['vsvr_ip'] . '/32' : $entry['vsvr_' . $address_type] . '/128'; $ip_array[] = array('type' => 'netscaler_vsvr', 'device_id' => $entry['device_id'], 'hostname' => $entry['hostname'], 'vsvr_id' => $entry['vsvr_id'], 'vsvr_label' => $entry['vsvr_label'], 'ifAlias' => 'Netscaler: ' . $entry['vsvr_type'] . '/' . $entry['vsvr_entitytype'], $address_type . '_address' => $ip_address, $address_type . '_network' => $ip_network); } //print_message($query_netscaler_count); $query = 'FROM `ip_addresses` AS A '; $query .= 'LEFT JOIN `ports` AS I ON I.`port_id` = A.`port_id` '; $query .= 'LEFT JOIN `devices` AS D ON I.`device_id` = D.`device_id` '; $query .= 'LEFT JOIN `ip_networks` AS N ON N.`ip_network_id` = A.`ip_network_id` '; $query .= $where . $query_port_permitted; //$query_count = 'SELECT COUNT(`ip_address_id`) ' . $query; $query = 'SELECT * ' . $query; $query .= ' ORDER BY A.`ip_address`'; if ($ip_valid) { $pagination = FALSE; } // Override by address type $query = str_replace(array('ip_address', 'ip_network'), array($address_type . '_address', $address_type . '_network'), $query); //$query_count = str_replace(array('ip_address', 'ip_network'), array($address_type.'_address', $address_type.'_network'), $query_count); // Query addresses $entries = dbFetchRows($query, $param); $ip_array = array_merge($ip_array, $entries); $ip_array = array_sort($ip_array, $address_type . '_address'); // Query address count //if ($pagination) { $count = dbFetchCell($query_count, $param); } if ($pagination) { $count = count($ip_array); $ip_array = array_slice($ip_array, $start, $pagesize); } $list = array('device' => FALSE); if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'search') { $list['device'] = TRUE; } $string = generate_box_open($vars['header']); $string .= '<table class="' . OBS_CLASS_TABLE_STRIPED . '">' . PHP_EOL; if (!$short) { $string .= ' <thead>' . PHP_EOL; $string .= ' <tr>' . PHP_EOL; if ($list['device']) { $string .= ' <th>Device</th>' . PHP_EOL; } $string .= ' <th>Interface</th>' . PHP_EOL; $string .= ' <th>Address</th>' . PHP_EOL; $string .= ' <th>Description</th>' . PHP_EOL; $string .= ' </tr>' . PHP_EOL; $string .= ' </thead>' . PHP_EOL; } $string .= ' <tbody>' . PHP_EOL; foreach ($ip_array as $entry) { $address_show = TRUE; if ($ip_valid) { // If address not in specified network, don't show entry. if ($address_type === 'ipv4') { $address_show = Net_IPv4::ipInNetwork($entry[$address_type . '_address'], $addr . '/' . $mask); } else { $address_show = Net_IPv6::isInNetmask($entry[$address_type . '_address'], $addr, $mask); } } if ($address_show) { list($prefix, $length) = explode('/', $entry[$address_type . '_network']); if (port_permitted($entry['port_id']) || $entry['type'] == 'netscaler_vsvr') { if ($entry['type'] == 'netscaler_vsvr') { $entity_link = generate_entity_link($entry['type'], $entry); } else { humanize_port($entry); if ($entry['ifInErrors_delta'] > 0 || $entry['ifOutErrors_delta'] > 0) { $port_error = generate_port_link($entry, '<span class="label label-important">Errors</span>', 'port_errors'); } $entity_link = generate_port_link($entry, $entry['port_label_short']) . ' ' . $port_error; } $device_link = generate_device_link($entry); $string .= ' <tr>' . PHP_EOL; if ($list['device']) { $string .= ' <td class="entity" style="white-space: nowrap">' . $device_link . '</td>' . PHP_EOL; } $string .= ' <td class="entity">' . $entity_link . '</td>' . PHP_EOL; if ($address_type === 'ipv6') { $entry[$address_type . '_address'] = Net_IPv6::compress($entry[$address_type . '_address']); } $string .= ' <td>' . generate_popup_link('ip', $entry[$address_type . '_address'] . '/' . $length) . '</td>' . PHP_EOL; $string .= ' <td>' . $entry['ifAlias'] . '</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 addresses echo $string; }
function entity_rewrite($entity_type, &$entity) { $translate = entity_type_translate_array($entity_type); // By default, fill $entity['entity_name'] with name_field contents. if (isset($translate['name_field'])) { $entity['entity_name'] = $entity[$translate['name_field']]; } // By default, fill $entity['entity_shortname'] with shortname_field contents. Fallback to entity_name when field name is not set. if (isset($translate['shortname_field'])) { $entity['entity_shortname'] = $entity[$translate['name_field']]; } else { $entity['entity_shortname'] = $entity['entity_name']; } // By default, fill $entity['entity_descr'] with descr_field contents. if (isset($translate['descr_field'])) { $entity['entity_descr'] = $entity[$translate['descr_field']]; } // By default, fill $entity['entity_id'] with id_field contents. if (isset($translate['id_field'])) { $entity['entity_id'] = $entity[$translate['id_field']]; } switch ($entity_type) { case "bgp_peer": // Special handling of name/shortname/descr for bgp_peer, since it combines multiple elements. if (Net_IPv6::checkIPv6($entity['bgpPeerRemoteAddr'])) { $addr = Net_IPv6::compress($entity['bgpPeerRemoteAddr']); } else { $addr = $entity['bgpPeerRemoteAddr']; } $entity['entity_name'] = "AS" . $entity['bgpPeerRemoteAs'] . " " . $addr; $entity['entity_shortname'] = $addr; $entity['entity_descr'] = $entity['astext']; break; case "sla": $entity['entity_name'] = "SLA #" . $entity['sla_index'] . " (" . $entity['sla_tag'] . ")"; $entity['entity_shortname'] = "#" . $entity['sla_index'] . " (" . $entity['sla_tag'] . ")"; break; case "pseudowire": $entity['entity_name'] = $entity['pwID'] . ($entity['pwDescr'] ? " (" . $entity['pwDescr'] . ")" : ''); $entity['entity_shortname'] = $entity['pwID']; break; } }
function is_ipv6_valid($ipv6_address, $ipv6_prefixlen = NULL) { if (strpos($ipv6_address, '/') !== FALSE) { list($ipv6_address, $ipv6_prefixlen) = explode('/', $ipv6_address); } // False if prefix less or equal 0 and more 128 if (is_numeric($ipv6_prefixlen) && ($ipv6_prefixlen < '0' || $ipv6_prefixlen > '128')) { return FALSE; } // False if invalid IPv6 syntax if (!Net_IPv6::checkIPv6($ipv6_address)) { return FALSE; } $ipv6_type = Net_IPv6::getAddressType($ipv6_address); // False if link-local if ($ipv6_type == NET_IPV6_LOCAL_LINK || $ipv6_type == NET_IPV6_UNSPECIFIED) { return FALSE; } return TRUE; }
function validate_ipv6($ip) { // Singleton static $class = null; if ($class === null) { $class = new Net_IPv6(); } return $class->checkIPv6($ip); }
<div id="center"> <div id="top" style="background: <?php echo $config['header_color']; ?> ;"> <table cellpadding="0" cellspacing="0" width="100%"> <tr> <td align="left"></td> <td align="right"> <?php if ($_SESSION['authenticated']) { echo "Logged in as <b>" . $_SESSION['username'] . "</b> (<a href='?logout=yes'>Logout</a>)"; } else { echo "Not logged in!"; } if (Net_IPv6::checkIPv6($_SERVER['REMOTE_ADDR'])) { echo " via <b>IPv6</b>"; } else { echo " via <b>IPv4</b>"; } ?> </td> </tr> </table> </div> <div id="header" style="border: 1px none #ccf;"> <table width="100%" style="padding: 0px; margin:0px;"> <tr> <td style="padding: 0px; margin:0px; border: none;"> <div id="logo" style="padding: 10px"><a href="index.php"><img src="<?php
function generate_entity_link($type, $entity, $text = NULL, $graph_type = NULL, $escape = TRUE) { global $config, $entity_cache; if (is_numeric($entity)) { $entity = get_entity_by_id_cache($type, $entity); } // Rewrite sensor subtypes to 'sensor' $translate = entity_type_translate_array($type); if (isset($translate['parent_type'])) { $type = $translate['parent_type']; } switch ($type) { case "device": if (empty($text)) { $text = $entity['hostname']; } // FIXME use name_field property for all of these? Like entity_rewrite above does. $link = generate_link($text, array('page' => 'device', 'device' => $entity['device_id']), array(), $escape); break; case "mempool": if (empty($text)) { $text = $entity['mempool_descr']; } $link = generate_link($text, array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'health', 'metric' => 'mempool'), array(), $escape); break; case "processor": if (empty($text)) { $text = $entity['processor_descr']; } $link = generate_link($text, array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'health', 'metric' => 'processor'), array(), $escape); break; case "sensor": if (empty($text)) { $text = $entity['sensor_descr']; } $link = generate_link($text, array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'health', 'metric' => $entity['sensor_class']), array(), $escape); break; case "toner": if (empty($text)) { $text = $entity['toner_descr']; } $link = generate_link($text, array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'printing'), array(), $escape); break; case "port": $link = generate_port_link($entity, $text, $graph_type, $escape); break; case "storage": if (empty($text)) { $text = $entity['storage_descr']; } $link = generate_link($text, array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'health', 'metric' => 'storage'), array(), $escape); break; case "bgp_peer": if (Net_IPv6::checkIPv6($entity['bgpPeerRemoteAddr'])) { $addr = Net_IPv6::compress($entity['bgpPeerRemoteAddr']); } else { $addr = $entity['bgpPeerRemoteAddr']; } if (empty($text)) { $text = $addr . " (AS" . $entity['bgpPeerRemoteAs'] . ")"; } $link = generate_link($text, array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'routing', 'proto' => 'bgp'), array(), $escape); break; case "netscaler_vsvr": if (empty($text)) { $text = $entity['vsvr_label']; } $link = generate_link($text, array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'loadbalancer', 'type' => 'netscaler_vsvr', 'vsvr' => $entity['vsvr_id']), array(), $escape); break; case "netscaler_svc": if (empty($text)) { $text = $entity['svc_label']; } $link = generate_link($text, array('page' => 'device', 'device' => $entity['device_id'], 'tab' => 'loadbalancer', 'type' => 'netscaler_services', 'svc' => $entity['svc_id']), array(), $escape); break; default: $link = $entity[$type . '_id']; } return $link; }