www/caddy: Update DNS Provider list and improve maintainability (#4556)

* www/caddy: Consolidate all selective DNS Provider logic to includeDnsProvider

* www/caddy: Update list of DNS providers with optional remaining or new ones from caddy-dns
This commit is contained in:
Monviech
2025-03-06 18:05:22 +01:00
committed by GitHub
parent 51fd4b5bb4
commit 5610d1a88e
4 changed files with 160 additions and 14 deletions
@@ -108,7 +108,7 @@
<id>caddy.general.TlsDnsProvider</id>
<label>DNS Provider</label>
<type>dropdown</type>
<help><![CDATA[Select the DNS Provider for the DNS-01 Challenge and Dynamic DNS. Providers marked as "optional" must be installed manually, see https://caddyserver.com/docs/command-line#caddy-add-package. For more information, visit https://github.com/caddy-dns where each module is community maintained.]]></help>
<help><![CDATA[Select the DNS Provider for the DNS-01 Challenge and Dynamic DNS. Providers marked as "optional" must be installed manually, see https://caddyserver.com/docs/command-line#caddy-add-package. Important: When the version of the caddy binary changes, "optional" provider must be reinstalled. For more information, visit https://github.com/caddy-dns where each module is community maintained.]]></help>
</field>
<field>
<type>header</type>
@@ -118,37 +118,37 @@
<id>caddy.general.TlsDnsApiKey</id>
<label>API Field 1</label>
<type>text</type>
<help><![CDATA[This is the standard field for the API Key. Field can be left empty if optional: Cloudflare "api_token", Duckdns "api_token", DigitalOcean "auth_token", Godaddy "api_token", Gandi "bearer_token", IONOS "api_token", deSEC "token", Route53 "access_key_id", Porkbun "api_key", ACME-DNS "username", Netlify "personal_access_token", Njalla "api_token", Google Cloud DNS "gcp_project", Azure "tenant_id", OVH "endpoint", Namecheap "api_key", PowerDNS "server_url", DDNSS "api_token", Linode "api_token", Tencent Cloud "secret_id", Dinahosting "username", Hexonet "username", Mail-in-a-Box "api_url", DNS Made Easy "api_key", Bunny "access_key", Civo "api_token", Scaleway "secret_key", ACME Proxy "username", INWX "username", Netcup "customer_number", RFC2136 "key_name", Name.com "token", EasyDNS "api_token", Infomaniak "api_token", DirectAdmin "host", Hosttech "api_token", Vultr "api_token", Hetzner "api_token", ClouDNS "auth_id".]]></help>
<help><![CDATA[This is the standard field for the API Key. Field can be left empty if optional for the chosen provider. Cloudflare "api_token", Duckdns "api_token", DigitalOcean "auth_token", Godaddy "api_token", Gandi "bearer_token", IONOS "api_token", deSEC "token", Route53 "access_key_id", Porkbun "api_key", ACME-DNS "username", Netlify "personal_access_token", Njalla "api_token", Google Cloud DNS "gcp_project", Azure "tenant_id", OVH "endpoint", Namecheap "api_key", PowerDNS "server_url", DDNSS "api_token", Linode "api_token", Tencent Cloud "secret_id", Dinahosting "username", Hexonet "username", Mail-in-a-Box "api_url", DNS Made Easy "api_key", Bunny "access_key", Civo "api_token", Scaleway "secret_key", ACME Proxy "username", INWX "username", Netcup "customer_number", RFC2136 "key_name", Name.com "token", EasyDNS "api_token", Infomaniak "api_token", DirectAdmin "host", Hosttech "api_token", Vultr "api_token", Hetzner "api_token", ClouDNS "auth_id", Gcore "api_token", Huawei Cloud "access_key_id", DNSExit "api_token", Nanelo "api_token", Katapult "api_token", Regfish "api_key", Leaseweb "api_token", DreamHost "api_key", Exoscale "api_key", TransIP "account_name", Selectel "user", LuaDNS "email", Hurricane Electric "api_key", Namesilo "api_token", Dode "api_token", Dynu "api_token", Glesys "project", NFSN "login", GoDaddy "api_token", Vercel "api_token", Loopia "username", DNSPod "api_token", Mythic Beasts "key_id", Dynv6 "api_token", AliDNS "access_key_id", Metaname "api_key"]]></help>
</field>
<field>
<id>caddy.general.TlsDnsSecretApiKey</id>
<label>API Field 2</label>
<type>text</type>
<help><![CDATA[Leave empty if your DNS Provider isn't specified here. Field can be left empty if optional: Duckdns "override_domain", Route53 "secret_access_key", Porkbun "api_secret_key", ACME-DNS "password", Azure "client_id", OVH "application_key", Namecheap "user", PowerDNS "api_token", DDNSS "username", Linode "api_url", Tencent Cloud "secret_key", Dinahosting "password", Hexonet "password", Mail-in-a-Box "email_address", DNS Made Easy "secret_key", Scaleway "organization_id", ACME Proxy "password", INWX "password", Netcup "api_key", RFC2136 "key_alg", Name.com "server", EasyDNS "api_key", DirectAdmin "user", ClouDNS "auth_password".]]></help>
<help><![CDATA[Leave empty if your DNS Provider isn't specified here. Field can be left empty if optional for the chosen provider. Duckdns "override_domain", Route53 "secret_access_key", Porkbun "api_secret_key", ACME-DNS "password", Azure "client_id", OVH "application_key", Namecheap "user", PowerDNS "api_token", DDNSS "username", Linode "api_url", Tencent Cloud "secret_key", Dinahosting "password", Hexonet "password", Mail-in-a-Box "email_address", DNS Made Easy "secret_key", Scaleway "organization_id", ACME Proxy "password", INWX "password", Netcup "api_key", RFC2136 "key_alg", Name.com "server", EasyDNS "api_key", DirectAdmin "user", ClouDNS "auth_password", Huawei Cloud "secret_access_key", Exoscale "api_secret", TransIP "private_key_path", Selectel "password", LuaDNS "api_key", Dynu "own_domain", Glesys "api_key", NFSN "api_key", Loopia "password", Mythic Beasts "secret", AliDNS "access_key_secret", Metaname "account_reference"]]></help>
</field>
<field>
<id>caddy.general.TlsDnsOptionalField1</id>
<label>API Field 3</label>
<type>text</type>
<help><![CDATA[Leave empty if your DNS Provider isn't specified here. Field can be left empty if optional: Route53 "hosted_zone_id", ACME-DNS "subdomain", Azure "client_secret", OVH "application_secret", Namecheap "api_endpoint", DDNSS "password", Linode "api_version", Mail-in-a-Box "password", DNS Made Easy "api_endpoint", ACME Proxy "endpoint", INWX "shared_secret", Netcup "api_password", Name.com "user", EasyDNS "api_url", DirectAdmin "login_key", RFC2136 "key", ClouDNS "sub_auth_id".]]></help>
<help><![CDATA[Leave empty if your DNS Provider isn't specified here. Field can be left empty if optional for the chosen provider. Route53 "hosted_zone_id", ACME-DNS "subdomain", Azure "client_secret", OVH "application_secret", Namecheap "api_endpoint", DDNSS "password", Linode "api_version", Mail-in-a-Box "password", DNS Made Easy "api_endpoint", ACME Proxy "endpoint", INWX "shared_secret", Netcup "api_password", Name.com "user", EasyDNS "api_url", DirectAdmin "login_key", RFC2136 "key", ClouDNS "sub_auth_id", Selectel "account_id"]]></help>
</field>
<field>
<id>caddy.general.TlsDnsOptionalField2</id>
<label>API Field 4</label>
<type>text</type>
<help><![CDATA[Leave empty if your DNS Provider isn't specified here. Field can be left empty if optional: Route53 "profile", ACME-DNS "server_url", Azure "subscription_id", OVH "consumer_key", Namecheap "client_ip", DDNS "password", INWX "endpoint_url", DirectAdmin "insecure_requests", RFC2136 "server".]]></help>
<help><![CDATA[Leave empty if your DNS Provider isn't specified here. Field can be left empty if optional for the chosen provider. Route53 "profile", ACME-DNS "server_url", Azure "subscription_id", OVH "consumer_key", Namecheap "client_ip", DDNS "password", INWX "endpoint_url", DirectAdmin "insecure_requests", RFC2136 "server", Selectel "project_name"]]></help>
</field>
<field>
<id>caddy.general.TlsDnsOptionalField3</id>
<label>API Field 5</label>
<type>text</type>
<help><![CDATA[Leave empty if your DNS Provider isn't specified here. Field can be left empty if optional: Route53 "region", Azure "resource_group_name".]]></help>
<help><![CDATA[Leave empty if your DNS Provider isn't specified here. Field can be left empty if optional for the chosen provider. Route53 "region", Azure "resource_group_name"]]></help>
</field>
<field>
<id>caddy.general.TlsDnsOptionalField4</id>
<label>API Field 6</label>
<type>text</type>
<help><![CDATA[Leave empty if your DNS Provider isn't specified here. Field can be left empty if optional: Route53 "session_token".]]></help>
<help><![CDATA[Leave empty if your DNS Provider isn't specified here. Field can be left empty if optional for the chosen provider. Route53 "session_token"]]></help>
</field>
<field>
<type>header</type>
@@ -262,4 +262,4 @@
</field>
</tab>
<activetab>general-settings</activetab>
</form>
</form>
@@ -62,6 +62,33 @@
<easydns>EasyDNS (optional)</easydns>
<hosttech>Hosttech (optional)</hosttech>
<cloudns>ClouDNS (optional)</cloudns>
<gcore>Gcore (optional)</gcore>
<huaweicloud>Huawei Cloud (optional)</huaweicloud>
<dnsexit>DNSExit (optional)</dnsexit>
<nanelo>Nanelo (optional)</nanelo>
<katapult>Katapult (optional)</katapult>
<regfish>Regfish (optional)</regfish>
<leaseweb>Leaseweb (optional)</leaseweb>
<dreamhost>DreamHost (optional)</dreamhost>
<exoscale>Exoscale (optional)</exoscale>
<transip>TransIP (optional)</transip>
<selectel>Selectel (optional)</selectel>
<dnsimple>DNSimple (optional)</dnsimple>
<luadns>LuaDNS (optional)</luadns>
<he>Hurricane Electric (optional)</he>
<namesilo>Namesilo (optional)</namesilo>
<dode>Dode (optional)</dode>
<dynu>Dynu (optional)</dynu>
<glesys>Glesys (optional)</glesys>
<nfsn>NFSN (optional)</nfsn>
<godaddy>GoDaddy (optional)</godaddy>
<vercel>Vercel (optional)</vercel>
<loopia>Loopia (optional)</loopia>
<dnspod>DNSPod (optional)</dnspod>
<mythicbeasts>Mythic Beasts (optional)</mythicbeasts>
<dynv6>Dynv6 (optional)</dynv6>
<alidns>AliDNS (optional)</alidns>
<metaname>Metaname (optional)</metaname>
</OptionValues>
</TlsDnsProvider>
<TlsDnsApiKey type="TextField"/>
@@ -174,12 +174,8 @@
{% endfor %}
{% endfor %}
{#
# Define special DNS Providers that have more than one API key, or special requirements that do not allow the use of the default.
# The same providers have to be added to "OPNsense/Caddy/includeDnsProvider", best in the same order as in this array for maintainability.
# For a new provider to work, it has to be compiled into the caddy binary.
#}
{% set dnsProviderSpecialConfig = ['duckdns', 'porkbun', 'desec', 'route53', 'acmedns', 'googleclouddns', 'azure', 'ovh', 'namecheap', 'powerdns', 'ddnss', 'linode', 'tencentcloud', 'dinahosting', 'hexonet', 'mailinabox', 'netcup', 'rfc2136', 'dnsmadeeasy', 'civo', 'scaleway', 'acmeproxy', 'inwx', 'namedotcom', 'easydns', 'directadmin', 'cloudns'] %}
{% import "OPNsense/Caddy/includeDnsProvider" as dns_includes %}
{% set dnsProviderSpecialConfig = dns_includes.dnsProviderSpecialConfig() %}
{# Conditionally add the dynamic_dns section, acmedns provider is special, it does not support dynamic_dns. #}
{% if dnsProvider and dynDnsDomains|length > 0 and dnsProvider != "acmedns" %}
@@ -187,6 +183,7 @@
{# duckdns provider is special, it has a different configuration for dynamic dns than for the dns-01 challenge. #}
{% if dnsProvider in dnsProviderSpecialConfig and dnsProvider != "duckdns" %}
provider {{ dnsProvider }} {
{% set context_var = 'dnsProviderSpecialLogic' %}
{% include "OPNsense/Caddy/includeDnsProvider" %}
}
{% else %}
@@ -325,6 +322,7 @@ http://{{ domain }} {
tls {% if customCert %}/var/db/caddy/data/caddy/certificates/temp/{{ customCert }}.pem /var/db/caddy/data/caddy/certificates/temp/{{ customCert }}.key{% endif %} {% if not customCert and dnsChallenge == "1" and dnsProvider %}{
issuer acme {
dns {{ dnsProvider }} {% if dnsProvider not in dnsProviderSpecialConfig %}{{ dnsApiKey }}{% else %}{
{% set context_var = 'dnsProviderSpecialLogic' %}
{% include "OPNsense/Caddy/includeDnsProvider" %}
}
{% endif %}
@@ -6,6 +6,53 @@
# It only includes DNS Providers that need specific settings and do not default to
# "dns {{ dnsProvider }} {{ dnsApiKey }}"
#}
{% macro dnsProviderSpecialConfig() %}
[
'duckdns',
'porkbun',
'desec',
'route53',
'acmedns',
'googleclouddns',
'azure',
'ovh',
'namecheap',
'powerdns',
'ddnss',
'linode',
'tencentcloud',
'dinahosting',
'hexonet',
'mailinabox',
'netcup',
'rfc2136',
'dnsmadeeasy',
'civo',
'scaleway',
'acmeproxy',
'inwx',
'namedotcom',
'easydns',
'directadmin',
'cloudns',
'huaweicloud',
'regfish',
'dreamhost',
'exoscale',
'transip',
'selectel',
'luadns',
'he',
'dynu',
'glesys',
'nfsn',
'loopia',
'mythicbeasts',
'alidns',
'metaname'
]
{% endmacro %}
{% if context_var == 'dnsProviderSpecialLogic' %}
{% if dnsProvider == 'duckdns' %}
{% if dnsApiKey %}api_token {{ dnsApiKey }}
{% endif %}
@@ -190,4 +237,78 @@
{% endif %}
{% if dnsOptionalField1 %}sub_auth_id {{ dnsOptionalField1 }}
{% endif %}
{% elif dnsProvider == 'huaweicloud' %}
{% if dnsApiKey %}access_key_id {{ dnsApiKey }}
{% endif %}
{% if dnsSecretApiKey %}secret_access_key {{ dnsSecretApiKey }}
{% endif %}
{% elif dnsProvider == 'regfish' %}
{% if dnsApiKey %}api_key {{ dnsApiKey }}
{% endif %}
{% elif dnsProvider == 'dreamhost' %}
{% if dnsApiKey %}api_key {{ dnsApiKey }}
{% endif %}
{% elif dnsProvider == 'exoscale' %}
{% if dnsApiKey %}api_key {{ dnsApiKey }}
{% endif %}
{% if dnsSecretApiKey %}api_secret {{ dnsSecretApiKey }}
{% endif %}
{% elif dnsProvider == 'transip' %}
{% if dnsApiKey %}account_name {{ dnsApiKey }}
{% endif %}
{% if dnsSecretApiKey %}private_key_path {{ dnsSecretApiKey }}
{% endif %}
{% elif dnsProvider == 'selectel' %}
{% if dnsApiKey %}user {{ dnsApiKey }}
{% endif %}
{% if dnsSecretApiKey %}password {{ dnsSecretApiKey }}
{% endif %}
{% if dnsOptionalField1 %}account_id {{ dnsOptionalField1 }}
{% endif %}
{% if dnsOptionalField2 %}project_name {{ dnsOptionalField2 }}
{% endif %}
{% elif dnsProvider == 'luadns' %}
{% if dnsApiKey %}email {{ dnsApiKey }}
{% endif %}
{% if dnsSecretApiKey %}api_key {{ dnsSecretApiKey }}
{% endif %}
{% elif dnsProvider == 'he' %}
{% if dnsApiKey %}api_key {{ dnsApiKey }}
{% endif %}
{% elif dnsProvider == 'dynu' %}
{% if dnsApiKey %}api_token {{ dnsApiKey }}
{% endif %}
{% if dnsSecretApiKey %}own_domain {{ dnsSecretApiKey }}
{% endif %}
{% elif dnsProvider == 'glesys' %}
{% if dnsApiKey %}project {{ dnsApiKey }}
{% endif %}
{% if dnsSecretApiKey %}api_key {{ dnsSecretApiKey }}
{% endif %}
{% elif dnsProvider == 'nfsn' %}
{% if dnsApiKey %}login {{ dnsApiKey }}
{% endif %}
{% if dnsSecretApiKey %}api_key {{ dnsSecretApiKey }}
{% endif %}
{% elif dnsProvider == 'loopia' %}
{% if dnsApiKey %}username {{ dnsApiKey }}
{% endif %}
{% if dnsSecretApiKey %}password {{ dnsSecretApiKey }}
{% endif %}
{% elif dnsProvider == 'mythicbeasts' %}
{% if dnsApiKey %}key_id {{ dnsApiKey }}
{% endif %}
{% if dnsSecretApiKey %}secret {{ dnsSecretApiKey }}
{% endif %}
{% elif dnsProvider == 'alidns' %}
{% if dnsApiKey %}access_key_id {{ dnsApiKey }}
{% endif %}
{% if dnsSecretApiKey %}access_key_secret {{ dnsSecretApiKey }}
{% endif %}
{% elif dnsProvider == 'metaname' %}
{% if dnsApiKey %}api_key {{ dnsApiKey }}
{% endif %}
{% if dnsSecretApiKey %}account_reference {{ dnsSecretApiKey }}
{% endif %}
{% endif %}
{% endif %}