|
@@ -4,6 +4,8 @@ import jwt
|
|
import base64
|
|
import base64
|
|
import hmac
|
|
import hmac
|
|
import hashlib
|
|
import hashlib
|
|
|
|
+import requests
|
|
|
|
+
|
|
|
|
|
|
from datetime import UTC, datetime, timedelta
|
|
from datetime import UTC, datetime, timedelta
|
|
from typing import Optional, Union, List, Dict
|
|
from typing import Optional, Union, List, Dict
|
|
@@ -11,6 +13,7 @@ from typing import Optional, Union, List, Dict
|
|
from open_webui.models.users import Users
|
|
from open_webui.models.users import Users
|
|
|
|
|
|
from open_webui.constants import ERROR_MESSAGES
|
|
from open_webui.constants import ERROR_MESSAGES
|
|
|
|
+from open_webui.config import override_static
|
|
from open_webui.env import WEBUI_SECRET_KEY, TRUSTED_SIGNATURE_KEY
|
|
from open_webui.env import WEBUI_SECRET_KEY, TRUSTED_SIGNATURE_KEY
|
|
|
|
|
|
from fastapi import Depends, HTTPException, Request, Response, status
|
|
from fastapi import Depends, HTTPException, Request, Response, status
|
|
@@ -44,6 +47,36 @@ def verify_signature(payload: str, signature: str) -> bool:
|
|
return False
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
+def get_license_data(app, key):
|
|
|
|
+ if key:
|
|
|
|
+ try:
|
|
|
|
+ res = requests.post(
|
|
|
|
+ "https://api.openwebui.com/api/v1/license",
|
|
|
|
+ json={"key": key, "version": "1"},
|
|
|
|
+ timeout=5,
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ 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)
|
|
|
|
+
|
|
|
|
+ return True
|
|
|
|
+ else:
|
|
|
|
+ print(
|
|
|
|
+ f"License: retrieval issue: {getattr(res, 'text', 'unknown error')}"
|
|
|
|
+ )
|
|
|
|
+ except Exception as ex:
|
|
|
|
+ print(f"License: Uncaught Exception: {ex}")
|
|
|
|
+ return False
|
|
|
|
+
|
|
|
|
+
|
|
bearer_security = HTTPBearer(auto_error=False)
|
|
bearer_security = HTTPBearer(auto_error=False)
|
|
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
|
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
|
|
|
|