diff --git a/src/main.ts b/src/main.ts index dc7aca7..4087210 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,8 +1,12 @@ import { SuricataSocketStream } from "./socket-server/server.ts"; -// UGLY: take them from +// UGLY: take them from const UNIXPATH = "/var/lib/suricata/eve.sock" -const WEB_SOCKET_URI = "" +const WEB_SOCKET_URI = Deno.env.get("WEBSOCKET_RELAY") + +if (!WEB_SOCKET_URI) { + throw Error("There's no value associated with WEBSOCKET_RELAY environment variable") +} const app = new SuricataSocketStream( UNIXPATH, diff --git a/src/socket-server/server.ts b/src/socket-server/server.ts index d3dea31..bbc91d3 100644 --- a/src/socket-server/server.ts +++ b/src/socket-server/server.ts @@ -17,7 +17,7 @@ export class SuricataSocketStream { }); this.webSocket = new WebSocket(webSocketURI); - + } public async serve() { @@ -31,7 +31,7 @@ export class SuricataSocketStream { const jsonParser = new JSON_Chunker() do { - + let bytesRead: number | null = 0; const chunk: Uint8Array = new Uint8Array(this.maxBlobSize); @@ -48,28 +48,17 @@ export class SuricataSocketStream { while (jsonParser.messageReady) { this.messageProcess(jsonParser.message!) - } + } + - } while (true); } } - + // UGLY: change this to a more flexible method private messageProcess(msg: string | Uint8Array) { - // this.webSocket.send(msg); - console.log( -` -Debug, found this message: - -${msg} - -END OF MESSAGE - - -` -) + this.webSocket.send(msg); } }