diff options
Diffstat (limited to 'httpd.py')
-rw-r--r-- | httpd.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/httpd.py b/httpd.py new file mode 100644 index 0000000..f61b22b --- /dev/null +++ b/httpd.py @@ -0,0 +1,41 @@ +#! /usr/bin/env python3 + +from http.server import * +import json +import tempfile +import base64 + +class HandlerClass(BaseHTTPRequestHandler): + def __init__(self, request, client_address, server): + self.timeout = 20 + BaseHTTPRequestHandler.__init__(self, request, client_address, server) + + def do_POST(self): + to_read = int(self.headers['Content-Length']) + data = self.rfile.read(to_read) + if len(data) > 0: + dat_str = data.decode("ascii") + body = json.loads(dat_str) + ssh_key = body['ssh'] + gpg_key = body['gpg'] + print("your (base64) ssh_key: " + ssh_key) + print("your (base64) gpg_key: " + gpg_key) + ssh_keypath = as_tempfile(base64.b64decode(ssh_key)) + gpg_keypath = as_tempfile(base64.b64decode(gpg_key)) + recv_keys(ssh_keypath, gpg_keypath) + + self.send_response(200) + self.end_headers() + +def as_tempfile(content): + tmpfile = tempfile.NamedTemporaryFile() + tmpfile.write(content) + return tmpfile + +def main(): + print("Running on port whatever") + server_address = ('', 8002) + httpd = HTTPServer(server_address, HandlerClass) + httpd.serve_forever() + +main() |