diff --git a/Makefile b/Makefile index c0c1012..ec8440a 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,9 @@ .PHONY: debian run: build + reset cp -f control-panel-dns ~/ - ./control-panel-dns + sudo ./control-panel-dns build: -mkdir -p resources/ @@ -117,3 +118,14 @@ ssl-cert-hash: sudo-cp: sudo cp -a lets-encrypt-r3.pem 8d33f237.0 /etc/ssl/certs/ + +# apt install uml-utilities +fake0-up: + tunctl -t fake0 + ifconfig fake0 up + # ifconfig fake0 inet6 add 2001:470:1f12:2cd::2/64 + ifconfig fake0 inet6 add 2604:BBC0:1234:1234::1234/128 + +fake0-down: + ifconfig fake0 down + tunctl -d fake0 diff --git a/errorBox.go b/errorBox.go index 427b86e..3b4d432 100644 --- a/errorBox.go +++ b/errorBox.go @@ -103,10 +103,34 @@ func (eb *errorBox) addIPerror(kind ProblemType, action ActionType, ip string) b } tmp := kind.String() + " " + ip if eb.fixes[tmp] != nil { - log.Log(WARN, "Error is already here", kind, ip) - log.Log(WARN, "kind =", kind) - log.Log(WARN, "action =", action) - log.Log(WARN, "ip =", ip) + log.Log(WARN, "Error is already here tmp =", tmp) + log.Log(WARN, "kind =", kind, "action =", action, "ip =", ip) + log.Log(WARN, "Need to check here if this thing is fixed") + thing := eb.fixes[tmp] + switch action { + case CREATE: + log.Log(WARN, "ValidDNS() CREATE begun =", thing.problem.begun) + if ValidDNS(ip) { + log.Log(WARN, "ValidDNS() == true begun =", thing.problem.begun) + if thing.problem.begun { + log.Log(WARN, "CREATE WORKED. IP is in DNS.", ip) + } + } else { + log.Log(WARN, "ValidDNS() == false. begun =", thing.problem.begun) + } + case DELETE: + log.Log(WARN, "ValidDNS() DELETE begun =", thing.problem.begun) + if ValidDNS(ip) { + if thing.problem.begun { + log.Log(WARN, "DELETE FAILED. IP is still in DNS", ip) + } + } else { + log.Log(WARN, "ValidDNS() == false. begun =", thing.problem.begun) + } + default: + log.Log(WARN, "ValidDNS() begun =", thing.problem.begun) + log.Log(WARN, "ValidDNS() unhandled ACTION", action) + } return false } @@ -209,8 +233,13 @@ func (eb *errorBox) Scan() []anError { log.Log(WARN, "Scan()", "attempted to fix has happened") } else { log.Log(WARN, "Scan()", "attempted to fix not yet happened") - thing.Fix() + if thing.Fix() { + log.Log(WARN, "Scan()", "FIXED OK") + } else { + log.Log(WARN, "Scan()", "FIX FAILED") + } } + thing.button.Disable() } return nil diff --git a/fix.go b/fix.go index 4025c34..e4fdac6 100644 --- a/fix.go +++ b/fix.go @@ -57,6 +57,25 @@ func fix() bool { return true } +// returns true if the IP address is in DNS +func ValidDNS(ip string) bool { + // check for DNS AAAA RR's (Resource Record) + for _, aaaa := range me.statusDNS.GetIPv6() { + log.Log(WARN, "statusDNS.GetIPv6() FOUND DNS AAAA ip", aaaa) + if ip == aaaa { + return true + } + } + // check for DNS A RR's (Resource Record) + for _, a := range me.statusDNS.GetIPv4() { + log.Log(WARN, "statusDNS.GetIPv4() FOUND DNS A ip", a) + if ip == a { + return true + } + } + return false +} + func fixIPv6dns() bool { log.Log(INFO, "What are my IPv6 addresses?") var broken bool = false @@ -137,6 +156,11 @@ func deleteFromDNS(aaaa string) bool { return false } +// returns TRUE if there is a Resource Record in DNS for the AAAA value +func inDNS(aaaa string) bool { + return false +} + func addToDNS(aaaa string) bool { log.Log(CHANGE, "Add this to DNS !!!!", aaaa) api := me.statusDNS.API() diff --git a/hostnameStatusWindow.go b/hostnameStatusWindow.go index c37f430..0f5d777 100644 --- a/hostnameStatusWindow.go +++ b/hostnameStatusWindow.go @@ -234,6 +234,17 @@ func (hs *hostnameStatus) GetIPv6() []string { return strings.Split(tmp, "\n") } +func (hs *hostnameStatus) GetIPv4() []string { + if !hs.Ready() { + return nil + } + // clean out any blank lines + // todo: fix this whole hacky thing + tmp := hs.dnsA.String() + tmp = strings.TrimSpace(tmp) + return strings.Split(tmp, "\n") +} + func (hs *hostnameStatus) updateStatus() { if !hs.Ready() { return @@ -349,7 +360,7 @@ func (hs *hostnameStatus) verifyIPv6() (bool, error) { 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) + // log.Log(INFO, "FOUND DNS AAAA ip", aaaa) dnsAAAA[aaaa] = "dns" } diff --git a/main.go b/main.go index 0896047..36e98f0 100644 --- a/main.go +++ b/main.go @@ -15,8 +15,6 @@ import ( "go.wit.com/lib/gadgets" "go.wit.com/lib/gui/linuxstatus" - - "github.com/miekg/dns" ) //go:embed resources/* @@ -26,15 +24,8 @@ func main() { // parsedown() // initialize the maps to track IP addresses and network interfaces - me.ipmap = make(map[string]*IPtype) - me.dnsmap = make(map[string]*IPtype) - me.ifmap = make(map[int]*IFtype) me.nsmap = make(map[string]string) - // initialize maps for the returned DNS records - me.ipv4s = make(map[string]dns.RR) - me.ipv6s = make(map[string]dns.RR) - me.myGui = gui.New() me.myGui.InitEmbed(resToolkit) me.myGui.Default() diff --git a/structs.go b/structs.go index 4a1f8b8..94e0e8b 100644 --- a/structs.go +++ b/structs.go @@ -9,8 +9,6 @@ import ( "go.wit.com/lib/gadgets" "go.wit.com/lib/gui/linuxstatus" - - "github.com/miekg/dns" ) // It's probably a terrible idea to call this 'me' @@ -42,14 +40,8 @@ type Host struct { changed bool // set to true if things changed - ipmap map[string]*IPtype // the current ip addresses - dnsmap map[string]*IPtype // the current dns addresses - ifmap map[int]*IFtype // the current interfaces - nsmap map[string]string // the NS records - - // DNS A and AAAA results - ipv4s map[string]dns.RR - ipv6s map[string]dns.RR + ifmap map[int]*IFtype // the current interfaces + nsmap map[string]string // the NS records // DNS stuff DnsStatus *gui.Node // the current state of DNS