diff options
| author | Jeff Carr <[email protected]> | 2025-03-10 07:51:28 -0500 | 
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-03-10 07:59:25 -0500 | 
| commit | c3e8971e30e39757d63cc440b0ba2ed68bb97533 (patch) | |
| tree | 4155323940d617a4c698b34f2f09f5acc5a52766 | |
| parent | 18c1221efc1a4e6b97afb5547d44055a29150dff (diff) | |
more on events and auto save events pbv0.0.3
| -rw-r--r-- | doGui.go | 5 | ||||
| -rw-r--r-- | event.proto | 19 | ||||
| -rw-r--r-- | main.go | 11 | ||||
| -rw-r--r-- | structs.go | 23 | ||||
| -rw-r--r-- | windowEvents.go | 34 | 
5 files changed, 66 insertions, 26 deletions
@@ -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() { diff --git a/event.proto b/event.proto index b0c29d7..4f2e13a 100644 --- a/event.proto +++ b/event.proto @@ -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;  } @@ -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)  } @@ -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 { diff --git a/windowEvents.go b/windowEvents.go index 6a93188..e13df5b 100644 --- a/windowEvents.go +++ b/windowEvents.go @@ -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("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("enabled", enabledf) +	t.AddStringFunc("etime", etimef)  	t.AddHostname()  	t.AddAddress()  	t.AddWhere() +	t.AddLocalPort()  	t.ShowTable()  	return t  }  | 
