From dfc37d6ea738aaf8c1d99b4b6a722297b8524e96 Mon Sep 17 00:00:00 2001 From: justuser Date: Mon, 19 Aug 2024 14:49:25 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BF=D1=80=D0=BE=D0=BA=D1=81=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web_proxy.py | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/web_proxy.py b/web_proxy.py index 448d099..14922d6 100644 --- a/web_proxy.py +++ b/web_proxy.py @@ -4,7 +4,7 @@ import urllib.request import logging from db import * -domain = read()['domain'] +base_url = read()['base_url'] # Логирование #logging.basicConfig(level=ic, format='%(asctime)s - %(message)s') @@ -13,23 +13,26 @@ ic.disable() # Выключить отладку class Proxy(http.server.SimpleHTTPRequestHandler): def do_GET(self): - # Log the requested domain ic(f"Request for: {self.path}") # 'js-check.jet/favicon.ico' -> '127.0.0.1:8000/favicon.ico' target = self.path + domain = target[7:] + domain = domain[:domain.find('/')] # Если статичный - if 'jet' in target: - target = f'{domain}/{target[7:]}' # http://127.0.0.1:8000 / js-check.jet - ic(f"Modded request: {target}") - elif 'dyn' in target: - addr = target[target.find('://')+3:] - addr = addr[:addr.find('/')] - port = read(f'cached/{addr}/config.json')['port'] - target = f'http://bore.del.pw:{port}/{target[target.find("dyn")+4:]}' - ic(f"Modded request: {target}") + if read(f'cached/{domain}/config.json')['type'] == 'static': + target = f'{base_url}/{target[7:]}' # http://127.0.0.1:8000 / js-check.jet + # Если динамический + elif read(f'cached/{domain}/config.json')['type'] == 'dynamic': + port = read(f'cached/{domain}/config.json')['port'] + target = f'http://bore.del.pw:{port}/{target.replace(f"http://{domain}/", "")}' + else: + self.send_error(404, f"Site not found") + return 0 + + ic(f"Modded request: {target}") - # Forward the request to the actual server + # Направление запроса по адресу try: with urllib.request.urlopen(target) as response: self.send_response(response.getcode()) @@ -40,16 +43,20 @@ class Proxy(http.server.SimpleHTTPRequestHandler): self.send_error(500, f"Error: {str(e)}") def do_POST(self): - # Log the requested domain ic(f"Request for: {self.path}") - if 'jet' in target: - target = f'{domain}/{target[7:]}' # http://127.0.0.1:8000 / js-check.jet - ic(f"Modded request: {target}") + if read(f'cached/{domain}/config.json')['type'] == 'static': + target = f'{base_url}/{target[7:]}' # http://127.0.0.1:8000 / js-check.jet + elif read(f'cached/{domain}/config.json')['type'] == 'dynamic': + port = read(f'cached/{domain}/config.json')['port'] + target = f'http://bore.del.pw:{port}/{target.replace(f"http://{domain}/", "")}' else: - pass + self.send_error(404, f"Site not found") + return 0 + + ic(f"Modded request: {target}") - # Forward the request to the actual server + # Направление запроса по адресу try: content_length = int(self.headers['Content-Length']) post_data = self.rfile.read(content_length)