fixed dns-https

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-05 23:00:30 -06:00
parent 2d1e321326
commit 244ba1be03
8 changed files with 226 additions and 199 deletions

16
args.go
View File

@ -18,11 +18,13 @@ var args struct {
VerboseDNS bool `arg:"--verbose-dns" help:"debug your dns settings"` VerboseDNS bool `arg:"--verbose-dns" help:"debug your dns settings"`
} }
var NET log.LogFlag
var NOW log.LogFlag var NOW log.LogFlag
var NET log.LogFlag
var DNS log.LogFlag
var PROC log.LogFlag var PROC log.LogFlag
var SPEW log.LogFlag var SPEW log.LogFlag
var CHANGE log.LogFlag var CHANGE log.LogFlag
var STATUS log.LogFlag
func init() { func init() {
arg.MustParse(&args) arg.MustParse(&args)
@ -40,6 +42,12 @@ func init() {
NET.Desc = "Network logging" NET.Desc = "Network logging"
NET.Register() NET.Register()
DNS.B = false
DNS.Name = "DNS"
DNS.Subsystem = "cpdns"
DNS.Desc = "dnsStatus.update()"
DNS.Register()
PROC.B = false PROC.B = false
PROC.Name = "PROC" PROC.Name = "PROC"
PROC.Subsystem = "cpdns" PROC.Subsystem = "cpdns"
@ -58,6 +66,12 @@ func init() {
CHANGE.Desc = "show droplet state changes" CHANGE.Desc = "show droplet state changes"
CHANGE.Register() CHANGE.Register()
STATUS.B = false
STATUS.Name = "STATUS"
STATUS.Subsystem = "cpdns"
STATUS.Desc = "updateStatus()"
STATUS.Register()
if debugger.ArgDebug() { if debugger.ArgDebug() {
log.Log(true, "INIT() gui debug == true") log.Log(true, "INIT() gui debug == true")
} else { } else {

View File

@ -8,30 +8,18 @@ import (
"net/http" "net/http"
) )
/*
func getAAAArecords() {
hostname := "go.wit.com"
ipv6Addresses, err := dnsLookupDoH(hostname)
if err != nil {
log.Error(err, "getAAAArecords")
return
}
fmt.Printf("IPv6 Addresses for %s:\n", hostname)
for _, addr := range ipv6Addresses {
log.Println(addr)
}
}
*/
// dnsLookupDoH performs a DNS lookup for AAAA records over HTTPS. // dnsLookupDoH performs a DNS lookup for AAAA records over HTTPS.
func dnsAAAAlookupDoH(domain string) ([]string, error) { func dnsAAAAlookupDoH(hostname string) ([]string, error) {
var ipv6Addresses []string var ipv6Addresses []string
// Construct the URL for a DNS query with Google's DNS-over-HTTPS API // Construct the URL for a DNS query with Google's DNS-over-HTTPS API
url := fmt.Sprintf("https://dns.google/resolve?name=%s&type=AAAA", domain) url := fmt.Sprintf("https://dns.google/resolve?name=%s&type=AAAA", hostname)
log.Println("curl", url) log.Log(DNS, "dnsAAAAlookupDoH()", url)
if hostname == "" {
log.Warn("dnsAAAAlookupDoH() was sent a empty hostname")
return nil, fmt.Errorf("hostname blank")
}
// Perform the HTTP GET request // Perform the HTTP GET request
resp, err := http.Get(url) resp, err := http.Get(url)
@ -71,7 +59,11 @@ func lookupDoH(hostname string, rrType string) []string {
// Construct the URL for a DNS query with Google's DNS-over-HTTPS API // Construct the URL for a DNS query with Google's DNS-over-HTTPS API
url := fmt.Sprintf("https://dns.google/resolve?name=%s&type=%s", hostname, rrType) url := fmt.Sprintf("https://dns.google/resolve?name=%s&type=%s", hostname, rrType)
log.Println("curl", url) log.Log(DNS, "lookupDoH()", url)
if hostname == "" {
log.Warn("lookupDoH() was sent a empty hostname")
return nil
}
// Perform the HTTP GET request // Perform the HTTP GET request
resp, err := http.Get(url) resp, err := http.Get(url)

View File

@ -16,6 +16,7 @@ import (
"os" "os"
"fmt" "fmt"
"time" "time"
"strings"
"strconv" "strconv"
"reflect" "reflect"
"errors" "errors"
@ -171,18 +172,28 @@ func (ds *digStatus) IPv6() bool {
return false return false
} }
func (ds *digStatus) setIPv4(s string) { func (ds *digStatus) setIPv4status(s string) {
ds.statusIPv4 = s ds.statusIPv4 = s
if ! ds.Ready() {return} if ! ds.Ready() {return}
me.digStatus.set(ds.status, s) me.digStatus.set(ds.status, s)
} }
func (ds *digStatus) setIPv6(s string) { func (ds *digStatus) setIPv6status(s string) {
ds.statusIPv6 = s ds.statusIPv6 = s
if ! ds.Ready() {return} if ! ds.Ready() {return}
me.digStatus.set(ds.statusAAAA, s) me.digStatus.set(ds.statusAAAA, s)
} }
func (ds *digStatus) SetIPv6(s string) {
if ! ds.Ready() {return}
log.Warn("Should SetIPv6() here to", s)
log.Warn("Should SetIPv6() here to", s)
log.Warn("Should SetIPv6() here to", s)
log.Warn("Should SetIPv6() here to", s)
me.DnsAAAA.Set(s)
// me.digStatus.set(ds.httpGoWitCom, addr)
}
func (ds *digStatus) set(a any, s string) { func (ds *digStatus) set(a any, s string) {
if ! ds.Ready() {return} if ! ds.Ready() {return}
if ds.hidden { if ds.hidden {
@ -227,39 +238,43 @@ 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 ds.checkLookupDoH("go.wit.com") { if me.status.ValidHostname() {
log.Println("updateDnsStatus() HTTP DNS lookups working") if ds.checkLookupDoH(me.status.GetHostname()) {
me.digStatus.set(ds.statusHTTP, "WORKING") log.Log(DNS, "updateDnsStatus() HTTP DNS lookups working")
me.digStatus.set(ds.statusHTTP, "WORKING")
} else {
log.Log(DNS, "updateDnsStatus() HTTP DNS lookups not working")
log.Log(DNS, "updateDnsStatus() It's really unlikely you are on the internet")
me.digStatus.set(ds.statusHTTP, "BROKEN")
}
} else { } else {
log.Println("updateDnsStatus() HTTP DNS lookups not working") me.digStatus.set(ds.statusHTTP, "INVALID HOSTNAME")
log.Println("updateDnsStatus() It's really unlikely you are on the internet")
me.digStatus.set(ds.statusHTTP, "BROKEN")
} }
if (ipv4) { if (ipv4) {
log.Println("updateDnsStatus() IPv4 A lookups working") log.Log(DNS, "updateDnsStatus() IPv4 A lookups working")
ds.setIPv4("OK") ds.setIPv4status("OK")
} else { } else {
log.Println("updateDnsStatus() IPv4 A lookups not working. No internet?") log.Log(DNS, "updateDnsStatus() IPv4 A lookups not working. No internet?")
ds.setIPv4("No Internet?") ds.setIPv4status("No Internet?")
} }
if (ipv6) { if (ipv6) {
log.Println("updateDnsStatus() IPv6 AAAA lookups working") log.Log(DNS, "updateDnsStatus() IPv6 AAAA lookups working")
ds.setIPv4("GOOD") ds.setIPv4status("GOOD")
ds.setIPv6("GOOD") ds.setIPv6status("GOOD")
} else { } else {
log.Println("updateDnsStatus() IPv6 AAAA lookups are not working") log.Log(DNS, "updateDnsStatus() IPv6 AAAA lookups are not working")
ds.setIPv6("Need VPN") ds.setIPv6status("Need VPN")
} }
cmd = "dig +noall +answer www.wit.com A" cmd = "dig +noall +answer www.wit.com A"
out = shell.Run(cmd) out = shell.Run(cmd)
log.Println("makeDnsStatusGrid() dig", out) log.Log(DNS, "makeDnsStatusGrid() dig", out)
me.digStatus.set(ds.DnsDigUDP, out) me.digStatus.set(ds.DnsDigUDP, out)
cmd = "dig +noall +answer www.wit.com AAAA" cmd = "dig +noall +answer www.wit.com AAAA"
out = shell.Run(cmd) out = shell.Run(cmd)
log.Println("makeDnsStatusGrid() dig", out) log.Log(DNS, "makeDnsStatusGrid() dig", out)
me.digStatus.set(ds.DnsDigTCP, out) me.digStatus.set(ds.DnsDigTCP, out)
} }
@ -307,9 +322,9 @@ func (ds *dnsStatus) update() (bool, bool) {
var a bool = false var a bool = false
var aaaa bool = false var aaaa bool = false
log.Println("dnsStatus.update() For server", ds.server, "on", ds.hostname) log.Log(DNS, "dnsStatus.update() For server", ds.server, "on", ds.hostname)
results, _ = dnsUdpLookup(ds.server, ds.hostname, dns.TypeA) results, _ = dnsUdpLookup(ds.server, ds.hostname, dns.TypeA)
log.Println("dnsStatus.update() UDP type A =", results) log.Log(DNS, "dnsStatus.update() UDP type A =", results)
if (len(results) == 0) { if (len(results) == 0) {
me.digStatus.set(ds.udpA, "BROKEN") me.digStatus.set(ds.udpA, "BROKEN")
@ -321,7 +336,7 @@ func (ds *dnsStatus) update() (bool, bool) {
} }
results, _ = dnsTcpLookup(ds.server, ds.hostname, dns.TypeA) results, _ = dnsTcpLookup(ds.server, ds.hostname, dns.TypeA)
log.Println("dnsStatus.update() TCP type A =", results) log.Log(DNS, "dnsStatus.update() TCP type A =", results)
if (len(results) == 0) { if (len(results) == 0) {
me.digStatus.set(ds.tcpA, "BROKEN") me.digStatus.set(ds.tcpA, "BROKEN")
@ -336,7 +351,7 @@ func (ds *dnsStatus) update() (bool, bool) {
me.digStatus.set(ds.aSuccess,strconv.Itoa(ds.aSuccessc)) me.digStatus.set(ds.aSuccess,strconv.Itoa(ds.aSuccessc))
results, _ = dnsUdpLookup(ds.server, ds.hostname, dns.TypeAAAA) results, _ = dnsUdpLookup(ds.server, ds.hostname, dns.TypeAAAA)
log.Println("dnsStatus.update() UDP type AAAA =", results) log.Log(DNS, "dnsStatus.update() UDP type AAAA =", results)
if (len(results) == 0) { if (len(results) == 0) {
me.digStatus.set(ds.udpAAAA, "BROKEN") me.digStatus.set(ds.udpAAAA, "BROKEN")
@ -349,7 +364,7 @@ func (ds *dnsStatus) update() (bool, bool) {
} }
results, _ = dnsTcpLookup(ds.server, ds.hostname, dns.TypeAAAA) results, _ = dnsTcpLookup(ds.server, ds.hostname, dns.TypeAAAA)
log.Println("dnsStatus.update() UDP type AAAA =", results) log.Log(DNS, "dnsStatus.update() UDP type AAAA =", results)
if (len(results) == 0) { if (len(results) == 0) {
me.digStatus.set(ds.tcpAAAA, "BROKEN") me.digStatus.set(ds.tcpAAAA, "BROKEN")
@ -387,14 +402,14 @@ func (ds *digStatus) makeDnsStatusGrid() {
grid.NewLabel(cmd) grid.NewLabel(cmd)
ds.DnsDigUDP = grid.NewLabel("?") ds.DnsDigUDP = grid.NewLabel("?")
out = shell.Run(cmd) out = shell.Run(cmd)
log.Println("makeDnsStatusGrid() dig", out) log.Log(DNS, "makeDnsStatusGrid() dig", out)
me.digStatus.set(ds.DnsDigUDP, out) me.digStatus.set(ds.DnsDigUDP, out)
cmd = "dig +noall +answer go.wit.com AAAA" cmd = "dig +noall +answer go.wit.com AAAA"
grid.NewLabel(cmd) grid.NewLabel(cmd)
ds.DnsDigTCP = grid.NewLabel("?") ds.DnsDigTCP = grid.NewLabel("?")
out = shell.Run(cmd) out = shell.Run(cmd)
log.Println("makeDnsStatusGrid() dig", out) log.Log(DNS, "makeDnsStatusGrid() dig", out)
me.digStatus.set(ds.DnsDigTCP, out) me.digStatus.set(ds.DnsDigTCP, out)
group.Pad() group.Pad()
@ -443,19 +458,20 @@ func dnsTcpLookup(server string, domain string, recordType uint16) ([]string, er
func (ds *digStatus) checkLookupDoH(hostname string) bool { func (ds *digStatus) checkLookupDoH(hostname string) bool {
var status bool = false var status bool = false
domain := "go.wit.com" ipv6Addresses, err := dnsAAAAlookupDoH(hostname)
ipv6Addresses, err := dnsAAAAlookupDoH(domain)
if err != nil { if err != nil {
log.Error(err, "checkLookupDoH()") log.Error(err, "checkLookupDoH()")
return status return status
} }
log.Println("IPv6 Addresses for %s:\n", domain) log.Log(DNS, "IPv6 Addresses for ", hostname)
var s []string
for _, addr := range ipv6Addresses { for _, addr := range ipv6Addresses {
log.Println(addr) log.Log(DNS, addr)
me.digStatus.set(ds.httpGoWitCom, addr) s = append(s, addr)
status = true status = true
} }
me.digStatus.SetIPv6(strings.Join(s, "\n"))
return status return status
} }

118
gui.go
View File

@ -6,11 +6,9 @@ import (
"os" "os"
"os/user" "os/user"
"strconv" "strconv"
// "net"
"strings" "strings"
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/shell"
"go.wit.com/gui/gui" "go.wit.com/gui/gui"
"go.wit.com/gui/gadgets" "go.wit.com/gui/gadgets"
@ -100,8 +98,9 @@ func debugTab(title string) {
}) })
g2.NewButton("dig +trace", func () { g2.NewButton("dig +trace", func () {
o := shell.Run("dig +trace +noadditional DS " + me.hostname + " @8.8.8.8") log.Log(NOW, "TODO: redo this")
log.Println(o) // o := shell.Run("dig +trace +noadditional DS " + me.hostname + " @8.8.8.8")
// log.Println(o)
}) })
g2 = me.debug.Box().NewGroup("debugging options") g2 = me.debug.Box().NewGroup("debugging options")
@ -149,14 +148,14 @@ func missingAAAA() string {
func displayDNS() string { func displayDNS() string {
var aaaa []string var aaaa []string
aaaa = dhcpAAAA() // your AAAA records right now 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"
for _, s := range aaaa { for _, s := range aaaa {
log.Log(NOW, "host", h, "DNS AAAA =", s, "ipmap[s] =", me.ipmap[s]) log.Log(STATUS, "host", "fixme", "DNS AAAA =", s, "ipmap[s] =", me.ipmap[s])
all += s + "\n" all += s + "\n"
if ( me.ipmap[s] == nil) { if ( me.ipmap[s] == nil) {
log.Warn("THIS IS THE WRONG AAAA DNS ENTRY: host", h, "DNS AAAA =", s) log.Warn("THIS IS THE WRONG AAAA DNS ENTRY: host", "fixme", "DNS AAAA =", s)
broken = "wrong AAAA entry" broken = "wrong AAAA entry"
} else { } else {
if (broken == "unknown") { if (broken == "unknown") {
@ -166,7 +165,7 @@ func displayDNS() string {
} }
all = sortLines(all) all = sortLines(all)
if (me.workingIPv6.S != all) { if (me.workingIPv6.S != all) {
log.Warn("workingIPv6.SetText() to:", all) log.Log(NOW, "workingIPv6.SetText() to:", all)
me.workingIPv6.SetText(all) me.workingIPv6.SetText(all)
} }
@ -174,11 +173,11 @@ func displayDNS() string {
a = realA() a = realA()
all = sortLines(strings.Join(a, "\n")) all = sortLines(strings.Join(a, "\n"))
if (all == "") { if (all == "") {
log.Info("THERE IS NOT a real A DNS ENTRY") log.Log(NOW, "THERE IS NOT a real A DNS ENTRY")
all = "CNAME ipv6.wit.com" all = "CNAME ipv6.wit.com"
} }
if (me.DnsA.S != all) { if (me.DnsA.S != all) {
log.Warn("DnsA.SetText() to:", all) log.Log(NOW, "DnsA.SetText() to:", all)
me.DnsA.SetText(all) me.DnsA.SetText(all)
} }
return broken return broken
@ -199,19 +198,18 @@ func mainWindow(title string) {
grid.NewLabel("hostname =") grid.NewLabel("hostname =")
me.fqdn = grid.NewLabel("?") me.fqdn = grid.NewLabel("?")
me.hostname = ""
grid.NewLabel("DNS AAAA =") // grid.NewLabel("DNS AAAA =")
me.DnsAAAA = grid.NewLabel("?") me.DnsAAAA = gadgets.NewOneLiner(grid, "DNS AAAA =").Set("unknown")
grid.NewLabel("DNS A =") grid.NewLabel("DNS A =")
me.DnsA = grid.NewLabel("?") me.DnsA = grid.NewLabel("?")
me.digStatus = NewDigStatusWindow(me.myGui) me.digStatus = NewDigStatusWindow(me.myGui)
me.hostnameStatus = NewHostnameStatusWindow(me.myGui) me.status = NewHostnameStatusWindow(me.myGui)
me.hostnameStatusButton = me.mainStatus.NewButton("Fix hostname DNS", func () { me.hostnameStatusButton = me.mainStatus.NewButton("Fix hostname DNS", func () {
me.hostnameStatus.window.Toggle() me.status.window.Toggle()
}) })
grid.Margin() grid.Margin()
@ -220,19 +218,16 @@ func mainWindow(title string) {
statusGrid(me.window.Box()) statusGrid(me.window.Box())
gr := me.window.Box().NewGroup("debugging") gr := me.window.Box().NewGroup("debugging")
gr.NewButton("GO GUI Debugger", func () {
debugger.DebugWindow(me.myGui)
})
gr.NewButton("OS Details", func () { gr.NewButton("OS Details", func () {
me.details.Toggle() me.details.Toggle()
}) })
gr.NewButton("DNS Debug", func () {
me.debug.Toggle()
})
gr.NewButton("Resolver Status", func () { gr.NewButton("Resolver Status", func () {
if ! me.digStatus.Ready() {return} if ! me.digStatus.Ready() {return}
me.digStatus.window.Toggle() me.digStatus.window.Toggle()
}) })
gr.NewButton("Control Panel Debug", func () {
me.debug.Toggle()
})
} }
func statusGrid(n *gui.Node) { func statusGrid(n *gui.Node) {
@ -240,15 +235,15 @@ func statusGrid(n *gui.Node) {
gridP := problems.NewGrid("nuts", 2, 2) gridP := problems.NewGrid("nuts", 2, 2)
gridP.NewLabel("hostname =")
me.hostnameStatus = gridP.NewLabel("invalid")
gridP.NewLabel("DNS Status =") gridP.NewLabel("DNS Status =")
me.DnsStatus = gridP.NewLabel("unknown") me.DnsStatus = gridP.NewLabel("unknown")
me.statusIPv6 = gadgets.NewOneLiner(gridP, "IPv6 working") me.statusIPv6 = gadgets.NewOneLiner(gridP, "IPv6 working")
me.statusIPv6.Set("known") me.statusIPv6.Set("known")
gridP.NewLabel("hostname =")
me.hostnameStatusOLD = gridP.NewLabel("invalid")
gridP.NewLabel("dns resolution") gridP.NewLabel("dns resolution")
me.DnsSpeed = gridP.NewLabel("unknown") me.DnsSpeed = gridP.NewLabel("unknown")
@ -279,52 +274,51 @@ func statusGrid(n *gui.Node) {
// run everything because something has changed // run everything because something has changed
func updateDNS() { func updateDNS() {
var aaaa []string
h := me.hostname
if (h == "") {
h = "test.wit.com"
}
me.digStatus.Update() me.digStatus.Update()
me.hostnameStatus.Update() me.status.Update()
// log.Println("digAAAA()") // log.Println("digAAAA()")
aaaa = digAAAA(h)
log.Log(NOW, "digAAAA() =", aaaa)
// log.Println(SPEW, me) if me.status.ValidHostname() {
if (aaaa == nil) { var aaaa []string
log.Warn("There are no DNS AAAA records for hostname: ", h) h := me.status.GetHostname()
me.DnsAAAA.SetText("(none)") aaaa = digAAAA(h)
if (cloudflare.CFdialog.TypeNode != nil) { log.Log(NOW, "digAAAA() for", h, "=", aaaa)
cloudflare.CFdialog.TypeNode.SetText("AAAA new")
}
if (cloudflare.CFdialog.NameNode != nil) { // log.Println(SPEW, me)
cloudflare.CFdialog.NameNode.SetText(me.hostname) if (aaaa == nil) {
} log.Warn("There are no DNS AAAA records for hostname: ", h)
me.DnsAAAA.Set("(none)")
d := deleteAAA() if (cloudflare.CFdialog.TypeNode != nil) {
if (d != "") { cloudflare.CFdialog.TypeNode.SetText("AAAA new")
if (cloudflare.CFdialog.ValueNode != nil) {
cloudflare.CFdialog.ValueNode.SetText(d)
} }
}
m := missingAAAA() if (cloudflare.CFdialog.NameNode != nil) {
if (m != "") { cloudflare.CFdialog.NameNode.SetText(h)
if (cloudflare.CFdialog.ValueNode != nil) {
cloudflare.CFdialog.ValueNode.SetText(m)
} }
/*
rr := &cloudflare.RRT{ d := deleteAAA()
Type: "AAAA", if (d != "") {
Name: me.hostname, if (cloudflare.CFdialog.ValueNode != nil) {
Ttl: "Auto", cloudflare.CFdialog.ValueNode.SetText(d)
Proxied: false, }
Content: m, }
m := missingAAAA()
if (m != "") {
if (cloudflare.CFdialog.ValueNode != nil) {
cloudflare.CFdialog.ValueNode.SetText(m)
}
/*
rr := &cloudflare.RRT{
Type: "AAAA",
Name: me.hostname,
Ttl: "Auto",
Proxied: false,
Content: m,
}
cloudflare.Update(rr)
*/
} }
cloudflare.Update(rr)
*/
} }
} }
status := displayDNS() // update the GUI based on dig results status := displayDNS() // update the GUI based on dig results

View File

@ -22,14 +22,7 @@ func getHostname() {
log.Error(err, "FQDN hostname error") log.Error(err, "FQDN hostname error")
return return
} }
if (me.fqdn != nil) { me.status.SetHostname(s)
if (me.hostname != s) {
me.fqdn.SetText(s)
me.hostname = s
me.changed = true
}
}
log.Log(NET, "FQDN =", s)
dn := run("domainname") dn := run("domainname")
if (me.domainname.S != dn) { if (me.domainname.S != dn) {
@ -47,17 +40,17 @@ func getHostname() {
var test string var test string
test = hshort + "." + dn test = hshort + "." + dn
if (me.hostname != test) { if (me.status.GetHostname() != test) {
log.Info("me.hostname", me.hostname, "does not equal", test) log.Log(CHANGE, "me.hostname", me.status.GetHostname(), "does not equal", test)
if (me.hostnameStatusOLD.S != "BROKEN") { if (me.hostnameStatus.S != "BROKEN") {
log.Log(CHANGE, "me.hostname", me.hostname, "does not equal", test) log.Log(CHANGE, "me.hostname", me.status.GetHostname(), "does not equal", test)
me.changed = true me.changed = true
me.hostnameStatusOLD.SetText("BROKEN") me.hostnameStatus.SetText("BROKEN")
} }
} else { } else {
if (me.hostnameStatusOLD.S != "VALID") { if (me.hostnameStatus.S != "VALID") {
log.Log(CHANGE, "me.hostname", me.hostname, "is valid") log.Log(CHANGE, "me.hostname", me.status.GetHostname(), "is valid")
me.hostnameStatusOLD.SetText("VALID") me.hostnameStatus.SetText("VALID")
me.changed = true me.changed = true
} }
// enable the cloudflare button if the provider is cloudflare // enable the cloudflare button if the provider is cloudflare
@ -76,7 +69,7 @@ func getHostname() {
// check that all the OS settings are correct here // check that all the OS settings are correct here
// On Linux, /etc/hosts, /etc/hostname // On Linux, /etc/hosts, /etc/hostname
// and domainname and hostname // and domainname and hostname
func goodHostname(h string) bool { func goodHostname() bool {
hostname := shell.Chomp(shell.Cat("/etc/hostname")) hostname := shell.Chomp(shell.Cat("/etc/hostname"))
log.Log(NOW, "hostname =", hostname) log.Log(NOW, "hostname =", hostname)
@ -141,20 +134,3 @@ func digAAAA(hostname string) []string {
return blah return blah
} }
/*
func dnsHttpsLookup(domain string, recordType uint16) ([]string, error) {
domain := "google.com"
dnsLookupDoH(domain string) ([]string, error) {
ipv6Addresses, err := dnsLookupDoH(domain)
if err != nil {
log.Println("Error:", err)
return
}
log.Printf("IPv6 Addresses for %s:\n", domain)
for _, addr := range ipv6Addresses {
log.Println(addr)
}
}
*/

View File

@ -23,7 +23,8 @@ type hostnameStatus struct {
ready bool ready bool
hidden bool hidden bool
hostname string // my hostname. Example: "test.wit.com" // hostname string // my hostname. Example: "test.wit.com"
lastname string // used to watch for changes in the hostname
window *gadgets.BasicWindow window *gadgets.BasicWindow
@ -60,9 +61,9 @@ func NewHostnameStatusWindow(p *gui.Node) *hostnameStatus {
hs.ready = false hs.ready = false
hs.hidden = true hs.hidden = true
hs.hostname = me.hostname // hs.hostname = me.hostname
hs.window = gadgets.NewBasicWindow(p, hs.hostname + " Status") hs.window = gadgets.NewBasicWindow(p, "fix hostname here" + " Status")
hs.window.Draw() hs.window.Draw()
hs.window.Hide() hs.window.Hide()
@ -116,6 +117,25 @@ func NewHostnameStatusWindow(p *gui.Node) *hostnameStatus {
return hs return hs
} }
func (hs *hostnameStatus) ValidHostname() bool {
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 ""}
return hs.domainname.Get() return hs.domainname.Get()
@ -128,26 +148,26 @@ func (hs *hostnameStatus) API() string {
func (hs *hostnameStatus) deleteDNSrecord(value string) bool { func (hs *hostnameStatus) deleteDNSrecord(value string) bool {
log.Info("deleteDNSrecord() START for", value) log.Info("deleteDNSrecord() START for", value)
log.Info("deleteDNSrecord() hostname =", me.hostname) log.Info("deleteDNSrecord() hostname =", me.status.GetHostname())
log.Info("deleteDNSrecord() domain =", hs.Domain()) log.Info("deleteDNSrecord() domain =", hs.Domain())
log.Info("deleteDNSrecord() DNS API Provider =", hs.API()) log.Info("deleteDNSrecord() DNS API Provider =", hs.API())
if (hs.API() == "cloudflare") { if (hs.API() == "cloudflare") {
log.Info("deleteDNSrecord() Try to delete via cloudflare") log.Info("deleteDNSrecord() Try to delete via cloudflare")
return cloudflare.Delete(hs.Domain(), me.hostname, value) return cloudflare.Delete(hs.Domain(), me.status.GetHostname(), value)
} }
return false return false
} }
func (hs *hostnameStatus) createDNSrecord(value string) bool { func (hs *hostnameStatus) createDNSrecord(value string) bool {
log.Info("createDNSrecord() START for", value) log.Info("createDNSrecord() START for", value)
log.Info("createDNSrecord() hostname =", me.hostname) log.Info("createDNSrecord() hostname =", me.status.GetHostname())
log.Info("createDNSrecord() domain =", hs.Domain()) log.Info("createDNSrecord() domain =", hs.Domain())
log.Info("createDNSrecord() DNS API Provider =", hs.API()) log.Info("createDNSrecord() DNS API Provider =", hs.API())
if (hs.API() == "cloudflare") { if (hs.API() == "cloudflare") {
log.Warn("createDNSrecord() Try to delete via cloudflare:", me.hostname, value) log.Warn("createDNSrecord() Try to create via cloudflare:", me.status.GetHostname(), value)
return cloudflare.Create(hs.Domain(), me.hostname, value) return cloudflare.Create(hs.Domain(), me.status.GetHostname(), value)
} }
return false return false
} }
@ -229,10 +249,10 @@ func (hs *hostnameStatus) set(a any, s string) {
if reflect.TypeOf(a) == reflect.TypeOf(ol) { if reflect.TypeOf(a) == reflect.TypeOf(ol) {
ol = a.(*gadgets.OneLiner) ol = a.(*gadgets.OneLiner)
if ol == nil { if ol == nil {
log.Println("ol = nil", reflect.TypeOf(a), "a =", a) // log.Println("ol = nil", reflect.TypeOf(a), "a =", a)
return return
} }
log.Println("SETTING ol:", ol) // log.Println("SETTING ol:", ol)
ol.Set(s) ol.Set(s)
return return
} }
@ -240,15 +260,26 @@ func (hs *hostnameStatus) set(a any, s string) {
os.Exit(0) os.Exit(0)
} }
// returns true if AAAA record already exists in DNS
func (hs *hostnameStatus) existsAAAA(s string) bool {
log.Log(NOW, "existsAAAA() try to see if AAAA is already set", s)
return false
}
// figure out if I'm missing any IPv6 address in DNS // figure out if I'm missing any IPv6 address in DNS
func (hs *hostnameStatus) missingAAAA() bool { func (hs *hostnameStatus) missingAAAA() bool {
var aaaa []string var aaaa []string
aaaa = dhcpAAAA() aaaa = dhcpAAAA()
for _, s := range aaaa { for _, s := range aaaa {
log.Log(NET, "my actual AAAA = ",s) log.Log(NET, "my actual AAAA = ",s)
hs.dnsValue.SetText(s) if hs.existsAAAA(s) {
hs.dnsAction.SetText("CREATE") log.Log(NOW, "my actual AAAA already exists in DNS =",s)
return true } else {
log.Log(NOW, "my actual AAAA is missing from DNS",s)
hs.dnsValue.SetText(s)
hs.dnsAction.SetText("CREATE")
return true
}
} }
return false return false
@ -257,46 +288,48 @@ func (hs *hostnameStatus) missingAAAA() bool {
func (hs *hostnameStatus) updateStatus() { func (hs *hostnameStatus) updateStatus() {
var s string var s string
var vals []string var vals []string
log.Info("updateStatus() START") log.Log(STATUS, "updateStatus() START")
if ! hs.Ready() { return } if ! hs.Ready() { return }
hs.hostShort.Set(me.hostshort.S) hs.hostShort.Set(me.hostshort.S)
hs.domainname.Set(me.domainname.S) hs.domainname.Set(me.domainname.S)
vals = lookupDoH(hs.hostname, "AAAA") if hs.ValidHostname() {
vals = lookupDoH(hs.GetHostname(), "AAAA")
log.Println("DNS IPv6 Addresses for ", hs.hostname, "=", vals) log.Log(STATUS, "DNS IPv6 Addresses for ", hs.GetHostname(), "=", vals)
if len(vals) == 0 { if len(vals) == 0 {
s = "(none)" s = "(none)"
hs.setIPv6("Check for real IPv6 addresses here") hs.setIPv6("Check for real IPv6 addresses here")
if hs.missingAAAA() { if hs.missingAAAA() {
hs.setIPv6("Add the missing IPv6 address") hs.setIPv6("Add the missing IPv6 address")
}
} else {
for _, addr := range vals {
log.Log(STATUS, addr)
s += addr + " (DELETE)"
hs.setIPv6("NEEDS DELETE")
hs.dnsValue.SetText(addr)
hs.dnsAction.SetText("DELETE")
}
} }
} else { hs.set(hs.dnsAAAA, s)
for _, addr := range vals {
log.Println(addr) vals = lookupDoH(hs.GetHostname(), "A")
s += addr + " (DELETE)" log.Log(STATUS, "IPv4 Addresses for ", hs.GetHostname(), "=", vals)
hs.setIPv6("NEEDS DELETE") s = strings.Join(vals, "\n")
hs.dnsValue.SetText(addr) if (s == "") {
hs.dnsAction.SetText("DELETE") s = "(none)"
hs.setIPv4("NEEDS CNAME")
} }
} hs.set(hs.dnsA, s)
hs.set(hs.dnsAAAA, s)
vals = lookupDoH(hs.hostname, "A") vals = lookupDoH(hs.GetHostname(), "CNAME")
log.Println("IPv4 Addresses for ", hs.hostname, "=", vals) s = strings.Join(vals, "\n")
s = strings.Join(vals, "\n") if (s != "") {
if (s == "") { hs.set(hs.dnsA, "CNAME " + s)
s = "(none)" hs.setIPv4("GOOD")
hs.setIPv4("NEEDS CNAME") }
}
hs.set(hs.dnsA, s)
vals = lookupDoH(hs.hostname, "CNAME")
s = strings.Join(vals, "\n")
if (s != "") {
hs.set(hs.dnsA, "CNAME " + s)
hs.setIPv4("GOOD")
} }
hs.currentIPv4.Set(me.IPv4.S) hs.currentIPv4.Set(me.IPv4.S)
@ -312,7 +345,7 @@ func (hs *hostnameStatus) updateStatus() {
} }
func (hs *hostnameStatus) Show() { func (hs *hostnameStatus) Show() {
log.Info("hostnameStatus.Show() window") log.Log(STATUS, "hostnameStatus.Show() window")
if hs.hidden { if hs.hidden {
hs.window.Show() hs.window.Show()
} }
@ -320,7 +353,7 @@ func (hs *hostnameStatus) Show() {
} }
func (hs *hostnameStatus) Hide() { func (hs *hostnameStatus) Hide() {
log.Info("hostnameStatus.Hide() window") log.Log(STATUS, "hostnameStatus.Hide() window")
if ! hs.hidden { if ! hs.hidden {
hs.window.Hide() hs.window.Hide()
} }

View File

@ -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.hostname 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 {

View File

@ -13,10 +13,13 @@ import (
var me Host var me Host
type Host struct { type Host struct {
hostname string // mirrors status *hostnameStatus // keeps track of the hostname and it's status
hostnameStatus *gui.Node // a summary for the user of where things are
// hostname string // mirrors
domainname *gui.Node // kernel.org domainname *gui.Node // kernel.org
hostshort *gui.Node // hostname -s hostshort *gui.Node // hostname -s
hostnameStatusOLD *gui.Node // is the hostname configured correctly in the OS?
// fqdn string // mirrors.kernel.org // fqdn string // mirrors.kernel.org
// dnsTTL int `default:"3"` // Recheck DNS is working every TTL (in seconds) // dnsTTL int `default:"3"` // Recheck DNS is working every TTL (in seconds)
@ -59,7 +62,7 @@ type Host struct {
// DNS stuff // DNS stuff
NSrr *gui.Node // NS resource records for the domain name 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 *gui.Node // the actual DNS AAAA results DnsAAAA *gadgets.OneLiner // the actual DNS AAAA results
workingIPv6 *gui.Node // currently working AAAA 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
@ -81,7 +84,6 @@ type Host struct {
statusIPv6 *gadgets.OneLiner statusIPv6 *gadgets.OneLiner
digStatusButton *gui.Node digStatusButton *gui.Node
hostnameStatus *hostnameStatus
hostnameStatusButton *gui.Node hostnameStatusButton *gui.Node
myDebug *gui.Node myDebug *gui.Node