Ejemplo n.º 1
0
 /**
  * shared functionality for all components
  * @param $dispatcher
  * @return bool
  * @throws \Exception
  */
 public function beforeExecuteRoute($dispatcher)
 {
     // only handle input validation on first request.
     if (!$dispatcher->wasForwarded()) {
         // Authentication
         // - use authentication of legacy OPNsense.
         if (!$this->doAuth()) {
             return false;
         }
         // check for valid csrf on post requests
         if ($this->request->isPost() && !$this->security->checkToken()) {
             // post without csrf, exit.
             return false;
         }
         // REST type calls should be implemented by inheriting ApiControllerBase.
         // because we don't check for csrf on these methods, we want to make sure these aren't used.
         if ($this->request->isHead() || $this->request->isPut() || $this->request->isDelete() || $this->request->isPatch() || $this->request->isOptions()) {
             throw new \Exception('request type not supported');
         }
     }
     // include csrf for volt view rendering.
     $this->view->setVars(['csrf_tokenKey' => $this->security->getTokenKey(), 'csrf_token' => $this->security->getToken()]);
     // set translator
     $this->view->setVar('lang', $this->getTranslator());
     // link menu system to view, append /ui in uri because of rewrite
     $menu = new Menu\MenuSystem();
     // add interfaces to "Interfaces" menu tab... kind of a hack, may need some improvement.
     $cnf = Config::getInstance();
     $ifarr = array();
     foreach ($cnf->object()->interfaces->children() as $key => $node) {
         $ifarr[$key] = $node;
     }
     ksort($ifarr);
     $ordid = 0;
     foreach ($ifarr as $key => $node) {
         $menu->appendItem('Interfaces', $key, array('url' => '/interfaces.php?if=' . $key, 'order' => $ordid++, 'visiblename' => $node->descr ? $node->descr : strtoupper($key)));
     }
     unset($ifarr);
     $this->view->menuSystem = $menu->getItems("/ui" . $this->router->getRewriteUri());
     // set theme in ui_theme template var, let template handle its defaults (if there is no theme).
     if ($cnf->object()->theme != null && !empty($cnf->object()->theme) && is_dir('/usr/local/opnsense/www/themes/' . (string) $cnf->object()->theme)) {
         $this->view->ui_theme = $cnf->object()->theme;
     }
     // append ACL object to view
     $this->view->acl = new \OPNsense\Core\ACL();
 }
Ejemplo n.º 2
0
 /**
  * request user context sensitive menu (items)
  * @param string $selected_uri selected uri
  * @return array menu items
  */
 private function getMenu($selected_uri)
 {
     // construct menu and acl and merge collected info
     $menu = new Menu\MenuSystem();
     $acl = new ACL();
     // get username into context
     if ($this->session->has("Username")) {
         $this->username = $this->session->get("Username");
     }
     // add interfaces to "Interfaces" menu tab... kind of a hack, may need some improvement.
     $cnf = Config::getInstance();
     $ifarr = array();
     foreach ($cnf->object()->interfaces->children() as $key => $node) {
         $ifarr[$key] = $node->descr ? $node->descr->__toString() : strtoupper($key);
     }
     natcasesort($ifarr);
     $ordid = 0;
     foreach ($ifarr as $key => $descr) {
         $menu->appendItem('Interfaces', $key, array('url' => '/interfaces.php?if=' . $key, 'visiblename' => '[' . $descr . ']', 'cssclass' => 'fa fa-sitemap', 'order' => $ordid++));
     }
     unset($ifarr);
     // fetch menu items and apply acl
     $menu_items = $menu->getItems($selected_uri);
     $this->applyACL($menu_items, $acl);
     return $menu_items;
 }