-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathupdater.go
39 lines (31 loc) · 960 Bytes
/
updater.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"strings"
)
const tunnelUpdateFmt = "https://ipv4.tunnelbroker.net/ipv4_end.php?ipv4b=%s&user_id=%s&pass=%s&tunnel_id=%s"
func tunnelBrokerUpdate(address string) error {
requestURI := fmt.Sprintf(tunnelUpdateFmt, address, *userID, *password, *tunnelID)
log.Printf("Requesting update to tunnel %s config with IP: %s", *tunnelID, address)
res, err := http.Get(requestURI)
if err != nil {
return fmt.Errorf("error requesting tunnel update: %s", err)
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return fmt.Errorf("error reading response body: %s", err)
}
if res.StatusCode != 200 {
return fmt.Errorf("tunnel config update failed: %d %s", res.StatusCode, body)
}
// Check for errors in the body
if strings.Contains(string(body), "ERROR") {
return fmt.Errorf(string(body))
}
log.Printf("successfully updated tunnel config")
return nil
}