mirror of
https://github.com/Justuser3310/jetwork.git
synced 2025-01-18 08:58:48 +00:00
Исправление хоста обратного прокси
This commit is contained in:
parent
f89269a1f6
commit
27eba1fbf4
@ -124,7 +124,7 @@ def recv(s, data_out):
|
||||
data_out.put(data)
|
||||
|
||||
# op = operation
|
||||
def client(port, op = "ping", host = 'bore.pub'):
|
||||
def client(port, op = "ping", host = 'bore.del.pw'):
|
||||
# Если порт не определён
|
||||
if not port:
|
||||
return None
|
||||
|
@ -134,7 +134,7 @@ elif op == '4':
|
||||
client(port, f'publish_{domain}<>{http_port}')
|
||||
sleep(5)
|
||||
|
||||
host = 'bore.pub'
|
||||
host = 'bore.del.pw'
|
||||
# Проверяем тип сайта
|
||||
type = read(f'mysites//{domain}/config.json')['type']
|
||||
# Если динамический - вставляем спец страницу
|
||||
@ -163,8 +163,7 @@ if op != '':
|
||||
if pub == 'n':
|
||||
exit()
|
||||
|
||||
print('Введите ваш порт сервера (при запуске main.py)')
|
||||
serv_port = int(input('>> '))
|
||||
serv_port = int( read()['our_port'] )
|
||||
http_port = client(serv_port, f'is_{domain}')
|
||||
|
||||
print('Получаем все порты...')
|
||||
|
71
web_proxy.py.bak
Normal file
71
web_proxy.py.bak
Normal file
@ -0,0 +1,71 @@
|
||||
import http.server
|
||||
import socketserver
|
||||
import urllib.request
|
||||
import logging
|
||||
|
||||
from db import *
|
||||
domain = read()['domain']
|
||||
|
||||
# Логирование
|
||||
#logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(message)s')
|
||||
from icecream import ic
|
||||
|
||||
class Proxy(http.server.SimpleHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
# Log the requested domain
|
||||
logging.info(f"Request for: {self.path}")
|
||||
|
||||
# 'js-check.jet/favicon.ico' -> '127.0.0.1:8000/favicon.ico'
|
||||
target = self.path
|
||||
# Если статичный
|
||||
if 'jet' in target:
|
||||
target = f'{domain}/{target[7:]}' # http://127.0.0.1:8000 / js-check.jet
|
||||
logging.info(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.pub:{port}/{target[target.find("dyn")+4:]}'
|
||||
logging.info(f"Modded request: {target}")
|
||||
|
||||
# Forward the request to the actual server
|
||||
try:
|
||||
with urllib.request.urlopen(target) as response:
|
||||
self.send_response(response.getcode())
|
||||
self.send_header("Content-type", response.headers.get_content_type())
|
||||
self.end_headers()
|
||||
self.wfile.write(response.read())
|
||||
except Exception as e:
|
||||
self.send_error(500, f"Error: {str(e)}")
|
||||
|
||||
def do_POST(self):
|
||||
# Log the requested domain
|
||||
logging.info(f"Request for: {self.path}")
|
||||
|
||||
if 'jet' in target:
|
||||
target = f'{domain}/{target[7:]}' # http://127.0.0.1:8000 / js-check.jet
|
||||
logging.info(f"Modded request: {target}")
|
||||
else:
|
||||
pass
|
||||
|
||||
# Forward the request to the actual server
|
||||
try:
|
||||
content_length = int(self.headers['Content-Length'])
|
||||
post_data = self.rfile.read(content_length)
|
||||
req = urllib.request.Request(self.path, data=post_data, method='POST')
|
||||
with urllib.request.urlopen(req) as response:
|
||||
self.send_response(response.getcode())
|
||||
self.send_header("Content-type", response.headers.get_content_type())
|
||||
self.end_headers()
|
||||
self.wfile.write(response.read())
|
||||
except Exception as e:
|
||||
self.send_error(500, f"Error: {str(e)}")
|
||||
|
||||
#if __name__ == "__main__":
|
||||
def web_proxy():
|
||||
PORT = 8080
|
||||
with socketserver.TCPServer(("", PORT), Proxy) as httpd:
|
||||
logging.info(f"Serving on port {PORT}")
|
||||
httpd.serve_forever()
|
||||
|
||||
web_proxy()
|
Loading…
Reference in New Issue
Block a user