-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathserver.py
77 lines (58 loc) · 1.89 KB
/
server.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python 2.7
import SimpleHTTPServer
import SocketServer
import time
import os
from blessings import Terminal
t = Terminal()
def quickshell():
cwd = os.getcwd()
print "[" + t.green("+") + "]OS Shell in " + cwd
print "[" + t.green("+") + "]Enter 'Q' to quit"
try:
while True:
command = raw_input("\n<" + t.cyan("SERVER") + ">$ ")
if not command in ('q', 'Q'):
os.system(command)
else:
print "\n[" + t.red("!") + "]Exiting shell."
time.sleep(1.5)
break
except KeyboardInterrupt:
print "\n[" + t.red("!") + "]Critical. User Aborted"
print "\n[" + t.green("+") + "]Basic HTTP Server.\n"
default = raw_input("[" + t.magenta("?") + "]Default Config? [Y]es/[N]o: ").lower()
if default == 'y':
PORT = 8000
IP = "127.0.0.1"
print "\n[" + t.green("+") + "]Default settings loaded.\n"
elif default == 'n':
print "[" + t.green("+") + "]Specify custom values.\n"
PORT = input("Enter port: ")
IP = raw_input("Enter host: ")
print "[" + t.green("+") + "]Invoke a shell to make adjustments in server directory?"
invoke = raw_input("[" + t.magenta("?") + "][Y]es/[N]o: ").lower()
if invoke == 'y':
quickshell()
elif invoke == 'n':
print "[" + t.green("+") + "]Done."
else:
print "\n[" + t.red("!") + "]Unhandled Option."
else:
print "\n[" + t.red("!") + "]Unhandled Option."
print "[" + t.green("+") + "]Starting Server.\n"
Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
Handler.extensions_map.update({
'.webapp': 'application/x-web-app-manifest+json',
});
try:
httpd = SocketServer.TCPServer((IP, PORT), Handler)
except Exception as e:
print "\n[" + t.red("!") + "]Critical. An exception was raised with the following error message"
print e
print "[" + t.green("+") + "]Serving at", IP, repr(PORT)
# Catching keyboard interrupt for aesthetics purposes
try:
httpd.serve_forever()
except KeyboardInterrupt:
print "\n[" + t.red("!") + "]User Aborted."