everything auto-updates on open

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-03-26 16:17:32 -05:00
parent 53c8c54b15
commit 70a7ca6d75
5 changed files with 97 additions and 65 deletions

58
gui.go
View File

@ -33,6 +33,9 @@ func addDNSTab(title string) {
g2 = me.tab.NewGroup("Real Stuff") g2 = me.tab.NewGroup("Real Stuff")
g2.NewButton("gui.DebugWindow()", func () {
gui.DebugWindow()
})
g2.NewButton("Network Interfaces", func () { g2.NewButton("Network Interfaces", func () {
for i, t := range me.ifmap { for i, t := range me.ifmap {
log("name =", t.iface.Name) log("name =", t.iface.Name)
@ -73,9 +76,6 @@ func addDNSTab(title string) {
g2.NewButton("Escalate()", func () { g2.NewButton("Escalate()", func () {
Escalate() Escalate()
}) })
g2.NewButton("gui.DebugWindow()", func () {
gui.DebugWindow()
})
g2.NewButton("LookupAddr(<raw ipv6>) == fire from /etc/hosts", func () { g2.NewButton("LookupAddr(<raw ipv6>) == fire from /etc/hosts", func () {
host, err := net.LookupAddr("2600:1700:afd5:6000:b26e:bfff:fe80:3c52") host, err := net.LookupAddr("2600:1700:afd5:6000:b26e:bfff:fe80:3c52")
if err != nil { if err != nil {
@ -122,19 +122,38 @@ func nsupdateGroup(w *gui.Node) {
grid.NewLabel("DNS A =") grid.NewLabel("DNS A =")
me.DnsA = grid.NewLabel("?") 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 =") grid.NewLabel("DNS Status =")
me.DnsStatus = grid.NewLabel("unknown") 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 () { g.NewButton("Update DNS", func () {
updateDNS()
me.tab.Margin()
me.tab.Pad()
grid.Pad()
})
}
var outJunk string
func output(s string, a bool) {
if (a) {
outJunk += s
} else {
outJunk = s
}
me.output.SetText(outJunk)
log(outJunk)
}
func updateDNS() {
var aaaa []string var aaaa []string
h := me.hostname h := me.hostname
if (h == "") { if (h == "") {
@ -176,19 +195,4 @@ func nsupdateGroup(w *gui.Node) {
if (me.uid != nil) { if (me.uid != nil) {
me.uid.SetText(user.Username + " (" + strconv.Itoa(os.Getuid()) + ")") me.uid.SetText(user.Username + " (" + strconv.Itoa(os.Getuid()) + ")")
} }
me.tab.Margin()
me.tab.Pad()
grid.Pad()
})
}
var outJunk string
func output(s string, a bool) {
if (a) {
outJunk += s
} else {
outJunk = s
}
me.output.SetText(outJunk)
log(outJunk)
} }

View File

@ -28,9 +28,11 @@ func getHostname() {
if (me.fqdn != nil) { if (me.fqdn != nil) {
// s = me.fqdn.GetText() // s = me.fqdn.GetText()
log("trying to update gui.Label") log("trying to update gui.Label")
// me.fqdn.AddText(s) if (me.hostname != s) {
me.fqdn.SetText(s) me.fqdn.SetText(s)
me.hostname = s me.hostname = s
me.changed = true
}
} }
log("FQDN =", s) log("FQDN =", s)
} }

18
main.go
View File

@ -7,7 +7,7 @@ package main
import ( import (
"strconv" "strconv"
"runtime" "runtime"
// "net" "time"
arg "github.com/alexflint/go-arg" arg "github.com/alexflint/go-arg"
"git.wit.org/wit/gui" "git.wit.org/wit/gui"
) )
@ -71,17 +71,29 @@ func checkNetworkChanges() {
// Run this every once and a while // Run this every once and a while
func dnsTTL() { func dnsTTL() {
me.changed = false
log("FQDN =", me.fqdn.GetText()) log("FQDN =", me.fqdn.GetText())
getHostname() getHostname()
scanInterfaces() scanInterfaces()
for i, t := range me.ifmap { for i, t := range me.ifmap {
log(strconv.Itoa(i) + " iface = " + t.iface.Name) log(strconv.Itoa(i) + " iface = " + t.iface.Name)
} }
var aaaa []string var aaaa []string
aaaa = realAAAA() aaaa = realAAAA()
var all string
for _, s := range aaaa { for _, s := range aaaa {
log("my actual AAAA = ",s) log("my actual AAAA = ",s)
// me.IPv6.AddText(s) all += s + "\n"
me.IPv6.SetText(s) }
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)
} }
} }

24
net.go
View File

@ -78,7 +78,7 @@ func checkInterface(i net.Interface) {
me.ifmap[i.Index] = new(IFtype) me.ifmap[i.Index] = new(IFtype)
me.ifmap[i.Index].gone = false me.ifmap[i.Index].gone = false
me.ifmap[i.Index].iface = &i me.ifmap[i.Index].iface = &i
me.ipchange = true me.changed = true
if (me.Interfaces != nil) { if (me.Interfaces != nil) {
me.Interfaces.AddText(i.Name) me.Interfaces.AddText(i.Name)
me.Interfaces.SetText(i.Name) me.Interfaces.SetText(i.Name)
@ -90,7 +90,7 @@ func checkInterface(i net.Interface) {
if (val.iface.Name != i.Name) { if (val.iface.Name != i.Name) {
log(val.iface.Name, "has changed to it's name to", i.Name) log(val.iface.Name, "has changed to it's name to", i.Name)
me.ifmap[i.Index].iface = &i me.ifmap[i.Index].iface = &i
me.ipchange = true me.changed = true
if (me.Interfaces != nil) { if (me.Interfaces != nil) {
me.Interfaces.AddText(i.Name) me.Interfaces.AddText(i.Name)
me.Interfaces.SetText(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 me.ipmap[realip].ipv4 = false
t = "IPv6" t = "IPv6"
if (me.IPv6 != nil) { if (me.IPv6 != nil) {
me.IPv6.AddText(realip)
me.IPv6.SetText(realip) me.IPv6.SetText(realip)
} }
} else { } else {
me.ipmap[realip].ipv6 = false me.ipmap[realip].ipv6 = false
me.ipmap[realip].ipv4 = true me.ipmap[realip].ipv4 = true
if (me.IPv4 != nil) { if (me.IPv4 != nil) {
me.IPv4.AddText(realip)
me.IPv4.SetText(realip) me.IPv4.SetText(realip)
} }
} }
@ -189,7 +187,7 @@ func checkIP(ip *net.IPNet, i net.Interface) bool {
} }
func scanInterfaces() { func scanInterfaces() {
me.ipchange = false me.changed = false
ifaces, _ := net.Interfaces() ifaces, _ := net.Interfaces()
// me.ifnew = ifaces // me.ifnew = ifaces
log(DEBUGNET, SPEW, ifaces) log(DEBUGNET, SPEW, ifaces)
@ -215,6 +213,20 @@ func scanInterfaces() {
} }
} }
deleteChanges() 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 // delete network interfaces and ip addresses from the gui
@ -223,6 +235,7 @@ func deleteChanges() {
if (t.gone) { if (t.gone) {
log("DELETE int =", i, "name =", t.name, t.iface) log("DELETE int =", i, "name =", t.name, t.iface)
delete(me.ifmap, i) delete(me.ifmap, i)
me.changed = true
} }
t.gone = true t.gone = true
} }
@ -233,6 +246,7 @@ func deleteChanges() {
log("DELETE name =", s, "iface =", t.iface) log("DELETE name =", s, "iface =", t.iface)
log("DELETE name =", s, "ip =", t.ip) log("DELETE name =", s, "ip =", t.ip)
delete(me.ipmap, s) delete(me.ipmap, s)
me.changed = true
} }
t.gone = true t.gone = true
} }

View File

@ -14,11 +14,11 @@ type Host struct {
domainname string // kernel.org domainname string // kernel.org
// fqdn string // mirrors.kernel.org // fqdn string // mirrors.kernel.org
dnsTTL int // Recheck DNS is working every TTL (in seconds) dnsTTL int // Recheck DNS is working every TTL (in seconds)
changed bool // set to true if things changed
user string // name of the user user string // name of the user
ipmap map[string]*IPtype // the current ip addresses ipmap map[string]*IPtype // the current ip addresses
dnsmap map[string]*IPtype // the current dns addresses dnsmap map[string]*IPtype // the current dns addresses
ifmap map[int]*IFtype // the current interfaces ifmap map[int]*IFtype // the current interfaces
ipchange bool // set to true if things change
window *gui.Node // the main window window *gui.Node // the main window
tab *gui.Node // the main dns tab tab *gui.Node // the main dns tab
notes *gui.Node // using this to put notes here notes *gui.Node // using this to put notes here