Archived
Simplify DDNS flow and polish UI
This commit is contained in:
1 parent
5beee0e5c6
commit
5a90bd9d87
42 files changed
+587
-1418
No files matched your search
@@ -1,11 +1,9 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import secrets
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Request
|
||||
from fastapi.responses import PlainTextResponse
|
||||
|
||||
from ..dependencies import ServiceDep, SettingsDep, StoreDep, apply_update_response, authenticate_update
|
||||
from ..dependencies import ServiceDep, StoreDep, apply_update_response, authenticate_update
|
||||
from .path_params import UpdateSlugPath
|
||||
|
||||
router = APIRouter()
|
||||
@@ -25,13 +23,14 @@ def slug_update(
|
||||
account = store.get_account_by_slug(update_slug)
|
||||
if not account or account["disabled"]:
|
||||
raise HTTPException(status_code=404, detail="not found")
|
||||
if not service.hostname_is_managed(str(account["hostname"])):
|
||||
raise HTTPException(status_code=404, detail="not found")
|
||||
return apply_update_response(service, request, str(account["hostname"]), myip, ipaddr, myipv6, ip6addr)
|
||||
|
||||
|
||||
@router.get("/nic/update", response_class=PlainTextResponse, response_model=None)
|
||||
def update(
|
||||
request: Request,
|
||||
settings: SettingsDep,
|
||||
store: StoreDep,
|
||||
service: ServiceDep,
|
||||
credentials: tuple[str | None, str | None] = Depends(authenticate_update),
|
||||
@@ -45,17 +44,10 @@ def update(
|
||||
host = (hostname or domain or "").strip().lower().rstrip(".")
|
||||
if not host:
|
||||
return PlainTextResponse("nohost", status_code=400)
|
||||
if settings.allowed_hosts and host not in settings.allowed_hosts:
|
||||
if not service.hostname_is_managed(host):
|
||||
return PlainTextResponse("nohost", status_code=403)
|
||||
supplied_user, supplied_token = credentials
|
||||
account_ok = store.verify_account(host, supplied_user, supplied_token)
|
||||
global_secret_ok = (
|
||||
bool(settings.allowed_hosts)
|
||||
and host in settings.allowed_hosts
|
||||
and bool(settings.shared_secret)
|
||||
and bool(supplied_token)
|
||||
and secrets.compare_digest(supplied_token, settings.shared_secret)
|
||||
)
|
||||
if not global_secret_ok and not account_ok:
|
||||
if not account_ok:
|
||||
return PlainTextResponse("badauth", status_code=401)
|
||||
return apply_update_response(service, request, host, myip, ipaddr, myipv6, ip6addr)
|
||||
Reference in new issue
Block a user