当前位置: 首页>>代码示例>>PHP>>正文


PHP Net_IPv6::checkIPv6方法代码示例

本文整理汇总了PHP中Net_IPv6::checkIPv6方法的典型用法代码示例。如果您正苦于以下问题:PHP Net_IPv6::checkIPv6方法的具体用法?PHP Net_IPv6::checkIPv6怎么用?PHP Net_IPv6::checkIPv6使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Net_IPv6的用法示例。


在下文中一共展示了Net_IPv6::checkIPv6方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: Result

$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") {
开发者ID:martinsv,项目名称:phpipam,代码行数:31,代码来源:search-results-export.php

示例2: highlight_search

         <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.
开发者ID:skive,项目名称:observium,代码行数:31,代码来源:ajax_search.php

示例3: print_arptable

/**
 * 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));
//.........这里部分代码省略.........
开发者ID:rhizalpatrax64bit,项目名称:StacksNetwork,代码行数:101,代码来源:arptable.inc.php

示例4: elseif

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']) {
开发者ID:skive,项目名称:observium,代码行数:31,代码来源:netcmd.php

示例5: print_debug

    // 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";
开发者ID:rhizalpatrax64bit,项目名称:StacksNetwork,代码行数:31,代码来源:graph.php

示例6: generate_entity_link

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;
}
开发者ID:rhizalpatrax64bit,项目名称:StacksNetwork,代码行数:68,代码来源:entities.inc.php

示例7: set_host

 /**
  * 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;
     }
 }
开发者ID:karlstolley,项目名称:twitter-workshop-cw2010,代码行数:30,代码来源:simplepie.class.php

示例8: print_arptable

/**
 * 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']) {
//.........这里部分代码省略.........
开发者ID:Natolumin,项目名称:observium,代码行数:101,代码来源:arptable.inc.php

示例9: get_mx

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;
    }
}
开发者ID:hggh,项目名称:cpves,代码行数:24,代码来源:func.inc.php

示例10: ini_set

    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}";
开发者ID:samyscoub,项目名称:librenms,代码行数:31,代码来源:netcmd.php

示例11: ini_set

    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}";
开发者ID:wiad,项目名称:librenms,代码行数:31,代码来源:netcmd.php

示例12: verifyCidr

/**
 * 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;
}
开发者ID:retexica,项目名称:phpipam,代码行数:55,代码来源:functions-network.php

示例13: print_addresses

/**
 * 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` ';
//.........这里部分代码省略.........
开发者ID:Natolumin,项目名称:observium,代码行数:101,代码来源:addresses.inc.php

示例14: entity_rewrite

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;
    }
}
开发者ID:Natolumin,项目名称:observium,代码行数:43,代码来源:entities.inc.php

示例15: is_ipv6_valid

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;
}
开发者ID:rhizalpatrax64bit,项目名称:StacksNetwork,代码行数:20,代码来源:functions.inc.php


注:本文中的Net_IPv6::checkIPv6方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。