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

View File

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

View File

@ -157,7 +157,7 @@
</div>
<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"
on:click={() => {
checkForVersionUpdates();
@ -216,24 +216,26 @@
<div class="mb-2.5">
<div class="flex w-full justify-between items-center">
<div class="text-xs">
<div class="text-xs pr-2">
<div class="">
{$i18n.t('License')}
</div>
<a
class=" text-xs text-gray-500 underline"
class=" text-xs text-gray-500 hover:underline"
href="https://docs.openwebui.com/enterprise"
target="_blank"
>
{$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>
</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')}
</button> -->
</button>
</div>
</div>
</div>