Ejemplo n.º 1
0
 public static function check_restriction_for_ip_address($ip_address = NULL)
 {
     $ci =& get_instance();
     $ci->load->helper('ip_address');
     $ip_to_check = $ip_address;
     if (is_null($ip_address)) {
         $ip_to_check = getenv('REMOTE_ADDR');
     }
     if (check_valid_ip_address($ip_to_check)) {
         $time = date('Y-m-d H:i:s');
         $restriction = new Restriction();
         $restriction->where('start_time <=', $time);
         $restriction->where('end_time >=', $time);
         $restriction->get_iterated();
         foreach ($restriction as $restriction_record) {
             $ip_addresses = explode(',', $restriction_record->ip_addresses);
             if (count($ip_addresses)) {
                 foreach ($ip_addresses as $matching_pattern) {
                     if (trim($matching_pattern) !== '' && match_ip_address_agains(trim($matching_pattern), $ip_to_check)) {
                         return TRUE;
                     }
                 }
             }
         }
     }
     return FALSE;
 }
Ejemplo n.º 2
0
 public function _ip_addresses_validation($string)
 {
     $this->load->helper('ip_address');
     if (preg_match('/^[0-9\\*\\.\\ ]+$/', $string)) {
         $parts = explode(',', $string);
         foreach ($parts as $part) {
             $part = trim($part);
             if (!check_valid_ip_address($part) && !check_valid_ip_range($part) && !check_valid_ip_wildcard($part)) {
                 return FALSE;
             }
         }
         return TRUE;
     }
     return FALSE;
 }
Ejemplo n.º 3
0
function list_ip_2_number($ip_address)
{
    if (check_valid_ip_address($ip_address)) {
        $number = 0;
        $parts = explode('.', $ip_address);
        for ($i = 3; $i >= 0; $i--) {
            $number += $parts[$i] * pow(255, 3 - $i);
        }
        return $number;
    }
    return -1;
}