Ejemplo n.º 1
0
/**
 * Convert IP address to integer (get only 32bits of IPv6 address)
 *
 * @param string IP address
 * @return integer Number
 */
function ip2int($ip)
{
    if (!is_valid_ip_format($ip)) {
        // IP format is incorrect
        return 0;
    }
    if ($ip == '::1') {
        // Reserved IP for localhost
        $ip = '127.0.0.1';
    }
    $parts = unpack('N*', inet_pton($ip));
    // In case of IPv6 return only a parts of it
    $result = strpos($ip, '.') !== false ? $parts[1] : $parts[4];
    if ($result < 0) {
        // convert unsigned int to signed from unpack.
        // this should be OK as it will be a PHP float not an int
        $result += 4294967296;
    }
    return $result;
}
Ejemplo n.º 2
0
             break;
         default:
             $AdminUI->disp_view('antispam/views/_antispam_tools.view.php');
             break;
     }
     break;
 case 'ipranges':
     switch ($action) {
         case 'iprange_new':
             if (!isset($edited_IPRange)) {
                 // Define new IPRange object only when it was not defined before, e.g. in action 'iprange_create'
                 $edited_IPRange = new IPRange();
             }
             // Set IP Start and End from _GET request
             $ip = param('ip', 'string', '');
             if (!empty($ip) && is_valid_ip_format($ip) && ($ip = explode('.', $ip)) && count($ip) == 4) {
                 $edited_IPRange->set('IPv4start', ip2int(implode('.', array($ip[0], $ip[1], $ip[2], 0))));
                 $edited_IPRange->set('IPv4end', ip2int(implode('.', array($ip[0], $ip[1], $ip[2], 255))));
             }
             $AdminUI->disp_view('antispam/views/_antispam_ipranges.form.php');
             break;
         case 'iprange_edit':
             $AdminUI->disp_view('antispam/views/_antispam_ipranges.form.php');
             break;
         default:
             // View list of the IP Ranges
             $AdminUI->disp_view('antispam/views/_antispam_ipranges.view.php');
             break;
     }
     break;
 case 'countries':