From 2ddbc3831d7fb5a2b3de2ad4194c0e378224f37b Mon Sep 17 00:00:00 2001 From: Monviech <79600909+Monviech@users.noreply.github.com> Date: Wed, 5 Jun 2024 15:12:56 +0200 Subject: [PATCH] www/caddy: Remove port from subdomain since it is unsupported. (#4028) * www/caddy: Remove port from subdomain since it is unsupported. Subdomains track their port from their wildcard domain. * Add change logs and bump version to 1.5.7 * Changed numbering in validation caddy.php. Adjusted changelog to include new version of caddy. --- www/caddy/Makefile | 2 +- www/caddy/pkg-descr | 9 +++++++ .../OPNsense/Caddy/forms/dialogSubdomain.xml | 11 ++------- .../mvc/app/models/OPNsense/Caddy/Caddy.php | 24 ++++++++----------- .../mvc/app/models/OPNsense/Caddy/Caddy.xml | 7 +----- .../views/OPNsense/Caddy/reverse_proxy.volt | 1 - .../templates/OPNsense/Caddy/Caddyfile | 2 +- 7 files changed, 24 insertions(+), 32 deletions(-) diff --git a/www/caddy/Makefile b/www/caddy/Makefile index 3e61d6cc6..852d97abb 100644 --- a/www/caddy/Makefile +++ b/www/caddy/Makefile @@ -1,5 +1,5 @@ PLUGIN_NAME= caddy -PLUGIN_VERSION= 1.5.6 +PLUGIN_VERSION= 1.5.7 PLUGIN_DEPENDS= caddy-custom PLUGIN_COMMENT= Easy to configure Reverse Proxy with Automatic HTTPS and Dynamic DNS PLUGIN_MAINTAINER= cedrik@pischem.com diff --git a/www/caddy/pkg-descr b/www/caddy/pkg-descr index c7e00bd68..b29f9461b 100644 --- a/www/caddy/pkg-descr +++ b/www/caddy/pkg-descr @@ -26,6 +26,15 @@ DOC: https://docs.opnsense.org/manual/how-tos/caddy.html Plugin Changelog ================ +1.5.7 + +* Build: Update to Caddy v2.8.4 + caddy-dns plugins updated to latest upstream versions +* Add: Error message when OPNsense WebGUI settings conflict with Auto HTTPS. +* Add: Error message when Auto HTTPS is enabled, and ACME email field is empty, for caddy v2.8.4 +* Cleanup: Fix crash of searchAction when reverseUuids is null +* Cleanup: basicauth directive is now basic_auth in the Caddyfile template, for caddy v2.8.4 +* Fix: The subdomain port field has been removed, since it is unsupported. Subdomains track their ports from their parent wildcard domain. + 1.5.6 * Fix: Wildcard domains with activated "Dynamic DNS" update their base domain with * instead of @. diff --git a/www/caddy/src/opnsense/mvc/app/controllers/OPNsense/Caddy/forms/dialogSubdomain.xml b/www/caddy/src/opnsense/mvc/app/controllers/OPNsense/Caddy/forms/dialogSubdomain.xml index ca6eeb611..4777809ad 100644 --- a/www/caddy/src/opnsense/mvc/app/controllers/OPNsense/Caddy/forms/dialogSubdomain.xml +++ b/www/caddy/src/opnsense/mvc/app/controllers/OPNsense/Caddy/forms/dialogSubdomain.xml @@ -16,20 +16,13 @@ text opn.example.com - - - - subdomain.FromPort - - text - 443 - + subdomain.description text - opn.example.com.443 + opn.example.com diff --git a/www/caddy/src/opnsense/mvc/app/models/OPNsense/Caddy/Caddy.php b/www/caddy/src/opnsense/mvc/app/models/OPNsense/Caddy/Caddy.php index 2c009e188..467233827 100644 --- a/www/caddy/src/opnsense/mvc/app/models/OPNsense/Caddy/Caddy.php +++ b/www/caddy/src/opnsense/mvc/app/models/OPNsense/Caddy/Caddy.php @@ -37,13 +37,12 @@ use OPNsense\Core\Config; class Caddy extends BaseModel { // 1. Check domain-port combinations - // 2. Check subdomain-port combinations private function checkForUniquePortCombos($items, $messages) { $combos = []; foreach ($items as $item) { $key = $item->__reference; // Dynamic key based on item reference - $fromDomainOrSubdomain = (string) $item->FromDomain; + $fromDomain = (string) $item->FromDomain; $fromPort = (string) $item->FromPort; if ($fromPort === '') { @@ -53,14 +52,14 @@ class Caddy extends BaseModel } foreach ($defaultPorts as $port) { - // Create a unique key for domain/subdomain-port combination - $comboKey = $fromDomainOrSubdomain . ':' . $port; + // Create a unique key for domain-port combination + $comboKey = $fromDomain . ':' . $port; // Check for duplicate combinations if (isset($combos[$comboKey])) { // Use dynamic $key for message referencing $messages->appendMessage(new Message( - sprintf(gettext("Duplicate entry: The combination of '%s' and port '%s' is already used. Each combination of domain/subdomain and port must be unique."), $fromDomainOrSubdomain, $port), + sprintf(gettext("Duplicate entry: The combination of '%s' and port '%s' is already used. Each combination of domain and port must be unique."), $fromDomain, $port), $key . ".FromDomain", // Adjusted to use dynamic key "DuplicateDomainPort" )); @@ -71,7 +70,7 @@ class Caddy extends BaseModel } } - // 3. Check that subdomains are under a wildcard or exact domain + // 2. Check that subdomains are under a wildcard or exact domain private function checkSubdomainsAgainstDomains($subdomains, $domains, $messages) { $wildcardDomainList = []; @@ -108,7 +107,7 @@ class Caddy extends BaseModel } } - // 4. Get the current OPNsense WebGUI ports + // 3. Get the current OPNsense WebGUI ports and check for conflicts with Caddy private function getWebGuiPorts() { $webgui = Config::getInstance()->object()->system->webgui ?? null; $webGuiPorts = []; @@ -127,7 +126,6 @@ class Caddy extends BaseModel return $webGuiPorts; } - // 4. Check for conflicts between Caddy and OPNsense WebGUI ports private function checkWebGuiSettings($messages) { $overlap = array_intersect($this->getWebGuiPorts(), ['80', '443']); $tlsAutoHttpsSetting = (string)$this->general->TlsAutoHttps; @@ -141,7 +139,7 @@ class Caddy extends BaseModel } } - // 5. Check for ACME Email being required when Auto HTTPS on + // 4. Check for ACME Email being required when Auto HTTPS on private function checkAcmeEmailAutoHttps($messages) { $tlsAutoHttpsSetting = (string)$this->general->TlsAutoHttps; $tlsEmail = (string)$this->general->TlsEmail; @@ -160,13 +158,11 @@ class Caddy extends BaseModel $messages = parent::performValidation($validateFullModel); // 1. Check domain-port combinations $this->checkForUniquePortCombos($this->reverseproxy->reverse->iterateItems(), $messages); - // 2. Check subdomain-port combinations - $this->checkForUniquePortCombos($this->reverseproxy->subdomain->iterateItems(), $messages); - // 3. Check that subdomains are under a wildcard or exact domain + // 2. Check that subdomains are under a wildcard or exact domain $this->checkSubdomainsAgainstDomains($this->reverseproxy->subdomain->iterateItems(), $this->reverseproxy->reverse->iterateItems(), $messages); - // 4. Check WebGUI conflicts + // 3. Check WebGUI conflicts $this->checkWebGuiSettings($messages); - // 5. Check for ACME Email requirement + // 4. Check for ACME Email requirement $this->checkAcmeEmailAutoHttps($messages); return $messages; diff --git a/www/caddy/src/opnsense/mvc/app/models/OPNsense/Caddy/Caddy.xml b/www/caddy/src/opnsense/mvc/app/models/OPNsense/Caddy/Caddy.xml index 49e1aa122..a65ba0e4b 100644 --- a/www/caddy/src/opnsense/mvc/app/models/OPNsense/Caddy/Caddy.xml +++ b/www/caddy/src/opnsense/mvc/app/models/OPNsense/Caddy/Caddy.xml @@ -1,7 +1,7 @@ //Pischem/caddy A GUI model for configuring a reverse proxy in the Caddy web server. - 1.1.9 + 1.2.0 @@ -191,11 +191,6 @@ Please enter a valid 'from' Subdomain that is based upon the wildcard domain. N - - Please enter a valid 'from' port number. - Y - N - diff --git a/www/caddy/src/opnsense/mvc/app/views/OPNsense/Caddy/reverse_proxy.volt b/www/caddy/src/opnsense/mvc/app/views/OPNsense/Caddy/reverse_proxy.volt index 0afbf51bb..5884a9eb4 100644 --- a/www/caddy/src/opnsense/mvc/app/views/OPNsense/Caddy/reverse_proxy.volt +++ b/www/caddy/src/opnsense/mvc/app/views/OPNsense/Caddy/reverse_proxy.volt @@ -291,7 +291,6 @@ {{ lang._('Enabled') }} {{ lang._('Domain') }} {{ lang._('Subdomain') }} - {{ lang._('Port') }} {{ lang._('Access List') }} {{ lang._('Basic Auth') }} {{ lang._('Dynamic DNS') }} diff --git a/www/caddy/src/opnsense/service/templates/OPNsense/Caddy/Caddyfile b/www/caddy/src/opnsense/service/templates/OPNsense/Caddy/Caddyfile index 24f365087..db183733c 100644 --- a/www/caddy/src/opnsense/service/templates/OPNsense/Caddy/Caddyfile +++ b/www/caddy/src/opnsense/service/templates/OPNsense/Caddy/Caddyfile @@ -694,7 +694,7 @@ {% for subdomain in helpers.toList('Pischem.caddy.reverseproxy.subdomain') %} {% if subdomain.enabled|default("0") == "1" and subdomain.reverse == reverse['@uuid'] %} @{{ subdomain['@uuid'] }} { - host {{ subdomain.FromDomain }}{% if subdomain.FromPort %}:{{ subdomain.FromPort }}{% endif %} + host {{ subdomain.FromDomain }} } handle @{{ subdomain['@uuid'] }} {