mirror of
https://github.com/Justuser3310/jetwork.git
synced 2025-02-08 01:37:38 +00:00
Улучшение прокси
This commit is contained in:
parent
e83bee6b08
commit
dfc37d6ea7
43
web_proxy.py
43
web_proxy.py
@ -4,7 +4,7 @@ import urllib.request
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from db import *
|
from db import *
|
||||||
domain = read()['domain']
|
base_url = read()['base_url']
|
||||||
|
|
||||||
# Логирование
|
# Логирование
|
||||||
#logging.basicConfig(level=ic, format='%(asctime)s - %(message)s')
|
#logging.basicConfig(level=ic, format='%(asctime)s - %(message)s')
|
||||||
@ -13,23 +13,26 @@ ic.disable() # Выключить отладку
|
|||||||
|
|
||||||
class Proxy(http.server.SimpleHTTPRequestHandler):
|
class Proxy(http.server.SimpleHTTPRequestHandler):
|
||||||
def do_GET(self):
|
def do_GET(self):
|
||||||
# Log the requested domain
|
|
||||||
ic(f"Request for: {self.path}")
|
ic(f"Request for: {self.path}")
|
||||||
|
|
||||||
# 'js-check.jet/favicon.ico' -> '127.0.0.1:8000/favicon.ico'
|
# 'js-check.jet/favicon.ico' -> '127.0.0.1:8000/favicon.ico'
|
||||||
target = self.path
|
target = self.path
|
||||||
|
domain = target[7:]
|
||||||
|
domain = domain[:domain.find('/')]
|
||||||
# Если статичный
|
# Если статичный
|
||||||
if 'jet' in target:
|
if read(f'cached/{domain}/config.json')['type'] == 'static':
|
||||||
target = f'{domain}/{target[7:]}' # http://127.0.0.1:8000 / js-check.jet
|
target = f'{base_url}/{target[7:]}' # http://127.0.0.1:8000 / js-check.jet
|
||||||
ic(f"Modded request: {target}")
|
# Если динамический
|
||||||
elif 'dyn' in target:
|
elif read(f'cached/{domain}/config.json')['type'] == 'dynamic':
|
||||||
addr = target[target.find('://')+3:]
|
port = read(f'cached/{domain}/config.json')['port']
|
||||||
addr = addr[:addr.find('/')]
|
target = f'http://bore.del.pw:{port}/{target.replace(f"http://{domain}/", "")}'
|
||||||
port = read(f'cached/{addr}/config.json')['port']
|
else:
|
||||||
target = f'http://bore.del.pw:{port}/{target[target.find("dyn")+4:]}'
|
self.send_error(404, f"Site not found")
|
||||||
ic(f"Modded request: {target}")
|
return 0
|
||||||
|
|
||||||
# Forward the request to the actual server
|
ic(f"Modded request: {target}")
|
||||||
|
|
||||||
|
# Направление запроса по адресу
|
||||||
try:
|
try:
|
||||||
with urllib.request.urlopen(target) as response:
|
with urllib.request.urlopen(target) as response:
|
||||||
self.send_response(response.getcode())
|
self.send_response(response.getcode())
|
||||||
@ -40,16 +43,20 @@ class Proxy(http.server.SimpleHTTPRequestHandler):
|
|||||||
self.send_error(500, f"Error: {str(e)}")
|
self.send_error(500, f"Error: {str(e)}")
|
||||||
|
|
||||||
def do_POST(self):
|
def do_POST(self):
|
||||||
# Log the requested domain
|
|
||||||
ic(f"Request for: {self.path}")
|
ic(f"Request for: {self.path}")
|
||||||
|
|
||||||
if 'jet' in target:
|
if read(f'cached/{domain}/config.json')['type'] == 'static':
|
||||||
target = f'{domain}/{target[7:]}' # http://127.0.0.1:8000 / js-check.jet
|
target = f'{base_url}/{target[7:]}' # http://127.0.0.1:8000 / js-check.jet
|
||||||
ic(f"Modded request: {target}")
|
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:
|
else:
|
||||||
pass
|
self.send_error(404, f"Site not found")
|
||||||
|
return 0
|
||||||
|
|
||||||
# Forward the request to the actual server
|
ic(f"Modded request: {target}")
|
||||||
|
|
||||||
|
# Направление запроса по адресу
|
||||||
try:
|
try:
|
||||||
content_length = int(self.headers['Content-Length'])
|
content_length = int(self.headers['Content-Length'])
|
||||||
post_data = self.rfile.read(content_length)
|
post_data = self.rfile.read(content_length)
|
||||||
|
Loading…
Reference in New Issue
Block a user