Compare commits

...

4 Commits

Author SHA1 Message Date
Jeff Carr 34569cbcee main window is pretty clean
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-01-07 12:45:01 -06:00
Jeff Carr 6916a6428d error button disables
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-01-07 11:52:15 -06:00
Jeff Carr f10c3085c6 the thing works pretty well if you use cloudflare
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-01-07 11:32:43 -06:00
Jeff Carr 937f77b355 delete works
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-01-07 11:23:51 -06:00
8 changed files with 156 additions and 122 deletions

46
dns.go
View File

@ -40,42 +40,16 @@ func (h *Host) setIPv4(ipv4s map[string]*IPtype) {
} }
} }
/* func lookupNSprovider(domain string) string {
func (h *Host) checkDNS() { for s, d := range me.nsmap {
var ip4 bool = false log.Log(CHANGE, "lookupNS() domain =", d, "server =", s)
var ip6 bool = false if (domain == d) {
// figure out the provider (google, cloudflare, etc)
for s, t := range h.ipmap { return s + " blah"
i := t.iface
ipt := "IPv4"
if (t.ipv6) {
ipt = "IPv6"
}
if (! t.IsReal()) {
log.Println(args.VerboseDNS, "\tIP is not Real", ipt, i.Index, i.Name, s)
continue
}
log.Println(args.VerboseDNS, "\tIP is Real ", ipt, i.Index, i.Name, s)
if (t.ipv6) {
ip6 = true
} else {
ip4 = true
} }
} }
return "blah"
if (ip4 == true) {
log.Println(args.VerboseDNS, "IPv4 should work. Wow. You actually have a real IPv4 address")
} else {
log.Println(args.VerboseDNS, "IPv4 is broken. (be nice and setup ipv4-only.wit.com)")
} }
if (ip6 == true) {
log.Println(args.VerboseDNS, "IPv6 should be working. Need to test it here.")
} else {
log.Println(args.VerboseDNS, "IPv6 is broken. Need to fix it here.")
}
}
*/
// nsLookup performs an NS lookup on the given domain name. // nsLookup performs an NS lookup on the given domain name.
func lookupNS(domain string) { func lookupNS(domain string) {
@ -127,9 +101,15 @@ func setProvider(hostname string) {
if len(parts) >= 2 { if len(parts) >= 2 {
provider = parts[len(parts)-2] provider = parts[len(parts)-2]
} }
if me.APIprovider != provider {
log.Log(CHANGE, "setProvider() changed to =", provider)
}
me.APIprovider = provider
/*
if (me.DnsAPI.S != provider) { if (me.DnsAPI.S != provider) {
me.changed = true me.changed = true
log.Log(CHANGE, "setProvider() changed to =", provider) log.Log(CHANGE, "setProvider() changed to =", provider)
me.DnsAPI.SetText(provider) me.DnsAPI.SetText(provider)
} }
*/
} }

View File

@ -27,7 +27,7 @@ type errorBox struct {
type anError struct { type anError struct {
kind string // what kind of error is it? kind string // what kind of error is it?
ip string aaaa string
status string status string
kindLabel *gui.Node kindLabel *gui.Node
@ -62,20 +62,43 @@ func (eb *errorBox) add(kind string, ip string) bool {
anErr := new(anError) anErr := new(anError)
anErr.kind = kind anErr.kind = kind
anErr.aaaa = ip
anErr.kindLabel = eb.grid.NewLabel(kind) anErr.kindLabel = eb.grid.NewLabel(kind)
anErr.ipLabel = eb.grid.NewLabel(ip) anErr.ipLabel = eb.grid.NewLabel(ip)
anErr.statusLabel = eb.grid.NewLabel("") anErr.statusLabel = eb.grid.NewLabel("")
anErr.button = eb.grid.NewButton(kind, func() { anErr.button = eb.grid.NewButton(kind, func() {
log.Log(WARN, "got", kind, "here. IP =", ip) log.Log(WARN, "got", kind, "here. IP =", ip)
eb.fix(kind, ip) eb.fix(tmp)
}) })
eb.fixes[tmp] = anErr eb.fixes[tmp] = anErr
return false return false
} }
func (eb *errorBox) fix(name string, ip string) bool { func (eb *errorBox) fix(key string) bool {
log.Log(WARN, "should try to fix", name, "here. IP =", ip) if eb.fixes[key] == nil {
log.Log(WARN, "Unknown error. could not find key =", key)
log.Log(WARN, "TODO: probably remove this error. key =", key)
return true
}
myErr := eb.fixes[key]
log.Log(WARN, "should try to fix", myErr.kind, "here. IP =", myErr.aaaa)
if myErr.kind == "DELETE" {
if deleteFromDNS(myErr.aaaa) {
log.Log(INFO, "Delete AAAA", myErr.aaaa, "Worked")
} else {
log.Log(INFO, "Delete AAAA", myErr.aaaa, "Failed")
}
return true
}
if myErr.kind == "CREATE" {
if addToDNS(myErr.aaaa) {
log.Log(INFO, "Delete AAAA", myErr.aaaa, "Worked")
} else {
log.Log(INFO, "Delete AAAA", myErr.aaaa, "Failed")
}
return true
}
return false return false
} }

19
fix.go
View File

@ -8,8 +8,6 @@ import (
) )
func fix() bool { func fix() bool {
log.Log(CHANGE, "")
// make and toggle the fixWindow display // make and toggle the fixWindow display
if me.fixWindow == nil { if me.fixWindow == nil {
me.fixWindow = smartwindow.New() me.fixWindow = smartwindow.New()
@ -120,16 +118,25 @@ func fixIPv6dns() bool {
} }
func deleteFromDNS(aaaa string) bool { func deleteFromDNS(aaaa string) bool {
log.Log(CHANGE, "deleteFromDNS", aaaa) log.Log(CHANGE, "Delete this from DNS !!!!", aaaa)
api := me.statusDNS.API()
log.Log(CHANGE, "your API provider is =", api)
if api == "cloudflare" {
log.Log(CHANGE, "Let's try a DELETE via the Cloudflare API")
hostname := me.statusOS.GetHostname()
b, response := cloudflare.Delete("wit.com", hostname, aaaa)
log.Log(CHANGE, "response was:", response)
return b
}
return false return false
} }
func addToDNS(aaaa string) bool { func addToDNS(aaaa string) bool {
log.Log(CHANGE, "TODO: Add this to DNS !!!!", aaaa) log.Log(CHANGE, "Add this to DNS !!!!", aaaa)
api := me.statusDNS.API() api := me.statusDNS.API()
log.Log(CHANGE, "what is your API provider?", api) log.Log(CHANGE, "your API provider is =", api)
if api == "cloudflare" { if api == "cloudflare" {
log.Log(CHANGE, "Let's try an ADD via the Cloudflare API") log.Log(CHANGE, "Let's try a CREATE via the Cloudflare API")
hostname := me.statusOS.GetHostname() hostname := me.statusOS.GetHostname()
return cloudflare.Create("wit.com", hostname, aaaa) return cloudflare.Create("wit.com", hostname, aaaa)
} }

181
gui.go
View File

@ -11,7 +11,8 @@ import (
"go.wit.com/gui/gadgets" "go.wit.com/gui/gadgets"
"go.wit.com/gui/cloudflare" "go.wit.com/gui/cloudflare"
"go.wit.com/gui/debugger" "go.wit.com/gui/debugger"
// "go.wit.com/control-panels/dns/linuxstatus" "go.wit.com/gui/gadgets/logsettings"
"go.wit.com/control-panels/dns/smartwindow"
) )
// This setups up the dns control panel window // This setups up the dns control panel window
@ -43,18 +44,34 @@ func debugTab(title string) {
}) })
g2 = me.debug.Box().NewGroup("debugging options") g2 = me.debug.Box().NewGroup("debugging options")
gridP := g2.NewGrid("nuts", 2, 1)
// makes a slider widget // makes a slider widget
me.ttl = gadgets.NewDurationSlider(g2, "Loop Timeout", 10 * time.Millisecond, 5 * time.Second) me.ttl = gadgets.NewDurationSlider(gridP, "Loop Timeout", 10 * time.Millisecond, 5 * time.Second)
me.ttl.Set(300 * time.Millisecond) me.ttl.Set(300 * time.Millisecond)
// makes a slider widget // makes a slider widget
me.dnsTtl = gadgets.NewDurationSlider(g2, "DNS Timeout", 800 * time.Millisecond, 300 * time.Second) me.dnsTtl = gadgets.NewDurationSlider(gridP, "DNS Timeout", 800 * time.Millisecond, 300 * time.Second)
me.dnsTtl.Set(60 * time.Second) me.dnsTtl.Set(60 * time.Second)
gridP.NewLabel("dns resolution")
me.DnsSpeed = gridP.NewLabel("unknown")
gridP.NewLabel("dns resolution speed")
me.DnsSpeedActual = gridP.NewLabel("unknown")
gridP.NewLabel("Test speed")
newGrid := gridP.NewGrid("nuts", 2, 1).Pad()
g2.Margin() g2.Margin()
g2.Pad() g2.Pad()
newGrid.NewLabel("ping.wit.com =")
newGrid.NewLabel("unknown")
newGrid.NewLabel("ping6.wit.com =")
newGrid.NewLabel("unknown")
me.debug.Hide() me.debug.Hide()
} }
@ -69,7 +86,7 @@ func mainWindow(title string) {
gr := me.window.Box().NewGroup("dns update") gr := me.window.Box().NewGroup("dns update")
// This is where you figure out what to do next to fix the problems // This is where you figure out what to do next to fix the problems
me.fixButton = gr.NewButton("fix", func () { me.fixButton = gr.NewButton("Check Errors", func () {
if ! fix() { if ! fix() {
log.Log(CHANGE, "boo. IPv6 isn't working yet") log.Log(CHANGE, "boo. IPv6 isn't working yet")
return return
@ -80,12 +97,14 @@ func mainWindow(title string) {
// me.hostname.Set(hostname) // me.hostname.Set(hostname)
me.hostnameStatus.Set("WORKING") me.hostnameStatus.Set("WORKING")
me.DnsStatus.Set("WORKING") me.DnsStatus.Set("WORKING")
// me.fixButton.Disable() me.fixButton.SetText("No Errors!")
me.fixButton.Disable()
}) })
statusGrid(me.window.Box()) statusGrid(me.window.Box())
gr = me.window.Box().NewGroup("debugging") gr = me.window.Box().NewGroup("")
/*
me.statusDNSbutton = gr.NewButton("hostname status", func () { me.statusDNSbutton = gr.NewButton("hostname status", func () {
if ! me.statusDNS.Ready() {return} if ! me.statusDNS.Ready() {return}
me.statusDNS.window.Toggle() me.statusDNS.window.Toggle()
@ -97,57 +116,86 @@ func mainWindow(title string) {
if ! me.digStatus.Ready() {return} if ! me.digStatus.Ready() {return}
me.digStatus.window.Toggle() me.digStatus.window.Toggle()
}) })
gr.NewButton("cloudflare wit.com", func () { */
gr.NewButton("Debug", func () {
me.debug.Toggle()
})
var myLS *logsettings.LogSettings
gr.NewButton("Logging Settings", func () {
if myLS == nil {
// initialize the log settings window (does not display it)
myLS = logsettings.New(me.myGui)
return
}
myLS.Toggle()
})
gr.NewButton("Show Errors", func () {
if me.fixWindow == nil {
me.fixWindow = smartwindow.New()
me.fixWindow.SetParent(me.myGui)
me.fixWindow.Title("fix window")
me.fixWindow.SetDraw(drawFixWindow)
me.fixWindow.Vertical()
me.fixWindow.Make()
me.fixWindow.Draw()
me.fixWindow.Hide()
return
}
me.fixWindow.Toggle()
})
}
func statusGrid(n *gui.Node) {
problems := n.NewGroup("status")
problems.Margin()
problems.Pad()
gridP := problems.NewGrid("nuts", 3, 1)
gridP.Margin()
gridP.Pad()
gridP.NewLabel("hostname =")
me.hostnameStatus = gridP.NewLabel("invalid")
gridP.NewButton("Linux Status", func () {
me.statusOS.Toggle()
})
me.statusIPv6 = gadgets.NewOneLiner(gridP, "DNS Lookup")
me.statusIPv6.Set("known")
gridP.NewButton("resolver status", func () {
if ! me.digStatus.Ready() {return}
me.digStatus.window.Toggle()
})
gridP.NewLabel("DNS Status")
me.DnsStatus = gridP.NewLabel("unknown")
me.statusDNSbutton = gridP.NewButton("hostname status", func () {
if ! me.statusDNS.Ready() {return}
me.statusDNS.window.Toggle()
})
gridP.NewLabel("DNS API")
me.DnsAPIstatus = gridP.NewLabel("unknown")
var apiButton *gui.Node
apiButton = gridP.NewButton("unknown wit.com", func () {
log.Log(CHANGE, "WHAT API ARE YOU USING?")
provider := me.statusDNS.GetDNSapi()
apiButton.SetText(provider + " wit.com")
if provider == "cloudflare" {
me.DnsAPIstatus.Set("WORKING")
return
if me.witcom != nil { if me.witcom != nil {
me.witcom.Toggle() me.witcom.Toggle()
} }
me.witcom = cloudflare.CreateRR(me.myGui, "wit.com", "3777302ac4a78cd7fa4f6d3f72086d06") me.witcom = cloudflare.CreateRR(me.myGui, "wit.com", "3777302ac4a78cd7fa4f6d3f72086d06")
})
gr.NewButton("Debug", func () {
me.debug.Toggle()
})
} }
})
func statusGrid(n *gui.Node) { n.NewGroup("NOTES")
problems := n.NewGroup("status")
gridP := problems.NewGrid("nuts", 2, 2)
gridP.NewLabel("hostname =")
me.hostnameStatus = gridP.NewLabel("invalid")
gridP.NewLabel("DNS Status =")
me.DnsStatus = gridP.NewLabel("unknown")
me.statusIPv6 = gadgets.NewOneLiner(gridP, "IPv6 working")
me.statusIPv6.Set("known")
gridP.NewLabel("dns resolution")
me.DnsSpeed = gridP.NewLabel("unknown")
gridP.NewLabel("dns resolution speed")
me.DnsSpeedActual = gridP.NewLabel("unknown")
gridP.NewLabel("dns API provider =")
me.DnsAPI = gridP.NewLabel("unknown")
gridP.Margin()
gridP.Pad()
// TODO: these are notes for me things to figure out
ng := n.NewGroup("TODO:")
gridP = ng.NewGrid("nut2", 2, 2)
gridP.NewLabel("ping.wit.com =")
gridP.NewLabel("unknown")
gridP.NewLabel("ping6.wit.com =")
gridP.NewLabel("unknown")
problems.Margin()
problems.Pad()
gridP.Margin()
gridP.Pad()
} }
// run everything because something has changed // run everything because something has changed
@ -155,45 +203,14 @@ func updateDNS() {
me.digStatus.Update() me.digStatus.Update()
me.statusDNS.Update() me.statusDNS.Update()
// log.Println("digAAAA()")
/*
if me.statusOS.ValidHostname() {
var aaaa []string
h := me.statusOS.GetHostname()
aaaa = digAAAA(h)
log.Log(INFO, "digAAAA() for", h, "=", aaaa)
// log.Println(SPEW, me)
if (aaaa == nil) {
log.Warn("There are no DNS AAAA records for hostname: ", h)
// me.DnsAAAA.Set("(none)")
if (cloudflare.CFdialog.TypeNode != nil) {
cloudflare.CFdialog.TypeNode.SetText("AAAA new")
}
if (cloudflare.CFdialog.NameNode != nil) {
cloudflare.CFdialog.NameNode.SetText(h)
}
}
}
*/
// status := displayDNS() // update the GUI based on dig results
// me.DnsStatus.SetText(status)
if me.digStatus.Ready() { if me.digStatus.Ready() {
if me.digStatus.IPv6() { if me.digStatus.IPv6() {
me.statusIPv6.Set("IPv6 WORKING") me.statusIPv6.Set("WORKING")
} else { } else {
me.statusIPv6.Set("Need VPN") me.statusIPv6.Set("Need VPN")
} }
} }
// me.fix.Enable()
// lookup the NS records for your domain // lookup the NS records for your domain
// if your host is test.wit.com, find the NS resource records for wit.com // if your host is test.wit.com, find the NS resource records for wit.com
lookupNS(me.statusOS.GetDomainName()) lookupNS(me.statusOS.GetDomainName())

View File

@ -323,7 +323,9 @@ func (hs *hostnameStatus) updateStatus() {
hs.status.Set("BROKEN") hs.status.Set("BROKEN")
} }
hs.dnsAPI.Set(me.DnsAPI.S) // lookup the DNS provider
// hs.dnsAPI.Set(me.DnsAPI.S)
lookupNSprovider("wit.com")
} }
func (hs *hostnameStatus) Show() { func (hs *hostnameStatus) Show() {
@ -341,3 +343,7 @@ func (hs *hostnameStatus) Hide() {
} }
hs.hidden = true hs.hidden = true
} }
func (hs *hostnameStatus) GetDNSapi() string {
return me.APIprovider
}

