send everything through go.wit.com/log

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-05 19:33:41 -06:00
parent 2ce239c6ce
commit 8f34aa62f2
6 changed files with 52 additions and 40 deletions

35
api.go
View File

@ -22,7 +22,7 @@ func DoChange() *RRT {
var dnsRow *RRT
dnsRow = new(RRT)
log.Println("DoChange() START")
log.Log(INFO, "DoChange() START")
if (CFdialog.proxyNode.S == "On") {
dnsRow.Proxied = true
} else {
@ -42,20 +42,20 @@ func DoChange() *RRT {
dnsRow.data = makeJSON(dnsRow)
// show the JSON
log.Println(dnsRow)
log.Log(INFO, dnsRow)
if (CFdialog.curlNode != nil) {
pretty, _ := FormatJSON(dnsRow.data)
log.Println("http PUT curl =", pretty)
log.Log(INFO, "http PUT curl =", pretty)
CFdialog.curlNode.SetText(pretty)
}
return dnsRow
}
func SetRow(dnsRow *RRT) {
log.Println("Look for changes in row", dnsRow.ID)
log.Log(INFO, "Look for changes in row", dnsRow.ID)
if (CFdialog.proxyNode != nil) {
log.Println("Proxy", dnsRow.Proxied, "vs", CFdialog.proxyNode.S)
log.Log(INFO, "Proxy", dnsRow.Proxied, "vs", CFdialog.proxyNode.S)
if (dnsRow.Proxied == true) {
CFdialog.proxyNode.SetText("On")
} else {
@ -68,12 +68,12 @@ func SetRow(dnsRow *RRT) {
if (CFdialog.zoneIdNode != nil) {
CFdialog.zoneIdNode.SetText(dnsRow.ZoneID)
}
log.Println("zoneIdNode =", dnsRow.ZoneID)
log.Log(INFO, "zoneIdNode =", dnsRow.ZoneID)
if (CFdialog.rrNode != nil) {
CFdialog.rrNode.SetText(dnsRow.ID)
}
if (CFdialog.ValueNode != nil) {
log.Println("Content", dnsRow.Content, "vs", CFdialog.ValueNode.S)
log.Log(INFO, "Content", dnsRow.Content, "vs", CFdialog.ValueNode.S)
CFdialog.ValueNode.SetText(dnsRow.Content)
}
if (CFdialog.NameNode != nil) {
@ -90,17 +90,17 @@ func SetRow(dnsRow *RRT) {
// show the JSON
tmp := makeJSON(dnsRow)
log.Println(tmp)
log.Spew(tmp)
if (CFdialog.curlNode != nil) {
pretty, _ := FormatJSON(tmp)
log.Println("http PUT curl =", pretty)
log.Spew("http PUT curl =", pretty)
CFdialog.curlNode.SetText(pretty)
}
}
func GetZonefile(c *ConfigT) *DNSRecords {
var url = cloudflareURL + c.ZoneID + "/dns_records/?per_page=100"
log.Println("getZonefile()", c.Domain, url)
log.Log(ZONE, "getZonefile()", c.Domain, url)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
log.Error(err, "http.NewRequest error")
@ -112,7 +112,7 @@ func GetZonefile(c *ConfigT) *DNSRecords {
// req.Header.Set("X-Auth-Key", c.Auth)
// req.Header.Set("X-Auth-Email", c.Email)
log.Println("getZonefile() auth, email", c.Auth, c.Email)
log.Log(ZONE, "getZonefile() auth, email", c.Auth, c.Email)
client := &http.Client{}
resp, err := client.Do(req)
@ -142,7 +142,7 @@ func GetZonefile(c *ConfigT) *DNSRecords {
return nil
}
log.Println("getZonefile() worked", records)
log.Log(ZONE, "getZonefile() worked", records)
return &records
}
@ -172,7 +172,7 @@ func makeJSON(dnsRow *RRT) string {
// https://api.cloudflare.com/client/v4/zones
func GetZones(auth, email string) *DNSRecords {
var url = "https://api.cloudflare.com/client/v4/zones?per_page=100"
log.Println("getZones()", url)
log.Log(ZONE, "getZones()", url)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
log.Error(err, "http.NewRequest error")
@ -184,7 +184,7 @@ func GetZones(auth, email string) *DNSRecords {
// req.Header.Set("X-Auth-Key", auth)
// req.Header.Set("X-Auth-Email", email)
log.Println("getZones() auth, email", auth, email)
log.Log(ZONE, "getZones() auth, email", auth, email)
client := &http.Client{}
resp, err := client.Do(req)
@ -218,9 +218,6 @@ func GetZones(auth, email string) *DNSRecords {
Proxiable bool "json:\"proxiable\""; TTL int "json:\"ttl\"" }
*/
// log.Println("getZones() worked", records)
// log.Println("spew dump:")
// spew.Dump(records)
for _, record := range records.Result {
log.Spew("spew record:", record)
log.Info("record:", record.Name, record.ID)
@ -234,10 +231,10 @@ func GetZones(auth, email string) *DNSRecords {
newc.Email = email
Config[record.Name] = newc
log.Println("zonedrop.AddText:", record.Name, record.ID)
log.Log(ZONE, "zonedrop.AddText:", record.Name, record.ID)
}
for d, _ := range Config {
log.Println("Config entry:", d)
log.Log(ZONE, "Config entry:", d)
}
return &records

16
args.go
View File

@ -6,13 +6,29 @@ import (
"go.wit.com/log"
)
var INFO log.LogFlag
var CURL log.LogFlag
var ZONE log.LogFlag
func init() {
INFO.B = true
INFO.Name = "INFO"
INFO.Subsystem = "cloudflare"
INFO.Short = "gui cf"
INFO.Desc = "general info"
INFO.Register()
CURL.B = true
CURL.Name = "CURL"
CURL.Subsystem = "cloudflare"
CURL.Short = "gui cf"
CURL.Desc = "curl interactions()"
CURL.Register()
ZONE.B = true
ZONE.Name = "ZONE"
ZONE.Subsystem = "cloudflare"
ZONE.Short = "gui cf"
ZONE.Desc = "zone details"
ZONE.Register()
}

View File

@ -2,9 +2,9 @@
package cloudflare
import (
"log"
"strconv"
"go.wit.com/log"
"go.wit.com/gui/gui"
"go.wit.com/gui/gadgets"
)
@ -12,7 +12,7 @@ import (
func LoadZoneWindow(n *gui.Node, c *ConfigT) {
hostname := c.Domain
zoneID := c.ZoneID
log.Println("adding DNS record", hostname)
log.Log(INFO, "adding DNS record", hostname)
newW := gadgets.NewBasicWindow(n, hostname)
newg := newW.Box().NewGroup("more zoneID = " + zoneID)
@ -21,7 +21,7 @@ func LoadZoneWindow(n *gui.Node, c *ConfigT) {
grid := newg.NewGrid("gridnuts", 6, 1)
// grid.NewButton("Type", func () {
// log.Println("sort by Type")
// log.Log(INFO, "sort by Type")
// })
grid.NewLabel("RR type")
grid.NewLabel("hostname")
@ -74,7 +74,7 @@ func LoadZoneWindow(n *gui.Node, c *ConfigT) {
load := grid.NewButton("Load", nil)
load.Custom = func () {
name := "save stuff to cloudflare for " + rr.ID
log.Println(name)
log.Log(INFO, name)
/*
rr.Domain = domainWidget.S

View File

@ -3,8 +3,8 @@ package cloudflare
import (
"os"
"log"
"go.wit.com/log"
"go.wit.com/gui/gui"
"go.wit.com/gui/gadgets"
)
@ -13,7 +13,7 @@ import (
func MakeCloudflareWindow(n *gui.Node) *gadgets.BasicWindow {
CFdialog.rootGui = n
log.Println("buttonWindow() START")
log.Log(INFO, "buttonWindow() START")
CFdialog.mainWindow = gadgets.NewBasicWindow(n,"Cloudflare Config")
CFdialog.mainWindow.Vertical()
@ -34,15 +34,15 @@ func MakeCloudflareWindow(n *gui.Node) *gadgets.BasicWindow {
CFdialog.zonedrop.Custom = func () {
domain := CFdialog.zonedrop.S
log.Println("custom dropdown() zone (domain name) =", CFdialog.zonedrop.Name, domain)
log.Log(ZONE, "custom dropdown() zone (domain name) =", CFdialog.zonedrop.Name, domain)
if (Config[domain] == nil) {
log.Println("custom dropdown() Config[domain] = nil for domain =", domain)
log.Log(ZONE, "custom dropdown() Config[domain] = nil for domain =", domain)
CFdialog.domainWidget.SetText(domain)
CFdialog.zoneWidget.SetText("")
CFdialog.authWidget.SetText("")
CFdialog.emailWidget.SetText("")
} else {
log.Println("custom dropdown() a =", domain, Config[domain].ZoneID, Config[domain].Auth, Config[domain].Email)
log.Log(ZONE, "custom dropdown() a =", domain, Config[domain].ZoneID, Config[domain].Auth, Config[domain].Email)
CFdialog.domainWidget.SetText(Config[domain].Domain)
CFdialog.zoneWidget.SetText(Config[domain].ZoneID)
CFdialog.authWidget.SetText(Config[domain].Auth)
@ -82,16 +82,16 @@ func makeConfigWindow(vb *gui.Node) {
grid.Pad()
vb.NewButton("Lookup Hostname", func () {
log.Println("Find all the Resource Records for hostname:", hostname.Get())
log.Println("Find all the Resource Records for zone:", zone.Get())
log.Log(INFO, "Find all the Resource Records for hostname:", hostname.Get())
log.Log(INFO, "Find all the Resource Records for zone:", zone.Get())
GetZones(aw.S, ew.S)
for d, v := range Config {
log.Println("Zone =", d, "v =", v)
log.Log(ZONE, "Zone =", d, "v =", v)
}
})
vb.NewButton("getZones()", func () {
log.Println("getZones()")
log.Log(ZONE, "getZones()")
GetZones(aw.S, ew.S)
for d, _ := range Config {
CFdialog.zonedrop.AddText(d)

9
rr.go
View File

@ -7,9 +7,9 @@
package cloudflare
import (
"log"
"os"
"go.wit.com/log"
"go.wit.com/gui/gui"
"go.wit.com/gui/gadgets"
)
@ -21,7 +21,7 @@ func init() {
func CreateRR(myGui *gui.Node, zone string, zoneID string) {
if (CFdialog.cloudflareW != nil) {
// skip this if the window has already been created
log.Println("createRR() the cloudflare window already exists")
log.Warn("createRR() the cloudflare window already exists")
CFdialog.cloudflareB.Disable()
return
}
@ -130,7 +130,7 @@ func CreateRR(myGui *gui.Node, zone string, zoneID string) {
CFdialog.resultNode.SetText(result)
pretty, _ := FormatJSON(result)
log.Println(pretty)
log.Spew(pretty)
})
group.NewButton("Update RR doCurl(PUT)", func () {
@ -142,11 +142,10 @@ func CreateRR(myGui *gui.Node, zone string, zoneID string) {
CFdialog.resultNode.SetText(result)
pretty, _ := FormatJSON(result)
log.Println(pretty)
log.Spew(pretty)
})
// CFdialog.saveNode.Disable()
group.Pad()
grid.Pad()
grid.Expand()

View File

@ -19,15 +19,15 @@ func drawZoneBox(box *gui.Node) {
CFdialog.zonedrop.Custom = func () {
domain := CFdialog.zonedrop.S
log.Println("custom dropdown() zone (domain name) =", CFdialog.zonedrop.Name, domain)
log.Log(INFO, "custom dropdown() zone (domain name) =", CFdialog.zonedrop.Name, domain)
if (Config[domain] == nil) {
log.Println("custom dropdown() Config[domain] = nil for domain =", domain)
log.Log(INFO, "custom dropdown() Config[domain] = nil for domain =", domain)
CFdialog.domainWidget.SetText(domain)
CFdialog.zoneWidget.SetText("")
CFdialog.authWidget.SetText("")
CFdialog.emailWidget.SetText("")
} else {
log.Println("custom dropdown() a =", domain, Config[domain].ZoneID, Config[domain].Auth, Config[domain].Email)
log.Log(INFO, "custom dropdown() a =", domain, Config[domain].ZoneID, Config[domain].Auth, Config[domain].Email)
CFdialog.domainWidget.SetText(Config[domain].Domain)
CFdialog.zoneWidget.SetText(Config[domain].ZoneID)
CFdialog.authWidget.SetText(Config[domain].Auth)