Esempio n. 1
0
 function preFilter()
 {
     parent::preFilter();
     if (!$this->isAdmin) {
         $this->session->set('error', _('You need to be an admin to manage maps.'));
         $this->request->redirectArgList('/');
     }
 }
Esempio n. 2
0
 function preFilter()
 {
     parent::preFilter();
     $host = $this->request->get('host');
     $port = $this->request->get('port');
     $service = new \DedicatedManager\Services\ServerService();
     try {
         $this->server = $service->get($host, $port);
         $this->server->fetchDetails();
     } catch (\Exception $e) {
         $this->session->set('error', _('The server is unreachable, maybe it is closed'));
         $this->request->redirectArgList('/');
     }
     if (!$this->isAdmin) {
         $service = new \DedicatedManager\Services\ManagerService();
         if (!$service->isAllowed($host, $port, $this->session->login)) {
             $this->session->set('error', _('You\'re not allowed to edit this server.'));
             $this->request->redirectArgList('/');
         }
     }
     $rm = new \ReflectionMethod($this, $this->request->getAction('index'));
     $comment = $rm->getDocComment();
     if ($this->server->isRelay && $comment && preg_match('/@norelay/u', $comment)) {
         $this->session->set('error', _('Unauthorized action on a relay.'));
         if ($this->request->getReferer() == $this->request->createLink()) {
             $this->request->redirectArgList('..');
         } else {
             $this->request->redirectToReferer();
         }
     }
     $mapDirectory = \DedicatedManager\Config::getInstance()->dedicatedPath . 'UserData/Maps/';
     if (!in_array($this->server->rpcHost, array('127.0.0.1', 'localhost')) && $this->server->connection->getMapsDirectory() != $mapDirectory) {
         if (preg_match('/@local/u', $comment)) {
             $this->session->set('error', _('Unauthorized action on a distant server.'));
             if ($this->request->getReferer() == $this->request->createLink()) {
                 $this->request->redirectArgList('..');
             } else {
                 $this->request->redirectToReferer();
             }
         }
         $this->response->isLocal = false;
     } else {
         $this->response->isLocal = true;
     }
     if (!$comment || !preg_match('/@redirect/u', $comment)) {
         $this->request->registerReferer();
         $this->players = $this->server->connection->getPlayerList(-1, 0);
         $this->options = $this->server->connection->getServerOptions();
         $this->currentMap = $this->server->connection->getCurrentMapInfo();
         if (!$this->server->isRelay) {
             $this->nextMap = $this->server->connection->getNextMapInfo();
         }
     }
 }