add enough to support libvirt Spice

This commit is contained in:
Jeff Carr 2025-03-11 07:23:13 -05:00
parent c3e8971e30
commit c325f87217
5 changed files with 64 additions and 17 deletions

View File

@ -4,13 +4,29 @@ 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`

16
http.go
View File

@ -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)

View File

@ -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

View File

@ -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`

View File

@ -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