Skip to content

Commit a6b8959

Browse files
authored
Add custom parameters for online subscription conversion (#3945)
1 parent 9376e29 commit a6b8959

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

luci-app-openclash/luasrc/model/cbi/openclash/config-subscribe-edit.lua

+6
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ o:value("true", translate("Enable"))
177177
o.default = "false"
178178
o:depends("sub_convert", "1")
179179

180+
---- custom params
181+
o = s:option(DynamicList, "custom_params", translate("Custom Params"))
182+
o.description = font_red..bold_on..translate("eg: \"rename=\\s+([2-9])[xX]@ (HIGH:$1)\"")..bold_off..font_off
183+
o.rmempty = false
184+
o:depends("sub_convert", "1")
185+
180186
---- key
181187
o = s:option(DynamicList, "keyword", font_red..bold_on..translate("Keyword Match")..bold_off..font_off)
182188
o.description = font_red..bold_on..translate("eg: hk or tw&bgp")..bold_off..font_off

luci-app-openclash/po/zh-cn/openclash.zh-cn.po

+6
Original file line numberDiff line numberDiff line change
@@ -2874,6 +2874,12 @@ msgstr "Fake-IP 持久化缓存清理"
28742874
msgid "No Specify Upload File"
28752875
msgstr "未选择上传文件"
28762876

2877+
msgid "Custom Params"
2878+
msgstr "自定义参数"
2879+
2880+
msgid "eg: \"rename=\\s+([2-9])[xX]@ (HIGH:$1)\""
2881+
msgstr "格式示例:\"rename=\\s+([2-9])[xX]@ (高倍率:$1)\""
2882+
28772883
msgid "Use Rule Provider"
28782884
msgstr "使用规则集"
28792885

luci-app-openclash/root/usr/share/openclash/openclash.sh

+12-2
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,18 @@ server_key_match()
367367
fi
368368
}
369369

370+
convert_custom_param()
371+
{
372+
if ! (echo "$1" | grep -qE "^\w+=.+$") then
373+
return
374+
fi
375+
local p_name="${1%%=*}" p_value="${1#*=}"
376+
append_custom_params="${append_custom_params}&${p_name}=$(urlencode "$p_value")"
377+
}
378+
370379
sub_info_get()
371380
{
372-
local section="$1" subscribe_url template_path subscribe_url_param template_path_encode key_match_param key_ex_match_param c_address de_ex_keyword sub_ua
381+
local section="$1" subscribe_url template_path subscribe_url_param template_path_encode key_match_param key_ex_match_param c_address de_ex_keyword sub_ua append_custom_params
373382
config_get_bool "enabled" "$section" "enabled" "1"
374383
config_get "name" "$section" "name" ""
375384
config_get "sub_convert" "$section" "sub_convert" ""
@@ -454,10 +463,11 @@ sub_info_get()
454463
template_path=$custom_template_url
455464
fi
456465
if [ -n "$template_path" ]; then
466+
config_list_foreach "$section" "custom_params" convert_custom_param
457467
template_path_encode=$(urlencode "$template_path")
458468
[ -n "$key_match_param" ] && key_match_param="$(urlencode "(?i)$key_match_param")"
459469
[ -n "$key_ex_match_param" ] && key_ex_match_param="$(urlencode "(?i)$key_ex_match_param")"
460-
subscribe_url_param="?target=clash&new_name=true&url=$subscribe_url&config=$template_path_encode&include=$key_match_param&exclude=$key_ex_match_param&emoji=$emoji&list=false&sort=$sort$udp&scv=$skip_cert_verify&append_type=$node_type&fdn=true$rule_provider"
470+
subscribe_url_param="?target=clash&new_name=true&url=$subscribe_url&config=$template_path_encode&include=$key_match_param&exclude=$key_ex_match_param&emoji=$emoji&list=false&sort=$sort$udp&scv=$skip_cert_verify&append_type=$node_type&fdn=true$rule_provider$append_custom_params"
461471
c_address="$convert_address"
462472
else
463473
subscribe_url=$address

0 commit comments

Comments
 (0)