diff --git a/luci-app-mosdns/luasrc/controller/mosdns.lua b/luci-app-mosdns/luasrc/controller/mosdns.lua
index 6ada27b..60840fb 100644
--- a/luci-app-mosdns/luasrc/controller/mosdns.lua
+++ b/luci-app-mosdns/luasrc/controller/mosdns.lua
@@ -20,6 +20,7 @@ function index()
entry({"admin", "services", "mosdns", "get_log"}, call("get_log")).leaf = true
entry({"admin", "services", "mosdns", "clear_log"}, call("clear_log")).leaf = true
entry({"admin", "services", "mosdns", "geo_update"}, call("geo_update")).leaf = true
+ entry({"admin", "services", "mosdns", "flush_cache"}, call("flush_cache")).leaf = true
end
function act_status()
@@ -43,3 +44,10 @@ function geo_update()
http.prepare_content("application/json")
http.write_json(e)
end
+
+function flush_cache()
+ local e = {}
+ e.flushing = sys.call("/usr/share/mosdns/mosdns.sh flush >/dev/null") == 0
+ http.prepare_content("application/json")
+ http.write_json(e)
+end
diff --git a/luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua b/luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua
index 380bae3..3d693c6 100644
--- a/luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua
+++ b/luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua
@@ -170,7 +170,7 @@ o:value("https://raw.githubusercontent.com/QiuSimons/openwrt-mos/master/dat/serv
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")
+ sys.exec("/etc/init.d/mosdns reload")
end
o:depends("configfile", "/etc/mosdns/config_custom.yaml")
@@ -200,4 +200,9 @@ o.datatype = "and(port,min(1))"
o.default = 9091
o:depends("configfile", "/etc/mosdns/config.yaml")
+o = s:taboption("api", Button, "flush_cache", translate("Flush Cache"), translate("Flushing Cache will clear any IP addresses or DNS records from MosDNS cache"))
+o.rawhtml = true
+o.template = "mosdns/mosdns_flush_cache"
+o:depends("enabled_api", "1")
+
return m
diff --git a/luci-app-mosdns/luasrc/view/mosdns/mosdns_flush_cache.htm b/luci-app-mosdns/luasrc/view/mosdns/mosdns_flush_cache.htm
new file mode 100644
index 0000000..f462ce3
--- /dev/null
+++ b/luci-app-mosdns/luasrc/view/mosdns/mosdns_flush_cache.htm
@@ -0,0 +1,34 @@
+<%+cbi/valueheader%>
+
+
+<%=self.value%>
+<%+cbi/valuefooter%>
diff --git a/luci-app-mosdns/po/zh-cn/mosdns.po b/luci-app-mosdns/po/zh-cn/mosdns.po
index ffbf944..eba7c14 100644
--- a/luci-app-mosdns/po/zh-cn/mosdns.po
+++ b/luci-app-mosdns/po/zh-cn/mosdns.po
@@ -34,6 +34,21 @@ msgstr "启用 API"
msgid "API Listen port"
msgstr "API 监听端口"
+msgid "Flush Cache"
+msgstr "刷新缓存"
+
+msgid "Flushing Cache will clear any IP addresses or DNS records from MosDNS cache"
+msgstr "刷新缓存会清空 MosDNS 所有 IP 地址和 DNS 解析缓存"
+
+msgid "Flushing..."
+msgstr "正在刷新..."
+
+msgid "Flushing Success"
+msgstr "刷新成功"
+
+msgid "Flushing Failed, Please check if the API is enabled"
+msgstr "刷新失败,请检查 API 是否已启用"
+
msgid "Log Level"
msgstr "日志等级"
diff --git a/luci-app-mosdns/root/usr/share/mosdns/mosdns.sh b/luci-app-mosdns/root/usr/share/mosdns/mosdns.sh
index 9fd6fd3..06332b0 100755
--- a/luci-app-mosdns/root/usr/share/mosdns/mosdns.sh
+++ b/luci-app-mosdns/root/usr/share/mosdns/mosdns.sh
@@ -94,6 +94,10 @@ ecs_remote() {
echo "ecs ${ipaddr%.*}.0/24"
}
+flush_cache() {
+ curl -s 127.0.0.1:$(uci -q get mosdns.config.listen_port_api)/plugins/cache/flush || exit 1
+}
+
case $script_action in
"dns")
interface_dns
@@ -116,6 +120,9 @@ case $script_action in
"ecs_remote")
ecs_remote
;;
+ "flush")
+ flush_cache
+ ;;
"version")
mosdns version
;;