Merge pull request #2890 from stangri/master-luci-app-https_dns_proxy
luci-app-https_dns_proxy: better handling of ports, update dhcp config
This commit is contained in:
commit
e8ce961cc3
2 changed files with 67 additions and 13 deletions
|
@ -10,7 +10,7 @@ LUCI_TITLE:=HTTPS DNS Proxy Web UI
|
||||||
LUCI_DESCRIPTION:=Provides Web UI for HTTPS DNS Proxy
|
LUCI_DESCRIPTION:=Provides Web UI for HTTPS DNS Proxy
|
||||||
LUCI_DEPENDS:=+luci-mod-admin-full +https_dns_proxy
|
LUCI_DEPENDS:=+luci-mod-admin-full +https_dns_proxy
|
||||||
LUCI_PKGARCH:=all
|
LUCI_PKGARCH:=all
|
||||||
PKG_RELEASE:=2
|
PKG_RELEASE:=3
|
||||||
|
|
||||||
include ../../luci.mk
|
include ../../luci.mk
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,41 @@
|
||||||
local uci = require("luci.model.uci").cursor()
|
local uci = require("luci.model.uci").cursor()
|
||||||
|
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 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
|
||||||
|
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
|
||||||
|
|
||||||
|
lval[#lval+1] = value
|
||||||
|
uci:set(conf, sect, opt, lval)
|
||||||
|
end
|
||||||
|
|
||||||
m = Map("https_dns_proxy", translate("HTTPS DNS Proxy Settings"))
|
m = Map("https_dns_proxy", translate("HTTPS DNS Proxy Settings"))
|
||||||
m.template="cbi/map"
|
m.template="cbi/map"
|
||||||
|
@ -9,10 +46,22 @@ s3.sortable = false
|
||||||
s3.anonymous = true
|
s3.anonymous = true
|
||||||
s3.addremove = true
|
s3.addremove = 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
|
||||||
|
end)
|
||||||
|
|
||||||
prov = s3:option(ListValue, "url_prefix", translate("Provider"))
|
prov = s3:option(ListValue, "url_prefix", translate("Provider"))
|
||||||
prov:value("https://cloudflare-dns.com/dns-query?ct=application/dns-json&","Cloudflare")
|
prov:value("https://cloudflare-dns.com/dns-query?ct=application/dns-json&","Cloudflare")
|
||||||
prov:value("https://dns.google.com/resolve?","Google")
|
prov:value("https://dns.google.com/resolve?","Google")
|
||||||
prov.write = function(self, section, value)
|
prov.write = function(self, section, value)
|
||||||
|
local la_val = la:formvalue(section)
|
||||||
|
local lp_val = lp:formvalue(section)
|
||||||
|
if not la_val then la_val = "127.0.0.1" end
|
||||||
|
if not lp_val then lp_val = n + 5053 end
|
||||||
if value and value:match("cloudflare") then
|
if value and 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, "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&")
|
uci:set("https_dns_proxy", section, "url_prefix", "https://cloudflare-dns.com/dns-query?ct=application/dns-json&")
|
||||||
|
@ -23,6 +72,12 @@ prov.write = function(self, section, value)
|
||||||
uci:set("https_dns_proxy", section, "user", "nobody")
|
uci:set("https_dns_proxy", section, "user", "nobody")
|
||||||
uci:set("https_dns_proxy", section, "group", "nogroup")
|
uci:set("https_dns_proxy", section, "group", "nogroup")
|
||||||
uci:save("https_dns_proxy")
|
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")
|
||||||
end
|
end
|
||||||
|
|
||||||
la = s3:option(Value, "listen_addr", translate("Listen address"))
|
la = s3:option(Value, "listen_addr", translate("Listen address"))
|
||||||
|
@ -31,23 +86,22 @@ la.rmempty = true
|
||||||
|
|
||||||
lp = s3:option(Value, "listen_port", translate("Listen port"))
|
lp = s3:option(Value, "listen_port", translate("Listen port"))
|
||||||
lp.datatype = "port"
|
lp.datatype = "port"
|
||||||
lp.placeholder = "5053"
|
lp.value = n + 5053
|
||||||
lp.rmempty = true
|
lp.write = function(self, section, value)
|
||||||
|
if not value then
|
||||||
-- user = s3:option(Value, "user", translate("User name"))
|
uci:set("https_dns_proxy", section, "listen_port", n + 5053)
|
||||||
-- user.placeholder = "nobody"
|
else
|
||||||
-- user.rmempty = true
|
uci:set("https_dns_proxy", section, "listen_port", value)
|
||||||
|
end
|
||||||
-- group = s3:option(Value, "group", translate("Group name"))
|
uci:save("https_dns_proxy")
|
||||||
-- group.placeholder = "nogroup"
|
end
|
||||||
-- group.rmempty = true
|
|
||||||
|
|
||||||
sa = s3:option(Value, "subnet_addr", translate("Subnet address"))
|
sa = s3:option(Value, "subnet_addr", translate("Subnet address"))
|
||||||
sa.datatype = "ip4addr"
|
sa.datatype = "ip4prefix"
|
||||||
sa.rmempty = true
|
sa.rmempty = true
|
||||||
|
|
||||||
ps = s3:option(Value, "proxy_server", translate("Proxy server"))
|
ps = s3:option(Value, "proxy_server", translate("Proxy server"))
|
||||||
-- ps.datatype = "or(ipaddr,hostname)"
|
ps.datatype = "or(ipaddr,hostname)"
|
||||||
ps.rmempty = true
|
ps.rmempty = true
|
||||||
|
|
||||||
return m
|
return m
|
||||||
|
|
Loading…
Reference in a new issue