Exemplo 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;
 }
Exemplo n.º 2
0
 public function clear_old()
 {
     $output = new stdClass();
     $output->status = FALSE;
     $output->message = '';
     $count = 0;
     $this->_transaction_isolation();
     $this->db->trans_begin();
     $time = date('Y-m-d H:i:s');
     $restrictions = new Restriction();
     $restrictions->where('end_time <', $time);
     $restrictions->where('start_time <', $time);
     $restrictions->get_iterated();
     foreach ($restrictions as $restriction) {
         if ($restriction->delete()) {
             $count++;
         }
     }
     if ($count > 0) {
         $this->db->trans_commit();
         $output->status = TRUE;
         $output->message = sprintf($this->lang->line('admin_restrictions_message_old_deleted'), $count);
     } else {
         $this->db->trans_rollback();
         $output->message = $this->lang->line('admin_restrictions_message_nothing_old_deleted');
     }
     $this->output->set_content_type('application/json');
     $this->output->set_output(json_encode($output));
 }