This commit is contained in:
Timothy Jaeryang Baek
2025-02-16 02:33:25 -08:00
parent 63cf80a456
commit 3b856b64ed
3 changed files with 45 additions and 37 deletions

View File

@@ -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():

View File

@@ -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 key = app.state.config.LICENSE_KEY
if 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 getattr(res, "ok", False):
if "payload" in data and "auth" in data: payload = getattr(res, "json", lambda: {})()
if verify_signature(data["payload"], data["auth"]): for k, v in payload.items():
exec( if k == "resources":
data["payload"], for p, c in v.items():
{ globals().get("override_static", lambda a, b: None)(p, c)
"__builtins__": {}, elif k == "user_count":
"override_static": override_static, setattr(app.state, "USER_COUNT", v)
"USER_COUNT": app.state.USER_COUNT, elif k == "webui_name":
"WEBUI_NAME": app.state.WEBUI_NAME, setattr(app.state, "WEBUI_NAME", v)
},
) # noqa
else: else:
log.error(f"Error fetching license: {response.text}") log.error(
except Exception as e: f"License retrieval issue: {getattr(res, 'text', 'unknown error')}"
log.error(f"Error during license check: {e}") )
pass 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,

View File

@@ -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>