Add status of process

This commit is contained in:
Nick Peng
2018-08-03 22:49:55 +08:00
parent f5863e4d82
commit 08c1f5e8d1
9 changed files with 178 additions and 101 deletions

View File

@@ -8,7 +8,18 @@ function index()
end
local page
page = entry({"admin", "services", "smartdns"}, cbi("smartdns"), _("SmartDNS"), 60)
page.dependent = true
page = entry({"admin", "services", "smartdns", "status"}, call("act_status"))
page.leaf = true
end
local function is_running()
return luci.sys.call("pidof smartdns >/dev/null") == 0
end
function act_status()
local e={}
e.running = is_running()
luci.http.prepare_content("application/json")
luci.http.write_json(e)
end

View File

@@ -4,6 +4,15 @@ msgstr "Content-Type: text/plain; charset=UTF-8\n"
msgid "SmartDNS"
msgstr "SmartDNS"
msgid "SmartDNS is a local high-performance DNS server"
msgstr "SmartDNS是一个本地高性能DNS服务器"
msgid "SmartDNS Server"
msgstr "SmartDNS 服务器"
msgid "SmartDNS is a local high-performance DNS server, supports finding fastest IP, supports ad filtering, and supports avoiding DNS poisoning."
msgstr "SmartDNS是一个本地高性能DNS服务器支持避免域名污染支持返回最快IP支持广告过滤。"
msgid "Server Name"
msgstr "服务器名称"
@@ -22,8 +31,8 @@ msgstr "SmartDNS本地服务端口"
msgid "Redirect"
msgstr "重定向"
msgid "Redirect standard dns query from 53 to smartdns"
msgstr "将53端口的DNS请求重定向到SmartDNS"
msgid "Redirect standard dns query from 53 to smartdns, as default DNS server"
msgstr "将53端口的DNS请求重定向到SmartDNS, 替换默认DNS服务"
msgid "Cache Size"
msgstr "缓存大小"

View File

@@ -1,16 +1,15 @@
-- Copyright 2018 Nick Peng (pymumu@gmail.com)
require("nixio.fs")
require("luci.http")
require ("nixio.fs")
require ("luci.http")
require ("luci.dispatcher")
require ("nixio.fs")
m = Map("smartdns", translate("SmartDNS"),
translate("SmartDNS is a local dns server to find fastest ip."))
m = Map("smartdns")
m.title = translate("SmartDNS Server")
m.description = translate("SmartDNS is a local high-performance DNS server, supports finding fastest IP, supports ad filtering, and supports avoiding DNS poisoning.")
if luci.sys.call("pidof smartdns >/dev/null") == 0 then
m = Map("smartdns", translate("SmartDNS"), "%s - %s" %{translate("SmartDNS"), translate("RUNNING")})
else
m = Map("smartdns", translate("SmartDNS"), "%s - %s" %{translate("SmartDNS"), translate("NOT RUNNING")})
end
m:section(SimpleSection).template = "smartdns/smartdns_status"
-- Basic
s = m:section(TypedSection, "smartdns", translate("Settings"), translate("General Settings"))
@@ -18,6 +17,7 @@ s.anonymous = true
---- Eanble
o = s:option(Flag, "enabled", translate("Enable"), translate("Enable or disable smartdns server"))
o.default = o.disabled
o.rempty = false
---- server name
@@ -33,10 +33,12 @@ o.default = 5353
o.datatype = "port"
o.rempty = false
o = s:option(Flag, "redirect", translate("Redirect"), translate("Redirect standard dns query from 53 to smartdns"))
o.default = true
o.placeholder = "1"
o.rempty = false
o = s:option(Flag, "redirect", translate("Redirect"), translate("Redirect standard dns query from 53 to smartdns, as default DNS server"))
o.rmempty = false
o.default = o.enabled
o.cfgvalue = function(...)
return Flag.cfgvalue(...) or "1"
end
---- cache-size
o = s:option(Value, "cache_size", translate("Cache Size"), translate("DNS domain result cache size"))

View File

@@ -0,0 +1,22 @@
<script type="text/javascript">//<![CDATA[
XHR.poll(3, '<%=luci.dispatcher.build_url("admin", "services", "smartdns", "status")%>', null,
function(x, data) {
var tb = document.getElementById('smartdns_status');
if (data && tb) {
if (data.running) {
var links = '<b><font color=green>SmartDNS - <%:RUNNING%></font></b></em>';
tb.innerHTML = links;
} else {
tb.innerHTML = '<b><font color=red>SmartDNS - <%:NOT RUNNING%></font></b>';
}
}
}
);
//]]>
</script>
<style>.mar-10 {margin-left: 50px; margin-right: 10px;}</style>
<fieldset class="cbi-section">
<p id="smartdns_status">
<em><%:Collecting data...%></em>
</p>
</fieldset>