Skip to content

Commit abde720

Browse files
authored
Merge pull request #487 from nandogva63/patch-1
Update infomaniak.go
2 parents da449bf + 8dc154e commit abde720

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

pkg/ddns/providers/infomaniak.go

+31-7
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,44 @@ package providers
22

33
import (
44
"fmt"
5+
"io"
6+
"net/http"
7+
"strings"
58
)
69

710
type UpdateInfomaniakRequest struct {
8-
Domain string
9-
Host string
10-
Username string
11-
Password string
12-
UseProviderIP bool
11+
Host string
12+
Username string
13+
Password string
1314
}
1415

1516
func UpdateInfomaniak(request interface{}, ipAddr string) error {
1617
r, ok := request.(*UpdateInfomaniakRequest)
1718
if !ok {
18-
return fmt.Errorf("invalid request type: %T", request)
19+
return fmt.Errorf("invalid request type: %T", r)
20+
}
21+
urlStr := fmt.Sprintf("https://%s:%[email protected]/nic/update?hostname=%s&myip=%s", r.Username, r.Password, r.Host, ipAddr)
22+
req, err := http.NewRequest(http.MethodGet, urlStr, nil)
23+
if err != nil {
24+
return err
25+
}
26+
req.Header.Set("User-Agent", "Plaenkler DDNS-Updater/V0 [email protected]")
27+
resp, err := http.DefaultClient.Do(req)
28+
if err != nil {
29+
return err
30+
}
31+
defer resp.Body.Close()
32+
bytes, err := io.ReadAll(resp.Body)
33+
if err != nil {
34+
return err
35+
}
36+
text := string(bytes)
37+
switch {
38+
case strings.Contains(text, "good"):
39+
return nil
40+
case strings.Contains(text, "nochg"):
41+
return nil
42+
default:
43+
return fmt.Errorf("failed to update DDNS entry: %s", text)
1944
}
20-
return fmt.Errorf("not implemented %s", r.Domain)
2145
}

0 commit comments

Comments
 (0)