Compare commits

..

4 Commits

Author SHA1 Message Date
Jeff Carr 1decb6925b watches for finished setup
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-01-07 14:43:17 -06:00
Jeff Carr c82e88d015 provider automatically updates
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-01-07 14:19:57 -06:00
Jeff Carr 8e4d24a3d0 starting to watch all the engines run
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-01-07 14:11:15 -06:00
Jeff Carr 1208cdeda6 background gui.debugger init
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-01-07 13:03:48 -06:00
3 changed files with 112 additions and 135 deletions

35
gui.go
View File

@ -38,9 +38,8 @@ func debugTab(title string) {
debugger.DebugWindow(me.myGui) debugger.DebugWindow(me.myGui)
}) })
g2.NewButton("dig A & AAAA DNS records", func () { g2.NewButton("dig A & AAAA DNS records (updateDNS())", func () {
log.Println("updateDNS()") log.Log(CHANGE, "updateDNS() going to run:")
updateDNS()
}) })
g2 = me.debug.Box().NewGroup("debugging options") g2 = me.debug.Box().NewGroup("debugging options")
@ -178,42 +177,18 @@ func statusGrid(n *gui.Node) {
gridP.NewLabel("DNS API") gridP.NewLabel("DNS API")
me.DnsAPIstatus = gridP.NewLabel("unknown") me.DnsAPIstatus = gridP.NewLabel("unknown")
var apiButton *gui.Node me.apiButton = gridP.NewButton("unknown wit.com", func () {
apiButton = gridP.NewButton("unknown wit.com", func () {
log.Log(CHANGE, "WHAT API ARE YOU USING?") log.Log(CHANGE, "WHAT API ARE YOU USING?")
provider := me.statusDNS.GetDNSapi() provider := me.statusDNS.GetDNSapi()
apiButton.SetText(provider + " wit.com")
if provider == "cloudflare" { if provider == "cloudflare" {
me.DnsAPIstatus.Set("WORKING")
return
if me.witcom != nil { if me.witcom != nil {
me.witcom.Toggle() me.witcom.Toggle()
} } else {
me.witcom = cloudflare.CreateRR(me.myGui, "wit.com", "3777302ac4a78cd7fa4f6d3f72086d06") me.witcom = cloudflare.CreateRR(me.myGui, "wit.com", "3777302ac4a78cd7fa4f6d3f72086d06")
} }
}
}) })
n.NewGroup("NOTES") n.NewGroup("NOTES")
} }
// run everything because something has changed
func updateDNS() {
me.digStatus.Update()
me.statusDNS.Update()
if me.digStatus.Ready() {
if me.digStatus.IPv6() {
me.statusIPv6.Set("WORKING")
} else {
me.statusIPv6.Set("Need VPN")
}
}
// lookup the NS records for your domain
// if your host is test.wit.com, find the NS resource records for wit.com
lookupNS(me.statusOS.GetDomainName())
log.Println("updateDNS() END")
}

195
main.go
View File

