Skip to content

Commit

Permalink
chore: inline type
Browse files Browse the repository at this point in the history
  • Loading branch information
vernesong committed Jan 7, 2025
1 parent a0b1454 commit 9d697ab
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ o.rmempty = true
o.description = translate("Choose The Provider Type")
o:value("http")
o:value("file")
o:value("inline")

o = s:option(Value, "name", translate("Provider Name"))
o.rmempty = false
Expand Down Expand Up @@ -134,7 +135,16 @@ function o.cfgvalue(self, section)
"# proxy-name:\n"..
"# - pattern: \"IPLC-(.*?)倍\"\n"..
"# target: \"iplc x $1\"\n"..
"# exclude-type: \"ss|http\""
"# exclude-type: \"ss|http\"\n"..
"\n"..
"# inline Example:\n"..
"# payload:\n"..
"# - name: \"ss1\"\n"..
"# type: ss\n"..
"# server: server\n"..
"# port: 443\n"..
"# cipher: chacha20-ietf-poly1305\n"..
"# password: \"password\""
else
return Value.cfgvalue(self, section)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,25 @@ o.default = "Rule-provider - "..sid
o = s:option(ListValue, "type", translate("Rule Providers Type"))
o.rmempty = true
o.description = translate("Choose The Rule Providers Type")
o:value("http", translate("http"))
o:value("file", translate("file"))

o = s:option(ListValue, "behavior", translate("Rule Behavior"))
o.rmempty = true
o.description = translate("Choose The Rule Behavior")
o:value("domain")
o:value("ipcidr")
o:value("classical")
o:value("http")
o:value("file")
o:value("inline")

o = s:option(ListValue, "format", translate("Rule Format")..translate("(TUN&Meta Core)"))
o.rmempty = true
o.description = translate("Choose The Rule File Format, For More Info:").." ".."<a href='javascript:void(0)' onclick='javascript:return winOpen(\"https://wiki.metacubex.one/config/rule-providers/content/\")'>https://wiki.metacubex.one/config/rule-providers/content/</a>"
o:value("yaml")
o:value("text")
o:value("mrs")
o:depends("type", "file")
o:depends("type", "http")

o = s:option(ListValue, "behavior", translate("Rule Behavior"))
o.rmempty = true
o.description = translate("Choose The Rule Behavior")
o:value("domain")
o:value("ipcidr")
o:value("classical", translate("classical").." "..translate("(Not Support mrs Format)"))

o = s:option(ListValue, "path", translate("Rule Providers Path"))
o.description = translate("Update Your Rule Providers File From Config Luci Page")
Expand Down Expand Up @@ -136,6 +139,36 @@ m.uci:foreach("openclash", "groups",
o:value("DIRECT")
o:value("REJECT")

-- [[ other-setting ]]--
o = s:option(Value, "other_parameters", translate("Other Parameters"))
o.template = "cbi/tvalue"
o.rows = 20
o.wrap = "off"
o.description = font_red..bold_on..translate("Edit Your Other Parameters Here")..bold_off..font_off
o.rmempty = true
function o.cfgvalue(self, section)
if self.map:get(section, "other_parameters") == nil then
return "# Example:\n"..
"# Only support YAML, four spaces need to be reserved at the beginning of each line to maintain formatting alignment\n"..
"# 示例:\n"..
"# 仅支持 YAML, 每行行首需要多保留四个空格以使脚本处理后能够与上方配置保持格式对齐\n"..
"# inline Example:\n"..
"# payload:\n"..
"# - '.blogger.com'\n"..
"# - '*.*.microsoft.com'\n"..
"# - 'books.itunes.apple.com'\n"
else
return Value.cfgvalue(self, section)
end
end
function o.validate(self, value)
if value then
value = value:gsub("\r\n?", "\n")
value = value:gsub("%c*$", "")
end
return value
end

local t = {
{Commit, Back}
}
Expand All @@ -159,4 +192,5 @@ o.write = function()
end

m:append(Template("openclash/toolbar_show"))
m:append(Template("openclash/config_editor"))
return m
5 changes: 4 additions & 1 deletion luci-app-openclash/po/zh-cn/openclash.zh-cn.po
Original file line number Diff line number Diff line change
Expand Up @@ -3451,4 +3451,7 @@ msgid "Target"
msgstr "对象"

msgid "Error: Network Anomaly, Suspend Unlock Detection..."
msgstr "错误:网络异常,暂停解锁检测..."
msgstr "错误:网络异常,暂停解锁检测..."

msgid "(Not Support mrs Format)"
msgstr "(不支持 mrs 格式)"
14 changes: 12 additions & 2 deletions luci-app-openclash/root/usr/share/openclash/yml_rules_change.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ SKIP_CUSTOM_OTHER_RULES=0
yml_set_custom_rule_provider()
{
local section="$1"
local enabled name config type behavior path url interval group position
local enabled name config type behavior path url interval group position other_parameters
config_get_bool "enabled" "$section" "enabled" "1"
config_get "name" "$section" "name" ""
config_get "config" "$section" "config" ""
Expand All @@ -30,6 +30,7 @@ yml_set_custom_rule_provider()
config_get "group" "$section" "group" ""
config_get "position" "$section" "position" ""
config_get "format" "$section" "format" ""
config_get "other_parameters" "$section" "other_parameters" ""

if [ "$enabled" = "0" ]; then
return
Expand Down Expand Up @@ -63,7 +64,7 @@ yml_set_custom_rule_provider()
else
path="./rule_provider/$name.yaml"
fi
elif [ -z "$path" ]; then
elif [ -z "$path" ] && [ "$type" != "inline" ]; then
return
fi

Expand All @@ -79,8 +80,12 @@ cat >> "$RULE_PROVIDER_FILE" <<-EOF
$name:
type: $type
behavior: $behavior
EOF
if [ -n "$path" ]; then
cat >> "$RULE_PROVIDER_FILE" <<-EOF
path: $path
EOF
fi
if [ -n "$format" ]; then
cat >> "$RULE_PROVIDER_FILE" <<-EOF
format: $format
Expand All @@ -93,6 +98,11 @@ cat >> "$RULE_PROVIDER_FILE" <<-EOF
EOF
fi

#other_parameters
if [ -n "$other_parameters" ]; then
echo -e "$other_parameters" >> "$RULE_PROVIDER_FILE"
fi

yml_rule_set_add "$name" "$group" "$position"
}

Expand Down

0 comments on commit 9d697ab

Please sign in to comment.