summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doGui.go5
-rw-r--r--event.proto19
-rw-r--r--main.go11
-rw-r--r--structs.go23
-rw-r--r--windowEvents.go34
5 files changed, 66 insertions, 26 deletions
diff --git a/doGui.go b/doGui.go
index 9584624..77f308a 100644
--- a/doGui.go
+++ b/doGui.go
@@ -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;
}
diff --git a/main.go b/main.go
index 916dc3a..d66d6a9 100644
--- a/main.go
+++ b/main.go
@@ -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)
}
diff --git a/structs.go b/structs.go
index 91299b9..372fa87 100644
--- a/structs.go
+++ b/structs.go
@@ -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
}