From 8fb9173c958821e517a5e6347bd52e6bf6142c33 Mon Sep 17 00:00:00 2001 From: Thomas N <28116938+Twisterado@users.noreply.github.com> Date: Mon, 10 Apr 2023 16:46:52 +0200 Subject: [PATCH] allow setting custom ip service urls --- config/example.yml | 5 +++++ internal/config.go | 2 ++ internal/dns_configurator.go | 2 +- internal/ip.go | 16 ++++------------ 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/config/example.yml b/config/example.yml index 9bbc9a4..78792f6 100644 --- a/config/example.yml +++ b/config/example.yml @@ -14,6 +14,11 @@ IP-CACHE: '/home/user/.cache/dyndns.cache' # To disable the cache set the value to 0. IP-CACHE-TIMEOUT: 3600 +# Services to query for the current IPv4 or IPv6 address. +# The differentiation between IPv4 and IPv6 has to be made by the service. +IPV4-SERVICE: "https://api.ipify.org?format=text" +IPV6-SERVICE: "https://api6.ipify.org?format=text" + DOMAINS: - NAME: 'example.de' # Your domain name without any subdomains. IPV6: true # Whether the 'AAAA' entries of this host should be diff --git a/internal/config.go b/internal/config.go index 1fd930c..f0848c6 100644 --- a/internal/config.go +++ b/internal/config.go @@ -13,6 +13,8 @@ type Config struct { APIPassword string `yaml:"APIPASSWORD"` IPCache string `yaml:"IP-CACHE"` IPCacheTimeout int `yaml:"IP-CACHE-TIMEOUT"` + IPv4Service string `yaml:"IPV4-SERVICE"` + IPv6Service string `yaml:"IPV6-SERVICE"` Domains []Domain `yaml:"DOMAINS"` } diff --git a/internal/dns_configurator.go b/internal/dns_configurator.go index a2268f5..e989a30 100644 --- a/internal/dns_configurator.go +++ b/internal/dns_configurator.go @@ -29,7 +29,7 @@ func NewDNSConfigurator(config *Config, cache *Cache, logger *Logger) *DNSConfig func (dnsc *DNSConfiguratorService) Configure() { dnsc.login() - ipAddresses, err := GetAddrInfo(dnsc.config.IPv4Enabled(), dnsc.config.IPv6Enabled()) + ipAddresses, err := GetAddrInfo(dnsc.config.IPv4Enabled(), dnsc.config.IPv6Enabled(), dnsc.config.IPv4Service, dnsc.config.IPv6Service) if err != nil { dnsc.logger.Error(err) } diff --git a/internal/ip.go b/internal/ip.go index 851f67a..bf950b8 100644 --- a/internal/ip.go +++ b/internal/ip.go @@ -12,11 +12,11 @@ type AddrInfo struct { } // GetAddrInfo retrieves an AddrInfo instance -func GetAddrInfo(ipv4 bool, ipv6 bool) (*AddrInfo, error) { +func GetAddrInfo(ipv4 bool, ipv6 bool, ipv4service string, ipv6service string) (*AddrInfo, error) { adresses := &AddrInfo{} if ipv4 { - address, err := getIPv4() + address, err := getIP(ipv4service) if err != nil { return nil, err } @@ -24,7 +24,7 @@ func GetAddrInfo(ipv4 bool, ipv6 bool) (*AddrInfo, error) { } if ipv6 { - address, err := getIPv6() + address, err := getIP(ipv6service) if err != nil { return nil, err } @@ -35,15 +35,7 @@ func GetAddrInfo(ipv4 bool, ipv6 bool) (*AddrInfo, error) { return adresses, nil } -func getIPv4() (string, error) { - return do("https://api.ipify.org?format=text") -} - -func getIPv6() (string, error) { - return do("https://api6.ipify.org?format=text") -} - -func do(url string) (string, error) { +func getIP(url string) (string, error) { resp, err := http.Get(url) if err != nil { return "", err