Skip to content

Commit

Permalink
fix(subscription): remove user-agent for sing-box and clash
Browse files Browse the repository at this point in the history
  • Loading branch information
M03ED committed Jul 23, 2024
1 parent 715ead4 commit ff03e3a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 37 deletions.
21 changes: 10 additions & 11 deletions app/subscription/clash.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
from app.subscription.funcs import get_grpc_gun
from app.templates import render_template
from config import (
CLASH_SUBSCRIPTION_TEMPLATE,
GRPC_USER_AGENT_TEMPLATE,
CLASH_SUBSCRIPTION_TEMPLATE,
MUX_TEMPLATE,
USER_AGENT_TEMPLATE
USER_AGENT_TEMPLATE,
)


Expand All @@ -31,13 +30,7 @@ def __init__(self):
else:
self.user_agent_list = []

temp_grpc_user_agent_data = render_template(GRPC_USER_AGENT_TEMPLATE)
grpc_user_agent_data = json.loads(temp_grpc_user_agent_data)

if 'list' in grpc_user_agent_data and isinstance(grpc_user_agent_data['list'], list):
self.grpc_user_agent_data = grpc_user_agent_data['list']
else:
self.grpc_user_agent_data = []
del temp_user_agent_data, user_agent_data

def render(self, reverse=False):
if reverse:
Expand Down Expand Up @@ -96,7 +89,6 @@ def make_node(self,
network = 'http'

remark = self._remark_validation(name)
self.proxy_remarks.append(remark)
node = {
'name': remark,
'type': type,
Expand Down Expand Up @@ -215,15 +207,18 @@ def add(self, remark: str, address: str, inbound: dict, settings: dict):
node['alterId'] = 0
node['cipher'] = 'auto'
self.data['proxies'].append(node)
self.proxy_remarks.append(remark)

if inbound['protocol'] == 'trojan':
node['password'] = settings['password']
self.data['proxies'].append(node)
self.proxy_remarks.append(remark)

if inbound['protocol'] == 'shadowsocks':
node['password'] = settings['password']
node['cipher'] = settings['method']
self.data['proxies'].append(node)
self.proxy_remarks.append(remark)


class ClashMetaConfiguration(ClashConfiguration):
Expand Down Expand Up @@ -301,6 +296,7 @@ def add(self, remark: str, address: str, inbound: dict, settings: dict):
node['alterId'] = 0
node['cipher'] = 'auto'
self.data['proxies'].append(node)
self.proxy_remarks.append(remark)

if inbound['protocol'] == 'vless':
node['uuid'] = settings['id']
Expand All @@ -309,6 +305,7 @@ def add(self, remark: str, address: str, inbound: dict, settings: dict):
node['flow'] = settings.get('flow', '')

self.data['proxies'].append(node)
self.proxy_remarks.append(remark)

if inbound['protocol'] == 'trojan':
node['password'] = settings['password']
Expand All @@ -317,8 +314,10 @@ def add(self, remark: str, address: str, inbound: dict, settings: dict):
node['flow'] = settings.get('flow', '')

self.data['proxies'].append(node)
self.proxy_remarks.append(remark)

if inbound['protocol'] == 'shadowsocks':
node['password'] = settings['password']
node['cipher'] = settings['method']
self.data['proxies'].append(node)
self.proxy_remarks.append(remark)
36 changes: 10 additions & 26 deletions app/subscription/singbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
SINGBOX_SETTINGS_TEMPLATE,
MUX_TEMPLATE,
USER_AGENT_TEMPLATE,
GRPC_USER_AGENT_TEMPLATE,
)


Expand All @@ -27,19 +26,10 @@ def __init__(self):
else:
self.user_agent_list = []

temp_grpc_user_agent_data = render_template(GRPC_USER_AGENT_TEMPLATE)
grpc_user_agent_data = json.loads(temp_grpc_user_agent_data)

if 'list' in grpc_user_agent_data and isinstance(grpc_user_agent_data['list'], list):
self.grpc_user_agent_data = grpc_user_agent_data['list']
else:
self.grpc_user_agent_data = []


temp_settings = render_template(SINGBOX_SETTINGS_TEMPLATE)
self.settings = json.loads(temp_settings)

del temp_user_agent_data, user_agent_data, temp_grpc_user_agent_data, grpc_user_agent_data, temp_settings
del temp_user_agent_data, user_agent_data, temp_settings

def _remark_validation(self, remark):
if not remark in self.proxy_remarks:
Expand Down Expand Up @@ -147,17 +137,11 @@ def ws_config(self, host='', path='', random_user_agent: bool = False,

return config

def grpc_config(self, path='', random_user_agent: bool = False):
config = self.settings.get("grpcSettings", {
"headers": {}
})
if "headers" not in config:
config["headers"] = {}
def grpc_config(self, path=''):
config = self.settings.get("grpcSettings", {})

if path:
config["service_name"] = path
if random_user_agent:
config["headers"]["User-Agent"] = choice(self.grpc_user_agent_data)

return config

Expand All @@ -182,7 +166,8 @@ def transport_config(self,
path='',
max_early_data=None,
early_data_header_name=None,
random_user_agent: bool = False):
random_user_agent: bool = False,
):

transport_config = {}

Expand All @@ -191,7 +176,7 @@ def transport_config(self,
transport_config = self.http_config(
host=host,
path=path,
random_user_agent=random_user_agent
random_user_agent=random_user_agent,
)

elif transport_type == "ws":
Expand All @@ -200,19 +185,18 @@ def transport_config(self,
path=path,
random_user_agent=random_user_agent,
max_early_data=max_early_data,
early_data_header_name=early_data_header_name
early_data_header_name=early_data_header_name,
)

elif transport_type == "grpc":
transport_config = self.grpc_config(
path=path,
random_user_agent=random_user_agent)
transport_config = self.grpc_config(path=path)

elif transport_type == "httpupgrade":
transport_config = self.httpupgrade_config(
host=host,
path=path,
random_user_agent=random_user_agent)
random_user_agent=random_user_agent,
)

transport_config['type'] = transport_type
return transport_config
Expand Down

0 comments on commit ff03e3a

Please sign in to comment.