summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-simple-adblock/luasrc/model/cbi/simple-adblock.lua
diff options
context:
space:
mode:
authorStan Grishin <stangri@melmac.ca>2022-08-24 03:03:42 +0300
committerGitHub <noreply@github.com>2022-08-24 03:03:42 +0300
commitf5e53402bab1333f1e3042b20eb97fe93b07045a (patch)
treee3b94b67d0e270e721fef78d38e4c243a4f2ba8d /applications/luci-app-simple-adblock/luasrc/model/cbi/simple-adblock.lua
parent541eaab1c941c952c110a83333c65bf7d1158b37 (diff)
parent9b71a35428e0ddbf0347c8ba62da2f4168ddb21b (diff)
Merge pull request #5940 from stangri/master-luci-app-simple-adblock
luci-app-simple-adblock: update to 1.9.0-1
Diffstat (limited to 'applications/luci-app-simple-adblock/luasrc/model/cbi/simple-adblock.lua')
-rw-r--r--applications/luci-app-simple-adblock/luasrc/model/cbi/simple-adblock.lua86
1 files changed, 59 insertions, 27 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