aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre-Alexandre Meyer <pierre@mouraf.org>2009-11-13 00:01:16 -0800
committerPierre-Alexandre Meyer <pierre@mouraf.org>2009-11-13 00:01:16 -0800
commita419b128ea17dffbfada5194cc919b51f808a940 (patch)
treea391cc879a4aaffd23175c084b978faf04c32ac4
parent46d5615617d6f78ee037ca894c9036e4ec55b1d6 (diff)
downloadhdt-pierre-online-reporting.tar.gz
hdt-pierre-online-reporting.tar.xz
hdt-pierre-online-reporting.zip
hdt: add webserver to handle reportsonline-reporting
We will eventually have a central database where we can keep and display reports sent by users. As a proof of concept, this small webserver accepts reports (raw data, doesn't do de-serialization yet) and forward them to tinypaste.com. This will be helpful for testing purposes. Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
-rw-r--r--com32/hdt/utils/report/webserver.py84
1 files changed, 84 insertions, 0 deletions
diff --git a/com32/hdt/utils/report/webserver.py b/com32/hdt/utils/report/webserver.py
new file mode 100644
index 00000000..2506a4c4
--- /dev/null
+++ b/com32/hdt/utils/report/webserver.py
@@ -0,0 +1,84 @@
+#----------------------------------------------------------------------- *
+#
+# Copyright 2009 Pierre-Alexandre Meyer - All Rights Reserved
+#
+# Permission is hereby granted, free of charge, to any person
+# obtaining a copy of this software and associated documentation
+# files (the "Software"), to deal in the Software without
+# restriction, including without limitation the rights to use,
+# copy, modify, merge, publish, distribute, sublicense, and/or
+# sell copies of the Software, and to permit persons to whom
+# the Software is furnished to do so, subject to the following
+# conditions:
+#
+# The above copyright notice and this permission notice shall
+# be included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+# OTHER DEALINGS IN THE SOFTWARE.
+#
+#-----------------------------------------------------------------------
+#
+# Simple webserver to accept reported data via POST.
+# Right now, it redirects the reports to tinypaste.com, until
+# we come up with a better way to manage them...
+#
+# Usage:
+# python webserver.py
+#
+# Client:
+# curl -d"hello My World\!" http://hdt-project.org:8080
+
+import cgi, xmlrpclib
+from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
+
+pastebinURL = "http://tinypaste.com"
+pastebinRPCURL = "%s/api/xml-rpc/xml-rpc-server.php" % pastebinURL
+pastebinServer = xmlrpclib.Server(pastebinRPCURL);
+
+class HDTHandler(BaseHTTPRequestHandler):
+ def do_POST(self):
+ global rootnode
+ try:
+ ctype, pdict = cgi.parse_header(self.headers.getheader('content-type'))
+ clen = self.headers.getheader('content-length')
+ if clen:
+ clen = int(clen)
+ else:
+ return
+
+ # XXX Raw data. JSON? Thrift? ...?
+ raw_report = self.rfile.read(clen)
+
+ # Re-POST data to pastebin
+ pastebin_id = pastebinServer.tinypaste.setPaste(raw_report);
+ response = "%s/%s" % (pastebinURL, pastebin_id)
+
+ # Send the pastebin URL back
+ self.send_response(200, 'OK')
+ self.send_header('Content-type', 'text/html; charset=utf-8')
+ self.send_header('Connection', 'close')
+ self.send_header('Content-length', len(response))
+ self.end_headers()
+ self.wfile.write(response)
+ return
+ except:
+ pass
+
+def main():
+ try:
+ server = HTTPServer(('hdt-project.org', 8080), HDTHandler)
+ print 'Started httpserver...'
+ server.serve_forever()
+ except KeyboardInterrupt:
+ print 'SIGINT received, shutting down server'
+ server.socket.close()
+
+if __name__ == '__main__':
+ main()