diff options
Diffstat (limited to 'applications/luci-app-simple-adblock/luasrc')
-rw-r--r-- | applications/luci-app-simple-adblock/luasrc/model/cbi/simple-adblock.lua | 86 | ||||
-rw-r--r-- | applications/luci-app-simple-adblock/luasrc/view/simple-adblock/buttons.htm | 49 |
2 files changed, 83 insertions, 52 deletions
diff --git a/applications/luci-app-simple-adblock/luasrc/model/cbi/simple-adblock.lua b/applications/luci-app-simple-adblock/luasrc/model/cbi/simple-adblock.lua index 0b38cf73ac..00674ab267 100644 --- a/applications/luci-app-simple-adblock/luasrc/model/cbi/simple-adblock.lua +++ b/applications/luci-app-simple-adblock/luasrc/model/cbi/simple-adblock.lua @@ -1,4 +1,4 @@ --- Copyright 2016-2018 Stan Grishin <stangri@melmac.net> +-- Copyright 2016-2018 Stan Grishin <stangri@melmac.ca> -- Licensed to the public under the Apache License 2.0. local packageName = "simple-adblock" @@ -12,6 +12,8 @@ local nutil = require "nixio.util" local http = require "luci.http" local dispatcher = require "luci.dispatcher" +local jsonStatusFile = "/var/run/" .. packageName .. "/" .. packageName .. ".json" + function getPackageVersion() local opkgFile = "/usr/lib/opkg/status" local line @@ -40,6 +42,7 @@ end function checkDnsmasq() return fs.access("/usr/sbin/dnsmasq") end function checkUnbound() return fs.access("/usr/sbin/unbound") end + function checkIpset() if fs.access("/usr/sbin/ipset") and sys.call("/usr/sbin/ipset help hash:net >/dev/null 2>&1") == 0 then return true @@ -48,6 +51,14 @@ function checkIpset() end end +function checkNftset() + if sys.call("command -v nft") == 0 then + return true + else + return false + end +end + function checkDnsmasqIpset() if checkDnsmasq() then local o = util.trim(util.exec("/usr/sbin/dnsmasq -v 2>/dev/null")) @@ -61,6 +72,19 @@ function checkDnsmasqIpset() end end +function checkDnsmasqNftset() + if checkDnsmasq() then + local o = util.trim(util.exec("/usr/sbin/dnsmasq -v 2>/dev/null")) + if not o:match("no%-nftset") and o:match("nftset") and checkNftset() then + return true + else + return false + end + else + return false + end +end + local enabledFlag = uci:get(packageName, "config", "enabled") local command, outputFile, outputCache, outputGzip local targetDNS = uci:get(packageName, "config", "dns") @@ -70,30 +94,34 @@ if not targetDNS or targetDNS == "" then end if targetDNS ~= "dnsmasq.addnhosts" and targetDNS ~= "dnsmasq.conf" and - targetDNS ~= "dnsmasq.ipset" and targetDNS ~= "dnsmasq.servers" and - targetDNS ~= "unbound.adb_list" then + targetDNS ~= "dnsmasq.ipset" and targetDNS ~= "dnsmasq.nftset" and + targetDNS ~= "dnsmasq.servers" and targetDNS ~= "unbound.adb_list" then targetDNS = "dnsmasq.servers" end if targetDNS == "dnsmasq.addnhosts" then - outputFile="/var/run/" .. packageName .. ".addnhosts" - outputCache="/var/run/" .. packageName .. ".addnhosts.cache" - outputGzip="/etc/" .. packageName .. ".addnhosts.gz" + outputFile="/var/run/" .. packageName .. "/dnsmasq.addnhosts" + outputCache="/var/run/" .. packageName .. "/dnsmasq.addnhosts.cache" + outputGzip="/etc/" .. packageName .. ".dnsmasq.addnhosts.gz" elseif targetDNS == "dnsmasq.conf" then - outputFile="/var/dnsmasq.d/" .. packageName .. "" - outputCache="/var/run/" .. packageName .. ".dnsmasq.cache" - outputGzip="/etc/" .. packageName .. ".dnsmasq.gz" + outputFile="/tmp/dnsmasq.d/" .. packageName + outputCache="/var/run/" .. packageName .. "/dnsmasq.conf.cache" + outputGzip="/etc/" .. packageName .. ".dnsmasq.conf.gz" elseif targetDNS == "dnsmasq.ipset" then - outputFile="/var/dnsmasq.d/" .. packageName .. ".ipset" - outputCache="/var/run/" .. packageName .. ".ipset.cache" - outputGzip="/etc/" .. packageName .. ".ipset.gz" + outputFile="/tmp/dnsmasq.d/" .. packageName .. ".ipset" + outputCache="/var/run/" .. packageName .. "/dnsmasq.ipset.cache" + outputGzip="/etc/" .. packageName .. ".dnsmasq.ipset.gz" +elseif targetDNS == "dnsmasq.nftset" then + outputFile="/tmp/dnsmasq.d/" .. packageName .. ".nftset" + outputCache="/var/run/" .. packageName .. "/dnsmasq.nftset.cache" + outputGzip="/etc/" .. packageName .. ".dnsmasq.nftset.gz" elseif targetDNS == "dnsmasq.servers" then - outputFile="/var/run/" .. packageName .. ".servers" - outputCache="/var/run/" .. packageName .. ".servers.cache" - outputGzip="/etc/" .. packageName .. ".servers.gz" + outputFile="/var/run/" .. packageName .. "/dnsmasq.servers" + outputCache="/var/run/" .. packageName .. "/dnsmasq.servers.cache" + outputGzip="/etc/" .. packageName .. ".dnsmasq.servers.gz" elseif targetDNS == "unbound.adb_list" then - outputFile="/var/lib/unbound/adb_list." .. packageName .. "" - outputCache="/var/run/" .. packageName .. ".unbound.cache" + outputFile="/var/lib/unbound/adb_list." .. packageName + outputCache="/var/run/" .. packageName .. "/unbound.cache" outputGzip="/etc/" .. packageName .. ".unbound.gz" end @@ -106,8 +134,8 @@ else tmpfsStatus = "statusStopped" end -if fs.access("/var/run/" .. packageName .. ".json") then - local f = io.open("/var/run/" .. packageName .. ".json") +if fs.access(jsonStatusFile) then + local f = io.open(jsonStatusFile) local s = f:read("*a") f:close() tmpfs = jsonc.parse(s) @@ -160,6 +188,7 @@ errorTable["errorDownloadingList"] = translate("failed to download") errorTable["errorParsingConfigUpdate"] = translate("failed to parse Config Update file") errorTable["errorParsingList"] = translate("failed to parse") errorTable["errorNoSSLSupport"] = translate("no HTTPS/SSL support on device") +errorTable["errorCreatingDirectory"] = translate("failed to create output/cache/gzip file directory") m = Map("simple-adblock", translate("Simple AdBlock Settings")) m.apply_on_parse = true @@ -273,8 +302,13 @@ if not checkDnsmasq() then dns_descr = dns_descr .. "<br />" .. translatef("Please note that %s is not supported on this system.", "<i>dnsmasq.conf</i>") dns_descr = dns_descr .. "<br />" .. translatef("Please note that %s is not supported on this system.", "<i>dnsmasq.ipset</i>") dns_descr = dns_descr .. "<br />" .. translatef("Please note that %s is not supported on this system.", "<i>dnsmasq.servers</i>") -elseif not checkDnsmasqIpset() then - dns_descr = dns_descr .. "<br />" .. translatef("Please note that %s is not supported on this system.", "<i>dnsmasq.ipset</i>") +else + if not checkDnsmasqIpset() then + dns_descr = dns_descr .. "<br />" .. translatef("Please note that %s is not supported on this system.", "<i>dnsmasq.ipset</i>") + end + if not checkDnsmasqNftset() then + dns_descr = dns_descr .. "<br />" .. translatef("Please note that %s is not supported on this system.", "<i>dnsmasq.nftset</i>") + end end if not checkUnbound() then dns_descr = dns_descr .. "<br />" .. translatef("Please note that %s is not supported on this system.", "<i>unbound.adb_list</i>") @@ -287,6 +321,9 @@ if checkDnsmasq() then if checkDnsmasqIpset() then dns:value("dnsmasq.ipset", translate("DNSMASQ IP Set")) end + if checkDnsmasqNftset() then + dns:value("dnsmasq.nftset", translate("DNSMASQ NFT Set")) + end dns:value("dnsmasq.servers", translate("DNSMASQ Servers File")) end if checkUnbound() then @@ -333,26 +370,21 @@ s2 = m:section(NamedSection, "config", "simple-adblock", translate("Allowed and -- Allowed Domains d1 = s2:option(DynamicList, "allowed_domain", translate("Allowed Domains"), translate("Individual domains to be allowed.")) d1.addremove = false -d1.optional = false -- Allowed Domains URLs d2 = s2:option(DynamicList, "allowed_domains_url", translate("Allowed Domain URLs"), translate("URLs to lists of domains to be allowed.")) d2.addremove = false -d2.optional = false -- Blocked Domains d3 = s2:option(DynamicList, "blocked_domain", translate("Blocked Domains"), translate("Individual domains to be blocked.")) d3.addremove = false -d3.optional = false -- Blocked Domains URLs d4 = s2:option(DynamicList, "blocked_domains_url", translate("Blocked Domain URLs"), translate("URLs to lists of domains to be blocked.")) d4.addremove = false -d4.optional = false -- Blocked Hosts URLs d5 = s2:option(DynamicList, "blocked_hosts_url", translate("Blocked Hosts URLs"), translate("URLs to lists of hosts to be blocked.")) d5.addremove = false -d5.optional = false -return m
\ No newline at end of file +return m diff --git a/applications/luci-app-simple-adblock/luasrc/view/simple-adblock/buttons.htm b/applications/luci-app-simple-adblock/luasrc/view/simple-adblock/buttons.htm index 64df62142a..c8d4e5e8a6 100644 --- a/applications/luci-app-simple-adblock/luasrc/view/simple-adblock/buttons.htm +++ b/applications/luci-app-simple-adblock/luasrc/view/simple-adblock/buttons.htm @@ -1,4 +1,4 @@ -<%# Copyright 2020 Stan Grishin <stangri@melmac.net> -%> +<%# Copyright 2020 Stan Grishin <stangri@melmac.ca> -%> <%+simple-adblock/css%> <%+simple-adblock/js%> @@ -7,8 +7,9 @@ local packageName = "simple-adblock" local serviceRunning, serviceEnabled = false, false; local tmpfs, tmpfsStatus; - if nixio.fs.access("/var/run/" .. packageName .. ".json") then - tmpfs = luci.jsonc.parse(luci.util.trim(luci.sys.exec("cat /var/run/" .. packageName .. ".json"))) + local jsonStatusFile = "/var/run/" .. packageName .. "/" .. packageName .. ".json" + if nixio.fs.access(jsonStatusFile) then + tmpfs = luci.jsonc.parse(luci.util.trim(luci.sys.exec("cat " .. jsonStatusFile))) if tmpfs and tmpfs['data'] and tmpfs['data']['status'] then tmpfsStatus = tmpfs['data']['status'] end @@ -48,27 +49,25 @@ -%> <%+cbi/valueheader%> - <div class="cbi-value-field"> - <input type="button" class="btn cbi-button cbi-button-apply" id="btn_start" name="start" value="<%:Start%>" - onclick="button_action(this)" /> - <span id="btn_start_spinner" class="btn_spinner"></span> - <input type="button" class="btn cbi-button cbi-button-apply" id="btn_action" name="action" value="<%:Force Re-Download%>" - onclick="button_action(this)" /> - <span id="btn_action_spinner" class="btn_spinner"></span> - <input type="button" class="btn cbi-button cbi-button-reset" id="btn_stop" name="stop" value="<%:Stop%>" - onclick="button_action(this)" /> - <span id="btn_stop_spinner" class="btn_spinner"></span> -   -   -   -   - <input type="button" class="btn cbi-button cbi-button-apply" id="btn_enable" name="enable" value="<%:Enable%>" - onclick="button_action(this)" /> - <span id="btn_enable_spinner" class="btn_spinner"></span> - <input type="button" class="btn cbi-button cbi-button-reset" id="btn_disable" name="disable" value="<%:Disable%>" - onclick="button_action(this)" /> - <span id="btn_disable_spinner" class="btn_spinner"></span> - </div> + <input type="button" class="btn cbi-button cbi-button-apply" id="btn_start" name="start" value="<%:Start%>" + onclick="button_action(this)" /> + <span id="btn_start_spinner" class="btn_spinner"></span> + <input type="button" class="btn cbi-button cbi-button-apply" id="btn_action" name="action" value="<%:Force Re-Download%>" + onclick="button_action(this)" /> + <span id="btn_action_spinner" class="btn_spinner"></span> + <input type="button" class="btn cbi-button cbi-button-reset" id="btn_stop" name="stop" value="<%:Stop%>" + onclick="button_action(this)" /> + <span id="btn_stop_spinner" class="btn_spinner"></span> +   +   +   +   + <input type="button" class="btn cbi-button cbi-button-apply" id="btn_enable" name="enable" value="<%:Enable%>" + onclick="button_action(this)" /> + <span id="btn_enable_spinner" class="btn_spinner"></span> + <input type="button" class="btn cbi-button cbi-button-reset" id="btn_disable" name="disable" value="<%:Disable%>" + onclick="button_action(this)" /> + <span id="btn_disable_spinner" class="btn_spinner"></span> <%+cbi/valuefooter%> <%-if not btn_start_status then%> @@ -85,4 +84,4 @@ <%-end%> <%-if not btn_disable_status then%> <script type="text/javascript">document.getElementById("btn_disable").disabled = true;</script> -<%-end%>
\ No newline at end of file +<%-end%> |