luci-app-adblock: small fixes in overview tab 1083/head
authorDirk Brenken <dev@brenken.org>
Mon, 27 Mar 2017 09:36:41 +0000 (11:36 +0200)
committerDirk Brenken <dev@brenken.org>
Mon, 27 Mar 2017 09:36:41 +0000 (11:36 +0200)
* mute stderr in syscalls
* better suspend/resume button handling

Signed-off-by: Dirk Brenken <dev@brenken.org>
applications/luci-app-adblock/luasrc/model/cbi/adblock/overview_tab.lua

index 51039232ab06c409fed43096d4ecef51b0dc7abb..7919b71516f7a9e8729650d901264a679d8b4672 100644 (file)
@@ -5,8 +5,8 @@
 local sys = require("luci.sys")
 local util = require("luci.util")
 local data = util.ubus("service", "get_data", "name", "adblock") or { }
-local dnsFile1 = sys.exec("find '/tmp/dnsmasq.d' -maxdepth 1 -type f -name 'adb_list*' -print")
-local dnsFile2 = sys.exec("find '/var/lib/unbound' -maxdepth 1 -type f -name 'adb_list*' -print")
+local dnsFile1 = sys.exec("find '/tmp/dnsmasq.d' -maxdepth 1 -type f -name 'adb_list*' -print 2>/dev/null")
+local dnsFile2 = sys.exec("find '/var/lib/unbound' -maxdepth 1 -type f -name 'adb_list*' -print 2>/dev/null")
 
 m = Map("adblock", translate("Adblock"),
        translate("Configuration of the adblock package to block ad/abuse domains by using DNS. ")
@@ -24,17 +24,24 @@ o1 = s:option(Flag, "adb_enabled", translate("Enable adblock"))
 o1.rmempty = false
 o1.default = 0
 
-if data.adblock ~= nil and (dnsFile1 ~= "" or dnsFile2 ~= "") then
-btn = s:option( Button, "_btn", translate("Suspend adblock"))
+btn = s:option(Button, "", translate("Suspend / Resume adblock"))
+if data.adblock == nil then
+       btn.inputtitle = "n/a"
+       btn.inputstyle = nil
+       btn.disabled = true
+elseif dnsFile1 ~= "" or dnsFile2 ~= "" then
+       btn.inputtitle = "Suspend adblock"
        btn.inputstyle = "reset"
+       btn.disabled = false
        function btn.write()
-               luci.sys.call("/etc/init.d/adblock suspend")
+               luci.sys.call("/etc/init.d/adblock suspend >/dev/null 2>&1")
        end
 else
-       btn = s:option( Button, "_btn", translate("Resume adblock"))
+       btn.inputtitle = "Resume adblock"
        btn.inputstyle = "apply"
+       btn.disabled = false
        function btn.write()
-               luci.sys.call("/etc/init.d/adblock resume")
+               luci.sys.call("/etc/init.d/adblock resume >/dev/null 2>&1")
        end
 end
 
@@ -53,44 +60,46 @@ o3.rmempty =false
        ds.template = "cbi/nullsection"
 
        dv1 = s:option(DummyValue, "adblock_version", translate("Adblock version"))
+       dv1.template = "adblock/runtime"
        if data.adblock ~= nil then
-               dv1.value = data.adblock.adblock.adblock_version or "?"
+               dv1.value = data.adblock.adblock.adblock_version or "n/a"
        else
-               dv1.value = "?"
+               dv1.value = "n/a"
        end
-       dv1.template = "adblock/runtime"
 
        dv2 = s:option(DummyValue, "status", translate("Status"))
-       if dnsFile1 ~= "" or dnsFile2 ~= "" then
+       dv2.template = "adblock/runtime"
+       if data.adblock == nil then
+               dv2.value = "n/a"
+       elseif dnsFile1 ~= "" or dnsFile2 ~= "" then
                dv2.value = "active"
        else
                dv2.value = "suspended"
        end
-       dv2.template = "adblock/runtime"
 
        dv3 = s:option(DummyValue, "dns_backend", translate("DNS backend"))
+       dv3.template = "adblock/runtime"
        if data.adblock ~= nil then
-               dv3.value = data.adblock.adblock.dns_backend or "?"
+               dv3.value = data.adblock.adblock.dns_backend or "n/a"
        else
-               dv3.value = "?"
+               dv3.value = "n/a"
        end
-       dv3.template = "adblock/runtime"
 
        dv4 = s:option(DummyValue, "blocked_domains", translate("Blocked domains (overall)"))
+       dv4.template = "adblock/runtime"
        if data.adblock ~= nil then
-               dv4.value = data.adblock.adblock.blocked_domains or "?"
+               dv4.value = data.adblock.adblock.blocked_domains or "n/a"
        else
-               dv4.value = "?"
+               dv4.value = "n/a"
        end
-       dv4.template = "adblock/runtime"
 
        dv5 = s:option(DummyValue, "last_rundate", translate("Last rundate"))
+       dv5.template = "adblock/runtime"
        if data.adblock ~= nil then
-               dv5.value = data.adblock.adblock.last_rundate or "?"
+               dv5.value = data.adblock.adblock.last_rundate or "n/a"
        else
-               dv5.value = "?"
+               dv5.value = "n/a"
        end
-       dv5.template = "adblock/runtime"
 
 -- Blocklist options