From 20876f43d875aacf64042971f557d384a927a6d5 Mon Sep 17 00:00:00 2001 From: ReturnFI <151555003+ReturnFI@users.noreply.github.com> Date: Thu, 5 Sep 2024 21:50:58 +0000 Subject: [PATCH] modify singbox sub --- core/scripts/singbox/singbox.json | 2 +- core/scripts/singbox/singbox.py | 17 +++++++++++++++-- menu.sh | 4 ++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/core/scripts/singbox/singbox.json b/core/scripts/singbox/singbox.json index 2f9b8aa..46e0350 100644 --- a/core/scripts/singbox/singbox.json +++ b/core/scripts/singbox/singbox.json @@ -96,7 +96,7 @@ "password": "{username}:{password}", "tls": { "enabled": true, - "server_name": "bts.com", + "server_name": "{sni}", "insecure": true } }, diff --git a/core/scripts/singbox/singbox.py b/core/scripts/singbox/singbox.py index 3383ee0..8e7cfac 100644 --- a/core/scripts/singbox/singbox.py +++ b/core/scripts/singbox/singbox.py @@ -18,6 +18,20 @@ CERTFILE = os.getenv('HYSTERIA_CERTFILE') KEYFILE = os.getenv('HYSTERIA_KEYFILE') PORT = int(os.getenv('HYSTERIA_PORT', '3324')) +def load_sni_from_env(): + sni = "bts.com" + try: + with open('/etc/hysteria/.configs.env', 'r') as env_file: + for line in env_file: + if line.startswith('SNI='): + sni = line.strip().split('=')[1] + break + except FileNotFoundError: + print("Warning: /etc/hysteria/.configs.env not found. Using default SNI.") + return sni + +SNI = load_sni_from_env() + RATE_LIMIT = 100 RATE_LIMIT_WINDOW = 60 @@ -102,8 +116,7 @@ def generate_singbox_config(username, ip_version, fragment): config['outbounds'][2]['obfs']['password'] = components['obfs_password'] config['outbounds'][2]['password'] = f"{username}:{components['password']}" - if fragment: - config['outbounds'][2]['tls']['server_name'] = fragment + config['outbounds'][2]['tls']['server_name'] = fragment if fragment else SNI config['outbounds'][0]['outbounds'] = ["auto", hysteria_tag] config['outbounds'][1]['outbounds'] = [hysteria_tag] diff --git a/menu.sh b/menu.sh index 6df4af7..b1a4d0a 100644 --- a/menu.sh +++ b/menu.sh @@ -247,6 +247,10 @@ hysteria2_change_sni_handler() { done python3 $CLI_PATH change-hysteria2-sni --sni "$sni" + + if systemctl is-active --quiet singbox.service; then + systemctl restart singbox.service + fi }