mirror of
https://github.com/Justuser3310/jetwork.git
synced 2025-01-19 01:18:48 +00:00
Наконец (вроде) работает публикация сайтов
This commit is contained in:
parent
2339e439ce
commit
ef68206cca
6
main.py
6
main.py
@ -49,6 +49,12 @@ os.chdir("../") # возвращаемся в корень
|
||||
server = Thread(target = server, args=(serv_port,))
|
||||
server.start()
|
||||
|
||||
#print(client(8000, "ping"))
|
||||
#ports = port_check(serv_port)
|
||||
#print(ports)
|
||||
|
||||
#client(4140, "ping")
|
||||
|
||||
|
||||
'''
|
||||
# Режим отладки
|
||||
|
55
network.py
55
network.py
@ -8,6 +8,7 @@ from random import randint
|
||||
from shutil import unpack_archive
|
||||
# Убираем ненужное (../some => some)
|
||||
from re import compile, sub
|
||||
# Timeout для команды
|
||||
|
||||
from verify import *
|
||||
from domain_check import *
|
||||
@ -30,12 +31,11 @@ def port_gen():
|
||||
port = randint(4000, 4200)
|
||||
return port
|
||||
|
||||
|
||||
def server_http():
|
||||
os.chdir("cached")
|
||||
os.system("python -m http.server")
|
||||
|
||||
def server(server_port):
|
||||
def server(http_port):
|
||||
host = "127.0.0.1"
|
||||
port = 8001
|
||||
|
||||
@ -51,7 +51,6 @@ def server(server_port):
|
||||
while True:
|
||||
try:
|
||||
op = conn.recv(1024).decode()
|
||||
print(op)
|
||||
except:
|
||||
pass
|
||||
if not op:
|
||||
@ -78,6 +77,17 @@ def server(server_port):
|
||||
|
||||
conn.close()
|
||||
|
||||
def recv(q, s):
|
||||
okay = False
|
||||
while not okay:
|
||||
try:
|
||||
data = s.recv(1024).decode()
|
||||
okay = True
|
||||
except:
|
||||
pass
|
||||
q.put(data)
|
||||
|
||||
import multiprocessing as mp
|
||||
# op = operation
|
||||
def client(port, op = "ping"):
|
||||
host = 'jetwork.404.mn'
|
||||
@ -90,16 +100,26 @@ def client(port, op = "ping"):
|
||||
return None
|
||||
|
||||
s.send(op.encode())
|
||||
okay = False
|
||||
while not okay:
|
||||
try:
|
||||
data = s.recv(1024).decode()
|
||||
okay = True
|
||||
except:
|
||||
pass
|
||||
print(data)
|
||||
|
||||
# Канал обмена процесс - наша функция
|
||||
q = mp.Queue()
|
||||
# Стартуем процесс получения ответа
|
||||
p = mp.Process(target=recv, args=(q, s))
|
||||
p.start()
|
||||
# Ждём 10 секунд - максимум
|
||||
p.join(10)
|
||||
|
||||
try:
|
||||
data = q.get(block=False)
|
||||
except:
|
||||
data = None
|
||||
|
||||
# Если процесс жив - убираем
|
||||
if p.is_alive():
|
||||
p.terminate()
|
||||
|
||||
s.close()
|
||||
|
||||
return data
|
||||
elif op[:4] == "get_":
|
||||
site = op[4:]
|
||||
@ -144,3 +164,16 @@ def client(port, op = "ping"):
|
||||
# Удаляем фальшивые файлы
|
||||
os.remove(f"verify/{site}.zip")
|
||||
os.remove(f"verify/{site}.sig")
|
||||
|
||||
|
||||
from tqdm import tqdm
|
||||
def port_check(your_port):
|
||||
ports = []
|
||||
|
||||
checks = list(range(4000, 4200))
|
||||
checks.remove(your_port)
|
||||
for port in tqdm(range(4000, 4200)):
|
||||
if client(port, "ping"):
|
||||
ports.append(port)
|
||||
|
||||
return ports
|
||||
|
@ -1,8 +1,10 @@
|
||||
from os import system, mkdir
|
||||
from db import *
|
||||
from shutil import copyfile, make_archive, rmtree
|
||||
from tqdm import tqdm
|
||||
|
||||
from verify import *
|
||||
from shutil import copyfile, make_archive, rmtree
|
||||
from network import *
|
||||
|
||||
print("(1) Создать сайт")
|
||||
print("(2) Обновить сайт")
|
||||
@ -89,4 +91,30 @@ elif op == "3":
|
||||
make_archive(f"mysites/{domain}", "zip", f"mysites/{domain}")
|
||||
sign(f"mysites/{domain}.zip", f"mysites/{domain}.key", f"mysites/{domain}")
|
||||
|
||||
exit()
|
||||
|
||||
|
||||
# Копируем файлы из mysites в cached
|
||||
copyfile(f"mysites/{domain}", "cached/{domain}")
|
||||
copyfile(f"mysites/{domain}.pem", "cached/{domain}.pem")
|
||||
copyfile(f"mysites/{domain}.sig", "cached/{domain}.sig")
|
||||
copyfile(f"mysites/{domain}.zip", "cached/{domain}.zip")
|
||||
|
||||
|
||||
|
||||
print("Опубликовать сайт?")
|
||||
pub = input("y/n >> ")
|
||||
|
||||
if pub == "n":
|
||||
exit()
|
||||
|
||||
print("Введите ваш порт сервера (при запуске main.py)")
|
||||
serv_port = int(input(">> "))
|
||||
http_port = client(serv_port, f"is_{domain}")
|
||||
|
||||
print("Получаем все порты...")
|
||||
ports = port_check(serv_port)
|
||||
|
||||
print("Публикуем сайт...")
|
||||
for port in tqdm(ports):
|
||||
client(port, f"publish_{domain}<>{http_port}")
|
||||
|
Loading…
Reference in New Issue
Block a user