@ -6,7 +6,7 @@ package main
import ( import (
"fmt" "fmt"
"runtime" // "runtime"
"time" "time"
"embed" "embed"
@ -54,111 +54,57 @@ func main() {
me.statusOS.Draw2() me.statusOS.Draw2()
if debugger.ArgDebug() { if debugger.ArgDebug() {
go func() {
log.Sleep(2) log.Sleep(2)
debugger.DebugWindow(me.myGui) debugger.DebugWindow(me.myGui)
}
// forever monitor for network and dns changes
log.Sleep(me.artificialSleep)
checkNetworkChanges()
}
/*
Poll for changes to the networking settings
*/
/* https://github.com/robfig/cron/blob/master/cron.go
// Run the cron scheduler, or no-op if already running.
func (c *Cron) Run() {
c.runningMu.Lock()
if c.running {
c.runningMu.Unlock()
return
}
c.running = true
c.runningMu.Unlock()
c.run()
}
// run the scheduler.. this is private just due to the need to synchronize
// access to the 'running' state variable.
func (c *Cron) run() {
c.logger.Info("start")
*/
func checkNetworkChanges() {
var lastLocal time.Time = time.Now()
var lastDNS time.Time = time.Now()
timer2 := time.NewTimer(time.Second)
go func() {
<-timer2.C
fmt.Println("Timer 2 fired")
}() }()
}
for { log.Sleep(me.artificialSleep)
time.Sleep(me.ttl.Duration)
if (time.Since(lastLocal) > me.localSleep) { // TCP & UDP port 53 lookups + DNS over HTTP lookups + os.Exec(dig)
if (runtime.GOOS == "linux") { go myTicker(60 * time.Second, "DNSloop", func() {
duration := timeFunction(linuxLoop) me.digStatus.Update()
s := fmt.Sprint(duration)
me.statusOS.SetSpeedActual(s) if me.digStatus.Ready() {
current := me.statusIPv6.Get()
if me.digStatus.IPv6() {
if current != "WORKING" {
log.Log(CHANGE, "IPv6 resolution is WORKING")
me.statusIPv6.Set("WORKING")
}
} else { } else {
// TODO: make windows and macos diagnostics if current != "Need VPN" {
log.Warn("Windows and MacOS don't work yet") log.Log(CHANGE, "IPv6 resolution seems to have broken")
me.statusIPv6.Set("Need VPN")
} }
lastLocal = time.Now()
} }
if (time.Since(lastDNS) > me.dnsTtl.Duration) {
DNSloop()
lastDNS = time.Now()
} }
})
/* // checks if your DNS records are still broken
stop2 := timer2.Stop() // if everything is working, then it just ignores
if stop2 { // things until the timeout happens
fmt.Println("Timer 2 stopped")
}
*/
}
}
// run this on each timeout lastProvider := "unknown"
func DNSloop() { go myTicker(10 * time.Second, "DNSloop", func() {
duration := timeFunction(dnsTTL) log.Log(CHANGE, "me.statusDNS.Update() START")
log.Info("dnsTTL() execution Time: ", duration) me.statusDNS.Update()
var s, newSpeed string
if (duration > 5000 * time.Millisecond ) {
newSpeed = "VERY SLOW"
} else if (duration > 2000 * time.Millisecond ) {
newSpeed = "SLOWER"
} else if (duration > 500 * time.Millisecond ) {
newSpeed = "SLOW"
} else if (duration > 100 * time.Millisecond ) {
newSpeed = "OK"
} else {
newSpeed = "FAST"
}
if (newSpeed != me.DnsSpeedLast) {
log.Log(CHANGE, "dns lookup speed changed =", newSpeed)
log.Log(CHANGE, "dnsTTL() execution Time: ", duration)
me.DnsSpeed.SetText(newSpeed)
me.DnsSpeedLast = newSpeed
}
s = fmt.Sprint(duration)
me.DnsSpeedActual.SetText(s)
}
// This checks for changes to the network settings provider := me.statusDNS.GetDNSapi()
// and verifies that DNS is working or not working if provider != lastProvider {
func dnsTTL() { log.Log(CHANGE, "Your DNS API provider appears to have changed to", provider)
updateDNS() lastProvider = provider
me.apiButton.SetText(provider + " wit.com")
} }
if provider == "cloudflare" {
me.DnsAPIstatus.Set("WORKING")
}
})
// run update on the LinuxStatus() window // probes the OS network settings
// also update a few things on the main window go myTicker(500 * time.Millisecond, "me.statusOS,Update()", func() {
func linuxLoop() { duration := timeFunction( func() {
me.statusOS.Update() me.statusOS.Update()
if me.statusOS.ValidHostname() { if me.statusOS.ValidHostname() {
@ -168,12 +114,38 @@ func linuxLoop() {
} }
} }
// re-check DNS API provider
if (me.statusOS.Changed()) { if (me.statusOS.Changed()) {
stamp := time.Now().Format("2006/01/02 15:04:05") // lookup the NS records for your domain
log.Log(CHANGE, "Network things changed on", stamp) // if your host is test.wit.com, find the NS resource records for wit.com
duration := timeFunction(updateDNS) lookupNS(me.statusOS.GetDomainName())
log.Log(CHANGE, "updateDNS() execution Time: ", duration) log.Log(CHANGE, "updateDNS() END")
} }
})
s := fmt.Sprint(duration)
me.statusOS.SetSpeedActual(s)
})
// check the four known things to see if they are all WORKING
myTicker(3 * time.Second, "MAIN LOOP", func() {
if me.hostnameStatus.GetText() != "WORKING" {
log.Log(CHANGE, "The hostname is not WORKING yet", me.hostnameStatus.GetText())
return
}
if me.statusIPv6.Get() != "WORKING" {
log.Log(CHANGE, "IPv6 DNS lookup has not been confirmed yet", me.statusIPv6.Get())
return
}
if me.DnsStatus.GetText() != "WORKING" {
log.Log(CHANGE, "Your IPv6 DNS settings have not been confirmed yet", me.DnsStatus.GetText())
return
}
if me.DnsAPIstatus.GetText() != "WORKING" {
log.Log(CHANGE, "The DNS API provider is not yet working", me.DnsAPIstatus.GetText())
return
}
log.Log(CHANGE, "EVERYTHING IS WORKING. YOU HAVE IPv6 BLISS")
})
} }
/* /*
@ -188,3 +160,32 @@ func timeFunction(f func()) time.Duration {
f() // Execute the function f() // Execute the function
return time.Since(startTime) // Calculate the elapsed time return time.Since(startTime) // Calculate the elapsed time
} }
func timeStamp() string {
stamp := time.Now().Format("2006/01/02 15:04:05")
log.Log(CHANGE, "Network things changed on", stamp)
return stamp
}
func myTicker(t time.Duration, name string, f func()) {
ticker := time.NewTicker(t)
defer ticker.Stop()
done := make(chan bool)
/*
go func() {
time.Sleep(10 * time.Second)
done <- true
}()
*/
for {
select {
case <-done:
fmt.Println("Done!")
return
case t := <-ticker.C:
log.Log(INFO, name, "Current time: ", t)
f()
}
}
}

View File

@ -30,6 +30,7 @@ type Host struct {
hostnameStatus *gui.Node // a summary for the user of where things are hostnameStatus *gui.Node // a summary for the user of where things are
DnsAPIstatus *gui.Node // does your DNS API work? DnsAPIstatus *gui.Node // does your DNS API work?
APIprovider string APIprovider string
apiButton *gui.Node // the button you click for the API config page
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