Skip to content

Commit 3ee019d

Browse files
committed
Fixing annoying assignment bug
1 parent 44798e0 commit 3ee019d

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

hover-ddns.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,14 @@ func main() {
121121
}
122122

123123
func run(config *Config, provider publicip.LookupProvider, dryRun *bool, manualV4 *string, manualV6 *string) {
124-
publicV4 := net.IP{}
125-
publicV6 := net.IP{}
124+
var publicV4 net.IP
125+
var publicV6 net.IP
126+
var err error
126127

127128
if !config.DisableV4 {
128129
if *manualV4 == "" {
129130
log.Info("Getting public IPv4...")
130-
publicV4, err := provider.GetPublicIP()
131+
publicV4, err = provider.GetPublicIP()
131132

132133
if err != nil {
133134
log.Warn("Failed to get public ip: ", err)
@@ -154,7 +155,7 @@ func run(config *Config, provider publicip.LookupProvider, dryRun *bool, manualV
154155
log.Info("Received current IPv4 " + currentV4.String())
155156
}
156157

157-
if currentV4 != nil && currentV4.Equal(publicV4) {
158+
if currentV4 != nil && publicV4 != nil && currentV4.Equal(publicV4) {
158159
if !config.ForceUpdate {
159160
log.Info("v4 DNS entry already up to date - nothing to do.")
160161
publicV4 = nil
@@ -171,7 +172,7 @@ func run(config *Config, provider publicip.LookupProvider, dryRun *bool, manualV
171172
if !config.DisableV6 {
172173
if *manualV6 == "" {
173174
log.Info("Getting public IPv6...")
174-
publicV6, err := provider.GetPublicIPv6()
175+
publicV6, err = provider.GetPublicIPv6()
175176

176177
if err != nil {
177178
log.Warn("Failed to get public ip: ", err)
@@ -198,7 +199,7 @@ func run(config *Config, provider publicip.LookupProvider, dryRun *bool, manualV
198199
log.Info("Received current IPv6 " + currentV6.String())
199200
}
200201

201-
if currentV6 != nil && currentV6.Equal(publicV6) {
202+
if currentV6 != nil && publicV6 != nil && currentV6.Equal(publicV6) {
202203
if !config.ForceUpdate {
203204
log.Info("v6 DNS entry already up to date - nothing to do.")
204205
publicV6 = nil

hover/hover.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,23 @@ func Update(user string, password string, domainName string, hostName string, ip
6969
log.Info("Found domain ID: " + domainID)
7070

7171
if ip4 != nil {
72-
err = updateSingleRecord(client, sessionCookie, authCookie, domainID, hostName, ip4.String(), "A")
73-
if err != nil {
74-
log.Error("Was not able to update IPv4 record:", err)
72+
if ip4.To4() == nil {
73+
log.Error(fmt.Sprintf("Not updating invalid address '%s'", ip4.String()))
74+
} else {
75+
err = updateSingleRecord(client, sessionCookie, authCookie, domainID, hostName, ip4.String(), "A")
76+
if err != nil {
77+
log.Error("Was not able to update IPv4 record:", err)
78+
}
7579
}
7680
}
7781
if ip6 != nil {
78-
err = updateSingleRecord(client, sessionCookie, authCookie, domainID, hostName, ip6.String(), "AAAA")
79-
if err != nil {
80-
log.Error("Was not able to update IPv6 record:", err)
82+
if ip6.To16() == nil {
83+
log.Error(fmt.Sprintf("Not updating invalid address '%s'", ip4.String()))
84+
} else {
85+
err = updateSingleRecord(client, sessionCookie, authCookie, domainID, hostName, ip6.String(), "AAAA")
86+
if err != nil {
87+
log.Error("Was not able to update IPv6 record:", err)
88+
}
8189
}
8290
}
8391

@@ -103,7 +111,7 @@ func updateSingleRecord(client *http.Client, sessionCookie http.Cookie, authCook
103111
}
104112

105113
// Create new record
106-
log.Info("Creating new record...")
114+
log.Info(fmt.Sprintf("Creating new record of type '%s' and IP '%s'...", recordType, ip))
107115
err = createRecord(client, sessionCookie, authCookie, domainID, hostName, ip, recordType)
108116
if err != nil {
109117
log.Error("Was not able to create new record: ", err)
@@ -148,6 +156,10 @@ func getHoverAuthCookie(client *http.Client, username string, password string) (
148156
req.Header.Set("Content-Type", "application/json")
149157

150158
resp, err = client.Do(req)
159+
if err != nil {
160+
return sessionCookie, authCookie, err
161+
}
162+
defer resp.Body.Close()
151163

152164
if resp.StatusCode != http.StatusOK {
153165
bodyBytes, _ := ioutil.ReadAll(resp.Body)
@@ -278,6 +290,7 @@ func createRecord(client *http.Client, sessionCookie http.Cookie, authCookie htt
278290
}
279291

280292
recordPostURL := "https://www.hover.com/api/domains/" + domainID + "/dns"
293+
log.Debug("Creating record: " + string(jsonStr))
281294

282295
req, err := http.NewRequest("POST", recordPostURL, bytes.NewBuffer(jsonStr))
283296
if err != nil {

0 commit comments

Comments
 (0)