2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
18 local uci = require "luci.model.uci".cursor()
19 local tools = require "luci.tools.ffwizard"
22 -------------------- View --------------------
23 f = SimpleForm("ffwizward", "Freifunkassistent",
24 "Dieser Assistent unterstüzt bei der Einrichtung des Routers für das Freifunknetz.")
27 dev = f:field(ListValue, "device", "WLAN-Gerät")
28 uci:foreach("wireless", "wifi-device",
30 dev:value(section[".name"])
34 main = f:field(Flag, "wifi", "Freifunkzugang einrichten")
36 net = f:field(Value, "net", "Freifunknetz")
38 net:depends("wifi", "1")
39 net:value("104.0", "Berlin (104.0)")
40 net:value("104.59", "Leisnig/Gadow/div. (104.59)")
41 net:value("104.61", "Leipzig (104.61)")
42 net:value("104.62", "Halle (104.62)")
43 net:value("191.161", "Augsburg (191.161)")
45 function net.cfgvalue(self, section)
46 return uci:get("freifunk", "wizard", "net")
48 function net.write(self, section, value)
49 uci:set("freifunk", "wizard", "net", value)
54 subnet = f:field(ListValue, "subnet", "Subnetz (Projekt)")
56 subnet:depends("wifi", "1")
60 function subnet.cfgvalue(self, section)
61 return uci:get("freifunk", "wizard", "subnet")
63 function subnet.write(self, section, value)
64 uci:set("freifunk", "wizard", "subnet", value)
68 node = f:field(Value, "node", "Knoten")
70 node:depends("wifi", "1")
74 function node.cfgvalue(self, section)
75 return uci:get("freifunk", "wizard", "node")
77 function node.write(self, section, value)
78 uci:set("freifunk", "wizard", "node", value)
82 client = f:field(Flag, "client", "WLAN-DHCP anbieten")
83 client:depends("wifi", "1")
86 olsr = f:field(Flag, "olsr", "OLSR einrichten")
88 share = f:field(ListValue, "sharenet", "Eigenen Internetzugang freigeben")
89 share:value("maybe", "-- keine Aktion --")
90 share:value("yes", "einschalten")
91 share:value("no", "ausschalten")
95 -------------------- Control --------------------
96 function f.handle(self, state, data)
97 if state == FORM_VALID then
98 luci.http.redirect(luci.dispatcher.build_url("admin", "uci", "changes"))
100 elseif state == FORM_INVALID then
101 self.errmessage = "Ungültige Eingabe: Bitte die Formularfelder auf Fehler prüfen."
106 local function _strip_internals(tbl)
108 for k, v in pairs(tbl) do
109 if k:sub(1, 1) == "." then
116 -- Configure Freifunk checked
117 function main.write(self, section, value)
122 local device = dev:formvalue(section)
124 -- Collect IP-Address
125 local inet = net:formvalue(section)
126 local isubnet = subnet:formvalue(section)
127 local inode = node:formvalue(section)
131 net.tag_missing[section] = true
134 subnet.tag_missing[section] = true
137 node.tag_missing[section] = true
140 if not inet or not isubnet or not inode then
144 local ip = "%s.%s.%s" % {inet, isubnet, inode}
148 luci.util.perror("1")
149 tools.wifi_delete_ifaces(device)
150 luci.util.perror("2")
151 tools.network_remove_interface(device)
152 luci.util.perror("3")
153 tools.firewall_zone_remove_interface("freifunk", device)
157 local devconfig = _strip_internals(uci:get_all("freifunk", "wifi_device"))
158 uci:tset("wireless", device, devconfig)
161 local ifconfig = _strip_internals(uci:get_all("freifunk", "wifi_iface"))
162 ifconfig.device = device
163 ifconfig.network = device
164 uci:section("wireless", "wifi-iface", nil, ifconfig)
169 -- Create firewall zone and add default rules (first time)
170 local newzone = tools.firewall_create_zone("freifunk", "DROP", "ACCEPT", "DROP", true)
172 uci:foreach("freifunk", "fw_forwarding", function(section)
173 uci:section("firewall", "forwarding", nil, _strip_internals(section))
176 uci:foreach("freifunk", "fw_rule", function(section)
177 uci:section("firewall", "rule", nil, _strip_internals(section))
184 -- Crate network interface
185 local netconfig = _strip_internals(uci:get_all("freifunk", "interface"))
186 netconfig.proto = "static"
187 netconfig.ipaddr = ip
188 uci:section("network", "interface", device, netconfig)
192 tools.firewall_zone_add_interface("freifunk", device)
196 function olsr.write(self, section, value)
201 local device = dev:formvalue(section)
203 -- Delete old interface
204 uci:delete_all("freifunk", "Interface", {Interface=device})
206 -- Write new interface
207 local olsrbase = _strip_internals(uci:get_all("freifunk", "olsr_interface"))
208 olsrbase.interface = device
209 olsrbase.ignore = "0"
210 uci:section("olsrd", "Interface", nil, olsrbase)
215 function share.write(self, section, value)
216 if value == "maybe" then
220 uci:delete_all("firewall", "forwarding", {src="freifunk", dest="wan"})
222 if value == "yes" then
223 uci:section("firewall", "forwarding", nil, {src="freifunk", dest="wan"})
229 function client.write(self, section, value)
234 local device = dev:formvalue(section)
236 -- Collect IP-Address
237 local inet = net:formvalue(section)
238 local isubnet = subnet:formvalue(section)
239 local inode = node:formvalue(section)
241 if not inet or not isubnet or not inode then
245 local dhcpbeg = 48 + tonumber(inode) * 4
246 local dclient = "%s.%s.%s" % {inet:gsub("^[0-9]+", "10"), isubnet, dhcpbeg}
247 local limit = dhcpbeg < 252 and 3 or 2
250 uci:delete("network", device .. "dhcp")
253 local aliasbase = _strip_internals(uci:get_all("freifunk", "alias"))
254 aliasbase.interface = device
255 aliasbase.ipaddr = dclient
256 aliasbase.proto = "static"
257 uci:section("network", "alias", device .. "dhcp", aliasbase)
262 local dhcpbase = _strip_internals(uci:get_all("freifunk", "dhcp"))
263 dhcpbase.interface = device .. "dhcp"
264 dhcpbase.start = dhcpbeg
265 dhcpbase.limit = limit
267 uci:section("dhcp", "dhcp", device .. "dhcp", dhcpbase)
272 uci:delete_all("luci_splash", "iface", {net=device, zone="freifunk"})
275 uci:section("luci_splash", "iface", nil, {net=device, zone="freifunk"})
276 uci:save("luci_splash")