1 module("ffluci.controller.freifunk.freifunk", package.seeall)
5 page.target = alias("freifunk")
7 local page = node("freifunk")
8 page.title = "Freifunk"
9 page.target = alias("freifunk", "index")
11 page.setuser = "nobody"
12 page.setgroup = "nogroup"
14 local page = node("freifunk", "index")
15 page.target = template("freifunk/index")
16 page.title = "Übersicht"
19 local page = node("freifunk", "index", "contact")
20 page.target = template("freifunk/contact")
21 page.title = "Kontakt"
24 local page = node("freifunk", "status")
25 page.target = action_status
31 local page = node("freifunk", "status", "routes")
32 page.target = template("public_status/routes")
33 page.title = "Routingtabelle"
36 local page = node("freifunk", "status", "iwscan")
37 page.target = template("public_status/iwscan")
38 page.title = "WLAN-Scan"
42 local page = node("admin", "index", "wizard")
43 page.target = action_wizard
44 page.title = "Freifunkassistent"
47 local page = node("admin", "index", "freifunk")
48 page.target = cbi("freifunk/freifunk")
49 page.title = "Freifunk"
52 local page = node("admin", "index", "contact")
53 page.target = cbi("freifunk/contact")
54 page.title = "Kontakt"
58 function action_status()
61 data.s, data.m, data.r = ffluci.sys.sysinfo()
63 data.wifi = ffluci.sys.wifi.getiwconfig()
66 for i, r in pairs(ffluci.sys.net.routes()) do
67 if r.Destination == "00000000" then
68 table.insert(data.routes, r)
73 ffluci.template.render("public_status/index", data)
76 function action_wizard()
77 if ffluci.http.formvalue("ip") then
78 return configure_freifunk()
82 local wldevs = ffluci.model.uci.sections("wireless")
85 for k, v in pairs(wldevs) do
86 if v[".type"] == "wifi-device" then
87 table.insert(ifaces, k)
92 ffluci.template.render("freifunk/wizard", {ifaces=ifaces})
95 function configure_freifunk()
96 local ip = ffluci.http.formvalue("ip")
97 local uci = ffluci.model.uci.Session()
100 uci:t_load("network")
102 uci:t_load("freifunk")
103 uci:t_load("luci_splash")
105 uci:t_load("wireless")
106 uci:t_load("luci_fw")
109 -- Configure FF-Interface
110 uci:t_del("network", "ff")
111 uci:t_del("network", "ffdhcp")
113 uci:t_set("network", "ff", nil, "interface")
114 uci:t_set("network", "ff", "type", "bridge")
115 uci:t_set("network", "ff", "proto", "static")
116 uci:t_set("network", "ff", "ipaddr", ip)
117 uci:t_set("network", "ff", "netmask", uci:t_get("freifunk", "community", "mask"))
118 uci:t_set("network", "ff", "dns", uci:t_get("freifunk", "community", "dns"))
121 local routing = uci:t_sections("luci_fw")
123 for k, v in pairs(routing) do
124 if v[".type"] == "routing" and (v.iface == "ff" or v.oface == "ff") then
125 uci:t_del("luci_fw", k)
129 local int = uci:t_add("luci_fw", "routing")
130 uci:t_set("luci_fw", int, "iface", "ff")
131 uci:t_set("luci_fw", int, "oface", "ff")
132 uci:t_set("luci_fw", int, "fwd", "1")
135 -- Routing from Internal
136 local iface = ffluci.http.formvalue("frominternal")
137 if iface and iface ~= "" then
138 local routing = uci:t_sections("luci_fw")
140 for k, v in pairs(routing) do
141 if v[".type"] == "routing" and (v.iface == iface and v.oface == "ff") then
142 uci:t_del("luci_fw", k)
146 local int = uci:t_add("luci_fw", "routing")
147 uci:t_set("luci_fw", int, "iface", iface)
148 uci:t_set("luci_fw", int, "oface", "ff")
149 uci:t_set("luci_fw", int, "fwd", "1")
150 uci:t_set("luci_fw", int, "nat", "1")
154 -- Routing to External
155 local iface = ffluci.http.formvalue("toexternal")
156 if iface and iface ~= "" then
157 local routing = uci:t_sections("luci_fw")
159 for k, v in pairs(routing) do
160 if v[".type"] == "routing" and (v.oface == iface and v.iface == "ff") then
161 uci:t_del("luci_fw", k)
165 local int = uci:t_add("luci_fw", "routing")
166 uci:t_set("luci_fw", int, "iface", "ff")
167 uci:t_set("luci_fw", int, "oface", iface)
168 uci:t_set("luci_fw", int, "fwd", "1")
169 uci:t_set("luci_fw", int, "nat", "1")
174 if ffluci.http.formvalue("dhcp") then
175 local dhcpnet = uci:t_get("freifunk", "community", "dhcp"):match("^([0-9]+)")
176 local dhcpip = ip:gsub("^[0-9]+", dhcpnet)
178 uci:t_set("network", "ffdhcp", nil, "interface")
179 uci:t_set("network", "ffdhcp", "proto", "static")
180 uci:t_set("network", "ffdhcp", "ifname", "br-ff:dhcp")
181 uci:t_set("network", "ffdhcp", "ipaddr", dhcpip)
182 uci:t_set("network", "ffdhcp", "netmask", uci:t_get("freifunk", "community", "dhcpmask"))
184 local dhcp = uci:t_sections("dhcp")
186 for k, v in pairs(dhcp) do
187 if v[".type"] == "dhcp" and v.interface == "ffdhcp" then
192 local dhcpbeg = 48 + tonumber(ip:match("[0-9]+$")) * 4
194 local sk = uci:t_add("dhcp", "dhcp")
195 uci:t_set("dhcp", sk, "interface", "ffdhcp")
196 uci:t_set("dhcp", sk, "start", dhcpbeg)
197 uci:t_set("dhcp", sk, "limit", (dhcpbeg < 252) and 3 or 2)
198 uci:t_set("dhcp", sk, "leasetime", "30m")
201 local splash = uci:t_sections("luci_splash")
203 for k, v in pairs(splash) do
204 if v[".type"] == "iface" then
205 uci:t_del("luci_splash", k)
209 local sk = uci:t_add("luci_splash", "iface")
210 uci:t_set("luci_splash", sk, "network", "ffdhcp")
213 local routing = uci:t_sections("luci_fw")
215 for k, v in pairs(routing) do
216 if v[".type"] == "routing" and (v.iface == "ffdhcp" or v.oface == "ffdhcp") then
217 uci:t_del("luci_fw", k)
221 local int = uci:t_add("luci_fw", "routing")
222 uci:t_set("luci_fw", int, "iface", "ffdhcp")
223 uci:t_set("luci_fw", int, "oface", "ff")
224 uci:t_set("luci_fw", int, "nat", "1")
226 local iface = ffluci.http.formvalue("toexternal")
227 if iface and iface ~= "" then
228 local int = uci:t_add("luci_fw", "routing")
229 uci:t_set("luci_fw", int, "iface", "ffdhcp")
230 uci:t_set("luci_fw", int, "oface", iface)
231 uci:t_set("luci_fw", int, "nat", "1")
237 if ffluci.http.formvalue("olsr") and uci:t_sections("olsr") then
238 for k, v in pairs(uci:t_sections("olsr")) do
239 if v[".type"] == "Interface" or v[".type"] == "LoadPlugin" then
244 if ffluci.http.formvalue("shareinet") then
245 uci:t_set("olsr", "dyn_gw", nil, "LoadPlugin")
246 uci:t_set("olsr", "dyn_gw", "Library", "olsrd_dyn_gw.so.0.4")
249 uci:t_set("olsr", "nameservice", nil, "LoadPlugin")
250 uci:t_set("olsr", "nameservice", "Library", "olsrd_nameservice.so.0.3")
251 uci:t_set("olsr", "nameservice", "name", ip:gsub("%.", "-"))
252 uci:t_set("olsr", "nameservice", "hosts_file", "/var/etc/hosts")
253 uci:t_set("olsr", "nameservice", "suffix", ".olsr")
254 uci:t_set("olsr", "nameservice", "latlon_infile", "/tmp/latlon.txt")
256 uci:t_set("olsr", "txtinfo", nil, "LoadPlugin")
257 uci:t_set("olsr", "txtinfo", "Library", "olsrd_txtinfo.so.0.1")
258 uci:t_set("olsr", "txtinfo", "Accept", "127.0.0.1")
260 local oif = uci:t_add("olsr", "Interface")
261 uci:t_set("olsr", oif, "Interface", "ff")
262 uci:t_set("olsr", oif, "HelloInterval", "6.0")
263 uci:t_set("olsr", oif, "HelloValidityTime", "108.0")
264 uci:t_set("olsr", oif, "TcInterval", "4.0")
265 uci:t_set("olsr", oif, "TcValidityTime", "324.0")
266 uci:t_set("olsr", oif, "MidInterval", "18.0")
267 uci:t_set("olsr", oif, "MidValidityTime", "324.0")
268 uci:t_set("olsr", oif, "HnaInterval", "18.0")
269 uci:t_set("olsr", oif, "HnaValidityTime", "108.0")
273 local wcfg = uci:t_sections("wireless")
275 for iface, v in pairs(wcfg) do
276 if v[".type"] == "wifi-device" and ffluci.http.formvalue("wifi."..iface) then
278 for k, j in pairs(wcfg) do
279 if j[".type"] == "wifi-iface" and j.device == iface then
280 uci:t_del("wireless", k)
284 uci:t_set("wireless", iface, "disabled", "0")
285 uci:t_set("wireless", iface, "mode", "11g")
286 uci:t_set("wireless", iface, "txantenna", 1)
287 uci:t_set("wireless", iface, "rxantenna", 1)
288 uci:t_set("wireless", iface, "channel", uci:t_get("freifunk", "community", "channel"))
290 local wif = uci:t_add("wireless", "wifi-iface")
291 uci:t_set("wireless", wif, "device", iface)
292 uci:t_set("wireless", wif, "network", "ff")
293 uci:t_set("wireless", wif, "mode", "adhoc")
294 uci:t_set("wireless", wif, "ssid", uci:t_get("freifunk", "community", "essid"))
295 uci:t_set("wireless", wif, "bssid", uci:t_get("freifunk", "community", "bssid"))
296 uci:t_set("wireless", wif, "txpower", 13)
302 uci:t_save("network")
304 uci:t_save("freifunk")
305 uci:t_save("luci_splash")
307 uci:t_save("wireless")
308 uci:t_save("luci_fw")
310 ffluci.http.redirect(ffluci.dispatcher.build_url("admin", "uci", "changes"))