From 12382d5205fa3ba38f0dad8df8e4fc266ba01f29 Mon Sep 17 00:00:00 2001 From: James Taylor Date: Fri, 13 Jul 2018 15:51:04 -0700 Subject: move settings to file, fix error if no banned_addresses.txt --- server.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'server.py') 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() -- cgit v1.2.3