summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-https_dns_proxy/luasrc/model/cbi
diff options
context:
space:
mode:
authorStan Grishin <stangri@melmac.net>2019-11-13 04:25:53 -0700
committerStan Grishin <stangri@melmac.net>2019-11-13 04:25:53 -0700
commit5a81e4f6c1d556de3d7fbdabfc68ba6a1429dcfc (patch)
treeb8183182edd97ae07d1d0faec4479ea44a0afe8a /applications/luci-app-https_dns_proxy/luasrc/model/cbi
parent8da8f38bf97c925f6f113d3b4793edb23e7e0dc2 (diff)
luci-app-https_dns_proxy: remove dnsmasq integration, better service controls, providers as plugins, misc fixes
Signed-off-by: Stan Grishin <stangri@melmac.net>
Diffstat (limited to 'applications/luci-app-https_dns_proxy/luasrc/model/cbi')
-rw-r--r--applications/luci-app-https_dns_proxy/luasrc/model/cbi/https_dns_proxy.lua226
1 files changed, 100 insertions, 126 deletions
diff --git a/applications/luci-app-https_dns_proxy/luasrc/model/cbi/https_dns_proxy.lua b/applications/luci-app-https_dns_proxy/luasrc/model/cbi/https_dns_proxy.lua
index 17ce610eab..4e7e02524f 100644
--- a/applications/luci-app-https_dns_proxy/luasrc/model/cbi/https_dns_proxy.lua
+++ b/applications/luci-app-https_dns_proxy/luasrc/model/cbi/https_dns_proxy.lua
@@ -1,144 +1,118 @@
+local sys = require "luci.sys"
+local util = require "luci.util"
+local fs = require "nixio.fs"
+local dispatcher = require "luci.dispatcher"
+local i18n = require "luci.i18n"
local uci = require("luci.model.uci").cursor()
-local dispatcher = require("luci.dispatcher")
-function uci_del_list(conf, sect, opt, value)
- local lval = uci:get(conf, sect, opt)
- if lval == nil or lval == "" then
- lval = {}
- elseif type(lval) ~= "table" then
- lval = { lval }
- end
+local packageName = "https_dns_proxy"
+local providers_dir = "/usr/lib/lua/luci/" .. packageName .. "/providers/"
- local i
- local changed = false
- for i = #lval, 1 do
- if lval[i] == value then
- table.remove(lval, i)
- changed = true
- end
- end
-
- if changed then
- if #lval > 0 then
- uci:set(conf, sect, opt, lval)
- else
- uci:delete(conf, sect, opt)
- end
- end
+function get_provider_name(value)
+ for filename in fs.dir(providers_dir) do
+ local p_func = loadfile(providers_dir .. filename)
+ setfenv(p_func, { _ = i18n.translate })
+ local p = p_func()
+ value = value:gsub('[%p%c%s]', '')
+ p.url_match = p.url_prefix:gsub('[%p%c%s]', '')
+ if value:match(p.url_match) then
+ return p.label
+ end
+ end
+ return translate("Uknown Provider")
end
-function uci_add_list(conf, sect, opt, value)
- local lval = uci:get(conf, sect, opt)
- if lval == nil or lval == "" then
- lval = {}
- elseif type(lval) ~= "table" then
- lval = { lval }
- end
+local tmpfsStatus, tmpfsStatusCode
+local ubusStatus = util.ubus("service", "list", { name = packageName })
+local tmpfsVersion = tostring(util.trim(sys.exec("opkg list-installed " .. packageName .. " | awk '{print $3}'")))
- lval[#lval+1] = value
- uci:set(conf, sect, opt, lval)
+if not tmpfsVersion or tmpfsVersion == "" then
+ tmpfsStatusCode = -1
+ tmpfsVersion = ""
+ tmpfsStatus = packageName .. " " .. translate("is not installed or not found")
+else
+ tmpfsVersion = " [" .. packageName .. " " .. tmpfsVersion .. "]"
+ if not ubusStatus or not ubusStatus[packageName] then
+ tmpfsStatusCode = 0
+ tmpfsStatus = translate("Stopped")
+ else
+ tmpfsStatusCode, tmpfsStatus = 1, ""
+ for n = 1,1000 do
+ if ubusStatus and ubusStatus[packageName] and
+ ubusStatus[packageName]["instances"] and
+ ubusStatus[packageName]["instances"]["instance" .. n] and
+ ubusStatus[packageName]["instances"]["instance" .. n]["running"] then
+ local value, k, v, url, url_flag, la, la_flag, lp, lp_flag
+ for k, v in pairs(ubusStatus[packageName]["instances"]["instance" .. n]["command"]) do
+ if la_flag then la, la_flag = v, false end
+ if lp_flag then lp, lp_flag = v, false end
+ if url_flag then url, url_flag = v, false end
+ if v == "-a" then la_flag = true end
+ if v == "-p" then lp_flag = true end
+ if v == "-r" then url_flag = true end
+ end
+ la = la or "127.0.0.1"
+ lp = lp or n + 5053
+ tmpfsStatus = tmpfsStatus .. translate("Running") .. ": " .. get_provider_name(url) .. " " .. translate("DoH") .. " " .. translate("at") .. " " .. la .. ":" .. lp .. "\n"
+ else
+ break
+ end
+ end
+ end
end
-m = Map("https_dns_proxy", translate("HTTPS DNS Proxy Settings"))
-m.template="cbi/map"
+m = Map("https_dns_proxy", translate("DNS over HTTPS Proxy Settings"))
+
+h = m:section(TypedSection, "_dummy", translate("Service Status") .. tmpfsVersion)
+h.template = "cbi/nullsection"
+ss = h:option(DummyValue, "_dummy", translate("Service Status"))
+if tmpfsStatusCode == -1 then
+ ss.template = packageName .. "/status"
+ ss.value = tmpfsStatus
+else
+ if tmpfsStatusCode == 0 then
+ ss.template = packageName .. "/status"
+ else
+ ss.template = packageName .. "/status-textarea"
+ end
+ ss.value = tmpfsStatus
+ buttons = h:option(DummyValue, "_dummy")
+ buttons.template = packageName .. "/buttons"
+end
s3 = m:section(TypedSection, "https_dns_proxy", translate("Instances"), translate("When you add/remove any instances below, they will be used to override the 'DNS forwardings' section of ")
.. [[ <a href="]] .. dispatcher.build_url("admin/network/dhcp") .. [[">]]
- .. translate("DHCP and DNS") .. [[</a>]] .. "."
--- .. "</br>"
--- .. translate("For more information on different options check ")
--- .. [[ <a href="https://adguard.com/en/adguard-dns/overview.html#instruction">]]
--- .. "AdGuard.com" .. [[</a>]] .. ", "
--- .. [[ <a href="https://cleanbrowsing.org/guides/dnsoverhttps">]]
--- .. "CleanBrowsing.org" .. [[</a>]] .. " " .. translate("and") .. " "
--- .. [[ <a href="https://www.quad9.net/doh-quad9-dns-servers/">]]
--- .. "Quad9.net" .. [[</a>]] .. "."
- )
+ .. translate("DHCP and DNS") .. [[</a>]] .. ".")
s3.template = "cbi/tblsection"
s3.sortable = false
s3.anonymous = true
s3.addremove = true
prov = s3:option(ListValue, "url_prefix", translate("Provider"))
--- prov:value("https://dns.adguard.com/dns-query?", "AdGuard (Standard)")
--- prov:value("https://dns-family.adguard.com/dns-query?", "AdGuard (Family Protection)")
--- prov:value("https://doh.cleanbrowsing.org/doh/security-filter/?ct&", "CleanBrowsing (Security Filter)")
--- prov:value("https://doh.cleanbrowsing.org/doh/family-filter/?ct&", "CleanBrowsing (Family Filter)")
--- prov:value("https://doh.cleanbrowsing.org/doh/adult-filter/?ct&", "CleanBrowsing (Adult Filter)")
-prov:value("https://cloudflare-dns.com/dns-query?ct=application/dns-json&", "Cloudflare")
--- prov:value("https://dns.digitale-gesellschaft.ch/dns-query?", "Digitale Gesellschaft (ch)")
-prov:value("https://doh.dns.sb/dns-query?", "DNS.SB")
-prov:value("https://dns.google.com/resolve?", "Google")
--- prov:value("https://odvr.nic.cz/doh?", "ODVR (nic.cz)")
--- prov:value("https://dns.quad9.net:5053/dns-query?", "Quad9 (Recommended)")
--- prov:value("https://dns9.quad9.net:5053/dns-query?", "Quad9 (Secured)")
--- prov:value("https://dns10.quad9.net:5053/dns-query?", "Quad9 (Unsecured)")
--- prov:value("https://dns11.quad9.net:5053/dns-query?", "Quad9 (Secured with ECS Support)")
-prov.default = "https://dns.google.com/resolve?"
+for filename in fs.dir(providers_dir) do
+ local p_func = loadfile(providers_dir .. filename)
+ setfenv(p_func, { _ = i18n.translate })
+ local p = p_func()
+ prov:value(p.url_prefix, p.label)
+ if p.default then
+ prov.default = p.url_prefix
+ end
+end
prov.forcewrite = true
prov.write = function(self, section, value)
- if not value then return end
- local n = 0
- uci:foreach("https_dns_proxy", "https_dns_proxy", function(s)
- if s[".name"] == section then
- return false
- end
- n = n + 1
- end)
- local la_val = la:formvalue(section)
- local lp_val = lp:formvalue(section)
- if not la_val or la_val == "" then la_val = "127.0.0.1" end
- if not lp_val or lp_val == "" then lp_val = n + 5053 end
- if value:match("dns\.adguard") then
- uci:set("https_dns_proxy", section, "bootstrap_dns", "176.103.130.130,176.103.130.131")
- uci:set("https_dns_proxy", section, "url_prefix", "https://dns.adguard.com/dns-query?ct&")
- elseif value:match("family\.adguard") then
- uci:set("https_dns_proxy", section, "bootstrap_dns", "176.103.130.132,176.103.130.134")
- uci:set("https_dns_proxy", section, "url_prefix", "https://dns-family.adguard.com/dns-query?ct&")
- elseif value:match("cleanbrowsing\.org/doh/security") then
- uci:set("https_dns_proxy", section, "bootstrap_dns", "185.228.168.168")
- uci:set("https_dns_proxy", section, "url_prefix", "https://doh.cleanbrowsing.org/doh/security-filter/?ct&")
- elseif value:match("cleanbrowsing\.org/doh/family") then
- uci:set("https_dns_proxy", section, "bootstrap_dns", "185.228.168.168")
- uci:set("https_dns_proxy", section, "url_prefix", "https://doh.cleanbrowsing.org/doh/family-filter/?ct&")
- elseif value:match("cleanbrowsing\.org/doh/adult") then
- uci:set("https_dns_proxy", section, "bootstrap_dns", "185.228.168.168")
- uci:set("https_dns_proxy", section, "url_prefix", "https://doh.cleanbrowsing.org/doh/adult-filter/?ct&")
- elseif value:match("cloudflare") then
- uci:set("https_dns_proxy", section, "bootstrap_dns", "1.1.1.1,1.0.0.1")
- uci:set("https_dns_proxy", section, "url_prefix", "https://cloudflare-dns.com/dns-query?ct=application/dns-json&")
- elseif value:match("gesellschaft\.ch") then
- uci:set("https_dns_proxy", section, "bootstrap_dns", "185.95.218.42,185.95.218.43")
- uci:set("https_dns_proxy", section, "url_prefix", "https://dns.digitale-gesellschaft.ch/dns-query?")
- elseif value:match("dns\.sb") then
- uci:set("https_dns_proxy", section, "bootstrap_dns", "185.222.222.222,185.184.222.222")
- uci:set("https_dns_proxy", section, "url_prefix", "https://doh.dns.sb/dns-query?")
- elseif value:match("google") then
- uci:set("https_dns_proxy", section, "bootstrap_dns", "8.8.8.8,8.8.4.4")
- uci:set("https_dns_proxy", section, "url_prefix", "https://dns.google.com/resolve?")
- elseif value:match("odvr\.nic\.cz") then
- uci:set("https_dns_proxy", section, "bootstrap_dns", "193.17.47.1,185.43.135.1")
- uci:set("https_dns_proxy", section, "url_prefix", "https://odvr.nic.cz/doh?")
- elseif value:match("dns\.quad9") then
- uci:set("https_dns_proxy", section, "bootstrap_dns", "9.9.9.9,149.112.112.112")
- uci:set("https_dns_proxy", section, "url_prefix", "https://dns.quad9.net:5053/dns-query?")
- elseif value:match("dns9\.quad9") then
- uci:set("https_dns_proxy", section, "bootstrap_dns", "9.9.9.9,149.112.112.9")
- uci:set("https_dns_proxy", section, "url_prefix", "https://dns9.quad9.net:5053/dns-query?")
- elseif value:match("dns10\.quad9") then
- uci:set("https_dns_proxy", section, "bootstrap_dns", "9.9.9.10,149.112.112.10")
- uci:set("https_dns_proxy", section, "url_prefix", "https://dns10.quad9.net:5053/dns-query?")
- elseif value:match("dns11\.quad9") then
- uci:set("https_dns_proxy", section, "bootstrap_dns", "9.9.9.11,149.112.112.11")
- uci:set("https_dns_proxy", section, "url_prefix", "https://dns11.quad9.net:5053/dns-query?")
- end
- uci:save("https_dns_proxy")
- if n == 0 then
- uci:delete("dhcp", "@dnsmasq[0]", "server")
- end
- uci_del_list("dhcp", "@dnsmasq[0]", "server", tostring(la_val) .. "#" .. tostring(lp_val))
- uci_add_list("dhcp", "@dnsmasq[0]", "server", tostring(la_val) .. "#" .. tostring(lp_val))
- uci:save("dhcp")
+ if not value then return end
+ for filename in fs.dir(providers_dir) do
+ local p_func = loadfile(providers_dir .. filename)
+ setfenv(p_func, { _ = i18n.translate })
+ local p = p_func()
+ value = value:gsub('[%p%c%s]', '')
+ p.url_match = p.url_prefix:gsub('[%p%c%s]', '')
+ if value:match(p.url_match) then
+ uci:set("https_dns_proxy", section, "bootstrap_dns", p.bootstrap_dns)
+ uci:set("https_dns_proxy", section, "url_prefix", p.url_prefix)
+ end
+ end
+ uci:save("https_dns_proxy")
end
la = s3:option(Value, "listen_addr", translate("Listen address"))
@@ -148,10 +122,10 @@ la.rmempty = true
local n = 0
uci:foreach("https_dns_proxy", "https_dns_proxy", function(s)
- if s[".name"] == section then
- return false
- end
- n = n + 1
+ if s[".name"] == section then
+ return false
+ end
+ n = n + 1
end)
lp = s3:option(Value, "listen_port", translate("Listen port"))