From 9721cb94633f484b89dab27b235dc03e72b68cbd Mon Sep 17 00:00:00 2001 From: iBelieve Date: Thu, 4 Jul 2024 16:04:03 +0800 Subject: [PATCH] Add custom parameters for online subscription conversion --- .../model/cbi/openclash/config-subscribe-edit.lua | 6 ++++++ luci-app-openclash/po/zh-cn/openclash.zh-cn.po | 6 ++++++ .../root/usr/share/openclash/openclash.sh | 14 ++++++++++++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/luci-app-openclash/luasrc/model/cbi/openclash/config-subscribe-edit.lua b/luci-app-openclash/luasrc/model/cbi/openclash/config-subscribe-edit.lua index 7ea0473502..07e3bda143 100644 --- a/luci-app-openclash/luasrc/model/cbi/openclash/config-subscribe-edit.lua +++ b/luci-app-openclash/luasrc/model/cbi/openclash/config-subscribe-edit.lua @@ -177,6 +177,12 @@ o:value("true", translate("Enable")) o.default = "false" o:depends("sub_convert", "1") +---- custom params +o = s:option(DynamicList, "custom_params", translate("Custom Params")) +o.description = font_red..bold_on..translate("eg: \"rename=\\s+([2-9])[xX]@ (HIGH:$1)\"")..bold_off..font_off +o.rmempty = false +o:depends("sub_convert", "1") + ---- key o = s:option(DynamicList, "keyword", font_red..bold_on..translate("Keyword Match")..bold_off..font_off) o.description = font_red..bold_on..translate("eg: hk or tw&bgp")..bold_off..font_off diff --git a/luci-app-openclash/po/zh-cn/openclash.zh-cn.po b/luci-app-openclash/po/zh-cn/openclash.zh-cn.po index 9cf9ae397d..74bbeed723 100644 --- a/luci-app-openclash/po/zh-cn/openclash.zh-cn.po +++ b/luci-app-openclash/po/zh-cn/openclash.zh-cn.po @@ -2841,6 +2841,12 @@ msgstr "Fake-IP 持久化缓存清理" msgid "No Specify Upload File" msgstr "未选择上传文件" +msgid "Custom Params" +msgstr "自定义参数" + +msgid "eg: \"rename=\\s+([2-9])[xX]@ (HIGH:$1)\"" +msgstr "格式示例:\"rename=\\s+([2-9])[xX]@ (高倍率:$1)\"" + msgid "Use Rule Provider" msgstr "使用规则集" diff --git a/luci-app-openclash/root/usr/share/openclash/openclash.sh b/luci-app-openclash/root/usr/share/openclash/openclash.sh index 421e746812..d38a352e97 100644 --- a/luci-app-openclash/root/usr/share/openclash/openclash.sh +++ b/luci-app-openclash/root/usr/share/openclash/openclash.sh @@ -544,9 +544,18 @@ server_key_match() fi } +convert_custom_param() +{ + if ! (echo "$1" | grep -qE "^\w+=.+$") then + return + fi + local p_name="${1%%=*}" p_value="${1#*=}" + append_custom_params="${append_custom_params}&${p_name}=$(urlencode "$p_value")" +} + sub_info_get() { - 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 + 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 config_get_bool "enabled" "$section" "enabled" "1" config_get "name" "$section" "name" "" config_get "sub_convert" "$section" "sub_convert" "" @@ -627,10 +636,11 @@ sub_info_get() template_path=$custom_template_url fi if [ -n "$template_path" ]; then + config_list_foreach "$section" "custom_params" convert_custom_param template_path_encode=$(urlencode "$template_path") [ -n "$key_match_param" ] && key_match_param="(?i)$(urlencode "$key_match_param")" [ -n "$key_ex_match_param" ] && key_ex_match_param="(?i)$(urlencode "$key_ex_match_param")" - 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" + 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" c_address="$convert_address" else subscribe_url=$address