1 module("ffluci.controller.admin.index.wizard", package.seeall)
4 if ffluci.http.formvalue("ip") then
5 return configure_freifunk()
9 local wldevs = ffluci.model.uci.sections("wireless")
12 for k, v in pairs(wldevs) do
13 if v[".type"] == "wifi-device" then
14 table.insert(ifaces, k)
19 ffluci.template.render("admin_index/wizard", {ifaces=ifaces})
22 function configure_freifunk()
23 local ip = ffluci.http.formvalue("ip")
24 local uci = ffluci.model.uci.Session()
29 uci:t_load("freifunk")
30 uci:t_load("luci_splash")
32 uci:t_load("wireless")
36 -- Configure FF-Interface
37 uci:t_del("network", "ff")
38 uci:t_del("network", "ffdhcp")
40 uci:t_set("network", "ff", nil, "interface")
41 uci:t_set("network", "ff", "type", "bridge")
42 uci:t_set("network", "ff", "proto", "static")
43 uci:t_set("network", "ff", "ipaddr", ip)
44 uci:t_set("network", "ff", "netmask", uci:t_get("freifunk", "community", "mask"))
45 uci:t_set("network", "ff", "dns", uci:t_get("freifunk", "community", "dns"))
48 local routing = uci:t_sections("luci_fw")
50 for k, v in pairs(routing) do
51 if v[".type"] == "routing" and (v.iface == "ff" or v.oface == "ff") then
52 uci:t_del("luci_fw", k)
56 local int = uci:t_add("luci_fw", "routing")
57 uci:t_set("luci_fw", int, "iface", "ff")
58 uci:t_set("luci_fw", int, "oface", "ff")
59 uci:t_set("luci_fw", int, "fwd", "1")
62 -- Routing from Internal
63 local iface = ffluci.http.formvalue("frominternal")
64 if iface and iface ~= "" then
65 local routing = uci:t_sections("luci_fw")
67 for k, v in pairs(routing) do
68 if v[".type"] == "routing" and (v.iface == iface and v.oface == "ff") then
69 uci:t_del("luci_fw", k)
73 local int = uci:t_add("luci_fw", "routing")
74 uci:t_set("luci_fw", int, "iface", iface)
75 uci:t_set("luci_fw", int, "oface", "ff")
76 uci:t_set("luci_fw", int, "fwd", "1")
77 uci:t_set("luci_fw", int, "nat", "1")
81 -- Routing to External
82 local iface = ffluci.http.formvalue("toexternal")
83 if iface and iface ~= "" then
84 local routing = uci:t_sections("luci_fw")
86 for k, v in pairs(routing) do
87 if v[".type"] == "routing" and (v.oface == iface and v.iface == "ff") then
88 uci:t_del("luci_fw", k)
92 local int = uci:t_add("luci_fw", "routing")
93 uci:t_set("luci_fw", int, "iface", "ff")
94 uci:t_set("luci_fw", int, "oface", iface)
95 uci:t_set("luci_fw", int, "fwd", "1")
96 uci:t_set("luci_fw", int, "nat", "1")
101 if ffluci.http.formvalue("dhcp") then
102 local dhcpnet = uci:t_get("freifunk", "community", "dhcp"):match("^([0-9]+)")
103 local dhcpip = ip:gsub("^[0-9]+", dhcpnet)
105 uci:t_set("network", "ffdhcp", nil, "interface")
106 uci:t_set("network", "ffdhcp", "proto", "static")
107 uci:t_set("network", "ffdhcp", "ifname", "br-ff:dhcp")
108 uci:t_set("network", "ffdhcp", "ipaddr", dhcpip)
109 uci:t_set("network", "ffdhcp", "netmask", uci:t_get("freifunk", "community", "dhcpmask"))
111 local dhcp = uci:t_sections("dhcp")
113 for k, v in pairs(dhcp) do
114 if v[".type"] == "dhcp" and v.interface == "ffdhcp" then
119 local dhcpbeg = 48 + tonumber(ip:match("[0-9]+$")) * 4
121 local sk = uci:t_add("dhcp", "dhcp")
122 uci:t_set("dhcp", sk, "interface", "ffdhcp")
123 uci:t_set("dhcp", sk, "start", dhcpbeg)
124 uci:t_set("dhcp", sk, "limit", (dhcpbeg < 252) and 3 or 2)
125 uci:t_set("dhcp", sk, "leasetime", "30m")
128 local splash = uci:t_sections("luci_splash")
130 for k, v in pairs(splash) do
131 if v[".type"] == "iface" then
132 uci:t_del("luci_splash", k)
136 local sk = uci:t_add("luci_splash", "iface")
137 uci:t_set("luci_splash", sk, "network", "ffdhcp")
140 local routing = uci:t_sections("luci_fw")
142 for k, v in pairs(routing) do
143 if v[".type"] == "routing" and (v.iface == "ffdhcp" or v.oface == "ffdhcp") then
144 uci:t_del("luci_fw", k)
148 local int = uci:t_add("luci_fw", "routing")
149 uci:t_set("luci_fw", int, "iface", "ffdhcp")
150 uci:t_set("luci_fw", int, "oface", "ff")
151 uci:t_set("luci_fw", int, "nat", "1")
153 local iface = ffluci.http.formvalue("toexternal")
154 if iface and iface ~= "" then
155 local int = uci:t_add("luci_fw", "routing")
156 uci:t_set("luci_fw", int, "iface", "ffdhcp")
157 uci:t_set("luci_fw", int, "oface", iface)
158 uci:t_set("luci_fw", int, "nat", "1")
164 if ffluci.http.formvalue("olsr") and uci:t_sections("olsr") then
165 for k, v in pairs(uci:t_sections("olsr")) do
166 if v[".type"] == "Interface" or v[".type"] == "LoadPlugin" then
171 if ffluci.http.formvalue("shareinet") then
172 uci:t_set("olsr", "dyn_gw", nil, "LoadPlugin")
173 uci:t_set("olsr", "dyn_gw", "Library", "olsrd_dyn_gw.so.0.4")
176 uci:t_set("olsr", "nameservice", nil, "LoadPlugin")
177 uci:t_set("olsr", "nameservice", "Library", "olsrd_nameservice.so.0.3")
178 uci:t_set("olsr", "nameservice", "name", ip:gsub("%.", "-"))
179 uci:t_set("olsr", "nameservice", "hosts_file", "/var/etc/hosts")
180 uci:t_set("olsr", "nameservice", "suffix", ".olsr")
181 uci:t_set("olsr", "nameservice", "latlon_infile", "/tmp/latlon.txt")
183 uci:t_set("olsr", "txtinfo", nil, "LoadPlugin")
184 uci:t_set("olsr", "txtinfo", "Library", "olsrd_txtinfo.so.0.1")
185 uci:t_set("olsr", "txtinfo", "Accept", "127.0.0.1")
187 local oif = uci:t_add("olsr", "Interface")
188 uci:t_set("olsr", oif, "Interface", "ff")
189 uci:t_set("olsr", oif, "HelloInterval", "6.0")
190 uci:t_set("olsr", oif, "HelloValidityTime", "108.0")
191 uci:t_set("olsr", oif, "TcInterval", "4.0")
192 uci:t_set("olsr", oif, "TcValidityTime", "324.0")
193 uci:t_set("olsr", oif, "MidInterval", "18.0")
194 uci:t_set("olsr", oif, "MidValidityTime", "324.0")
195 uci:t_set("olsr", oif, "HnaInterval", "18.0")
196 uci:t_set("olsr", oif, "HnaValidityTime", "108.0")
200 local wcfg = uci:t_sections("wireless")
202 for iface, v in pairs(wcfg) do
203 if v[".type"] == "wifi-device" and ffluci.http.formvalue("wifi."..iface) then
205 for k, j in pairs(wcfg) do
206 if j[".type"] == "wifi-iface" and j.device == iface then
207 uci:t_del("wireless", k)
211 uci:t_set("wireless", iface, "disabled", "0")
212 uci:t_set("wireless", iface, "mode", "11g")
213 uci:t_set("wireless", iface, "txantenna", 1)
214 uci:t_set("wireless", iface, "rxantenna", 1)
215 uci:t_set("wireless", iface, "channel", uci:t_get("freifunk", "community", "channel"))
217 local wif = uci:t_add("wireless", "wifi-iface")
218 uci:t_set("wireless", wif, "device", iface)
219 uci:t_set("wireless", wif, "network", "ff")
220 uci:t_set("wireless", wif, "mode", "adhoc")
221 uci:t_set("wireless", wif, "ssid", uci:t_get("freifunk", "community", "essid"))
222 uci:t_set("wireless", wif, "bssid", uci:t_get("freifunk", "community", "bssid"))
223 uci:t_set("wireless", wif, "txpower", 13)
229 uci:t_save("network")
231 uci:t_save("freifunk")
232 uci:t_save("luci_splash")
234 uci:t_save("wireless")
235 uci:t_save("luci_fw")
237 ffluci.http.redirect(ffluci.dispatcher.build_url("admin", "uci", "changes"))