Timothy Jaeryang Baek 2 月之前
父節點
當前提交
3b856b64ed
共有 3 個文件被更改,包括 45 次插入37 次删除
  1. 16 0
      backend/open_webui/config.py
  2. 21 31
      backend/open_webui/main.py
  3. 8 6
      src/lib/components/admin/Settings/General.svelte

+ 16 - 0
backend/open_webui/config.py

@@ -2,6 +2,8 @@ import json
 import logging
 import logging
 import os
 import os
 import shutil
 import shutil
+import base64
+
 from datetime import datetime
 from datetime import datetime
 from pathlib import Path
 from pathlib import Path
 from typing import Generic, Optional, TypeVar
 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()
 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"
 frontend_favicon = FRONTEND_BUILD_DIR / "static" / "favicon.png"
 
 
 if frontend_favicon.exists():
 if frontend_favicon.exists():

+ 21 - 31
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.models.users import UserModel, Users
 
 
 from open_webui.config import (
 from open_webui.config import (
+    override_static,
     LICENSE_KEY,
     LICENSE_KEY,
     # Ollama
     # Ollama
     ENABLE_OLLAMA_API,
     ENABLE_OLLAMA_API,
@@ -372,47 +373,36 @@ async def lifespan(app: FastAPI):
     if RESET_CONFIG_ON_START:
     if RESET_CONFIG_ON_START:
         reset_config()
         reset_config()
 
 
-    license_key = app.state.config.LICENSE_KEY
-    if license_key:
+    key = app.state.config.LICENSE_KEY
+    if key:
         try:
         try:
-            response = requests.post(
+            res = requests.post(
                 "https://api.openwebui.com/api/v1/license",
                 "https://api.openwebui.com/api/v1/license",
-                json={"key": license_key, "version": "1"},
+                json={"key": key, "version": "1"},
                 timeout=5,
                 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:
             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())
     asyncio.create_task(periodic_usage_pool_cleanup())
     yield
     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(
 app = FastAPI(
     docs_url="/docs" if ENV == "dev" else None,
     docs_url="/docs" if ENV == "dev" else None,
     openapi_url="/openapi.json" if ENV == "dev" else None,
     openapi_url="/openapi.json" if ENV == "dev" else None,

+ 8 - 6
src/lib/components/admin/Settings/General.svelte

@@ -157,7 +157,7 @@
 							</div>
 							</div>
 
 
 							<button
 							<button
-								class=" text-xs px-3 py-1.5 bg-gray-100 hover:bg-gray-200 dark:bg-gray-850 dark:hover:bg-gray-800 transition rounded-lg font-medium"
+								class=" text-xs px-3 py-1.5 bg-gray-50 hover:bg-gray-100 dark:bg-gray-850 dark:hover:bg-gray-800 transition rounded-lg font-medium"
 								type="button"
 								type="button"
 								on:click={() => {
 								on:click={() => {
 									checkForVersionUpdates();
 									checkForVersionUpdates();
@@ -216,24 +216,26 @@
 
 
 					<div class="mb-2.5">
 					<div class="mb-2.5">
 						<div class="flex w-full justify-between items-center">
 						<div class="flex w-full justify-between items-center">
-							<div class="text-xs">
+							<div class="text-xs pr-2">
 								<div class="">
 								<div class="">
 									{$i18n.t('License')}
 									{$i18n.t('License')}
 								</div>
 								</div>
 								<a
 								<a
-									class=" text-xs text-gray-500 underline"
+									class=" text-xs text-gray-500 hover:underline"
 									href="https://docs.openwebui.com/enterprise"
 									href="https://docs.openwebui.com/enterprise"
 									target="_blank"
 									target="_blank"
 								>
 								>
 									{$i18n.t(
 									{$i18n.t(
-										'Upgrade to a licensed plan for enhanced capabilities and dedicated support.'
+										'Upgrade to a licensed plan for enhanced capabilities, including custom theming and branding, and dedicated support.'
 									)}
 									)}
 								</a>
 								</a>
 							</div>
 							</div>
 
 
-							<!-- <button class=" text-xs font-medium">
+							<button
+								class="flex-shrink-0 text-xs px-3 py-1.5 bg-gray-50 hover:bg-gray-100 dark:bg-gray-850 dark:hover:bg-gray-800 transition rounded-lg font-medium"
+							>
 								{$i18n.t('Activate')}
 								{$i18n.t('Activate')}
-							</button> -->
+							</button>
 						</div>
 						</div>
 					</div>
 					</div>
 				</div>
 				</div>