From 4d4cdca4b3282c31e3528cf152c12fa958b42656 Mon Sep 17 00:00:00 2001 From: fodhelper <161948085+fodhelper@users.noreply.github.com> Date: Thu, 4 Apr 2024 02:34:01 +0100 Subject: [PATCH 1/6] Update .env.example --- .env.example | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.env.example b/.env.example index bcef7fc6..e77d5c62 100644 --- a/.env.example +++ b/.env.example @@ -37,6 +37,10 @@ UVICORN_PORT = 8000 # SINGBOX_SUBSCRIPTION_TEMPLATE="singbox/default.json" # MUX_TEMPLATE="mux/default.json" +## Your preferred config type for different client types +# USE_CUSTOM_JSON_FOR_V2RAYN=false +# USE_CUSTOM_JSON_FOR_V2RAYNG=true + ## Set headers for subscription # SUB_PROFILE_TITLE = "Susbcription" # SUB_SUPPORT_URL = "https://t.me/support" From 202bf93c604eb2465a64c6cbe830fd7b9c04bede Mon Sep 17 00:00:00 2001 From: fodhelper <161948085+fodhelper@users.noreply.github.com> Date: Thu, 4 Apr 2024 02:34:12 +0100 Subject: [PATCH 2/6] Update config.py --- config.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config.py b/config.py index fcfc8cc1..fa728e0c 100755 --- a/config.py +++ b/config.py @@ -51,6 +51,9 @@ MUX_TEMPLATE = config("MUX_TEMPLATE", default="mux/default.json") V2RAY_SUBSCRIPTION_TEMPLATE = config("V2RAY_SUBSCRIPTION_TEMPLATE", default="v2ray/default.json") +USE_CUSTOM_JSON_FOR_V2RAYN = config("USE_CUSTOM_JSON_FOR_V2RAYN", default=False, cast=bool) +USE_CUSTOM_JSON_FOR_V2RAYNG = config("USE_CUSTOM_JSON_FOR_V2RAYNG", default=True, cast=bool) + ACTIVE_STATUS_TEXT = config("ACTIVE_STATUS_TEXT", default="Active") EXPIRED_STATUS_TEXT = config("EXPIRED_STATUS_TEXT", default="Expired") LIMITED_STATUS_TEXT = config("LIMITED_STATUS_TEXT", default="Limited") From c0b3d374a6b0050527479f9a3c2dbec2d0ce61a1 Mon Sep 17 00:00:00 2001 From: fodhelper <161948085+fodhelper@users.noreply.github.com> Date: Thu, 4 Apr 2024 02:43:01 +0100 Subject: [PATCH 3/6] Update subscription.py --- app/views/subscription.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/app/views/subscription.py b/app/views/subscription.py index 844d9535..4d438710 100644 --- a/app/views/subscription.py +++ b/app/views/subscription.py @@ -16,7 +16,9 @@ SUB_SUPPORT_URL, SUB_UPDATE_INTERVAL, SUBSCRIPTION_PAGE_TEMPLATE, - XRAY_SUBSCRIPTION_PATH + XRAY_SUBSCRIPTION_PATH, + USE_CUSTOM_JSON_FOR_V2RAYN, + USE_CUSTOM_JSON_FOR_V2RAYNG ) @@ -91,14 +93,23 @@ def get_subscription_user_info(user: UserResponse) -> dict: conf = generate_subscription(user=user, config_format="outline", as_base64=False) return Response(content=conf, media_type="application/json", headers=response_headers) + elif re.match('^v2rayN/(\d+\.\d+)', user_agent): + version_str = re.match('^v2rayN/(\d+\.\d+)', user_agent).group(1) + if LooseVersion(version_str) >= LooseVersion("6.40") and USE_CUSTOM_JSON_FOR_V2RAYN: + conf = generate_subscription(user=user, config_format="v2ray-json", as_base64=False) + return Response(content=conf, media_type="application/json", headers=response_headers) + else: + conf = generate_subscription(user=user, config_format="v2ray", as_base64=True) + return Response(content=conf, media_type="text/plain", headers=response_headers) + elif re.match('^v2rayNG/(\d+\.\d+\.\d+)', user_agent): version_str = re.match('^v2rayNG/(\d+\.\d+\.\d+)', user_agent).group(1) - if LooseVersion(version_str) >= LooseVersion("1.8.16"): + if LooseVersion(version_str) >= LooseVersion("1.8.16") and USE_CUSTOM_JSON_FOR_V2RAYNG: conf = generate_subscription(user=user, config_format="v2ray-json", as_base64=False) return Response(content=conf, media_type="application/json", headers=response_headers) else: conf = generate_subscription(user=user, config_format="v2ray", as_base64=True) - return Response(content=conf, media_type="application/json", headers=response_headers) + return Response(content=conf, media_type="text/plain", headers=response_headers) else: conf = generate_subscription(user=user, config_format="v2ray", as_base64=True) From 4c67192885e7b8fdc166f16f2e600cba33ff6abc Mon Sep 17 00:00:00 2001 From: fodhelper <161948085+fodhelper@users.noreply.github.com> Date: Thu, 4 Apr 2024 02:45:39 +0100 Subject: [PATCH 4/6] Update subscription.py --- app/views/subscription.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/subscription.py b/app/views/subscription.py index 4d438710..26093eb9 100644 --- a/app/views/subscription.py +++ b/app/views/subscription.py @@ -151,7 +151,7 @@ def user_get_usage(token: str, return Response(status_code=204) if start is None: - start_date = datetime.fromtimestamp(datetime.utcnow().timestamp() - 30 * 24 * 3600) + start_date = datetime.utcfromtimestamp(datetime.utcnow().timestamp() - 30 * 24 * 3600) else: start_date = datetime.fromisoformat(start) From d6f2e9ba01046b876ed6d0e37ea133eacf9c56ca Mon Sep 17 00:00:00 2001 From: fodhelper <161948085+fodhelper@users.noreply.github.com> Date: Thu, 4 Apr 2024 03:40:18 +0100 Subject: [PATCH 5/6] Update .env.example --- .env.example | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index e77d5c62..6bdaada9 100644 --- a/.env.example +++ b/.env.example @@ -14,7 +14,7 @@ UVICORN_PORT = 8000 # XRAY_JSON = "xray_config.json" # XRAY_SUBSCRIPTION_URL_PREFIX = "https://example.com" -# XRAY_SUBSCRIPTION_PATH = sub +# XRAY_SUBSCRIPTION_PATH = "sub" # XRAY_EXECUTABLE_PATH = "/usr/local/bin/xray" # XRAY_ASSETS_PATH = "/usr/local/share/xray" # XRAY_EXCLUDE_INBOUND_TAGS = "INBOUND_X INBOUND_Y" @@ -38,8 +38,8 @@ UVICORN_PORT = 8000 # MUX_TEMPLATE="mux/default.json" ## Your preferred config type for different client types -# USE_CUSTOM_JSON_FOR_V2RAYN=false -# USE_CUSTOM_JSON_FOR_V2RAYNG=true +# USE_CUSTOM_JSON_FOR_V2RAYN=False +# USE_CUSTOM_JSON_FOR_V2RAYNG=True ## Set headers for subscription # SUB_PROFILE_TITLE = "Susbcription" @@ -56,8 +56,8 @@ UVICORN_PORT = 8000 # ONHOLD_STATUS_TEXT = "On-Hold" ### for developers -# DOCS=true -# DEBUG=true +# DOCS=True +# DEBUG=True # If You Want To Send Webhook To Multiple Server Add Multi Address # WEBHOOK_ADDRESS = "http://127.0.0.1:9000/,http://127.0.0.1:9001/" From 9844a6e14c4eb927a8d318942edcdb0ae9f37724 Mon Sep 17 00:00:00 2001 From: fodhelper <161948085+fodhelper@users.noreply.github.com> Date: Thu, 4 Apr 2024 04:06:14 +0100 Subject: [PATCH 6/6] Update .env.example --- .env.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 6bdaada9..3f26a375 100644 --- a/.env.example +++ b/.env.example @@ -37,7 +37,7 @@ UVICORN_PORT = 8000 # SINGBOX_SUBSCRIPTION_TEMPLATE="singbox/default.json" # MUX_TEMPLATE="mux/default.json" -## Your preferred config type for different client types +## Your preferred config type for different clients # USE_CUSTOM_JSON_FOR_V2RAYN=False # USE_CUSTOM_JSON_FOR_V2RAYNG=True