2024-01-07 05:46:59 -06:00
|
|
|
/*
|
|
|
|
Show a box for a configuration error
|
|
|
|
*/
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"go.wit.com/log"
|
|
|
|
"go.wit.com/gui/gui"
|
|
|
|
"go.wit.com/gui/gadgets"
|
|
|
|
)
|
|
|
|
|
|
|
|
type errorBox struct {
|
2024-01-08 11:05:40 -06:00
|
|
|
ready bool
|
2024-01-08 11:55:56 -06:00
|
|
|
hidden bool
|
2024-01-07 05:46:59 -06:00
|
|
|
|
|
|
|
parent *gui.Node
|
|
|
|
group *gui.Node
|
|
|
|
grid *gui.Node
|
|
|
|
|
|
|
|
l *gui.Node
|
|
|
|
b *gui.Node
|
|
|
|
|
2024-01-07 10:38:17 -06:00
|
|
|
fixes map[string]*anError
|
|
|
|
|
2024-01-07 05:46:59 -06:00
|
|
|
something *gadgets.OneLiner
|
|
|
|
}
|
|
|
|
|
2024-01-07 10:38:17 -06:00
|
|
|
type anError struct {
|
|
|
|
kind string // what kind of error is it?
|
2024-01-07 11:23:51 -06:00
|
|
|
aaaa string
|
2024-01-07 10:38:17 -06:00
|
|
|
status string
|
|
|
|
|
|
|
|
kindLabel *gui.Node
|
|
|
|
ipLabel *gui.Node
|
|
|
|
statusLabel *gui.Node
|
|
|
|
button *gui.Node
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewErrorBox(p *gui.Node, name string, ip string) *errorBox {
|
2024-01-07 05:46:59 -06:00
|
|
|
var eb *errorBox
|
|
|
|
eb = new(errorBox)
|
|
|
|
eb.parent = p
|
2024-01-07 10:38:17 -06:00
|
|
|
eb.group = p.NewGroup(name)
|
|
|
|
eb.grid = eb.group.NewGrid("stuff", 4, 1)
|
2024-01-07 05:46:59 -06:00
|
|
|
|
2024-01-07 10:38:17 -06:00
|
|
|
eb.grid.NewLabel("Type")
|
|
|
|
eb.grid.NewLabel("IP")
|
|
|
|
eb.grid.NewLabel("Status")
|
|
|
|
eb.grid.NewLabel("")
|
2024-01-07 05:46:59 -06:00
|
|
|
|
2024-01-07 10:38:17 -06:00
|
|
|
eb.fixes = make(map[string]*anError)
|
2024-01-08 11:05:40 -06:00
|
|
|
eb.ready = true
|
2024-01-07 05:46:59 -06:00
|
|
|
return eb
|
|
|
|
}
|
|
|
|
|
2024-01-08 11:55:56 -06:00
|
|
|
func (eb *errorBox) Show() {
|
|
|
|
if eb == nil {return}
|
|
|
|
eb.hidden = false
|
|
|
|
eb.group.Show()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (eb *errorBox) Hide() {
|
|
|
|
if eb == nil {return}
|
|
|
|
eb.hidden = true
|
|
|
|
eb.group.Hide()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (eb *errorBox) Toggle() {
|
|
|
|
if eb == nil {return}
|
|
|
|
if eb.hidden {
|
|
|
|
eb.Show()
|
|
|
|
} else {
|
|
|
|
eb.Hide()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-08 11:05:40 -06:00
|
|
|
func (eb *errorBox) Ready() bool {
|
|
|
|
if eb == nil {return false}
|
|
|
|
return eb.ready
|
|
|
|
}
|
2024-01-07 10:38:17 -06:00
|
|
|
|
|
|
|
func (eb *errorBox) add(kind string, ip string) bool {
|
2024-01-08 11:05:40 -06:00
|
|
|
if ! eb.Ready() {return false}
|
2024-01-07 10:38:17 -06:00
|
|
|
tmp := kind + " " + ip
|
|
|
|
if eb.fixes[tmp] != nil {
|
|
|
|
log.Log(WARN, "Error is already here", kind, ip)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
anErr := new(anError)
|
|
|
|
anErr.kind = kind
|
2024-01-07 11:23:51 -06:00
|
|
|
anErr.aaaa = ip
|
2024-01-07 10:38:17 -06:00
|
|
|
|
|
|
|
anErr.kindLabel = eb.grid.NewLabel(kind)
|
|
|
|
anErr.ipLabel = eb.grid.NewLabel(ip)
|
|
|
|
anErr.statusLabel = eb.grid.NewLabel("")
|
|
|
|
anErr.button = eb.grid.NewButton(kind, func() {
|
|
|
|
log.Log(WARN, "got", kind, "here. IP =", ip)
|
2024-01-07 11:23:51 -06:00
|
|
|
eb.fix(tmp)
|
2024-01-07 10:38:17 -06:00
|
|
|
})
|
|
|
|
eb.fixes[tmp] = anErr
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2024-01-07 11:23:51 -06:00
|
|
|
func (eb *errorBox) fix(key string) bool {
|
|
|
|
if eb.fixes[key] == nil {
|
|
|
|
log.Log(WARN, "Unknown error. could not find key =", key)
|
|
|
|
log.Log(WARN, "TODO: probably remove this error. key =", key)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
myErr := eb.fixes[key]
|
|
|
|
log.Log(WARN, "should try to fix", myErr.kind, "here. IP =", myErr.aaaa)
|
|
|
|
if myErr.kind == "DELETE" {
|
|
|
|
if deleteFromDNS(myErr.aaaa) {
|
|
|
|
log.Log(INFO, "Delete AAAA", myErr.aaaa, "Worked")
|
|
|
|
} else {
|
|
|
|
log.Log(INFO, "Delete AAAA", myErr.aaaa, "Failed")
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if myErr.kind == "CREATE" {
|
|
|
|
if addToDNS(myErr.aaaa) {
|
|
|
|
log.Log(INFO, "Delete AAAA", myErr.aaaa, "Worked")
|
|
|
|
} else {
|
|
|
|
log.Log(INFO, "Delete AAAA", myErr.aaaa, "Failed")
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
2024-01-07 10:38:17 -06:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2024-01-07 05:46:59 -06:00
|
|
|
func (eb *errorBox) update() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (eb *errorBox) toggle() {
|
|
|
|
}
|