From 3537bcc5039254aca19cf7ae57fd22251d84e6ca Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Thu, 19 Feb 2015 15:07:48 +0100 Subject: [PATCH] add Interfaces to menu system, in the current setup this is the only dynamic item. May need an easier hook in the future, but or now this works fine --- .../OPNsense/Base/ControllerBase.php | 22 ++++++++++++++----- .../app/models/OPNsense/Base/Menu/Menu.xml | 3 +-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Base/ControllerBase.php b/src/opnsense/mvc/app/controllers/OPNsense/Base/ControllerBase.php index 5967f083d..bca7543ec 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/Base/ControllerBase.php +++ b/src/opnsense/mvc/app/controllers/OPNsense/Base/ControllerBase.php @@ -28,8 +28,8 @@ */ namespace OPNsense\Base; +use OPNsense\Core\Config; use Phalcon\Mvc\Controller; - use Phalcon\Translate\Adapter\NativeArray; /** @@ -67,15 +67,19 @@ class ControllerBase extends Controller */ public function beforeExecuteRoute($dispatcher) { - // Authentication / validation + // Authentication // - use authentication of legacy OPNsense. - // - check for valid csrf and include csrf for GET requests. if ($this->session->has("Username") == false) { $this->response->redirect("/", true); - } elseif ($this->request->isPost() && !$this->security->checkToken()) { + } + // check for valid csrf + if ($this->request->isPost() && !$this->security->checkToken()) { // post without csrf, exit. return false; - } elseif ($this->request->isGet()) { + } + + // include csrf for GET requests. + if ($this->request->isGet()) { // inject csrf information $this->view->setVars([ 'csrf_tokenKey' => $this->security->getTokenKey(), @@ -88,6 +92,14 @@ class ControllerBase extends Controller // 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(); + $ordid = 0; + foreach ($cnf->object()->interfaces->children() as $key => $node) { + $menu->appendItem("Interfaces", $key, array("url"=>"/interfaces.php?if=".$key,"order"=>($ordid++), "visiblename"=>$node->descr)); + } + $this->view->menuSystem = $menu->getItems("/ui".$this->router->getRewriteUri()); // append ACL object to view diff --git a/src/opnsense/mvc/app/models/OPNsense/Base/Menu/Menu.xml b/src/opnsense/mvc/app/models/OPNsense/Base/Menu/Menu.xml index 631249e42..3f213acb2 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Base/Menu/Menu.xml +++ b/src/opnsense/mvc/app/models/OPNsense/Base/Menu/Menu.xml @@ -11,7 +11,6 @@ - - + \ No newline at end of file