@@ -69,15 +69,23 @@ func Update(user string, password string, domainName string, hostName string, ip
69
69
log .Info ("Found domain ID: " + domainID )
70
70
71
71
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
+ }
75
79
}
76
80
}
77
81
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
+ }
81
89
}
82
90
}
83
91
@@ -103,7 +111,7 @@ func updateSingleRecord(client *http.Client, sessionCookie http.Cookie, authCook
103
111
}
104
112
105
113
// 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 ) )
107
115
err = createRecord (client , sessionCookie , authCookie , domainID , hostName , ip , recordType )
108
116
if err != nil {
109
117
log .Error ("Was not able to create new record: " , err )
@@ -148,6 +156,10 @@ func getHoverAuthCookie(client *http.Client, username string, password string) (
148
156
req .Header .Set ("Content-Type" , "application/json" )
149
157
150
158
resp , err = client .Do (req )
159
+ if err != nil {
160
+ return sessionCookie , authCookie , err
161
+ }
162
+ defer resp .Body .Close ()
151
163
152
164
if resp .StatusCode != http .StatusOK {
153
165
bodyBytes , _ := ioutil .ReadAll (resp .Body )
@@ -278,6 +290,7 @@ func createRecord(client *http.Client, sessionCookie http.Cookie, authCookie htt
278
290
}
279
291
280
292
recordPostURL := "https://www.hover.com/api/domains/" + domainID + "/dns"
293
+ log .Debug ("Creating record: " + string (jsonStr ))
281
294
282
295
req , err := http .NewRequest ("POST" , recordPostURL , bytes .NewBuffer (jsonStr ))
283
296
if err != nil {
0 commit comments