Skip to content

Commit

Permalink
feat: support gRPC Custom Path
Browse files Browse the repository at this point in the history
  • Loading branch information
M03ED committed Apr 30, 2024
1 parent 41ae408 commit dae8eb8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
3 changes: 3 additions & 0 deletions app/subscription/clash.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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':
Expand Down
9 changes: 9 additions & 0 deletions app/subscription/funcs.py
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion app/subscription/singbox.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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'],
Expand All @@ -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', ''),
Expand Down
12 changes: 8 additions & 4 deletions app/subscription/v2ray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -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", ""),
Expand All @@ -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", ""),
Expand All @@ -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", ""),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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', ''),
Expand Down
4 changes: 3 additions & 1 deletion app/xray/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', '')
Expand Down

0 comments on commit dae8eb8

Please sign in to comment.