Compare commits

..

2 Commits

Author SHA1 Message Date
Jeff Carr 74bfddc1e4 logic for comparing OS and DNS IPv6 addresses
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-01-07 15:27:44 -06:00
Jeff Carr 837a8a4be4 can't continue. need gocui to work
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-01-07 15:05:36 -06:00
2 changed files with 71 additions and 27 deletions

View File

@ -22,6 +22,7 @@ import (
type hostnameStatus struct { type hostnameStatus struct {
ready bool ready bool
hidden bool hidden bool
changed bool
lastname string // used to watch for changes in the hostname lastname string // used to watch for changes in the hostname
@ -268,36 +269,29 @@ func (hs *hostnameStatus) updateStatus() {
} }
hs.domainname.Set(me.statusOS.GetDomainName()) hs.domainname.Set(me.statusOS.GetDomainName())
tmp := me.statusOS.GetIPv4() var tmp []string
tmp = me.statusOS.GetIPv4()
sort.Strings(tmp) sort.Strings(tmp)
hs.currentIPv4.Set(strings.Join(tmp, "\n")) s = strings.Join(tmp, "\n")
if s != hs.currentIPv4.Get() {
log.Log(CHANGE, "DNS IPv4 Addresses changed", tmp)
hs.currentIPv4.Set(s)
hs.changed = true
}
tmp = me.statusOS.GetIPv6() tmp = me.statusOS.GetIPv6()
sort.Strings(tmp) sort.Strings(tmp)
hs.currentIPv6.Set(strings.Join(tmp, "\n")) s = strings.Join(tmp, "\n")
if s != hs.currentIPv6.Get() {
log.Log(CHANGE, "DNS IPv6 Addresses changed", tmp)
hs.currentIPv6.Set(s)
hs.changed = true
}
if me.statusOS.ValidHostname() { if me.statusOS.ValidHostname() {
vals = lookupDoH(me.statusOS.GetHostname(), "AAAA") vals = lookupDoH(me.statusOS.GetHostname(), "AAAA")
log.Log(STATUS, "DNS IPv6 Addresses for ", me.statusOS.GetHostname(), "=", vals) log.Log(STATUS, "DNS IPv6 Addresses for ", me.statusOS.GetHostname(), "=", vals)
if len(vals) == 0 {
s = "(none)"
} else {
hs.setIPv6("Check for real IPv6 addresses here")
/*
if hs.missingAAAA() {
hs.setIPv6("Add the missing IPv6 address")
}
*/
for _, addr := range vals {
log.Log(STATUS, addr)
s += addr + " (DELETE)" + "\n"
hs.setIPv6("NEEDS DELETE")
// hs.dnsValue.SetText(addr)
// hs.dnsAction.SetText("DELETE")
}
}
sort.Strings(vals)
hs.dnsAAAA.Set(strings.Join(vals, "\n")) hs.dnsAAAA.Set(strings.Join(vals, "\n"))
vals = lookupDoH(me.statusOS.GetHostname(), "A") vals = lookupDoH(me.statusOS.GetHostname(), "A")
@ -315,6 +309,11 @@ func (hs *hostnameStatus) updateStatus() {
hs.set(hs.dnsA, "CNAME " + s) hs.set(hs.dnsA, "CNAME " + s)
hs.setIPv4("GOOD") hs.setIPv4("GOOD")
} }
if hs.changed {
log.Log(CHANGE, "stuff changed. trying fixIPv6dns()")
fixIPv6dns()
hs.changed = false
}
} }
if hs.IPv4() && hs.IPv6() { if hs.IPv4() && hs.IPv6() {
@ -323,9 +322,54 @@ func (hs *hostnameStatus) updateStatus() {
hs.status.Set("BROKEN") hs.status.Set("BROKEN")
} }
// lookup the DNS provider if hs.verifyIPv6() {
// hs.dnsAPI.Set(me.DnsAPI.S) hs.statusIPv6.Set("WORKING")
lookupNSprovider("wit.com") } else {
hs.statusIPv6.Set("BROKEN")
}
}
func (hs *hostnameStatus) verifyIPv6() bool {
var working bool = true
osAAAA := make(map[string]string)
dnsAAAA := make(map[string]string)
log.Log(INFO, "What are the AAAA resource records in the OS?")
tmp := me.statusOS.GetIPv6()
if len(tmp) == 0 {
// you don't have any IPv6 addresses in your OS right now
return false
}
for _, aaaa := range me.statusOS.GetIPv6() {
log.Log(INFO, "FOUND OS AAAA ip", aaaa)
osAAAA[aaaa] = "os"
}
log.Log(INFO, "What are the AAAA resource records in DNS?")
for _, aaaa := range me.statusDNS.GetIPv6() {
log.Log(INFO, "FOUND DNS AAAA ip", aaaa)
dnsAAAA[aaaa] = "dns"
}
for aaaa, _ := range dnsAAAA {
if osAAAA[aaaa] == "os" {
log.Log(INFO, "DNS AAAA is in OS", aaaa)
} else {
working = false
log.Log(INFO, "DNS AAAA is not in OS", aaaa)
}
}
for aaaa, _ := range osAAAA {
if dnsAAAA[aaaa] == "dns" {
log.Log(INFO, "OS AAAA is in DNS", aaaa)
} else {
working = false
log.Log(INFO, "OS AAAA is not in DNS", aaaa)
}
}
return working
} }
func (hs *hostnameStatus) Show() { func (hs *hostnameStatus) Show() {

View File

@ -88,7 +88,7 @@ func main() {
lastProvider := "unknown" lastProvider := "unknown"
go myTicker(10 * time.Second, "DNSloop", func() { go myTicker(10 * time.Second, "DNSloop", func() {
log.Log(CHANGE, "me.statusDNS.Update() START") log.Log(INFO, "me.statusDNS.Update() START")
me.statusDNS.Update() me.statusDNS.Update()
provider := me.statusDNS.GetDNSapi() provider := me.statusDNS.GetDNSapi()
@ -127,7 +127,7 @@ func main() {
}) })
// check the four known things to see if they are all WORKING // check the four known things to see if they are all WORKING
myTicker(3 * time.Second, "MAIN LOOP", func() { myTicker(10 * time.Second, "MAIN LOOP", func() {
if me.hostnameStatus.GetText() != "WORKING" { if me.hostnameStatus.GetText() != "WORKING" {
log.Log(CHANGE, "The hostname is not WORKING yet", me.hostnameStatus.GetText()) log.Log(CHANGE, "The hostname is not WORKING yet", me.hostnameStatus.GetText())
return return
@ -144,7 +144,7 @@ func main() {
log.Log(CHANGE, "The DNS API provider is not yet working", me.DnsAPIstatus.GetText()) log.Log(CHANGE, "The DNS API provider is not yet working", me.DnsAPIstatus.GetText())
return return
} }
log.Log(CHANGE, "EVERYTHING IS WORKING. YOU HAVE IPv6 BLISS") log.Log(CHANGE, "EVERYTHING IS WORKING. YOU HAVE IPv6 BLISS. TODO: don't check so often now")
}) })
} }