diff --git a/app/subscription/clash.py b/app/subscription/clash.py index ffda30796..947a52271 100644 --- a/app/subscription/clash.py +++ b/app/subscription/clash.py @@ -1,6 +1,7 @@ import yaml import json from app.templates import render_template +from app.subscription.funcs import grpc_correct_path from config import CLASH_SUBSCRIPTION_TEMPLATE, MUX_TEMPLATE @@ -61,6 +62,8 @@ def make_node(self, ais: bool = '', mux_enable : bool = False): + path = grpc_correct_path(path=path, word="customTunMulti") + if type == 'shadowsocks': type = 'ss' if network == 'tcp' and headers == 'http': diff --git a/app/subscription/funcs.py b/app/subscription/funcs.py new file mode 100644 index 000000000..27aa2ee50 --- /dev/null +++ b/app/subscription/funcs.py @@ -0,0 +1,9 @@ +import re +from typing import List + +def grpc_correct_path(path: str, word: str): + + pattern = r'\b(?:' + re.escape(word) + r'|[|])\b' + path = re.sub(pattern, '', path) + + return path \ No newline at end of file diff --git a/app/subscription/singbox.py b/app/subscription/singbox.py index fb38f8e0e..819ffab93 100644 --- a/app/subscription/singbox.py +++ b/app/subscription/singbox.py @@ -1,5 +1,6 @@ import json from app.templates import render_template +from app.subscription.funcs import grpc_correct_path from config import SINGBOX_SUBSCRIPTION_TEMPLATE, MUX_TEMPLATE @@ -193,6 +194,9 @@ def make_outbound(self, return config def add(self, remark: str, address: str, inbound: dict, settings: dict): + + path = grpc_correct_path(path=inbound["path"], word="customTunMulti") + outbound = self.make_outbound( remark=remark, type=inbound['protocol'], @@ -203,7 +207,7 @@ def add(self, remark: str, address: str, inbound: dict, settings: dict): flow=settings.get('flow', ''), sni=inbound['sni'], host=inbound['host'], - path=inbound['path'], + path=path, alpn=inbound.get('alpn', ''), fp=inbound.get('fp', ''), pbk=inbound.get('pbk', ''), diff --git a/app/subscription/v2ray.py b/app/subscription/v2ray.py index 586473058..d214ccdd4 100644 --- a/app/subscription/v2ray.py +++ b/app/subscription/v2ray.py @@ -4,6 +4,7 @@ from typing import Union from uuid import UUID +from app.subscription.funcs import grpc_correct_path from app.templates import render_template from config import (MUX_TEMPLATE, V2RAY_SUBSCRIPTION_TEMPLATE) @@ -21,6 +22,8 @@ def render(self): def add(self, remark: str, address: str, inbound: dict, settings: dict): + path = grpc_correct_path(path=inbound["path"], word="customTun") + if inbound["protocol"] == "vmess": link = self.vmess( remark=remark, @@ -36,7 +39,7 @@ def add(self, remark: str, address: str, inbound: dict, settings: dict): sid=inbound.get("sid", ""), spx=inbound.get("spx", ""), host=inbound["host"], - path=inbound["path"], + path=path, type=inbound["header_type"], ais=inbound.get("ais", ""), fs=inbound.get("fragment_setting", ""), @@ -59,7 +62,7 @@ def add(self, remark: str, address: str, inbound: dict, settings: dict): sid=inbound.get("sid", ""), spx=inbound.get("spx", ""), host=inbound["host"], - path=inbound["path"], + path=path, type=inbound["header_type"], ais=inbound.get("ais", ""), fs=inbound.get("fragment_setting", ""), @@ -82,7 +85,7 @@ def add(self, remark: str, address: str, inbound: dict, settings: dict): sid=inbound.get("sid", ""), spx=inbound.get("spx", ""), host=inbound["host"], - path=inbound["path"], + path=path, type=inbound["header_type"], ais=inbound.get("ais", ""), fs=inbound.get("fragment_setting", ""), @@ -680,6 +683,7 @@ def add(self, remark: str, address: str, inbound: dict, settings: dict): tls = (inbound['tls']) headers = inbound['header_type'] fragment = inbound['fragment_setting'] + path = grpc_correct_path(path=inbound["path"], word="customTun") outbound = { "tag": remark, @@ -735,7 +739,7 @@ def add(self, remark: str, address: str, inbound: dict, settings: dict): tls=tls, sni=inbound['sni'], host=inbound['host'], - path=inbound['path'], + path=path, alpn=inbound.get('alpn', ''), fp=inbound.get('fp', ''), pbk=inbound.get('pbk', ''), diff --git a/app/xray/config.py b/app/xray/config.py index b1a3c2081..f74ea2399 100644 --- a/app/xray/config.py +++ b/app/xray/config.py @@ -265,11 +265,13 @@ def _resolve_inbounds(self): if isinstance(host, str): settings['host'] = [host] - elif net == 'grpc': + elif net == 'grpc' or net == 'gun': settings['header_type'] = '' settings['path'] = net_settings.get('serviceName', '') settings['host'] = [] settings['multiMode'] = net_settings.get('multiMode', False) + if 'customTunMulti' in settings['path']: + settings['multiMode'] = True elif net == 'quic': settings['header_type'] = net_settings.get('header', {}).get('type', '')