www/caddy: Fix IPv6 address + Port combination in Caddyfile template (#4054)

* Fix IPv6 in handlers. IPv6 will be detected and put into square brackets. Additionally removed that IP addresses are valid in the frontend domain, since that would break some template sections like dyndns and certificate generation, so it is unsupported in the scope of the GUI.

* www/caddy: Remove IP address in domains from help text too.

* www/caddy: Explicitely set IpAllowed to N since the default is Y.
This commit is contained in:
Monviech
2024-06-27 15:18:21 +02:00
committed by GitHub
parent 78a784c5d9
commit f1d5434657
3 changed files with 7 additions and 5 deletions
@@ -10,7 +10,7 @@
<label>Domain</label>
<type>text</type>
<hint>example.com</hint>
<help><![CDATA[Enter a domain name or IP address. For a base domain, use "example.com" or "opn.example.com". Using a base domain enables automatic "Let's Encrypt" and "ZeroSSL" certificates by default. For a wildcard domain, use "*.example.com". Only use wildcard domains with wildcard certificates, which require a DNS Provider.]]></help>
<help><![CDATA[Enter a domain name. For a base domain, use "example.com" or "opn.example.com". Using a base domain enables automatic "Let's Encrypt" and "ZeroSSL" certificates by default. For a wildcard domain, use "*.example.com". Only use wildcard domains with wildcard certificates, which require a DNS Provider.]]></help>
</field>
<field>
<id>reverse.FromPort</id>
@@ -135,8 +135,8 @@
</enabled>
<FromDomain type="HostnameField">
<Required>Y</Required>
<ValidationMessage>Please enter a valid 'from' domain or IP address.</ValidationMessage>
<IpAllowed>Y</IpAllowed>
<ValidationMessage>Please enter a valid 'from' domain.</ValidationMessage>
<IpAllowed>N</IpAllowed>
<HostWildcardAllowed>Y</HostWildcardAllowed>
<FqdnWildcardAllowed>Y</FqdnWildcardAllowed>
<ZoneRootAllowed>N</ZoneRootAllowed>
@@ -350,9 +350,11 @@
rewrite * {{ handle.ToPath }}{uri}
{% endif %}
reverse_proxy {% for domain in handle.ToDomain.split(',') %}
{# Check if the domain is IPv6 and wrap in square brackets if necessary #}
{% set is_ipv6 = (':' in domain and domain.count(':') >= 2) %}
{# For each domain/IP, append the port if it's specified, followed by a space #}
{{- domain -}}{% if handle.ToPort %}:{{ handle.ToPort }}{% endif %}{% if not loop.last %} {% endif %}
{% endfor %}{
{{- '[' if is_ipv6 else '' -}}{{ domain }}{{ ']' if is_ipv6 else '' -}}{% if handle.ToPort %}:{{ handle.ToPort }}{% endif %}{% if not loop.last %} {% endif %}
{% endfor %} {
{{ header_manipulation(handle) }}
{% if handle.PassiveHealthFailDuration|default("") %}
fail_duration {{ handle.PassiveHealthFailDuration }}s