some updates

This commit is contained in:
MoonDev
2025-05-22 21:57:13 +03:00
parent 5d47f71e0a
commit a775fe1c80
15 changed files with 425 additions and 110 deletions

View File

@@ -10,8 +10,11 @@ from fastapi.responses import JSONResponse
import hashlib
import json
import time
import yaml
from pathlib import Path
from utils.get_primary_ip import get_primary_ip
PASSWORD = "<password>"
PASSWORD = "10010055"
@@ -29,11 +32,6 @@ app.add_middleware(
# Static files & UI server
app.mount("/static", StaticFiles(directory="static"), name="static")
# Pydantic model for request payload
class CommandModel(BaseModel):
args: Dict[str, Any]
hash: str # Mandatory hash field
# Show main page
@app.get("/")
async def read_index():
@@ -41,6 +39,51 @@ async def read_index():
html_content = f.read()
return HTMLResponse(content=html_content, status_code=200)
# Pydantic model for request payload
class CommandModel(BaseModel):
args: Dict[str, Any]
hash: str # Mandatory hash field
@app.get("/primary-ip", response_model=None)
def get_config():
return get_primary_ip()
@app.get("/frontend-config", response_model=None)
def get_config(hash: str):
computed_hash = hashlib.sha256( ("frontend_config"+PASSWORD).encode("utf-8")).hexdigest()
# Verify hash
if computed_hash != hash:
raise HTTPException(status_code=401, detail="Invalid hash")
CONFIG_FILE = Path("config/frontend.yaml")
# Checking the existence of the file
if not CONFIG_FILE.exists():
raise HTTPException(status_code=404, detail="Файл frontend.yaml не найден")
try:
# YAML reading and parsing
with open(CONFIG_FILE, "r", encoding="utf-8") as file:
data = yaml.safe_load(file)
# Adding an id
for idx, item in enumerate(data):
item["id"] = idx
return data
except yaml.YAMLError as e:
# YAML parsing error
raise HTTPException(status_code=500, detail=f"Ошибка в формате YAML: {e}")
except Exception as e:
# Any other error
raise HTTPException(status_code=500, detail=f"Внутренняя ошибка сервера: {e}")
# Process actions via POST
@app.post("/action/{name:path}")
async def handle_action(name: str, payload: CommandModel):