aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--server.py22
-rw-r--r--settings.py11
3 files changed, 24 insertions, 10 deletions
diff --git a/.gitignore b/.gitignore
index e792bf6..4f51029 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@ __pycache__/
debug/
data/
banned_addresses.txt
+settings.txt
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()
diff --git a/settings.py b/settings.py
new file mode 100644
index 0000000..499b32b
--- /dev/null
+++ b/settings.py
@@ -0,0 +1,11 @@
+default_settings = '''route_tor = False
+port_number = 80
+allow_foreign_addresses = False
+'''
+exec(default_settings)
+try:
+ with open('settings.txt', 'r', encoding='utf-8') as file:
+ exec(file.read())
+except FileNotFoundError:
+ with open('settings.txt', 'a', encoding='utf-8') as file:
+ file.write(default_settings) \ No newline at end of file