From f4081dfcdf523b19bc306fd29d705084d5f24ce9 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Thu, 13 Apr 2023 09:22:30 +0200 Subject: [PATCH] Services: Unbound DNS: DNS over TLS - minor improvements to handle "Dot" endpoints and make sure the page actually calls them cc @swhite2 Some small fixes to prevent referer magic to determine he dot endpoint (searchDotAction, getDotAction, ...), since __call() will only be triggered for non existing endpoints (https://www.php.net/manual/en/language.oop5.overloading.php#object.call), we need to set the default to the methods that do exist. Next we can filter and change the target accordingly. The volt template should figure out where it lives, we could have passed this in the ui controller as well, but as these are only two templates and a single page, javascript will do. --- .../OPNsense/Unbound/Api/SettingsController.php | 11 ++++------- .../mvc/app/views/OPNsense/Unbound/dot.volt | 17 +++++++++-------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Unbound/Api/SettingsController.php b/src/opnsense/mvc/app/controllers/OPNsense/Unbound/Api/SettingsController.php index c398907df..3a33b1d7f 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/Unbound/Api/SettingsController.php +++ b/src/opnsense/mvc/app/controllers/OPNsense/Unbound/Api/SettingsController.php @@ -38,7 +38,7 @@ class SettingsController extends ApiMutableModelControllerBase protected static $internalModelClass = '\OPNsense\Unbound\Unbound'; protected static $internalModelName = 'unbound'; - private $type = 'dot'; + private $type = 'forward'; public function updateBlocklistAction() { @@ -108,17 +108,14 @@ class SettingsController extends ApiMutableModelControllerBase /* * Catch all Dot API endpoints and redirect them to Forward for * backwards compatibility and infer the type from the request. - * If no type is provided, default to dot. + * If no type is provided, default to forward (__call only triggers on non-existing methods). */ public function __call($method, $args) { if (substr($method, -6) == 'Action') { $fn = preg_replace('/Dot/', 'Forward', $method); - if (method_exists(get_class($this), $fn)) { - // set the type to forward if the request came from the corresponding gui page or is explicitly set in the API call - if (preg_match("/forward/i", $this->request->getHTTPReferer()) || ($this->request->getPost('dot') && $this->request->getPost('dot')['type'] == 'forward')) { - $this->type = "forward"; - } + if (method_exists(get_class($this), $fn) && preg_match("/.*dot/i", $method)) { + $this->type = "dot"; return $this->$fn(...$args); } } diff --git a/src/opnsense/mvc/app/views/OPNsense/Unbound/dot.volt b/src/opnsense/mvc/app/views/OPNsense/Unbound/dot.volt index a7e75d002..8c3913ff3 100644 --- a/src/opnsense/mvc/app/views/OPNsense/Unbound/dot.volt +++ b/src/opnsense/mvc/app/views/OPNsense/Unbound/dot.volt @@ -27,6 +27,7 @@