luci-base: luci.dispatcher: allow overriding sysauth template
[project/luci.git] / applications / luci-app-travelmate / luasrc / model / cbi / travelmate / setup_tab.lua
1 -- Copyright 2017 Dirk Brenken (dev@brenken.org)
2 -- This is free software, licensed under the Apache License, Version 2.0
3
4 local nw  = require("luci.model.network").init()
5 local fw  = require("luci.model.firewall").init()
6 local util = require("luci.util")
7 local uci = require("luci.model.uci").cursor()
8
9 m = SimpleForm("network", translate("Interface Setup"),
10         translate("Automatically create a new wireless wan interface, configure it to use dhcp and " ..
11         "add it to the wan zone of the firewall. This step has only to be done once."))
12 m.reset = false
13
14 iface = m:field(Value, "netname", translate("Name of the new wireless wan interface"),
15         translate("The allowed characters are: <code>A-Z</code>, <code>a-z</code>, " ..
16                 "<code>0-9</code> and <code>_</code> (3-15 characters)."))
17 iface.default = "wwan"
18 iface.datatype = "and(uciname,minlength(3),maxlength(15))"
19
20 function iface.validate(self, value, section)
21         local value = iface:formvalue(section)
22         local name = uci.get("network", value)
23         if name then
24                 iface:add_error(section, translate("The given network interface name already exist"))
25         else
26                 iface.datatype = false
27                 iface.default = iface.disabled
28                 f = m:field(DummyValue, "textfield", "&nbsp;", translatef("Direct Link: "
29                         .. "<a href=\"%s\">"
30                         .. "Wireless Setup</a>", luci.dispatcher.build_url("admin/network/wireless")))
31                 f.default = translatef("Network Interface '%s' created successfully." ..
32                                         " Feel free to scan & add new stations via standard wireless setup.", value)
33                 f.disabled = true
34         end
35         return value
36 end
37
38 function iface.write(self, section, value)
39         local name = iface:formvalue(section)
40         if name then
41                 local net = nw:add_network(name, { proto = "dhcp" })
42                 if net then
43                         nw:save("network")
44                         nw:commit("network")
45                         local zone = fw:get_zone_by_network("wan")
46                         if zone then
47                                 zone:add_network(name)
48                                 fw:save("firewall")
49                                 fw:commit("firewall")
50                         end
51                 end
52         end
53 end
54
55 return m