Skip to content
This repository has been archived by the owner on Aug 19, 2024. It is now read-only.

Commit

Permalink
chore(hy2): rewrite options like upstream (#22)
Browse files Browse the repository at this point in the history
Signed-off-by: Leo Douglas <douglarek@gmail.com>
  • Loading branch information
douglarek authored Nov 5, 2023
1 parent 4e2b905 commit db9bbef
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 81 deletions.
63 changes: 29 additions & 34 deletions htdocs/luci-static/resources/view/homeproxy/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,10 @@ return view.extend({
so = ss.option(form.ListValue, 'type', _('Type'));
so.value('direct', _('Direct'));
so.value('http', _('HTTP'));
if (features.with_quic)
if (features.with_quic) {
so.value('hysteria', _('Hysteria'));
so.value('hysteria2', _('Hysteria2'));
}
so.value('shadowsocks', _('Shadowsocks'));
if (features.with_shadowsocksr)
so.value('shadowsocksr', _('ShadowsocksR'));
Expand All @@ -550,8 +552,6 @@ return view.extend({
so.value('trojan', _('Trojan'));
if (features.with_quic)
so.value('tuic', _('Tuic'));
if (features.with_quic)
so.value('hysteria2', _('Hysteria2'));
if (features.with_wireguard)
so.value('wireguard', _('WireGuard'));
so.value('vless', _('VLESS'));
Expand Down Expand Up @@ -621,7 +621,7 @@ return view.extend({
so.datatype = 'port';
so.depends('type', 'direct');

/* Hysteria config start */
/* Hysteria(2) config start */
so = ss.option(form.ListValue, 'hysteria_protocol', _('Protocol'));
so.value('udp');
/* WeChat-Video / FakeTCP are unsupported by sing-box currently
Expand All @@ -648,8 +648,15 @@ return view.extend({
so.rmempty = false;
so.modalonly = true;

so = ss.option(form.ListValue, 'hysteria_obfs_type', _('Obfuscate type'));
so.value('', _('Disable'));
so.value('salamander', _('Salamander'));
so.depends('type', 'hysteria2');
so.modalonly = true;

so = ss.option(form.Value, 'hysteria_obfs_password', _('Obfuscate password'));
so.depends('type', 'hysteria');
so.depends({'type': 'hysteria2', 'hysteria_obfs_type': /[\s\S]/});
so.modalonly = true;

so = ss.option(form.Value, 'hysteria_down_mbps', _('Max download speed'),
Expand Down Expand Up @@ -683,7 +690,21 @@ return view.extend({
so.default = so.disabled;
so.depends('type', 'hysteria');
so.modalonly = true;
/* Hysteria config end */

so = ss.option(form.ListValue, 'hysteria_network', _('Enabled network'));
so.value('', _('Default'));
so.value('tcp', _('TCP'));
so.value('udp', _('UDP'));
so.default = '';
so.depends('type', 'hysteria2');
so.modalonly = true;

so = ss.option(form.Flag, 'hysteria_brutal_debug', _('Debug Hysteria Brutal CC'),
_('Enable debug information logging for Hysteria Brutal CC.'));
so.default = so.disabled;
so.depends('type', 'hysteria2');
so.modalonly = true;
/* Hysteria(2) config end */

/* Shadowsocks config start */
so = ss.option(form.ListValue, 'shadowsocks_encrypt_method', _('Encrypt method'));
Expand Down Expand Up @@ -848,32 +869,6 @@ return view.extend({
so.modalonly = true;
/* Tuic config end */

/* Hysteria2 config start */
so = ss.option(form.Value, 'hysteria2_obfs_type', _('QUIC traffic obfuscator type'));
so.depends('type', 'hysteria2');
so.default = '';
so.modalonly = true;

so = ss.option(form.Value, 'hysteria2_obfs_password', _('QUIC traffic obfuscator password'));
so.depends('type', 'hysteria2');
so.default = '';
so.modalonly = true;

so = ss.option(form.ListValue, 'hysteria2_network', _('Enabled network'));
so.value('', _('Default'));
so.value('tcp', _('TCP'));
so.value('udp', _('UDP'));
so.default = '';
so.depends('type', 'hysteria2');
so.modalonly = true;

so = ss.option(form.Flag, 'hysteria2_brutal_debug', _('Debug Hysteria Brutal CC'),
_('Enable debug information logging for Hysteria Brutal CC.'));
so.default = so.disabled;
so.depends('type', 'hysteria2');
so.modalonly = true;
/* Hysteria2 config end */

/* VMess / VLESS config start */
so = ss.option(form.ListValue, 'vless_flow', _('Flow'));
so.value('', _('None'));
Expand Down Expand Up @@ -1168,18 +1163,18 @@ return view.extend({
so.default = so.disabled;
so.depends('type', 'http');
so.depends('type', 'hysteria');
so.depends('type', 'hysteria2');
so.depends('type', 'shadowtls');
so.depends('type', 'trojan');
so.depends('type', 'tuic');
so.depends('type', 'hysteria2');
so.depends('type', 'vless');
so.depends('type', 'vmess');
so.validate = function(section_id, value) {
if (section_id) {
var type = this.map.lookupOption('type', section_id)[0].formvalue(section_id);
var tls = this.map.findElement('id', 'cbid.homeproxy.%s.tls'.format(section_id)).firstElementChild;

if (['hysteria', 'shadowtls', 'tuic', 'hysteria2'].includes(type)) {
if (['hysteria', 'hysteria2', 'shadowtls', 'tuic'].includes(type)) {
tls.checked = true;
tls.disabled = true;
} else {
Expand Down Expand Up @@ -1291,7 +1286,7 @@ return view.extend({
so.value('random', _('Random'));
so.value('randomized', _('Randomized'));
so.value('safari', _('Safari'));
so.depends({'tls': '1', 'type': /^((?!hysteria$).)+$/});
so.depends({'tls': '1', 'type': /^((?!hysteria2$).)+$/});
so.validate = function(section_id, value) {
if (section_id) {
let tls_reality = this.map.findElement('id', 'cbid.homeproxy.%s.tls_reality'.format(section_id)).firstElementChild;
Expand Down
64 changes: 29 additions & 35 deletions htdocs/luci-static/resources/view/homeproxy/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,14 @@ return view.extend({
o.value('http', _('HTTP'));
if (features.with_quic) {
o.value('hysteria', _('Hysteria'));
o.value('hysteria2', _('Hysteria2'));
o.value('naive', _('NaïveProxy'));
}
o.value('shadowsocks', _('Shadowsocks'));
o.value('socks', _('Socks'));
o.value('trojan', _('Trojan'));
if (features.with_quic)
o.value('tuic', _('Tuic'));
if (features.with_quic)
o.value('hysteria2', _('Hysteria2'));
o.value('vless', _('VLESS'));
o.value('vmess', _('VMess'));
o.rmempty = false;
Expand Down Expand Up @@ -161,7 +160,7 @@ return view.extend({
}
o.modalonly = true;

/* Hysteria config start */
/* Hysteria(2) config start */
o = s.option(form.ListValue, 'hysteria_protocol', _('Protocol'));
o.value('udp');
/* WeChat-Video / FakeTCP are unsupported by sing-box currently
Expand Down Expand Up @@ -202,8 +201,15 @@ return view.extend({
o.rmempty = false;
o.modalonly = true;

o = s.option(form.ListValue, 'hysteria_obfs_type', _('Obfuscate type'));
o.value('', _('Disable'));
o.value('salamander', _('Salamander'));
o.depends('type', 'hysteria2');
o.modalonly = true;

o = s.option(form.Value, 'hysteria_obfs_password', _('Obfuscate password'));
o.depends('type', 'hysteria');
o.depends({'type': 'hysteria2', 'hysteria_obfs_type': /[\s\S]/});
o.modalonly = true;

o = s.option(form.Value, 'hysteria_recv_window_conn', _('QUIC stream receive window'),
Expand Down Expand Up @@ -232,7 +238,24 @@ return view.extend({
o.default = o.disabled;
o.depends('type', 'hysteria');
o.modalonly = true;
/* Hysteria config end */

o = s.option(form.Flag, 'hysteria_ignore_client_bandwidth', _('Commands the client to use the BBR flow control algorithm instead of Hysteria CC'),
_('Conflict with up_mbps and down_mbps.'));
o.default = o.disabled;
o.depends({'type': 'hysteria2', 'hysteria_down_mbps': '', 'hysteria_up_mbps': ''});
o.modalonly = true;

o = s.option(form.Value, 'hysteria_masquerade', _('HTTP3 server behavior when authentication fails'),
_('A 404 page will be returned if empty.'));
o.depends('type', 'hysteria2');
o.modalonly = true;

o = s.option(form.Flag, 'hysteria_brutal_debug', _('Debug Hysteria Brutal CC'),
_('Enable debug information logging for Hysteria Brutal CC.'));
o.default = s.disabled;
o.depends('type', 'hysteria2');
o.modalonly = true;
/* Hysteria(2) config end */

/* Shadowsocks config */
o = s.option(form.ListValue, 'shadowsocks_encrypt_method', _('Encrypt method'));
Expand Down Expand Up @@ -281,36 +304,6 @@ return view.extend({
o.modalonly = true;
/* Tuic config end */

/* Hysteria2 config start */
o = s.option(form.Value, 'hysteria2_obfs_type', _('QUIC traffic obfuscator type'));
o.default = '';
o.depends('type', 'hysteria2');
o.modalonly = true;

o = s.option(form.Value, 'hysteria2_obfs_password', _('QUIC traffic obfuscator password'));
o.default = '';
o.depends('type', 'hysteria2');
o.modalonly = true;

o = s.option(form.Flag, 'hysteria2_ignore_client_bandwidth', _('Commands the client to use the BBR flow control algorithm instead of Hysteria CC'),
_('Conflict with up_mbps and down_mbps.'));
o.default = o.disabled;
o.depends('type', 'hysteria2');
o.modalonly = true;

o = s.option(form.Value, 'hysteria2_masquerade', _('HTTP3 server behavior when authentication fails'),
_('A 404 page will be returned if empty.'));
o.default = '';
o.depends('type', 'hysteria2');
o.modalonly = true;

o = s.option(form.Flag, 'hysteria2_brutal_debug', _('Debug Hysteria Brutal CC'),
_('Enable debug information logging for Hysteria Brutal CC.'));
o.default = s.disabled;
o.depends('type', 'hysteria2');
o.modalonly = true;
/* Hysteria2 config end */

/* VLESS / VMess config start */
o = s.option(form.ListValue, 'vless_flow', _('Flow'));
o.value('', _('None'));
Expand Down Expand Up @@ -424,6 +417,7 @@ return view.extend({
o.default = o.disabled;
o.depends('type', 'http');
o.depends('type', 'hysteria');
o.depends('type', 'hysteria2');
o.depends('type', 'naive');
o.depends('type', 'trojan');
o.depends('type', 'vless');
Expand All @@ -434,7 +428,7 @@ return view.extend({
var type = this.map.lookupOption('type', section_id)[0].formvalue(section_id);
var tls = this.map.findElement('id', 'cbid.homeproxy.%s.tls'.format(section_id)).firstElementChild;

if (['hysteria', 'tuic'].includes(type)) {
if (['hysteria', 'hysteria2', 'tuic'].includes(type)) {
tls.checked = true;
tls.disabled = true;
} else {
Expand Down
12 changes: 7 additions & 5 deletions root/etc/homeproxy/scripts/generate_client.uc
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,20 @@ function generate_outbound(node) {
/* Direct */
override_address: node.override_address,
override_port: strToInt(node.override_port),
/* Hysteria */
/* Hysteria(2) */
up_mbps: strToInt(node.hysteria_down_mbps),
down_mbps: strToInt(node.hysteria_down_mbps),
obfs: (node.type == 'hysteria2') ? {type: node.hysteria2_obfs_type, password: node.hyseria2_obfs_password} : node.hysteria_obfs_password,
obfs: node.hysteria_obfs_type ? {
type: node.hysteria_obfs_type,
password: node.hysteria_obfs_password
} : node.hysteria_obfs_password,
auth: (node.hysteria_auth_type === 'base64') ? node.hysteria_auth_payload : null,
auth_str: (node.hysteria_auth_type === 'string') ? node.hysteria_auth_payload : null,
recv_window_conn: strToInt(node.hysteria_recv_window_conn),
recv_window: strToInt(node.hysteria_revc_window),
disable_mtu_discovery: strToBool(node.hysteria_disable_mtu_discovery),
network: node.hysteria_network,
brutal_debug: strToBool(node.hysteria_brutal_debug),
/* Shadowsocks */
method: node.shadowsocks_encrypt_method || node.shadowsocksr_encrypt_method,
plugin: node.shadowsocks_plugin,
Expand All @@ -179,9 +184,6 @@ function generate_outbound(node) {
udp_over_stream: strToBool(node.tuic_udp_over_stream),
zero_rtt_handshake: strToBool(node.tuic_enable_zero_rtt),
heartbeat: node.tuic_heartbeat ? (node.tuic_heartbeat + 's') : null,
/* Hysteria2 */
network: node.hysteria2_network,
brutal_debug: strToBool(node.hysteria2_brutal_debug),
/* VLESS / VMess */
flow: node.vless_flow,
alter_id: strToInt(node.vmess_alterid),
Expand Down
15 changes: 8 additions & 7 deletions root/etc/homeproxy/scripts/generate_server.uc
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,17 @@ uci.foreach(uciconfig, uciserver, (cfg) => {
/* Hysteria */
up_mbps: strToInt(cfg.hysteria_up_mbps),
down_mbps: strToInt(cfg.hysteria_down_mbps),
obfs: (cfg.type == 'hysteria2') ? {type: cfg.hyteria2_obfs_type, password: cfg.hysteria2_obfs_password} : cfg.hysteria_obfs_password,
obfs: cfg.hysteria_obfs_type ? {
type: cfg.hysteria_obfs_type,
password: cfg.hysteria_obfs_password
} : cfg.hysteria_obfs_password,
recv_window_conn: strToInt(cfg.hysteria_recv_window_conn),
recv_window_client: strToInt(cfg.hysteria_revc_window_client),
max_conn_client: strToInt(cfg.hysteria_max_conn_client),
disable_mtu_discovery: strToBool(cfg.hysteria_disable_mtu_discovery),
ignore_client_bandwidth: strToBool(cfg.hysteria_ignore_client_bandwidth),
masquerade: cfg.hysteria_masquerade,
brutal_debug: strToBool(cfg.hysteria_brutal_debug),

/* Shadowsocks */
method: (cfg.type === 'shadowsocks') ? cfg.shadowsocks_encrypt_method : null,
Expand All @@ -73,12 +79,7 @@ uci.foreach(uciconfig, uciserver, (cfg) => {
zero_rtt_handshake: strToBool(cfg.tuic_enable_zero_rtt),
heartbeat: cfg.tuic_heartbeat ? (cfg.tuic_heartbeat + 's') : null,

/* hysteria2 */
ignore_client_bandwidth: cfg.hysteria2_ignore_client_bandwidth,
masquerade: cfg.hysteria2_masquerade,
brutal_debug: strToBool(cfg.hysteria2_brutal_debug),

/* HTTP / Hysteria / Socks / Trojan / Tuic / Hysteria2/ VLESS / VMess */
/* HTTP / Hysteria(2) / Socks / Trojan / Tuic / VLESS / VMess */
users: (cfg.type !== 'shadowsocks') ? [
{
name: !(cfg.type in ['http', 'socks']) ? 'cfg-' + cfg['.name'] + '-server' : null,
Expand Down
1 change: 1 addition & 0 deletions root/etc/homeproxy/scripts/update_subscriptions.uc
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ function parse_uri(uri) {
password: url.password ? urldecode(url.password) : null,
hysteria_obfs_type: params.obfs,
hysteria_obfs_password: params['obfs-password'],
hysteria_brutal_debug: params.brutal_debug,
tls: '1',
tls_insecure: params.insecure ? '1' : '0',
tls_sni: params.sni
Expand Down

0 comments on commit db9bbef

Please sign in to comment.