public function onEvent(GenericEvent $event, $eventName)
 {
     if (stripos($this->request->getRequestUri(), '.asp') !== false) {
         $ua = $this->request->getUserAgent();
         if ($this->enforceHttps && $ua !== null && stripos($ua, 'Baiduspider') === false && stripos($ua, 'Sogou web spider') === false && stripos($ua, 'Sosospider') === false) {
             $prefix = 'https://';
         } else {
             $prefix = 'http://';
         }
         $uri = $this->request->getRequestUri();
         $host = $this->canonical;
         if (stripos($uri, '/problem_show.asp') !== false) {
             $location = $prefix . $host . '/problem/' . $this->request->query->get('id');
         } elseif (stripos($uri, '/user_show.asp') !== false) {
             $location = $prefix . $host . '/user/' . $this->request->query->get('id');
         } elseif (stripos($uri, '/problem_discuss.asp') !== false) {
             $location = $prefix . $host . '/problem/' . $this->request->query->get('id');
         } elseif (stripos($uri, '/problem_discuss_show.asp') !== false) {
             $location = $prefix . $host . '/problem/' . $this->request->query->get('id');
         } elseif (stripos($uri, '/problem2.asp') !== false) {
             $location = $prefix . $host . '/problem';
         } else {
             $location = $prefix . $host;
         }
         $this->response->redirect($location, true);
         $event->stopPropagation();
         //TODO: redirect VJ2 style URIs
     }
 }
 public function onEvent(GenericEvent $event, $eventName)
 {
     if (!$this->enforceHttps) {
         return;
     }
     $nossl = $this->request->get('nossl');
     if ($nossl !== null) {
         $nossl = strtolower($nossl);
         if ($nossl === 'false' || $nossl === 'off') {
             $this->response->headers->clearCookie('nossl');
             $this->request->cookies->remove('nossl');
         } else {
             $this->response->headers->setCookie(new Cookie('nossl', 'on'));
             $this->request->cookies->set('nossl', 'on');
         }
     }
     if (!$this->request->isSecure() && $this->request->cookies->get('nossl') === null) {
         $ua = $this->request->getUserAgent();
         //Unsafe search engine friendly
         if ($ua !== null && stripos($ua, 'Baiduspider') === false && stripos($ua, 'Sogou web spider') === false && stripos($ua, 'Sosospider') === false) {
             $this->response->redirect('https://' . $this->request->headers->get('host', $this->canonical) . $this->request->getRequestUri());
             $event->stopPropagation();
         }
     }
 }
 public function onEvent(GenericEvent $event, $eventName)
 {
     $identifier = $this->ir->getMixedIdentifier();
     $denyExpire = $this->redis->get('SECURITY:DENY:' . $identifier);
     if ($denyExpire === false) {
         // not listed in blacklist
         return;
     }
     $this->response->setStatusCode(Response::HTTP_FORBIDDEN);
     $this->response->headers->set('content-type', 'text/html');
     $this->response->setContent(Application::trans('error.code.ip_blacklisted', ['seconds' => $denyExpire === 0 ? mt_rand() : ceil(($denyExpire - time()) / 60) * 60]));
     $this->response->send();
     $event->stopPropagation();
 }