Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Singbox multiplex & tls_fragment object to configs (client-side) #95

Merged
merged 8 commits into from
Jan 23, 2024
6 changes: 4 additions & 2 deletions hiddifypanel/panel/admin/SettingAdmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ class CategoryForm(FlaskForm):
"config.telegram_lib.description"), default=hconfig(ConfigEnum.telegram_lib))
elif c.key == ConfigEnum.mux_protocol:
choices = [("smux", 'smux'), ("yamux", "yamux"), ("h2mux", "h2mux")]
field = wtf.fields.SelectField(_(f"config.{c.key}.label"), choices=choices, description=_(f"config.{c.key}.description"))
field = wtf.fields.SelectField(_(f"config.{c.key}.label"), choices=choices, description=_(f"config.{c.key}.description"), default=hconfig(c.key))

elif c.key == ConfigEnum.warp_sites:
validators = [wtf.validators.Length(max=2048)]
render_kw = {'class': "ltr", 'maxlength': 2048}
Expand Down Expand Up @@ -274,7 +275,8 @@ class CategoryForm(FlaskForm):
if c.key in [ConfigEnum.tls_fragment_size, ConfigEnum.tls_fragment_sleep, ConfigEnum.tls_padding_length]:
validators.append(wtf.validators.Regexp("^\d+-\d+$", re.IGNORECASE, _("config.Invalid! The pattern is number-number")+f' {c.key}'))
# mux and hysteria validations
if c.key in [ConfigEnum.hysteria_up_mbps, ConfigEnum.hysteria_down_mbps, ConfigEnum.mux_max_connections, ConfigEnum.mux_min_streams, ConfigEnum.mux_max_streams, ConfigEnum.mux_brutal_down_mbps, ConfigEnum.mux_brutal_up_mbps]:
if c.key in [ConfigEnum.hysteria_up_mbps, ConfigEnum.hysteria_down_mbps, ConfigEnum.mux_max_connections, ConfigEnum.mux_min_streams, ConfigEnum.mux_max_streams,
ConfigEnum.mux_brutal_down_mbps, ConfigEnum.mux_brutal_up_mbps]:
validators.append(wtf.validators.Regexp("^\d+$", re.IGNORECASE, _("config.Invalid! it should be a number only")+f' {c.key}'))
for val in validators:
if hasattr(val, "regex"):
Expand Down
1 change: 0 additions & 1 deletion hiddifypanel/panel/hiddify.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,6 @@ def __parse_user_agent(ua):

def is_ssh_password_authentication_enabled():
if os.path.isfile('/etc/ssh/sshd_config'):
content = ''
with open('/etc/ssh/sshd_config', 'r') as f:
for line in f.readlines():
line = line.strip()
Expand Down
51 changes: 44 additions & 7 deletions hiddifypanel/panel/user/link_maker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from flask import g, request, render_template
from ipaddress import IPv4Address, IPv4Address
from ipaddress import IPv4Address, IPv6Address
import enum
from hiddifypanel import hutils
from hiddifypanel.models import *
Expand Down Expand Up @@ -523,6 +523,9 @@ def to_singbox(proxy):

add_singbox_tls(base, proxy)

if g.user_agent.get('is_hiddify') and proxy["proto"] in ['vmess', 'vless', 'trojan']:
add_singbox_tls_tricks(base)

if proxy.get('flow'):
base["flow"] = proxy['flow']
# base["flow-show"] = True
Expand Down Expand Up @@ -567,15 +570,31 @@ def add_hysteria(base, proxy):


def add_singbox_multiplex(base):
return
if not hconfig(ConfigEnum.mux_enable):
return
base['multiplex'] = {
"enabled": True,
"protocol": "h2mux",
"max_connections": 4,
"min_streams": 4,
"max_streams": 0,
"padding": false
"protocol": hconfig(ConfigEnum.mux_protocol),
"padding": hconfig(ConfigEnum.mux_padding_enable)
}
# Conflicts: max_streams with max_connections and min_streams
mux_max_streams = int(hconfig(ConfigEnum.mux_max_streams))
if mux_max_streams and mux_max_streams != 0:
base['multiplex']['max_streams'] = mux_max_streams
else:
base['multiplex']['max_connections'] = int(hconfig(ConfigEnum.mux_max_connections))
base['multiplex']['min_streams'] = int(hconfig(ConfigEnum.mux_min_streams))

add_singbox_tcp_brutal(base)


def add_singbox_tcp_brutal(base):
if 'multiplex' in base:
base['multiplex']['brutal'] = {
"enabled": hconfig(ConfigEnum.mux_brutal_enable),
"up_mbps": int(hconfig(ConfigEnum.mux_brutal_up_mbps)),
"down_mbps": int(hconfig(ConfigEnum.mux_brutal_down_mbps))
}


def add_singbox_udp_over_tcp(base):
Expand Down Expand Up @@ -611,6 +630,24 @@ def add_singbox_tls(base, proxy):
# }


def add_singbox_tls_tricks(base):
if hconfig(ConfigEnum.tls_fragment_enable):
base['tls_fragment'] = {
Iam54r1n4 marked this conversation as resolved.
Show resolved Hide resolved
'enable': True,
'size': hconfig(ConfigEnum.tls_fragment_size),
'sleep': hconfig(ConfigEnum.tls_fragment_sleep)
}
if hconfig(ConfigEnum.tls_padding_enable):
base['tls_tricks'] = {
'padding_size': hconfig(ConfigEnum.tls_padding_length)
}
if hconfig(ConfigEnum.tls_mixed_case):
if 'tls_tricks' not in base:
base['tls_tricks'] = {'mixedcase_sni': True}
else:
base['tls_tricks']['mixedcase_sni'] = True


def add_singbox_transport(base, proxy):
if proxy['l3'] == 'reality' and proxy['transport'] not in ["grpc"]:
return
Expand Down