summaryrefslogtreecommitdiff
path: root/cloudflare/http.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2023-12-28 09:43:45 -0600
committerJeff Carr <[email protected]>2023-12-28 09:43:45 -0600
commit6fa6d6dfc9e5a88e7dff2ed3c148b3b4271f566c (patch)
treef08edaac07ddf1a2e8a7401ef32c53707bdf5537 /cloudflare/http.go
parent73b0cee93320bb5b572881cd1a5ba9d878a4ba3a (diff)
Detect that a VPN is needed
IPv6() returns true if it's working display duration a 'DNS Lookup Status' window actual dig results display status and failure counters count lookup failures and successes add TCP dns lookup logic to test if dns is working at all add DNS over HTTPS cloudflare new & update kind of working holy shit, go.wit.com finally works with git mod tidy working, but cloudflare api stuff is broken AAAA '(none)' logic detection is better cloudflare control panel display the working real AAAA addresses Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'cloudflare/http.go')
-rw-r--r--cloudflare/http.go49
1 files changed, 23 insertions, 26 deletions
diff --git a/cloudflare/http.go b/cloudflare/http.go
index f258f61..1917c8b 100644
--- a/cloudflare/http.go
+++ b/cloudflare/http.go
@@ -3,7 +3,6 @@ package cloudflare
import (
"log"
- "fmt"
"io/ioutil"
"net/http"
"bytes"
@@ -27,45 +26,43 @@ curl --request POST \
}'
*/
-func httpPut(dnsRow *RRT) (string, string) {
- var url string = cloudflareURL + dnsRow.ZoneID + "/dns_records/" + dnsRow.ID
- var authKey string = dnsRow.Auth
- var email string = dnsRow.Email
-
- var tmp string
- tmp = makeJSON(dnsRow)
- data := []byte(tmp)
+func doCurl(method string, rr *RRT) string {
+ var err error
+ var req *http.Request
- log.Println("http PUT url =", url)
- // log.Println("http PUT data =", data)
- // spew.Dump(data)
- pretty, _ := FormatJSON(string(data))
- log.Println("http PUT data =", pretty)
+ data := []byte(rr.data)
- req, err := http.NewRequest(http.MethodPut, url, bytes.NewBuffer(data))
+ if (method == "PUT") {
+ req, err = http.NewRequest(http.MethodPut, rr.url, bytes.NewBuffer(data))
+ } else {
+ req, err = http.NewRequest(http.MethodPost, rr.url, bytes.NewBuffer(data))
+ }
// Set headers
req.Header.Set("Content-Type", "application/json")
- req.Header.Set("X-Auth-Key", authKey)
- req.Header.Set("X-Auth-Email", email)
+ req.Header.Set("X-Auth-Key", rr.Auth)
+ req.Header.Set("X-Auth-Email", rr.Email)
+
+ log.Println("http PUT url =", rr.url)
+ log.Println("http PUT Auth =", rr.Auth)
+ log.Println("http PUT Email =", rr.Email)
+ log.Println("http PUT data =", rr.data)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Println(err)
- return tmp, fmt.Sprintf("blah err =", err)
+ return ""
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Println(err)
- return tmp, fmt.Sprintf("blah err =", err)
+ return ""
}
- // log.Println("http PUT body =", body)
- // spew.Dump(body)
- return tmp, string(body)
+ return string(body)
}
func curlPost(dnsRow *RRT) string {
@@ -75,10 +72,10 @@ func curlPost(dnsRow *RRT) string {
url := dnsRow.url
tmp := dnsRow.data
- log.Println("curl() START")
- log.Println("curl() authkey = ", authKey)
- log.Println("curl() email = ", email)
- log.Println("curl() url = ", url)
+ log.Println("curlPost() START")
+ log.Println("curlPost() authkey = ", authKey)
+ log.Println("curlPost() email = ", email)
+ log.Println("curlPost() url = ", url)
data := []byte(tmp)
req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(data))