summaryrefslogtreecommitdiffstats
path: root/qa/sock_to_gzip_file.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 17:39:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 17:39:49 +0000
commita0aa2307322cd47bbf416810ac0292925e03be87 (patch)
tree37076262a026c4b48c8a0e84f44ff9187556ca35 /qa/sock_to_gzip_file.py
parentInitial commit. (diff)
downloadsuricata-3c02481111c540a7642503dfcf0b62e8c69b6ff0.tar.xz
suricata-3c02481111c540a7642503dfcf0b62e8c69b6ff0.zip
Adding upstream version 1:7.0.3.upstream/1%7.0.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'qa/sock_to_gzip_file.py')
-rwxr-xr-xqa/sock_to_gzip_file.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/qa/sock_to_gzip_file.py b/qa/sock_to_gzip_file.py
new file mode 100755
index 0000000..4c51782
--- /dev/null
+++ b/qa/sock_to_gzip_file.py
@@ -0,0 +1,57 @@
+#!/usr/bin/python
+#I love the python Power Glove. It's so bad!
+#Usage: sudo -u suricata ./sock_to_gzip_file.py --output-file="http.log.gz" --listen-sock="http.log.sock"
+
+import socket,os
+import gzip
+import sys
+from optparse import OptionParser
+
+if __name__ == "__main__":
+ parser = OptionParser()
+ #Path to the socket
+ parser.add_option("--listen-sock", dest="lsock", type="string", help="Path to the socket we will listen on.")
+ #Path to gzip file we will write
+ parser.add_option("--output-file", dest="output", type="string", help="Path to file name to output gzip file we will write to.")
+
+ #parse the opts
+ (options, args) = parser.parse_args()
+
+ options.usage = "example: sudo -u suricata ./sock_to_gzip_file.py --output-file=\"http.log.gz\" --listen-sock=\"http.log.sock\"\n"
+ #Open the output file
+ if options.output:
+ try:
+ f = gzip.open(options.output, 'wb')
+ except Exception,e:
+ print("Error: could not open output file %s:\n%s\n", options.output, e)
+ sys.exit(-1)
+ else:
+ print("Error: --output-file option required and was not specified\n%s" % (options.usage))
+ sys.exit(-1)
+
+ #Open our socket and bind
+ if options.lsock:
+ if os.path.exists(options.lsock):
+ try:
+ os.remove(options.lsock)
+ except OSError:
+ pass
+ try:
+ s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+ s.bind(options.lsock)
+ s.listen(1)
+ conn, addr = s.accept()
+ except Exception,e:
+ print("Error: Failed to bind socket %s\n%s\n", options.lsock, e)
+ sys.exit(-1)
+ else:
+ print("Error: --listen-sock option required and was not specified\n%s" % (options.usage))
+ sys.exit(-1)
+
+ #Read data from the socket and write to the file
+ while 1:
+ data = conn.recv(1024)
+ if not data: break
+ f.write(data)
+ conn.close()
+ f.close()