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.
This commit is contained in:
Monviech
2024-06-05 15:12:56 +02:00
committed by GitHub
parent 75d55d99e2
commit 2ddbc3831d
7 changed files with 24 additions and 32 deletions
+1 -1
View File
@@ -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
+9
View File
@@ -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 @.
@@ -16,20 +16,13 @@
<label>Subdomain</label>
<type>text</type>
<hint>opn.example.com</hint>
<help><![CDATA[Enter a subdomain. For example, "opn.example.com" if the wildcard domain is "*.example.com".]]></help>
</field>
<field>
<id>subdomain.FromPort</id>
<label>Port</label>
<type>text</type>
<hint>443</hint>
<help><![CDATA[Leave empty to use ports 80 and 443 with automatic redirection from HTTP to HTTPS or choose a custom port. Do not forget to allow these ports with a Firewall rule.]]></help>
<help><![CDATA[Enter a subdomain. For example, "opn.example.com" if the wildcard domain is "*.example.com". All subdomains use the same ports as their parent wildcard domain.]]></help>
</field>
<field>
<id>subdomain.description</id>
<label>Description</label>
<type>text</type>
<hint>opn.example.com.443</hint>
<hint>opn.example.com</hint>
<help><![CDATA[Enter a description for this subdomain.]]></help>
</field>
<field>
@@ -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;
@@ -1,7 +1,7 @@
<model>
<mount>//Pischem/caddy</mount>
<description>A GUI model for configuring a reverse proxy in the Caddy web server.</description>
<version>1.1.9</version>
<version>1.2.0</version>
<items>
<general>
<enabled type="BooleanField">
@@ -191,11 +191,6 @@
<ValidationMessage>Please enter a valid 'from' Subdomain that is based upon the wildcard domain.</ValidationMessage>
<ZoneRootAllowed>N</ZoneRootAllowed>
</FromDomain>
<FromPort type="PortField">
<ValidationMessage>Please enter a valid 'from' port number.</ValidationMessage>
<EnableWellKnown>Y</EnableWellKnown>
<EnableRanges>N</EnableRanges>
</FromPort>
<accesslist type="ModelRelationField">
<Model>
<reverseproxy>
@@ -291,7 +291,6 @@
<th data-column-id="enabled" data-width="6em" data-type="boolean" data-formatter="rowtoggle">{{ lang._('Enabled') }}</th>
<th data-column-id="reverse" data-type="string">{{ lang._('Domain') }}</th>
<th data-column-id="FromDomain" data-type="string">{{ lang._('Subdomain') }}</th>
<th data-column-id="FromPort" data-type="string">{{ lang._('Port') }}</th>
<th data-column-id="accesslist" data-type="string" data-visible="false">{{ lang._('Access List') }}</th>
<th data-column-id="basicauth" data-type="string" data-visible="false">{{ lang._('Basic Auth') }}</th>
<th data-column-id="DynDns" data-type="boolean" data-formatter="boolean" data-visible="false">{{ lang._('Dynamic DNS') }}</th>
@@ -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'] }} {