From db56472b845b12d47f59e63aa8411bdca3a6f004 Mon Sep 17 00:00:00 2001 From: Nick Peng Date: Sun, 12 Feb 2023 23:02:13 +0800 Subject: [PATCH] luci: add ipset-no-speed and nftset-no-speed options. --- .../files/luci/i18n/smartdns.zh-cn.po | 17 +++++- .../luci/model/cbi/smartdns/smartdns.lua | 25 ++++++++ .../luci/files/luci/i18n/smartdns.zh-cn.po | 17 +++++- .../resources/view/smartdns/smartdns.js | 60 ++++++++++++++++++- package/openwrt/files/etc/init.d/smartdns | 6 ++ 5 files changed, 121 insertions(+), 4 deletions(-) diff --git a/package/luci-compat/files/luci/i18n/smartdns.zh-cn.po b/package/luci-compat/files/luci/i18n/smartdns.zh-cn.po index 4641656..a919757 100644 --- a/package/luci-compat/files/luci/i18n/smartdns.zh-cn.po +++ b/package/luci-compat/files/luci/i18n/smartdns.zh-cn.po @@ -231,6 +231,12 @@ msgstr "IPSet名称" msgid "IPset name." msgstr "IPSet名称。" +msgid "Ipset name, Add domain result to ipset when speed check fails." +msgstr "IPset名称,当测速失败时,将查询到的结果添加到对应的IPSet集合中。" + +msgid "ipset name format error, format: [#[4|6]:]ipsetname" +msgstr "IPset名称格式错误,格式:[#[4|6]:]ipsetname" + msgid "If you like this software, please buy me a cup of coffee." msgstr "如果本软件对你有帮助,请给作者加个蛋。" @@ -240,7 +246,7 @@ msgstr "包含配置文件" msgid "" "Include other config files from /etc/smartdns/conf.d or custom path, can be " "downloaded from the download page." -msgstr "包含配置文件,路径为/etc/smartdns/conf.d,或自定义配置文件路径,可以从下载页" +msgstr "包含配置文件,路径为/etc/smartdns/conf.d,或自定义配置文件路径,可以从下载页配置自动下载。" msgid "List of files to download." msgstr "下载的文件列表。" @@ -275,6 +281,15 @@ msgstr "NFTSet名称格式错误,格式:[#[4|6]:[family#table#set]]" msgid "NFTset name, format: [#[4|6]:[family#table#set]]" msgstr "NFTSet名称,格式:[#[4|6]:[family#table#set]]" +msgid "Nftset name, Add domain result to nftset when speed check fails, format: [#[4|6]:[family#table#set]]" +msgstr "NFTset名称,当测速失败时,将查询到的结果添加到对应的NFTSet集合中。" + +msgid "No Speed IPset Name" +msgstr "无速度时IPSet名称" + +msgid "No Speed NFTset Name" +msgstr "无速度时NFTSet名称" + msgid "NOT RUNNING" msgstr "未运行" diff --git a/package/luci-compat/files/luci/model/cbi/smartdns/smartdns.lua b/package/luci-compat/files/luci/model/cbi/smartdns/smartdns.lua index 5f5bbd7..db8826b 100644 --- a/package/luci-compat/files/luci/model/cbi/smartdns/smartdns.lua +++ b/package/luci-compat/files/luci/model/cbi/smartdns/smartdns.lua @@ -211,6 +211,31 @@ o.cfgvalue = function(...) return Flag.cfgvalue(...) or "1" end +---- Ipset no speed. +o = s:taboption("advanced", Value, "ipset_no_speed", translate("No Speed IPset Name"), + translate("Ipset name, Add domain result to ipset when speed check fails.")); +o.rmempty = true; +o.datatype = "hostname"; +o.rempty = true; + +---- NFTset no speed. +o = s:taboption("advanced", Value, "nftset_no_speed", translate("No Speed NFTset Name"), + translate("Nftset name, Add domain result to nftset when speed check fails, format: [#[4|6]:[family#table#set]]")); +o.rmempty = true; +o.datatype = "string"; +o.rempty = true; +function o.validate(self, value) + if (value == "") then + return value + end + + if (value:match("#[4|6]:[a-zA-Z0-9%-_]+#[a-zA-Z0-9%-_]+#[a-zA-Z0-9%-_]+$")) then + return value + end + + return nil, translate("NFTset name format error, format: [#[4|6]:[family#table#set]]") +end + ---- rr-ttl o = s:taboption("advanced", Value, "rr_ttl", translate("Domain TTL"), translate("TTL for all domain result.")) o.rempty = true diff --git a/package/luci/files/luci/i18n/smartdns.zh-cn.po b/package/luci/files/luci/i18n/smartdns.zh-cn.po index ab740b6..0d39cfb 100644 --- a/package/luci/files/luci/i18n/smartdns.zh-cn.po +++ b/package/luci/files/luci/i18n/smartdns.zh-cn.po @@ -255,6 +255,12 @@ msgstr "IPset名称" msgid "IPset name." msgstr "IPSet名称。" +msgid "Ipset name, Add domain result to ipset when speed check fails." +msgstr "IPset名称,当测速失败时,将查询到的结果添加到对应的IPSet集合中。" + +msgid "ipset name format error, format: [#[4|6]:]ipsetname" +msgstr "IPset名称格式错误,格式:[#[4|6]:]ipsetname" + msgid "If you like this software, please buy me a cup of coffee." msgstr "如果本软件对你有帮助,请给作者加个蛋。" @@ -265,7 +271,7 @@ msgid "" "Include other config files from /etc/smartdns/conf.d or custom path, can be " "downloaded from the download page." msgstr "" -"包含配置文件,路径为/etc/smartdns/conf.d,或自定义配置文件路径,可以从下载页" +"包含配置文件,路径为/etc/smartdns/conf.d,或自定义配置文件路径,可以从下载页配置自动下载。" "面配置自动下载。" msgid "List of files to download." @@ -301,6 +307,15 @@ msgstr "NFTSet名称格式错误,格式:[#[4|6]:[family#table#set]]" msgid "NFTset name, format: [#[4|6]:[family#table#set]]" msgstr "NFTSet名称,格式:[#[4|6]:[family#table#set]]" +msgid "Nftset name, Add domain result to nftset when speed check fails, format: [#[4|6]:[family#table#set]]" +msgstr "NFTset名称,当测速失败时,将查询到的结果添加到对应的NFTSet集合中。" + +msgid "No Speed IPset Name" +msgstr "无速度时IPSet名称" + +msgid "No Speed NFTset Name" +msgstr "无速度时NFTSet名称" + msgid "NOT RUNNING" msgstr "未运行" diff --git a/package/luci/files/root/www/luci-static/resources/view/smartdns/smartdns.js b/package/luci/files/root/www/luci-static/resources/view/smartdns/smartdns.js index f41ee2d..4869733 100644 --- a/package/luci/files/root/www/luci-static/resources/view/smartdns/smartdns.js +++ b/package/luci/files/root/www/luci-static/resources/view/smartdns/smartdns.js @@ -277,6 +277,48 @@ return view.extend({ o.rmempty = false; o.default = o.enabled; + // Ipset no speed. + o = s.taboption("advanced", form.Value, "ipset_no_speed", _("No Speed IPset Name"), + _("Ipset name, Add domain result to ipset when speed check fails.")); + o.rmempty = true; + o.datatype = "string"; + o.rempty = true; + o.validate = function (section_id, value) { + if (value == "") { + return true; + } + + var ipset = value.split(",") + for (var i = 0; i < ipset.length; i++) { + if (!ipset[i].match(/^(#[4|6]:)?[a-zA-Z0-9\-_]+$/)) { + return _("ipset name format error, format: [#[4|6]:]ipsetname"); + } + } + + return true; + } + + // NFTset no speed. + o = s.taboption("advanced", form.Value, "nftset_no_speed", _("No Speed NFTset Name"), + _("Nftset name, Add domain result to nftset when speed check fails, format: [#[4|6]:[family#table#set]]")); + o.rmempty = true; + o.datatype = "string"; + o.rempty = true; + o.validate = function (section_id, value) { + if (value == "") { + return true; + } + + var nftset = value.split(",") + for (var i = 0; i < nftset.length; i++) { + if (!nftset[i].match(/^#[4|6]:[a-zA-Z0-9\-_]+#[a-zA-Z0-9\-_]+#[a-zA-Z0-9\-_]+$/)) { + return _("NFTset name format error, format: [#[4|6]:[family#table#set]]"); + } + } + + return true; + } + // rr-ttl; o = s.taboption("advanced", form.Value, "rr_ttl", _("Domain TTL"), _("TTL for all domain result.")); o.rempty = true; @@ -720,8 +762,22 @@ return view.extend({ o = s.taboption("forwarding", form.Value, "ipset_name", _("IPset Name"), _("IPset name.")); o.rmempty = true; - o.datatype = "hostname"; + o.datatype = "string"; o.rempty = true; + o.validate = function (section_id, value) { + if (value == "") { + return true; + } + + var ipset = value.split(",") + for (var i = 0; i < ipset.length; i++) { + if (!ipset[i].match(/^(#[4|6]:)?[a-zA-Z0-9\-_]+$/)) { + return _("ipset name format error, format: [#[4|6]:]ipsetname"); + } + } + + return true; + } o = s.taboption("forwarding", form.Value, "nftset_name", _("NFTset Name"), _("NFTset name, format: [#[4|6]:[family#table#set]]")); o.rmempty = true; @@ -734,7 +790,7 @@ return view.extend({ var nftset = value.split(",") for (var i = 0; i < nftset.length; i++) { - if (!nftset[i].match(/#[4|6]:[a-zA-Z0-9\-_]+#[a-zA-Z0-9\-_]+#[a-zA-Z0-9\-_]+$/)) { + if (!nftset[i].match(/^#[4|6]:[a-zA-Z0-9\-_]+#[a-zA-Z0-9\-_]+#[a-zA-Z0-9\-_]+$/)) { return _("NFTset name format error, format: [#[4|6]:[family#table#set]]"); } } diff --git a/package/openwrt/files/etc/init.d/smartdns b/package/openwrt/files/etc/init.d/smartdns index c50bdbc..f492a1e 100644 --- a/package/openwrt/files/etc/init.d/smartdns +++ b/package/openwrt/files/etc/init.d/smartdns @@ -507,6 +507,12 @@ load_service() config_get auto_set_dnsmasq "$section" "auto_set_dnsmasq" "1" + config_get ipset_no_speed "$section" "ipset_no_speed" "" + [ -z "$ipset_no_speed" ] || conf_append "ipset-no-speed" "$ipset_no_speed" + + config_get nftset_no_speed "$section" "nftset_no_speed" "" + [ -z "$nftset_no_speed" ] || conf_append "nftset-no-speed" "$nftset_no_speed" + config_get rr_ttl "$section" "rr_ttl" "" [ -z "$rr_ttl" ] || conf_append "rr-ttl" "$rr_ttl"