From e138175cb42095c778b0ae51e6db1f650432adf6 Mon Sep 17 00:00:00 2001 From: sbwml <984419930@qq.com> Date: Sat, 25 Mar 2023 00:56:05 +0800 Subject: [PATCH] luci-app-mosdns: Add DNS cache saving support --- luci-app-mosdns/Makefile | 1 + luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua | 14 ++++++++++++-- luci-app-mosdns/po/zh-cn/mosdns.po | 9 +++++++++ luci-app-mosdns/root/etc/config/mosdns | 5 +++-- luci-app-mosdns/root/etc/init.d/mosdns | 7 +++++-- luci-app-mosdns/root/etc/mosdns/cache.dump | Bin 0 -> 36 bytes 6 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 luci-app-mosdns/root/etc/mosdns/cache.dump diff --git a/luci-app-mosdns/Makefile b/luci-app-mosdns/Makefile index d4b3513..b105f8a 100644 --- a/luci-app-mosdns/Makefile +++ b/luci-app-mosdns/Makefile @@ -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 diff --git a/luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua b/luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua index 4c2d218..e4a6a25 100644 --- a/luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua +++ b/luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua @@ -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))" diff --git a/luci-app-mosdns/po/zh-cn/mosdns.po b/luci-app-mosdns/po/zh-cn/mosdns.po index 31f431c..a692d29 100644 --- a/luci-app-mosdns/po/zh-cn/mosdns.po +++ b/luci-app-mosdns/po/zh-cn/mosdns.po @@ -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)" diff --git a/luci-app-mosdns/root/etc/config/mosdns b/luci-app-mosdns/root/etc/config/mosdns index 44558f1..31c054a 100644 --- a/luci-app-mosdns/root/etc/config/mosdns +++ b/luci-app-mosdns/root/etc/config/mosdns @@ -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' diff --git a/luci-app-mosdns/root/etc/init.d/mosdns b/luci-app-mosdns/root/etc/init.d/mosdns index 88e5e34..fc3b4c7 100755 --- a/luci-app-mosdns/root/etc/init.d/mosdns +++ b/luci-app-mosdns/root/etc/init.d/mosdns @@ -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}' \ diff --git a/luci-app-mosdns/root/etc/mosdns/cache.dump b/luci-app-mosdns/root/etc/mosdns/cache.dump new file mode 100644 index 0000000000000000000000000000000000000000..ab98d152ed7b6feb017e319f08e83df8fc3dad56 GIT binary patch literal 36 kcmb2|=HOu9%