summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-03-11 07:23:13 -0500
committerJeff Carr <[email protected]>2025-03-11 12:16:21 -0500
commitc325f872178779f51390d7265efc50fe6fac8235 (patch)
tree8fd6911ed8827437208e09d9ee12c50941a43a9b
parentc3e8971e30e39757d63cc440b0ba2ed68bb97533 (diff)
add enough to support libvirt Spice
-rw-r--r--event.proto36
-rw-r--r--http.go16
-rw-r--r--main.go6
-rw-r--r--portmap.proto5
-rw-r--r--windowEvents.go16
5 files changed, 63 insertions, 16 deletions
diff --git a/event.proto b/event.proto
index 4f2e13a..169a069 100644
--- a/event.proto
+++ b/event.proto
@@ -4,17 +4,33 @@ package gus;
import "google/protobuf/timestamp.proto"; // Import the well-known type for Timestamp
+enum GusEventType {
+ Connect = 0; // a socket connect attempt
+ Disconnect = 1; // a socket closed
+ Enable = 2; // listening on a port was enabled
+ Disable = 3; // listening on a port was disabled
+}
+
+message GusSocket {
+ string srcHostname = 1; // the hostname
+ string srcIp = 2; // the IPv4 or IPv6 address
+ string srcPort = 3; // the port
+ string destHostname = 4; // the hostname
+ string destIp = 5; // the IPv4 or IPv6 address
+ string destPort = 6; // the port
+}
+
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
- int64 localPort = 6; // the port gus was listening on
+ string Hostname = 1; // the hostname
+ int64 localPort = 2; // the port gus was listening on
+ GusEventType etype = 3; // what kind of event was this
+ GusSocket sock = 4; // socket details if event needs them
+ google.protobuf.Timestamp ctime = 5; // event create time
+ google.protobuf.Timestamp etime = 6; // event end time
}
-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/http.go b/http.go
index 8a733d3..80ccd44 100644
--- a/http.go
+++ b/http.go
@@ -25,6 +25,8 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
// domname := r.URL.Query().Get("domain")
flag := r.URL.Query().Get("flag")
+ port := r.URL.Query().Get("port")
+ dest := r.URL.Query().Get("dest")
msg, err := ioutil.ReadAll(r.Body) // Read the body as []byte
if err != nil {
@@ -66,6 +68,20 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
return
}
+ if route == "/enable" {
+ log.HttpMode(w)
+ defer log.HttpMode(nil)
+ log.Info("enable port/dest", port, dest)
+ return
+ }
+
+ if route == "/disable" {
+ log.HttpMode(w)
+ defer log.HttpMode(nil)
+ log.Info("enable port/dest", port, dest)
+ return
+ }
+
// toggle logging flags
if route == "/flag" {
log.HttpMode(w)
diff --git a/main.go b/main.go
index d66d6a9..ae254ca 100644
--- a/main.go
+++ b/main.go
@@ -121,9 +121,11 @@ func handleConnection(clientConn net.Conn, where string, localport int) {
// 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.Etype = GusEventType_Connect
e.LocalPort = int64(localport)
+ e.Sock = new(GusSocket)
+ e.Sock.SrcIp = fmt.Sprintf("%s", clientConn.RemoteAddr())
+ e.Sock.DestIp = where
e.Ctime = timestamppb.New(time.Now())
me.events.Append(e)
me.eventsChanged = true
diff --git a/portmap.proto b/portmap.proto
index 2a0d627..fd9c297 100644
--- a/portmap.proto
+++ b/portmap.proto
@@ -4,9 +4,12 @@ package gus;
message Portmap {
int64 listen = 1; // `autogenpb:unique`
- string connect = 2; // `autogenpb:unique`
+ string connect = 2;
bool enabled = 3;
bool allowIPv4 = 4;
+ bool useME = 5;
+ string hosts = 6;
+ string iptables = 7;
}
message Portmaps { // `autogenpb:marshal` `autogenpb:gui` `autogenpb:nomutex`
diff --git a/windowEvents.go b/windowEvents.go
index e13df5b..1608635 100644
--- a/windowEvents.go
+++ b/windowEvents.go
@@ -55,7 +55,7 @@ func makeEventsWin() {
all := me.events.All()
for all.Scan() {
e := all.Next()
- if strings.HasPrefix(e.Address, "192.168") {
+ if strings.HasPrefix(e.Sock.SrcIp, "192.168") {
continue
}
found.Append(e)
@@ -114,8 +114,18 @@ func AddEventsPB(tbox *gui.Node, pb *Events) *EventsTable {
t.AddStringFunc("etime", etimef)
t.AddHostname()
- t.AddAddress()
- t.AddWhere()
+ t.AddStringFunc("src ip", func(e *Event) string {
+ if e.Sock != nil {
+ return e.Sock.SrcIp
+ }
+ return ""
+ })
+ t.AddStringFunc("dest ip", func(e *Event) string {
+ if e.Sock != nil {
+ return e.Sock.DestIp
+ }
+ return ""
+ })
t.AddLocalPort()
t.ShowTable()
return t