fix paths

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-18 01:33:28 -06:00
parent 586494505b
commit f0b712faf8
11 changed files with 152 additions and 152 deletions

58
api.go
View File

@ -1,7 +1,7 @@
// This is a simple example // This is a simple example
package cloudflare package cloudflare
import ( import (
"encoding/json" "encoding/json"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
@ -10,20 +10,20 @@ import (
) )
/* /*
This function should run each time This function should run each time
the user chanegs anything in the GUi the user chanegs anything in the GUi
or each time something in general changes or each time something in general changes
It returns a RR record which then can be It returns a RR record which then can be
turned into JSON and sent via http turned into JSON and sent via http
to cloudflare's API to cloudflare's API
*/ */
func DoChange() *RRT { func DoChange() *RRT {
var dnsRow *RRT var dnsRow *RRT
dnsRow = new(RRT) dnsRow = new(RRT)
log.Log(INFO, "DoChange() START") log.Log(INFO, "DoChange() START")
if (CFdialog.proxyNode.String() == "On") { if CFdialog.proxyNode.String() == "On" {
dnsRow.Proxied = true dnsRow.Proxied = true
} else { } else {
dnsRow.Proxied = false dnsRow.Proxied = false
@ -44,7 +44,7 @@ func DoChange() *RRT {
// show the JSON // show the JSON
log.Log(INFO, dnsRow) log.Log(INFO, dnsRow)
if (CFdialog.curlNode != nil) { if CFdialog.curlNode != nil {
pretty, _ := FormatJSON(dnsRow.data) pretty, _ := FormatJSON(dnsRow.data)
log.Log(INFO, "http PUT curl =", pretty) log.Log(INFO, "http PUT curl =", pretty)
CFdialog.curlNode.SetText(pretty) CFdialog.curlNode.SetText(pretty)
@ -54,36 +54,36 @@ func DoChange() *RRT {
func SetRow(dnsRow *RRT) { func SetRow(dnsRow *RRT) {
log.Log(INFO, "Look for changes in row", dnsRow.ID) log.Log(INFO, "Look for changes in row", dnsRow.ID)
if (CFdialog.proxyNode != nil) { if CFdialog.proxyNode != nil {
log.Log(INFO, "Proxy", dnsRow.Proxied, "vs", CFdialog.proxyNode.String()) log.Log(INFO, "Proxy", dnsRow.Proxied, "vs", CFdialog.proxyNode.String())
if (dnsRow.Proxied == true) { if dnsRow.Proxied == true {
CFdialog.proxyNode.SetText("On") CFdialog.proxyNode.SetText("On")
} else { } else {
CFdialog.proxyNode.SetText("Off") CFdialog.proxyNode.SetText("Off")
} }
} }
if (CFdialog.zoneNode != nil) { if CFdialog.zoneNode != nil {
CFdialog.zoneNode.SetText(dnsRow.Domain) CFdialog.zoneNode.SetText(dnsRow.Domain)
} }
if (CFdialog.zoneIdNode != nil) { if CFdialog.zoneIdNode != nil {
CFdialog.zoneIdNode.SetText(dnsRow.ZoneID) CFdialog.zoneIdNode.SetText(dnsRow.ZoneID)
} }
log.Log(INFO, "zoneIdNode =", dnsRow.ZoneID) log.Log(INFO, "zoneIdNode =", dnsRow.ZoneID)
if (CFdialog.rrNode != nil) { if CFdialog.rrNode != nil {
CFdialog.rrNode.SetText(dnsRow.ID) CFdialog.rrNode.SetText(dnsRow.ID)
} }
if (CFdialog.ValueNode != nil) { if CFdialog.ValueNode != nil {
log.Log(INFO, "Content", dnsRow.Content, "vs", CFdialog.ValueNode.String()) log.Log(INFO, "Content", dnsRow.Content, "vs", CFdialog.ValueNode.String())
CFdialog.ValueNode.SetText(dnsRow.Content) CFdialog.ValueNode.SetText(dnsRow.Content)
} }
if (CFdialog.NameNode != nil) { if CFdialog.NameNode != nil {
CFdialog.NameNode.SetText(dnsRow.Name) CFdialog.NameNode.SetText(dnsRow.Name)
} }
if (CFdialog.TypeNode != nil) { if CFdialog.TypeNode != nil {
CFdialog.TypeNode.SetText(dnsRow.Type) CFdialog.TypeNode.SetText(dnsRow.Type)
} }
if (CFdialog.urlNode != nil) { if CFdialog.urlNode != nil {
url := cloudflareURL + dnsRow.ZoneID + "/dns_records/" + dnsRow.ID url := cloudflareURL + dnsRow.ZoneID + "/dns_records/" + dnsRow.ID
CFdialog.urlNode.SetText(url) CFdialog.urlNode.SetText(url)
} }
@ -91,7 +91,7 @@ func SetRow(dnsRow *RRT) {
// show the JSON // show the JSON
tmp := makeJSON(dnsRow) tmp := makeJSON(dnsRow)
log.Spew(tmp) log.Spew(tmp)
if (CFdialog.curlNode != nil) { if CFdialog.curlNode != nil {
pretty, _ := FormatJSON(tmp) pretty, _ := FormatJSON(tmp)
log.Spew("http PUT curl =", pretty) log.Spew("http PUT curl =", pretty)
CFdialog.curlNode.SetText(pretty) CFdialog.curlNode.SetText(pretty)
@ -108,7 +108,7 @@ func GetZonefile(c *ConfigT) *DNSRecords {
} }
// Set headers // Set headers
req.Header.Set("Authorization", "Bearer " + c.Auth) req.Header.Set("Authorization", "Bearer "+c.Auth)
// req.Header.Set("X-Auth-Key", c.Auth) // req.Header.Set("X-Auth-Key", c.Auth)
// req.Header.Set("X-Auth-Email", c.Email) // req.Header.Set("X-Auth-Email", c.Email)
@ -147,14 +147,14 @@ func GetZonefile(c *ConfigT) *DNSRecords {
} }
/* /*
pass in a DNS Resource Records (the stuff in a zonefile) pass in a DNS Resource Records (the stuff in a zonefile)
This will talk to the cloudflare API and generate a resource record in the zonefile: This will talk to the cloudflare API and generate a resource record in the zonefile:
For example: For example:
gitea.wit.com. 3600 IN CNAME git.wit.com. gitea.wit.com. 3600 IN CNAME git.wit.com.
go.wit.com. 3600 IN A 1.1.1.9 go.wit.com. 3600 IN A 1.1.1.9
test.wit.com. 3600 IN NS ns1.wit.com. test.wit.com. 3600 IN NS ns1.wit.com.
*/ */
func makeJSON(dnsRow *RRT) string { func makeJSON(dnsRow *RRT) string {
// make a json record to send on port 80 to cloudflare // make a json record to send on port 80 to cloudflare
@ -162,9 +162,9 @@ func makeJSON(dnsRow *RRT) string {
tmp = `{"content": "` + dnsRow.Content + `", ` tmp = `{"content": "` + dnsRow.Content + `", `
tmp += `"name": "` + dnsRow.Name + `", ` tmp += `"name": "` + dnsRow.Name + `", `
tmp += `"type": "` + dnsRow.Type + `", ` tmp += `"type": "` + dnsRow.Type + `", `
tmp+= `"ttl": "` + "1" + `", ` tmp += `"ttl": "` + "1" + `", `
tmp += `"comment": "WIT DNS Control Panel"` tmp += `"comment": "WIT DNS Control Panel"`
tmp += `}` tmp += `}`
return tmp return tmp
} }
@ -180,7 +180,7 @@ func GetZones(auth, email string) *DNSRecords {
} }
// Set headers // Set headers
req.Header.Set("Authorization", "Bearer " + auth) req.Header.Set("Authorization", "Bearer "+auth)
// req.Header.Set("X-Auth-Key", auth) // req.Header.Set("X-Auth-Key", auth)
// req.Header.Set("X-Auth-Email", email) // req.Header.Set("X-Auth-Email", email)

View File

@ -18,11 +18,11 @@ func init() {
full := "go.wit.com/gui/cloudflare" full := "go.wit.com/gui/cloudflare"
short := "cfgui" short := "cfgui"
NOW = log.NewFlag( "NOW", true, full, short, "temp debugging stuff") NOW = log.NewFlag("NOW", true, full, short, "temp debugging stuff")
INFO = log.NewFlag("INFO", false, full, short, "general info") INFO = log.NewFlag("INFO", false, full, short, "general info")
WARN = log.NewFlag("WARN", true, full, short, "bad things") WARN = log.NewFlag("WARN", true, full, short, "bad things")
SPEW = log.NewFlag("SPEW", false, full, short, "spew stuff") SPEW = log.NewFlag("SPEW", false, full, short, "spew stuff")
CURL = log.NewFlag("CURL", true, full, short, "curl interactions") CURL = log.NewFlag("CURL", true, full, short, "curl interactions")
ZONE = log.NewFlag("ZONE", false, full, short, "zone details") ZONE = log.NewFlag("ZONE", false, full, short, "zone details")
} }

View File

@ -6,7 +6,7 @@
package cloudflare package cloudflare
import ( import (
"os" "os"
"go.wit.com/log" "go.wit.com/log"
@ -17,11 +17,11 @@ func Create(zone string, hostname string, value string) bool {
key := os.Getenv("CF_API_KEY") key := os.Getenv("CF_API_KEY")
email := os.Getenv("CF_API_EMAIL") email := os.Getenv("CF_API_EMAIL")
if (key == "") { if key == "" {
log.Warn("cloudflare.Create() MISSING environment variable CF_API_KEY") log.Warn("cloudflare.Create() MISSING environment variable CF_API_KEY")
return false return false
} }
if (email == "") { if email == "" {
log.Warn("cloudflare.Create() MISSING environment variable CF_API_EMAIL") log.Warn("cloudflare.Create() MISSING environment variable CF_API_EMAIL")
return false return false
} }
@ -30,12 +30,12 @@ func Create(zone string, hostname string, value string) bool {
var z *ConfigT var z *ConfigT
for d, v := range Config { for d, v := range Config {
log.Log(INFO, "cloudflare.Create() zone =", d, "value =", v) log.Log(INFO, "cloudflare.Create() zone =", d, "value =", v)
if (zone == d) { if zone == d {
z = Config[zone] z = Config[zone]
log.Log(INFO, "cloudflare.Create() FOUND ZONE", zone, "ID =", z.ZoneID) log.Log(INFO, "cloudflare.Create() FOUND ZONE", zone, "ID =", z.ZoneID)
} }
} }
if (z == nil) { if z == nil {
log.Warn("cloudflare.Create() COULD NOT FIND ZONE", zone) log.Warn("cloudflare.Create() COULD NOT FIND ZONE", zone)
return false return false
} }
@ -48,7 +48,7 @@ func Create(zone string, hostname string, value string) bool {
data += `"type": "AAAA", ` data += `"type": "AAAA", `
data += `"ttl": "1", ` data += `"ttl": "1", `
data += `"comment": "WIT DNS Control Panel"` data += `"comment": "WIT DNS Control Panel"`
data += `}` data += `}`
result := doCurlCreate(key, email, z.ZoneID, data) result := doCurlCreate(key, email, z.ZoneID, data)
pretty, _ := FormatJSON(result) pretty, _ := FormatJSON(result)

View File

@ -6,9 +6,9 @@
package cloudflare package cloudflare
import ( import (
"os"
"go.wit.com/log" "go.wit.com/log"
"os"
) )
func Delete(zone string, hostname string, value string) (bool, string) { func Delete(zone string, hostname string, value string) (bool, string) {
@ -16,11 +16,11 @@ func Delete(zone string, hostname string, value string) (bool, string) {
key := os.Getenv("CF_API_KEY") key := os.Getenv("CF_API_KEY")
email := os.Getenv("CF_API_EMAIL") email := os.Getenv("CF_API_EMAIL")
if (key == "") { if key == "" {
log.Log(WARN, "Delete() MISSING environment variable CF_API_KEY") log.Log(WARN, "Delete() MISSING environment variable CF_API_KEY")
return false, "" return false, ""
} }
if (email == "") { if email == "" {
log.Log(WARN, "Delete() MISSING environment variable CF_API_EMAIL") log.Log(WARN, "Delete() MISSING environment variable CF_API_EMAIL")
return false, "" return false, ""
} }
@ -29,12 +29,12 @@ func Delete(zone string, hostname string, value string) (bool, string) {
var z *ConfigT var z *ConfigT
for d, v := range Config { for d, v := range Config {
log.Log(INFO, "Delete() zone =", d, "value =", v) log.Log(INFO, "Delete() zone =", d, "value =", v)
if (zone == d) { if zone == d {
z = Config[zone] z = Config[zone]
log.Log(INFO, "Delete() FOUND ZONE", zone, "ID =", z.ZoneID) log.Log(INFO, "Delete() FOUND ZONE", zone, "ID =", z.ZoneID)
} }
} }
if (z == nil) { if z == nil {
log.Log(WARN, "Delete() COULD NOT FIND ZONE", zone) log.Log(WARN, "Delete() COULD NOT FIND ZONE", zone)
return false, "" return false, ""
} }
@ -42,10 +42,10 @@ func Delete(zone string, hostname string, value string) (bool, string) {
records := GetZonefile(z) records := GetZonefile(z)
for i, record := range records.Result { for i, record := range records.Result {
if (record.Name == hostname) { if record.Name == hostname {
log.Log(INFO, "Delete() FOUND hostname:", i, record.ID, record.Type, record.Name, record.Content) log.Log(INFO, "Delete() FOUND hostname:", i, record.ID, record.Type, record.Name, record.Content)
} }
if (record.Content == value) { if record.Content == value {
log.Log(INFO, "Delete() FOUND CONTENT:", i, record.ID, record.Type, record.Name, record.Content) log.Log(INFO, "Delete() FOUND CONTENT:", i, record.ID, record.Type, record.Name, record.Content)
log.Log(INFO, "Delete() DO THE ACTUAL cloudflare DELETE here") log.Log(INFO, "Delete() DO THE ACTUAL cloudflare DELETE here")
result := doCurlDelete(key, email, z.ZoneID, record.ID) result := doCurlDelete(key, email, z.ZoneID, record.ID)

16
http.go
View File

@ -1,10 +1,10 @@
// This is a simple example // This is a simple example
package cloudflare package cloudflare
import ( import (
"bytes"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"bytes"
"go.wit.com/log" "go.wit.com/log"
) )
@ -49,7 +49,7 @@ func doCurlDelete(auth string, email string, zoneId string, rrId string) string
// Set headers // Set headers
req.Header.Set("Content-Type", "application/json") req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer " + auth) req.Header.Set("Authorization", "Bearer "+auth)
// changed from this 2024-01-05 // changed from this 2024-01-05
// req.Header.Set("X-Auth-Key", auth) // req.Header.Set("X-Auth-Key", auth)
// req.Header.Set("X-Auth-Email", email) // req.Header.Set("X-Auth-Email", email)
@ -87,11 +87,11 @@ func doCurlCreate(auth string, email string, zoneId string, data string) string
log.Log(CURL, "doCurlCreate() POST Email =", email) log.Log(CURL, "doCurlCreate() POST Email =", email)
log.Log(CURL, "doCurlCreate() POST data =", data) log.Log(CURL, "doCurlCreate() POST data =", data)
req, err = http.NewRequest(http.MethodPost, url, bytes.NewBuffer( []byte(data) )) req, err = http.NewRequest(http.MethodPost, url, bytes.NewBuffer([]byte(data)))
// Set headers // Set headers
req.Header.Set("Content-Type", "application/json") req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer " + auth) req.Header.Set("Authorization", "Bearer "+auth)
client := &http.Client{} client := &http.Client{}
resp, err := client.Do(req) resp, err := client.Do(req)
@ -118,7 +118,7 @@ func doCurl(method string, rr *RRT) string {
data := []byte(rr.data) data := []byte(rr.data)
if (method == "PUT") { if method == "PUT" {
req, err = http.NewRequest(http.MethodPut, rr.url, bytes.NewBuffer(data)) req, err = http.NewRequest(http.MethodPut, rr.url, bytes.NewBuffer(data))
} else { } else {
req, err = http.NewRequest(http.MethodPost, rr.url, bytes.NewBuffer(data)) req, err = http.NewRequest(http.MethodPost, rr.url, bytes.NewBuffer(data))
@ -126,7 +126,7 @@ func doCurl(method string, rr *RRT) string {
// Set headers // Set headers
req.Header.Set("Content-Type", "application/json") req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer " + rr.Auth) req.Header.Set("Authorization", "Bearer "+rr.Auth)
log.Log(CURL, "http PUT url =", rr.url) log.Log(CURL, "http PUT url =", rr.url)
log.Log(CURL, "http PUT Auth =", rr.Auth) log.Log(CURL, "http PUT Auth =", rr.Auth)
@ -166,7 +166,7 @@ func curlPost(dnsRow *RRT) string {
// Set headers // Set headers
req.Header.Set("Content-Type", "application/json") req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer " + authKey) req.Header.Set("Authorization", "Bearer "+authKey)
client := &http.Client{} client := &http.Client{}
resp, err := client.Do(req) resp, err := client.Do(req)

View File

@ -1,7 +1,7 @@
// This is a simple example // This is a simple example
package cloudflare package cloudflare
import ( import (
"encoding/json" "encoding/json"
) )

View File

@ -1,12 +1,12 @@
// This is a simple example // This is a simple example
package cloudflare package cloudflare
import ( import (
"strconv" "strconv"
"go.wit.com/log"
"go.wit.com/gui/gui" "go.wit.com/gui/gui"
"go.wit.com/gui/gadgets" "go.wit.com/lib/gadgets"
"go.wit.com/log"
) )
func LoadZoneWindow(n *gui.Node, c *ConfigT) { func LoadZoneWindow(n *gui.Node, c *ConfigT) {
@ -20,9 +20,9 @@ func LoadZoneWindow(n *gui.Node, c *ConfigT) {
// make a grid 6 things wide // make a grid 6 things wide
grid := newg.NewGrid("gridnuts", 6, 1) grid := newg.NewGrid("gridnuts", 6, 1)
// grid.NewButton("Type", func () { // grid.NewButton("Type", func () {
// log.Log(INFO, "sort by Type") // log.Log(INFO, "sort by Type")
// }) // })
grid.NewLabel("RR type") grid.NewLabel("RR type")
grid.NewLabel("hostname") grid.NewLabel("hostname")
@ -54,14 +54,14 @@ func LoadZoneWindow(n *gui.Node, c *ConfigT) {
grid.NewLabel(record.Name) grid.NewLabel(record.Name)
proxy := grid.NewLabel("proxy") proxy := grid.NewLabel("proxy")
if (record.Proxied) { if record.Proxied {
proxy.SetText("On") proxy.SetText("On")
} else { } else {
proxy.SetText("Off") proxy.SetText("Off")
} }
var ttl string var ttl string
if (record.TTL == 1) { if record.TTL == 1 {
ttl = "Auto" ttl = "Auto"
} else { } else {
ttl = strconv.Itoa(record.TTL) ttl = strconv.Itoa(record.TTL)
@ -72,15 +72,15 @@ func LoadZoneWindow(n *gui.Node, c *ConfigT) {
val.SetText(record.Content) val.SetText(record.Content)
load := grid.NewButton("Load", nil) load := grid.NewButton("Load", nil)
load.Custom = func () { load.Custom = func() {
name := "save stuff to cloudflare for " + rr.ID name := "save stuff to cloudflare for " + rr.ID
log.Log(INFO, name) log.Log(INFO, name)
/* /*
rr.Domain = domainWidget.S rr.Domain = domainWidget.S
rr.ZoneID = zoneWidget.S rr.ZoneID = zoneWidget.S
rr.Auth = authWidget.S rr.Auth = authWidget.S
rr.Email = emailWidget.S rr.Email = emailWidget.S
*/ */
SetRow(&rr) SetRow(&rr)

View File

@ -1,12 +1,12 @@
// This is a simple example // This is a simple example
package cloudflare package cloudflare
import ( import (
"os" "os"
"go.wit.com/log"
"go.wit.com/gui/gui" "go.wit.com/gui/gui"
"go.wit.com/gui/gadgets" "go.wit.com/lib/gadgets"
"go.wit.com/log"
) )
// This creates a window // This creates a window
@ -15,13 +15,13 @@ func MakeCloudflareWindow(n *gui.Node) *gadgets.BasicWindow {
log.Log(INFO, "buttonWindow() START") log.Log(INFO, "buttonWindow() START")
CFdialog.mainWindow = gadgets.NewBasicWindow(n,"Cloudflare Config") CFdialog.mainWindow = gadgets.NewBasicWindow(n, "Cloudflare Config")
CFdialog.mainWindow.Vertical() CFdialog.mainWindow.Vertical()
// this tab has the master cloudflare API credentials // this tab has the master cloudflare API credentials
makeConfigWindow(CFdialog.mainWindow.Box()) makeConfigWindow(CFdialog.mainWindow.Box())
win := gadgets.NewBasicWindow(n,"Zones") win := gadgets.NewBasicWindow(n, "Zones")
g1 := win.Box().NewGroup("zones") g1 := win.Box().NewGroup("zones")
// make dropdown list of zones // make dropdown list of zones
@ -32,10 +32,10 @@ func MakeCloudflareWindow(n *gui.Node) *gadgets.BasicWindow {
} }
CFdialog.zonedrop.AddText("stablesid.org") CFdialog.zonedrop.AddText("stablesid.org")
CFdialog.zonedrop.Custom = func () { CFdialog.zonedrop.Custom = func() {
domain := CFdialog.zonedrop.String() domain := CFdialog.zonedrop.String()
log.Log(ZONE, "custom dropdown() zone (domain name) =", CFdialog.zonedrop.String(), domain) log.Log(ZONE, "custom dropdown() zone (domain name) =", CFdialog.zonedrop.String(), domain)
if (Config[domain] == nil) { if Config[domain] == nil {
log.Log(ZONE, "custom dropdown() Config[domain] = nil for domain =", domain) log.Log(ZONE, "custom dropdown() Config[domain] = nil for domain =", domain)
CFdialog.domainWidget.SetText(domain) CFdialog.domainWidget.SetText(domain)
CFdialog.zoneWidget.SetText("") CFdialog.zoneWidget.SetText("")
@ -81,7 +81,7 @@ func makeConfigWindow(vb *gui.Node) {
grid.Pad() grid.Pad()
vb.NewButton("Lookup Hostname", func () { vb.NewButton("Lookup Hostname", func() {
log.Log(INFO, "Find all the Resource Records for hostname:", hostname.String()) log.Log(INFO, "Find all the Resource Records for hostname:", hostname.String())
log.Log(INFO, "Find all the Resource Records for zone:", zone.String()) log.Log(INFO, "Find all the Resource Records for zone:", zone.String())
GetZones(aw.String(), ew.String()) GetZones(aw.String(), ew.String())
@ -90,7 +90,7 @@ func makeConfigWindow(vb *gui.Node) {
} }
}) })
vb.NewButton("getZones()", func () { vb.NewButton("getZones()", func() {
log.Log(ZONE, "getZones()") log.Log(ZONE, "getZones()")
GetZones(aw.String(), ew.String()) GetZones(aw.String(), ew.String())
for d, _ := range Config { for d, _ := range Config {
@ -98,7 +98,7 @@ func makeConfigWindow(vb *gui.Node) {
} }
}) })
vb.NewButton("cloudflare wit.com", func () { vb.NewButton("cloudflare wit.com", func() {
CreateRR(CFdialog.rootGui, "wit.com", "3777302ac4a78cd7fa4f6d3f72086d06") CreateRR(CFdialog.rootGui, "wit.com", "3777302ac4a78cd7fa4f6d3f72086d06")
}) })
@ -130,7 +130,7 @@ func showCloudflareCredentials(box *gui.Node) {
grid.Pad() grid.Pad()
CFdialog.loadButton = box.NewButton("Load Cloudflare DNS zonefile", func () { CFdialog.loadButton = box.NewButton("Load Cloudflare DNS zonefile", func() {
var domain ConfigT var domain ConfigT
domain.Domain = CFdialog.domainWidget.String() domain.Domain = CFdialog.domainWidget.String()
domain.ZoneID = CFdialog.zoneWidget.String() domain.ZoneID = CFdialog.zoneWidget.String()

26
rr.go
View File

@ -6,12 +6,12 @@
package cloudflare package cloudflare
import ( import (
"os" "os"
"go.wit.com/log"
"go.wit.com/gui/gui" "go.wit.com/gui/gui"
"go.wit.com/gui/gadgets" "go.wit.com/lib/gadgets"
"go.wit.com/log"
) )
func init() { func init() {
@ -19,13 +19,13 @@ func init() {
} }
func CreateRR(myGui *gui.Node, zone string, zoneID string) *gadgets.BasicWindow { func CreateRR(myGui *gui.Node, zone string, zoneID string) *gadgets.BasicWindow {
if (CFdialog.cloudflareW != nil) { if CFdialog.cloudflareW != nil {
// skip this if the window has already been created // skip this if the window has already been created
log.Warn("createRR() the cloudflare window already exists") log.Warn("createRR() the cloudflare window already exists")
CFdialog.cloudflareB.Disable() CFdialog.cloudflareB.Disable()
return CFdialog.cloudflareW return CFdialog.cloudflareW
} }
CFdialog.cloudflareW = gadgets.NewBasicWindow(myGui, "cloudflare " + zone + " API") CFdialog.cloudflareW = gadgets.NewBasicWindow(myGui, "cloudflare "+zone+" API")
group := CFdialog.cloudflareW.Box().NewGroup("Create a new DNS Resource Record (rr)") group := CFdialog.cloudflareW.Box().NewGroup("Create a new DNS Resource Record (rr)")
@ -60,7 +60,7 @@ func CreateRR(myGui *gui.Node, zone string, zoneID string) *gadgets.BasicWindow
CFdialog.TypeNode.AddText("TXT") CFdialog.TypeNode.AddText("TXT")
CFdialog.TypeNode.AddText("MX") CFdialog.TypeNode.AddText("MX")
CFdialog.TypeNode.AddText("NS") CFdialog.TypeNode.AddText("NS")
CFdialog.TypeNode.Custom = func () { CFdialog.TypeNode.Custom = func() {
DoChange() DoChange()
} }
CFdialog.TypeNode.SetText("AAAA") CFdialog.TypeNode.SetText("AAAA")
@ -73,7 +73,7 @@ func CreateRR(myGui *gui.Node, zone string, zoneID string) *gadgets.BasicWindow
CFdialog.NameNode.AddText("go") CFdialog.NameNode.AddText("go")
CFdialog.NameNode.AddText("blog") CFdialog.NameNode.AddText("blog")
CFdialog.NameNode.AddText("ns1") CFdialog.NameNode.AddText("ns1")
CFdialog.NameNode.Custom = func () { CFdialog.NameNode.Custom = func() {
DoChange() DoChange()
} }
CFdialog.NameNode.SetText("www") CFdialog.NameNode.SetText("www")
@ -82,7 +82,7 @@ func CreateRR(myGui *gui.Node, zone string, zoneID string) *gadgets.BasicWindow
CFdialog.proxyNode = grid.NewDropdown() CFdialog.proxyNode = grid.NewDropdown()
CFdialog.proxyNode.AddText("On") CFdialog.proxyNode.AddText("On")
CFdialog.proxyNode.AddText("Off") CFdialog.proxyNode.AddText("Off")
CFdialog.proxyNode.Custom = func () { CFdialog.proxyNode.Custom = func() {
DoChange() DoChange()
} }
CFdialog.proxyNode.SetText("Off") CFdialog.proxyNode.SetText("Off")
@ -92,7 +92,7 @@ func CreateRR(myGui *gui.Node, zone string, zoneID string) *gadgets.BasicWindow
CFdialog.ValueNode.AddText("127.0.0.1") CFdialog.ValueNode.AddText("127.0.0.1")
CFdialog.ValueNode.AddText("2001:4860:4860::8888") CFdialog.ValueNode.AddText("2001:4860:4860::8888")
CFdialog.ValueNode.AddText("ipv6.wit.com") CFdialog.ValueNode.AddText("ipv6.wit.com")
CFdialog.ValueNode.Custom = func () { CFdialog.ValueNode.Custom = func() {
DoChange() DoChange()
} }
CFdialog.ValueNode.SetText("127.0.0.1") CFdialog.ValueNode.SetText("127.0.0.1")
@ -103,7 +103,7 @@ func CreateRR(myGui *gui.Node, zone string, zoneID string) *gadgets.BasicWindow
group.NewLabel("curl") group.NewLabel("curl")
CFdialog.curlNode = group.NewTextbox("curl") CFdialog.curlNode = group.NewTextbox("curl")
CFdialog.curlNode.Custom = func () { CFdialog.curlNode.Custom = func() {
DoChange() DoChange()
} }
CFdialog.curlNode.SetText("put the curl text here") CFdialog.curlNode.SetText("put the curl text here")
@ -111,7 +111,7 @@ func CreateRR(myGui *gui.Node, zone string, zoneID string) *gadgets.BasicWindow
CFdialog.resultNode = group.NewTextbox("result") CFdialog.resultNode = group.NewTextbox("result")
CFdialog.resultNode.SetText("API response will show here") CFdialog.resultNode.SetText("API response will show here")
CFdialog.SaveNode = group.NewButton("Save curlPost()", func () { CFdialog.SaveNode = group.NewButton("Save curlPost()", func() {
dnsRow := DoChange() dnsRow := DoChange()
result := curlPost(dnsRow) result := curlPost(dnsRow)
CFdialog.resultNode.SetText(result) CFdialog.resultNode.SetText(result)
@ -121,7 +121,7 @@ func CreateRR(myGui *gui.Node, zone string, zoneID string) *gadgets.BasicWindow
// CFdialog.resultNode.SetText(result) // CFdialog.resultNode.SetText(result)
}) })
// CFdialog.saveNode.Disable() // CFdialog.saveNode.Disable()
group.NewButton("New RR doCurl(PUT)", func () { group.NewButton("New RR doCurl(PUT)", func() {
rr := DoChange() rr := DoChange()
rr.url = "https://api.cloudflare.com/client/v4/zones/" + rr.ZoneID + "/dns_records" rr.url = "https://api.cloudflare.com/client/v4/zones/" + rr.ZoneID + "/dns_records"
@ -133,7 +133,7 @@ func CreateRR(myGui *gui.Node, zone string, zoneID string) *gadgets.BasicWindow
log.Spew(pretty) log.Spew(pretty)
}) })
group.NewButton("Update RR doCurl(PUT)", func () { group.NewButton("Update RR doCurl(PUT)", func() {
rr := DoChange() rr := DoChange()
rr.url = "https://api.cloudflare.com/client/v4/zones/" + rr.ZoneID + "/dns_records/" + rr.ID rr.url = "https://api.cloudflare.com/client/v4/zones/" + rr.ZoneID + "/dns_records/" + rr.ID

View File

@ -1,9 +1,9 @@
// This is a simple example // This is a simple example
package cloudflare package cloudflare
import ( import (
"go.wit.com/gui/gui" "go.wit.com/gui/gui"
"go.wit.com/gui/gadgets" "go.wit.com/lib/gadgets"
) )
var cloudflareURL string = "https://api.cloudflare.com/client/v4/zones/" var cloudflareURL string = "https://api.cloudflare.com/client/v4/zones/"
@ -12,13 +12,13 @@ var cloudflareURL string = "https://api.cloudflare.com/client/v4/zones/"
// This structure should be adjusted based on the actual format of the response. // This structure should be adjusted based on the actual format of the response.
type DNSRecords struct { type DNSRecords struct {
Result []struct { Result []struct {
ID string `json:"id"` ID string `json:"id"`
Type string `json:"type"` Type string `json:"type"`
Name string `json:"name"` Name string `json:"name"`
Content string `json:"content"` Content string `json:"content"`
Proxied bool `json:"proxied"` Proxied bool `json:"proxied"`
Proxiable bool `json:"proxiable"` Proxiable bool `json:"proxiable"`
TTL int `json:"ttl"` TTL int `json:"ttl"`
} `json:"result"` } `json:"result"`
} }
@ -27,80 +27,80 @@ type DNSRecords struct {
var CFdialog dialogT var CFdialog dialogT
type dialogT struct { type dialogT struct {
rootGui *gui.Node // the root node rootGui *gui.Node // the root node
mainWindow *gadgets.BasicWindow // the window node mainWindow *gadgets.BasicWindow // the window node
zonedrop *gui.Node // the drop down menu of zones zonedrop *gui.Node // the drop down menu of zones
domainWidget *gui.Node domainWidget *gui.Node
zoneWidget *gui.Node zoneWidget *gui.Node
authWidget *gui.Node authWidget *gui.Node
emailWidget *gui.Node emailWidget *gui.Node
loadButton *gui.Node loadButton *gui.Node
saveButton *gui.Node saveButton *gui.Node
cloudflareW *gadgets.BasicWindow // the window node cloudflareW *gadgets.BasicWindow // the window node
cloudflareB *gui.Node // the cloudflare button cloudflareB *gui.Node // the cloudflare button
TypeNode *gui.Node // CNAME, A, AAAA, ... TypeNode *gui.Node // CNAME, A, AAAA, ...
NameNode *gui.Node // www, mail, ... NameNode *gui.Node // www, mail, ...
ValueNode *gui.Node // 4.2.2.2, "dkim stuff", etc ValueNode *gui.Node // 4.2.2.2, "dkim stuff", etc
rrNode *gui.Node // cloudflare Resource Record ID rrNode *gui.Node // cloudflare Resource Record ID
proxyNode *gui.Node // If cloudflare is a port 80 & 443 proxy proxyNode *gui.Node // If cloudflare is a port 80 & 443 proxy
ttlNode *gui.Node // just set to 1 which means automatic to cloudflare ttlNode *gui.Node // just set to 1 which means automatic to cloudflare
curlNode *gui.Node // shows you what you could run via curl curlNode *gui.Node // shows you what you could run via curl
resultNode *gui.Node // what the cloudflare API returned resultNode *gui.Node // what the cloudflare API returned
SaveNode *gui.Node // button to send it to cloudflare SaveNode *gui.Node // button to send it to cloudflare
zoneNode *gui.Node // "wit.com" zoneNode *gui.Node // "wit.com"
zoneIdNode *gui.Node // cloudflare zone ID zoneIdNode *gui.Node // cloudflare zone ID
apiNode *gui.Node // cloudflare API key (from environment var CF_API_KEY) apiNode *gui.Node // cloudflare API key (from environment var CF_API_KEY)
emailNode *gui.Node // cloudflare email (from environment var CF_API_EMAIL) emailNode *gui.Node // cloudflare email (from environment var CF_API_EMAIL)
urlNode *gui.Node // the URL to POST, PUT, DELETE, etc urlNode *gui.Node // the URL to POST, PUT, DELETE, etc
} }
// Resource Record (used in a DNS zonefile) // Resource Record (used in a DNS zonefile)
type RRT struct { type RRT struct {
ID string ID string
Type string Type string
Name string Name string
Content string Content string
ProxyS string ProxyS string
Proxied bool Proxied bool
Proxiable bool Proxiable bool
Ttl string Ttl string
Domain string Domain string
ZoneID string ZoneID string
Auth string Auth string
Email string Email string
url string url string
data string data string
} }
/* /*
This is a structure of all the RR's (Resource Records) This is a structure of all the RR's (Resource Records)
in the DNS zonefiile for a hostname. For example: in the DNS zonefiile for a hostname. For example:
For the host test.wit.com: For the host test.wit.com:
test.wit.com A 127.0.0.1 test.wit.com A 127.0.0.1
test.wit.com AAAA test.wit.com AAAA
test.wit.com TXT email test@wit.com test.wit.com TXT email test@wit.com
test.wit.com TXT phone 212-555-1212 test.wit.com TXT phone 212-555-1212
test.wit.com CNAME real.wit.com test.wit.com CNAME real.wit.com
*/ */
type hostT struct { type hostT struct {
hostname string hostname string
RRs []ConfigT RRs []ConfigT
} }
type ConfigT struct { type ConfigT struct {
Domain string Domain string
ZoneID string ZoneID string
Auth string Auth string
Email string Email string
} }
var Config map[string]*ConfigT var Config map[string]*ConfigT

View File

@ -1,9 +1,9 @@
// This is a simple example // This is a simple example
package cloudflare package cloudflare
import ( import (
"go.wit.com/log"
"go.wit.com/gui/gui" "go.wit.com/gui/gui"
"go.wit.com/log"
) )
func drawZoneBox(box *gui.Node) { func drawZoneBox(box *gui.Node) {
@ -17,10 +17,10 @@ func drawZoneBox(box *gui.Node) {
} }
CFdialog.zonedrop.AddText("stablesid.org") CFdialog.zonedrop.AddText("stablesid.org")
CFdialog.zonedrop.Custom = func () { CFdialog.zonedrop.Custom = func() {
domain := CFdialog.zonedrop.String() domain := CFdialog.zonedrop.String()
log.Log(INFO, "custom dropdown() zone (domain name) =", CFdialog.zonedrop.String(), domain) log.Log(INFO, "custom dropdown() zone (domain name) =", CFdialog.zonedrop.String(), domain)
if (Config[domain] == nil) { if Config[domain] == nil {
log.Log(INFO, "custom dropdown() Config[domain] = nil for domain =", domain) log.Log(INFO, "custom dropdown() Config[domain] = nil for domain =", domain)
CFdialog.domainWidget.SetText(domain) CFdialog.domainWidget.SetText(domain)
CFdialog.zoneWidget.SetText("") CFdialog.zoneWidget.SetText("")