From d1f7e4d3359a150d0030faf14e1a6bab763bc08d Mon Sep 17 00:00:00 2001 From: Nick Peng Date: Sat, 30 Dec 2023 01:04:58 +0800 Subject: [PATCH] luci: add ip-rule config tabs. --- .../files/luci/i18n/smartdns.zh-cn.po | 58 +++++++++++++++ .../luci/model/cbi/smartdns/smartdns.lua | 72 +++++++++++++++++-- .../luci/files/luci/i18n/smartdns.zh-cn.po | 6 ++ .../resources/view/smartdns/smartdns.js | 62 +++++++++------- package/openwrt/files/etc/init.d/smartdns | 8 +++ 5 files changed, 174 insertions(+), 32 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 6f65c9f3e8..7ae39e6c89 100644 --- a/package/luci-compat/files/luci/i18n/smartdns.zh-cn.po +++ b/package/luci-compat/files/luci/i18n/smartdns.zh-cn.po @@ -6,6 +6,10 @@ msgid "" "Additional Flags for rules, read help on domain-rule for more information." msgstr "额外的规则标识,具体参考domain-rule的帮助说明。" +msgid "" +"Additional Flags for rules, read help on ip-rule for more information." +msgstr "额外的规则标识,具体参考ip-rule的帮助说明。" + msgid "Additional Rule Flag" msgstr "额外规则标识" @@ -47,6 +51,15 @@ msgstr "绑定到设备" msgid "Bind Device Name" msgstr "绑定的设备名称" +msgid "Bogus nxdomain" +msgstr "假冒IP" + +msgid "Blacklist IP" +msgstr "黑名单" + +msgid "Blacklist IP Rule, Decline IP addresses within the range." +msgstr "黑名单规则,拒绝指定范围的IP地址。" + msgid "Block domain" msgstr "屏蔽域名" @@ -79,6 +92,9 @@ msgstr "配置分流域名列表" msgid "Custom Settings" msgstr "自定义设置" +msgid "Do not use these IP addresses." +msgstr "忽略这些IP地址" + msgid "DOH Server" msgstr "DOH服务器" @@ -316,12 +332,42 @@ msgstr "授予访问 LuCI 应用 smartdns 的权限" msgid "HTTP Host" msgstr "HTTP主机" +msgid "IP alias" +msgstr "IP别名" + +msgid "IP Alias Setting" +msgstr "IP别名设置" + msgid "IP Blacklist" msgstr "IP黑名单" msgid "IP Blacklist Filtering" msgstr "IP黑名单过滤" +msgid "IP Addresses" +msgstr "IP地址" + +msgid "IP Address Mapping, Can be used for CDN acceleration with Anycast IP, such as Cloudflare's CDN." +msgstr "IP地址映射,可用于支持AnyCast IP的CDN加速,比如Cloudflare的CDN。" + +msgid "Ignore IP" +msgstr "忽略IP" + +msgid "IP Rules" +msgstr "IP规则" + +msgid "IP Rules Settings" +msgstr "IP规则设置" + +msgid "IP Rule Name" +msgstr "IP规则名称" + +msgid "IP Set File" +msgstr "IP集合列表文件" + +msgid "IP addresses, CIDR format." +msgstr "IP地址,CIDR格式。" + msgid "IPV6 Server" msgstr "IPV6服务器" @@ -452,6 +498,9 @@ msgstr "设置返回给客户端的域名TTL最大值。" msgid "Report bugs" msgstr "报告BUG" +msgid "Return SOA when the requested result contains a specified IP address." +msgstr "当结果包含对应范围的IP时,返回SOA。" + msgid "Resolve Local Hostnames" msgstr "解析本地主机名" @@ -680,6 +729,9 @@ msgstr "上传域名列表文件,或在下载文件设置页面设置自动下 msgid "Upload domain list file." msgstr "上传域名列表文件" +msgid "Upload IP set file." +msgstr "上传IP集合列表文件。" + msgid "Upload smartdns config file to /etc/smartdns/conf.d" msgstr "上传配置文件到/etc/smartdns/conf.d" @@ -710,6 +762,12 @@ msgstr "" "用于校验 TLS 服务器的有效性,数值为 Base64 编码的 SPKI 指纹,留空表示不验证 " "TLS 的合法性。" +msgid "Whitelist IP" +msgstr "白名单" + +msgid "Whitelist IP Rule, Accept IP addresses within the range." +msgstr "白名单规则,接受指定范围的IP地址。" + msgid "Write cache to disk on exit and load on startup." msgstr "退出时保存cache到磁盘,启动时加载。" 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 82ddd6fa8b..62430ce36f 100644 --- a/package/luci-compat/files/luci/model/cbi/smartdns/smartdns.lua +++ b/package/luci-compat/files/luci/model/cbi/smartdns/smartdns.lua @@ -612,6 +612,7 @@ s.nodescriptions = true s:tab("forwarding", translate('DNS Forwarding Setting')) s:tab("block", translate("DNS Block Setting")) s:tab("domain-address", translate("Domain Address"), translate("Set Specific domain ip address.")) +s:tab("ip-alias", translate('IP Alias Setting')) s:tab("blackip-list", translate("IP Blacklist"), translate("Set Specific ip blacklist.")) ---- domain forwarding; @@ -735,7 +736,7 @@ function o.write(self, section, value) end -- Doman addresss -addr = s:taboption("domain-address", Value, "address", +addr = s:taboption("domain-address", Value, "dummy_address", translate(""), translate("Specify an IP address to return for any host in the given domains, Queries in the domains are never forwarded and always replied to with the specified IP address which may be IPv4 or IPv6.")) @@ -751,10 +752,71 @@ function addr.write(self, section, value) nixio.fs.writefile("/etc/smartdns/address.conf", value) end +---- ip rules; +s = m:section(TypedSection, "ip-rule", translate("IP Rules"), translate("IP Rules Settings")) +s.anonymous = true +s.nodescriptions = true + +s:tab("ip-alias", translate('IP Alias Setting')) +s:tab("blackip-list", translate("IP Blacklist"), translate("Set Specific ip blacklist.")) + +-- enable flag; +o = s:taboption("ip-alias", Flag, "enabled", translate("Enable"), translate("Enable")); +o.rmempty = false; +o.default = o.enabled; +o.editable = true; + +-- name; +o = s:taboption("ip-alias", Value, "name", translate("IP Rule Name"), translate("IP Rule Name")); +o.rmempty = true; +o.datatype = "string"; + +o = s:taboption("ip-alias", FileUpload, "ip_set_file", translate("IP Set File"), translate("Upload IP set file.")); +o.rmempty = true +o.datatype = "file" +o.modalonly = true; +o.root_directory = "/etc/smartdns/ip-set" + +o = s:taboption("ip-alias", DynamicList, "ip_addr", translate("IP Addresses"), translate("IP addresses, CIDR format.")); +o.rmempty = true; +o.datatype = "ipaddr" +o.modalonly = true; + +o = s:taboption("ip-alias", Flag, "whitelist_ip", translate("Whitelist IP"), translate("Whitelist IP Rule, Accept IP addresses within the range.")); +o.rmempty = true; +o.default = o.disabled; +o.modalonly = true; + +o = s:taboption("ip-alias", Flag, "blacklist_ip", translate("Blacklist IP"), translate("Blacklist IP Rule, Decline IP addresses within the range.")); +o.rmempty = true; +o.default = o.disabled; +o.modalonly = true; + +o = s:taboption("ip-alias", Flag, "ignore_ip", translate("Ignore IP"), translate("Do not use these IP addresses.")); +o.rmempty = true; +o.default = o.disabled; +o.modalonly = true; + +o = s:taboption("ip-alias", Flag, "bogus_nxdomain", translate("Bogus nxdomain"), translate("Return SOA when the requested result contains a specified IP address.")); +o.rmempty = true; +o.default = o.disabled; +o.modalonly = true; + +o = s:taboption("ip-alias", DynamicList, "ip_alias", translate("IP alias"), translate("IP Address Mapping, Can be used for CDN acceleration with Anycast IP, such as Cloudflare's CDN.")); +o.rmempty = true; +o.datatype = 'ipaddr("nomask")'; +o.modalonly = true; + +-- other args +o = s:taboption("ip-alias", Value, "addition_flag", translate("Additional Rule Flag"), translate("Additional Flags for rules, read help on ip-rule for more information.")) +o.default = "" +o.rempty = true +o.modalonly = true; + -- IP Blacklist -addr = s:taboption("blackip-list", Value, "blacklist_ip", - translate(""), - translate("Configure IP blacklists that will be filtered from the results of specific DNS server.")) +addr = s:taboption("blackip-list", Value, "dummy_blacklist_ip", + translate(""), + translate("Configure IP blacklists that will be filtered from the results of specific DNS server.")) addr.template = "cbi/tvalue" addr.rows = 20 @@ -764,7 +826,7 @@ function addr.cfgvalue(self, section) end function addr.write(self, section, value) - value = value:gsub("\r\n?", "\n") + -- value = value:gsub("\r\n?", "\n") nixio.fs.writefile("/etc/smartdns/blacklist-ip.conf", value) end diff --git a/package/luci/files/luci/i18n/smartdns.zh-cn.po b/package/luci/files/luci/i18n/smartdns.zh-cn.po index d6d3310b6e..e9f7711688 100644 --- a/package/luci/files/luci/i18n/smartdns.zh-cn.po +++ b/package/luci/files/luci/i18n/smartdns.zh-cn.po @@ -356,6 +356,12 @@ msgstr "IP地址映射,可用于支持AnyCast IP的CDN加速,比如Cloudflar msgid "Ignore IP" msgstr "忽略IP" +msgid "IP Rules" +msgstr "IP规则" + +msgid "IP Rules Settings" +msgstr "IP规则设置" + msgid "IP Rule List" msgstr "IP规则列表" 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 0a0f20bace..ddf52d0a22 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 @@ -915,9 +915,7 @@ return view.extend({ s.tab("forwarding", _('DNS Forwarding Setting')); s.tab("block", _("DNS Block Setting")); s.tab("domain-rule-list", _("Domain Rule List"), _("Set Specific domain rule list.")); - s.tab("ip-rule-list", _("IP Rule List"), _("Set Specific ip rule list.")); s.tab("domain-address", _("Domain Address"), _("Set Specific domain ip address.")); - s.tab("blackip-list", _("IP Blacklist"), _("Set Specific ip blacklist.")); /////////////////////////////////////// // domain forwarding; @@ -1204,25 +1202,6 @@ return view.extend({ so.rempty = true so.modalonly = true; - /////////////////////////////////////// - // IP Blacklist; - /////////////////////////////////////// - // blacklist; - o = s.taboption("blackip-list", form.TextValue, "blackip_ip_conf", - "", _("Configure IP blacklists that will be filtered from the results of specific DNS server.")); - o.rows = 20; - o.cfgvalue = function (section_id) { - return fs.trimmed('/etc/smartdns/blacklist-ip.conf'); - }; - o.write = function (section_id, formvalue) { - return this.cfgvalue(section_id).then(function (value) { - if (value == formvalue) { - return - } - return fs.write('/etc/smartdns/blacklist-ip.conf', formvalue.trim().replace(/\r\n/g, '\n') + '\n'); - }); - }; - /////////////////////////////////////// // domain address /////////////////////////////////////// @@ -1243,6 +1222,23 @@ return view.extend({ }); }; + // other args + so = ss.option(form.Value, "addition_flag", _("Additional Rule Flag"), + _("Additional Flags for rules, read help on ip-rule for more information.")) + so.default = "" + so.rempty = true + so.modalonly = true; + + //////////////// + // ip rules; + //////////////// + s = m.section(form.TypedSection, "ip-rule", _("IP Rules"), _("IP Rules Settings")); + s.anonymous = true; + s.nodescriptions = true; + + s.tab("ip-rule-list", _("IP Rule List"), _("Set Specific ip rule list.")); + s.tab("blackip-list", _("IP Blacklist"), _("Set Specific ip blacklist.")); + /////////////////////////////////////// // ip rule list; /////////////////////////////////////// @@ -1302,12 +1298,24 @@ return view.extend({ so.datatype = 'ipaddr("nomask")'; so.modalonly = true; - // other args - so = ss.option(form.Value, "addition_flag", _("Additional Rule Flag"), - _("Additional Flags for rules, read help on ip-rule for more information.")) - so.default = "" - so.rempty = true - so.modalonly = true; + /////////////////////////////////////// + // IP Blacklist; + /////////////////////////////////////// + // blacklist; + o = s.taboption("blackip-list", form.TextValue, "blackip_ip_conf", + "", _("Configure IP blacklists that will be filtered from the results of specific DNS server.")); + o.rows = 20; + o.cfgvalue = function (section_id) { + return fs.trimmed('/etc/smartdns/blacklist-ip.conf'); + }; + o.write = function (section_id, formvalue) { + return this.cfgvalue(section_id).then(function (value) { + if (value == formvalue) { + return + } + return fs.write('/etc/smartdns/blacklist-ip.conf', formvalue.trim().replace(/\r\n/g, '\n') + '\n'); + }); + }; //////////////// // Support diff --git a/package/openwrt/files/etc/init.d/smartdns b/package/openwrt/files/etc/init.d/smartdns index 8b1a2f1b03..6e867a8ce8 100644 --- a/package/openwrt/files/etc/init.d/smartdns +++ b/package/openwrt/files/etc/init.d/smartdns @@ -753,6 +753,8 @@ load_service() config_foreach load_domain_rule_list "domain-rule-list" + config_foreach load_IP_rule_list "ip-rule" + config_foreach load_IP_rule_list "ip-rule-list" { @@ -840,6 +842,12 @@ check_and_add_entry() { docommit=1 fi + uci -q get smartdns.@ip-rule[0] >/dev/null + if [ $? -ne 0 ]; then + uci -q add smartdns ip-rule >/dev/null + docommit=1 + fi + if [ "$docommit" = "1" ]; then uci -q commit smartdns >/dev/null fi