Skip to content

Commit

Permalink
allow setting custom ip service urls
Browse files Browse the repository at this point in the history
  • Loading branch information
Twisterado committed Apr 10, 2023
1 parent b69a968 commit 8fb9173
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
5 changes: 5 additions & 0 deletions config/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
2 changes: 1 addition & 1 deletion internal/dns_configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
16 changes: 4 additions & 12 deletions internal/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ 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
}
adresses.IPv4 = address
}

if ipv6 {
address, err := getIPv6()
address, err := getIP(ipv6service)
if err != nil {
return nil, err
}
Expand All @@ -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
Expand Down

0 comments on commit 8fb9173

Please sign in to comment.