diff options
author | 2013-06-25 04:35:14 +0100 | |
---|---|---|
committer | 2013-06-25 04:35:14 +0100 | |
commit | be084216e7dc58032645215edd02324e80728cb2 (patch) | |
tree | 1305d9ca9090e7d77b740ef4f3404f90161f8a72 | |
parent | Initial commit with .gitignore (diff) | |
download | log-analysis-be084216e7dc58032645215edd02324e80728cb2.tar.gz log-analysis-be084216e7dc58032645215edd02324e80728cb2.tar.bz2 log-analysis-be084216e7dc58032645215edd02324e80728cb2.zip |
Basic HTTP server that prints out POST request info
-rw-r--r-- | CollectionDaemon.py | 25 | ||||
-rw-r--r-- | CollectionHTTPServer.py | 33 |
2 files changed, 58 insertions, 0 deletions
diff --git a/CollectionDaemon.py b/CollectionDaemon.py new file mode 100644 index 0000000..a728e75 --- /dev/null +++ b/CollectionDaemon.py @@ -0,0 +1,25 @@ +""" +Implements a daemon that hosts the HTTP server for log collection. + +TODO: + daemonisation + implement both IPv4 and IPv6 modes + proper shutdown +""" + +import CollectionHTTPServer + +class CollectionDaemon: + + def __init__(self, port=8000): + server_class = CollectionHTTPServer.HTTPServer6 + handler_class = CollectionHTTPServer.HTTPRequestHandler + + self.server_address = ('::', port) + self.httpd = server_class(self.server_address, handler_class) + + def start(self): + self.httpd.serve_forever() + +if __name__ == '__main__': + CollectionDaemon().start() diff --git a/CollectionHTTPServer.py b/CollectionHTTPServer.py new file mode 100644 index 0000000..d2982fd --- /dev/null +++ b/CollectionHTTPServer.py @@ -0,0 +1,33 @@ +""" +Implements the HTTP handler for log collection + +TODO: + decide on exact protocol + HTTP/1.1 + retrieve client's hostname + send to analyser + store in filesystem (later in storage backend) + log groups +""" + +import BaseHTTPServer +import socket + +class HTTPServer6(BaseHTTPServer.HTTPServer): + + address_family = socket.AF_INET6 + +class HTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): + + #protocol_version = "HTTP/1.1" + + def do_POST(self): + print(self.client_address) + print(self.command, self.path, self.request_version) + print(self.headers.headers) + + size = int(self.headers.getheader('Content-Length')) + + print(self.rfile.read(size)) + self.send_response(200) + self.end_headers() |