luci-app-mosdns: Add DNS cache saving support

This commit is contained in:
sbwml 2023-03-25 00:56:05 +08:00
parent 94b85324bd
commit e138175cb4
6 changed files with 30 additions and 6 deletions

View File

@ -10,6 +10,7 @@ LUCI_DEPENDS:=+mosdns +jsonfilter +luci-compat +curl +v2ray-geoip +v2ray-geosite
define Package/$(PKG_NAME)/conffiles
/etc/config/mosdns
/etc/mosdns/cache.dump
/etc/mosdns/config_custom.yaml
/etc/mosdns/rule
endef

View File

@ -80,14 +80,24 @@ remote_dns_pipeline:depends( "configfile", "/etc/mosdns/config.yaml")
cache_size = s:option(Value, "cache_size", translate("DNS Cache Size"))
cache_size.datatype = "and(uinteger,min(0))"
cache_size.default = "200000"
cache_size.default = "20000"
cache_size:depends( "configfile", "/etc/mosdns/config.yaml")
cache_size = s:option(Value, "cache_survival_time", translate("Cache Survival Time"))
cache_size.datatype = "and(uinteger,min(0))"
cache_size.default = "259200"
cache_size.default = "86400"
cache_size:depends( "configfile", "/etc/mosdns/config.yaml")
cache_dump = s:option(Flag, "dump_file", translate("Save Cache"), translate("Save the cache locally to reload the cache on the next startup"))
cache_dump.rmempty = false
cache_dump.default = false
cache_dump:depends( "configfile", "/etc/mosdns/config.yaml")
cache_dump = s:option(Value, "dump_interval", translate("Auto Save Cache Interval"))
cache_dump.datatype = "and(uinteger,min(0))"
cache_dump.default = "600"
cache_dump:depends("dump_file", "1")
minimal_ttl = s:option(Value, "minimal_ttl", translate("Minimum TTL"))
minimal_ttl.datatype = "and(uinteger,min(0))"
minimal_ttl.datatype = "and(uinteger,max(3600))"

View File

@ -139,6 +139,15 @@ msgstr "DNS 缓存大小(条)"
msgid "Cache Survival Time"
msgstr "缓存生存时间(秒)"
msgid "Save Cache"
msgstr "保存缓存"
msgid "Save the cache locally to reload the cache on the next startup"
msgstr "保存缓存到本地文件,以供下次启动时重新载入缓存"
msgid "Auto Save Cache Interval"
msgstr "自动保存缓存间隔(秒)"
msgid "Minimum TTL"
msgstr "覆盖最小 TTL 值(默认 0"

View File

@ -10,8 +10,9 @@ config mosdns 'config'
option configfile '/etc/mosdns/config.yaml'
option log_level 'info'
option logfile '/tmp/mosdns.log'
option cache_size '200000'
option cache_survival_time '259200'
option cache_size '20000'
option cache_survival_time '86400'
option dump_file '0'
option minimal_ttl '0'
option maximum_ttl '0'
option custom_local_dns '0'

View File

@ -30,8 +30,10 @@ get_config() {
config_get enabled $1 enabled 0
config_get adblock $1 adblock 0
config_get ad_source $1 ad_source ""
config_get cache_size $1 cache_size 200000
config_get cache_survival_time $1 cache_survival_time 259200
config_get cache_size $1 cache_size 20000
config_get cache_survival_time $1 cache_survival_time 86400
config_get dump_file $1 dump_file 0
config_get dump_interval $1 dump_interval 600
config_get enable_pipeline $1 enable_pipeline 0
config_get geo_auto_update $1 geo_auto_update 0
config_get geo_update_day_time $1 geo_update_day_time 2
@ -62,6 +64,7 @@ init_yaml() {
s,maximum_ttl_custom,$maximum_ttl_custom,g; \
s,adblock,$adlist,g;s,remote_dns_pipeline,$enable_pipeline,g" \
/usr/share/mosdns/default.yaml > $CONF
[ "$dump_file" -eq 1 ] && sed -i "/lazy_cache_ttl/a\ dump_file: /etc/mosdns/cache.dump\n dump_interval: $dump_interval" $CONF
echo "${local_dns}" > $tmpdir/local_dns.txt
echo "${remote_dns}" > $tmpdir/remote_dns.txt
sed -i -e '/- addr: local_dns/{r '$tmpdir/local_dns.txt -e';d};/- addr: remote_dns/{r '$tmpdir/remote_dns.txt -e';d}' \

Binary file not shown.