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