more on events and auto save events pb

This commit is contained in:
Jeff Carr 2025-03-10 07:51:28 -05:00
parent 18c1221efc
commit c3e8971e30
5 changed files with 66 additions and 26 deletions

View File

@ -20,6 +20,11 @@ func refresh() {
if argv.Verbose {
log.Info("gus scan here")
}
if me.eventsChanged {
log.Info("gus scan saved event changes")
me.events.Save()
me.eventsChanged = false
}
}
func doGui() {

View File

@ -5,15 +5,16 @@ package gus;
import "google/protobuf/timestamp.proto"; // Import the well-known type for Timestamp
message Event {
string hostname = 1; // the hostname of the client
string address = 2; // the IP address from the client
string where = 3; // where gus was sending the client traffic
google.protobuf.Timestamp ctime = 4; // when the socket opened
google.protobuf.Timestamp etime = 5; // when the socket ended
string hostname = 1; // the hostname of the client
string address = 2; // the IP address from the client
string where = 3; // where gus was sending the client traffic
google.protobuf.Timestamp ctime = 4; // when the socket opened
google.protobuf.Timestamp etime = 5; // when the socket ended
int64 localPort = 6; // the port gus was listening on
}
message Events { // `autogenpb:marshal` `autogenpb:gui` `autogenpb:nomutex`
string uuid = 1; // `autogenpb:uuid:4e91f9e6-f545-4c72-bec4-ab951276da1d`
string version = 2; // `autogenpb:version:v0.0.1`
repeated Event events = 3;
message Events { // `autogenpb:marshal` `autogenpb:gui` `autogenpb:nomutex`
string uuid = 1; // `autogenpb:uuid:4e91f9e6-f545-4c72-bec4-ab951276da1d`
string version = 2; // `autogenpb:version:v0.0.1`
repeated Event events = 3;
}

11
main.go
View File

@ -117,18 +117,23 @@ func handleConnection(clientConn net.Conn, where string, localport int) {
return
}
defer targetConn.Close()
// log.Printf("Connected to target server: %s where = %s\n", targetConn.RemoteAddr(), where)
log.Printf("Connected on port %d from client: %s to where = %s\n", localport, clientConn.RemoteAddr(), where)
// make a new event from this new connection
log.Printf("Connected on port %d from client: %s to where = %s\n", localport, clientConn.RemoteAddr(), where)
e := new(Event)
e.Address = fmt.Sprintf("%s\n", clientConn.RemoteAddr())
e.Where = where
e.LocalPort = int64(localport)
e.Ctime = timestamppb.New(time.Now())
me.events.Append(e)
me.eventsChanged = true
// Bidirectional copy of data
go io.Copy(targetConn, clientConn) // Client -> Target
io.Copy(clientConn, targetConn) // Target -> Client
// if the socket closes, record the close time
e.Etime = timestamppb.New(time.Now())
me.eventsChanged = true
log.Printf("Connection closed on port %d from client: %s to where = %s\n", localport, clientConn.RemoteAddr(), where)
}

View File

@ -15,17 +15,18 @@ var me *gusconf
// this app's variables
type gusconf struct {
myGui *gui.Node // the base of the gui
portmaps *Portmaps // the portmap window
events *Events // the event log
portwin *stdTableWin // the portwin window
eventswin *stdEventTableWin // the event window
urlbase string // the dns name for the zookeeper
hostname string // my hostname
pollDelay time.Duration // how often to report our status
dog *time.Ticker // the watchdog timer
failcount int // how many times we've failed to contact the zookeeper
failcountmax int // after this, exit and let systemd restart the daemon
myGui *gui.Node // the base of the gui
portmaps *Portmaps // the portmap window
portwin *stdTableWin // the portwin window
events *Events // the event log
eventswin *stdEventTableWin // the event window
eventsChanged bool // are there new events?
urlbase string // the dns name for the zookeeper
hostname string // my hostname
pollDelay time.Duration // how often to report our status
dog *time.Ticker // the watchdog timer
failcount int // how many times we've failed to contact the zookeeper
failcountmax int // after this, exit and let systemd restart the daemon
}
type stdTableWin struct {

View File

@ -4,6 +4,8 @@
package main
import (
"strings"
"go.wit.com/gui"
"go.wit.com/lib/gadgets"
"go.wit.com/log"
@ -48,6 +50,19 @@ func makeEventsWin() {
doEventsTable(found)
})
grid.NewButton("abnormal", func() {
found := NewEvents()
all := me.events.All()
for all.Scan() {
e := all.Next()
if strings.HasPrefix(e.Address, "192.168") {
continue
}
found.Append(e)
}
doEventsTable(found)
})
grid.NewButton("Save Current", func() {
log.Info("event log is len =", me.events.Len())
me.events.Save()
@ -81,14 +96,27 @@ func AddEventsPB(tbox *gui.Node, pb *Events) *EventsTable {
t.NewUuid()
t.SetParent(tbox)
enabledf := func(p *Event) string {
return "todo"
ctimef := func(e *Event) string {
ctime := e.Ctime.AsTime()
return ctime.Format("2006/01/02 15:04")
}
t.AddStringFunc("enabled", enabledf)
t.AddStringFunc("ctime", ctimef)
etimef := func(e *Event) string {
etime := e.Etime.AsTime()
s := etime.Format("2006/01/02 15:04")
if strings.HasPrefix(s, "1970/") {
// just show a blank if it's not set
return ""
}
return s
}
t.AddStringFunc("etime", etimef)
t.AddHostname()
t.AddAddress()
t.AddWhere()
t.AddLocalPort()
t.ShowTable()
return t
}