From a61f53209e0584f9d912bb262aed65eee761e4d0 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Tue, 6 Feb 2018 20:46:00 +0100 Subject: [PATCH] net/frr: merge version 1.0_2 from master --- net/frr/Makefile | 2 +- .../OPNsense/Quagga/Api/BgpController.php | 416 ++---------------- .../Quagga/Api/Ospf6settingsController.php | 143 +----- .../Quagga/Api/OspfsettingsController.php | 335 +------------- .../OPNsense/Quagga/Api/RipController.php | 45 +- 5 files changed, 80 insertions(+), 861 deletions(-) diff --git a/net/frr/Makefile b/net/frr/Makefile index 5197e2f72..071dcd680 100644 --- a/net/frr/Makefile +++ b/net/frr/Makefile @@ -1,6 +1,6 @@ PLUGIN_NAME= frr PLUGIN_VERSION= 1.0 -PLUGIN_REVISION= 1 +PLUGIN_REVISION= 2 PLUGIN_COMMENT= The FRRouting Protocol Suite PLUGIN_DEPENDS= frr ruby PLUGIN_CONFLICTS= quagga diff --git a/net/frr/src/opnsense/mvc/app/controllers/OPNsense/Quagga/Api/BgpController.php b/net/frr/src/opnsense/mvc/app/controllers/OPNsense/Quagga/Api/BgpController.php index d6289196f..878bf3a19 100644 --- a/net/frr/src/opnsense/mvc/app/controllers/OPNsense/Quagga/Api/BgpController.php +++ b/net/frr/src/opnsense/mvc/app/controllers/OPNsense/Quagga/Api/BgpController.php @@ -31,476 +31,150 @@ namespace OPNsense\Quagga\Api; -use \OPNsense\Quagga\BGP; -use \OPNsense\Core\Config; use \OPNsense\Base\ApiMutableModelControllerBase; -use \OPNsense\Base\UIModelGrid; class BgpController extends ApiMutableModelControllerBase { - static protected $internalModelName = 'BGP'; + static protected $internalModelName = 'bgp'; static protected $internalModelClass = '\OPNsense\Quagga\BGP'; - public function getAction() - { - // define list of configurable settings - $result = array(); - if ($this->request->isGet()) { - $mdlBGP = new BGP(); - $result['bgp'] = $mdlBGP->getNodes(); - } - return $result; - } - public function setAction() - { - $result = array("result"=>"failed"); - if ($this->request->isPost()) { - // load model and update with provided data - $mdlBGP = new BGP(); - $mdlBGP->setNodes($this->request->getPost("bgp")); - // perform validation - $valMsgs = $mdlBGP->performValidation(); - foreach ($valMsgs as $field => $msg) { - if (!array_key_exists("validations", $result)) { - $result["validations"] = array(); - } - $result["validations"]["bgp.".$msg->getField()] = $msg->getMessage(); - } - // serialize model to config and save - if ($valMsgs->count() == 0) { - $mdlBGP->serializeToConfig(); - Config::getInstance()->save(); - $result["result"] = "saved"; - } - } - return $result; - } public function searchNeighborAction() { $this->sessionClose(); - $mdlBGP = $this->getModel(); - $grid = new UIModelGrid($mdlBGP->neighbors->neighbor); - return $grid->fetchBindRequest( - $this->request, - array("enabled", "address", "remoteas", "updatesource", "nexthopself", "defaultoriginate", "linkedPrefixlistIn", "linkedPrefixlistOut", "linkedRoutemapIn", "linkedRoutemapOut" ) - ); + return $this->searchBase('neighbors.neighbor', + array("enabled", + "address", + "remoteas", + "updatesource", + "nexthopself", + "defaultoriginate", + "linkedPrefixlistIn", + "linkedPrefixlistOut", + "linkedRoutemapIn", + "linkedRoutemapOut")); } public function getNeighborAction($uuid = null) { - $mdlBGP = $this->getModel(); - if ($uuid != null) { - $node = $mdlBGP->getNodeByReference('neighbors.neighbor.' . $uuid); - if ($node != null) { - // return node - return array("neighbor" => $node->getNodes()); - } - } else { - $node = $mdlBGP->neighbors->neighbor->add(); - return array("neighbor" => $node->getNodes()); - } - return array(); + $this->sessionClose(); + return $this->getBase('neighbor', 'neighbors.neighbor', $uuid); } public function addNeighborAction() { - $result = array("result" => "failed"); - if ($this->request->isPost() && $this->request->hasPost("neighbor")) { - $result = array("result" => "failed", "validations" => array()); - $mdlBGP = $this->getModel(); - $node = $mdlBGP->neighbors->neighbor->Add(); - $node->setNodes($this->request->getPost("neighbor")); - $valMsgs = $mdlBGP->performValidation(); - foreach ($valMsgs as $field => $msg) { - $fieldnm = str_replace($node->__reference, "neighbor", $msg->getField()); - $result["validations"][$fieldnm] = $msg->getMessage(); - } - if (count($result['validations']) == 0) { - unset($result['validations']); - // save config if validated correctly - $mdlBGP->serializeToConfig(); - Config::getInstance()->save(); - unset($result['validations']); - $result["result"] = "saved"; - } - } - return $result; + return $this->addBase('neighbor', 'neighbors.neighbor'); } public function delNeighborAction($uuid) { - $result = array("result" => "failed"); - if ($this->request->isPost()) { - $mdlBGP = $this->getModel(); - if ($uuid != null) { - if ($mdlBGP->neighbors->neighbor->del($uuid)) { - $mdlBGP->serializeToConfig(); - Config::getInstance()->save(); - $result['result'] = 'deleted'; - } else { - $result['result'] = 'not found'; - } - } - } - return $result; + return $this->delBase('neighbors.neighbor', $uuid); } public function setNeighborAction($uuid) { - if ($this->request->isPost() && $this->request->hasPost("neighbor")) { - $mdlNeighbor = $this->getModel(); - if ($uuid != null) { - $node = $mdlNeighbor->getNodeByReference('neighbors.neighbor.' . $uuid); - if ($node != null) { - $result = array("result" => "failed", "validations" => array()); - $neighborInfo = $this->request->getPost("neighbor"); - $node->setNodes($neighborInfo); - $valMsgs = $mdlNeighbor->performValidation(); - foreach ($valMsgs as $field => $msg) { - $fieldnm = str_replace($node->__reference, "neighbor", $msg->getField()); - $result["validations"][$fieldnm] = $msg->getMessage(); - } - if (count($result['validations']) == 0) { - // save config if validated correctly - $mdlNeighbor->serializeToConfig(); - Config::getInstance()->save(); - $result = array("result" => "saved"); - } - return $result; - } - } - } - return array("result" => "failed"); + return $this->setBase('neighbor', 'neighbors.neighbor', $uuid); } public function searchAspathAction() { $this->sessionClose(); - $mdlBGP = $this->getModel(); - $grid = new UIModelGrid($mdlBGP->aspaths->aspath); - return $grid->fetchBindRequest( - $this->request, - array("enabled", "number", "action", "as" ) - ); + return $this->searchBase('aspaths.aspath', + array("enabled", "number", "action", "as" )); } public function getAspathAction($uuid = null) { - $mdlBGP = $this->getModel(); - if ($uuid != null) { - $node = $mdlBGP->getNodeByReference('aspaths.aspath.' . $uuid); - if ($node != null) { - // return node - return array("aspath" => $node->getNodes()); - } - } else { - $node = $mdlBGP->aspaths->aspath->add(); - return array("aspath" => $node->getNodes()); - } - return array(); + $this->sessionClose(); + return $this->getBase('aspath', 'aspaths.aspath', $uuid); } public function addAspathAction() { - $result = array("result" => "failed"); - if ($this->request->isPost() && $this->request->hasPost("aspath")) { - $result = array("result" => "failed", "validations" => array()); - $mdlBGP = $this->getModel(); - $node = $mdlBGP->aspaths->aspath->Add(); - $node->setNodes($this->request->getPost("aspath")); - $valMsgs = $mdlBGP->performValidation(); - foreach ($valMsgs as $field => $msg) { - $fieldnm = str_replace($node->__reference, "aspath", $msg->getField()); - $result["validations"][$fieldnm] = $msg->getMessage(); - } - if (count($result['validations']) == 0) { - // save config if validated correctly - $mdlBGP->serializeToConfig(); - Config::getInstance()->save(); - unset($result['validations']); - $result["result"] = "saved"; - } - } - return $result; + return $this->addBase('aspath', 'aspaths.aspath'); } public function delAspathAction($uuid) { - $result = array("result" => "failed"); - if ($this->request->isPost()) { - $mdlBGP = $this->getModel(); - if ($uuid != null) { - if ($mdlBGP->aspaths->aspath->del($uuid)) { - $mdlBGP->serializeToConfig(); - Config::getInstance()->save(); - $result['result'] = 'deleted'; - } else { - $result['result'] = 'not found'; - } - } - } - return $result; + return $this->delBase('aspaths.aspath', $uuid); } public function setAspathAction($uuid) { - if ($this->request->isPost() && $this->request->hasPost("aspath")) { - $mdlNeighbor = $this->getModel(); - if ($uuid != null) { - $node = $mdlNeighbor->getNodeByReference('aspaths.aspath.' . $uuid); - if ($node != null) { - $result = array("result" => "failed", "validations" => array()); - $aspathInfo = $this->request->getPost("aspath"); - $node->setNodes($aspathInfo); - $valMsgs = $mdlNeighbor->performValidation(); - foreach ($valMsgs as $field => $msg) { - $fieldnm = str_replace($node->__reference, "aspath", $msg->getField()); - $result["validations"][$fieldnm] = $msg->getMessage(); - } - if (count($result['validations']) == 0) { - // save config if validated correctly - $mdlNeighbor->serializeToConfig(); - Config::getInstance()->save(); - $result = array("result" => "saved"); - } - return $result; - } - } - } - return array("result" => "failed"); + return $this->setBase('aspath', 'aspaths.aspath', $uuid); } public function searchPrefixlistAction() { $this->sessionClose(); - $mdlBGP = $this->getModel(); - $grid = new UIModelGrid($mdlBGP->prefixlists->prefixlist); - return $grid->fetchBindRequest( - $this->request, - array("enabled", "name", "seqnumber", "action", "network" ) - ); + return $this->searchBase('prefixlists.prefixlist', + array("enabled", "name", "seqnumber", "action", "network" )); } public function getPrefixlistAction($uuid = null) { - $mdlBGP = $this->getModel(); - if ($uuid != null) { - $node = $mdlBGP->getNodeByReference('prefixlists.prefixlist.' . $uuid); - if ($node != null) { - // return node - return array("prefixlist" => $node->getNodes()); - } - } else { - $node = $mdlBGP->prefixlists->prefixlist->add(); - return array("prefixlist" => $node->getNodes()); - } - return array(); + $this->sessionClose(); + return $this->getBase('prefixlist', 'prefixlists.prefixlist', $uuid); } + public function addPrefixlistAction() { - $result = array("result" => "failed"); - if ($this->request->isPost() && $this->request->hasPost("prefixlist")) { - $result = array("result" => "failed", "validations" => array()); - $mdlBGP = $this->getModel(); - $node = $mdlBGP->prefixlists->prefixlist->Add(); - $node->setNodes($this->request->getPost("prefixlist")); - $valMsgs = $mdlBGP->performValidation(); - foreach ($valMsgs as $field => $msg) { - $fieldnm = str_replace($node->__reference, "prefixlist", $msg->getField()); - $result["validations"][$fieldnm] = $msg->getMessage(); - } - if (count($result['validations']) == 0) { - // save config if validated correctly - $mdlBGP->serializeToConfig(); - Config::getInstance()->save(); - unset($result['validations']); - $result["result"] = "saved"; - } - } - return $result; + return $this->addBase('prefixlist', 'prefixlists.prefixlist'); } + public function delPrefixlistAction($uuid) { - $result = array("result" => "failed"); - if ($this->request->isPost()) { - $mdlBGP = $this->getModel(); - if ($uuid != null) { - if ($mdlBGP->prefixlists->prefixlist->del($uuid)) { - $mdlBGP->serializeToConfig(); - Config::getInstance()->save(); - $result['result'] = 'deleted'; - } else { - $result['result'] = 'not found'; - } - } - } - return $result; + return $this->delBase('prefixlists.prefixlist', $uuid); } + public function setPrefixlistAction($uuid) { - if ($this->request->isPost() && $this->request->hasPost("prefixlist")) { - $mdlNeighbor = $this->getModel(); - if ($uuid != null) { - $node = $mdlNeighbor->getNodeByReference('prefixlists.prefixlist.' . $uuid); - if ($node != null) { - $result = array("result" => "failed", "validations" => array()); - $prefixlistInfo = $this->request->getPost("prefixlist"); - $node->setNodes($prefixlistInfo); - $valMsgs = $mdlNeighbor->performValidation(); - foreach ($valMsgs as $field => $msg) { - $fieldnm = str_replace($node->__reference, "prefixlist", $msg->getField()); - $result["validations"][$fieldnm] = $msg->getMessage(); - } - if (count($result['validations']) == 0) { - // save config if validated correctly - $mdlNeighbor->serializeToConfig(); - Config::getInstance()->save(); - $result = array("result" => "saved"); - } - return $result; - } - } - } - return array("result" => "failed"); + return $this->setBase('prefixlist', 'prefixlists.prefixlist', $uuid); } public function searchRoutemapAction() { $this->sessionClose(); - $mdlBGP = $this->getModel(); - $grid = new UIModelGrid($mdlBGP->routemaps->routemap); - return $grid->fetchBindRequest( - $this->request, - array("enabled", "name", "action", "id", "match", "set" ) - ); + return $this->searchBase('routemaps.routemap', + array("enabled", "name", "action", "id", "match", "set")); } public function getRoutemapAction($uuid = null) { - $mdlBGP = $this->getModel(); - if ($uuid != null) { - $node = $mdlBGP->getNodeByReference('routemaps.routemap.' . $uuid); - if ($node != null) { - // return node - return array("routemap" => $node->getNodes()); - } - } else { - $node = $mdlBGP->routemaps->routemap->add(); - return array("routemap" => $node->getNodes()); - } - return array(); + $this->sessionClose(); + return $this->getBase('routemap', 'routemaps.routemap', $uuid); } public function addRoutemapAction() { - $result = array("result" => "failed"); - if ($this->request->isPost() && $this->request->hasPost("routemap")) { - $result = array("result" => "failed", "validations" => array()); - $mdlBGP = $this->getModel(); - $node = $mdlBGP->routemaps->routemap->Add(); - $node->setNodes($this->request->getPost("routemap")); - $valMsgs = $mdlBGP->performValidation(); - foreach ($valMsgs as $field => $msg) { - $fieldnm = str_replace($node->__reference, "routemap", $msg->getField()); - $result["validations"][$fieldnm] = $msg->getMessage(); - } - if (count($result['validations']) == 0) { - // save config if validated correctly - $mdlBGP->serializeToConfig(); - Config::getInstance()->save(); - unset($result['validations']); - $result["result"] = "saved"; - } - } - return $result; + return $this->addBase('routemap', 'routemaps.routemap'); } public function delRoutemapAction($uuid) { - $result = array("result" => "failed"); - if ($this->request->isPost()) { - $mdlBGP = $this->getModel(); - if ($uuid != null) { - if ($mdlBGP->routemaps->routemap->del($uuid)) { - $mdlBGP->serializeToConfig(); - Config::getInstance()->save(); - $result['result'] = 'deleted'; - } else { - $result['result'] = 'not found'; - } - } - } - return $result; + return $this->delBase('routemaps.routemap', $uuid); } public function setRoutemapAction($uuid) { - if ($this->request->isPost() && $this->request->hasPost("routemap")) { - $mdlNeighbor = $this->getModel(); - if ($uuid != null) { - $node = $mdlNeighbor->getNodeByReference('routemaps.routemap.' . $uuid); - if ($node != null) { - $result = array("result" => "failed", "validations" => array()); - $routemapInfo = $this->request->getPost("routemap"); - $node->setNodes($routemapInfo); - $valMsgs = $mdlNeighbor->performValidation(); - foreach ($valMsgs as $field => $msg) { - $fieldnm = str_replace($node->__reference, "routemap", $msg->getField()); - $result["validations"][$fieldnm] = $msg->getMessage(); - } - if (count($result['validations']) == 0) { - // save config if validated correctly - $mdlNeighbor->serializeToConfig(); - Config::getInstance()->save(); - $result = array("result" => "saved"); - } - return $result; - } - } - } - return array("result" => "failed"); - } - - public function toggle_handler($uuid, $elements, $element) - { - $result = array("result" => "failed"); - if ($this->request->isPost()) { - $mdlNeighbor = $this->getModel(); - if ($uuid != null) { - $node = $mdlNeighbor->getNodeByReference($elements . '.'. $element .'.' . $uuid); - if ($node != null) { - if ($node->enabled->__toString() == "1") { - $result['result'] = "Disabled"; - $node->enabled = "0"; - } else { - $result['result'] = "Enabled"; - $node->enabled = "1"; - } - // if item has toggled, serialize to config and save - $mdlNeighbor->serializeToConfig(); - Config::getInstance()->save(); - } - } - } - return $result; + return $this->setBase('routemap', 'routemaps.routemap', $uuid); } public function toggleNeighborAction($uuid) { - return $this->toggle_handler($uuid, 'neighbors', 'neighbor'); + return $this->toggleBase('neighbors.neighbor', $uuid); } public function toggleAspathAction($uuid) { - return $this->toggle_handler($uuid, 'aspaths', 'aspath'); + return $this->toggleBase('aspaths.aspath', $uuid); } public function togglePrefixlistAction($uuid) { - return $this->toggle_handler($uuid, 'prefixlists', 'prefixlist'); + return $this->toggleBase('prefixlists.prefixlist', $uuid); } public function toggleRoutemapAction($uuid) { - return $this->toggle_handler($uuid, 'routemaps', 'routemap'); + return $this->toggleBase('routemaps.routemap', $uuid); } } diff --git a/net/frr/src/opnsense/mvc/app/controllers/OPNsense/Quagga/Api/Ospf6settingsController.php b/net/frr/src/opnsense/mvc/app/controllers/OPNsense/Quagga/Api/Ospf6settingsController.php index 5f6a3ea97..90db5b629 100644 --- a/net/frr/src/opnsense/mvc/app/controllers/OPNsense/Quagga/Api/Ospf6settingsController.php +++ b/net/frr/src/opnsense/mvc/app/controllers/OPNsense/Quagga/Api/Ospf6settingsController.php @@ -38,159 +38,32 @@ use \OPNsense\Base\UIModelGrid; class Ospf6settingsController extends ApiMutableModelControllerBase { - static protected $internalModelName = 'OSPF6'; + static protected $internalModelName = 'ospf6'; static protected $internalModelClass = '\OPNsense\Quagga\OSPF6'; - public function getAction() - { - $result = array(); - if ($this->request->isGet()) { - $mdlospf6 = new OSPF6(); - $result['ospf6'] = $mdlospf6->getNodes(); - } - return $result; - } - public function setAction() - { - $result = array("result"=>"failed"); - if ($this->request->isPost()) { - // load model and update with provided data - $mdlospf6 = new OSPF6(); - $mdlospf6->setNodes($this->request->getPost("ospf6")); - // perform validation - $valMsgs = $mdlospf6->performValidation(); - foreach ($valMsgs as $field => $msg) { - if (!array_key_exists("validations", $result)) { - $result["validations"] = array(); - } - $result["validations"]["general.".$msg->getField()] = $msg->getMessage(); - } - // serialize model to config and save - if ($valMsgs->count() == 0) { - $mdlospf6->serializeToConfig(); - Config::getInstance()->save(); - $result["result"] = "saved"; - } - } - return $result; - } -///////////////////////////////////////////////////////////////////// public function searchInterfaceAction() { $this->sessionClose(); - $mdlOSPF6 = $this->getModel(); - $grid = new UIModelGrid($mdlOSPF6->interfaces->interface); - return $grid->fetchBindRequest( - $this->request, - array("enabled", "interfacename", "area", "networktype") - ); + return $this->searchBase('interfaces.interface', array("enabled", "interfacename", "area", "networktype")); } public function getInterfaceAction($uuid = null) { - $mdlOSPF6 = $this->getModel(); - if ($uuid != null) { - $node = $mdlOSPF6->getNodeByReference('interfaces.interface.' . $uuid); - if ($node != null) { - // return node - return array("interface" => $node->getNodes()); - } - } else { - $node = $mdlOSPF6->interfaces->interface->add(); - return array("interface" => $node->getNodes()); - } - return array(); + $this->sessionClose(); + return $this->getBase('interface', 'interfaces.interface', $uuid); } public function addInterfaceAction() { - $result = array("result" => "failed"); - if ($this->request->isPost() && $this->request->hasPost("interface")) { - $result = array("result" => "failed", "validations" => array()); - $mdlOSPF6 = $this->getModel(); - $node = $mdlOSPF6->interfaces->interface->Add(); - $node->setNodes($this->request->getPost("interface")); - $valMsgs = $mdlOSPF6->performValidation(); - foreach ($valMsgs as $field => $msg) { - $fieldnm = str_replace($node->__reference, "interface", $msg->getField()); - $result["validations"][$fieldnm] = $msg->getMessage(); - } - if (count($result['validations']) == 0) { - // save config if validated correctly - $mdlOSPF6->serializeToConfig(); - Config::getInstance()->save(); - unset($result['validations']); - $result["result"] = "saved"; - } - } - return $result; + return $this->addBase('interface', 'interfaces.interface'); } public function delInterfaceAction($uuid) { - $result = array("result" => "failed"); - if ($this->request->isPost()) { - $mdlOSPF6 = $this->getModel(); - if ($uuid != null) { - if ($mdlOSPF6->interfaces->interface->del($uuid)) { - $mdlOSPF6->serializeToConfig(); - Config::getInstance()->save(); - $result['result'] = 'deleted'; - } else { - $result['result'] = 'not found'; - } - } - } - return $result; + return $this->delBase('interfaces.interface', $uuid); } public function setInterfaceAction($uuid) { - if ($this->request->isPost() && $this->request->hasPost("interface")) { - $mdlNetwork = $this->getModel(); - if ($uuid != null) { - $node = $mdlNetwork->getNodeByReference('interfaces.interface.' . $uuid); - if ($node != null) { - $result = array("result" => "failed", "validations" => array()); - $interfaceInfo = $this->request->getPost("interface"); - $node->setNodes($interfaceInfo); - $valMsgs = $mdlNetwork->performValidation(); - foreach ($valMsgs as $field => $msg) { - $fieldnm = str_replace($node->__reference, "interface", $msg->getField()); - $result["validations"][$fieldnm] = $msg->getMessage(); - } - if (count($result['validations']) == 0) { - // save config if validated correctly - $mdlNetwork->serializeToConfig(); - Config::getInstance()->save(); - $result = array("result" => "saved"); - } - return $result; - } - } - } - return array("result" => "failed"); - } - public function toggle_handler($uuid, $elements, $element) - { - $result = array("result" => "failed"); - if ($this->request->isPost()) { - $mdlNetwork = $this->getModel(); - if ($uuid != null) { - $node = $mdlNetwork->getNodeByReference($elements . '.'. $element .'.' . $uuid); - if ($node != null) { - if ($node->enabled->__toString() == "1") { - $result['result'] = "Disabled"; - $node->enabled = "0"; - } else { - $result['result'] = "Enabled"; - $node->enabled = "1"; - } - // if item has toggled, serialize to config and save - $mdlNetwork->serializeToConfig(); - Config::getInstance()->save(); - } - } - } - return $result; + return $this->setBase('interface', 'interfaces.interface', $uuid); } public function toggleInterfaceAction($uuid) { - return $this->toggle_handler($uuid, 'interfaces', 'interface'); + return $this->toggleBase('interfaces.interface', $uuid); } } diff --git a/net/frr/src/opnsense/mvc/app/controllers/OPNsense/Quagga/Api/OspfsettingsController.php b/net/frr/src/opnsense/mvc/app/controllers/OPNsense/Quagga/Api/OspfsettingsController.php index 6c55bed5c..2909104cb 100644 --- a/net/frr/src/opnsense/mvc/app/controllers/OPNsense/Quagga/Api/OspfsettingsController.php +++ b/net/frr/src/opnsense/mvc/app/controllers/OPNsense/Quagga/Api/OspfsettingsController.php @@ -1,8 +1,6 @@ request->isGet()) { - $mdlospf = new OSPF(); - $result['ospf'] = $mdlospf->getNodes(); - } - return $result; - } - public function setAction() - { - $result = array("result"=>"failed"); - if ($this->request->isPost()) { - // load model and update with provided data - $mdlospf = new OSPF(); - $mdlospf->setNodes($this->request->getPost("ospf")); - - // perform validation - $valMsgs = $mdlospf->performValidation(); - foreach ($valMsgs as $field => $msg) { - if (!array_key_exists("validations", $result)) { - $result["validations"] = array(); - } - $result["validations"]["general.".$msg->getField()] = $msg->getMessage(); - } - - // serialize model to config and save - if ($valMsgs->count() == 0) { - $mdlospf->serializeToConfig(); - Config::getInstance()->save(); - $result["result"] = "saved"; - } - } - return $result; - } - - -///////////////////////////////////////////////////////////////////// public function searchNetworkAction() { $this->sessionClose(); - $mdlOSPF = $this->getModel(); - $grid = new UIModelGrid($mdlOSPF->networks->network); - return $grid->fetchBindRequest( - $this->request, - array("enabled", "ipaddr", "netmask", "area") - ); + return $this->searchBase('networks.network', array("enabled", "ipaddr", "netmask", "area")); } public function searchInterfaceAction() { $this->sessionClose(); - $mdlOSPF = $this->getModel(); - $grid = new UIModelGrid($mdlOSPF->interfaces->interface); - return $grid->fetchBindRequest( - $this->request, - array("enabled", "interfacename", "networktype", "authtype", "area") - ); + return $this->searchBase('interfaces.interface', array("enabled", "interfacename", "networktype", "authtype", "area")); } public function searchPrefixlistAction() { $this->sessionClose(); - $mdlOSPF = $this->getModel(); - $grid = new UIModelGrid($mdlOSPF->prefixlists->prefixlist); - return $grid->fetchBindRequest( - $this->request, - array("enabled", "name", "seqnumber", "action", "network" ) - ); + return $this->searchBase('prefixlists.prefixlist', array("enabled", "name", "seqnumber", "action", "network" )); } public function getNetworkAction($uuid = null) { - $mdlOSPF = $this->getModel(); - if ($uuid != null) { - $node = $mdlOSPF->getNodeByReference('networks.network.' . $uuid); - if ($node != null) { - // return node - return array("network" => $node->getNodes()); - } - } else { - $node = $mdlOSPF->networks->network->add(); - return array("network" => $node->getNodes()); - } - return array(); + $this->sessionClose(); + return $this->getBase('network', 'networks.network', $uuid); } public function getInterfaceAction($uuid = null) { - $mdlOSPF = $this->getModel(); - if ($uuid != null) { - $node = $mdlOSPF->getNodeByReference('interfaces.interface.' . $uuid); - if ($node != null) { - // return node - return array("interface" => $node->getNodes()); - } - } else { - $node = $mdlOSPF->interfaces->interface->add(); - return array("interface" => $node->getNodes()); - } - return array(); + $this->sessionClose(); + return $this->getBase('interface', 'interfaces.interface', $uuid); } public function getPrefixlistAction($uuid = null) { - $mdlOSPF = $this->getModel(); - if ($uuid != null) { - $node = $mdlOSPF->getNodeByReference('prefixlists.prefixlist.' . $uuid); - if ($node != null) { - // return node - return array("prefixlist" => $node->getNodes()); - } - } else { - $node = $mdlOSPF->prefixlists->prefixlist->add(); - return array("prefixlist" => $node->getNodes()); - } - return array(); + $this->sessionClose(); + return $this->getBase('prefixlist', 'prefixlists.prefixlist', $uuid); } public function addNetworkAction() { - $result = array("result" => "failed"); - if ($this->request->isPost() && $this->request->hasPost("network")) { - $result = array("result" => "failed", "validations" => array()); - $mdlOSPF = $this->getModel(); - $node = $mdlOSPF->networks->network->Add(); - $node->setNodes($this->request->getPost("network")); - $valMsgs = $mdlOSPF->performValidation(); - - foreach ($valMsgs as $field => $msg) { - $fieldnm = str_replace($node->__reference, "network", $msg->getField()); - $result["validations"][$fieldnm] = $msg->getMessage(); - } - - if (count($result['validations']) == 0) { - // save config if validated correctly - $mdlOSPF->serializeToConfig(); - Config::getInstance()->save(); - unset($result['validations']); - $result["result"] = "saved"; - } - } - return $result; + return $this->addBase('network', 'networks.network'); } public function addInterfaceAction() { - $result = array("result" => "failed"); - if ($this->request->isPost() && $this->request->hasPost("interface")) { - $result = array("result" => "failed", "validations" => array()); - $mdlOSPF = $this->getModel(); - $node = $mdlOSPF->interfaces->interface->Add(); - $node->setNodes($this->request->getPost("interface")); - $valMsgs = $mdlOSPF->performValidation(); - - foreach ($valMsgs as $field => $msg) { - $fieldnm = str_replace($node->__reference, "interface", $msg->getField()); - $result["validations"][$fieldnm] = $msg->getMessage(); - } - - if (count($result['validations']) == 0) { - // save config if validated correctly - $mdlOSPF->serializeToConfig(); - Config::getInstance()->save(); - unset($result['validations']); - $result["result"] = "saved"; - } - } - return $result; + return $this->addBase('interface', 'interfaces.interface'); } public function addPrefixlistAction() { - $result = array("result" => "failed"); - if ($this->request->isPost() && $this->request->hasPost("prefixlist")) { - $result = array("result" => "failed", "validations" => array()); - $mdlOSPF = $this->getModel(); - $node = $mdlOSPF->prefixlists->prefixlist->Add(); - $node->setNodes($this->request->getPost("prefixlist")); - $valMsgs = $mdlOSPF->performValidation(); - foreach ($valMsgs as $field => $msg) { - $fieldnm = str_replace($node->__reference, "prefixlist", $msg->getField()); - $result["validations"][$fieldnm] = $msg->getMessage(); - } - if (count($result['validations']) == 0) { - // save config if validated correctly - $mdlOSPF->serializeToConfig(); - Config::getInstance()->save(); - unset($result['validations']); - $result["result"] = "saved"; - } - } - return $result; + return $this->addBase('prefixlist', 'prefixlists.prefixlist'); } public function delNetworkAction($uuid) { - - $result = array("result" => "failed"); - - if ($this->request->isPost()) { - $mdlOSPF = $this->getModel(); - if ($uuid != null) { - if ($mdlOSPF->networks->network->del($uuid)) { - $mdlOSPF->serializeToConfig(); - Config::getInstance()->save(); - $result['result'] = 'deleted'; - } else { - $result['result'] = 'not found'; - } - } - } - return $result; + return $this->delBase('networks.network', $uuid); } public function delInterfaceAction($uuid) { - - $result = array("result" => "failed"); - - if ($this->request->isPost()) { - $mdlOSPF = $this->getModel(); - if ($uuid != null) { - if ($mdlOSPF->interfaces->interface->del($uuid)) { - $mdlOSPF->serializeToConfig(); - Config::getInstance()->save(); - $result['result'] = 'deleted'; - } else { - $result['result'] = 'not found'; - } - } - } - return $result; + return $this->delBase('interfaces.interface', $uuid); } public function delPrefixlistAction($uuid) { - $result = array("result" => "failed"); - if ($this->request->isPost()) { - $mdlOSPF = $this->getModel(); - if ($uuid != null) { - if ($mdlOSPF->prefixlists->prefixlist->del($uuid)) { - $mdlOSPF->serializeToConfig(); - Config::getInstance()->save(); - $result['result'] = 'deleted'; - } else { - $result['result'] = 'not found'; - } - } - } - return $result; + return $this->delBase('prefixlists.prefixlist', $uuid); } public function setNetworkAction($uuid) { - if ($this->request->isPost() && $this->request->hasPost("network")) { - $mdlNetwork = $this->getModel(); - if ($uuid != null) { - $node = $mdlNetwork->getNodeByReference('networks.network.' . $uuid); - if ($node != null) { - $result = array("result" => "failed", "validations" => array()); - $networkInfo = $this->request->getPost("network"); - - $node->setNodes($networkInfo); - $valMsgs = $mdlNetwork->performValidation(); - foreach ($valMsgs as $field => $msg) { - $fieldnm = str_replace($node->__reference, "network", $msg->getField()); - $result["validations"][$fieldnm] = $msg->getMessage(); - } - - if (count($result['validations']) == 0) { - // save config if validated correctly - $mdlNetwork->serializeToConfig(); - Config::getInstance()->save(); - $result = array("result" => "saved"); - } - return $result; - } - } - } - return array("result" => "failed"); + return $this->setBase('network', 'networks.network', $uuid); } public function setInterfaceAction($uuid) { - if ($this->request->isPost() && $this->request->hasPost("interface")) { - $mdlNetwork = $this->getModel(); - if ($uuid != null) { - $node = $mdlNetwork->getNodeByReference('interfaces.interface.' . $uuid); - if ($node != null) { - $result = array("result" => "failed", "validations" => array()); - $interfaceInfo = $this->request->getPost("interface"); - - $node->setNodes($interfaceInfo); - $valMsgs = $mdlNetwork->performValidation(); - foreach ($valMsgs as $field => $msg) { - $fieldnm = str_replace($node->__reference, "interface", $msg->getField()); - $result["validations"][$fieldnm] = $msg->getMessage(); - } - - if (count($result['validations']) == 0) { - // save config if validated correctly - $mdlNetwork->serializeToConfig(); - Config::getInstance()->save(); - $result = array("result" => "saved"); - } - return $result; - } - } - } - return array("result" => "failed"); + return $this->setBase('interface', 'interfaces.interface', $uuid); } public function setPrefixlistAction($uuid) { - if ($this->request->isPost() && $this->request->hasPost("prefixlist")) { - $mdlNeighbor = $this->getModel(); - if ($uuid != null) { - $node = $mdlNeighbor->getNodeByReference('prefixlists.prefixlist.' . $uuid); - if ($node != null) { - $result = array("result" => "failed", "validations" => array()); - $prefixlistInfo = $this->request->getPost("prefixlist"); - $node->setNodes($prefixlistInfo); - $valMsgs = $mdlNeighbor->performValidation(); - foreach ($valMsgs as $field => $msg) { - $fieldnm = str_replace($node->__reference, "prefixlist", $msg->getField()); - $result["validations"][$fieldnm] = $msg->getMessage(); - } - if (count($result['validations']) == 0) { - // save config if validated correctly - $mdlNeighbor->serializeToConfig(); - Config::getInstance()->save(); - $result = array("result" => "saved"); - } - return $result; - } - } - } - return array("result" => "failed"); + return $this->setBase('prefixlist', 'prefixlists.prefixlist', $uuid); } - public function toggle_handler($uuid, $elements, $element) - { - - $result = array("result" => "failed"); - - if ($this->request->isPost()) { - $mdlNetwork = $this->getModel(); - if ($uuid != null) { - $node = $mdlNetwork->getNodeByReference($elements . '.'. $element .'.' . $uuid); - if ($node != null) { - if ($node->enabled->__toString() == "1") { - $result['result'] = "Disabled"; - $node->enabled = "0"; - } else { - $result['result'] = "Enabled"; - $node->enabled = "1"; - } - // if item has toggled, serialize to config and save - $mdlNetwork->serializeToConfig(); - Config::getInstance()->save(); - } - } - } - return $result; - } - public function toggleNetworkAction($uuid) { - return $this->toggle_handler($uuid, 'networks', 'network'); + return $this->toggleBase('networks.network', $uuid); } public function toggleInterfaceAction($uuid) { - return $this->toggle_handler($uuid, 'interfaces', 'interface'); + return $this->toggleBase('interfaces.interface', $uuid); } public function togglePrefixlistAction($uuid) { - return $this->toggle_handler($uuid, 'prefixlists', 'prefixlist'); + return $this->toggleBase('prefixlists.prefixlist', $uuid); } } diff --git a/net/frr/src/opnsense/mvc/app/controllers/OPNsense/Quagga/Api/RipController.php b/net/frr/src/opnsense/mvc/app/controllers/OPNsense/Quagga/Api/RipController.php index 39de9150d..6cdce68be 100644 --- a/net/frr/src/opnsense/mvc/app/controllers/OPNsense/Quagga/Api/RipController.php +++ b/net/frr/src/opnsense/mvc/app/controllers/OPNsense/Quagga/Api/RipController.php @@ -1,6 +1,5 @@ request->isGet()) { - $mdlRIP = new RIP(); - $result['rip'] = $mdlRIP->getNodes(); - } - return $result; - } - public function setAction() - { - $result = array("result"=>"failed"); - if ($this->request->isPost()) { - // load model and update with provided data - $mdlRIP = new RIP(); - $mdlRIP->setNodes($this->request->getPost("rip")); - - // perform validation - $valMsgs = $mdlRIP->performValidation(); - foreach ($valMsgs as $field => $msg) { - if (!array_key_exists("validations", $result)) { - $result["validations"] = array(); - } - $result["validations"]["rip.".$msg->getField()] = $msg->getMessage(); - } - - // serialize model to config and save - if ($valMsgs->count() == 0) { - $mdlRIP->serializeToConfig(); - Config::getInstance()->save(); - $result["result"] = "saved"; - } - } - return $result; - } + static protected $internalModelName = 'rip'; + static protected $internalModelClass = '\OPNsense\Quagga\RIP'; }