luci-app-mosdns: Add a Settings tab category

This commit is contained in:
sbwml 2023-03-27 08:37:39 +08:00
parent b1756bd586
commit 9d98b22173
3 changed files with 148 additions and 123 deletions

View File

@ -1,3 +1,6 @@
local sys = require "luci.sys"
local http = require "luci.http"
module("luci.controller.mosdns", package.seeall) module("luci.controller.mosdns", package.seeall)
function index() function index()
@ -21,22 +24,22 @@ end
function act_status() function act_status()
local e = {} local e = {}
e.running = luci.sys.call("pgrep -f mosdns >/dev/null") == 0 e.running = sys.call("pgrep -f mosdns >/dev/null") == 0
luci.http.prepare_content("application/json") http.prepare_content("application/json")
luci.http.write_json(e) http.write_json(e)
end end
function get_log() function get_log()
luci.http.write(luci.sys.exec("cat $(/usr/share/mosdns/mosdns.sh logfile)")) http.write(sys.exec("cat $(/usr/share/mosdns/mosdns.sh logfile)"))
end end
function clear_log() function clear_log()
luci.sys.call("cat /dev/null > $(/usr/share/mosdns/mosdns.sh logfile)") sys.call("cat /dev/null > $(/usr/share/mosdns/mosdns.sh logfile)")
end end
function geo_update() function geo_update()
local e = {} local e = {}
e.updating = luci.sys.call("/usr/share/mosdns/mosdns.sh geodata >/dev/null") == 0 e.updating = sys.call("/usr/share/mosdns/mosdns.sh geodata >/dev/null") == 0
luci.http.prepare_content("application/json") http.prepare_content("application/json")
luci.http.write_json(e) http.write_json(e)
end end

View File

