mirror of
https://github.com/Justuser3310/jetwork.git
synced 2025-04-19 20:19:52 +00:00
Переработка создателей сайтов и переосмысление доменов
This commit is contained in:
parent
e72996af3c
commit
ec0523d52c
@ -1,15 +1,23 @@
|
|||||||
from re import compile, sub
|
from re import compile, sub
|
||||||
|
domains = ['jet', 'mirror', 'org', 'info', 'news', 'me']
|
||||||
|
|
||||||
def domain_ok(domain):
|
def domain_ok(domain):
|
||||||
domains = ["jet", "jw", "404", "dash", "awesome", "mirror"]
|
global domains
|
||||||
|
if domain.count('.') == 1:
|
||||||
if domain.count(".") == 1:
|
if domain.split('.')[1] in domains:
|
||||||
if domain.split(".")[1] in domains:
|
|
||||||
# ../some => some
|
# ../some => some
|
||||||
# Защита от проверки папок выше, чем нужно и др.
|
# Защита от проверки папок выше, чем нужно и др.
|
||||||
regex = compile('[^a-z.-]')
|
regex = compile('[^a-z0-9.-]')
|
||||||
c_domain = regex.sub('', domain)
|
c_domain = regex.sub('', domain)
|
||||||
if domain == c_domain:
|
if domain == c_domain:
|
||||||
return domain
|
return domain
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def domain_list():
|
||||||
|
global domains
|
||||||
|
out = ''
|
||||||
|
for i in domains:
|
||||||
|
out += f'{i}, '
|
||||||
|
out = out[:-2]
|
||||||
|
return out
|
||||||
|
224
site_creator.py
224
site_creator.py
@ -1,4 +1,4 @@
|
|||||||
from os import system, mkdir
|
from os import system, mkdir, walk
|
||||||
from db import *
|
from db import *
|
||||||
from shutil import copyfile, make_archive, rmtree, copytree
|
from shutil import copyfile, make_archive, rmtree, copytree
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
@ -6,176 +6,172 @@ from time import sleep
|
|||||||
|
|
||||||
from verify import *
|
from verify import *
|
||||||
from network import *
|
from network import *
|
||||||
|
from domain_check import domain_list
|
||||||
|
|
||||||
print("(1) Создать сайт")
|
def your_sites():
|
||||||
print("(2) Обновить сайт")
|
sites = {}; num = 1
|
||||||
print("(3) Сменить тип")
|
for i in next(walk('cached/'), (None, None, []))[1]:
|
||||||
print("(4) Авто-раздача сайта")
|
sites[str(num)] = i
|
||||||
print("Enter для просто публикации.")
|
print(f'{str(num)}. {i}')
|
||||||
|
num += 1
|
||||||
|
return sites
|
||||||
|
|
||||||
op = input(">> ")
|
print('(1) Создать сайт')
|
||||||
|
print('(2) Обновить сайт')
|
||||||
|
print('(3) Сменить тип')
|
||||||
|
print('(4) Авто-раздача сайта')
|
||||||
|
print('Enter для просто публикации.')
|
||||||
|
|
||||||
if op == "1":
|
op = input('>> ')
|
||||||
|
|
||||||
|
if op == '1':
|
||||||
from domain_check import *
|
from domain_check import *
|
||||||
|
|
||||||
print("\nДомены: .jet, .jw, .404, .dash, .awesome, .mirror")
|
print(f'\nДоступные 1 lvl домены: {domain_list()}')
|
||||||
domain = input("Домен сайта: ")
|
domain = input('Домен сайта: ')
|
||||||
if not domain_ok(domain):
|
if not domain_ok(domain):
|
||||||
print("Неправильный формат или домен.")
|
print('Неправильный формат или домен.')
|
||||||
exit()
|
exit()
|
||||||
print("\n(1) Статичный / (2) Динамический")
|
print('\n(1) Статичный / (2) Динамический')
|
||||||
type = input("Тип: ")
|
type = input('Тип: ')
|
||||||
|
|
||||||
# Создаём папку и ключи для подписи
|
# Создаём папку и ключи для подписи
|
||||||
mkdir(f"mysites/{domain}")
|
mkdir(f'mysites/{domain}')
|
||||||
key_gen(f"mysites/{domain}")
|
key_gen(f'mysites/{domain}')
|
||||||
|
|
||||||
if type == "1":
|
if type == '1':
|
||||||
conf = {"type": "static", "ver": 1}
|
conf = {'type': 'static', 'ver': 1}
|
||||||
print("ПРИМЕЧАНИЕ: index.html обязателен.")
|
print('\nПРИМЕЧАНИЕ: index.html обязателен.')
|
||||||
elif type == "2":
|
|
||||||
port = input("Порт сервера: ")
|
|
||||||
conf = {"type": "dynamic", "ver": 1, "port": int(port)}
|
|
||||||
write(conf, f"mysites/{domain}/config.json")
|
|
||||||
|
|
||||||
if type == "1":
|
|
||||||
# Создаём index.html для загрузки сайта
|
# Создаём index.html для загрузки сайта
|
||||||
with open(f"mysites/{domain}/index.html", "w") as f:
|
with open(f'mysites/{domain}/index.html', 'w') as f:
|
||||||
f.write("<h1> Hello jetwork! </h1>")
|
f.write('<h1> Hello jetwork! </h1>')
|
||||||
f.close()
|
f.close()
|
||||||
|
elif type == '2':
|
||||||
|
port = input('Порт сервера: ')
|
||||||
|
conf = {'type': 'dynamic', 'ver': 1, 'port': int(port)}
|
||||||
|
write(conf, f'mysites/{domain}/config.json')
|
||||||
|
|
||||||
# Архивируем и создаём сигнатуру для подтверждения неизменности архива
|
# Архивируем и создаём сигнатуру для подтверждения неизменности архива
|
||||||
make_archive(f"mysites/{domain}", "zip", f"mysites/{domain}")
|
make_archive(f'mysites/{domain}', 'zip', f'mysites/{domain}')
|
||||||
sign(f"mysites/{domain}.zip", f"mysites/{domain}.key", f"mysites/{domain}")
|
sign(f'mysites/{domain}.zip', f'mysites/{domain}.key', f'mysites/{domain}')
|
||||||
|
|
||||||
elif op == "2":
|
elif op == '2':
|
||||||
domain = input("\nДомен сайта: ")
|
print()
|
||||||
if not os.path.exists(f"mysites/{domain}"):
|
sites = your_sites()
|
||||||
print("Не существует такого сайта.")
|
|
||||||
exit()
|
|
||||||
|
|
||||||
conf = read(f"mysites/{domain}/config.json")
|
domain = sites[input('Домен сайта: ')]
|
||||||
type = conf["type"]
|
|
||||||
if type == "dynamic":
|
conf = read(f'mysites/{domain}/config.json')
|
||||||
port = input("Порт сервера: ")
|
type = conf['type']
|
||||||
conf["port"] = port
|
if type == 'dynamic':
|
||||||
write(conf, f"mysites/{domain}/config.json")
|
port = input('Порт сервера: ')
|
||||||
|
conf['port'] = port
|
||||||
|
write(conf, f'mysites/{domain}/config.json')
|
||||||
|
|
||||||
# Обновляем версию
|
# Обновляем версию
|
||||||
conf = read(f"mysites/{domain}/config.json")
|
conf = read(f'mysites/{domain}/config.json')
|
||||||
conf["ver"] = conf["ver"] + 1
|
conf['ver'] = conf['ver'] + 1
|
||||||
write(conf, f"mysites/{domain}/config.json")
|
write(conf, f'mysites/{domain}/config.json')
|
||||||
|
|
||||||
# Архивируем и создаём сигнатуру для подтверждения неизменности архива
|
# Архивируем и создаём сигнатуру для подтверждения неизменности архива
|
||||||
make_archive(f"mysites/{domain}", "zip", f"mysites/{domain}")
|
make_archive(f'mysites/{domain}', 'zip', f'mysites/{domain}')
|
||||||
sign(f"mysites/{domain}.zip", f"mysites/{domain}.key", f"mysites/{domain}")
|
sign(f'mysites/{domain}.zip', f'mysites/{domain}.key', f'mysites/{domain}')
|
||||||
|
|
||||||
elif op == "3":
|
elif op == '3':
|
||||||
from os import rmdir
|
from os import rmdir
|
||||||
|
|
||||||
domain = input("\nДомен сайта: ")
|
print()
|
||||||
if not os.path.exists(f"mysites/{domain}"):
|
sites = your_sites()
|
||||||
print("Не существует такого сайта.")
|
domain = sites[input('Домен сайта: ')]
|
||||||
exit()
|
|
||||||
|
|
||||||
print("\n(1) Статичный / (2) Динамический")
|
print('\n(1) Статичный / (2) Динамический')
|
||||||
type = input("Тип: ")
|
type = input('Тип: ')
|
||||||
|
|
||||||
if type == "1":
|
if type == '1':
|
||||||
conf = read(f"mysites/{domain}/config.json")
|
conf = read(f'mysites/{domain}/config.json')
|
||||||
conf["type"] = "static"
|
conf['type'] = 'static'
|
||||||
conf.pop("port")
|
conf.pop('port')
|
||||||
with open(f"mysites/{domain}/index.html", "w") as f:
|
with open(f'mysites/{domain}/index.html', 'w') as f:
|
||||||
f.write("<h1> Hello jetwork! </h1>")
|
f.write('<h1> Hello jetwork! </h1>')
|
||||||
f.close()
|
f.close()
|
||||||
elif type == "2":
|
elif type == '2':
|
||||||
conf = read(f"mysites/{domain}/config.json")
|
conf = read(f'mysites/{domain}/config.json')
|
||||||
port = input("Порт сервера: ")
|
port = input('Порт сервера: ')
|
||||||
|
|
||||||
clean = input("Удалить все лишние файлы сайта (y/n): ")
|
clean = input('Удалить все лишние файлы сайта (y/n): ')
|
||||||
if clean == "y":
|
if clean == 'y':
|
||||||
# Удаляем папку, сохраняем конфиг и копируем публичный ключ
|
# Удаляем папку, сохраняем конфиг и копируем публичный ключ
|
||||||
rmtree(f"mysites/{domain}")
|
rmtree(f'mysites/{domain}')
|
||||||
sleep(0.1)
|
sleep(0.1)
|
||||||
system(f"mkdir mysites/{domain}")
|
system(f'mkdir mysites/{domain}')
|
||||||
|
|
||||||
conf["type"] = "dynamic"
|
conf['type'] = 'dynamic'
|
||||||
conf["port"] = int(port)
|
conf['port'] = int(port)
|
||||||
write(conf, f"mysites/{domain}/config.json")
|
write(conf, f'mysites/{domain}/config.json')
|
||||||
|
|
||||||
# Обновляем версию
|
# Обновляем версию
|
||||||
conf = read(f"mysites/{domain}/config.json")
|
conf = read(f'mysites/{domain}/config.json')
|
||||||
conf["ver"] = conf["ver"] + 1
|
conf['ver'] = conf['ver'] + 1
|
||||||
write(conf, f"mysites/{domain}/config.json")
|
write(conf, f'mysites/{domain}/config.json')
|
||||||
|
|
||||||
# Архивируем и создаём сигнатуру для подтверждения неизменности архива
|
# Архивируем и создаём сигнатуру для подтверждения неизменности архива
|
||||||
make_archive(f"mysites/{domain}", "zip", f"mysites/{domain}")
|
make_archive(f'mysites/{domain}', 'zip', f'mysites/{domain}')
|
||||||
sign(f"mysites/{domain}.zip", f"mysites/{domain}.key", f"mysites/{domain}")
|
sign(f'mysites/{domain}.zip', f'mysites/{domain}.key', f'mysites/{domain}')
|
||||||
|
|
||||||
elif op == "4":
|
elif op == '4':
|
||||||
domain = input("\nДомен сайта: ")
|
print()
|
||||||
if not os.path.exists(f"mysites/{domain}"):
|
sites = your_sites()
|
||||||
print("Не существует такого сайта.")
|
domain = sites[input('Домен сайта: ')]
|
||||||
exit()
|
|
||||||
|
|
||||||
print("\nВведите ваш порт сервера (при запуске main.py)")
|
serv_port = int( read()['our_port'] )
|
||||||
serv_port = int(input(">> "))
|
http_port = client(serv_port, f'is_{domain}')
|
||||||
http_port = client(serv_port, f"is_{domain}")
|
|
||||||
|
|
||||||
print("\nСтарт вечной раздачи...")
|
print('\nСтарт вечной раздачи...')
|
||||||
while True:
|
while True:
|
||||||
ports = port_check(serv_port)
|
ports = port_check(serv_port)
|
||||||
sleep(1)
|
sleep(1)
|
||||||
for port in tqdm(ports):
|
for port in tqdm(ports):
|
||||||
client(port, f"publish_{domain}<>{http_port}")
|
client(port, f'publish_{domain}<>{http_port}')
|
||||||
sleep(5)
|
sleep(5)
|
||||||
|
|
||||||
elif op == "":
|
host = 'bore.pub'
|
||||||
domain = input("\nДомен сайта: ")
|
# Проверяем тип сайта
|
||||||
if not os.path.exists(f"mysites/{domain}"):
|
type = read(f'mysites//{domain}/config.json')['type']
|
||||||
print("Не существует такого сайта.")
|
# Если динамический - вставляем спец страницу
|
||||||
exit()
|
if type == 'dynamic':
|
||||||
pub = "y"
|
port = read(f'mysites//{domain}/config.json')['port']
|
||||||
|
with open(f'mysites//{domain}/index.html', 'w') as f:
|
||||||
|
f.write(f"<iframe src='http://{host}:{port}' style='position:fixed; top:0; left:0; bottom:0; right:0; width:100%; height:100%; border:none; margin:0; padding:0; overflow:hidden; z-index:999999;'></iframe>")
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
# Копируем файлы из mysites в cached
|
# Копируем файлы из mysites в cached
|
||||||
try:
|
try:
|
||||||
rmtree(f"cached/{domain}")
|
rmtree(f'cached/{domain}')
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
copytree(f"mysites/{domain}", f"cached/{domain}")
|
copytree(f'mysites/{domain}', f'cached/{domain}')
|
||||||
copyfile(f"mysites/{domain}.pem", f"cached/{domain}.pem")
|
copyfile(f'mysites/{domain}.pem', f'cached/{domain}.pem')
|
||||||
copyfile(f"mysites/{domain}.sig", f"cached/{domain}.sig")
|
copyfile(f'mysites/{domain}.sig', f'cached/{domain}.sig')
|
||||||
copyfile(f"mysites/{domain}.zip", f"cached/{domain}.zip")
|
copyfile(f'mysites/{domain}.zip', f'cached/{domain}.zip')
|
||||||
|
|
||||||
|
|
||||||
host = "jetwork.404.mn"
|
if op != '':
|
||||||
# Проверяем тип сайта
|
print('\nОпубликовать сайт?')
|
||||||
type = read(f"cached/{domain}/config.json")["type"]
|
pub = input('y/n >> ')
|
||||||
# Если динамический
|
|
||||||
if type == "dynamic":
|
|
||||||
port = read(f"cached/{domain}/config.json")["port"]
|
|
||||||
with open(f"cached/{domain}/index.html", "w") as f:
|
|
||||||
f.write(f'<iframe src="http://{host}:{port}" style="position:fixed; top:0; left:0; bottom:0; right:0; width:100%; height:100%; border:none; margin:0; padding:0; overflow:hidden; z-index:999999;"></iframe>')
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
|
if pub == 'n':
|
||||||
if op != "":
|
|
||||||
print("Опубликовать сайт?")
|
|
||||||
pub = input("y/n >> ")
|
|
||||||
|
|
||||||
if pub == "n":
|
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
print("Введите ваш порт сервера (при запуске main.py)")
|
print('Введите ваш порт сервера (при запуске main.py)')
|
||||||
serv_port = int(input(">> "))
|
serv_port = int(input('>> '))
|
||||||
http_port = client(serv_port, f"is_{domain}")
|
http_port = client(serv_port, f'is_{domain}')
|
||||||
|
|
||||||
print("Получаем все порты...")
|
print('Получаем все порты...')
|
||||||
ports = port_check(serv_port)
|
ports = port_check(serv_port)
|
||||||
|
|
||||||
print(ports)
|
print(ports)
|
||||||
|
|
||||||
print("Публикуем сайт...")
|
print('Публикуем сайт...')
|
||||||
for port in tqdm(ports):
|
for port in tqdm(ports):
|
||||||
client(port, f"publish_{domain}<>{http_port}")
|
client(port, f'publish_{domain}<>{http_port}')
|
||||||
|
Loading…
Reference in New Issue
Block a user