Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting custom IP service URLs #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dynamic DNS needs.
* Creation of a DNS record if it doesn't already exist
* Multi host support (nice when you need to update both `@` and `*`)
* IPv6 support
* Allow setting custom IP service

If you need additional features please open up an
[Issue](https://github.com/Hentra/dyndns-netcup-go/issues).
Expand Down
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