@ -1,5 +1,8 @@
if nixio.fs.access("/usr/bin/mosdns") then local fs = require "nixio.fs"
mosdns_version = luci.sys.exec("/usr/share/mosdns/mosdns.sh version") local sys = require "luci.sys"
if fs.access("/usr/bin/mosdns") then
mosdns_version = sys.exec("/usr/share/mosdns/mosdns.sh version")
else else
mosdns_version = "Unknown Version" mosdns_version = "Unknown Version"
end end
@ -13,142 +16,146 @@ s = m:section(TypedSection, "mosdns")
s.addremove = false s.addremove = false
s.anonymous = true s.anonymous = true
enable = s:option(Flag, "enabled", translate("Enable")) s:tab("basic", translate("Basic Options"))
enable.rmempty = false
configfile = s:option(ListValue, "configfile", translate("Config File")) o = s:taboption("basic", Flag, "enabled", translate("Enabled"))
configfile:value("/etc/mosdns/config.yaml", translate("Default Config")) o.rmempty = false
configfile:value("/etc/mosdns/config_custom.yaml", translate("Custom Config"))
configfile.default = "/etc/mosdns/config.yaml"
listenport = s:option(Value, "listen_port", translate("Listen port")) o = s:taboption("basic", ListValue, "configfile", translate("Config File"))
listenport.datatype = "and(port,min(1))" o:value("/etc/mosdns/config.yaml", translate("Default Config"))
listenport.default = 5335 o:value("/etc/mosdns/config_custom.yaml", translate("Custom Config"))
listenport:depends("configfile", "/etc/mosdns/config.yaml") o.default = "/etc/mosdns/config.yaml"
loglevel = s:option(ListValue, "log_level", translate("Log Level")) o = s:taboption("basic", Value, "listen_port", translate("Listen port"))
loglevel:value("debug", translate("Debug")) o.datatype = "and(port,min(1))"
loglevel:value("info", translate("Info")) o.default = 5335
loglevel:value("warn", translate("Warning")) o:depends("configfile", "/etc/mosdns/config.yaml")
loglevel:value("error", translate("Error"))
loglevel.default = "info"
loglevel:depends("configfile", "/etc/mosdns/config.yaml")
logfile = s:option(Value, "logfile", translate("Log File")) o = s:taboption("basic", ListValue, "log_level", translate("Log Level"))
logfile.placeholder = "/tmp/mosdns.log" o:value("debug", translate("Debug"))
logfile.default = "/tmp/mosdns.log" o:value("info", translate("Info"))
logfile:depends("configfile", "/etc/mosdns/config.yaml") o:value("warn", translate("Warning"))
o:value("error", translate("Error"))
o.default = "info"
o:depends("configfile", "/etc/mosdns/config.yaml")
redirect = s:option(Flag, "redirect", translate("DNS Forward"), translate("Forward Dnsmasq Domain Name resolution requests to MosDNS")) o = s:taboption("basic", Value, "logfile", translate("Log File"))
redirect.default = true o.placeholder = "/tmp/mosdns.log"
o.default = "/tmp/mosdns.log"
o:depends("configfile", "/etc/mosdns/config.yaml")
custom_local_dns = s:option(Flag, "custom_local_dns", translate("Local DNS"), translate("Follow WAN interface DNS if not enabled")) o = s:taboption("basic", Flag, "redirect", translate("DNS Forward"), translate("Forward Dnsmasq Domain Name resolution requests to MosDNS"))
custom_local_dns:depends( "configfile", "/etc/mosdns/config.yaml") o.default = true
custom_local_dns.default = false
custom_local_dns = s:option(DynamicList, "local_dns", translate("Upstream DNS servers"))
custom_local_dns:value("119.29.29.29", "119.29.29.29 (DNSPod Primary)")
custom_local_dns:value("119.28.28.28", "119.28.28.28 (DNSPod Secondary)")
custom_local_dns:value("223.5.5.5", "223.5.5.5 (AliDNS Primary)")
custom_local_dns:value("223.6.6.6", "223.6.6.6 (AliDNS Secondary)")
custom_local_dns:value("114.114.114.114", "114.114.114.114 (114DNS Primary)")
custom_local_dns:value("114.114.115.115", "114.114.115.115 (114DNS Secondary)")
custom_local_dns:value("180.76.76.76", "180.76.76.76 (Baidu DNS)")
custom_local_dns:value("https://doh.pub/dns-query", "DNSPod DoH")
custom_local_dns:value("https://dns.alidns.com/dns-query", "AliDNS DoH")
custom_local_dns:value("https://doh.360.cn/dns-query", "360DNS DoH")
custom_local_dns:depends("custom_local_dns", "1")
remote_dns = s:option(DynamicList, "remote_dns", translate("Remote DNS")) o = s:taboption("basic", Flag, "custom_local_dns", translate("Local DNS"), translate("Follow WAN interface DNS if not enabled"))
remote_dns:value("tls://1.1.1.1", "1.1.1.1 (CloudFlare DNS)") o:depends( "configfile", "/etc/mosdns/config.yaml")
remote_dns:value("tls://1.0.0.1", "1.0.0.1 (CloudFlare DNS)") o.default = false
remote_dns:value("tls://8.8.8.8", "8.8.8.8 (Google DNS)") o = s:taboption("basic", DynamicList, "local_dns", translate("Upstream DNS servers"))
remote_dns:value("tls://8.8.4.4", "8.8.4.4 (Google DNS)") o:value("119.29.29.29", "119.29.29.29 (DNSPod Primary)")
remote_dns:value("tls://9.9.9.9", "9.9.9.9 (Quad9 DNS)") o:value("119.28.28.28", "119.28.28.28 (DNSPod Secondary)")
remote_dns:value("tls://149.112.112.112", "149.112.112.112 (Quad9 DNS)") o:value("223.5.5.5", "223.5.5.5 (AliDNS Primary)")
remote_dns:value("tls://45.11.45.11", "45.11.45.11 (DNS.SB)") o:value("223.6.6.6", "223.6.6.6 (AliDNS Secondary)")
remote_dns:value("tls://208.67.222.222", "208.67.222.222 (Open DNS)") o:value("114.114.114.114", "114.114.114.114 (114DNS Primary)")
remote_dns:value("tls://208.67.220.220", "208.67.220.220 (Open DNS)") o:value("114.114.115.115", "114.114.115.115 (114DNS Secondary)")
remote_dns:depends("configfile", "/etc/mosdns/config.yaml") o:value("180.76.76.76", "180.76.76.76 (Baidu DNS)")
o:value("https://doh.pub/dns-query", "DNSPod DoH")
o:value("https://dns.alidns.com/dns-query", "AliDNS DoH")
o:value("https://doh.360.cn/dns-query", "360DNS DoH")
o:depends("custom_local_dns", "1")
bootstrap_dns = s:option(ListValue, "bootstrap_dns", translate("Bootstrap DNS servers"), translate("Bootstrap DNS servers are used to resolve IP addresses of the DoH/DoT resolvers you specify as upstreams")) o = s:taboption("basic", DynamicList, "remote_dns", translate("Remote DNS"))
bootstrap_dns:value("119.29.29.29", "119.29.29.29 (DNSPod Primary)") o:value("tls://1.1.1.1", "1.1.1.1 (CloudFlare DNS)")
bootstrap_dns:value("119.28.28.28", "119.28.28.28 (DNSPod Secondary)") o:value("tls://1.0.0.1", "1.0.0.1 (CloudFlare DNS)")
bootstrap_dns:value("223.5.5.5", "223.5.5.5 (AliDNS Primary)") o:value("tls://8.8.8.8", "8.8.8.8 (Google DNS)")
bootstrap_dns:value("223.6.6.6", "223.6.6.6 (AliDNS Secondary)") o:value("tls://8.8.4.4", "8.8.4.4 (Google DNS)")
bootstrap_dns:value("114.114.114.114", "114.114.114.114 (114DNS Primary)") o:value("tls://9.9.9.9", "9.9.9.9 (Quad9 DNS)")
bootstrap_dns:value("114.114.115.115", "114.114.115.115 (114DNS Secondary)") o:value("tls://149.112.112.112", "149.112.112.112 (Quad9 DNS)")
bootstrap_dns:value("180.76.76.76", "180.76.76.76 (Baidu DNS)") o:value("tls://45.11.45.11", "45.11.45.11 (DNS.SB)")
bootstrap_dns.default = "119.29.29.29" o:value("tls://208.67.222.222", "208.67.222.222 (Open DNS)")
bootstrap_dns:depends("configfile", "/etc/mosdns/config.yaml") o:value("tls://208.67.220.220", "208.67.220.220 (Open DNS)")
o:depends("configfile", "/etc/mosdns/config.yaml")
remote_dns_pipeline = s:option(Flag, "enable_pipeline", translate("TCP/DoT Connection Multiplexing"), translate("Enable TCP/DoT RFC 7766 new Query Pipelining connection multiplexing mode")) o = s:taboption("basic", ListValue, "bootstrap_dns", translate("Bootstrap DNS servers"), translate("Bootstrap DNS servers are used to resolve IP addresses of the DoH/DoT resolvers you specify as upstreams"))
remote_dns_pipeline.rmempty = false o:value("119.29.29.29", "119.29.29.29 (DNSPod Primary)")
remote_dns_pipeline.default = false o:value("119.28.28.28", "119.28.28.28 (DNSPod Secondary)")
remote_dns_pipeline:depends("configfile", "/etc/mosdns/config.yaml") o:value("223.5.5.5", "223.5.5.5 (AliDNS Primary)")
o:value("223.6.6.6", "223.6.6.6 (AliDNS Secondary)")
o:value("114.114.114.114", "114.114.114.114 (114DNS Primary)")
o:value("114.114.115.115", "114.114.115.115 (114DNS Secondary)")
o:value("180.76.76.76", "180.76.76.76 (Baidu DNS)")
o.default = "119.29.29.29"
o:depends("configfile", "/etc/mosdns/config.yaml")
cache_size = s:option(Value, "cache_size", translate("DNS Cache Size")) s:tab("advanced", translate("Advanced Options"))
cache_size.datatype = "and(uinteger,min(0))"
cache_size.default = "20000"
cache_size:depends("configfile", "/etc/mosdns/config.yaml")
cache_size = s:option(Value, "cache_survival_time", translate("Cache Survival Time")) o = s:taboption("advanced", Flag, "enable_pipeline", translate("TCP/DoT Connection Multiplexing"), translate("Enable TCP/DoT RFC 7766 new Query Pipelining connection multiplexing mode"))
cache_size.datatype = "and(uinteger,min(0))" o.rmempty = false
cache_size.default = "86400" o.default = false
cache_size:depends("configfile", "/etc/mosdns/config.yaml") o:depends("configfile", "/etc/mosdns/config.yaml")
cache_dump = s:option(Flag, "dump_file", translate("Cache Dump"), translate("Save the cache locally and reload the cache dump on the next startup")) o = s:taboption("advanced", Value, "cache_size", translate("DNS Cache Size"))
cache_dump.rmempty = false o.datatype = "and(uinteger,min(0))"
cache_dump.default = false o.default = "20000"
cache_dump:depends("configfile", "/etc/mosdns/config.yaml") o:depends("configfile", "/etc/mosdns/config.yaml")
cache_dump = s:option(Value, "dump_interval", translate("Auto Save Cache Interval")) o = s:taboption("advanced", Value, "cache_survival_time", translate("Cache Survival Time"))
cache_dump.datatype = "and(uinteger,min(0))" o.datatype = "and(uinteger,min(0))"
cache_dump.default = "600" o.default = "86400"
cache_dump:depends("dump_file", "1") o:depends("configfile", "/etc/mosdns/config.yaml")
minimal_ttl = s:option(Value, "minimal_ttl", translate("Minimum TTL")) o = s:taboption("advanced", Flag, "dump_file", translate("Cache Dump"), translate("Save the cache locally and reload the cache dump on the next startup"))
minimal_ttl.datatype = "and(uinteger,min(0))" o.rmempty = false
minimal_ttl.datatype = "and(uinteger,max(3600))" o.default = false
minimal_ttl.default = "0" o:depends("configfile", "/etc/mosdns/config.yaml")
minimal_ttl:depends("configfile", "/etc/mosdns/config.yaml")
maximum_ttl = s:option(Value, "maximum_ttl", translate("Maximum TTL")) o = s:taboption("advanced", Value, "dump_interval", translate("Auto Save Cache Interval"))
maximum_ttl.datatype = "and(uinteger,min(0))" o.datatype = "and(uinteger,min(0))"
maximum_ttl.default = "0" o.default = "600"
maximum_ttl:depends("configfile", "/etc/mosdns/config.yaml") o:depends("dump_file", "1")
adblock = s:option(Flag, "adblock", translate("Enable DNS ADblock")) o = s:taboption("advanced", Value, "minimal_ttl", translate("Minimum TTL"), translate("Modify the Minimum TTL value (seconds) for DNS answer results, 0 indicating no modification"))
adblock:depends("configfile", "/etc/mosdns/config.yaml") o.datatype = "and(uinteger,min(0))"
adblock.default = false o.datatype = "and(uinteger,max(3600))"
o.default = "0"
o:depends("configfile", "/etc/mosdns/config.yaml")
adblock = s:option(Value, "ad_source", translate("ADblock Source")) o = s:taboption("advanced", Value, "maximum_ttl", translate("Maximum TTL"), translate("Modify the Maximum TTL value (seconds) for DNS answer results, 0 indicating no modification"))
adblock:depends("adblock", "1") o.datatype = "and(uinteger,min(0))"
adblock.default = "https://raw.githubusercontent.com/privacy-protection-tools/anti-AD/master/anti-ad-domains.txt" o.default = "0"
adblock:value("geosite.dat", "v2ray-geosite") o:depends("configfile", "/etc/mosdns/config.yaml")
adblock:value("https://raw.githubusercontent.com/privacy-protection-tools/anti-AD/master/anti-ad-domains.txt", "anti-AD")
adblock:value("https://raw.githubusercontent.com/ookangzheng/dbl-oisd-nl/master/dbl_light.txt", "oisd (small)")
adblock:value("https://raw.githubusercontent.com/ookangzheng/dbl-oisd-nl/master/dbl.txt", "oisd (big)")
adblock:value("https://raw.githubusercontent.com/QiuSimons/openwrt-mos/master/dat/serverlist.txt", "QiuSimons/openwrt-mos")
reload_service = s:option( Button, "_reload", translate("Reload Service"), translate("Reload service to take effect of new configuration")) o = s:taboption("advanced", Flag, "adblock", translate("Enable DNS ADblock"))
reload_service.write = function() o:depends("configfile", "/etc/mosdns/config.yaml")
luci.sys.exec("/etc/init.d/mosdns reload") o.default = false
o = s:taboption("advanced", Value, "ad_source", translate("ADblock Source"), translate("When using custom rule sources, use the rule types supported by MosDNS"))
o:depends("adblock", "1")
o.default = "https://raw.githubusercontent.com/privacy-protection-tools/anti-AD/master/anti-ad-domains.txt"
o:value("geosite.dat", "v2ray-geosite")
o:value("https://raw.githubusercontent.com/privacy-protection-tools/anti-AD/master/anti-ad-domains.txt", "anti-AD")
o:value("https://raw.githubusercontent.com/ookangzheng/dbl-oisd-nl/master/dbl_light.txt", "oisd (small)")
o:value("https://raw.githubusercontent.com/ookangzheng/dbl-oisd-nl/master/dbl.txt", "oisd (big)")
o:value("https://raw.githubusercontent.com/QiuSimons/openwrt-mos/master/dat/serverlist.txt", "QiuSimons/openwrt-mos")
o = s:taboption("basic", Button, "_reload", translate("Reload Service"), translate("Reload service to take effect of new configuration"))
o.write = function()
sys.exec("/etc/init.d/mosdns reload")
end end
reload_service:depends("configfile", "/etc/mosdns/config_custom.yaml") o:depends("configfile", "/etc/mosdns/config_custom.yaml")
config = s:option(TextValue, "manual-config") o = s:taboption("basic", TextValue, "manual-config")
config.description = translate("<font color=\"ff0000\"><strong>View the Custom YAML Configuration file used by this MosDNS. You can edit it as you own need.</strong></font>") o.description = translate("<font color=\"ff0000\"><strong>View the Custom YAML Configuration file used by this MosDNS. You can edit it as you own need.</strong></font>")
config.template = "cbi/tvalue" o.template = "cbi/tvalue"
config.rows = 25 o.rows = 25
config:depends("configfile", "/etc/mosdns/config_custom.yaml") o:depends("configfile", "/etc/mosdns/config_custom.yaml")
function config.cfgvalue(self, section) function o.cfgvalue(self, section)
return nixio.fs.readfile("/etc/mosdns/config_custom.yaml") return fs.readfile("/etc/mosdns/config_custom.yaml")
end end
function config.write(self, section, value) function o.write(self, section, value)
value = value:gsub("\r\n?", "\n") value = value:gsub("\r\n?", "\n")
nixio.fs.writefile("/etc/mosdns/config_custom.yaml", value) fs.writefile("/etc/mosdns/config_custom.yaml", value)
end end
return m return m

