From 5e7609ea2a5e0c59fb7c64cd210731a665fceb8d Mon Sep 17 00:00:00 2001 From: Lenard Hess Date: Sat, 3 Feb 2024 13:57:09 +0100 Subject: [PATCH 1/3] porkbun: Added 'root-domain' config option Porkbun API requires separation of the root domain and subdomains. Previously ddclient only supported one layer of subdomain or the root domain by selecting between the two with the boolean 'on-root-domain'. This change now allows to specify the root domain via the 'root-domain' parameter ddclient will then split the host domain into root and subdomain --- ddclient.in | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/ddclient.in b/ddclient.in index 5c50d3d..dfe6a7d 100755 --- a/ddclient.in +++ b/ddclient.in @@ -869,6 +869,7 @@ my %services = ( 'variables' => { 'apikey' => setv(T_PASSWD, 1, 0, '', undef), 'secretapikey' => setv(T_PASSWD, 1, 0, '', undef), + 'root-domain' => setv(T_OFQDN, 0, 0, '', undef), 'on-root-domain' => setv(T_BOOL, 0, 0, 0, undef), 'login' => setv(T_LOGIN, 0, 0, 'unused', undef), 'password' => setv(T_PASSWD, 0, 0, 'unused', undef), @@ -7114,6 +7115,7 @@ https://kb.porkbun.com/article/190-getting-started-with-the-porkbun-api Available configuration variables: * apikey (required): API Key of Porkbun API * secretapikey (required): Secret API Key of Porkbun API + * root-domain: The root domain of the specified domain name. * on-root-domain=yes or no (default: no): Indicates whether the specified domain name (FQDN) is an unnamed record (Zone APEX) in a zone. It is useful to specify it as a local variable as shown in the example. @@ -7168,12 +7170,28 @@ sub nic_porkbun_update { my $rrset_type = is_ipv6($ip) ? "AAAA" : "A"; my ($sub_domain, $domain); - if ($config{$host}{'on-root-domain'}) { - $sub_domain = ''; - $domain = $host; - } else { - ($sub_domain, $domain) = split(/\./, $host, 2); + if ($config{$host}{'root-domain'} ne '') { + # Process 'root-domain' option + $domain = $config{$host}{'root-domain'}; + $sub_domain = $host; + $sub_domain =~ s/\.$domain//; + + if (!defined($sub_domain)) { + error("'root-domain' (%s) is not part of the full domain (%s)!", $domain, $host); + next; + } + warning("%s has both 'root-domain' and 'on-root-domain' defined. The latter is ignored") if $config{$host}{'on-root-domain'}; } + else { + # Process legacy 'on-root-domain' option + if ($config{$host}{'on-root-domain'}) { + $sub_domain = ''; + $domain = $host; + } else { + ($sub_domain, $domain) = split(/\./, $host, 2); + } + } + info("setting %s address to %s for %s", $ipv, $ip, $host); verbose("UPDATE:","updating %s", $host); From ae7f92772b664b2f2bb62d842324111e8e0b5ed5 Mon Sep 17 00:00:00 2001 From: Lenard Hess Date: Sat, 3 Feb 2024 16:12:28 +0100 Subject: [PATCH 2/3] porkbun: Updated documentation and config example --- ddclient.conf.in | 3 ++- ddclient.in | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/ddclient.conf.in b/ddclient.conf.in index 756aec3..c4d5172 100644 --- a/ddclient.conf.in +++ b/ddclient.conf.in @@ -301,8 +301,9 @@ ssl=yes # use ssl-support. Works with # protocol=porkbun # apikey=APIKey # secretapikey=SecretAPIKey +# root-domain=example.com # host.example.com,host2.sub.example.com -# on-root-domain=yes example.com,sub.example.com +# example.com,sub.example.com ## ## ClouDNS (https://www.cloudns.net) diff --git a/ddclient.in b/ddclient.in index dfe6a7d..b417b0e 100755 --- a/ddclient.in +++ b/ddclient.in @@ -7119,6 +7119,7 @@ Available configuration variables: * on-root-domain=yes or no (default: no): Indicates whether the specified domain name (FQDN) is an unnamed record (Zone APEX) in a zone. It is useful to specify it as a local variable as shown in the example. + This configuration value is deprecated, use root-domain instead! * usev4, usev6 : These configuration variables can be specified as local variables to override the global settings. It is useful to finely control IPv4 or IPv6 as shown in the example. * use (deprecated) : This parameter is deprecated but can be overridden like the above parameters. @@ -7126,13 +7127,19 @@ Available configuration variables: Limitations: * Multiple same name records (for round robin) are not supported. The same IP address is set for all, creating meaningless extra records. + * If neither root-domain nor on-root-domain are specified, ${program} will split the given + hostname into subdomain and domain on the first dot. + For example: + * sub.example.com -> Subdomain "sub", root domain "example.com" + * sub.foo.example.com -> Subdomain "sub", root domain "foo.example.com" + If both root-domain and on-root-domain are specified, root-domain takes precedence. Example ${program}.conf file entry: protocol=porkbun apikey=APIKey secretapikey=SecretAPIKey - host.example.com,host2.sub.example.com - on-root-domain=yes example.com,sub.example.com + root-domain=example.com + example.com,host.example.com,host2.sub.example.com Additional example to finely control IPv4 or IPv6 : # Example 01 : Global enable both IPv4 and IPv6, and update both records. @@ -7142,6 +7149,7 @@ Additional example to finely control IPv4 or IPv6 : protocol=porkbun apikey=APIKey secretapikey=SecretAPIKey + root-domain=example.com host.example.com,host2.sub.example.com # Example 02 : Global enable only IPv4, and update only IPv6 record. @@ -7150,8 +7158,16 @@ Additional example to finely control IPv4 or IPv6 : protocol=porkbun apikey=APIKey secretapikey=SecretAPIKey + root-domain=example.com usev6=ifv6, ifv6=enp1s0, usev4=disabled ipv6.example.com + # Example 03: Update just a root domain + protocol=porkbun + apikey=APIKey + secretapikey=SecretAPIKey + root-domain=host.example.com + host.example.com + EoEXAMPLE } From 330ddc6bd21bfa2b98cfc5d397a8e93b41befa43 Mon Sep 17 00:00:00 2001 From: Lenard Hess Date: Sat, 3 Feb 2024 16:16:39 +0100 Subject: [PATCH 3/3] porkbun: Moved subdomain processing out of IPv4/6 loop The domain/subdomain processing is the same for IPv4 and IPv6, no need to repeat it --- ddclient.in | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/ddclient.in b/ddclient.in index b417b0e..f88a638 100755 --- a/ddclient.in +++ b/ddclient.in @@ -7178,6 +7178,28 @@ sub nic_porkbun_update { debug("\nnic_porkbun_update -------------------"); foreach my $host (@_) { + my ($sub_domain, $domain); + if ($config{$host}{'root-domain'} ne '') { + # Process 'root-domain' option + $domain = $config{$host}{'root-domain'}; + $sub_domain = $host; + $sub_domain =~ s/\.$domain//; + + if (!defined($sub_domain)) { + error("'root-domain' (%s) is not part of the full domain (%s)!", $domain, $host); + next; + } + warning("%s has both 'root-domain' and 'on-root-domain' defined. The latter is ignored") if $config{$host}{'on-root-domain'}; + } elsif ($config{$host}{'on-root-domain'}) { + # Process legacy 'on-root-domain' option + $sub_domain = ''; + $domain = $host; + } else { + # Default to the subdomain/domain being split at the first dot + ($sub_domain, $domain) = split(/\./, $host, 2); + } + verbose("subdomain %s, root domain %s", $sub_domain, $domain) if $sub_domain != ''; + foreach my $ipv ('ipv4', 'ipv6') { my $ip = delete $config{$host}{"want$ipv"}; if (!$ip) { @@ -7185,29 +7207,6 @@ sub nic_porkbun_update { } my $rrset_type = is_ipv6($ip) ? "AAAA" : "A"; - my ($sub_domain, $domain); - if ($config{$host}{'root-domain'} ne '') { - # Process 'root-domain' option - $domain = $config{$host}{'root-domain'}; - $sub_domain = $host; - $sub_domain =~ s/\.$domain//; - - if (!defined($sub_domain)) { - error("'root-domain' (%s) is not part of the full domain (%s)!", $domain, $host); - next; - } - warning("%s has both 'root-domain' and 'on-root-domain' defined. The latter is ignored") if $config{$host}{'on-root-domain'}; - } - else { - # Process legacy 'on-root-domain' option - if ($config{$host}{'on-root-domain'}) { - $sub_domain = ''; - $domain = $host; - } else { - ($sub_domain, $domain) = split(/\./, $host, 2); - } - } - info("setting %s address to %s for %s", $ipv, $ip, $host); verbose("UPDATE:","updating %s", $host);