Archived
This commit is contained in:
1 parent
aadc19341d
commit
3841e93e32
13 files changed
+73
-24
No files matched your search
+5
-5
@@ -436,7 +436,7 @@ class NodeSettingsRequest(BaseModel):
|
||||
|
||||
|
||||
class AppSettingsRequest(BaseModel):
|
||||
refresh_seconds: int = Field(default=5, ge=2, le=60)
|
||||
refresh_seconds: int = Field(default=10, ge=2, le=60)
|
||||
online_threshold_seconds: int = Field(default=180, ge=30, le=3600)
|
||||
backup_retention: int = Field(default=20, ge=1, le=200)
|
||||
|
||||
@@ -522,7 +522,7 @@ def is_internal_interface(name: str) -> bool:
|
||||
|
||||
def request_interface(request: Request) -> str:
|
||||
current = getattr(request.state, "current_user", None)
|
||||
access = get_user_access(int(current["id"])) if current else {"role": "admin", "interfaces": []}
|
||||
access = getattr(request.state, "access", None) or (get_user_access(int(current["id"])) if current else {"role": "admin", "interfaces": []})
|
||||
default_iface = (access["interfaces"][0] if access["role"] == "user" and access["interfaces"] else WG_INTERFACE)
|
||||
value = (request.cookies.get("wgtools_interface") or default_iface).strip()
|
||||
if access["role"] == "user" and access["interfaces"] and value not in access["interfaces"]:
|
||||
@@ -580,7 +580,7 @@ def render(request: Request, template: str, page: str, title_key: str) -> HTMLRe
|
||||
"language": language,
|
||||
"messages_json": messages_json,
|
||||
"tr": tr,
|
||||
"current_user": get_user(int(request.session.get("user_id", 0))) if request.session.get("user_id") else None,
|
||||
"current_user": getattr(request.state, "current_user", None),
|
||||
"help_sections": get_help_sections(language) if request.state.access['role'] == 'admin' else [],
|
||||
},
|
||||
headers={"X-Robots-Tag": "noindex, nofollow, noarchive, nosnippet"},
|
||||
@@ -649,9 +649,9 @@ async def require_authentication(request: Request, call_next):
|
||||
if path in PUBLIC_PATHS or path.startswith(PUBLIC_PREFIXES):
|
||||
return await call_next(request)
|
||||
|
||||
users_exist = user_count() > 0
|
||||
user_id = request.session.get("user_id")
|
||||
current = get_user(int(user_id)) if user_id else None
|
||||
users_exist = bool(current) or user_count() > 0
|
||||
if user_id and not current:
|
||||
request.session.clear()
|
||||
if current:
|
||||
@@ -682,7 +682,7 @@ async def require_authentication(request: Request, call_next):
|
||||
return RedirectResponse(url=f"{app_url(request, '/login')}?next={next_path}", status_code=303)
|
||||
|
||||
request.state.current_user = current
|
||||
access = get_user_access(int(current["id"]))
|
||||
access = get_user_access(int(current["id"]), initialize=False)
|
||||
request.state.access = access
|
||||
if access["role"] != "admin":
|
||||
allowed = {"/", "/clients", "/api/interfaces", "/api/snapshot", "/api/metrics/history", "/api/app-settings", "/api/auth/logout", "/api/clients/create", "/api/clients/update", "/api/clients/credentials/rotate", "/api/clients/config", "/api/clients/config/download", "/api/clients/qr", "/api/extended/forwardings", "/api/extended/forwardings/delete"}
|
||||
|
||||
Reference in new issue
Block a user