start rewrite after some years of nothing

This commit is contained in:
Jeff Carr 2024-03-02 11:51:16 -06:00
parent 7b4eb41de7
commit 46de348eb2
7 changed files with 46 additions and 17 deletions

View File

@ -39,8 +39,15 @@ func makeMainWindow() {
}
}
me.autofix = group.NewCheckbox("Auto-correct Errors")
me.autofix.SetChecked(false)
autofix := group.NewCheckbox("Auto-correct Errors").SetChecked(true)
os.Setenv("DNS_AUTOCORRECT", "true")
autofix.Custom = func() {
if autofix.Checked() {
os.Setenv("DNS_AUTOCORRECT", "true")
} else {
os.Unsetenv("DNS_AUTOCORRECT")
}
}
}
func statusGrid(n *gui.Node) {

View File

@ -5,6 +5,7 @@
package main
import (
"os"
"time"
"go.wit.com/gui"
@ -146,8 +147,8 @@ func (eb *errorBox) fix(key string) bool {
}
myErr := eb.fixes[key]
log.Log(WARN, "should try to fix", myErr.problem.kind, "here. IP =", myErr.problem.aaaa)
if !me.autofix.Checked() {
log.Log(WARN, "not autofixing. autofix == false")
if os.Getenv("DNS_AUTOCORRECT") != "true" {
log.Log(WARN, "not autofixing. $DNS_AUTOCORRECT != true")
log.Log(WARN, "problem.kind =", myErr.problem.kind)
log.Log(WARN, "problem.action =", myErr.problem.action)
log.Log(WARN, "problem.aaaa =", myErr.problem.aaaa)

12
fix.go
View File

@ -2,6 +2,8 @@
package main
import (
"strings"
"go.wit.com/lib/gadgets"
"go.wit.com/lib/gui/cloudflare"
"go.wit.com/log"
@ -68,12 +70,20 @@ func fixIPv6dns() bool {
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(WARN, "statusDNS.GetIPv6() FOUND DNS AAAA ip", aaaa)
dnsAAAA[aaaa] = "dns"
}
// remove old DNS entries first
for aaaa, _ := range dnsAAAA {
aaaa = strings.TrimSpace(aaaa)
if aaaa == "" {
log.Log(WARN, "AAAA is blank")
log.Log(WARN, "AAAA is blank")
log.Log(WARN, "AAAA is blank sleep 10")
log.Sleep(10)
continue
}
if osAAAA[aaaa] == "os" {
log.Log(INFO, "DNS AAAA is in OS", aaaa)
} else {

View File

@ -64,7 +64,7 @@ func InitHostnameStatus() *hostnameStatus {
hs.hidden = true
// hs.hostname = me.hostname
hs.window = gadgets.RawBasicWindow("fix hostname here"+" Status")
hs.window = gadgets.RawBasicWindow("fix hostname here" + " Status")
hs.window.Make()
// hs.window.Draw()
// hs.window.Hide()
@ -118,7 +118,7 @@ func (hs *hostnameStatus) API() string {
}
func (hs *hostnameStatus) Update() {
log.Info("hostnameStatus() Update() START")
// log.Info("hostnameStatus() Update() START")
if hs == nil {
log.Error(errors.New("hostnameStatus() Update() hs == nil"))
return
@ -136,7 +136,7 @@ func (hs *hostnameStatus) Update() {
} else {
hs.set(hs.speed, "FAST")
}
log.Info("hostnameStatus() Update() END")
// log.Info("hostnameStatus() Update() END")
}
// Returns true if the status is valid
@ -227,7 +227,11 @@ func (hs *hostnameStatus) GetIPv6() []string {
if !hs.Ready() {
return nil
}
return strings.Split(hs.dnsAAAA.String(), "\n")
// clean out any blank lines
// todo: fix this whole hacky thing
tmp := hs.dnsAAAA.String()
tmp = strings.TrimSpace(tmp)
return strings.Split(tmp, "\n")
}
func (hs *hostnameStatus) updateStatus() {
@ -305,7 +309,7 @@ func (hs *hostnameStatus) updateStatus() {
}
last := hs.statusIPv6.String()
if hs.verifyIPv6() {
if ok, err := hs.verifyIPv6(); ok {
if last != "WORKING" {
log.Log(CHANGE, "Your DNS IPv6 has started working.", me.statusOS.GetHostname(), "should now work")
hs.changed = true
@ -314,7 +318,7 @@ func (hs *hostnameStatus) updateStatus() {
}
} else {
if last != "BROKEN" {
log.Log(CHANGE, "Your DNS entries for IPv6 have BROKEN")
log.Log(CHANGE, "Your DNS entries for IPv6 have BROKEN", ok, err)
hs.changed = true
hs.statusIPv6.SetText("BROKEN")
me.DnsStatus.SetText("BROKEN")
@ -322,8 +326,13 @@ func (hs *hostnameStatus) updateStatus() {
}
}
func (hs *hostnameStatus) verifyIPv6() bool {
var ErrorNoIPv6 error = errors.New("OS has no IPv6")
var ErrorDeleteIPv6 error = errors.New("IPv6 Delete")
var ErrorCreateIPv6 error = errors.New("IPv6 Create")
func (hs *hostnameStatus) verifyIPv6() (bool, error) {
var working bool = true
var err error = nil
osAAAA := make(map[string]string)
dnsAAAA := make(map[string]string)
@ -331,7 +340,7 @@ func (hs *hostnameStatus) verifyIPv6() bool {
tmp := me.statusOS.GetIPv6()
if len(tmp) == 0 {
// you don't have any IPv6 addresses in your OS right now
return false
return false, ErrorNoIPv6
}
for _, aaaa := range me.statusOS.GetIPv6() {
log.Log(INFO, "FOUND OS AAAA ip", aaaa)
@ -351,6 +360,7 @@ func (hs *hostnameStatus) verifyIPv6() bool {
working = false
log.Log(INFO, "DNS AAAA is not in OS", aaaa)
addToFixWindow("DELETE", aaaa)
err = ErrorDeleteIPv6
}
}
@ -361,10 +371,11 @@ func (hs *hostnameStatus) verifyIPv6() bool {
working = false
log.Log(INFO, "OS AAAA is not in DNS", aaaa)
addToFixWindow("CREATE", aaaa)
err = ErrorCreateIPv6
}
}
return working
return working, err
}
func (hs *hostnameStatus) Show() {

View File

@ -47,7 +47,7 @@ func main() {
// These are your problems
me.problems = InitErrorBox(me.window.Box(), "Errors", "has problems?")
me.problems.addIPerror(RR, USER, "1:1:1:1")
// me.problems.addIPerror(RR, USER, "1:1:1:1")
me.window.Show()

View File

@ -66,7 +66,7 @@ type Host struct {
showErrorsB *gui.Node
problems *errorBox
autofix *gui.Node
// autofix *gui.Node
}
type IPtype struct {