View File

@ -33,7 +33,7 @@ func (ls *LinuxStatus) GetHostname() string {
func (ls *LinuxStatus) ValidHostname() bool { func (ls *LinuxStatus) ValidHostname() bool {
if ! me.Ready() {return false} if ! me.Ready() {return false}
if me.hostnameStatus.Get() == "VALID" { if me.hostnameStatus.Get() == "WORKING" {
return true return true
} }
return false return false
@ -104,9 +104,9 @@ func lookupHostname() {
me.hostnameStatus.Set("BROKEN") me.hostnameStatus.Set("BROKEN")
} }
} else { } else {
if (me.hostnameStatus.Get() != "VALID") { if (me.hostnameStatus.Get() != "WORKING") {
log.Log(CHANGE, "hostname", hostname, "is valid") log.Log(CHANGE, "hostname", hostname, "is valid")
me.hostnameStatus.Set("VALID") me.hostnameStatus.Set("WORKING")
me.changed = true me.changed = true
} }
} }

View File

@ -162,8 +162,8 @@ func linuxLoop() {
me.statusOS.Update() me.statusOS.Update()
if me.statusOS.ValidHostname() { if me.statusOS.ValidHostname() {
if me.hostnameStatus.GetText() != "VALID" { if me.hostnameStatus.GetText() != "WORKING" {
me.hostnameStatus.Set("VALID") me.hostnameStatus.Set("WORKING")
me.changed = true me.changed = true
} }
} }

View File

@ -26,8 +26,10 @@ type Host struct {
statusOS *linuxstatus.LinuxStatus // what the Linux OS sees statusOS *linuxstatus.LinuxStatus // what the Linux OS sees
digStatus *digStatus // window of the results of DNS lookups digStatus *digStatus // window of the results of DNS lookups
// WHEN THESE ARE ALL "WORKING", then everything is good
hostnameStatus *gui.Node // a summary for the user of where things are hostnameStatus *gui.Node // a summary for the user of where things are
// hostname *gadgets.OneLiner // the hostname grabbed from gadget.linuxStatus DnsAPIstatus *gui.Node // does your DNS API work?
APIprovider string
artificialSleep float64 `default:"0.7"` // artificial sleep on startup artificialSleep float64 `default:"0.7"` // artificial sleep on startup
artificialS string `default:"abc"` // artificial sleep on startup artificialS string `default:"abc"` // artificial sleep on startup
@ -49,7 +51,6 @@ type Host struct {
ipv6s map[string]dns.RR ipv6s map[string]dns.RR
// DNS stuff // DNS stuff
DnsAPI *gui.Node // what DNS API to use?
DnsStatus *gui.Node // the current state of DNS DnsStatus *gui.Node // the current state of DNS
DnsSpeed *gui.Node // 'FAST', 'OK', 'SLOW', etc DnsSpeed *gui.Node // 'FAST', 'OK', 'SLOW', etc
DnsSpeedActual *gui.Node // the last actual duration DnsSpeedActual *gui.Node // the last actual duration