2024-01-01 15:31:33 -06:00
|
|
|
/*
|
|
|
|
This will let you edit a single Resource Record within
|
|
|
|
a DNS zone file. For example:
|
|
|
|
google-dns.wit.com. 1 IN A 8.8.8.8
|
|
|
|
*/
|
|
|
|
|
|
|
|
package cloudflare
|
|
|
|
|
2024-01-18 01:33:28 -06:00
|
|
|
import (
|
2024-01-01 15:31:33 -06:00
|
|
|
"os"
|
|
|
|
|
2024-01-21 02:10:00 -06:00
|
|
|
"go.wit.com/gui"
|
2024-01-18 01:33:28 -06:00
|
|
|
"go.wit.com/lib/gadgets"
|
|
|
|
"go.wit.com/log"
|
2024-01-01 15:31:33 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
Config = make(map[string]*ConfigT)
|
|
|
|
}
|
|
|
|
|
2024-01-06 21:04:31 -06:00
|
|
|
func CreateRR(myGui *gui.Node, zone string, zoneID string) *gadgets.BasicWindow {
|
2024-01-18 01:33:28 -06:00
|
|
|
if CFdialog.cloudflareW != nil {
|
2024-01-01 15:31:33 -06:00
|
|
|
// skip this if the window has already been created
|
2024-01-05 19:33:41 -06:00
|
|
|
log.Warn("createRR() the cloudflare window already exists")
|
2024-01-01 15:31:33 -06:00
|
|
|
CFdialog.cloudflareB.Disable()
|
2024-01-06 21:04:31 -06:00
|
|
|
return CFdialog.cloudflareW
|
2024-01-01 15:31:33 -06:00
|
|
|
}
|
2024-01-18 01:33:28 -06:00
|
|
|
CFdialog.cloudflareW = gadgets.NewBasicWindow(myGui, "cloudflare "+zone+" API")
|
2024-01-01 15:31:33 -06:00
|
|
|
|
2024-01-05 09:38:20 -06:00
|
|
|
group := CFdialog.cloudflareW.Box().NewGroup("Create a new DNS Resource Record (rr)")
|
2024-01-01 15:31:33 -06:00
|
|
|
|
|
|
|
// make a grid 2 things wide
|
|
|
|
grid := group.NewGrid("gridnuts", 2, 3)
|
|
|
|
|
|
|
|
grid.NewLabel("zone")
|
|
|
|
CFdialog.zoneNode = grid.NewLabel("zone")
|
|
|
|
CFdialog.zoneNode.SetText(zone)
|
|
|
|
|
|
|
|
grid.NewLabel("zone ID")
|
|
|
|
CFdialog.zoneIdNode = grid.NewLabel("zoneID")
|
|
|
|
CFdialog.zoneIdNode.SetText(zoneID)
|
|
|
|
|
|
|
|
grid.NewLabel("shell env $CF_API_EMAIL")
|
|
|
|
CFdialog.emailNode = grid.NewLabel("type")
|
|
|
|
CFdialog.emailNode.SetText(os.Getenv("CF_API_EMAIL"))
|
|
|
|
|
|
|
|
grid.NewLabel("shell env $CF_API_KEY")
|
|
|
|
CFdialog.apiNode = grid.NewLabel("type")
|
|
|
|
CFdialog.apiNode.SetText(os.Getenv("CF_API_KEY"))
|
|
|
|
|
|
|
|
grid.NewLabel("Resource Record ID")
|
|
|
|
CFdialog.rrNode = grid.NewLabel("type")
|
|
|
|
CFdialog.rrNode.SetText(os.Getenv("cloudflare RR id"))
|
|
|
|
|
|
|
|
grid.NewLabel("Record Type")
|
2024-01-18 01:23:49 -06:00
|
|
|
CFdialog.TypeNode = grid.NewCombobox()
|
2024-01-01 15:31:33 -06:00
|
|
|
CFdialog.TypeNode.AddText("A")
|
|
|
|
CFdialog.TypeNode.AddText("AAAA")
|
|
|
|
CFdialog.TypeNode.AddText("CNAME")
|
|
|
|
CFdialog.TypeNode.AddText("TXT")
|
|
|
|
CFdialog.TypeNode.AddText("MX")
|
|
|
|
CFdialog.TypeNode.AddText("NS")
|
2024-01-18 01:33:28 -06:00
|
|
|
CFdialog.TypeNode.Custom = func() {
|
2024-01-01 15:31:33 -06:00
|
|
|
DoChange()
|
|
|
|
}
|
|
|
|
CFdialog.TypeNode.SetText("AAAA")
|
|
|
|
|
|
|
|
grid.NewLabel("Name (usually the hostname)")
|
2024-01-18 01:23:49 -06:00
|
|
|
CFdialog.NameNode = grid.NewCombobox()
|
2024-01-01 15:31:33 -06:00
|
|
|
CFdialog.NameNode.AddText("www")
|
|
|
|
CFdialog.NameNode.AddText("mail")
|
|
|
|
CFdialog.NameNode.AddText("git")
|
|
|
|
CFdialog.NameNode.AddText("go")
|
|
|
|
CFdialog.NameNode.AddText("blog")
|
|
|
|
CFdialog.NameNode.AddText("ns1")
|
2024-01-18 01:33:28 -06:00
|
|
|
CFdialog.NameNode.Custom = func() {
|
2024-01-01 15:31:33 -06:00
|
|
|
DoChange()
|
|
|
|
}
|
|
|
|
CFdialog.NameNode.SetText("www")
|
|
|
|
|
|
|
|
grid.NewLabel("Cloudflare Proxy")
|
2024-01-18 01:23:49 -06:00
|
|
|
CFdialog.proxyNode = grid.NewDropdown()
|
2024-01-01 15:31:33 -06:00
|
|
|
CFdialog.proxyNode.AddText("On")
|
|
|
|
CFdialog.proxyNode.AddText("Off")
|
2024-01-18 01:33:28 -06:00
|
|
|
CFdialog.proxyNode.Custom = func() {
|
2024-01-01 15:31:33 -06:00
|
|
|
DoChange()
|
|
|
|
}
|
|
|
|
CFdialog.proxyNode.SetText("Off")
|
|
|
|
|
|
|
|
grid.NewLabel("Value")
|
2024-01-18 01:23:49 -06:00
|
|
|
CFdialog.ValueNode = grid.NewCombobox()
|
2024-01-01 15:31:33 -06:00
|
|
|
CFdialog.ValueNode.AddText("127.0.0.1")
|
|
|
|
CFdialog.ValueNode.AddText("2001:4860:4860::8888")
|
|
|
|
CFdialog.ValueNode.AddText("ipv6.wit.com")
|
2024-01-18 01:33:28 -06:00
|
|
|
CFdialog.ValueNode.Custom = func() {
|
2024-01-01 15:31:33 -06:00
|
|
|
DoChange()
|
|
|
|
}
|
|
|
|
CFdialog.ValueNode.SetText("127.0.0.1")
|
|
|
|
CFdialog.ValueNode.Expand()
|
|
|
|
|
|
|
|
grid.NewLabel("URL")
|
|
|
|
CFdialog.urlNode = grid.NewLabel("URL")
|
|
|
|
|
|
|
|
group.NewLabel("curl")
|
|
|
|
CFdialog.curlNode = group.NewTextbox("curl")
|
2024-01-18 01:33:28 -06:00
|
|
|
CFdialog.curlNode.Custom = func() {
|
2024-01-01 15:31:33 -06:00
|
|
|
DoChange()
|
|
|
|
}
|
|
|
|
CFdialog.curlNode.SetText("put the curl text here")
|
|
|
|
|
|
|
|
CFdialog.resultNode = group.NewTextbox("result")
|
|
|
|
CFdialog.resultNode.SetText("API response will show here")
|
|
|
|
|
2024-01-18 01:33:28 -06:00
|
|
|
CFdialog.SaveNode = group.NewButton("Save curlPost()", func() {
|
2024-01-01 15:31:33 -06:00
|
|
|
dnsRow := DoChange()
|
|
|
|
result := curlPost(dnsRow)
|
|
|
|
CFdialog.resultNode.SetText(result)
|
|
|
|
// CreateCurlRR()
|
|
|
|
// url, data := CreateCurlRR()
|
|
|
|
// result := curl(url, data)
|
|
|
|
// CFdialog.resultNode.SetText(result)
|
|
|
|
})
|
|
|
|
// CFdialog.saveNode.Disable()
|
2024-01-18 01:33:28 -06:00
|
|
|
group.NewButton("New RR doCurl(PUT)", func() {
|
2024-01-01 15:31:33 -06:00
|
|
|
rr := DoChange()
|
|
|
|
|
|
|
|
rr.url = "https://api.cloudflare.com/client/v4/zones/" + rr.ZoneID + "/dns_records"
|
|
|
|
|
|
|
|
result := doCurl("POST", rr)
|
|
|
|
CFdialog.resultNode.SetText(result)
|
|
|
|
|
|
|
|
pretty, _ := FormatJSON(result)
|
2024-01-05 19:33:41 -06:00
|
|
|
log.Spew(pretty)
|
2024-01-01 15:31:33 -06:00
|
|
|
})
|
|
|
|
|
2024-01-18 01:33:28 -06:00
|
|
|
group.NewButton("Update RR doCurl(PUT)", func() {
|
2024-01-01 15:31:33 -06:00
|
|
|
rr := DoChange()
|
|
|
|
|
|
|
|
rr.url = "https://api.cloudflare.com/client/v4/zones/" + rr.ZoneID + "/dns_records/" + rr.ID
|
|
|
|
|
|
|
|
result := doCurl("PUT", rr)
|
|
|
|
CFdialog.resultNode.SetText(result)
|
|
|
|
|
|
|
|
pretty, _ := FormatJSON(result)
|
2024-01-05 19:33:41 -06:00
|
|
|
log.Spew(pretty)
|
2024-01-01 15:31:33 -06:00
|
|
|
})
|
|
|
|
// CFdialog.saveNode.Disable()
|
|
|
|
|
|
|
|
group.Pad()
|
|
|
|
grid.Pad()
|
|
|
|
grid.Expand()
|
2024-01-06 21:04:31 -06:00
|
|
|
|
|
|
|
return CFdialog.cloudflareW
|
2024-01-01 15:31:33 -06:00
|
|
|
}
|