2024-01-07 05:46:59 -06:00
|
|
|
/*
|
|
|
|
Show a box for a configuration error
|
|
|
|
*/
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-01-10 20:22:25 -06:00
|
|
|
"time"
|
|
|
|
|
2024-01-07 05:46:59 -06:00
|
|
|
"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 {
|
2024-01-10 20:22:25 -06:00
|
|
|
// kind ProblemType // what kind of error is it?
|
|
|
|
// action ActionType
|
|
|
|
// aaaa string
|
|
|
|
// status string
|
2024-01-07 10:38:17 -06:00
|
|
|
|
|
|
|
kindLabel *gui.Node
|
2024-01-08 22:34:08 -06:00
|
|
|
actionLabel *gui.Node
|
2024-01-07 10:38:17 -06:00
|
|
|
ipLabel *gui.Node
|
|
|
|
statusLabel *gui.Node
|
|
|
|
button *gui.Node
|
2024-01-08 22:34:08 -06:00
|
|
|
|
|
|
|
problem *Problem
|
2024-01-07 10:38:17 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2024-01-08 22:34:08 -06:00
|
|
|
eb.grid = eb.group.NewGrid("stuff", 5, 1)
|
2024-01-07 05:46:59 -06:00
|
|
|
|
2024-01-07 10:38:17 -06:00
|
|
|
eb.grid.NewLabel("Type")
|
2024-01-08 22:34:08 -06:00
|
|
|
eb.grid.NewLabel("Action")
|
2024-01-07 10:38:17 -06:00
|
|
|
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
|
|
|
|
2024-01-08 22:34:08 -06:00
|
|
|
func (eb *errorBox) addIPerror(kind ProblemType, action ActionType, ip string) bool {
|
2024-01-08 11:05:40 -06:00
|
|
|
if ! eb.Ready() {return false}
|
2024-01-08 22:34:08 -06:00
|
|
|
tmp := kind.String() + " " + ip
|
2024-01-07 10:38:17 -06:00
|
|
|
if eb.fixes[tmp] != nil {
|
|
|
|
log.Log(WARN, "Error is already here", kind, ip)
|
2024-01-10 20:22:25 -06:00
|
|
|
log.Log(WARN, "kind =", kind)
|
|
|
|
log.Log(WARN, "action =", action)
|
|
|
|
log.Log(WARN, "ip =", ip)
|
2024-01-07 10:38:17 -06:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
anErr := new(anError)
|
|
|
|
|
2024-01-08 22:34:08 -06:00
|
|
|
anErr.kindLabel = eb.grid.NewLabel(kind.String())
|
|
|
|
anErr.actionLabel = eb.grid.NewLabel(action.String())
|
2024-01-07 10:38:17 -06:00
|
|
|
anErr.ipLabel = eb.grid.NewLabel(ip)
|
|
|
|
anErr.statusLabel = eb.grid.NewLabel("")
|
2024-01-08 22:34:08 -06:00
|
|
|
anErr.button = eb.grid.NewButton("Try to Fix", func() {
|
2024-01-07 10:38:17 -06:00
|
|
|
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
|
|
|
})
|
2024-01-08 22:34:08 -06:00
|
|
|
anErr.problem = new(Problem)
|
|
|
|
anErr.problem.kind = kind
|
2024-01-10 20:22:25 -06:00
|
|
|
anErr.problem.action = action
|
2024-01-08 22:34:08 -06:00
|
|
|
anErr.problem.aaaa = ip
|
2024-01-10 20:22:25 -06:00
|
|
|
anErr.problem.born = time.Now()
|
|
|
|
anErr.problem.duration = 30 * time.Second
|
|
|
|
anErr.problem.begun = false
|
|
|
|
anErr.problem.begunResult = false
|
2024-01-07 10:38:17 -06:00
|
|
|
eb.fixes[tmp] = anErr
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2024-01-08 12:55:23 -06:00
|
|
|
// get all your problems!
|
|
|
|
func (eb *errorBox) Scan() []anError {
|
|
|
|
for s, thing := range eb.fixes {
|
|
|
|
log.Log(CHANGE, "Scan()", s, thing)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
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]
|
2024-01-10 20:22:25 -06:00
|
|
|
log.Log(WARN, "should try to fix", myErr.problem.kind, "here. IP =", myErr.problem.aaaa)
|
2024-01-11 22:15:29 -06:00
|
|
|
if ! me.autofix.GetBool() {
|
2024-01-10 20:22:25 -06:00
|
|
|
log.Log(WARN, "not autofixing. autofix == false")
|
|
|
|
log.Log(WARN, "problem.kind =", myErr.problem.kind)
|
|
|
|
log.Log(WARN, "problem.action =", myErr.problem.action)
|
|
|
|
log.Log(WARN, "problem.aaaa =", myErr.problem.aaaa)
|
|
|
|
log.Log(WARN, "problem.duration =", myErr.problem.duration)
|
|
|
|
log.Log(WARN, "problem.begun =", myErr.problem.begun)
|
|
|
|
log.Log(WARN, "problem.begunResult =", myErr.problem.begunResult)
|
|
|
|
// if myErr.problem.begunTime != nil {
|
|
|
|
log.Log(WARN, "problem.begunTime =", myErr.problem.begunTime)
|
|
|
|
// }
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if myErr.problem.begun {
|
|
|
|
log.Log(WARN, "problem has already begun. need to check the status of the problem here")
|
|
|
|
log.Log(WARN, "problem.begun =", myErr.problem.begun)
|
|
|
|
log.Log(WARN, "problem.begunResult =", myErr.problem.begunResult)
|
|
|
|
log.Log(WARN, "problem.duration =", myErr.problem.duration)
|
|
|
|
delay := time.Since(myErr.problem.begunTime)
|
|
|
|
log.Log(WARN, "problem duration time =", delay)
|
|
|
|
if delay >= myErr.problem.duration {
|
|
|
|
log.Log(WARN, "duration eclipsed. check the status of the error here")
|
2024-01-07 11:23:51 -06:00
|
|
|
}
|
2024-01-10 20:22:25 -06:00
|
|
|
return false
|
2024-01-07 11:23:51 -06:00
|
|
|
}
|
2024-01-10 20:22:25 -06:00
|
|
|
if myErr.problem.kind == RR {
|
|
|
|
if myErr.problem.action == DELETE {
|
|
|
|
myErr.problem.begun = true
|
|
|
|
myErr.problem.begunTime = time.Now()
|
|
|
|
if deleteFromDNS(myErr.problem.aaaa) {
|
|
|
|
log.Log(INFO, "Delete AAAA", myErr.problem.aaaa, "Worked")
|
|
|
|
myErr.problem.begunResult = true
|
|
|
|
} else {
|
|
|
|
log.Log(INFO, "Delete AAAA", myErr.problem.aaaa, "Failed")
|
|
|
|
myErr.problem.begunResult = false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if myErr.problem.action == CREATE {
|
|
|
|
myErr.problem.begun = true
|
|
|
|
myErr.problem.begunTime = time.Now()
|
|
|
|
if addToDNS(myErr.problem.aaaa) {
|
|
|
|
log.Log(INFO, "Delete AAAA", myErr.problem.aaaa, "Worked")
|
|
|
|
myErr.problem.begunResult = true
|
|
|
|
} else {
|
|
|
|
log.Log(INFO, "Delete AAAA", myErr.problem.aaaa, "Failed")
|
|
|
|
myErr.problem.begunResult = false
|
|
|
|
}
|
|
|
|
return true
|
2024-01-07 11:23:51 -06:00
|
|
|
}
|
|
|
|
}
|
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() {
|
|
|
|
}
|