Add DNS redirect & hosts support
This commit is contained in:
parent
82a0e545d6
commit
2c3d55cdf5
@ -2,14 +2,18 @@ local datatypes = require "luci.cbi.datatypes"
|
||||
|
||||
local white_list_file = "/etc/mosdns/rule/whitelist.txt"
|
||||
local block_list_file = "/etc/mosdns/rule/blocklist.txt"
|
||||
local hosts_list_file = "/etc/mosdns/rule/hosts.txt"
|
||||
local redirect_list_file = "/etc/mosdns/rule/redirect.txt"
|
||||
|
||||
m = Map("mosdns")
|
||||
|
||||
s = m:section(TypedSection, "mosdns", translate("Black and White List Settings"))
|
||||
s = m:section(TypedSection, "mosdns", translate("Rule Settings"))
|
||||
s.anonymous = true
|
||||
|
||||
s:tab("white_list", translate("White Lists"))
|
||||
s:tab("block_list", translate("Block Lists"))
|
||||
s:tab("hosts_list", translate("Hosts"))
|
||||
s:tab("redirect_list", translate("Redirect"))
|
||||
|
||||
o = s:taboption("white_list", TextValue, "whitelist", "", "<font color='red'>" .. translate("These domain names allow DNS resolution with the highest priority. Please input the domain names of websites, every line can input only one website domain. For example: hm.baidu.com.") .. "</font>" .. "<font color='#00bd3e'>" .. translate("<br>The list of rules only apply to 'Default Config' profiles.") .. "</font>")
|
||||
o.rows = 15
|
||||
@ -51,6 +55,40 @@ o.validate = function(self, value)
|
||||
return value
|
||||
end
|
||||
|
||||
o = s:taboption("hosts_list", TextValue, "hosts", "", "<font color='red'>" .. translate("Hosts For example: baidu.com 10.0.0.1") .. "</font>" .. "<font color='#00bd3e'>" .. translate("<br>The list of rules only apply to 'Default Config' profiles.") .. "</font>")
|
||||
o.rows = 15
|
||||
o.wrap = "off"
|
||||
o.cfgvalue = function(self, section) return nixio.fs.readfile(hosts_list_file) or "" end
|
||||
o.write = function(self, section, value) nixio.fs.writefile(hosts_list_file, value:gsub("\r\n", "\n")) end
|
||||
o.remove = function(self, section, value) nixio.fs.writefile(hosts_list_file, "") end
|
||||
o.validate = function(self, value)
|
||||
local hosts= {}
|
||||
string.gsub(value, '[^' .. "\r\n" .. ']+', function(w) table.insert(hosts, w) end)
|
||||
for index, host in ipairs(hosts) do
|
||||
if host:find("#") and host:find("#") == 1 then
|
||||
return value
|
||||
end
|
||||
end
|
||||
return value
|
||||
end
|
||||
|
||||
o = s:taboption("redirect_list", TextValue, "redirect", "", "<font color='red'>" .. translate("The domain name to redirect the request to. Requests domain A, but returns records for domain B. example: a.com b.com") .. "</font>" .. "<font color='#00bd3e'>" .. translate("<br>The list of rules only apply to 'Default Config' profiles.") .. "</font>")
|
||||
o.rows = 15
|
||||
o.wrap = "off"
|
||||
o.cfgvalue = function(self, section) return nixio.fs.readfile(redirect_list_file) or "" end
|
||||
o.write = function(self, section, value) nixio.fs.writefile(redirect_list_file, value:gsub("\r\n", "\n")) end
|
||||
o.remove = function(self, section, value) nixio.fs.writefile(redirect_list_file, "") end
|
||||
o.validate = function(self, value)
|
||||
local hosts= {}
|
||||
string.gsub(value, '[^' .. "\r\n" .. ']+', function(w) table.insert(hosts, w) end)
|
||||
for index, host in ipairs(hosts) do
|
||||
if host:find("#") and host:find("#") == 1 then
|
||||
return value
|
||||
end
|
||||
end
|
||||
return value
|
||||
end
|
||||
|
||||
local apply = luci.http.formvalue("cbi.apply")
|
||||
if apply then
|
||||
luci.sys.exec("/etc/init.d/mosdns reload")
|
||||
|
@ -109,8 +109,8 @@ msgstr "清空日志"
|
||||
msgid "Rule List"
|
||||
msgstr "规则列表"
|
||||
|
||||
msgid "Black and White List Settings"
|
||||
msgstr "自定义黑白名单"
|
||||
msgid "Rule Settings"
|
||||
msgstr "自定义规则列表"
|
||||
|
||||
msgid "<br>The list of rules only apply to 'Default Config' profiles."
|
||||
msgstr "<br>规则列表仅适用于 “内置预设” 配置文件"
|
||||
@ -119,13 +119,22 @@ msgid "White Lists"
|
||||
msgstr "白名单"
|
||||
|
||||
msgid "These domain names allow DNS resolution with the highest priority. Please input the domain names of websites, every line can input only one website domain. For example: hm.baidu.com."
|
||||
msgstr "加入的域名始终允许 DNS 解析,且优先级最高(每行只能输入一个域名)"
|
||||
msgstr "加入的域名始终允许 DNS 解析,且优先级最高(每个域名一行)"
|
||||
|
||||
msgid "Block Lists"
|
||||
msgstr "黑名单"
|
||||
|
||||
msgid "These domains are blocked from DNS resolution. Please input the domain names of websites, every line can input only one website domain. For example: baidu.com."
|
||||
msgstr "加入的域名将屏蔽 DNS 解析(每行只能输入一个域名)"
|
||||
msgstr "加入的域名将屏蔽 DNS 解析(每个域名一行)"
|
||||
|
||||
msgid "Not valid domain name, Please Re-enter."
|
||||
msgstr "不是有效域名,请重新输入"
|
||||
|
||||
msgid "Hosts For example: baidu.com 10.0.0.1"
|
||||
msgstr "自定义 Hosts 重写,如:baidu.com 10.0.0.1(每个规则一行)"
|
||||
|
||||
msgid "Redirect"
|
||||
msgstr "重定向"
|
||||
|
||||
msgid "The domain name to redirect the request to. Requests domain A, but returns records for domain B. example: a.com b.com"
|
||||
msgstr "重定向请求的域名。请求域名 A,但返回域名 B 的记录,如:baidu.com qq.com(每个规则一行)"
|
||||
|
@ -7,6 +7,8 @@ plugin:
|
||||
type: server
|
||||
args:
|
||||
entry:
|
||||
- query_is_hosts_domain
|
||||
- query_is_redirect_domain
|
||||
- _no_ecs
|
||||
- _prefer_ipv4
|
||||
- _single_flight
|
||||
@ -89,6 +91,18 @@ plugin:
|
||||
domain:
|
||||
- "ext:/etc/mosdns/rule/blocklist.txt"
|
||||
|
||||
- tag: query_is_hosts_domain
|
||||
type: hosts
|
||||
args:
|
||||
hosts:
|
||||
- "ext:/etc/mosdns/rule/hosts.txt"
|
||||
|
||||
- tag: query_is_redirect_domain
|
||||
type: redirect
|
||||
args:
|
||||
rule:
|
||||
- "ext:/etc/mosdns/rule/redirect.txt"
|
||||
|
||||
- tag: forward_remote
|
||||
type: fast_forward
|
||||
args:
|
||||
|
0
root/etc/mosdns/rule/hosts.txt
Normal file
0
root/etc/mosdns/rule/hosts.txt
Normal file
0
root/etc/mosdns/rule/redirect.txt
Normal file
0
root/etc/mosdns/rule/redirect.txt
Normal file
Loading…
Reference in New Issue
Block a user