diff --git a/gui.go b/gui.go index a9773de..649a437 100644 --- a/gui.go +++ b/gui.go @@ -33,6 +33,9 @@ func addDNSTab(title string) { g2 = me.tab.NewGroup("Real Stuff") + g2.NewButton("gui.DebugWindow()", func () { + gui.DebugWindow() + }) g2.NewButton("Network Interfaces", func () { for i, t := range me.ifmap { log("name =", t.iface.Name) @@ -73,9 +76,6 @@ func addDNSTab(title string) { g2.NewButton("Escalate()", func () { Escalate() }) - g2.NewButton("gui.DebugWindow()", func () { - gui.DebugWindow() - }) g2.NewButton("LookupAddr() == fire from /etc/hosts", func () { host, err := net.LookupAddr("2600:1700:afd5:6000:b26e:bfff:fe80:3c52") if err != nil { @@ -122,60 +122,20 @@ func nsupdateGroup(w *gui.Node) { grid.NewLabel("DNS A =") me.DnsA = grid.NewLabel("?") + grid.NewLabel("IPv4 =") + me.IPv4 = grid.NewLabel("?") + + grid.NewLabel("IPv6 =") + me.IPv6 = grid.NewLabel("?") + + grid.NewLabel("interfaces =") + me.Interfaces = grid.NewCombobox("Interfaces") + grid.NewLabel("DNS Status =") me.DnsStatus = grid.NewLabel("unknown") - grid.NewLabel("IPv4 =") - me.IPv4 = grid.NewCombobox("foo(2,1)") - - grid.NewLabel("IPv6 =") - me.IPv6 = grid.NewCombobox("foo(1,3)") - - grid.NewLabel("interfaces =") - me.Interfaces = grid.NewCombobox("foo(1,3)") - g.NewButton("Update DNS", func () { - var aaaa []string - h := me.hostname - if (h == "") { - h = "unknown.lab.wit.org" - // h = "hpdevone.lab.wit.org" - } - aaaa = dnsAAAA(h) - log(SPEW, me) - if (aaaa == nil) { - log("There are no DNS AAAA records for hostname: ", h) - } - var broken int = 0 - var all string - for _, s := range aaaa { - log("host", h, "DNS AAAA =", s) - all += s + "\n" - if ( me.ipmap[s] == nil) { - log("THIS IS THE WRONG AAAA DNS ENTRY: host", h, "DNS AAAA =", s) - broken = 2 - } else { - if (broken == 0) { - broken = 1 - } - } - } - all = strings.TrimSuffix(all, "\r\n") - all = strings.TrimSuffix(all, "\n") - me.DnsAAAA.SetText(all) - if (broken == 1) { - me.DnsStatus.SetText("WORKING") - } else { - me.DnsStatus.SetText("BROKEN") - log("Need to run go-nsupdate here") - } - - user, _ := user.Current() - spew.Dump(user) - log("os.Getuid =", user.Username, os.Getuid()) - if (me.uid != nil) { - me.uid.SetText(user.Username + " (" + strconv.Itoa(os.Getuid()) + ")") - } + updateDNS() me.tab.Margin() me.tab.Pad() grid.Pad() @@ -192,3 +152,47 @@ func output(s string, a bool) { me.output.SetText(outJunk) log(outJunk) } + +func updateDNS() { + var aaaa []string + h := me.hostname + if (h == "") { + h = "unknown.lab.wit.org" + // h = "hpdevone.lab.wit.org" + } + aaaa = dnsAAAA(h) + log(SPEW, me) + if (aaaa == nil) { + log("There are no DNS AAAA records for hostname: ", h) + } + var broken int = 0 + var all string + for _, s := range aaaa { + log("host", h, "DNS AAAA =", s) + all += s + "\n" + if ( me.ipmap[s] == nil) { + log("THIS IS THE WRONG AAAA DNS ENTRY: host", h, "DNS AAAA =", s) + broken = 2 + } else { + if (broken == 0) { + broken = 1 + } + } + } + all = strings.TrimSuffix(all, "\r\n") + all = strings.TrimSuffix(all, "\n") + me.DnsAAAA.SetText(all) + if (broken == 1) { + me.DnsStatus.SetText("WORKING") + } else { + me.DnsStatus.SetText("BROKEN") + log("Need to run go-nsupdate here") + } + + user, _ := user.Current() + spew.Dump(user) + log("os.Getuid =", user.Username, os.Getuid()) + if (me.uid != nil) { + me.uid.SetText(user.Username + " (" + strconv.Itoa(os.Getuid()) + ")") + } +} diff --git a/hostname.go b/hostname.go index d385e4f..0690c2e 100644 --- a/hostname.go +++ b/hostname.go @@ -28,9 +28,11 @@ func getHostname() { if (me.fqdn != nil) { // s = me.fqdn.GetText() log("trying to update gui.Label") - // me.fqdn.AddText(s) - me.fqdn.SetText(s) - me.hostname = s + if (me.hostname != s) { + me.fqdn.SetText(s) + me.hostname = s + me.changed = true + } } log("FQDN =", s) } diff --git a/main.go b/main.go index 1a232e1..57acc16 100644 --- a/main.go +++ b/main.go @@ -7,7 +7,7 @@ package main import ( "strconv" "runtime" - // "net" + "time" arg "github.com/alexflint/go-arg" "git.wit.org/wit/gui" ) @@ -71,17 +71,29 @@ func checkNetworkChanges() { // Run this every once and a while func dnsTTL() { + me.changed = false log("FQDN =", me.fqdn.GetText()) getHostname() scanInterfaces() for i, t := range me.ifmap { log(strconv.Itoa(i) + " iface = " + t.iface.Name) } + var aaaa []string aaaa = realAAAA() + var all string for _, s := range aaaa { log("my actual AAAA = ",s) - // me.IPv6.AddText(s) - me.IPv6.SetText(s) + all += s + "\n" + } + me.IPv6.SetText(all) + + if (me.changed) { + stamp := time.Now().Format("2006/01/02 15:04:05") + s := stamp + " Network things changed" + log(logError, "Network things changed on", stamp) + updateDNS() + me.output.SetText(s) + } } diff --git a/net.go b/net.go index 7731f77..0c80790 100644 --- a/net.go +++ b/net.go @@ -78,7 +78,7 @@ func checkInterface(i net.Interface) { me.ifmap[i.Index] = new(IFtype) me.ifmap[i.Index].gone = false me.ifmap[i.Index].iface = &i - me.ipchange = true + me.changed = true if (me.Interfaces != nil) { me.Interfaces.AddText(i.Name) me.Interfaces.SetText(i.Name) @@ -90,7 +90,7 @@ func checkInterface(i net.Interface) { if (val.iface.Name != i.Name) { log(val.iface.Name, "has changed to it's name to", i.Name) me.ifmap[i.Index].iface = &i - me.ipchange = true + me.changed = true if (me.Interfaces != nil) { me.Interfaces.AddText(i.Name) me.Interfaces.SetText(i.Name) @@ -165,14 +165,12 @@ func checkIP(ip *net.IPNet, i net.Interface) bool { me.ipmap[realip].ipv4 = false t = "IPv6" if (me.IPv6 != nil) { - me.IPv6.AddText(realip) me.IPv6.SetText(realip) } } else { me.ipmap[realip].ipv6 = false me.ipmap[realip].ipv4 = true if (me.IPv4 != nil) { - me.IPv4.AddText(realip) me.IPv4.SetText(realip) } } @@ -189,7 +187,7 @@ func checkIP(ip *net.IPNet, i net.Interface) bool { } func scanInterfaces() { - me.ipchange = false + me.changed = false ifaces, _ := net.Interfaces() // me.ifnew = ifaces log(DEBUGNET, SPEW, ifaces) @@ -215,6 +213,20 @@ func scanInterfaces() { } } deleteChanges() + var all4 string + var all6 string + for s, t := range me.ipmap { + log("HAVE name =", s, "IPv4 =", t.ipv4) + log("HAVE name =", s, "IPv6 =", t.ipv6) + if (t.ipv4) { + all4 += s + "\n" + } + if (t.ipv6) { + all6 += s + "\n" + } + } + me.IPv4.SetText(all4) + me.IPv6.SetText(all6) } // delete network interfaces and ip addresses from the gui @@ -223,6 +235,7 @@ func deleteChanges() { if (t.gone) { log("DELETE int =", i, "name =", t.name, t.iface) delete(me.ifmap, i) + me.changed = true } t.gone = true } @@ -233,6 +246,7 @@ func deleteChanges() { log("DELETE name =", s, "iface =", t.iface) log("DELETE name =", s, "ip =", t.ip) delete(me.ipmap, s) + me.changed = true } t.gone = true } diff --git a/structs.go b/structs.go index 5134f03..0f91a9f 100644 --- a/structs.go +++ b/structs.go @@ -14,11 +14,11 @@ type Host struct { domainname string // kernel.org // fqdn string // mirrors.kernel.org dnsTTL int // Recheck DNS is working every TTL (in seconds) + changed bool // set to true if things changed user string // name of the user ipmap map[string]*IPtype // the current ip addresses dnsmap map[string]*IPtype // the current dns addresses ifmap map[int]*IFtype // the current interfaces - ipchange bool // set to true if things change window *gui.Node // the main window tab *gui.Node // the main dns tab notes *gui.Node // using this to put notes here