diff --git a/security/tor/src/opnsense/mvc/app/controllers/OPNsense/Tor/Api/GeneralController.php b/security/tor/src/opnsense/mvc/app/controllers/OPNsense/Tor/Api/GeneralController.php index b24cb65c4..f1d0b4013 100644 --- a/security/tor/src/opnsense/mvc/app/controllers/OPNsense/Tor/Api/GeneralController.php +++ b/security/tor/src/opnsense/mvc/app/controllers/OPNsense/Tor/Api/GeneralController.php @@ -33,6 +33,7 @@ use \OPNsense\Base\ApiMutableModelControllerBase; use \OPNsense\Core\Backend; use \OPNsense\Core\Config; use \OPNsense\Tor\General; +use \OPNsense\Base\UIModelGrid; class GeneralController extends ApiMutableModelControllerBase { @@ -70,4 +71,137 @@ class GeneralController extends ApiMutableModelControllerBase } return $result; } + + + + /* Hidden service authentication */ + + public function searchhidservauthAction() + { + $this->sessionClose(); + $mdl = $this->getModel(); + $grid = new UIModelGrid($mdl->client_authentications->client_auth); + return $grid->fetchBindRequest( + $this->request, + array('enabled', 'onion_service', 'auth_cookie') + ); + } + public function gethidservauthAction($uuid = null) + { + $mdl = $this->getModel(); + if ($uuid != null) { + $node = $mdl->getNodeByReference('client_authentications.client_auth.' . $uuid); + if ($node != null) { + // return node + return array('client_auth' => $node->getNodes()); + } + } else { + $node = $mdl->client_authentications->client_auth->add(); + return array('client_auth' => $node->getNodes()); + } + return array(); + } + public function addhidservauthAction() + { + $result = array('result' => 'failed'); + if ($this->request->isPost() && $this->request->hasPost('client_auth')) { + $result = array('result' => 'failed', 'validations' => array()); + $mdl = $this->getModel(); + $node = $mdl->client_authentications->client_auth->Add(); + $node->setNodes($this->request->getPost('client_auth')); + $valMsgs = $mdl->performValidation(); + + foreach ($valMsgs as $field => $msg) { + $fieldnm = str_replace($node->__reference, 'client_auth', $msg->getField()); + $result['validations'][$fieldnm] = $msg->getMessage(); + } + + if (count($result['validations']) == 0) { + // save config if validated correctly + $mdl->serializeToConfig(); + Config::getInstance()->save(); + unset($result['validations']); + $result['result'] = 'saved'; + } + } + return $result; + } + public function delhidservauthAction($uuid) + { + + $result = array('result' => 'failed'); + + if ($this->request->isPost()) { + $mdl = $this->getModel(); + if ($uuid != null) { + if ($mdl->client_authentications->client_auth->del($uuid)) { + $mdl->serializeToConfig(); + Config::getInstance()->save(); + $result['result'] = 'deleted'; + } else { + $result['result'] = 'not found'; + } + } + } + return $result; + } + public function sethidservauthAction($uuid) + { + if ($this->request->isPost() && $this->request->hasPost('client_auth')) { + $mdl = $this->getModel(); + if ($uuid != null) { + $node = $mdl->getNodeByReference('client_authentications.client_auth.' . $uuid); + if ($node != null) { + $result = array('result' => 'failed', 'validations' => array()); + $info = $this->request->getPost('client_auth'); + + $node->setNodes($info); + $valMsgs = $mdl->performValidation(); + foreach ($valMsgs as $field => $msg) { + $fieldnm = str_replace($node->__reference, 'client_auth', $msg->getField()); + $result['validations'][$fieldnm] = $msg->getMessage(); + } + + if (count($result['validations']) == 0) { + // save config if validated correctly + $mdl->serializeToConfig(); + unset($result['validations']); + Config::getInstance()->save(); + $result = array('result' => 'saved'); + } + return $result; + } + } + } + return array('result' => 'failed'); + } + public function toggle_handler($uuid, $element) + { + + $result = array('result' => 'failed'); + + if ($this->request->isPost()) { + $mdl = $this->getModel(); + if ($uuid != null) { + $node = $mdl->getNodeByReference($element . '.' . $uuid); + if ($node != null) { + if ($node->enabled->__toString() == '1') { + $result['result'] = 'Disabled'; + $node->enabled = '0'; + } else { + $result['result'] = 'Enabled'; + $node->enabled = '1'; + } + $mdl->serializeToConfig(); + Config::getInstance()->save(); + } + } + } + return $result; + } + + public function togglehidservauthAction($uuid) + { + return $this->toggle_handler($uuid, 'client_authentications.client_auth'); + } } diff --git a/security/tor/src/opnsense/mvc/app/controllers/OPNsense/Tor/IndexController.php b/security/tor/src/opnsense/mvc/app/controllers/OPNsense/Tor/IndexController.php index 881e687b4..705e82e30 100644 --- a/security/tor/src/opnsense/mvc/app/controllers/OPNsense/Tor/IndexController.php +++ b/security/tor/src/opnsense/mvc/app/controllers/OPNsense/Tor/IndexController.php @@ -45,6 +45,7 @@ class IndexController extends \OPNsense\Base\IndexController $this->view->hidden_service = $this->getForm("hidden_service"); $this->view->hidden_service_acl = $this->getForm("hidden_service_acl"); $this->view->relay = $this->getForm("relay"); + $this->view->hidservauth = $this->getForm("hidservauth"); $this->view->exitpolicy = $this->getForm("acl_exitpolicy"); $this->view->pick('OPNsense/Tor/general'); } diff --git a/security/tor/src/opnsense/mvc/app/controllers/OPNsense/Tor/forms/hidservauth.xml b/security/tor/src/opnsense/mvc/app/controllers/OPNsense/Tor/forms/hidservauth.xml new file mode 100644 index 000000000..d195a9cfe --- /dev/null +++ b/security/tor/src/opnsense/mvc/app/controllers/OPNsense/Tor/forms/hidservauth.xml @@ -0,0 +1,17 @@ +
diff --git a/security/tor/src/opnsense/mvc/app/models/OPNsense/Tor/General.xml b/security/tor/src/opnsense/mvc/app/models/OPNsense/Tor/General.xml index 36b570efd..82bc0d222 100644 --- a/security/tor/src/opnsense/mvc/app/models/OPNsense/Tor/General.xml +++ b/security/tor/src/opnsense/mvc/app/models/OPNsense/Tor/General.xml @@ -99,5 +99,23 @@