go.wit.com/log NewFlag()

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-08 22:34:08 -06:00
parent 9b4bf224dc
commit ba020cdb37
9 changed files with 100 additions and 66 deletions

View File

@ -1,14 +1,18 @@
.PHONY: debian .PHONY: debian
run: build run: build
# ./control-panel-dns >/tmp/witgui.log.stderr 2>&1 # ./control-panel-dns >/tmp/witgui.log.stderr 2>&1
cp -f control-panel-dns ~/ cp -f control-panel-dns ~/
./control-panel-dns --tmp-log ./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.* rm -f go.*
go mod init GO111MODULE= go mod init
go mod tidy GO111MODULE= go mod tidy
install: install:
go install -v go.wit.com/control-panel-dns@latest go install -v go.wit.com/control-panel-dns@latest

40
args.go
View File

@ -23,37 +23,33 @@ var NOW log.LogFlag
var INFO log.LogFlag var INFO log.LogFlag
var NET log.LogFlag var NET log.LogFlag
var DNS log.LogFlag var DNS log.LogFlag
var WARN log.LogFlag var WARN log.LogFlag
var SPEW log.LogFlag var SPEW log.LogFlag
var CHANGE log.LogFlag var CHANGE log.LogFlag
var STATUS 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() { func init() {
arg.MustParse(&args) 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") NOW.NewFlag( "NOW", true, full, short, "temp debugging stuff")
myreg(&INFO, false, "INFO", "normal debugging stuff") INFO.NewFlag("INFO", false, full, short, "normal debugging stuff")
myreg(&NET, false, "NET", "Network logging") NET.NewFlag( "NET", false, full, short, "Network logging")
myreg(&DNS, false, "DNS", "dnsStatus.update()") DNS.NewFlag( "DNS", false, full, short, "dnsStatus.update()")
myreg(&WARN, true, "WARN", "bad things")
myreg(&SPEW, false, "SPEW", "spew stuff") WARN.NewFlag("WARN", true, full, short, "bad things")
myreg(&CHANGE, true, "CHANGE", "when host or dns change") SPEW.NewFlag("SPEW", false, full, short, "spew stuff")
myreg(&STATUS, false, "STATUS", "updateStatus()")
CHANGE.NewFlag("CHANGE", true, full, short, "when host or dns change")
STATUS.NewFlag("STATUS", false, full, short, "updateStatus() polling")
if debugger.ArgDebug() { if debugger.ArgDebug() {
log.Log(true, "INIT() gui debug == true") log.Log(NOW, "INIT() gui debug == true")
} else { } else {
log.Log(true, "INIT() gui debug == false") log.Log(NOW, "INIT() gui debug == false")
} }
me.dnsSleep = 500 * time.Millisecond 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.artificialSleep = 0.4 // seems to need to exist or GTK crashes. TODO: fix andlabs plugin
me.artificialS = "blah" me.artificialS = "blah"
log.Log(true, "init() me.artificialSleep =", me.artificialSleep) log.Log(INFO, "init() me.artificialSleep =", me.artificialSleep)
log.Log(true, "init() me.artificialS =", me.artificialS) log.Log(INFO, "init() me.artificialS =", me.artificialS)
log.Sleep(me.artificialSleep) log.Sleep(me.artificialSleep)
} }

View File

@ -32,9 +32,12 @@ type anError struct {
status string status string
kindLabel *gui.Node kindLabel *gui.Node
actionLabel *gui.Node
ipLabel *gui.Node ipLabel *gui.Node
statusLabel *gui.Node statusLabel *gui.Node
button *gui.Node button *gui.Node
problem *Problem
} }
func NewErrorBox(p *gui.Node, name string, ip string) *errorBox { 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 = new(errorBox)
eb.parent = p eb.parent = p
eb.group = p.NewGroup(name) 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("Type")
eb.grid.NewLabel("Action")
eb.grid.NewLabel("IP") eb.grid.NewLabel("IP")
eb.grid.NewLabel("Status") eb.grid.NewLabel("Status")
eb.grid.NewLabel("") eb.grid.NewLabel("")
@ -80,25 +84,28 @@ func (eb *errorBox) Ready() bool {
return eb.ready 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} if ! eb.Ready() {return false}
tmp := kind + " " + ip tmp := kind.String() + " " + ip
if eb.fixes[tmp] != nil { if eb.fixes[tmp] != nil {
log.Log(WARN, "Error is already here", kind, ip) log.Log(WARN, "Error is already here", kind, ip)
return false return false
} }
anErr := new(anError) anErr := new(anError)
anErr.kind = kind
anErr.aaaa = ip 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.ipLabel = eb.grid.NewLabel(ip)
anErr.statusLabel = eb.grid.NewLabel("") 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) log.Log(WARN, "got", kind, "here. IP =", ip)
eb.fix(tmp) eb.fix(tmp)
}) })
anErr.problem = new(Problem)
anErr.problem.kind = kind
anErr.problem.aaaa = ip
eb.fixes[tmp] = anErr eb.fixes[tmp] = anErr
return false return false
} }

