Attempt to avoid setting the domain to something that isn't an IP address
This commit is contained in:
parent
720bb3707f
commit
ed4428e846
1 changed files with 21 additions and 14 deletions
|
@ -7,6 +7,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
"net"
|
||||||
|
|
||||||
"git.darkcloud.ca/kevin/name-dyndns/api"
|
"git.darkcloud.ca/kevin/name-dyndns/api"
|
||||||
"git.darkcloud.ca/kevin/name-dyndns/log"
|
"git.darkcloud.ca/kevin/name-dyndns/log"
|
||||||
|
@ -28,24 +29,30 @@ func contains(c api.Config, val string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateDNSRecord(a api.API, domain, recordID string, newRecord api.DNSRecord) error {
|
func updateDNSRecord(a api.API, domain, recordID string, newRecord api.DNSRecord) error {
|
||||||
log.Logger.Printf("Deleting DNS record for %s.\n", newRecord.Name)
|
addr := net.ParseIP(record.Content)
|
||||||
err := a.DeleteDNSRecord(domain, newRecord.RecordID)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Logger.Printf("Creating DNS record for %s: %s\n", newRecord.Name, newRecord)
|
if addr != nil {
|
||||||
|
log.Logger.Printf("Deleting DNS record for %s.\n", newRecord.Name)
|
||||||
|
err := a.DeleteDNSRecord(domain, newRecord.RecordID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Remove the domain from the DNSRecord name.
|
log.Logger.Printf("Creating DNS record for %s: %s\n", newRecord.Name, newRecord)
|
||||||
// This is an unfortunate inconsistency from the API
|
|
||||||
// implementation (returns full name, but only requires host)
|
// Remove the domain from the DNSRecord name.
|
||||||
if newRecord.Name == domain {
|
// This is an unfortunate inconsistency from the API
|
||||||
newRecord.Name = ""
|
// implementation (returns full name, but only requires host)
|
||||||
|
if newRecord.Name == domain {
|
||||||
|
newRecord.Name = ""
|
||||||
|
} else {
|
||||||
|
newRecord.Name = strings.TrimSuffix(newRecord.Name, fmt.Sprintf(".%s", domain))
|
||||||
|
}
|
||||||
|
|
||||||
|
return a.CreateDNSRecord(domain, newRecord)
|
||||||
} else {
|
} else {
|
||||||
newRecord.Name = strings.TrimSuffix(newRecord.Name, fmt.Sprintf(".%s", domain))
|
log.Logger.Printf("Unable to parse IP: %s\n", newRecord)
|
||||||
}
|
}
|
||||||
|
|
||||||
return a.CreateDNSRecord(domain, newRecord)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func runConfig(c api.Config, daemon bool) {
|
func runConfig(c api.Config, daemon bool) {
|
||||||
|
|
Loading…
Reference in a new issue