aboutsummaryrefslogtreecommitdiff
path: root/test/server.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/server.py')
-rwxr-xr-x[-rw-r--r--]test/server.py65
1 files changed, 28 insertions, 37 deletions
diff --git a/test/server.py b/test/server.py
index 83a72fa..58a84bd 100644..100755
--- a/test/server.py
+++ b/test/server.py
@@ -1,3 +1,5 @@
+#!/usr/bin/env python3
+#
# Copyright (C) 2021 jahoti <jahoti@tilde.team>
# Licensing information is collated in the `copyright` file
@@ -6,41 +8,12 @@ A modular "virtual network" proxy,
wrapping the classes in proxy_core.py
"""
-from proxy_core import *
+import proxy_core
from urllib.parse import parse_qs
+from misc_constants import *
+from world_wide_library import catalog as internet
-internet = {} # Add info here later
-mime_types = {
- "7z": "application/x-7z-compressed", "oga": "audio/ogg",
- "abw": "application/x-abiword", "ogv": "video/ogg",
- "arc": "application/x-freearc", "ogx": "application/ogg",
- "bin": "application/octet-stream", "opus": "audio/opus",
- "bz": "application/x-bzip", "otf": "font/otf",
- "bz2": "application/x-bzip2", "pdf": "application/pdf",
- "css": "text/css", "png": "image/png",
- "csv": "text/csv", "sh": "application/x-sh",
- "gif": "image/gif", "svg": "image/svg+xml",
- "gz": "application/gzip", "tar": "application/x-tar",
- "htm": "text/html", "ts": "video/mp2t",
- "html": "text/html", "ttf": "font/ttf",
- "ico": "image/vnd.microsoft.icon", "txt": "text/plain",
- "js": "text/javascript", "wav": "audio/wav",
- "jpeg": "image/jpeg", "weba": "audio/webm",
- "jpg": "image/jpeg", "webm": "video/webm",
- "json": "application/json", "woff": "font/woff",
- "mjs": "text/javascript", "woff2": "font/woff2",
- "mp3": "audio/mpeg", "xhtml": "application/xhtml+xml",
- "mp4": "video/mp4", "zip": "application/zip",
- "mpeg": "video/mpeg",
- "odp": "application/vnd.oasis.opendocument.presentation",
- "ods": "application/vnd.oasis.opendocument.spreadsheet",
- "odt": "application/vnd.oasis.opendocument.text",
- "xml": "application/xml" # text/xml if readable from casual users
-}
-
-class RequestHijacker(ProxyRequestHandler):
- certdir = global_certdir
-
+class RequestHijacker(proxy_core.ProxyRequestHandler):
def handle_request(self, req_body):
path_components = self.path.split('?', maxsplit=1)
path = path_components[0]
@@ -103,8 +76,26 @@ class RequestHijacker(ProxyRequestHandler):
def do_an_internet(certdir, port):
"""Start up the proxy/server"""
- global global_certdir
- global_certdir = certdir
-
- httpd = ThreadingHTTPServer(('', port), RequestHijacker)
+ proxy_core.certdir = certdir
+ httpd = proxy_core.ThreadingHTTPServer(('', port), RequestHijacker)
httpd.serve_forever()
+
+if __name__ == '__main__':
+ import sys
+ def fail(msg, error_code):
+ print('Error:', msg)
+ print('Usage:', sys.argv[0], '[certificates directory] (port)')
+ sys.exit(error_code)
+
+ if len(sys.argv) < 2:
+ fail('missing required argument "certificates directory".', 1)
+
+ certdir = sys.argv[1]
+ if not proxy_core.os.path.isdir(certdir):
+ fail('selected certificate directory does not exist.', 2)
+
+ port = sys.argv[2] if len(sys.argv) > 2 else '1337'
+ if not port.isnumeric():
+ fail('port must be an integer.', 3)
+
+ do_an_internet(certdir, int(port))