diff --git a/Makefile b/Makefile index 0c35f00..b1ae8ec 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,18 @@ .PHONY: debian + run: build # ./control-panel-dns >/tmp/witgui.log.stderr 2>&1 cp -f control-panel-dns ~/ ./control-panel-dns --tmp-log -redomod: +check-git-clean: + @git diff-index --quiet HEAD -- || (echo "Git repository is dirty, please commit your changes first"; exit 1) + +redomod: check-git-clean rm -f go.* - go mod init - go mod tidy + GO111MODULE= go mod init + GO111MODULE= go mod tidy install: go install -v go.wit.com/control-panel-dns@latest diff --git a/args.go b/args.go index 08fdd8a..b521e42 100644 --- a/args.go +++ b/args.go @@ -23,37 +23,33 @@ var NOW log.LogFlag var INFO log.LogFlag var NET log.LogFlag var DNS log.LogFlag + var WARN log.LogFlag var SPEW log.LogFlag + var CHANGE 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" - f.Short = "cpdns" - f.Desc = desc - f.Name = name - f.Register() -} - func init() { arg.MustParse(&args) - // fmt.Println(args.Foo, args.Bar, args.User) + full := "go.wit.com/control-panels/dns" + short := "cpdns" - myreg(&NOW, true, "NOW", "temp debugging stuff") - myreg(&INFO, false, "INFO", "normal debugging stuff") - myreg(&NET, false, "NET", "Network logging") - myreg(&DNS, false, "DNS", "dnsStatus.update()") - myreg(&WARN, true, "WARN", "bad things") - myreg(&SPEW, false, "SPEW", "spew stuff") - myreg(&CHANGE, true, "CHANGE", "when host or dns change") - myreg(&STATUS, false, "STATUS", "updateStatus()") + NOW.NewFlag( "NOW", true, full, short, "temp debugging stuff") + INFO.NewFlag("INFO", false, full, short, "normal debugging stuff") + NET.NewFlag( "NET", false, full, short, "Network logging") + DNS.NewFlag( "DNS", false, full, short, "dnsStatus.update()") + + WARN.NewFlag("WARN", true, full, short, "bad things") + SPEW.NewFlag("SPEW", false, full, short, "spew stuff") + + CHANGE.NewFlag("CHANGE", true, full, short, "when host or dns change") + STATUS.NewFlag("STATUS", false, full, short, "updateStatus() polling") if debugger.ArgDebug() { - log.Log(true, "INIT() gui debug == true") + log.Log(NOW, "INIT() gui debug == true") } else { - log.Log(true, "INIT() gui debug == false") + log.Log(NOW, "INIT() gui debug == false") } me.dnsSleep = 500 * time.Millisecond @@ -61,7 +57,7 @@ func init() { me.artificialSleep = 0.4 // seems to need to exist or GTK crashes. TODO: fix andlabs plugin me.artificialS = "blah" - log.Log(true, "init() me.artificialSleep =", me.artificialSleep) - log.Log(true, "init() me.artificialS =", me.artificialS) + log.Log(INFO, "init() me.artificialSleep =", me.artificialSleep) + log.Log(INFO, "init() me.artificialS =", me.artificialS) log.Sleep(me.artificialSleep) } diff --git a/errorBox.go b/errorBox.go index 72a7940..1c8c835 100644 --- a/errorBox.go +++ b/errorBox.go @@ -32,9 +32,12 @@ type anError struct { status string kindLabel *gui.Node + actionLabel *gui.Node ipLabel *gui.Node statusLabel *gui.Node button *gui.Node + + problem *Problem } func NewErrorBox(p *gui.Node, name string, ip string) *errorBox { @@ -42,9 +45,10 @@ func NewErrorBox(p *gui.Node, name string, ip string) *errorBox { eb = new(errorBox) eb.parent = p eb.group = p.NewGroup(name) - eb.grid = eb.group.NewGrid("stuff", 4, 1) + eb.grid = eb.group.NewGrid("stuff", 5, 1) eb.grid.NewLabel("Type") + eb.grid.NewLabel("Action") eb.grid.NewLabel("IP") eb.grid.NewLabel("Status") eb.grid.NewLabel("") @@ -80,25 +84,28 @@ func (eb *errorBox) Ready() bool { return eb.ready } -func (eb *errorBox) add(kind string, ip string) bool { +func (eb *errorBox) addIPerror(kind ProblemType, action ActionType, ip string) bool { if ! eb.Ready() {return false} - tmp := kind + " " + ip + tmp := kind.String() + " " + ip if eb.fixes[tmp] != nil { log.Log(WARN, "Error is already here", kind, ip) return false } anErr := new(anError) - anErr.kind = kind anErr.aaaa = ip - anErr.kindLabel = eb.grid.NewLabel(kind) + anErr.kindLabel = eb.grid.NewLabel(kind.String()) + anErr.actionLabel = eb.grid.NewLabel(action.String()) anErr.ipLabel = eb.grid.NewLabel(ip) anErr.statusLabel = eb.grid.NewLabel("") - anErr.button = eb.grid.NewButton("Fix", func() { + anErr.button = eb.grid.NewButton("Try to Fix", func() { log.Log(WARN, "got", kind, "here. IP =", ip) eb.fix(tmp) }) + anErr.problem = new(Problem) + anErr.problem.kind = kind + anErr.problem.aaaa = ip eb.fixes[tmp] = anErr return false } diff --git a/fix.go b/fix.go index d0a5eeb..4d71087 100644 --- a/fix.go +++ b/fix.go @@ -84,7 +84,8 @@ func fixIPv6dns() bool { } else { broken = true log.Log(INFO, "DNS AAAA is not in OS", aaaa) - addToFixWindow("DELETE", aaaa) + // addToFixWindow("DELETE", aaaa) + me.problems.addIPerror(RR, DELETE, aaaa) /* if deleteFromDNS(aaaa) { log.Log(INFO, "Delete AAAA", aaaa, "Worked") @@ -153,7 +154,7 @@ func exists(m map[string]bool, s string) bool { func addToFixWindow(t string, ip string) { log.Log(INFO, "addToFixWindow() START") if ! me.problems.Ready() { return } - me.problems.add(t, ip) + me.problems.addIPerror(RR, CREATE, ip) log.Log(INFO, "addToFixWindow() END") } diff --git a/gui.go b/gui.go index 719bf13..135e1aa 100644 --- a/gui.go +++ b/gui.go @@ -128,7 +128,7 @@ func mainWindow(title string) { // These are your problems me.problems = NewErrorBox(me.window.Box(), "Errors", "has problems?") - me.problems.add("SOMETHING", "1:1:1:1:3") + me.problems.addIPerror(RR, USER, "1:1:1:1") } diff --git a/linuxstatus/args.go b/linuxstatus/args.go index 4ba7ae1..bbc390a 100644 --- a/linuxstatus/args.go +++ b/linuxstatus/args.go @@ -12,29 +12,27 @@ var NOW log.LogFlag var INFO log.LogFlag var NET log.LogFlag var DNS log.LogFlag + var PROC log.LogFlag var SPEW log.LogFlag var WARN log.LogFlag + var CHANGE 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() { - myreg(&NOW, true, "NOW", "temp debugging stuff") - myreg(&INFO, false, "INFO", "normal debugging stuff") - myreg(&NET, false, "NET", "Network Logging") - myreg(&DNS, false, "DNS", "dnsStatus.update()") - myreg(&PROC, false, "PROC", "/proc logging") - myreg(&SPEW, false, "SPEW", "spew stuff") - myreg(&WARN, true, "WARN", "bad things") - myreg(&CHANGE, true, "CHANGE", "show droplet state changes") - myreg(&STATUS, false, "STATUS", "Update() details") + full := "go.wit.com/control-panels/dns/linuxstatus" + short := "linux" + + NOW.NewFlag( "NOW", true, full, short, "temp debugging stuff") + INFO.NewFlag("INFO", false, full, short, "normal debugging stuff") + NET.NewFlag( "NET", false, full, short, "Network logging") + DNS.NewFlag( "DNS", false, full, short, "dnsStatus.update()") + + PROC.NewFlag("PROC", false, full, short, "/proc loggging") + WARN.NewFlag("WARN", true, full, short, "bad things") + SPEW.NewFlag("SPEW", false, full, short, "spew stuff") + + CHANGE.NewFlag("CHANGE", true, full, short, "when host or dns change") + STATUS.NewFlag("STATUS", false, full, short, "Update() details") } diff --git a/linuxstatus/net.go b/linuxstatus/net.go index cbb7ad5..f0ccd17 100644 --- a/linuxstatus/net.go +++ b/linuxstatus/net.go @@ -195,7 +195,7 @@ func scanInterfaces() { switch v := addr.(type) { case *net.IPNet: if checkIP(v, i) { - log.Log(true, "scanInterfaces() IP is new () i =", v.IP.String()) + log.Log(NET, "scanInterfaces() IP is new () i =", v.IP.String()) } default: log.Log(NET, "\t\taddr.(type) = NO IDEA WHAT TO DO HERE v =", v) diff --git a/problems.go b/problems.go index f315d8b..9a630ad 100644 --- a/problems.go +++ b/problems.go @@ -14,11 +14,19 @@ type Problem struct { id int Name string + desc string value string + aaaa string fixed bool duration *time.Duration } +var IPcreate = Problem { + kind: RR, + action: CREATE, + desc: "This RR entry in the zonefile needs to be removed", +} + /* var hostname Problem = ( kind: ProblemType.OS, @@ -46,3 +54,29 @@ const ( func (s Problem) String() string { return s.Name } + +func (s ProblemType) String() string { + switch s { + case OS: + return "OS" + case RR: + return "RR" + default: + return "something" + } + return "someprob" +} + +func (s ActionType) String() string { + switch s { + case USER: + return "USER" + case CREATE: + return "CREATE" + case DELETE: + return "DELETE" + default: + return "something" + } + return "someprob" +} diff --git a/smartwindow/args.go b/smartwindow/args.go index 2481b9b..71bf505 100644 --- a/smartwindow/args.go +++ b/smartwindow/args.go @@ -13,18 +13,12 @@ var INFO log.LogFlag var SPEW log.LogFlag var WARN log.LogFlag -func myreg(f *log.LogFlag, b bool, name string, desc string) { - f.B = b - f.Subsystem = "go.wit.com/gadgets/smartwindow" - f.Short = "smartWin" - f.Desc = desc - f.Name = name - f.Register() -} - func init() { - myreg(&NOW, true, "NOW", "temp debugging stuff") - myreg(&INFO, false, "INFO", "normal debugging stuff") - myreg(&SPEW, false, "SPEW", "spew stuff") - myreg(&WARN, true, "WARN", "bad things") + full := "go.wit.com/gui/gadgets/smartwindow" + short := "smartWin" + + NOW.NewFlag( "NOW", true, full, short, "temp debugging stuff") + INFO.NewFlag("INFO", false, full, short, "General Info") + SPEW.NewFlag("SPEW", false, full, short, "spew stuff") + WARN.NewFlag("WARN", false, full, short, "bad things") }