Exemplo n.º 1
0
 /**
  * beforeDispatch function
  * @param \Cake\Event\Event $event event
  * @return /Cake/Network/Response|null
  */
 public function beforeDispatch(Event $event)
 {
     parent::beforeDispatch($event);
     $maintenance = Setting::read('Maintenance');
     // Allow ip in the list only.
     // Allow all if empty restrict ip
     if (!$maintenance['enable'] || empty($maintenance['allowedIp'])) {
         return null;
     }
     $userIP = $this->_getUserIpAddr();
     $ips = explode(',', trim($maintenance['allowedIp']));
     foreach ($ips as $ip) {
         if ($this->_compareIp($userIP, trim($ip))) {
             return null;
         }
     }
     $view = $this->_getView();
     $body = $view->render('Public/maintenance', 'error');
     $response = $event->data['response'];
     $response->statusCode(503);
     $response->body($body);
     $event->stopPropagation();
     return $response;
 }