Compare commits
4 Commits
ef6eb7a96a
...
34569cbcee
Author | SHA1 | Date |
---|---|---|
|
34569cbcee | |
|
6916a6428d | |
|
f10c3085c6 | |
|
937f77b355 |
46
dns.go
46
dns.go
|
@ -40,42 +40,16 @@ func (h *Host) setIPv4(ipv4s map[string]*IPtype) {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func (h *Host) checkDNS() {
|
||||
var ip4 bool = false
|
||||
var ip6 bool = false
|
||||
|
||||
for s, t := range h.ipmap {
|
||||
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
|
||||
func lookupNSprovider(domain string) string {
|
||||
for s, d := range me.nsmap {
|
||||
log.Log(CHANGE, "lookupNS() domain =", d, "server =", s)
|
||||
if (domain == d) {
|
||||
// figure out the provider (google, cloudflare, etc)
|
||||
return s + " 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.")
|
||||
}
|
||||
return "blah"
|
||||
}
|
||||
*/
|
||||
|
||||
// nsLookup performs an NS lookup on the given domain name.
|
||||
func lookupNS(domain string) {
|
||||
|
@ -127,9 +101,15 @@ func setProvider(hostname string) {
|
|||
if 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) {
|
||||
me.changed = true
|
||||
log.Log(CHANGE, "setProvider() changed to =", provider)
|
||||
me.DnsAPI.SetText(provider)
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
31
errorBox.go
31
errorBox.go
|
@ -27,7 +27,7 @@ type errorBox struct {
|
|||
|
||||
type anError struct {
|
||||
kind string // what kind of error is it?
|
||||
ip string
|
||||
aaaa string
|
||||
status string
|
||||
|
||||
kindLabel *gui.Node
|
||||
|
@ -62,20 +62,43 @@ func (eb *errorBox) add(kind string, ip string) bool {
|
|||
|
||||
anErr := new(anError)
|
||||
anErr.kind = kind
|
||||
anErr.aaaa = ip
|
||||
|
||||
anErr.kindLabel = eb.grid.NewLabel(kind)
|
||||
anErr.ipLabel = eb.grid.NewLabel(ip)
|
||||
anErr.statusLabel = eb.grid.NewLabel("")
|
||||
anErr.button = eb.grid.NewButton(kind, func() {
|
||||
log.Log(WARN, "got", kind, "here. IP =", ip)
|
||||
eb.fix(kind, ip)
|
||||
eb.fix(tmp)
|
||||
})
|
||||
eb.fixes[tmp] = anErr
|
||||
return false
|
||||
}
|
||||
|
||||
func (eb *errorBox) fix(name string, ip string) bool {
|
||||
log.Log(WARN, "should try to fix", name, "here. IP =", ip)
|
||||
func (eb *errorBox) fix(key string) bool {
|
||||
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
|
||||
}
|
||||
|
||||
|
|
19
fix.go
19
fix.go
|
@ -8,8 +8,6 @@ import (
|
|||
)
|
||||
|
||||
func fix() bool {
|
||||
log.Log(CHANGE, "")
|
||||
|
||||
// make and toggle the fixWindow display
|
||||
if me.fixWindow == nil {
|
||||
me.fixWindow = smartwindow.New()
|
||||
|
@ -120,16 +118,25 @@ func fixIPv6dns() 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
|
||||
}
|
||||
|
||||
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()
|
||||
log.Log(CHANGE, "what is your API provider?", api)
|
||||
log.Log(CHANGE, "your API provider is =", api)
|
||||
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()
|
||||
return cloudflare.Create("wit.com", hostname, aaaa)
|
||||
}
|
||||
|
|
181
gui.go
181
gui.go
|
@ -11,7 +11,8 @@ import (
|
|||
"go.wit.com/gui/gadgets"
|
||||
"go.wit.com/gui/cloudflare"
|
||||
"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
|
||||
|
@ -43,18 +44,34 @@ func debugTab(title string) {
|
|||
})
|
||||
|
||||
g2 = me.debug.Box().NewGroup("debugging options")
|
||||
gridP := g2.NewGrid("nuts", 2, 1)
|
||||
|
||||
// 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)
|
||||
|
||||
// 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)
|
||||
|
||||
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.Pad()
|
||||
|
||||
newGrid.NewLabel("ping.wit.com =")
|
||||
newGrid.NewLabel("unknown")
|
||||
|
||||
newGrid.NewLabel("ping6.wit.com =")
|
||||
newGrid.NewLabel("unknown")
|
||||
|
||||
me.debug.Hide()
|
||||
}
|
||||
|
||||
|
@ -69,7 +86,7 @@ func mainWindow(title string) {
|
|||
gr := me.window.Box().NewGroup("dns update")
|
||||
|
||||
// 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() {
|
||||
log.Log(CHANGE, "boo. IPv6 isn't working yet")
|
||||
return
|
||||
|
@ -80,12 +97,14 @@ func mainWindow(title string) {
|
|||
// me.hostname.Set(hostname)
|
||||
me.hostnameStatus.Set("WORKING")
|
||||
me.DnsStatus.Set("WORKING")
|
||||
// me.fixButton.Disable()
|
||||
me.fixButton.SetText("No Errors!")
|
||||
me.fixButton.Disable()
|
||||
})
|
||||
|
||||
statusGrid(me.window.Box())
|
||||
|
||||
gr = me.window.Box().NewGroup("debugging")
|
||||
gr = me.window.Box().NewGroup("")
|
||||
/*
|
||||
me.statusDNSbutton = gr.NewButton("hostname status", func () {
|
||||
if ! me.statusDNS.Ready() {return}
|
||||
me.statusDNS.window.Toggle()
|
||||
|
@ -97,57 +116,86 @@ func mainWindow(title string) {
|
|||
if ! me.digStatus.Ready() {return}
|
||||
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 {
|
||||
me.witcom.Toggle()
|
||||
}
|
||||
me.witcom = cloudflare.CreateRR(me.myGui, "wit.com", "3777302ac4a78cd7fa4f6d3f72086d06")
|
||||
}
|
||||
})
|
||||
gr.NewButton("Debug", func () {
|
||||
me.debug.Toggle()
|
||||
})
|
||||
}
|
||||
|
||||
func statusGrid(n *gui.Node) {
|
||||
problems := n.NewGroup("status")
|
||||
n.NewGroup("NOTES")
|
||||
|
||||
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
|
||||
|
@ -155,45 +203,14 @@ func updateDNS() {
|
|||
me.digStatus.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.IPv6() {
|
||||
me.statusIPv6.Set("IPv6 WORKING")
|
||||
me.statusIPv6.Set("WORKING")
|
||||
} else {
|
||||
me.statusIPv6.Set("Need VPN")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// me.fix.Enable()
|
||||
|
||||
|
||||
// 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())
|
||||
|
|
|
@ -323,7 +323,9 @@ func (hs *hostnameStatus) updateStatus() {
|
|||
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() {
|
||||
|
@ -341,3 +343,7 @@ func (hs *hostnameStatus) Hide() {
|
|||
}
|
||||
hs.hidden = true
|
||||
}
|
||||
|
||||
func (hs *hostnameStatus) GetDNSapi() string {
|
||||
return me.APIprovider
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ func (ls *LinuxStatus) GetHostname() string {
|
|||
|
||||
func (ls *LinuxStatus) ValidHostname() bool {
|
||||
if ! me.Ready() {return false}
|
||||
if me.hostnameStatus.Get() == "VALID" {
|
||||
if me.hostnameStatus.Get() == "WORKING" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
@ -104,9 +104,9 @@ func lookupHostname() {
|
|||
me.hostnameStatus.Set("BROKEN")
|
||||
}
|
||||
} else {
|
||||
if (me.hostnameStatus.Get() != "VALID") {
|
||||
if (me.hostnameStatus.Get() != "WORKING") {
|
||||
log.Log(CHANGE, "hostname", hostname, "is valid")
|
||||
me.hostnameStatus.Set("VALID")
|
||||
me.hostnameStatus.Set("WORKING")
|
||||
me.changed = true
|
||||
}
|
||||
}
|
||||
|
|
4
main.go
4
main.go
|
@ -162,8 +162,8 @@ func linuxLoop() {
|
|||
me.statusOS.Update()
|
||||
|
||||
if me.statusOS.ValidHostname() {
|
||||
if me.hostnameStatus.GetText() != "VALID" {
|
||||
me.hostnameStatus.Set("VALID")
|
||||
if me.hostnameStatus.GetText() != "WORKING" {
|
||||
me.hostnameStatus.Set("WORKING")
|
||||
me.changed = true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,8 +26,10 @@ type Host struct {
|
|||
statusOS *linuxstatus.LinuxStatus // what the Linux OS sees
|
||||
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
|
||||
// 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
|
||||
artificialS string `default:"abc"` // artificial sleep on startup
|
||||
|
@ -49,7 +51,6 @@ type Host struct {
|
|||
ipv6s map[string]dns.RR
|
||||
|
||||
// DNS stuff
|
||||
DnsAPI *gui.Node // what DNS API to use?
|
||||
DnsStatus *gui.Node // the current state of DNS
|
||||
DnsSpeed *gui.Node // 'FAST', 'OK', 'SLOW', etc
|
||||
DnsSpeedActual *gui.Node // the last actual duration
|
||||
|
|
Loading…
Reference in New Issue