luci-app-mosdns: add DNS cache controller

Signed-off-by: sbwml <admin@cooluc.com>
This commit is contained in:
sbwml 2024-07-28 13:46:50 +08:00
parent 1837e20e69
commit c31e112465
5 changed files with 41 additions and 30 deletions

View File

@ -1,7 +1,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-mosdns PKG_NAME:=luci-app-mosdns
PKG_VERSION:=1.5.22 PKG_VERSION:=1.5.23
PKG_RELEASE:=1 PKG_RELEASE:=1
LUCI_TITLE:=LuCI Support for mosdns LUCI_TITLE:=LuCI Support for mosdns

View File

@ -150,20 +150,25 @@ o.rmempty = false
o.default = false o.default = false
o:depends("configfile", "/var/etc/mosdns.json") o:depends("configfile", "/var/etc/mosdns.json")
o = s:taboption("advanced", Value, "cache_size", translate("DNS Cache Size"), translate("DNS cache size (in piece). To disable caching, please set to 0.")) o = s:taboption("advanced", Flag, "cache", translate("Enable DNS Cache"))
o.rmempty = false
o.default = false
o:depends("configfile", "/var/etc/mosdns.json")
o = s:taboption("advanced", Value, "cache_size", translate("DNS Cache Size"), translate("DNS cache size (in piece)."))
o.datatype = "and(uinteger,min(0))" o.datatype = "and(uinteger,min(0))"
o.default = "8000" o.default = "8000"
o:depends("configfile", "/var/etc/mosdns.json") o:depends("cache", "1")
o = s:taboption("advanced", Value, "lazy_cache_ttl", translate("Lazy Cache TTL"), translate("Lazy cache survival time (in second). To disable Lazy Cache, please set to 0.")) o = s:taboption("advanced", Value, "lazy_cache_ttl", translate("Lazy Cache TTL"), translate("Lazy cache survival time (in second). To disable Lazy Cache, please set to 0."))
o.datatype = "and(uinteger,min(0))" o.datatype = "and(uinteger,min(0))"
o.default = "86400" o.default = "86400"
o:depends("configfile", "/var/etc/mosdns.json") o:depends("cache", "1")
o = s:taboption("advanced", Flag, "dump_file", translate("Cache Dump"), translate("Save the cache locally and reload the cache dump on the next startup")) o = s:taboption("advanced", Flag, "dump_file", translate("Cache Dump"), translate("Save the cache locally and reload the cache dump on the next startup"))
o.rmempty = false o.rmempty = false
o.default = false o.default = false
o:depends("configfile", "/var/etc/mosdns.json") o:depends("cache", "1")
o = s:taboption("advanced", Value, "dump_interval", translate("Auto Save Cache Interval")) o = s:taboption("advanced", Value, "dump_interval", translate("Auto Save Cache Interval"))
o.datatype = "and(uinteger,min(0))" o.datatype = "and(uinteger,min(0))"

View File

@ -292,11 +292,14 @@ msgstr "防止 DNS 泄漏"
msgid "Enable this option fallback policy forces forwarding to remote DNS" msgid "Enable this option fallback policy forces forwarding to remote DNS"
msgstr "启用此选项 fallback 策略会强制转发到远程 DNS" msgstr "启用此选项 fallback 策略会强制转发到远程 DNS"
msgid "Enable DNS Cache"
msgstr "启用 DNS 缓存"
msgid "DNS Cache Size" msgid "DNS Cache Size"
msgstr "DNS 缓存大小" msgstr "DNS 缓存大小"
msgid "DNS cache size (in piece). To disable caching, please set to 0." msgid "DNS cache size (in piece)."
msgstr "DNS 缓存大小(单位:条),要禁用缓存,请设置为 0" msgstr "DNS 缓存大小(单位:条)"
msgid "Lazy Cache TTL" msgid "Lazy Cache TTL"
msgstr "乐观缓存 TTL" msgstr "乐观缓存 TTL"

View File

@ -11,9 +11,7 @@ config mosdns 'config'
option configfile '/var/etc/mosdns.json' option configfile '/var/etc/mosdns.json'
option log_level 'info' option log_level 'info'
option log_file '/var/log/mosdns.log' option log_file '/var/log/mosdns.log'
option cache_size '8000' option cache '0'
option lazy_cache_ttl '86400'
option dump_file '0'
option concurrent '1' option concurrent '1'
option idle_timeout '30' option idle_timeout '30'
option minimal_ttl '0' option minimal_ttl '0'

View File

@ -33,6 +33,7 @@ get_config() {
config_get enabled $1 enabled 0 config_get enabled $1 enabled 0
config_get adblock $1 adblock 0 config_get adblock $1 adblock 0
config_get ad_source $1 ad_source "" config_get ad_source $1 ad_source ""
config_get cache $1 cache 0
config_get cache_size $1 cache_size 8000 config_get cache_size $1 cache_size 8000
config_get lazy_cache_ttl $1 lazy_cache_ttl 86400 config_get lazy_cache_ttl $1 lazy_cache_ttl 86400
config_get dump_file $1 dump_file 0 config_get dump_file $1 dump_file 0
@ -231,6 +232,7 @@ generate_config() {
json_close_object json_close_object
json_close_object json_close_object
# plugin: lazy_cache # plugin: lazy_cache
[ "$cache" -eq 1 ] && {
json_add_object json_add_object
json_add_string "tag" "lazy_cache" json_add_string "tag" "lazy_cache"
json_add_string "type" "cache" json_add_string "type" "cache"
@ -243,6 +245,7 @@ generate_config() {
} }
json_close_object json_close_object
json_close_object json_close_object
}
# plugin: forward_xinfeng_udp # plugin: forward_xinfeng_udp
json_add_object json_add_object
json_add_string "tag" "forward_xinfeng_udp" json_add_string "tag" "forward_xinfeng_udp"
@ -573,6 +576,7 @@ generate_config() {
json_add_object json_add_object
json_add_string "exec" "jump has_resp_sequence" json_add_string "exec" "jump has_resp_sequence"
json_close_object json_close_object
[ "$cache" -eq 1 ] && {
json_add_object json_add_object
json_add_array "matches" json_add_array "matches"
json_add_string "" "!qname \$ddnslist" json_add_string "" "!qname \$ddnslist"
@ -582,6 +586,7 @@ generate_config() {
json_close_array json_close_array
json_add_string "exec" "\$lazy_cache" json_add_string "exec" "\$lazy_cache"
json_close_object json_close_object
}
json_add_object json_add_object
json_add_string "exec" "\$redirect" json_add_string "exec" "\$redirect"
json_close_object json_close_object