View File

@ -1,6 +1,12 @@
msgid "Basic Setting" msgid "Basic Setting"
msgstr "基本设置" msgstr "基本设置"
msgid "Basic Options"
msgstr "基本选项"
msgid "Advanced Options"
msgstr "高级选项"
msgid "MosDNS is a 'programmable' DNS forwarder." msgid "MosDNS is a 'programmable' DNS forwarder."
msgstr "MosDNS 是一个插件化的 DNS 转发/分流器。" msgstr "MosDNS 是一个插件化的 DNS 转发/分流器。"
@ -13,7 +19,7 @@ msgstr "未运行"
msgid "Collecting data..." msgid "Collecting data..."
msgstr "获取数据中..." msgstr "获取数据中..."
msgid "Enable" msgid "Enabled"
msgstr "启用" msgstr "启用"
msgid "Listen port" msgid "Listen port"
@ -34,6 +40,9 @@ msgstr "启用 DNS 广告过滤"
msgid "ADblock Source" msgid "ADblock Source"
msgstr "广告过滤规则来源" msgstr "广告过滤规则来源"
msgid "When using custom rule sources, use the rule types supported by MosDNS"
msgstr "使用自定义规则来源时,请使用 MosDNS 支持的规则类型"
msgid "Reload Service" msgid "Reload Service"
msgstr "重载服务" msgstr "重载服务"
@ -151,9 +160,15 @@ msgstr "自动保存缓存间隔(秒)"
msgid "Minimum TTL" msgid "Minimum TTL"
msgstr "覆盖最小 TTL 值(默认 0" msgstr "覆盖最小 TTL 值(默认 0"
msgid "Modify the Minimum TTL value (seconds) for DNS answer results, 0 indicating no modification"
msgstr "修改 DNS 应答结果的最小 TTL 值 (秒)0 表示不修改"
msgid "Maximum TTL" msgid "Maximum TTL"
msgstr "覆盖最大 TTL 值(默认 0" msgstr "覆盖最大 TTL 值(默认 0"
msgid "Modify the Maximum TTL value (seconds) for DNS answer results, 0 indicating no modification"
msgstr "修改 DNS 应答结果的最大 TTL 值0 表示不修改"
msgid "Logs" msgid "Logs"
msgstr "日志" msgstr "日志"