aboutsummaryrefslogtreecommitdiffstats
path: root/server.py
diff options
context:
space:
mode:
authorJames Taylor <user234683@users.noreply.github.com>2018-07-13 15:51:04 -0700
committerJames Taylor <user234683@users.noreply.github.com>2018-07-13 15:51:04 -0700
commit12382d5205fa3ba38f0dad8df8e4fc266ba01f29 (patch)
treef38bb259cafa4d248e63d81f3b01eeb0d0268530 /server.py
parentc3b9f8c4582882cd1f768b0727eca75475bb4f94 (diff)
downloadyt-local-12382d5205fa3ba38f0dad8df8e4fc266ba01f29.tar.lz
yt-local-12382d5205fa3ba38f0dad8df8e4fc266ba01f29.tar.xz
yt-local-12382d5205fa3ba38f0dad8df8e4fc266ba01f29.zip
move settings to file, fix error if no banned_addresses.txt
Diffstat (limited to 'server.py')
-rw-r--r--server.py22
1 files changed, 12 insertions, 10 deletions
diff --git a/server.py b/server.py
index 93d8df5..3a55eae 100644
--- a/server.py
+++ b/server.py
@@ -10,13 +10,15 @@ import socks
import subprocess
import re
-ROUTE_TOR = True
-PORT_NUMBER=80
-ALLOW_FOREIGN_ADDRESSES=False
+import settings
+
BAN_FILE = "banned_addresses.txt"
-with open(BAN_FILE, 'r') as f:
- banned_addresses = f.read().splitlines()
+try:
+ with open(BAN_FILE, 'r') as f:
+ banned_addresses = f.read().splitlines()
+except FileNotFoundError:
+ banned_addresses = ()
def ban_address(address):
banned_addresses.append(address)
@@ -127,15 +129,15 @@ def site_dispatch(env, start_response):
-if ROUTE_TOR:
+if settings.route_tor:
#subprocess.Popen(TOR_PATH)
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, '127.0.0.1', 9150)
socket.socket = socks.socksocket
gevent.socket.socket = socks.socksocket
-if ALLOW_FOREIGN_ADDRESSES:
- server = WSGIServer(('0.0.0.0', PORT_NUMBER), site_dispatch)
+if settings.allow_foreign_addresses:
+ server = WSGIServer(('0.0.0.0', settings.port_number), site_dispatch)
else:
- server = WSGIServer(('127.0.0.1', PORT_NUMBER), site_dispatch)
-print('Started httpserver on port ' , PORT_NUMBER)
+ server = WSGIServer(('127.0.0.1', settings.port_number), site_dispatch)
+print('Started httpserver on port ' , settings.port_number)
server.serve_forever()