diff --git a/backend/open_webui/config.py b/backend/open_webui/config.py index 039602654..08d719162 100644 --- a/backend/open_webui/config.py +++ b/backend/open_webui/config.py @@ -2,6 +2,8 @@ import json import logging import os import shutil +import base64 + from datetime import datetime from pathlib import Path from typing import Generic, Optional, TypeVar @@ -586,6 +588,20 @@ load_oauth_providers() STATIC_DIR = Path(os.getenv("STATIC_DIR", OPEN_WEBUI_DIR / "static")).resolve() + +def override_static(path: str, content: str): + # Ensure path is safe + if "/" in path or ".." in path: + log.error(f"Invalid path: {path}") + return + + file_path = os.path.join(STATIC_DIR, path) + os.makedirs(os.path.dirname(file_path), exist_ok=True) + + with open(file_path, "wb") as f: + f.write(base64.b64decode(content)) # Convert Base64 back to raw binary + + frontend_favicon = FRONTEND_BUILD_DIR / "static" / "favicon.png" if frontend_favicon.exists(): diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index f952418e2..b45f192cc 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -88,6 +88,7 @@ from open_webui.models.models import Models from open_webui.models.users import UserModel, Users from open_webui.config import ( + override_static, LICENSE_KEY, # Ollama ENABLE_OLLAMA_API, @@ -372,47 +373,36 @@ async def lifespan(app: FastAPI): if RESET_CONFIG_ON_START: reset_config() - license_key = app.state.config.LICENSE_KEY - if license_key: + key = app.state.config.LICENSE_KEY + if key: try: - response = requests.post( + res = requests.post( "https://api.openwebui.com/api/v1/license", - json={"key": license_key, "version": "1"}, + json={"key": key, "version": "1"}, timeout=5, ) - if response.ok: - data = response.json() - if "payload" in data and "auth" in data: - if verify_signature(data["payload"], data["auth"]): - exec( - data["payload"], - { - "__builtins__": {}, - "override_static": override_static, - "USER_COUNT": app.state.USER_COUNT, - "WEBUI_NAME": app.state.WEBUI_NAME, - }, - ) # noqa + + if getattr(res, "ok", False): + payload = getattr(res, "json", lambda: {})() + for k, v in payload.items(): + if k == "resources": + for p, c in v.items(): + globals().get("override_static", lambda a, b: None)(p, c) + elif k == "user_count": + setattr(app.state, "USER_COUNT", v) + elif k == "webui_name": + setattr(app.state, "WEBUI_NAME", v) else: - log.error(f"Error fetching license: {response.text}") - except Exception as e: - log.error(f"Error during license check: {e}") - pass + log.error( + f"License retrieval issue: {getattr(res, 'text', 'unknown error')}" + ) + except Exception as ex: + log.error(f"Uncaught Exception: {ex}") asyncio.create_task(periodic_usage_pool_cleanup()) yield -def override_static(path: str, content: str): - # Ensure path is safe - if "/" in path: - log.error(f"Invalid path: {path}") - return - - with open(f"{STATIC_DIR}/{path}", "wb") as f: - shutil.copyfileobj(content, f) - - app = FastAPI( docs_url="/docs" if ENV == "dev" else None, openapi_url="/openapi.json" if ENV == "dev" else None, diff --git a/src/lib/components/admin/Settings/General.svelte b/src/lib/components/admin/Settings/General.svelte index f69ca039b..0876cdba5 100644 --- a/src/lib/components/admin/Settings/General.svelte +++ b/src/lib/components/admin/Settings/General.svelte @@ -157,7 +157,7 @@