Your Name 3 months ago
parent b3c9924e41
commit 9c10835f28

19
db.py

@ -0,0 +1,19 @@
import os
import json
if not os.path.exists('domains.json'):
db = {}
js = json.dumps(db, indent=2)
with open("domains.json", "w") as outfile:
outfile.write(js)
print('Created new domains.json')
def read(file = 'domains.json'):
with open(file, "r", encoding="utf-8") as openfile:
db = json.load(openfile)
return db
def write(db, file = 'domains.json'):
js = json.dumps(db, indent=2, ensure_ascii=False)
with open(file, "w", encoding="utf-8") as outfile:
outfile.write(js)

@ -0,0 +1,23 @@
from re import compile, sub
domains = ['jet', 'mirror', 'org', 'info', 'news', 'me']
def domain_ok(domain):
global domains
if domain.count('.') == 1:
if domain.split('.')[1] in domains:
# ../some => some
# Защита от проверки папок выше, чем нужно и др.
regex = compile('[^a-z0-9.-]')
c_domain = regex.sub('', domain)
if domain == c_domain:
return domain
return False
def domain_list():
global domains
out = ''
for i in domains:
out += f'{i}, '
out = out[:-2]
return out

@ -0,0 +1,52 @@
from fastapi import FastAPI, HTTPException
from uuid import uuid4
app = FastAPI()
# If you don't need domain check (jetwork):
# --- comment
# multi-comments uncomment
from db import *
from domain_check import *
def set_nginx(url: str, port: int):
f = open('/etc/nginx/nginx.conf')
@app.post('/api/create/{domain}/{port}')
def create(domain: str, port: int):
# ---
if domain_ok(domain):
db = read()
if domain not in db:
token = str(uuid4())
db[domain] = token
write(db)
return {'token': token}
else:
raise HTTPException(status_code=400, detail="Domain exist")
else:
raise HTTPException(status_code=400, detail="Bad domain")
# ---
'''
db = read()
if domain not in db:
token = str(uuid4())
db[domain] = token
write(db)
return {'token': token}
else:
raise HTTPException(status_code=400, detail="Domain exist")
'''
@app.post('/api/set/{domain}/{port}/{token}')
def set(domain: str, port: int, token: str):
return 200
@app.post('/api/del/{domain}/{port}/{token}')
def set(domain: str, port: int, token: str):
return 200
if __name__ == '__main__':
import uvicorn
uvicorn.run(app, host='127.0.0.1', port=8000)

@ -0,0 +1,38 @@
user www-data;
worker_processes auto;
pid /run/nginx.pid;
error_log /var/log/nginx/error.log;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/access.log;
gzip on;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
server
{
listen 80;
server_name jet-d.del.pw;
server_name_in_redirect off;
proxy_set_header Host $host:$server_port;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8000;
}}
}
Loading…
Cancel
Save