5
fix.go
View File

@ -84,7 +84,8 @@ func fixIPv6dns() bool {
} else { } else {
broken = true broken = true
log.Log(INFO, "DNS AAAA is not in OS", aaaa) 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) { if deleteFromDNS(aaaa) {
log.Log(INFO, "Delete AAAA", aaaa, "Worked") 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) { func addToFixWindow(t string, ip string) {
log.Log(INFO, "addToFixWindow() START") log.Log(INFO, "addToFixWindow() START")
if ! me.problems.Ready() { return } if ! me.problems.Ready() { return }
me.problems.add(t, ip) me.problems.addIPerror(RR, CREATE, ip)
log.Log(INFO, "addToFixWindow() END") log.Log(INFO, "addToFixWindow() END")
} }

2
gui.go
View File

@ -128,7 +128,7 @@ func mainWindow(title string) {
// These are your problems // These are your problems
me.problems = NewErrorBox(me.window.Box(), "Errors", "has 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")
} }

View File

@ -12,29 +12,27 @@ var NOW log.LogFlag
var INFO log.LogFlag var INFO log.LogFlag
var NET log.LogFlag var NET log.LogFlag
var DNS log.LogFlag var DNS log.LogFlag
var PROC log.LogFlag var PROC log.LogFlag
var SPEW log.LogFlag var SPEW log.LogFlag
var WARN log.LogFlag var WARN log.LogFlag
var CHANGE log.LogFlag var CHANGE log.LogFlag
var STATUS 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() { func init() {
myreg(&NOW, true, "NOW", "temp debugging stuff") full := "go.wit.com/control-panels/dns/linuxstatus"
myreg(&INFO, false, "INFO", "normal debugging stuff") short := "linux"
myreg(&NET, false, "NET", "Network Logging")
myreg(&DNS, false, "DNS", "dnsStatus.update()") NOW.NewFlag( "NOW", true, full, short, "temp debugging stuff")
myreg(&PROC, false, "PROC", "/proc logging") INFO.NewFlag("INFO", false, full, short, "normal debugging stuff")
myreg(&SPEW, false, "SPEW", "spew stuff") NET.NewFlag( "NET", false, full, short, "Network logging")
myreg(&WARN, true, "WARN", "bad things") DNS.NewFlag( "DNS", false, full, short, "dnsStatus.update()")
myreg(&CHANGE, true, "CHANGE", "show droplet state changes")
myreg(&STATUS, false, "STATUS", "Update() details") 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")
} }

View File

@ -195,7 +195,7 @@ func scanInterfaces() {
switch v := addr.(type) { switch v := addr.(type) {
case *net.IPNet: case *net.IPNet:
if checkIP(v, i) { 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: default:
log.Log(NET, "\t\taddr.(type) = NO IDEA WHAT TO DO HERE v =", v) log.Log(NET, "\t\taddr.(type) = NO IDEA WHAT TO DO HERE v =", v)

View File

@ -14,11 +14,19 @@ type Problem struct {
id int id int
Name string Name string
desc string
value string value string
aaaa string
fixed bool fixed bool
duration *time.Duration duration *time.Duration
} }
var IPcreate = Problem {
kind: RR,
action: CREATE,
desc: "This RR entry in the zonefile needs to be removed",
}
/* /*
var hostname Problem = ( var hostname Problem = (
kind: ProblemType.OS, kind: ProblemType.OS,
@ -46,3 +54,29 @@ const (
func (s Problem) String() string { func (s Problem) String() string {
return s.Name 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"
}

View File

@ -13,18 +13,12 @@ var INFO log.LogFlag
var SPEW log.LogFlag var SPEW log.LogFlag
var WARN 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() { func init() {
myreg(&NOW, true, "NOW", "temp debugging stuff") full := "go.wit.com/gui/gadgets/smartwindow"
myreg(&INFO, false, "INFO", "normal debugging stuff") short := "smartWin"
myreg(&SPEW, false, "SPEW", "spew stuff")
myreg(&WARN, true, "WARN", "bad things") 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")
} }