Skip to content

Commit

Permalink
Add custom parameters for online subscription conversion (#3945)
Browse files Browse the repository at this point in the history
  • Loading branch information
VMatrices authored Jul 4, 2024
1 parent 9376e29 commit a6b8959
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions luci-app-openclash/po/zh-cn/openclash.zh-cn.po
Original file line number Diff line number Diff line change
Expand Up @@ -2874,6 +2874,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 "使用规则集"

Expand Down
14 changes: 12 additions & 2 deletions luci-app-openclash/root/usr/share/openclash/openclash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,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" ""
Expand Down Expand Up @@ -454,10 +463,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="$(urlencode "(?i)$key_match_param")"
[ -n "$key_ex_match_param" ] && key_ex_match_param="$(urlencode "(?i)$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
Expand Down

0 comments on commit a6b8959

Please sign in to comment.