luci-app-mosdns: API: Add flush cache function
This commit is contained in:
parent
eddbeb7837
commit
0df11e88d2
@ -20,6 +20,7 @@ function index()
|
|||||||
entry({"admin", "services", "mosdns", "get_log"}, call("get_log")).leaf = true
|
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", "clear_log"}, call("clear_log")).leaf = true
|
||||||
entry({"admin", "services", "mosdns", "geo_update"}, call("geo_update")).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
|
end
|
||||||
|
|
||||||
function act_status()
|
function act_status()
|
||||||
@ -43,3 +44,10 @@ function geo_update()
|
|||||||
http.prepare_content("application/json")
|
http.prepare_content("application/json")
|
||||||
http.write_json(e)
|
http.write_json(e)
|
||||||
end
|
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
|
||||||
|
@ -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 = s:taboption("basic", Button, "_reload", translate("Reload Service"), translate("Reload service to take effect of new configuration"))
|
||||||
o.write = function()
|
o.write = function()
|
||||||
sys.exec("/etc/init.d/mosdns reload")
|
sys.exec("/etc/init.d/mosdns reload")
|
||||||
end
|
end
|
||||||
o:depends("configfile", "/etc/mosdns/config_custom.yaml")
|
o:depends("configfile", "/etc/mosdns/config_custom.yaml")
|
||||||
|
|
||||||
@ -200,4 +200,9 @@ o.datatype = "and(port,min(1))"
|
|||||||
o.default = 9091
|
o.default = 9091
|
||||||
o:depends("configfile", "/etc/mosdns/config.yaml")
|
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
|
return m
|
||||||
|
34
luci-app-mosdns/luasrc/view/mosdns/mosdns_flush_cache.htm
Normal file
34
luci-app-mosdns/luasrc/view/mosdns/mosdns_flush_cache.htm
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<%+cbi/valueheader%>
|
||||||
|
<script type="text/javascript">//<![CDATA[
|
||||||
|
function flush_cache(btn, dataname)
|
||||||
|
{
|
||||||
|
btn.disabled = true;
|
||||||
|
btn.value = '<%:Flushing...%> ';
|
||||||
|
st=dataname;
|
||||||
|
XHR.get('<%=luci.dispatcher.build_url("admin", "services", "mosdns", "flush_cache")%>',
|
||||||
|
{ set:st },
|
||||||
|
function(x,data)
|
||||||
|
{
|
||||||
|
var tb = document.getElementById(dataname+'-status');
|
||||||
|
if (tb)
|
||||||
|
{
|
||||||
|
switch (data.flushing)
|
||||||
|
{
|
||||||
|
case true:
|
||||||
|
tb.innerHTML = "<font color='green'>" + "<%:Flushing Success%>" + "</font>";
|
||||||
|
break;
|
||||||
|
case false:
|
||||||
|
tb.innerHTML = "<font color='red'>" + "<%:Flushing Failed, Please check if the API is enabled%>" + "</font>";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
btn.disabled = false;
|
||||||
|
btn.value = '<%:Flush Cache%>';
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//]]></script>
|
||||||
|
<input type="button" class="btn cbi-button cbi-button-reload" value="<%:Flush Cache%>" onclick="return flush_cache(this,'<%=self.option%>')" />
|
||||||
|
<span id="<%=self.option%>-status"><em><%=self.value%></em></span>
|
||||||
|
<%+cbi/valuefooter%>
|
@ -34,6 +34,21 @@ msgstr "启用 API"
|
|||||||
msgid "API Listen port"
|
msgid "API Listen port"
|
||||||
msgstr "API 监听端口"
|
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"
|
msgid "Log Level"
|
||||||
msgstr "日志等级"
|
msgstr "日志等级"
|
||||||
|
|
||||||
|
@ -94,6 +94,10 @@ ecs_remote() {
|
|||||||
echo "ecs ${ipaddr%.*}.0/24"
|
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
|
case $script_action in
|
||||||
"dns")
|
"dns")
|
||||||
interface_dns
|
interface_dns
|
||||||
@ -116,6 +120,9 @@ case $script_action in
|
|||||||
"ecs_remote")
|
"ecs_remote")
|
||||||
ecs_remote
|
ecs_remote
|
||||||
;;
|
;;
|
||||||
|
"flush")
|
||||||
|
flush_cache
|
||||||
|
;;
|
||||||
"version")
|
"version")
|
||||||
mosdns version
|
mosdns version
|
||||||
;;
|
;;
|
||||||
|
Loading…
Reference in New Issue
Block a user