-
Notifications
You must be signed in to change notification settings - Fork 803
FreeRADIUS plugin #190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
FreeRADIUS plugin #190
Changes from all commits
Commits
Show all changes
223 commits
Select commit
Hold shift + click to select a range
fdf46d3
Create freeradius3.inc
mimugmail bfd5b0f
Create Makefile
mimugmail 9deb431
Create pkg-descr
mimugmail dd12ac6
Create GeneralController.php
mimugmail 442b73b
Create general.xml
mimugmail dc99043
Create ACL.xml
mimugmail 05ecfe6
Create general.volt
mimugmail 71dd525
Create setup.sh
mimugmail 6c08d95
Create actions_freeradius3.conf
mimugmail 5d6b464
Create +TARGETS
mimugmail b7b6b55
Create radiusd
mimugmail 258615c
Update +TARGETS
mimugmail c6caf01
Create users
mimugmail 3974f52
Create GeneralController.php
mimugmail cf16e21
Update general.xml
mimugmail dff32cd
Update GeneralController.php
mimugmail 8cfabd4
Create ServiceController.php
mimugmail 74383e9
Create General.xml
mimugmail f8eac25
Create General.php
mimugmail c160316
Create Menu.xml
mimugmail 43e2ad3
Update ACL.xml
mimugmail 286873f
Update general.volt
mimugmail e074965
Update general.volt
mimugmail 35fe046
Update setup.sh
mimugmail 20a5a30
Update actions_freeradius3.conf
mimugmail f9b5e6e
Update actions_freeradius3.conf
mimugmail 40ece5c
Update ServiceController.php
mimugmail 2c83d1c
Update pkg-descr
mimugmail 426fa23
Update Menu.xml
mimugmail bd84f9e
Update Makefile
mimugmail b78e833
Update Makefile
mimugmail fe23da5
Update Makefile
mimugmail 4f13502
removed the 3
mimugmail 55208c4
Update and rename actions_freeradius3.conf to actions_freeradius.conf
mimugmail f5baf37
Rename net/freeradius3/opnsense/service/templates/OPNsense/Freeradius…
mimugmail f4cd15c
Update and rename net/freeradius3/opnsense/service/templates/OPNsense…
mimugmail 968f758
Rename net/freeradius3/opnsense/scripts/Freeradius3/setup.sh to net/f…
mimugmail e200d26
Update and rename net/freeradius3/opnsense/mvc/app/controllers/OPNsen…
mimugmail b50c503
Update and rename net/freeradius3/opnsense/mvc/app/controllers/OPNsen…
mimugmail b93fea9
Update and rename net/freeradius3/opnsense/mvc/app/controllers/OPNsen…
mimugmail d85f5e1
Update and rename net/freeradius3/opnsense/mvc/app/controllers/OPNsen…
mimugmail 59356a9
Update and rename net/freeradius3/opnsense/mvc/app/models/OPNsense/Fr…
mimugmail 5983b79
Update and rename net/freeradius3/opnsense/mvc/app/models/OPNsense/Fr…
mimugmail 49c8a0e
Update and rename net/freeradius3/opnsense/mvc/app/models/OPNsense/Fr…
mimugmail 762cb87
Update and rename net/freeradius3/opnsense/mvc/app/models/OPNsense/Fr…
mimugmail 9597f97
Update and rename net/freeradius3/opnsense/mvc/app/views/OPNsense/Fre…
mimugmail 997fe19
Rename net/freeradius3/pkg-descr to net/freeradius/pkg-descr
mimugmail f9b82a5
Rename net/freeradius3/Makefile to net/freeradius/Makefile
mimugmail cb2a11d
Rename net/freeradius3/src/etc/inc/plugins.inc.d/freeradius.inc to ne…
mimugmail d388b70
Rename net/freeradius3/opnsense/service/templates/OPNsense/Freeradius…
mimugmail 9337f69
Rename net/freeradius3/opnsense/service/templates/OPNsense/Freeradius…
mimugmail 201ea57
Rename net/freeradius3/opnsense/service/templates/OPNsense/Freeradius…
mimugmail 1877c3f
Rename net/freeradius3/opnsense/service/conf/actions.d/actions_freera…
mimugmail 35a5c0a
Rename net/freeradius3/opnsense/scripts/Freeradius/setup.sh to net/fr…
mimugmail dc6af8a
Rename net/freeradius3/opnsense/mvc/app/controllers/OPNsense/Freeradi…
mimugmail 38d5841
Rename net/freeradius3/opnsense/mvc/app/controllers/OPNsense/Freeradi…
mimugmail 9bdeb20
Rename net/freeradius3/opnsense/mvc/app/controllers/OPNsense/Freeradi…
mimugmail fa9ce5c
Update and rename net/freeradius3/opnsense/mvc/app/controllers/OPNsen…
mimugmail 6d365af
Rename net/freeradius3/opnsense/mvc/app/models/OPNsense/Freeradius/Ge…
mimugmail 35f8335
Rename net/freeradius3/opnsense/mvc/app/models/OPNsense/Freeradius/Ge…
mimugmail 45c7ad6
Rename net/freeradius3/opnsense/mvc/app/models/OPNsense/Freeradius/Me…
mimugmail 5713e90
Rename net/freeradius3/opnsense/mvc/app/models/OPNsense/Freeradius/AC…
mimugmail 78d37f1
Rename net/freeradius3/opnsense/mvc/app/views/OPNsense/Freeradius/gen…
mimugmail eeabf95
Update ACL.xml
mimugmail 9aa7a8b
Rename net/freeradius/opnsense/service/templates/OPNsense/Freeradius/…
mimugmail efb1445
Rename net/freeradius/opnsense/service/templates/OPNsense/Freeradius/…
mimugmail a0fd408
Rename net/freeradius/opnsense/service/templates/OPNsense/Freeradius/…
mimugmail 4c00bb5
Rename net/freeradius/opnsense/service/conf/actions.d/actions_freerad…
mimugmail 257361d
Rename net/freeradius/opnsense/scripts/Freeradius/setup.sh to net/fre…
mimugmail d0d5dec
Rename net/freeradius/opnsense/mvc/app/controllers/OPNsense/Freeradiu…
mimugmail b5270e7
Rename net/freeradius/opnsense/mvc/app/controllers/OPNsense/Freeradiu…
mimugmail dd7f8bd
Rename net/freeradius/opnsense/mvc/app/controllers/OPNsense/Freeradiu…
mimugmail 0f6d620
Rename net/freeradius/opnsense/mvc/app/controllers/OPNsense/Freeradiu…
mimugmail a2d3df1
Rename net/freeradius/opnsense/mvc/app/models/OPNsense/Freeradius/ACL…
mimugmail cedde41
Rename net/freeradius/opnsense/mvc/app/models/OPNsense/Freeradius/Men…
mimugmail a83f93d
Rename net/freeradius/opnsense/mvc/app/models/OPNsense/Freeradius/Gen…
mimugmail 0b4ef2a
Rename net/freeradius/opnsense/mvc/app/models/OPNsense/Freeradius/Gen…
mimugmail 7e64bb7
Rename net/freeradius/opnsense/mvc/app/views/OPNsense/Freeradius/gene…
mimugmail 2e27fb6
Rename GeneralController.ph to GeneralController.php
mimugmail 8ed3d31
Create clients.conf
mimugmail 39df406
Create dictionary
mimugmail f9169ad
Create hints
mimugmail ca40809
Create huntgroups
mimugmail 25bd0f7
Update huntgroups
mimugmail e6c1c0f
Create proxy.conf
mimugmail a1d4c9d
Update proxy.conf
mimugmail b279194
Create radius.conf
mimugmail 9d8c035
Create templates.conf
mimugmail be8abb3
Update templates.conf
mimugmail b51e1d3
Create trigger.conf
mimugmail 85dd03a
Update users
mimugmail 2aa67a0
Update users
mimugmail 533253a
Create default
mimugmail 3ece8b9
Create inner-tunnel
mimugmail e674146
Update inner-tunnel
mimugmail eee022b
Update +TARGETS
mimugmail 2865536
Update +TARGETS
mimugmail 33da1ab
Update +TARGETS
mimugmail 8a7fcba
Rename net/freeradius/src/opnsense/service/templates/OPNsense/Freerad…
mimugmail 9bf82d4
Rename net/freeradius/src/opnsense/service/templates/OPNsense/Freerad…
mimugmail e14fb7e
Update +TARGETS
mimugmail ce44d3d
Update radius.conf
mimugmail febc3e3
Update sites-enabled-default
mimugmail 810ea23
Update sites-enabled-default
mimugmail 7e1619c
Rename radius.conf to radiusd.conf
mimugmail ba1802d
Update +TARGETS
mimugmail fb121c4
Create UserController.php
mimugmail 40051d3
Create user.xml
mimugmail b44401d
Update user.xml
mimugmail a9808e0
Create UserController.php
mimugmail d9ceba4
Create User.php
mimugmail b965ea8
Update User.php
mimugmail 111e0fb
Create User.xml
mimugmail f2bef0e
Update UserController.php
mimugmail 3d5a0dc
Create user.volt
mimugmail abe2992
Update Menu.xml
mimugmail b0e70a9
Update UserController.php
mimugmail 86b5a8c
Rename user.xml to DialogEditFreeRADIUSUser.xml
mimugmail b4f4106
Update user.volt
mimugmail 889858b
Update user.volt
mimugmail 44cdce1
Update UserController.php
mimugmail f89b4d9
Update user.volt
mimugmail d8f9c1e
Rename DialogEditFreeRADIUSUser.xml to dialogEditFreeRADIUSUser.xml
mimugmail 03be2ea
Update user.volt
mimugmail 1e96a43
Update user.volt
mimugmail bcee9c2
Update user.volt
mimugmail 0e3ce23
Rename user.volt to user_.volt
mimugmail 809a709
Create user.volt
mimugmail be98e94
Delete user_.volt
mimugmail 81568d3
Update user.volt
mimugmail 449a084
Update User.xml
mimugmail 978a343
Update dialogEditFreeRADIUSUser.xml
mimugmail 383bd38
Update UserController.php
mimugmail 73965bd
Update UserController.php
mimugmail bed7a4c
Update UserController.php
mimugmail 26cfa11
Update UserController.php
mimugmail 44d0489
Update user.volt
mimugmail ded3a67
Update user.volt
mimugmail 231c64c
Update user.volt
mimugmail 22834ac
Update UserController.php
mimugmail 6c31e15
Update User.xml
mimugmail fd61f5a
Update UserController.php
mimugmail 6d65fde
Update users
mimugmail 3f8c5cc
Update users
mimugmail 5686ee7
Update users
mimugmail cbcfd97
Update users
mimugmail 0e84486
Update users
mimugmail 57eb5f1
Update users
mimugmail a90b212
Update users
mimugmail 8c23f42
Update users
mimugmail 3b1d6b8
Update User.xml
mimugmail 025a057
Update users
mimugmail 07d81e4
Update users
mimugmail ba2a55c
Update users
mimugmail b5a26bb
Update users
mimugmail c0ebea9
Update users
mimugmail fd0efd3
Update users
mimugmail 80afc0f
Update users
mimugmail 81eaa15
Create ClientController.php
mimugmail b7906df
Update ClientController.php
mimugmail d839a5d
Create ClientController.php
mimugmail a14e675
Create dialogEditFreeRADIUSClient.xml
mimugmail 5bc3127
Create Client.php
mimugmail 227a474
Create Client.xml
mimugmail 43b6af5
Update Menu.xml
mimugmail c4d9f75
Create client.volt
mimugmail b4f48e3
Update ClientController.php
mimugmail f75aace
Update client.volt
mimugmail c7f3f38
Update clients.conf
mimugmail 5ba8fdb
Update clients.conf
mimugmail 9ad80a8
Update clients.conf
mimugmail 95238b7
bump to 0.2.0
mimugmail 079a8f1
Delete dictionary
mimugmail 6d1bb56
Delete hints
mimugmail 669aada
Delete huntgroups
mimugmail ea19ef4
Delete proxy.conf
mimugmail 49d8e4e
Delete templates.conf
mimugmail 8b8052f
Delete trigger.conf
mimugmail e354da9
Update +TARGETS
mimugmail 0a24527
Update +TARGETS
mimugmail 4a0fe5d
Update users
mimugmail 95f2b55
Update users
mimugmail 6571de1
Update users
mimugmail 1883da7
Update user.volt
mimugmail 2dd0b78
Update User.xml
mimugmail be325a0
Update dialogEditFreeRADIUSUser.xml
mimugmail b13fdeb
Update UserController.php
mimugmail 1e4ac93
Update dialogEditFreeRADIUSUser.xml
mimugmail 1e450ae
Update users
mimugmail b930558
Update users
mimugmail a2d645b
Update users
mimugmail 0ac217d
Update users
mimugmail 5f78ed0
Update users
mimugmail 4c269d2
Update users
mimugmail 3687e75
Update users
mimugmail a0a4380
Update Menu.xml
mimugmail 0c3269b
Update Menu.xml
mimugmail 0b982e8
Update User.xml
mimugmail b3bb349
Update User.xml
mimugmail cb1840a
Update dialogEditFreeRADIUSUser.xml
mimugmail 4f02df4
Update User.xml
mimugmail 28f1ca5
Update dialogEditFreeRADIUSUser.xml
mimugmail 0ba2c8f
Update User.xml
mimugmail 3b11585
Update users
mimugmail 8729c91
Update dialogEditFreeRADIUSUser.xml
mimugmail faf0b31
Update general.xml
mimugmail e6318e6
Update General.xml
mimugmail 55ad2e1
Update +TARGETS
mimugmail 48089ba
Create mods-enabled-eap
mimugmail 3c7b55b
Update mods-enabled-eap
mimugmail f6af575
Update ClientController.php
mimugmail f3c958b
Update GeneralController.php
mimugmail 2908362
Update UserController.php
mimugmail 275018a
Added VLAN assignment and style fixes
mimugmail 337d95c
Update freeradius.inc
mimugmail 2c3f542
Update ClientController.php
mimugmail 9fbe999
Update ClientController.php
mimugmail dba79f9
Update GeneralController.php
mimugmail 1afdb5f
Update UserController.php
mimugmail 72b67ad
Update dialogEditFreeRADIUSUser.xml
mimugmail 11290f2
Update dialogEditFreeRADIUSClient.xml
mimugmail 752396e
Update general.xml
mimugmail 30dcec7
Update Menu.xml
mimugmail File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| PLUGIN_NAME= freeradius | ||
| PLUGIN_VERSION= 0.3.0 | ||
| PLUGIN_COMMENT= RADIUS Authentication, Authorization and Accounting Server | ||
| PLUGIN_DEPENDS= freeradius3 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also FYI, freeradius3 has been bumped to 3.0.14 in the ports tree two days ago |
||
| PLUGIN_MAINTAINER= m.muenz@gmail.com | ||
|
|
||
| .include "../../Mk/plugins.mk" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| FreeRADIUS includes a RADIUS server, a BSD licensed client library, | ||
| a PAM library, and an Apache module. In most cases, | ||
| the word FreeRADIUS refers to the RADIUS server. | ||
|
|
||
| FreeRADIUS is the most widely deployed RADIUS server in the world. | ||
| It is the basis for multiple commercial offerings. | ||
| It supplies the AAA needs of many Fortune-500 | ||
| companies and Tier 1 ISPs. | ||
|
|
||
| It is also widely used for Enterprise Wi-Fi and IEEE 802.1X | ||
| network security, particularly in the academic community, | ||
| including eduroam. | ||
|
|
||
| The server is fast, feature-rich, modular, and scalable. | ||
|
|
||
| WWW: http://www.freeradius.org |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| Copyright (C) 2017 Michael Muenz | ||
| All rights reserved. | ||
|
|
||
| Redistribution and use in source and binary forms, with or without | ||
| modification, are permitted provided that the following conditions are met: | ||
|
|
||
| 1. Redistributions of source code must retain the above copyright notice, | ||
| this list of conditions and the following disclaimer. | ||
|
|
||
| 2. Redistributions in binary form must reproduce the above copyright | ||
| notice, this list of conditions and the following disclaimer in the | ||
| documentation and/or other materials provided with the distribution. | ||
|
|
||
| THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
| INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY | ||
| AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
| AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, | ||
| OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| POSSIBILITY OF SUCH DAMAGE. | ||
| */ | ||
|
|
||
| function freeradius_services() | ||
| { | ||
| global $config; | ||
|
|
||
| $services = array(); | ||
|
|
||
| if (isset($config['OPNsense']['freeradius']['general']['enabled']) && $config['OPNsense']['freeradius']['general']['enabled'] == 1) { | ||
| $services[] = array( | ||
| 'description' => gettext('FreeRADIUS'), | ||
| 'configd' => array( | ||
| 'restart' => array('freeradius restart'), | ||
| 'start' => array('freeradius start'), | ||
| 'stop' => array('freeradius stop'), | ||
| ), | ||
| 'name' => 'freeradius', | ||
| 'pidfile' => '/var/run/radiusd/radiusd.pid' | ||
| ); | ||
| } | ||
|
|
||
| return $services; | ||
| } |
204 changes: 204 additions & 0 deletions
204
net/freeradius/src/opnsense/mvc/app/controllers/OPNsense/Freeradius/Api/ClientController.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,204 @@ | ||
| <?php | ||
| /** | ||
| * Copyright (C) 2015 - 2017 Deciso B.V. | ||
| * Copyright (C) 2017 Michael Muenz | ||
| * | ||
| * All rights reserved. | ||
| * | ||
| * Redistribution and use in source and binary forms, with or without | ||
| * modification, are permitted provided that the following conditions are met: | ||
| * | ||
| * 1. Redistributions of source code must retain the above copyright notice, | ||
| * this list of conditions and the following disclaimer. | ||
| * | ||
| * 2. Redistributions in binary form must reproduce the above copyright | ||
| * notice, this list of conditions and the following disclaimer in the | ||
| * documentation and/or other materials provided with the distribution. | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
| * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY | ||
| * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
| * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, | ||
| * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| * POSSIBILITY OF SUCH DAMAGE. | ||
| * | ||
| */ | ||
|
|
||
| namespace OPNsense\Freeradius\Api; | ||
|
|
||
| use \OPNsense\Freeradius\Client; | ||
| use \OPNsense\Core\Config; | ||
| use \OPNsense\Base\ApiMutableModelControllerBase; | ||
| use \OPNsense\Base\UIModelGrid; | ||
|
|
||
| class ClientController extends ApiMutableModelControllerBase | ||
| { | ||
| static protected $internalModelName = 'Client'; | ||
| static protected $internalModelClass = '\OPNsense\Freeradius\Client'; | ||
| public function getAction() | ||
| { | ||
| // define list of configurable settings | ||
| $result = array(); | ||
| if ($this->request->isGet()) { | ||
| $mdlClient = new Client(); | ||
| $result['client'] = $mdlClient->getNodes(); | ||
| } | ||
| return $result; | ||
| } | ||
|
|
||
| public function setAction() | ||
| { | ||
| $result = array("result"=>"failed"); | ||
| if ($this->request->isPost()) { | ||
| // load model and update with provided data | ||
| $mdlClient = new Client(); | ||
| $mdlClient->setNodes($this->request->getPost("client")); | ||
| // perform validation | ||
| $valMsgs = $mdlClient->performValidation(); | ||
| foreach ($valMsgs as $field => $msg) { | ||
| if (!array_key_exists("validations", $result)) { | ||
| $result["validations"] = array(); | ||
| } | ||
| $result["validations"]["client.".$msg->getField()] = $msg->getMessage(); | ||
| } | ||
| // serialize model to config and save | ||
| if ($valMsgs->count() == 0) { | ||
| $mdlClient->serializeToConfig(); | ||
| Config::getInstance()->save(); | ||
| $result["result"] = "saved"; | ||
| } | ||
| } | ||
| return $result; | ||
| } | ||
|
|
||
| public function searchClientAction() | ||
| { | ||
| $this->sessionClose(); | ||
| $mdlClient = $this->getModel(); | ||
| $grid = new UIModelGrid($mdlClient->clients->client); | ||
| return $grid->fetchBindRequest( | ||
| $this->request, | ||
| array("enabled", "name", "secret", "ip" ) | ||
| ); | ||
| } | ||
|
|
||
| public function getClientAction($uuid = null) | ||
| { | ||
| $mdlClient = $this->getModel(); | ||
| if ($uuid != null) { | ||
| $node = $mdlClient->getNodeByReference('clients.client.' . $uuid); | ||
| if ($node != null) { | ||
| // return node | ||
| return array("client" => $node->getNodes()); | ||
| } | ||
| } else { | ||
| $node = $mdlClient->clients->client->add(); | ||
| return array("client" => $node->getNodes()); | ||
| } | ||
| return array(); | ||
| } | ||
|
|
||
| public function addClientAction() | ||
| { | ||
| $result = array("result" => "failed"); | ||
| if ($this->request->isPost() && $this->request->hasPost("client")) { | ||
| $result = array("result" => "failed", "validations" => array()); | ||
| $mdlClient = $this->getModel(); | ||
| $node = $mdlClient->clients->client->Add(); | ||
| $node->setNodes($this->request->getPost("client")); | ||
| $valMsgs = $mdlClient->performValidation(); | ||
| foreach ($valMsgs as $field => $msg) { | ||
| $fieldnm = str_replace($node->__reference, "client", $msg->getField()); | ||
| $result["validations"][$fieldnm] = $msg->getMessage(); | ||
| } | ||
| if (count($result['validations']) == 0) { | ||
| unset($result['validations']); | ||
| // save config if validated correctly | ||
| $mdlClient->serializeToConfig(); | ||
| Config::getInstance()->save(); | ||
| unset($result['validations']); | ||
| $result["result"] = "saved"; | ||
| } | ||
| } | ||
| return $result; | ||
| } | ||
|
|
||
| public function delClientAction($uuid) | ||
| { | ||
| $result = array("result" => "failed"); | ||
| if ($this->request->isPost()) { | ||
| $mdlClient = $this->getModel(); | ||
| if ($uuid != null) { | ||
| if ($mdlClient->clients->client->del($uuid)) { | ||
| $mdlClient->serializeToConfig(); | ||
| Config::getInstance()->save(); | ||
| $result['result'] = 'deleted'; | ||
| } else { | ||
| $result['result'] = 'not found'; | ||
| } | ||
| } | ||
| } | ||
| return $result; | ||
| } | ||
|
|
||
| public function setClientAction($uuid) | ||
| { | ||
| if ($this->request->isPost() && $this->request->hasPost("client")) { | ||
| $mdlSetting = $this->getModel(); | ||
| if ($uuid != null) { | ||
| $node = $mdlSetting->getNodeByReference('clients.client.' . $uuid); | ||
| if ($node != null) { | ||
| $result = array("result" => "failed", "validations" => array()); | ||
| $clientInfo = $this->request->getPost("client"); | ||
| $node->setNodes($clientInfo); | ||
| $valMsgs = $mdlSetting->performValidation(); | ||
| foreach ($valMsgs as $field => $msg) { | ||
| $fieldnm = str_replace($node->__reference, "client", $msg->getField()); | ||
| $result["validations"][$fieldnm] = $msg->getMessage(); | ||
| } | ||
| if (count($result['validations']) == 0) { | ||
| // save config if validated correctly | ||
| $mdlSetting->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()) { | ||
| $mdlSetting = $this->getModel(); | ||
| if ($uuid != null) { | ||
| $node = $mdlSetting->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 | ||
| $mdlSetting->serializeToConfig(); | ||
| Config::getInstance()->save(); | ||
| } | ||
| } | ||
| } | ||
| return $result; | ||
| } | ||
|
|
||
| public function toggleClientAction($uuid) | ||
| { | ||
| return $this->toggle_handler($uuid, 'clients', 'client'); | ||
| } | ||
| } |
76 changes: 76 additions & 0 deletions
76
...freeradius/src/opnsense/mvc/app/controllers/OPNsense/Freeradius/Api/GeneralController.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| <?php | ||
| /** | ||
| * Copyright (C) 2015 - 2017 Deciso B.V. | ||
| * Copyright (C) 2017 Michael Muenz | ||
| * | ||
| * All rights reserved. | ||
| * | ||
| * Redistribution and use in source and binary forms, with or without | ||
| * modification, are permitted provided that the following conditions are met: | ||
| * | ||
| * 1. Redistributions of source code must retain the above copyright notice, | ||
| * this list of conditions and the following disclaimer. | ||
| * | ||
| * 2. Redistributions in binary form must reproduce the above copyright | ||
| * notice, this list of conditions and the following disclaimer in the | ||
| * documentation and/or other materials provided with the distribution. | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
| * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY | ||
| * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
| * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, | ||
| * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| * POSSIBILITY OF SUCH DAMAGE. | ||
| * | ||
| */ | ||
|
|
||
| namespace OPNsense\Freeradius\Api; | ||
|
|
||
| use \OPNsense\Base\ApiControllerBase; | ||
| use \OPNsense\Freeradius\General; | ||
| use \OPNsense\Core\Config; | ||
|
|
||
| class GeneralController extends ApiControllerBase | ||
| { | ||
| public function getAction() | ||
| { | ||
| // define list of configurable settings | ||
| $result = array(); | ||
| if ($this->request->isGet()) { | ||
| $mdlGeneral = new General(); | ||
| $result['general'] = $mdlGeneral->getNodes(); | ||
| } | ||
| return $result; | ||
| } | ||
|
|
||
| public function setAction() | ||
| { | ||
| $result = array("result"=>"failed"); | ||
| if ($this->request->isPost()) { | ||
| // load model and update with provided data | ||
| $mdlGeneral = new General(); | ||
| $mdlGeneral->setNodes($this->request->getPost("general")); | ||
|
|
||
| // perform validation | ||
| $valMsgs = $mdlGeneral->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) { | ||
| $mdlGeneral->serializeToConfig(); | ||
| Config::getInstance()->save(); | ||
| $result["result"] = "saved"; | ||
| } | ||
| } | ||
| return $result; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just FYI: as long as the pull request is open you don't have to necessarily bump the version more than once. we also have PLUGIN_REVISION= which can be set to a numeric value for bugfixes, that's why most plugins only have X.Y, not X.Y.Z. But @fabianfrz likes three version numbers and that's perfectly fine here... only want to explain :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with both, let's keep it this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok 👍