Compare commits
No commits in common. "15d9f9769360b1cb8c748de8ee995030ade5eb35" and "8b59a3141a6bd70eb8b434edbe347c3a22bfb3d6" have entirely different histories.
15d9f97693
...
8b59a3141a
9
args.go
9
args.go
|
@ -19,7 +19,6 @@ var args struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var NOW log.LogFlag
|
var NOW log.LogFlag
|
||||||
var INFO log.LogFlag
|
|
||||||
var NET log.LogFlag
|
var NET log.LogFlag
|
||||||
var DNS log.LogFlag
|
var DNS log.LogFlag
|
||||||
var PROC log.LogFlag
|
var PROC log.LogFlag
|
||||||
|
@ -37,12 +36,6 @@ func init() {
|
||||||
NOW.Desc = "temp debugging stuff"
|
NOW.Desc = "temp debugging stuff"
|
||||||
NOW.Register()
|
NOW.Register()
|
||||||
|
|
||||||
INFO.B = false
|
|
||||||
INFO.Name = "INFO"
|
|
||||||
INFO.Subsystem = "cpdns"
|
|
||||||
INFO.Desc = "normal debugging stuff"
|
|
||||||
INFO.Register()
|
|
||||||
|
|
||||||
NET.B = false
|
NET.B = false
|
||||||
NET.Name = "NET"
|
NET.Name = "NET"
|
||||||
NET.Subsystem = "cpdns"
|
NET.Subsystem = "cpdns"
|
||||||
|
@ -67,7 +60,7 @@ func init() {
|
||||||
SPEW.Desc = "spew logging"
|
SPEW.Desc = "spew logging"
|
||||||
SPEW.Register()
|
SPEW.Register()
|
||||||
|
|
||||||
CHANGE.B = true
|
CHANGE.B = false
|
||||||
CHANGE.Name = "CHANGE"
|
CHANGE.Name = "CHANGE"
|
||||||
CHANGE.Subsystem = "cpdns"
|
CHANGE.Subsystem = "cpdns"
|
||||||
CHANGE.Desc = "show droplet state changes"
|
CHANGE.Desc = "show droplet state changes"
|
||||||
|
|
|
@ -207,8 +207,8 @@ func (ds *digStatus) updateDnsStatus() {
|
||||||
ipv4, ipv6 = ds.dsCloudflare.update()
|
ipv4, ipv6 = ds.dsCloudflare.update()
|
||||||
ipv4, ipv6 = ds.dsGoogle.update()
|
ipv4, ipv6 = ds.dsGoogle.update()
|
||||||
|
|
||||||
if me.statusOS.ValidHostname() {
|
if me.status.ValidHostname() {
|
||||||
if ds.checkLookupDoH(me.statusOS.GetHostname()) {
|
if ds.checkLookupDoH(me.status.GetHostname()) {
|
||||||
log.Log(DNS, "updateDnsStatus() HTTP DNS lookups working")
|
log.Log(DNS, "updateDnsStatus() HTTP DNS lookups working")
|
||||||
me.digStatus.set(ds.statusHTTP, "WORKING")
|
me.digStatus.set(ds.statusHTTP, "WORKING")
|
||||||
} else {
|
} else {
|
||||||
|
|
30
dns-https.go
30
dns-https.go
|
@ -2,13 +2,10 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"go.wit.com/log"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"go.wit.com/log"
|
|
||||||
"github.com/miekg/dns"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// dnsLookupDoH performs a DNS lookup for AAAA records over HTTPS.
|
// dnsLookupDoH performs a DNS lookup for AAAA records over HTTPS.
|
||||||
|
@ -57,28 +54,3 @@ func lookupDoH(hostname string, rrType string) []string {
|
||||||
|
|
||||||
return values
|
return values
|
||||||
}
|
}
|
||||||
|
|
||||||
func digAAAA(hostname string) []string {
|
|
||||||
var blah, ipv6Addresses []string
|
|
||||||
// domain := hostname
|
|
||||||
recordType := dns.TypeAAAA // dns.TypeTXT
|
|
||||||
|
|
||||||
// Cloudflare's DNS server
|
|
||||||
blah, _ = dnsUdpLookup("1.1.1.1:53", hostname, recordType)
|
|
||||||
log.Println("digAAAA() has BLAH =", blah)
|
|
||||||
|
|
||||||
if (len(blah) == 0) {
|
|
||||||
log.Println("digAAAA() RUNNING dnsAAAAlookupDoH(domain)")
|
|
||||||
ipv6Addresses = lookupDoH(hostname, "AAAA")
|
|
||||||
log.Println("digAAAA() has ipv6Addresses =", strings.Join(ipv6Addresses, " "))
|
|
||||||
for _, addr := range ipv6Addresses {
|
|
||||||
log.Println(addr)
|
|
||||||
}
|
|
||||||
return ipv6Addresses
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: check digDoH vs blah, if so, then port 53 TCP and/or UDP is broken or blocked
|
|
||||||
log.Println("digAAAA() has BLAH =", blah)
|
|
||||||
|
|
||||||
return blah
|
|
||||||
}
|
|
||||||
|
|
4
dns.go
4
dns.go
|
@ -111,10 +111,10 @@ func lookupNS(domain string) {
|
||||||
}
|
}
|
||||||
tmp = shell.Chomp(tmp)
|
tmp = shell.Chomp(tmp)
|
||||||
|
|
||||||
if (tmp != me.status.NSrr.Get()) {
|
if (tmp != me.NSrr.S) {
|
||||||
me.changed = true
|
me.changed = true
|
||||||
log.Log(CHANGE, "lookupNS() setting me.NSrr =", tmp)
|
log.Log(CHANGE, "lookupNS() setting me.NSrr =", tmp)
|
||||||
me.status.NSrr.Set(tmp)
|
me.NSrr.SetText(tmp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
6
fix.go
6
fix.go
|
@ -11,10 +11,10 @@ func fix() bool {
|
||||||
log.Warn("The IPv6 Control Panel is not Ready() yet")
|
log.Warn("The IPv6 Control Panel is not Ready() yet")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if me.statusOS.ValidHostname() {
|
if me.status.ValidHostname() {
|
||||||
log.Warn("Your hostname is VALID:", me.statusOS.GetHostname())
|
log.Warn("Your hostname is VALID:", me.status.GetHostname())
|
||||||
} else {
|
} else {
|
||||||
log.Warn("You must first fix your hostname:", me.statusOS.GetHostname())
|
log.Warn("You must first fix your hostname:", me.status.GetHostname())
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if me.digStatus.IPv4() {
|
if me.digStatus.IPv4() {
|
||||||
|
|
81
gui.go
81
gui.go
|
@ -22,9 +22,57 @@ func setupControlPanelWindow() {
|
||||||
|
|
||||||
// setup the main tab
|
// setup the main tab
|
||||||
mainWindow("DNS and IPv6 Control Panel")
|
mainWindow("DNS and IPv6 Control Panel")
|
||||||
|
detailsTab("OS Details")
|
||||||
debugTab("Debug")
|
debugTab("Debug")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func detailsTab(title string) {
|
||||||
|
var g2 *gui.Node
|
||||||
|
|
||||||
|
me.details = gadgets.NewBasicWindow(me.myGui, title)
|
||||||
|
me.details.Draw()
|
||||||
|
me.details.Hide()
|
||||||
|
|
||||||
|
g2 = me.details.Box().NewGroup("Real Stuff")
|
||||||
|
|
||||||
|
grid := g2.NewGrid("gridnuts", 2, 2)
|
||||||
|
|
||||||
|
grid.SetNext(1,1)
|
||||||
|
|
||||||
|
grid.NewLabel("domainname =")
|
||||||
|
grid.NewLabel("DEPRECATED")
|
||||||
|
// me.domainname = grid.NewLabel("domainname")
|
||||||
|
|
||||||
|
grid.NewLabel("hostname -s =")
|
||||||
|
me.hostshort = grid.NewLabel("hostname -s")
|
||||||
|
|
||||||
|
grid.NewLabel("NS records =")
|
||||||
|
me.NSrr = grid.NewLabel("NS RR's")
|
||||||
|
|
||||||
|
grid.NewLabel("UID =")
|
||||||
|
grid.NewLabel("DEPRECATED")
|
||||||
|
|
||||||
|
grid.NewLabel("Current IPv4 =")
|
||||||
|
me.IPv4 = grid.NewLabel("?")
|
||||||
|
|
||||||
|
grid.NewLabel("Current IPv6 =")
|
||||||
|
me.IPv6 = grid.NewLabel("?")
|
||||||
|
|
||||||
|
grid.NewLabel("Working Real IPv6 =")
|
||||||
|
me.workingIPv6 = grid.NewLabel("?")
|
||||||
|
|
||||||
|
grid.NewLabel("interfaces =")
|
||||||
|
me.Interfaces = grid.NewCombobox("Interfaces")
|
||||||
|
|
||||||
|
grid.NewLabel("refresh speed")
|
||||||
|
me.LocalSpeedActual = grid.NewLabel("unknown")
|
||||||
|
|
||||||
|
grid.Margin()
|
||||||
|
grid.Pad()
|
||||||
|
|
||||||
|
me.details.Hide()
|
||||||
|
}
|
||||||
|
|
||||||
func debugTab(title string) {
|
func debugTab(title string) {
|
||||||
var g2 *gui.Node
|
var g2 *gui.Node
|
||||||
|
|
||||||
|
@ -38,6 +86,10 @@ func debugTab(title string) {
|
||||||
debugger.DebugWindow(me.myGui)
|
debugger.DebugWindow(me.myGui)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
g2.NewButton("getHostname() looks at the OS settings", func () {
|
||||||
|
getHostname()
|
||||||
|
})
|
||||||
|
|
||||||
g2.NewButton("dig A & AAAA DNS records", func () {
|
g2.NewButton("dig A & AAAA DNS records", func () {
|
||||||
log.Println("updateDNS()")
|
log.Println("updateDNS()")
|
||||||
updateDNS()
|
updateDNS()
|
||||||
|
@ -98,7 +150,7 @@ func missingAAAA() string {
|
||||||
// it just updates the GUI
|
// it just updates the GUI
|
||||||
func displayDNS() string {
|
func displayDNS() string {
|
||||||
var aaaa []string
|
var aaaa []string
|
||||||
aaaa = append(aaaa, "blah", "more")
|
aaaa = dhcpAAAA() // your AAAA records right now
|
||||||
// h := me.hostname
|
// h := me.hostname
|
||||||
var all string
|
var all string
|
||||||
var broken string = "unknown"
|
var broken string = "unknown"
|
||||||
|
@ -114,6 +166,11 @@ func displayDNS() string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
all = sortLines(all)
|
||||||
|
if (me.workingIPv6.S != all) {
|
||||||
|
log.Log(NOW, "workingIPv6.SetText() to:", all)
|
||||||
|
me.workingIPv6.SetText(all)
|
||||||
|
}
|
||||||
|
|
||||||
var a []string
|
var a []string
|
||||||
a = realA()
|
a = realA()
|
||||||
|
@ -142,7 +199,9 @@ func mainWindow(title string) {
|
||||||
|
|
||||||
grid.SetNext(1,1)
|
grid.SetNext(1,1)
|
||||||
|
|
||||||
me.hostname = gadgets.NewOneLiner(grid, "hostname =").Set("unknown")
|
grid.NewLabel("hostname =")
|
||||||
|
me.fqdn = grid.NewLabel("?")
|
||||||
|
|
||||||
me.DnsAAAA = gadgets.NewOneLiner(grid, "DNS AAAA =").Set("unknown")
|
me.DnsAAAA = gadgets.NewOneLiner(grid, "DNS AAAA =").Set("unknown")
|
||||||
|
|
||||||
grid.NewLabel("DNS A =")
|
grid.NewLabel("DNS A =")
|
||||||
|
@ -164,26 +223,22 @@ func mainWindow(title string) {
|
||||||
me.status.window.Toggle()
|
me.status.window.Toggle()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
gr.NewButton("OS details", func () {
|
||||||
|
me.details.Toggle()
|
||||||
|
})
|
||||||
gr.NewButton("linuxstatus.New()", func () {
|
gr.NewButton("linuxstatus.New()", func () {
|
||||||
if (me.statusOS == nil) {
|
|
||||||
me.statusOS = linuxstatus.New()
|
me.statusOS = linuxstatus.New()
|
||||||
}
|
|
||||||
me.statusOS.SetParent(me.myGui)
|
|
||||||
me.statusOS.InitWindow()
|
|
||||||
me.statusOS.Make()
|
|
||||||
me.statusOS.Draw2()
|
|
||||||
})
|
})
|
||||||
gr.NewButton("statusOS.Ready()", func () {
|
gr.NewButton("statusOS.Ready()", func () {
|
||||||
me.statusOS.Ready()
|
me.statusOS.Ready()
|
||||||
})
|
})
|
||||||
gr.NewButton("statusOS.Draw()", func () {
|
gr.NewButton("statusOS.Draw()", func () {
|
||||||
me.statusOS.Draw()
|
me.statusOS.Ready()
|
||||||
me.statusOS.Draw2()
|
|
||||||
})
|
})
|
||||||
gr.NewButton("statusOS.Update()", func () {
|
gr.NewButton("statusOS.Update()", func () {
|
||||||
me.statusOS.Update()
|
me.statusOS.Update()
|
||||||
})
|
})
|
||||||
gr.NewButton("Linux Status", func () {
|
gr.NewButton("Linux details", func () {
|
||||||
me.statusOS.Toggle()
|
me.statusOS.Toggle()
|
||||||
})
|
})
|
||||||
gr.NewButton("resolver status", func () {
|
gr.NewButton("resolver status", func () {
|
||||||
|
@ -247,9 +302,9 @@ func updateDNS() {
|
||||||
|
|
||||||
// log.Println("digAAAA()")
|
// log.Println("digAAAA()")
|
||||||
|
|
||||||
if me.statusOS.ValidHostname() {
|
if me.status.ValidHostname() {
|
||||||
var aaaa []string
|
var aaaa []string
|
||||||
h := me.statusOS.GetHostname()
|
h := me.status.GetHostname()
|
||||||
aaaa = digAAAA(h)
|
aaaa = digAAAA(h)
|
||||||
log.Log(NOW, "digAAAA() for", h, "=", aaaa)
|
log.Log(NOW, "digAAAA() for", h, "=", aaaa)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,92 @@
|
||||||
|
// figures out if your hostname is valid
|
||||||
|
// then checks if your DNS is setup correctly
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"go.wit.com/log"
|
||||||
|
"go.wit.com/shell"
|
||||||
|
// "go.wit.com/gui/cloudflare"
|
||||||
|
|
||||||
|
"github.com/miekg/dns"
|
||||||
|
// will try to get this hosts FQDN
|
||||||
|
"github.com/Showmax/go-fqdn"
|
||||||
|
)
|
||||||
|
|
||||||
|
func getHostname() {
|
||||||
|
var err error
|
||||||
|
var s string = "gui.Label == nil"
|
||||||
|
s, err = fqdn.FqdnHostname()
|
||||||
|
if (err != nil) {
|
||||||
|
log.Error(err, "FQDN hostname error")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
me.status.SetHostname(s)
|
||||||
|
|
||||||
|
dn := run("domainname")
|
||||||
|
hshort := run("hostname -s")
|
||||||
|
|
||||||
|
var test string
|
||||||
|
test = hshort + "." + dn
|
||||||
|
if (me.status.GetHostname() != test) {
|
||||||
|
log.Log(CHANGE, "me.hostname", me.status.GetHostname(), "does not equal", test)
|
||||||
|
if (me.hostnameStatus.S != "BROKEN") {
|
||||||
|
log.Log(CHANGE, "me.hostname", me.status.GetHostname(), "does not equal", test)
|
||||||
|
me.changed = true
|
||||||
|
me.hostnameStatus.SetText("BROKEN")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (me.hostnameStatus.S != "VALID") {
|
||||||
|
log.Log(CHANGE, "me.hostname", me.status.GetHostname(), "is valid")
|
||||||
|
me.hostnameStatus.SetText("VALID")
|
||||||
|
me.changed = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns true if the hostname is good
|
||||||
|
// check that all the OS settings are correct here
|
||||||
|
// On Linux, /etc/hosts, /etc/hostname
|
||||||
|
// and domainname and hostname
|
||||||
|
func goodHostname() bool {
|
||||||
|
hostname := shell.Chomp(shell.Cat("/etc/hostname"))
|
||||||
|
log.Log(NOW, "hostname =", hostname)
|
||||||
|
|
||||||
|
hs := run("hostname -s")
|
||||||
|
dn := run("domainname")
|
||||||
|
log.Log(NOW, "hostname short =", hs, "domainname =", dn)
|
||||||
|
|
||||||
|
tmp := hs + "." + dn
|
||||||
|
if (hostname == tmp) {
|
||||||
|
log.Log(NOW, "hostname seems to be good", hostname)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func digAAAA(hostname string) []string {
|
||||||
|
var blah, ipv6Addresses []string
|
||||||
|
// domain := hostname
|
||||||
|
recordType := dns.TypeAAAA // dns.TypeTXT
|
||||||
|
|
||||||
|
// Cloudflare's DNS server
|
||||||
|
blah, _ = dnsUdpLookup("1.1.1.1:53", hostname, recordType)
|
||||||
|
log.Println("digAAAA() has BLAH =", blah)
|
||||||
|
|
||||||
|
if (len(blah) == 0) {
|
||||||
|
log.Println("digAAAA() RUNNING dnsAAAAlookupDoH(domain)")
|
||||||
|
ipv6Addresses = lookupDoH(hostname, "AAAA")
|
||||||
|
log.Println("digAAAA() has ipv6Addresses =", strings.Join(ipv6Addresses, " "))
|
||||||
|
for _, addr := range ipv6Addresses {
|
||||||
|
log.Println(addr)
|
||||||
|
}
|
||||||
|
return ipv6Addresses
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: check digDoH vs blah, if so, then port 53 TCP and/or UDP is broken or blocked
|
||||||
|
log.Println("digAAAA() has BLAH =", blah)
|
||||||
|
|
||||||
|
return blah
|
||||||
|
}
|
|
@ -42,7 +42,6 @@ type hostnameStatus struct {
|
||||||
currentIPv6 *gadgets.OneLiner
|
currentIPv6 *gadgets.OneLiner
|
||||||
|
|
||||||
// what the DNS servers have
|
// what the DNS servers have
|
||||||
NSrr *gadgets.OneLiner
|
|
||||||
dnsA *gadgets.OneLiner
|
dnsA *gadgets.OneLiner
|
||||||
dnsAAAA *gadgets.OneLiner
|
dnsAAAA *gadgets.OneLiner
|
||||||
dnsAPI *gadgets.OneLiner
|
dnsAPI *gadgets.OneLiner
|
||||||
|
@ -85,7 +84,6 @@ func NewHostnameStatusWindow(p *gui.Node) *hostnameStatus {
|
||||||
hs.currentIPv4 = gadgets.NewOneLiner(grid, "Current IPv4")
|
hs.currentIPv4 = gadgets.NewOneLiner(grid, "Current IPv4")
|
||||||
hs.currentIPv6 = gadgets.NewOneLiner(grid, "Current IPv6")
|
hs.currentIPv6 = gadgets.NewOneLiner(grid, "Current IPv6")
|
||||||
|
|
||||||
hs.NSrr = gadgets.NewOneLiner(grid, "dns NS records").Set("unknown")
|
|
||||||
hs.dnsAPI = gadgets.NewOneLiner(grid, "dns API provider").Set("unknown")
|
hs.dnsAPI = gadgets.NewOneLiner(grid, "dns API provider").Set("unknown")
|
||||||
hs.dnsA = gadgets.NewOneLiner(grid, "dns IPv4 resource records").Set("unknown")
|
hs.dnsA = gadgets.NewOneLiner(grid, "dns IPv4 resource records").Set("unknown")
|
||||||
hs.dnsAAAA = gadgets.NewOneLiner(grid, "dns IPv6 resource records").Set("unknown")
|
hs.dnsAAAA = gadgets.NewOneLiner(grid, "dns IPv6 resource records").Set("unknown")
|
||||||
|
@ -120,11 +118,24 @@ func NewHostnameStatusWindow(p *gui.Node) *hostnameStatus {
|
||||||
return hs
|
return hs
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
func (hs *hostnameStatus) ValidHostname() bool {
|
func (hs *hostnameStatus) ValidHostname() bool {
|
||||||
return goodHostname()
|
return goodHostname()
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
func (hs *hostnameStatus) GetHostname() string {
|
||||||
|
return hs.lastname
|
||||||
|
}
|
||||||
|
|
||||||
|
func (hs *hostnameStatus) SetHostname(hostname string) {
|
||||||
|
if hostname == hs.lastname {return}
|
||||||
|
log.Log(CHANGE, "the hostname is changing from", hs.lastname, "to", hostname)
|
||||||
|
hs.lastname = hostname
|
||||||
|
me.changed = true
|
||||||
|
|
||||||
|
if (me.fqdn != nil) {
|
||||||
|
me.fqdn.SetText(hostname)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (hs *hostnameStatus) Domain() string {
|
func (hs *hostnameStatus) Domain() string {
|
||||||
if ! hs.Ready() {return ""}
|
if ! hs.Ready() {return ""}
|
||||||
|
@ -285,13 +296,13 @@ func (hs *hostnameStatus) updateStatus() {
|
||||||
var vals []string
|
var vals []string
|
||||||
log.Log(STATUS, "updateStatus() START")
|
log.Log(STATUS, "updateStatus() START")
|
||||||
|
|
||||||
hs.hostShort.Set(me.statusOS.GetHostShort())
|
hs.hostShort.Set(me.hostshort.S)
|
||||||
hs.domainname.Set(me.statusOS.GetDomainName())
|
hs.domainname.Set(me.statusOS.GetDomainName())
|
||||||
|
|
||||||
if me.statusOS.ValidHostname() {
|
if hs.ValidHostname() {
|
||||||
vals = lookupDoH(me.statusOS.GetHostname(), "AAAA")
|
vals = lookupDoH(hs.GetHostname(), "AAAA")
|
||||||
|
|
||||||
log.Log(STATUS, "DNS IPv6 Addresses for ", me.statusOS.GetHostname(), "=", vals)
|
log.Log(STATUS, "DNS IPv6 Addresses for ", hs.GetHostname(), "=", vals)
|
||||||
if len(vals) == 0 {
|
if len(vals) == 0 {
|
||||||
s = "(none)"
|
s = "(none)"
|
||||||
} else {
|
} else {
|
||||||
|
@ -311,8 +322,8 @@ func (hs *hostnameStatus) updateStatus() {
|
||||||
}
|
}
|
||||||
hs.set(hs.dnsAAAA, s)
|
hs.set(hs.dnsAAAA, s)
|
||||||
|
|
||||||
vals = lookupDoH(me.statusOS.GetHostname(), "A")
|
vals = lookupDoH(hs.GetHostname(), "A")
|
||||||
log.Log(STATUS, "IPv4 Addresses for ", me.statusOS.GetHostname(), "=", vals)
|
log.Log(STATUS, "IPv4 Addresses for ", hs.GetHostname(), "=", vals)
|
||||||
s = strings.Join(vals, "\n")
|
s = strings.Join(vals, "\n")
|
||||||
if (s == "") {
|
if (s == "") {
|
||||||
s = "(none)"
|
s = "(none)"
|
||||||
|
@ -320,7 +331,7 @@ func (hs *hostnameStatus) updateStatus() {
|
||||||
}
|
}
|
||||||
hs.set(hs.dnsA, s)
|
hs.set(hs.dnsA, s)
|
||||||
|
|
||||||
vals = lookupDoH(me.statusOS.GetHostname(), "CNAME")
|
vals = lookupDoH(hs.GetHostname(), "CNAME")
|
||||||
s = strings.Join(vals, "\n")
|
s = strings.Join(vals, "\n")
|
||||||
if (s != "") {
|
if (s != "") {
|
||||||
hs.set(hs.dnsA, "CNAME " + s)
|
hs.set(hs.dnsA, "CNAME " + s)
|
||||||
|
@ -328,10 +339,8 @@ func (hs *hostnameStatus) updateStatus() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// hs.currentIPv4.Set(me.IPv4.S)
|
hs.currentIPv4.Set(me.IPv4.S)
|
||||||
// hs.currentIPv6.Set(me.IPv6.S)
|
hs.currentIPv6.Set(me.IPv6.S)
|
||||||
hs.currentIPv4.Set("get this from linuxStatus")
|
|
||||||
hs.currentIPv6.Set("get this from linuxStatus")
|
|
||||||
|
|
||||||
if hs.IPv4() && hs.IPv6() {
|
if hs.IPv4() && hs.IPv6() {
|
||||||
hs.status.Set("GOOD")
|
hs.status.Set("GOOD")
|
||||||
|
|
|
@ -9,31 +9,53 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var NOW log.LogFlag
|
var NOW log.LogFlag
|
||||||
var INFO log.LogFlag
|
|
||||||
var NET log.LogFlag
|
var NET log.LogFlag
|
||||||
var DNS log.LogFlag
|
var DNS log.LogFlag
|
||||||
var PROC log.LogFlag
|
var PROC log.LogFlag
|
||||||
var SPEW log.LogFlag
|
var SPEW log.LogFlag
|
||||||
var WARN log.LogFlag
|
|
||||||
var CHANGE log.LogFlag
|
var CHANGE log.LogFlag
|
||||||
var STATUS log.LogFlag
|
var STATUS log.LogFlag
|
||||||
|
|
||||||
func myreg(f *log.LogFlag, b bool, name string, desc string) {
|
|
||||||
f.B = b
|
|
||||||
f.Subsystem = "go.wit.com/control-panels/dns/linuxstatus"
|
|
||||||
f.Short = "linux"
|
|
||||||
f.Desc = desc
|
|
||||||
f.Name = name
|
|
||||||
f.Register()
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
myreg(&NOW, true, "NOW", "temp debugging stuff")
|
NOW.B = false
|
||||||
myreg(&NET, false, "NET", "Network Logging")
|
NOW.Name = "NOW"
|
||||||
myreg(&DNS, false, "DNS", "dnsStatus.update()")
|
NOW.Subsystem = "cpdns"
|
||||||
myreg(&PROC, false, "PROC", "/proc logging")
|
NOW.Desc = "temp debugging stuff"
|
||||||
myreg(&SPEW, false, "SPEW", "spew stuff")
|
NOW.Register()
|
||||||
myreg(&WARN, true, "WARN", "bad things")
|
|
||||||
myreg(&CHANGE, true, "CHANGE", "show droplet state changes")
|
NET.B = false
|
||||||
myreg(&STATUS, false, "STATUS", "Update() details")
|
NET.Name = "NET"
|
||||||
|
NET.Subsystem = "cpdns"
|
||||||
|
NET.Desc = "Network logging"
|
||||||
|
NET.Register()
|
||||||
|
|
||||||
|
DNS.B = false
|
||||||
|
DNS.Name = "DNS"
|
||||||
|
DNS.Subsystem = "cpdns"
|
||||||
|
DNS.Desc = "dnsStatus.update()"
|
||||||
|
DNS.Register()
|
||||||
|
|
||||||
|
PROC.B = false
|
||||||
|
PROC.Name = "PROC"
|
||||||
|
PROC.Subsystem = "cpdns"
|
||||||
|
PROC.Desc = "/proc logging"
|
||||||
|
PROC.Register()
|
||||||
|
|
||||||
|
SPEW.B = false
|
||||||
|
SPEW.Name = "SPEW"
|
||||||
|
SPEW.Subsystem = "cpdns"
|
||||||
|
SPEW.Desc = "spew logging"
|
||||||
|
SPEW.Register()
|
||||||
|
|
||||||
|
CHANGE.B = false
|
||||||
|
CHANGE.Name = "CHANGE"
|
||||||
|
CHANGE.Subsystem = "cpdns"
|
||||||
|
CHANGE.Desc = "show droplet state changes"
|
||||||
|
CHANGE.Register()
|
||||||
|
|
||||||
|
STATUS.B = false
|
||||||
|
STATUS.Name = "STATUS"
|
||||||
|
STATUS.Subsystem = "cpdns"
|
||||||
|
STATUS.Desc = "updateStatus()"
|
||||||
|
STATUS.Register()
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,87 +3,32 @@ package linuxstatus
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
"go.wit.com/gui/gui"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// reports externally if something has changed
|
func (hs *LinuxStatus) Show() {
|
||||||
// since the last time it was asked about it
|
log.Log(CHANGE, "linuxStatus.Show() window")
|
||||||
func (ls *LinuxStatus) Changed() bool {
|
hs.window.Show()
|
||||||
if ! ls.Ready() {return false}
|
hs.hidden = false
|
||||||
if ls.changed {
|
|
||||||
ls.changed = false
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ls *LinuxStatus) Make() {
|
func (hs *LinuxStatus) Hide() {
|
||||||
if ! ls.Ready() {return}
|
log.Log(CHANGE, "linuxStatus.Hide() window")
|
||||||
log.Log(CHANGE, "Make() window ready =", ls.ready)
|
hs.window.Hide()
|
||||||
ls.window.Make()
|
hs.hidden = true
|
||||||
ls.ready = true
|
|
||||||
}
|
|
||||||
func (ls *LinuxStatus) Draw() {
|
|
||||||
if ! ls.Ready() {return}
|
|
||||||
log.Log(CHANGE, "Draw() window ready =", ls.ready)
|
|
||||||
ls.window.Draw()
|
|
||||||
ls.ready = true
|
|
||||||
}
|
|
||||||
func (ls *LinuxStatus) Draw2() {
|
|
||||||
if ! ls.Ready() {return}
|
|
||||||
log.Log(CHANGE, "draw(ls) ready =", ls.ready)
|
|
||||||
draw(ls)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ls *LinuxStatus) Show() {
|
func (hs *LinuxStatus) Toggle() {
|
||||||
if ! ls.Ready() {return}
|
log.Log(CHANGE, "linuxStatus.Toggle() window")
|
||||||
log.Log(CHANGE, "Show() window ready =", ls.ready)
|
if hs.hidden {
|
||||||
ls.window.Show()
|
hs.window.Show()
|
||||||
ls.hidden = false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ls *LinuxStatus) Hide() {
|
|
||||||
if ! ls.Ready() {return}
|
|
||||||
log.Log(CHANGE, "Hide() window ready =", ls.ready)
|
|
||||||
ls.window.Hide()
|
|
||||||
ls.hidden = true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ls *LinuxStatus) Toggle() {
|
|
||||||
if ! ls.Ready() {return}
|
|
||||||
log.Log(CHANGE, "Toggle() window ready =", ls.ready)
|
|
||||||
if ls.hidden {
|
|
||||||
ls.Show()
|
|
||||||
} else {
|
} else {
|
||||||
ls.Hide()
|
hs.window.Hide()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ls *LinuxStatus) Ready() bool {
|
func (hs *LinuxStatus) Ready() bool {
|
||||||
log.Log(SPEW, "Ready() maybe not ready? ls =", ls)
|
|
||||||
if me == nil {return false}
|
if me == nil {return false}
|
||||||
if ls == nil {return false}
|
if hs == nil {return false}
|
||||||
if ls.window == nil {return false}
|
if hs.window == nil {return false}
|
||||||
return me.ready
|
return me.ready
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ls *LinuxStatus) Initialized() bool {
|
|
||||||
log.Log(CHANGE, "checking Initialized()")
|
|
||||||
if me == nil {return false}
|
|
||||||
if ls == nil {return false}
|
|
||||||
if ls.parent == nil {return false}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ls *LinuxStatus) SetParent(p *gui.Node) {
|
|
||||||
log.Log(CHANGE, "Attempting SetParent")
|
|
||||||
if me == nil {return}
|
|
||||||
if ls == nil {return}
|
|
||||||
if ls.parent == nil {
|
|
||||||
log.Log(CHANGE, "SetParent =", p)
|
|
||||||
ls.parent = p
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
log.Log(CHANGE, "SetParent was already set to =", ls.parent)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -9,18 +9,15 @@ import (
|
||||||
// it's assumed you are always passing in a box
|
// it's assumed you are always passing in a box
|
||||||
func draw(ls *LinuxStatus) {
|
func draw(ls *LinuxStatus) {
|
||||||
if ! ls.Ready() {return}
|
if ! ls.Ready() {return}
|
||||||
ls.group = ls.window.Box().NewGroup("What Linux Knows It Is")
|
ls.group = ls.window.Box().NewGroup("Real Stuff")
|
||||||
|
|
||||||
ls.grid = ls.group.NewGrid("gridnuts", 2, 2)
|
ls.grid = ls.group.NewGrid("gridnuts", 2, 2)
|
||||||
|
|
||||||
ls.grid.SetNext(1,1)
|
ls.grid.SetNext(1,1)
|
||||||
|
|
||||||
ls.hostnameStatus = gadgets.NewOneLiner(ls.grid, "status")
|
|
||||||
ls.hostname = gadgets.NewOneLiner(ls.grid, "hostname -f")
|
|
||||||
ls.hostshort = gadgets.NewOneLiner(ls.grid, "hostname -s")
|
ls.hostshort = gadgets.NewOneLiner(ls.grid, "hostname -s")
|
||||||
ls.domainname = gadgets.NewOneLiner(ls.grid, "domain name")
|
ls.domainname = gadgets.NewOneLiner(ls.grid, "domain name")
|
||||||
ls.resolver = gadgets.NewOneLiner(ls.grid, "nameservers =")
|
ls.NSrr = gadgets.NewOneLiner(ls.grid, "NS records =")
|
||||||
ls.resolver.Set("TODO")
|
|
||||||
ls.uid = gadgets.NewOneLiner(ls.grid, "UID =")
|
ls.uid = gadgets.NewOneLiner(ls.grid, "UID =")
|
||||||
ls.IPv4 = gadgets.NewOneLiner(ls.grid, "Current IPv4 =")
|
ls.IPv4 = gadgets.NewOneLiner(ls.grid, "Current IPv4 =")
|
||||||
ls.IPv6 = gadgets.NewOneLiner(ls.grid, "Current IPv6 =")
|
ls.IPv6 = gadgets.NewOneLiner(ls.grid, "Current IPv6 =")
|
||||||
|
@ -30,7 +27,6 @@ func draw(ls *LinuxStatus) {
|
||||||
ls.grid.NewLabel("interfaces =")
|
ls.grid.NewLabel("interfaces =")
|
||||||
ls.Interfaces = ls.grid.NewCombobox("Interfaces")
|
ls.Interfaces = ls.grid.NewCombobox("Interfaces")
|
||||||
|
|
||||||
ls.speed = gadgets.NewOneLiner(ls.grid, "refresh speed =")
|
|
||||||
ls.speedActual = gadgets.NewOneLiner(ls.grid, "refresh speed =")
|
ls.speedActual = gadgets.NewOneLiner(ls.grid, "refresh speed =")
|
||||||
|
|
||||||
ls.grid.Margin()
|
ls.grid.Margin()
|
||||||
|
|
|
@ -15,101 +15,53 @@ func (ls *LinuxStatus) GetDomainName() string {
|
||||||
return me.domainname.Get()
|
return me.domainname.Get()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ls *LinuxStatus) setDomainName() {
|
func (ls *LinuxStatus) setDomainName(dn string) {
|
||||||
if ! me.Ready() {return}
|
if ! me.Ready() {return}
|
||||||
|
me.domainname.Set(dn)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getHostname() {
|
||||||
|
var err error
|
||||||
|
var s string = "gui.Label == nil"
|
||||||
|
s, err = fqdn.FqdnHostname()
|
||||||
|
if (err != nil) {
|
||||||
|
log.Error(err, "FQDN hostname error")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Warn("full hostname should be:", s)
|
||||||
|
|
||||||
dn := run("domainname")
|
dn := run("domainname")
|
||||||
if (me.domainname.Get() != dn) {
|
if (me.domainname.Get() != dn) {
|
||||||
log.Log(CHANGE, "domainname has changed from", me.GetDomainName(), "to", dn)
|
log.Log(CHANGE, "domainname has changed from", me.GetDomainName(), "to", dn)
|
||||||
me.domainname.Set(dn)
|
me.setDomainName(dn)
|
||||||
me.changed = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ls *LinuxStatus) GetHostname() string {
|
|
||||||
if ! me.Ready() {return ""}
|
|
||||||
return me.hostname.Get()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ls *LinuxStatus) ValidHostname() bool {
|
|
||||||
if ! me.Ready() {return false}
|
|
||||||
if me.hostnameStatus.Get() == "VALID" {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ls *LinuxStatus) setHostname(newname string) {
|
|
||||||
if ! me.Ready() {return}
|
|
||||||
if newname == me.hostname.Get() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
log.Log(CHANGE, "hostname has changed from", me.GetHostname(), "to", newname)
|
|
||||||
me.hostname.Set(newname)
|
|
||||||
me.changed = true
|
me.changed = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ls *LinuxStatus) GetHostShort() string {
|
|
||||||
if ! me.Ready() {return ""}
|
|
||||||
return me.hostshort.Get()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ls *LinuxStatus) setHostShort() {
|
|
||||||
if ! me.Ready() {return}
|
|
||||||
hshort := run("hostname -s")
|
hshort := run("hostname -s")
|
||||||
if (me.hostshort.Get() != hshort) {
|
if (me.hostshort.Get() != hshort) {
|
||||||
log.Log(CHANGE, "hostname -s has changed from", me.hostshort.Get(), "to", hshort)
|
log.Log(CHANGE, "hostname -s has changed from", me.hostshort.Get(), "to", hshort)
|
||||||
me.hostshort.Set(hshort)
|
me.hostshort.Set(hshort)
|
||||||
me.changed = true
|
me.changed = true
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func lookupHostname() {
|
|
||||||
if ! me.Ready() {return}
|
|
||||||
var err error
|
|
||||||
var hostfqdn string = "broken"
|
|
||||||
hostfqdn, err = fqdn.FqdnHostname()
|
|
||||||
if (err != nil) {
|
|
||||||
log.Error(err, "FQDN hostname error")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
log.Log(NET, "full hostname should be: ", hostfqdn)
|
|
||||||
|
|
||||||
me.setDomainName()
|
|
||||||
me.setHostShort()
|
|
||||||
|
|
||||||
// these are authoritative
|
|
||||||
// if they work wrong, your linux configuration is wrong.
|
|
||||||
// Do not complain.
|
|
||||||
// Fix your distro if your box is otherwise not working this way
|
|
||||||
hshort := me.GetHostShort() // from `hostname -s`
|
|
||||||
dn := me.GetDomainName() // from `domanname`
|
|
||||||
hostname := me.GetHostname() // from `hostname -f`
|
|
||||||
|
|
||||||
if hostfqdn != hostname {
|
|
||||||
log.Log(WARN, "hostname", hostname, "does not equal fqdn.FqdnHostname()", hostfqdn)
|
|
||||||
// TODO: figure out what is wrong
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/*
|
||||||
var test string
|
var test string
|
||||||
test = hshort + "." + dn
|
test = hshort + "." + dn
|
||||||
|
if (me.status.GetHostname() != test) {
|
||||||
me.setHostname(test)
|
log.Log(CHANGE, "me.hostname", me.status.GetHostname(), "does not equal", test)
|
||||||
|
if (me.hostnameStatus.S != "BROKEN") {
|
||||||
if (hostname != test) {
|
log.Log(CHANGE, "me.hostname", me.status.GetHostname(), "does not equal", test)
|
||||||
log.Log(CHANGE, "hostname", hostname, "does not equal", test)
|
|
||||||
if (me.hostnameStatus.Get() != "BROKEN") {
|
|
||||||
log.Log(CHANGE, "hostname", hostname, "does not equal", test)
|
|
||||||
me.changed = true
|
me.changed = true
|
||||||
me.hostnameStatus.Set("BROKEN")
|
me.hostnameStatus.SetText("BROKEN")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (me.hostnameStatus.Get() != "VALID") {
|
if (me.hostnameStatus.S != "VALID") {
|
||||||
log.Log(CHANGE, "hostname", hostname, "is valid")
|
log.Log(CHANGE, "me.hostname", me.status.GetHostname(), "is valid")
|
||||||
me.hostnameStatus.Set("VALID")
|
me.hostnameStatus.SetText("VALID")
|
||||||
me.changed = true
|
me.changed = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns true if the hostname is good
|
// returns true if the hostname is good
|
||||||
|
|
|
@ -8,15 +8,14 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func linuxLoop() {
|
func linuxLoop() {
|
||||||
me.changed = false
|
me.changed = false
|
||||||
duration := timeFunction(lookupHostname)
|
duration := timeFunction(getHostname)
|
||||||
log.Log(INFO, "getHostname() execution Time: ", duration, "me.changed =", me.changed)
|
log.Info("getHostname() execution Time: ", duration, "me.changed =", me.changed)
|
||||||
|
|
||||||
duration = timeFunction(scanInterfaces)
|
duration = timeFunction(scanInterfaces)
|
||||||
log.Log(NET, "scanInterfaces() execution Time: ", duration)
|
log.Log(NET, "scanInterfaces() execution Time: ", duration)
|
||||||
|
@ -24,13 +23,17 @@ func linuxLoop() {
|
||||||
log.Log(NET, strconv.Itoa(i) + " iface = " + t.iface.Name)
|
log.Log(NET, strconv.Itoa(i) + " iface = " + t.iface.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// get all the real AAAA records from all the network interfaces linux can see
|
var aaaa []string
|
||||||
tmp := strings.Join(realAAAA(), "\n")
|
aaaa = dhcpAAAA()
|
||||||
tmp = sortLines(tmp)
|
var all string
|
||||||
me.workingIPv6.Set(tmp)
|
for _, s := range aaaa {
|
||||||
|
log.Log(NET, "my actual AAAA = ",s)
|
||||||
|
all += s + "\n"
|
||||||
|
}
|
||||||
|
// me.IPv6.SetText(all)
|
||||||
|
|
||||||
user, _ := user.Current()
|
user, _ := user.Current()
|
||||||
log.Log(INFO, "os.Getuid =", user.Username, os.Getuid())
|
log.Println("os.Getuid =", user.Username, os.Getuid())
|
||||||
if (me.uid != nil) {
|
if (me.uid != nil) {
|
||||||
me.uid.Set(user.Username + " (" + strconv.Itoa(os.Getuid()) + ")")
|
me.uid.Set(user.Username + " (" + strconv.Itoa(os.Getuid()) + ")")
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,12 +4,40 @@ package linuxstatus
|
||||||
import (
|
import (
|
||||||
// "log"
|
// "log"
|
||||||
"net"
|
"net"
|
||||||
"sort"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// this doesn't work
|
||||||
|
/*
|
||||||
|
func watchNetworkInterfaces() {
|
||||||
|
// Get list of network interfaces
|
||||||
|
interfaces, _ := net.Interfaces()
|
||||||
|
|
||||||
|
// Set up a notification channel
|
||||||
|
notification := make(chan net.Interface)
|
||||||
|
|
||||||
|
log.Log(NET, "watchNet()")
|
||||||
|
// Start goroutine to watch for changes
|
||||||
|
go func() {
|
||||||
|
log.Log(NET, "watchNet() func")
|
||||||
|
for {
|
||||||
|
log.Log(NET, "forever loop start")
|
||||||
|
// Check for changes in each interface
|
||||||
|
for _, i := range interfaces {
|
||||||
|
log.Log(NET, "something on i =", i)
|
||||||
|
if status := i.Flags & net.FlagUp; status != 0 {
|
||||||
|
notification <- i
|
||||||
|
log.Log(NET, "something on i =", i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.Log(NET, "forever loop end")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
func IsIPv6(address string) bool {
|
func IsIPv6(address string) bool {
|
||||||
return strings.Count(address, ":") >= 2
|
return strings.Count(address, ":") >= 2
|
||||||
}
|
}
|
||||||
|
@ -46,7 +74,7 @@ func renameInterface(i *net.Interface) {
|
||||||
func checkInterface(i net.Interface) {
|
func checkInterface(i net.Interface) {
|
||||||
val, ok := me.ifmap[i.Index]
|
val, ok := me.ifmap[i.Index]
|
||||||
if ! ok {
|
if ! ok {
|
||||||
log.Log(INFO, i.Name, "is a new network interface. The linux kernel index =", i.Index)
|
log.Info(i.Name, "is a new network interface. The linux kernel index =", i.Index)
|
||||||
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
|
||||||
|
@ -60,7 +88,7 @@ func checkInterface(i net.Interface) {
|
||||||
me.ifmap[i.Index].gone = false
|
me.ifmap[i.Index].gone = false
|
||||||
log.Log(NET, "me.ifmap[i] does exist. Need to compare everything.", i.Index, i.Name, val.iface.Index, val.iface.Name)
|
log.Log(NET, "me.ifmap[i] does exist. Need to compare everything.", i.Index, i.Name, val.iface.Index, val.iface.Name)
|
||||||
if (val.iface.Name != i.Name) {
|
if (val.iface.Name != i.Name) {
|
||||||
log.Log(INFO, val.iface.Name, "has changed to it's name to", i.Name)
|
log.Info(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.changed = true
|
me.changed = true
|
||||||
if (me.Interfaces != nil) {
|
if (me.Interfaces != nil) {
|
||||||
|
@ -75,7 +103,7 @@ func checkInterface(i net.Interface) {
|
||||||
These are the real IP address you have been
|
These are the real IP address you have been
|
||||||
given from DHCP
|
given from DHCP
|
||||||
*/
|
*/
|
||||||
func realAAAA() []string {
|
func dhcpAAAA() []string {
|
||||||
var aaaa []string
|
var aaaa []string
|
||||||
|
|
||||||
for s, t := range me.ipmap {
|
for s, t := range me.ipmap {
|
||||||
|
@ -115,14 +143,14 @@ func checkDNS() (map[string]*IPtype, map[string]*IPtype) {
|
||||||
ipt = "IPv6"
|
ipt = "IPv6"
|
||||||
}
|
}
|
||||||
if (t.IsReal()) {
|
if (t.IsReal()) {
|
||||||
log.Log(INFO, "\tIP is Real ", ipt, i.Index, i.Name, s)
|
log.Info("\tIP is Real ", ipt, i.Index, i.Name, s)
|
||||||
if (t.ipv6) {
|
if (t.ipv6) {
|
||||||
ipv6s[s] = t
|
ipv6s[s] = t
|
||||||
} else {
|
} else {
|
||||||
ipv4s[s] = t
|
ipv4s[s] = t
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Log(INFO, "\tIP is not Real", ipt, i.Index, i.Name, s)
|
log.Info("\tIP is not Real", ipt, i.Index, i.Name, s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ipv6s, ipv4s
|
return ipv6s, ipv4s
|
||||||
|
@ -164,14 +192,14 @@ func checkIP(ip *net.IPNet, i net.Interface) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (IsReal(&ip.IP)) {
|
if (IsReal(&ip.IP)) {
|
||||||
log.Log(INFO, "\tIP is Real ", t, i.Index, i.Name, realip)
|
log.Info("\tIP is Real ", t, i.Index, i.Name, realip)
|
||||||
} else {
|
} else {
|
||||||
log.Log(INFO, "\tIP is not Real", t, i.Index, i.Name, realip)
|
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 IsPrivate() =", ip.IP.IsPrivate())
|
||||||
log.Log(NET, "\t\tIP is IsLoopback() =", ip.IP.IsLoopback())
|
log.Log(NET, "\t\tIP is IsLoopback() =", ip.IP.IsLoopback())
|
||||||
log.Log(NET, "\t\tIP is IsLinkLocalUnicast() =", ip.IP.IsLinkLocalUnicast())
|
log.Log(NET, "\t\tIP is IsLinkLocalUnicast() =", ip.IP.IsLinkLocalUnicast())
|
||||||
// log.Log(INFO, "HERE HERE", "realip =", realip, "me.ip[realip]=", me.ipmap[realip])
|
// log.Info("HERE HERE", "realip =", realip, "me.ip[realip]=", me.ipmap[realip])
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,7 +210,7 @@ func scanInterfaces() {
|
||||||
log.Log(NET, SPEW, ifaces)
|
log.Log(NET, SPEW, ifaces)
|
||||||
for _, i := range ifaces {
|
for _, i := range ifaces {
|
||||||
addrs, _ := i.Addrs()
|
addrs, _ := i.Addrs()
|
||||||
// log.Log(INFO, "range ifaces = ", i)
|
// log.Info("range ifaces = ", i)
|
||||||
checkInterface(i)
|
checkInterface(i)
|
||||||
log.Log(NET, "*net.Interface.Name = ", i.Name, i.Index)
|
log.Log(NET, "*net.Interface.Name = ", i.Name, i.Index)
|
||||||
log.Log(NET, SPEW, i)
|
log.Log(NET, SPEW, i)
|
||||||
|
@ -212,35 +240,28 @@ func scanInterfaces() {
|
||||||
|
|
||||||
// displays the IP address found on your network interfaces
|
// displays the IP address found on your network interfaces
|
||||||
func updateRealAAAA() {
|
func updateRealAAAA() {
|
||||||
var all4 []string
|
var all4 string
|
||||||
var all6 []string
|
var all6 string
|
||||||
for s, t := range me.ipmap {
|
for s, t := range me.ipmap {
|
||||||
if (t.ipv4) {
|
if (t.ipv4) {
|
||||||
all4 = append(all4, s)
|
all4 += s + "\n"
|
||||||
log.Log(NET, "IPv4 =", s)
|
log.Log(NET, "IPv4 =", s)
|
||||||
} else if (t.ipv6) {
|
} else if (t.ipv6) {
|
||||||
all6 = append(all6, s)
|
all6 += s + "\n"
|
||||||
log.Log(NET, "IPv6 =", s)
|
log.Log(NET, "IPv6 =", s)
|
||||||
} else {
|
} else {
|
||||||
log.Log(NET, "???? =", s)
|
log.Log(NET, "???? =", s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
all4 = sortLines(all4)
|
||||||
// sort and create text
|
all6 = sortLines(all6)
|
||||||
sort.Strings(all4)
|
if (me.IPv4.Get() != all4) {
|
||||||
sort.Strings(all6)
|
log.Log(NET, "IPv4 addresses have changed", all4)
|
||||||
s4 := strings.Join(all4, "\n")
|
me.IPv4.Set(all4)
|
||||||
s6 := strings.Join(all6, "\n")
|
|
||||||
|
|
||||||
if (me.IPv4.Get() != s4) {
|
|
||||||
log.Log(CHANGE, "IPv4 addresses have changed", s4)
|
|
||||||
me.IPv4.Set(s4)
|
|
||||||
me.changed = true
|
|
||||||
}
|
}
|
||||||
if (me.IPv6.Get() != s6) {
|
if (me.IPv6.Get() != all6) {
|
||||||
log.Log(CHANGE, "IPv6 addresses have changed", s6)
|
log.Log(NET, "IPv6 addresses have changed", all6)
|
||||||
me.IPv6.Set(s6)
|
me.IPv6.Set(all6)
|
||||||
me.changed = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,38 +2,16 @@
|
||||||
package linuxstatus
|
package linuxstatus
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go.wit.com/log"
|
|
||||||
|
|
||||||
"go.wit.com/gui/gadgets"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func New() *LinuxStatus {
|
func New() *LinuxStatus {
|
||||||
if me != nil {
|
|
||||||
log.Log(WARN, "You have done New() twice. You can only do this once")
|
|
||||||
return me
|
|
||||||
}
|
|
||||||
me = &LinuxStatus {
|
me = &LinuxStatus {
|
||||||
hidden: true,
|
hidden: true,
|
||||||
ready: false,
|
ready: false,
|
||||||
}
|
}
|
||||||
me.ifmap = make(map[int]*IFtype)
|
|
||||||
me.ipmap = make(map[string]*IPtype)
|
|
||||||
|
|
||||||
|
me.init = true
|
||||||
return me
|
return me
|
||||||
}
|
|
||||||
|
|
||||||
func (ls *LinuxStatus) InitWindow() {
|
// me.window = gadgets.NewBasicWindow(me.myGui, "Linux OS Details")
|
||||||
if ! ls.Initialized() {
|
|
||||||
log.Log(WARN, "not initalized yet (no parent for the window?)")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if ls.window != nil {
|
|
||||||
log.Log(WARN, "You already have a window")
|
|
||||||
ls.ready = true
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Log(WARN, "Creating the Window")
|
|
||||||
ls.window = gadgets.NewBasicWindow(ls.parent, "Linux OS Details")
|
|
||||||
ls.ready = true
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,12 +14,11 @@ import (
|
||||||
var me *LinuxStatus
|
var me *LinuxStatus
|
||||||
|
|
||||||
type LinuxStatus struct {
|
type LinuxStatus struct {
|
||||||
|
init bool
|
||||||
ready bool
|
ready bool
|
||||||
hidden bool
|
hidden bool
|
||||||
changed bool
|
changed bool
|
||||||
|
|
||||||
parent *gui.Node
|
|
||||||
|
|
||||||
ifmap map[int]*IFtype // the current interfaces
|
ifmap map[int]*IFtype // the current interfaces
|
||||||
ipmap map[string]*IPtype // the current ip addresses
|
ipmap map[string]*IPtype // the current ip addresses
|
||||||
|
|
||||||
|
@ -27,17 +26,15 @@ type LinuxStatus struct {
|
||||||
group *gui.Node
|
group *gui.Node
|
||||||
grid *gui.Node
|
grid *gui.Node
|
||||||
|
|
||||||
hostnameStatus *gadgets.OneLiner
|
|
||||||
hostname *gadgets.OneLiner
|
|
||||||
hostshort *gadgets.OneLiner
|
hostshort *gadgets.OneLiner
|
||||||
domainname *gadgets.OneLiner
|
domainname *gadgets.OneLiner
|
||||||
resolver *gadgets.OneLiner
|
fqdn *gadgets.OneLiner
|
||||||
|
NSrr *gadgets.OneLiner
|
||||||
uid *gadgets.OneLiner
|
uid *gadgets.OneLiner
|
||||||
IPv4 *gadgets.OneLiner
|
IPv4 *gadgets.OneLiner
|
||||||
IPv6 *gadgets.OneLiner
|
IPv6 *gadgets.OneLiner
|
||||||
workingIPv6 *gadgets.OneLiner
|
workingIPv6 *gadgets.OneLiner
|
||||||
Interfaces *gui.Node
|
Interfaces *gui.Node
|
||||||
speed *gadgets.OneLiner
|
|
||||||
speedActual *gadgets.OneLiner
|
speedActual *gadgets.OneLiner
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,3 @@ func sortLines(input string) string {
|
||||||
tmp = strings.TrimRight(tmp, "\n")
|
tmp = strings.TrimRight(tmp, "\n")
|
||||||
return tmp
|
return tmp
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ls *LinuxStatus) SetSpeedActual(s string) {
|
|
||||||
if ! ls.Ready() {return}
|
|
||||||
ls.speedActual.Set(s)
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,40 +1,31 @@
|
||||||
package linuxstatus
|
package linuxstatus
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
"errors"
|
|
||||||
|
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (ls *LinuxStatus) Update() {
|
func (ls *LinuxStatus) Update() {
|
||||||
if ! ls.Ready() {
|
log.Info("linuxStatus() Update() START")
|
||||||
log.Log(WARN, "can't update yet. ready is false")
|
if ls == nil {
|
||||||
log.Error(errors.New("Update() is not ready yet"))
|
log.Error(errors.New("linuxStatus() Update() ls == nil"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Log(INFO, "Update() START")
|
|
||||||
duration := timeFunction(func () {
|
duration := timeFunction(func () {
|
||||||
linuxLoop()
|
linuxLoop()
|
||||||
})
|
})
|
||||||
ls.SetSpeed(duration)
|
|
||||||
log.Log(INFO, "Update() END")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ls *LinuxStatus) SetSpeed(duration time.Duration) {
|
|
||||||
s := fmt.Sprint(duration)
|
s := fmt.Sprint(duration)
|
||||||
if ls.speedActual == nil {
|
|
||||||
log.Log(WARN, "can't actually warn")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ls.speedActual.Set(s)
|
ls.speedActual.Set(s)
|
||||||
|
|
||||||
if (duration > 500 * time.Millisecond ) {
|
if (duration > 500 * time.Millisecond ) {
|
||||||
ls.speed.Set("SLOW")
|
// ls.speed, "SLOW")
|
||||||
} else if (duration > 100 * time.Millisecond ) {
|
} else if (duration > 100 * time.Millisecond ) {
|
||||||
ls.speed.Set("OK")
|
// ls.speed, "OK")
|
||||||
} else {
|
} else {
|
||||||
ls.speed.Set("FAST")
|
// ls.speed, "FAST")
|
||||||
}
|
}
|
||||||
|
log.Info("linuxStatus() Update() END")
|
||||||
}
|
}
|
||||||
|
|
38
main.go
38
main.go
|
@ -8,6 +8,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
"embed"
|
"embed"
|
||||||
|
@ -100,7 +101,7 @@ func checkNetworkChanges() {
|
||||||
if (runtime.GOOS == "linux") {
|
if (runtime.GOOS == "linux") {
|
||||||
duration := timeFunction(linuxLoop)
|
duration := timeFunction(linuxLoop)
|
||||||
s := fmt.Sprint(duration)
|
s := fmt.Sprint(duration)
|
||||||
me.statusOS.SetSpeedActual(s)
|
me.LocalSpeedActual.SetText(s)
|
||||||
} else {
|
} else {
|
||||||
// TODO: make windows and macos diagnostics
|
// TODO: make windows and macos diagnostics
|
||||||
log.Warn("Windows and MacOS don't work yet")
|
log.Warn("Windows and MacOS don't work yet")
|
||||||
|
@ -153,16 +154,45 @@ func dnsTTL() {
|
||||||
updateDNS()
|
updateDNS()
|
||||||
}
|
}
|
||||||
|
|
||||||
// run update on the LinuxStatus() window
|
|
||||||
func linuxLoop() {
|
func linuxLoop() {
|
||||||
me.statusOS.Update()
|
me.changed = false
|
||||||
|
log.Log(NET, "FQDN =", me.fqdn.GetText())
|
||||||
|
duration := timeFunction(getHostname)
|
||||||
|
log.Info("getHostname() execution Time: ", duration, "me.changed =", me.changed)
|
||||||
|
|
||||||
if (me.statusOS.Changed()) {
|
duration = timeFunction(scanInterfaces)
|
||||||
|
log.Log(NET, "scanInterfaces() execution Time: ", duration)
|
||||||
|
for i, t := range me.ifmap {
|
||||||
|
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)
|
||||||
|
|
||||||
|
if (me.changed) {
|
||||||
stamp := time.Now().Format("2006/01/02 15:04:05")
|
stamp := time.Now().Format("2006/01/02 15:04:05")
|
||||||
log.Log(CHANGE, "Network things changed on", stamp)
|
log.Log(CHANGE, "Network things changed on", stamp)
|
||||||
duration := timeFunction(updateDNS)
|
duration := timeFunction(updateDNS)
|
||||||
log.Log(CHANGE, "updateDNS() execution Time: ", duration)
|
log.Log(CHANGE, "updateDNS() execution Time: ", duration)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
processName := getProcessNameByPort(53)
|
||||||
|
fmt.Println("Process with port 53:", processName)
|
||||||
|
|
||||||
|
commPath := filepath.Join("/proc", proc.Name(), "comm")
|
||||||
|
comm, err := ioutil.ReadFile(commPath)
|
||||||
|
if err != nil {
|
||||||
|
return "", err // Error reading the process name
|
||||||
|
}
|
||||||
|
return strings.TrimSpace(string(comm)), nil
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
201
net.go
201
net.go
|
@ -9,6 +9,35 @@ import (
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// this doesn't work
|
||||||
|
/*
|
||||||
|
func watchNetworkInterfaces() {
|
||||||
|
// Get list of network interfaces
|
||||||
|
interfaces, _ := net.Interfaces()
|
||||||
|
|
||||||
|
// Set up a notification channel
|
||||||
|
notification := make(chan net.Interface)
|
||||||
|
|
||||||
|
log.Log(NET, "watchNet()")
|
||||||
|
// Start goroutine to watch for changes
|
||||||
|
go func() {
|
||||||
|
log.Log(NET, "watchNet() func")
|
||||||
|
for {
|
||||||
|
log.Log(NET, "forever loop start")
|
||||||
|
// Check for changes in each interface
|
||||||
|
for _, i := range interfaces {
|
||||||
|
log.Log(NET, "something on i =", i)
|
||||||
|
if status := i.Flags & net.FlagUp; status != 0 {
|
||||||
|
notification <- i
|
||||||
|
log.Log(NET, "something on i =", i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.Log(NET, "forever loop end")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
func IsIPv6(address string) bool {
|
func IsIPv6(address string) bool {
|
||||||
return strings.Count(address, ":") >= 2
|
return strings.Count(address, ":") >= 2
|
||||||
}
|
}
|
||||||
|
@ -33,6 +62,43 @@ func IsReal(ip *net.IP) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func renameInterface(i *net.Interface) {
|
||||||
|
/*
|
||||||
|
/sbin/ip link set eth1 down
|
||||||
|
/sbin/ip link set eth1 name eth123
|
||||||
|
/sbin/ip link set eth123 up
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
// Will figure out if an interface was just added
|
||||||
|
func checkInterface(i net.Interface) {
|
||||||
|
val, ok := me.ifmap[i.Index]
|
||||||
|
if ! ok {
|
||||||
|
log.Info(i.Name, "is a new network interface. The linux kernel index =", i.Index)
|
||||||
|
me.ifmap[i.Index] = new(IFtype)
|
||||||
|
me.ifmap[i.Index].gone = false
|
||||||
|
me.ifmap[i.Index].iface = &i
|
||||||
|
me.changed = true
|
||||||
|
if (me.Interfaces != nil) {
|
||||||
|
me.Interfaces.AddText(i.Name)
|
||||||
|
me.Interfaces.SetText(i.Name)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
me.ifmap[i.Index].gone = false
|
||||||
|
log.Log(NET, "me.ifmap[i] does exist. Need to compare everything.", i.Index, i.Name, val.iface.Index, val.iface.Name)
|
||||||
|
if (val.iface.Name != i.Name) {
|
||||||
|
log.Info(val.iface.Name, "has changed to it's name to", i.Name)
|
||||||
|
me.ifmap[i.Index].iface = &i
|
||||||
|
me.changed = true
|
||||||
|
if (me.Interfaces != nil) {
|
||||||
|
me.Interfaces.AddText(i.Name)
|
||||||
|
me.Interfaces.SetText(i.Name)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
These are the real IP address you have been
|
These are the real IP address you have been
|
||||||
given from DHCP
|
given from DHCP
|
||||||
|
@ -89,3 +155,138 @@ func checkDNS() (map[string]*IPtype, map[string]*IPtype) {
|
||||||
}
|
}
|
||||||
return ipv6s, ipv4s
|
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 {
|
||||||
|
var changed bool = false
|
||||||
|
for i, t := range me.ifmap {
|
||||||
|
if (t.gone) {
|
||||||
|
log.Log(CHANGE, "DELETE int =", i, "name =", t.name, t.iface)
|
||||||
|
delete(me.ifmap, i)
|
||||||
|
changed = true
|
||||||
|
}
|
||||||
|
t.gone = true
|
||||||
|
}
|
||||||
|
for s, t := range me.ipmap {
|
||||||
|
if (t.gone) {
|
||||||
|
log.Log(CHANGE, "DELETE name =", s, "IPv4 =", t.ipv4)
|
||||||
|
log.Log(CHANGE, "DELETE name =", s, "IPv6 =", t.ipv6)
|
||||||
|
log.Log(CHANGE, "DELETE name =", s, "iface =", t.iface)
|
||||||
|
log.Log(CHANGE, "DELETE name =", s, "ip =", t.ip)
|
||||||
|
delete(me.ipmap, s)
|
||||||
|
changed = true
|
||||||
|
}
|
||||||
|
t.gone = true
|
||||||
|
}
|
||||||
|
|
||||||
|
return changed
|
||||||
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ func nsupdate() {
|
||||||
cmd := "go-nsupdate --tsig-algorithm=hmac-sha512"
|
cmd := "go-nsupdate --tsig-algorithm=hmac-sha512"
|
||||||
tsigSecret = os.Getenv("TIG_SECRET")
|
tsigSecret = os.Getenv("TIG_SECRET")
|
||||||
cmd += " --tig-secret=\"" + tsigSecret + "\""
|
cmd += " --tig-secret=\"" + tsigSecret + "\""
|
||||||
cmd += " -i wlo1 " + me.statusOS.GetHostname()
|
cmd += " -i wlo1 " + me.status.GetHostname()
|
||||||
log.Log(NET, "nsupdate() RUN:", cmd)
|
log.Log(NET, "nsupdate() RUN:", cmd)
|
||||||
|
|
||||||
for s, t := range me.ipmap {
|
for s, t := range me.ipmap {
|
||||||
|
|
16
structs.go
16
structs.go
|
@ -19,7 +19,9 @@ type Host struct {
|
||||||
statusOS *linuxstatus.LinuxStatus // what the Linux OS sees
|
statusOS *linuxstatus.LinuxStatus // what the Linux OS sees
|
||||||
|
|
||||||
hostnameStatus *gui.Node // a summary for the user of where things are
|
hostnameStatus *gui.Node // a summary for the user of where things are
|
||||||
hostname *gadgets.OneLiner // the hostname grabbed from gadget.linuxStatus
|
|
||||||
|
// domainname *gui.Node // kernel.org
|
||||||
|
hostshort *gui.Node // hostname -s
|
||||||
|
|
||||||
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
|
||||||
|
@ -42,19 +44,25 @@ type Host struct {
|
||||||
ipv6s map[string]dns.RR
|
ipv6s map[string]dns.RR
|
||||||
|
|
||||||
window *gadgets.BasicWindow // the main window
|
window *gadgets.BasicWindow // the main window
|
||||||
|
details *gadgets.BasicWindow // more details of the DNS state
|
||||||
debug *gadgets.BasicWindow // more attempts to debug the DNS state
|
debug *gadgets.BasicWindow // more attempts to debug the DNS state
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
// local OS settings, network interfaces, etc
|
// local OS settings, network interfaces, etc
|
||||||
// fqdn *gui.Node // display the full hostname
|
// uid *gui.Node // user
|
||||||
// Interfaces *gui.Node // Interfaces
|
fqdn *gui.Node // display the full hostname
|
||||||
// LocalSpeedActual *gui.Node // the time it takes to check each network interface
|
IPv4 *gui.Node // show valid IPv4 addresses
|
||||||
|
IPv6 *gui.Node // show valid IPv6 addresses
|
||||||
|
Interfaces *gui.Node // Interfaces
|
||||||
|
LocalSpeedActual *gui.Node // the time it takes to check each network interface
|
||||||
|
|
||||||
// DNS stuff
|
// DNS stuff
|
||||||
|
NSrr *gui.Node // NS resource records for the domain name
|
||||||
DnsAPI *gui.Node // what DNS API to use?
|
DnsAPI *gui.Node // what DNS API to use?
|
||||||
DnsAAAA *gadgets.OneLiner // the actual DNS AAAA results
|
DnsAAAA *gadgets.OneLiner // the actual DNS AAAA results
|
||||||
|
workingIPv6 *gui.Node // currently working AAAA
|
||||||
DnsA *gui.Node // the actual DNS A results (ignore for status since mostly never happens?)
|
DnsA *gui.Node // the actual DNS A results (ignore for status since mostly never happens?)
|
||||||
DnsStatus *gui.Node // the current state of DNS
|
DnsStatus *gui.Node // the current state of DNS
|
||||||
DnsSpeed *gui.Node // 'FAST', 'OK', 'SLOW', etc
|
DnsSpeed *gui.Node // 'FAST', 'OK', 'SLOW', etc
|
||||||
|
|
Loading…
Reference in New Issue