1 -- Copyright 2018 Eric Luehrsen <ericluehrsen@gmail.com>
2 -- Licensed to the public under the Apache License 2.0.
4 local sy = require "luci.sys"
5 local ds = require "luci.dispatcher"
6 local hp = require "luci.http"
8 local ena, flb, zty, znm, srv, rlv, tlu
9 local prt, tlp, tli, url
13 m7.redirect = ds.build_url("admin/services/unbound/zones")
16 if (arg[1] == "") then
17 hp.redirect(m7.redirect)
21 s7 = m7:section(NamedSection, arg[1], "zone",
22 translatef("Directed Zone"),
23 translatef("Edit a forward, stub, or zone-file-cache zone "
24 .. "for Unbound to use instead of recursion."))
29 ena = s7:option(Flag, "enabled", translate("Enabled"),
30 translate("Enable this directed zone"))
33 flb = s7:option(Flag, "fallback", translate("Fall Back"),
34 translate("Allow open recursion when record not in zone"))
37 zty = s7:option(ListValue, "zone_type", translate("Zone Type"))
38 zty:value("auth_zone", translate("Authoritative (zone file)"))
39 zty:value("stub_zone", translate("Stub (forced recursion)"))
40 zty:value("forward_zone", translate("Forward (simple handoff)"))
43 znm = s7:option(DynamicList, "zone_name", translate("Zone Names"),
44 translate("Zone (Domain) names included in this zone combination"))
45 znm.placeholder="new.example.net."
47 srv = s7:option(DynamicList, "server", translate("Servers"),
48 translate("Servers for this zone; see README.md for optional form"))
49 srv.placeholder="192.0.2.53"
51 rlv = s7:option(Flag, "resolv_conf", translate("Use 'resolv.conf.auto'"),
52 translate("Forward to upstream nameservers (ISP)"))
53 rlv:depends("zone_type", "forward_zone")
55 tlu = s7:option(Flag, "tls_upstream", translate("DNS over TLS"),
56 translate("Connect to servers using TLS"))
57 tlu:depends("zone_type", "forward_zone")
59 prt = s7:option(Value, "port", translate("Server Port"),
60 translate("Port servers will receive queries on"))
61 prt:depends("tls_upstream", false)
65 tlp = s7:option(Value, "tls_port", translate("Server TLS Port"),
66 translate("Port servers will receive queries on"))
67 tlp:depends("tls_upstream", true)
71 tli = s7:option(Value, "tls_index", translate("TLS Name Index"),
72 translate("Domain name to verify TLS certificate"))
73 tli:depends("tls_upstream", true)
74 tli.placeholder="dns.example.net"
76 url = s7:option(Value, "url_dir", translate("Zone Download URL"),
77 translate("Directory only part of URL"))
78 url:depends("zone_type", "auth_zone")
79 url.placeholder="https://www.example.net/dl/zones/"
83 function m7.on_commit(self)
84 if sy.init.enabled("unbound") then
85 -- Restart Unbound with configuration
86 sy.call("/etc/init.d/unbound restart >/dev/null 2>&1")
89 sy.call("/etc/init.d/unbound stop >/dev/null 2>&1")