Beispiel #1
0
function scanIPv6Space($pairlist)
{
    $ret = array();
    if (!count($pairlist)) {
        // this is normal for a network completely divided into smaller parts
        return $ret;
    }
    $or = '';
    $whereexpr1 = '(';
    $whereexpr2 = '(';
    $whereexpr3 = '(';
    $whereexpr4 = '(';
    $whereexpr6 = '(';
    $qparams = array();
    foreach ($pairlist as $tmp) {
        $whereexpr1 .= $or . "ip between ? and ?";
        $whereexpr2 .= $or . "ip between ? and ?";
        $whereexpr3 .= $or . "vip between ? and ?";
        $whereexpr4 .= $or . "rsip between ? and ?";
        $whereexpr6 .= $or . "l.ip between ? and ?";
        $or = ' or ';
        $qparams[] = $tmp['first'];
        $qparams[] = $tmp['last'];
    }
    $whereexpr1 .= ')';
    $whereexpr2 .= ')';
    $whereexpr3 .= ')';
    $whereexpr4 .= ')';
    $whereexpr6 .= ')';
    // 1. collect labels and reservations
    $query = "select ip, name, comment, reserved from IPv6Address " . "where {$whereexpr1} and (reserved = 'yes' or name != '' or comment != '')";
    $result = usePreparedSelectBlade($query, $qparams);
    while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
        $ip_bin = $row['ip'];
        if (!isset($ret[$ip_bin])) {
            $ret[$ip_bin] = constructIPAddress($ip_bin);
        }
        $ret[$ip_bin]['name'] = $row['name'];
        $ret[$ip_bin]['comment'] = $row['comment'];
        $ret[$ip_bin]['reserved'] = $row['reserved'];
    }
    unset($result);
    // 2. check for allocations
    $query = "select ip, object_id, name, type " . "from IPv6Allocation where {$whereexpr2} order by type";
    $result = usePreparedSelectBlade($query, $qparams);
    // release DBX early to avoid issues with nested spotEntity() calls
    $allRows = $result->fetchAll(PDO::FETCH_ASSOC);
    unset($result);
    foreach ($allRows as $row) {
        $ip_bin = $row['ip'];
        if (!isset($ret[$ip_bin])) {
            $ret[$ip_bin] = constructIPAddress($ip_bin);
        }
        $oinfo = spotEntity('object', $row['object_id']);
        $ret[$ip_bin]['allocs'][] = array('type' => $row['type'], 'name' => $row['name'], 'object_id' => $row['object_id'], 'object_name' => $oinfo['dname']);
    }
    // 3. look for virtual services
    $query = "select id, vip from IPv4VS where {$whereexpr3}";
    $result = usePreparedSelectBlade($query, $qparams);
    $allRows = $result->fetchAll(PDO::FETCH_ASSOC);
    unset($result);
    foreach ($allRows as $row) {
        $ip_bin = $row['vip'];
        if (!isset($ret[$ip_bin])) {
            $ret[$ip_bin] = constructIPAddress($ip_bin);
        }
        $ret[$ip_bin]['vslist'][] = $row['id'];
    }
    // 4. don't forget about real servers along with pools
    $query = "select rsip, rspool_id from IPv4RS where {$whereexpr4}";
    $result = usePreparedSelectBlade($query, $qparams);
    while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
        $ip_bin = $row['rsip'];
        if (!isset($ret[$ip_bin])) {
            $ret[$ip_bin] = constructIPAddress($ip_bin);
        }
        $ret[$ip_bin]['rsplist'][] = $row['rspool_id'];
    }
    unset($result);
    // 6. collect last log message
    $query = "select l.ip, l.user, UNIX_TIMESTAMP(l.date) AS time from IPv6Log l INNER JOIN " . " (SELECT MAX(id) as id FROM IPv6Log GROUP BY ip) v USING (id) WHERE {$whereexpr6}";
    $result = usePreparedSelectBlade($query, $qparams);
    while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
        $ip_bin = $row['ip'];
        if (isset($ret[$ip_bin])) {
            $ret[$ip_bin]['last_log'] = array('user' => $row['user'], 'time' => $row['time']);
        }
    }
    unset($result);
    return $ret;
}
Beispiel #2
0
function getIPAddress($ip_bin)
{
    $scanres = scanIPSpace(array(array('first' => $ip_bin, 'last' => $ip_bin)));
    if (empty($scanres)) {
        return constructIPAddress($ip_bin);
    }
    markupIPAddrList($scanres);
    return $scanres[$ip_bin];
}