cttynul 3 лет назад
Родитель
Сommit
df7e3decf5
3 измененных файлов с 38 добавлено и 10 удалено
  1. 11 0
      config.json
  2. 25 9
      config_handler.py
  3. 2 1
      waybackproxy.py

+ 11 - 0
config.json

@@ -0,0 +1,11 @@
+{
+    "LISTEN_PORT": 8888,
+    "DATE": "20011025",
+    "DATE_TOLERANCE": 365,
+    "GEOCITIES_FIX": true,
+    "QUICK_IMAGES": true,
+    "WAYBACK_API": true,
+    "CONTENT_TYPE_ENCODING": true,
+    "SILENT": false,
+    "SETTINGS_PAGE": true
+}

+ 25 - 9
config.py → config_handler.py

@@ -1,23 +1,24 @@
+import json
 # Listen port for the HTTP proxy.
-LISTEN_PORT = 8888
+global LISTEN_PORT
 
 # Date to get pages from Wayback. YYYYMMDD, YYYYMM and YYYY formats are
 # accepted, the more specific the better.
-DATE = '20011025' # <- Windows XP release date in case you're wondering
+global DATE 
 
 # Allow the client to load pages and assets up to X days after DATE.
 # Set to None to disable this restriction.
-DATE_TOLERANCE = 365
+global DATE_TOLERANCE
 
 # Send Geocities requests to oocities.org if set to True.
-GEOCITIES_FIX = True
+global GEOCITIES_FIX
 
 # Use the original Wayback Machine URL as a shortcut when loading images.
 # May result in faster page loads, but all images will point to
 # http://web.archive.org/... as a side effect. Set this value to 2 to enable an
 # experimental mode using authentication on top of the original URLs instead
 # (which is not supported by Internet Explorer and some other browsers).
-QUICK_IMAGES = True
+global QUICK_IMAGES
 
 # Use the Wayback Machine Availability API to find the closest available
 # snapshot to the desired date, instead of directly requesting that date. Helps
@@ -25,15 +26,30 @@ QUICK_IMAGES = True
 # is available at an earlier date. As a side effect, pages will take longer to
 # load due to the added API call. If enabled, this option will disable the
 # QUICK_IMAGES bypass mechanism built into the PAC file.
-WAYBACK_API = True
+global WAYBACK_API
 
 # Allow the Content-Type header to contain an encoding. Some old browsers
 # (Mosaic?) don't understand that and fail to load anything - set this to
 # False if you're using one of them.
-CONTENT_TYPE_ENCODING = True
+global CONTENT_TYPE_ENCODING
 
 # Disables logging if set to True.
-SILENT = False
+global SILENT
 
 # Enables the settings page on http://web.archive.org if set to True.
-SETTINGS_PAGE = True
+global SETTINGS_PAGE
+
+try:
+	with open("config.json") as f:
+		data = json.loads(f.read())
+		LISTEN_PORT = data["LISTEN_PORT"]
+		DATE = data["DATE"]
+		DATE_TOLERANCE = data["DATE_TOLERANCE"]
+		GEOCITIES_FIX = data["GEOCITIES_FIX"]
+		QUICK_IMAGES = data["QUICK_IMAGES"]
+		WAYBACK_API = data["WAYBACK_API"]
+		CONTENT_TYPE_ENCODING = data["CONTENT_TYPE_ENCODING"]
+		SILENT = data["SILENT"]
+		SETTINGS_PAGE = data["SETTINGS_PAGE"]
+except EnvironmentError as e:
+	print("Wops! Error opening config.json")

+ 2 - 1
waybackproxy.py

@@ -1,6 +1,6 @@
 #!/usr/bin/env python3
 import base64, datetime, json, lrudict, re, socket, socketserver, string, sys, threading, traceback, urllib.request, urllib.error, urllib.parse
-from config import *
+from config_handler import *
 
 class ThreadingTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
 	"""TCPServer with ThreadingMixIn added."""
@@ -575,6 +575,7 @@ def main():
 	"""Starts the server."""
 	server = ThreadingTCPServer(('', LISTEN_PORT), Handler)
 	_print('[-] Now listening on port', LISTEN_PORT)
+	_print('[-] Date set to', DATE)
 	try:
 		server.serve_forever()
 	except KeyboardInterrupt: # Ctrl+C to stop