From b8991ccf586159044c6a17b87654f10860fd22cb Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 6 Jan 2024 14:57:51 -0600 Subject: [PATCH] old window is nearly deprecated Signed-off-by: Jeff Carr --- linuxstatus/draw.go | 6 ++- linuxstatus/hostname.go | 4 +- linuxstatus/linuxloop.go | 13 ++--- linuxstatus/net.go | 2 +- linuxstatus/structs.go | 2 +- net.go | 111 +-------------------------------------- 6 files changed, 14 insertions(+), 124 deletions(-) diff --git a/linuxstatus/draw.go b/linuxstatus/draw.go index 6680f2d..5d28347 100644 --- a/linuxstatus/draw.go +++ b/linuxstatus/draw.go @@ -9,15 +9,17 @@ import ( // it's assumed you are always passing in a box func draw(ls *LinuxStatus) { if ! ls.Ready() {return} - ls.group = ls.window.Box().NewGroup("Real Stuff") + ls.group = ls.window.Box().NewGroup("What Linux Says It Is") ls.grid = ls.group.NewGrid("gridnuts", 2, 2) ls.grid.SetNext(1,1) + ls.fqdn = gadgets.NewOneLiner(ls.grid, "hostname -f") ls.hostshort = gadgets.NewOneLiner(ls.grid, "hostname -s") ls.domainname = gadgets.NewOneLiner(ls.grid, "domain name") - ls.NSrr = gadgets.NewOneLiner(ls.grid, "NS records =") + ls.resolver = gadgets.NewOneLiner(ls.grid, "nameservers =") + ls.resolver.Set("TODO") ls.uid = gadgets.NewOneLiner(ls.grid, "UID =") ls.IPv4 = gadgets.NewOneLiner(ls.grid, "Current IPv4 =") ls.IPv6 = gadgets.NewOneLiner(ls.grid, "Current IPv6 =") diff --git a/linuxstatus/hostname.go b/linuxstatus/hostname.go index 08c7971..78682dd 100644 --- a/linuxstatus/hostname.go +++ b/linuxstatus/hostname.go @@ -50,7 +50,7 @@ func (ls *LinuxStatus) GetHostShort() string { } func (ls *LinuxStatus) setHostShort() { - if ! me.Ready() {return ""} + if ! me.Ready() {return} hshort := run("hostname -s") if (me.hostshort.Get() != hshort) { log.Log(CHANGE, "hostname -s has changed from", me.hostshort.Get(), "to", hshort) @@ -71,7 +71,7 @@ func lookupHostname() { log.Error(errors.New("full hostname should be: " + s)) me.setDomainName() - + me.setHostShort() /* var test string diff --git a/linuxstatus/linuxloop.go b/linuxstatus/linuxloop.go index ba981aa..b2572d1 100644 --- a/linuxstatus/linuxloop.go +++ b/linuxstatus/linuxloop.go @@ -8,6 +8,7 @@ import ( "os" "os/user" "strconv" + "strings" "go.wit.com/log" ) @@ -23,14 +24,10 @@ func linuxLoop() { log.Log(NET, strconv.Itoa(i) + " iface = " + t.iface.Name) } - var aaaa []string - aaaa = dhcpAAAA() - var all string - for _, s := range aaaa { - log.Log(NET, "my actual AAAA = ",s) - all += s + "\n" - } - // me.IPv6.SetText(all) + // get all the real AAAA records from all the network interfaces linux can see + tmp := strings.Join(realAAAA(), "\n") + tmp = sortLines(tmp) + me.workingIPv6.Set(tmp) user, _ := user.Current() log.Log(INFO, "os.Getuid =", user.Username, os.Getuid()) diff --git a/linuxstatus/net.go b/linuxstatus/net.go index d86aac5..89f6de0 100644 --- a/linuxstatus/net.go +++ b/linuxstatus/net.go @@ -103,7 +103,7 @@ func checkInterface(i net.Interface) { These are the real IP address you have been given from DHCP */ -func dhcpAAAA() []string { +func realAAAA() []string { var aaaa []string for s, t := range me.ipmap { diff --git a/linuxstatus/structs.go b/linuxstatus/structs.go index 10fec02..a012074 100644 --- a/linuxstatus/structs.go +++ b/linuxstatus/structs.go @@ -30,7 +30,7 @@ type LinuxStatus struct { hostshort *gadgets.OneLiner domainname *gadgets.OneLiner fqdn *gadgets.OneLiner - NSrr *gadgets.OneLiner + resolver *gadgets.OneLiner uid *gadgets.OneLiner IPv4 *gadgets.OneLiner IPv6 *gadgets.OneLiner diff --git a/net.go b/net.go index 6f27c27..cd988d1 100644 --- a/net.go +++ b/net.go @@ -156,117 +156,8 @@ func checkDNS() (map[string]*IPtype, map[string]*IPtype) { return ipv6s, ipv4s } -// Will figure out if an IP address is new -func checkIP(ip *net.IPNet, i net.Interface) bool { - log.Log(NET, "\t\taddr.(type) = *net.IPNet") - log.Log(NET, "\t\taddr.(type) =", ip) - var realip string - realip = ip.IP.String() - - val, ok := me.ipmap[realip] - if ok { - log.Log(NET, val.ipnet.IP.String(), "is already a defined IP address") - me.ipmap[realip].gone = false - return false - } - - me.ipmap[realip] = new(IPtype) - me.ipmap[realip].gone = false - me.ipmap[realip].ipv4 = true - me.ipmap[realip].ipnet = ip - me.ipmap[realip].ip = ip.IP - me.ipmap[realip].iface = &i - t := "IPv4" - if (IsIPv6(ip.String())) { - me.ipmap[realip].ipv6 = true - me.ipmap[realip].ipv4 = false - t = "IPv6" - if (me.IPv6 != nil) { - me.IPv6.SetText(realip) - } - } else { - me.ipmap[realip].ipv6 = false - me.ipmap[realip].ipv4 = true - if (me.IPv4 != nil) { - me.IPv4.SetText(realip) - } - } - if (IsReal(&ip.IP)) { - log.Info("\tIP is Real ", t, i.Index, i.Name, realip) - } else { - log.Info("\tIP is not Real", t, i.Index, i.Name, realip) - } - log.Log(NET, "\t\tIP is IsPrivate() =", ip.IP.IsPrivate()) - log.Log(NET, "\t\tIP is IsLoopback() =", ip.IP.IsLoopback()) - log.Log(NET, "\t\tIP is IsLinkLocalUnicast() =", ip.IP.IsLinkLocalUnicast()) - // log.Info("HERE HERE", "realip =", realip, "me.ip[realip]=", me.ipmap[realip]) - return true -} - -func scanInterfaces() { - log.Log(NET, "scanInterfaces() START") - ifaces, _ := net.Interfaces() - // me.ifnew = ifaces - log.Log(NET, SPEW, ifaces) - for _, i := range ifaces { - addrs, _ := i.Addrs() - // log.Info("range ifaces = ", i) - checkInterface(i) - log.Log(NET, "*net.Interface.Name = ", i.Name, i.Index) - log.Log(NET, SPEW, i) - log.Log(NET, SPEW, addrs) - for _, addr := range addrs { - log.Log(NET, "\taddr =", addr) - log.Log(NET, SPEW, addrs) - ips, _ := net.LookupIP(addr.String()) - log.Log(NET, "\tLookupIP(addr) =", ips) - switch v := addr.(type) { - case *net.IPNet: - if checkIP(v, i) { - log.Log(true, "scanInterfaces() IP is new () i =", v.IP.String()) - } - default: - log.Log(NET, "\t\taddr.(type) = NO IDEA WHAT TO DO HERE v =", v) - } - } - } - if deleteChanges() { - me.changed = true - log.Log(NET, "deleteChanges() detected network changes") - } - updateRealAAAA() - log.Log(NET, "scanInterfaces() END") -} - -// displays the IP address found on your network interfaces -func updateRealAAAA() { - var all4 string - var all6 string - for s, t := range me.ipmap { - if (t.ipv4) { - all4 += s + "\n" - log.Log(NET, "IPv4 =", s) - } else if (t.ipv6) { - all6 += s + "\n" - log.Log(NET, "IPv6 =", s) - } else { - log.Log(NET, "???? =", s) - } - } - all4 = sortLines(all4) - all6 = sortLines(all6) - if (me.IPv4.S != all4) { - log.Log(NET, "IPv4 addresses have changed", all4) - me.IPv4.SetText(all4) - } - if (me.IPv6.S != all6) { - log.Log(NET, "IPv6 addresses have changed", all6) - me.IPv6.SetText(all6) - } -} - // delete network interfaces and ip addresses from the gui -func deleteChanges() bool { +func deleteChanges2() bool { var changed bool = false for i, t := range me.ifmap { if (t.gone) {