Переход на вид site.jet вместо 127.0.0.1:8000//site.jet

main
justuser 3 months ago
parent 9d2645d7ca
commit f09daea63e

@ -1,5 +1,5 @@
from re import compile, sub
domains = ['jet', 'mirror', 'org', 'info', 'news', 'me']
domains = ['jet', 'dyn']
def domain_ok(domain):
global domains

@ -77,11 +77,7 @@ def update_sites(n, s_val):
res = []
for i in next(walk('cached/'), (None, None, []))[1]:
conf = read(f'cached/{i}/config.json')
if conf['type'] == 'dynamic':
res.append(html.Div([ dcc.Link(children=i, href=f'http://bore.pub:{conf["port"]}',
target='_blank') ], className='sites_elem'))
else:
res.append(html.Div([ dcc.Link(children=i, href=f'{domain}/{i}',
res.append(html.Div([ dcc.Link(children=i, href=f'http://{i}',
target='_blank') ], className='sites_elem'))
return res

@ -7,7 +7,9 @@ from multiprocessing import Process
from network import *
from updater import *
from proxy import *
from web_proxy import *
from status import *
from db import *
#
@ -47,14 +49,18 @@ def main():
# http сервер
http = Thread(target = server_http)
http.start()
# сервер обработки запросов
# Cервер обработки запросов
srv = Thread(target = server, args=(http_port,))
srv.start()
# Прокси для браузера
http_proxy = Thread(target = web_proxy)
http_proxy.start()
# Стартуем авто-поиск портов и авто-обновление сайтов
updater = Thread(target = update_demon, args=(serv_port,))
updater.start()
# DEPRECATED??? DEPRECATED DEPRECATED
# Стартуем интерфейс
system('python interface.py')

@ -62,11 +62,7 @@ def update_sites(n, s_val):
res = []
for i in next(walk('cached/'), (None, None, []))[1]:
conf = read(f'cached/{i}/config.json')
if conf['type'] == 'dynamic':
res.append(html.Div([ dcc.Link(children=i, href=f'http://bore.pub:{conf["port"]}',
target='_blank') ], className='sites_elem'))
else:
res.append(html.Div([ dcc.Link(children=i, href=f'{domain}/{i}',
res.append(html.Div([ dcc.Link(children=i, href=f'{domain}/{i}',
target='_blank') ], className='sites_elem'))
return res

@ -0,0 +1,69 @@
import http.server
import socketserver
import urllib.request
import logging
from db import *
domain = read()['domain']
# Логирование
#logging.basicConfig(level=ic, format='%(asctime)s - %(message)s')
from icecream import ic
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
# Если статичный
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}")
# 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
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}")
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)}")
def web_proxy():
PORT = 8080
with socketserver.TCPServer(("", PORT), Proxy) as httpd:
ic(f"Serving on port {PORT}")
httpd.serve_forever()
Loading…
Cancel
Save