// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT. // This file was autogenerated with autogenpb v0.0.65 2025-03-12_15:38:32_UTC // go install go.wit.com/apps/autogenpb@latest // // define which structs (messages) you want to use in the .proto file // Then sort.pb.go and marshal.pb.go files are autogenerated // // autogenpb uses it and has an example .proto file with instructions // package main import ( "time" "github.com/google/uuid" "go.wit.com/gui" "go.wit.com/lib/protobuf/guipb" "go.wit.com/log" timestamppb "google.golang.org/protobuf/types/known/timestamppb" ) // START GUI func (x *Portmaps) NewTable(title string) *PortmapsTable { t := new(PortmapsTable) t.x = x pb := new(guipb.Table) pb.Title = title t.pb = pb return t } func (t *PortmapsTable) AddStringFunc(title string, f func(*Portmap) string) *PortmapStringFunc { t.pb.Order = append(t.pb.Order, title) sf := new(PortmapStringFunc) sf.title = title sf.f = f sf.order = t.order t.order += 1 t.stringFuncs = append(t.stringFuncs, sf) return sf } func (t *PortmapsTable) AddButtonFunc(title string, f func(*Portmap) string) *PortmapButtonFunc { t.pb.Order = append(t.pb.Order, title) sf := new(PortmapButtonFunc) sf.title = title sf.f = f sf.order = t.order t.order += 1 t.buttonFuncs = append(t.buttonFuncs, sf) return sf } func (t *PortmapsTable) AddIntFunc(title string, f func(*Portmap) int) *PortmapIntFunc { t.pb.Order = append(t.pb.Order, title) sf := new(PortmapIntFunc) sf.title = title sf.f = f sf.order = t.order t.order += 1 t.intFuncs = append(t.intFuncs, sf) return sf } func (t *PortmapsTable) AddTimeFunc(title string, f func(*Portmap) time.Time) *PortmapTimeFunc { t.pb.Order = append(t.pb.Order, title) sf := new(PortmapTimeFunc) sf.title = title sf.f = f sf.order = t.order t.order += 1 t.timeFuncs = append(t.timeFuncs, sf) return sf } func (sf *PortmapStringFunc) SetTitle(title string) { sf.title = title } func (sf *PortmapIntFunc) SetTitle(title string) { sf.title = title } func (sf *PortmapTimeFunc) SetTitle(title string) { sf.title = title } func (mt *PortmapsTable) SetParent(p *gui.Node) { mt.parent = p } func (mt *PortmapsTable) ShowTable() { // log.Info("ShowTable() SENDING TO GUI") mt.MakeTable() mt.parent.ShowTable(mt.pb) } type PortmapStringFunc struct { title string f func(*Portmap) string Custom func(*Portmap) order int } type PortmapButtonFunc struct { title string f func(*Portmap) string Custom func(*Portmap) order int } type PortmapIntFunc struct { title string f func(*Portmap) int Custom func(*Portmap) order int } type PortmapTimeFunc struct { title string f func(*Portmap) time.Time Custom func(*Portmap) order int } type PortmapsTable struct { pb *guipb.Table parent *gui.Node x *Portmaps hostnames []string stringFuncs []*PortmapStringFunc intFuncs []*PortmapIntFunc timeFuncs []*PortmapTimeFunc buttonFuncs []*PortmapButtonFunc CustomFunc func(*Portmap) order int } func (mt *PortmapsTable) doStringFunc(name string) bool { for _, sf := range mt.stringFuncs { if sf.title != name { continue } // log.Info("main: found stringfunc name:", name) r := new(guipb.StringRow) r.Header = new(guipb.Widget) r.Header.Name = name all := mt.x.All() for all.Scan() { m := all.Next() r.Vals = append(r.Vals, sf.f(m)) // log.Info("main: adding", name, r.Vals) } mt.pb.StringRows = append(mt.pb.StringRows, r) return true } return false } func (mt *PortmapsTable) doButtonFunc(name string) bool { for _, sf := range mt.buttonFuncs { if sf.title != name { continue } // log.Info("main: found stringfunc name:", name) r := new(guipb.ButtonRow) r.Header = new(guipb.Widget) r.Header.Name = name all := mt.x.All() for all.Scan() { m := all.Next() r.Vals = append(r.Vals, sf.f(m)) // log.Info("main: adding", name, r.Vals) } mt.pb.ButtonRows = append(mt.pb.ButtonRows, r) return true } return false } func (mt *PortmapsTable) doIntFunc(name string) bool { for _, sf := range mt.intFuncs { if sf.title != name { continue } // log.Info("main: found intfunc name:", name) r := new(guipb.IntRow) r.Header = new(guipb.Widget) r.Header.Name = name all := mt.x.All() for all.Scan() { m := all.Next() r.Vals = append(r.Vals, int64(sf.f(m))) // log.Info("main: adding", name, r.Vals) } mt.pb.IntRows = append(mt.pb.IntRows, r) return true } return false } func (mt *PortmapsTable) doTimeFunc(name string) bool { for _, sf := range mt.timeFuncs { if sf.title != name { continue } // log.Info("main: found timefunc name:", name) r := new(guipb.TimeRow) r.Header = new(guipb.Widget) r.Header.Name = name all := mt.x.All() for all.Scan() { m := all.Next() t := sf.f(m) r.Vals = append(r.Vals, timestamppb.New(t)) // convert to protobuf time // log.Info("main: adding", name, r.Vals) } mt.pb.TimeRows = append(mt.pb.TimeRows, r) return true } return false } func (mt *PortmapsTable) MakeTable() { for _, name := range mt.pb.Order { // log.Info("main: looking for row name()", name) if mt.doStringFunc(name) { continue } if mt.doIntFunc(name) { continue } if mt.doTimeFunc(name) { continue } if mt.doButtonFunc(name) { continue } } } func (t *PortmapsTable) AddLocalport() { t.AddIntFunc("Localport", func(m *Portmap) int { return int(m.Localport) }) } func (t *PortmapsTable) AddDest() *PortmapStringFunc { sf := t.AddStringFunc("Dest", func(m *Portmap) string { return m.Dest }) return sf } func (t *PortmapsTable) AddHosts() *PortmapStringFunc { sf := t.AddStringFunc("Hosts", func(m *Portmap) string { return m.Hosts }) return sf } func (t *PortmapsTable) AddIptables() *PortmapStringFunc { sf := t.AddStringFunc("Iptables", func(m *Portmap) string { return m.Iptables }) return sf } func (mt *PortmapsTable) NewUuid() { mt.pb.Uuid = uuid.New().String() } // START TABLE UPDATE func (mt *PortmapsTable) todoUpdate() { for _, name := range mt.pb.Order { // log.Info("Portmappb: trying to update row()", name) if mt.updateStringFunc(name) { continue } if mt.updateTimeFunc(name) { continue } /* if mt.updateIntFunc(name) { continue } */ } // mt.dumpStringFunc("Hostname") mt.parent.UpdateTable(mt.pb) } func (mt *PortmapsTable) dumpStringFunc(name string) { for i, r := range mt.pb.StringRows { // log.Info("could use", i, r.Header.Name, "for name =", name) if r.Header.Name == name { log.Info("dump Strings row", i, r.Header.Name, r.Vals) break } } } func (mt *PortmapsTable) updateStringFunc(name string) bool { // log.Info("LOOKING FOR STRING row", name) var found *guipb.StringRow for _, r := range mt.pb.StringRows { // log.Info("could use", i, r.Header.Name, "for name =", name) if r.Header.Name == name { // log.Info("found row", i, r.Header.Name) found = r break } } if found == nil { log.Info("did not find string row", name) return false } for _, sf := range mt.stringFuncs { if sf.title != name { continue } // log.Info("Portmappb: starting", name, found.Vals) for i, _ := range found.Vals { tmp := sf.f(mt.x.Portmaps[i]) if tmp == "www.wit.com" { log.Info("virtpb: FOUND WWW", i) tmp = "new.www" } found.Vals[i] = tmp } // log.Info("Portmappb: ending", name, found.Vals) return true } return false } func (mt *PortmapsTable) updateTimeFunc(name string) bool { log.Info("LOOKING FOR TIME row", name) var found *guipb.TimeRow for i, r := range mt.pb.TimeRows { // log.Info("could use", i, r.Header.Name, "for name =", name) if r.Header.Name == name { log.Info("found row", i, r.Header.Name) found = r break } } if found == nil { log.Info("did not find time row", name) return false } for _, sf := range mt.timeFuncs { if sf.title != name { continue } // log.Info("updateTimeFunc() has row len =", len(mt.x.Portmaps)) // log.Info("virtpb: starting", name, found.Vals) for i, _ := range found.Vals { newt := sf.f(mt.x.Portmaps[i]) found.Vals[i] = timestamppb.New(newt) // convert to protobuf time } // log.Info("virtpb: ending", name, found.Vals) return true } return false } func (mt *PortmapsTable) Delete() { if mt == nil { log.Info("mt == nil table already deleted") return } // log.Info("table Delete here") mt.parent.DeleteTable(mt.pb) } func (mt *PortmapsTable) portmapsCustom(w *guipb.Widget) { row := mt.x.Portmaps[w.Location.Y-1] // log.Info("got to portmapsCustom() with", w.Location.X, w.Location.Y-1) for _, sf := range mt.buttonFuncs { if sf.order == int(w.Location.X) { // log.Info("found order", sf.order) if sf.Custom != nil { log.Info("doing Custom() func for button") sf.Custom(row) return } } } mt.CustomFunc(row) } func (mt *PortmapsTable) Custom(f func(*Portmap)) { mt.pb.RegisterCustom(mt.portmapsCustom) mt.CustomFunc = f } func (mt *PortmapsTable) GetUuid() string { return mt.pb.Uuid } // END TABLE UPDATE // END GUI