-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebserve
executable file
·43 lines (34 loc) · 1018 Bytes
/
webserve
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/python3
import os
import sys
import http.server
import ssl
import socketserver
import signal
def handler(signum, frame):
print("Exiting after 24 hours...")
sys.exit(1)
signal.signal(signal.SIGALRM, handler)
signal.alarm(24 * 60 * 60)
try:
if sys.argv[1].startswith("/"):
filepath = sys.argv[1]
else:
filepath = os.getcwd() + "/" + sys.argv[1]
except IndexError:
filepath = os.getcwd()
os.chdir("/")
host = socketserver.socket.gethostname() + ".mclean.harvard.edu"
httpd = socketserver.TCPServer(("", 0), http.server.SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket(
httpd.socket,
server_side=True,
certfile="/home/ddrucker/mictools/everything-" + host + ".pem",
ssl_version=ssl.PROTOCOL_TLS,
)
print(
"Go to: https://" + host + ":" + str(httpd.socket.getsockname()[1]) + filepath
)
print("(In Terminal, you can right-click the above and select Open URL.)")
print("Please type Control-c when you are done.")
httpd.serve_forever()