1 module("luci.controller.luci_ffwizard_leipzig.wizard", package.seeall)
4 entry({"admin", "index", "wizard"}, call("action_wizard"), "Freifunkassistent", 20)
8 function action_wizard()
9 if luci.http.formvalue("ip") then
10 return configure_freifunk()
14 luci.model.uci.foreach("wireless", "wifi-device",
16 table.insert(ifaces, section[".name"])
19 luci.template.render("freifunk/wizard", {ifaces=ifaces})
22 function configure_freifunk()
23 local ip = luci.http.formvalue("ip")
24 local uci = luci.model.uci
25 local cfg = uci.config
28 -- Configure FF-Interface
29 uci.delete("network", "ff")
30 uci.delete("network", "ffdhcp")
32 cfg.network.ff = "interface"
33 cfg.network.ff.type = "bridge"
34 cfg.network.ff.proto = "static"
35 cfg.network.ff.ipaddr = ip
36 cfg.network.ff.netmask = cfg.freifunk.community.mask
37 cfg.network.ff.dns = cfg.freifunk.community.dns
40 uci.foreach("luci_fw", "routing",
42 if section.iface == "ff" or section.oface == "ff" then
43 uci.delete("luci_fw", section[".name"])
48 cfg.luci_fw[""] = "routing"
49 cfg.luci_fw[""].iface = "ff"
50 cfg.luci_fw[""].oface = "ff"
51 cfg.luci_fw[""].fwd = "1"
54 -- Routing from Internal
55 local iface = luci.http.formvalue("frominternal")
56 if iface and iface ~= "" then
57 uci.foreach("luci_fw", "routing",
59 if section.iface == iface and section.oface == "ff" then
60 uci.delete("luci_fw", section[".name"])
65 cfg.luci_fw[""] = "routing"
66 cfg.luci_fw[""].iface = iface
67 cfg.luci_fw[""].oface = "ff"
68 cfg.luci_fw[""].fwd = "1"
69 cfg.luci_fw[""].nat = "1"
73 -- Routing to External
74 local iface = luci.http.formvalue("toexternal")
75 if iface and iface ~= "" then
76 uci.foreach("luci_fw", "routing",
78 if section.oface == iface and section.iface == "ff" then
79 uci.delete("luci_fw", section[".name"])
84 cfg.luci_fw[""] = "routing"
85 cfg.luci_fw[""].oface = iface
86 cfg.luci_fw[""].iface = "ff"
87 cfg.luci_fw[""].fwd = "1"
88 cfg.luci_fw[""].nat = "1"
93 if luci.http.formvalue("dhcp") then
94 local dhcpnet = cfg.freifunk.community.dhcp:match("^([0-9]+)")
95 local dhcpip = ip:gsub("^[0-9]+", dhcpnet)
97 cfg.network.ffdhcp = "interface"
98 cfg.network.ffdhcp.proto = "static"
99 cfg.network.ffdhcp.ifname = "br-ff:dhcp"
100 cfg.network.ffdhcp.ipaddr = dhcpip
101 cfg.network.ffdhcp.netmask = cfg.freifunk.community.dhcpmask
103 uci.foreach("dhcp", "dhcp",
105 if section.interface == "ffdhcp" then
106 uci.delete("dhcp", section[".name"])
110 local dhcpbeg = 48 + tonumber(ip:match("[0-9]+$")) * 4
112 cfg.dhcp[""] = "dhcp"
113 cfg.dhcp[""].interface = "ffdhcp"
114 cfg.dhcp[""].start = dhcpbeg
115 cfg.dhcp[""].limit = (dhcpbeg < 252) and 3 or 2
116 cfg.dhcp[""].leasetime = "30m"
119 uci.foreach("luci_splash", "iface",
121 if section.network == "ffdhcp" then
122 uci.delete("luci_splash", section[".name"])
126 if cfg.luci_splash then
127 cfg.luci_splash[""] = "iface"
128 cfg.luci_splash[""].network = "ffdhcp"
132 uci.foreach("luci_fw", "routing",
134 if section.iface == "ffdhcp" or section.oface == "ffdhcp" then
135 uci.delete("luci_fw", section[".name"])
140 cfg.luci_fw[""] = "routing"
141 cfg.luci_fw[""].iface = "ffdhcp"
142 cfg.luci_fw[""].oface = "ff"
143 cfg.luci_fw[""].nat = "1"
145 local iface = luci.http.formvalue("toexternal")
146 if iface and iface ~= "" then
147 cfg.luci_fw[""] = "routing"
148 cfg.luci_fw[""].iface = "ffdhcp"
149 cfg.luci_fw[""].oface = iface
150 cfg.luci_fw[""].nat = "1"
156 if luci.http.formvalue("olsr") and cfg.olsr then
157 uci.foreach("olsr", "Interface",
159 uci.delete("olsr", section[".name"])
162 uci.foreach("olsr", "LoadPlugin",
164 uci.delete("olsr", section[".name"])
167 if luci.http.formvalue("shareinet") then
168 cfg.olsr.dyn_gw = "LoadPlugin"
169 cfg.olsr.dyn_gw.Library = "olsrd_dyn_gw.so.0.4"
172 cfg.olsr.nameservice = "LoadPlugin"
173 cfg.olsr.nameservice.Library = "olsrd_nameservice.so.0.3"
174 cfg.olsr.nameservice.name = ip:gsub("%.", "-")
175 cfg.olsr.nameservice.hosts_file = "/var/etc/hosts"
176 cfg.olsr.nameservice.suffix = ".olsr"
177 cfg.olsr.nameservice.latlon_infile = "/tmp/latlon.txt"
179 cfg.olsr.txtinfo = "LoadPlugin"
180 cfg.olsr.txtinfo.Library = "olsrd_txtinfo.so.0.1"
181 cfg.olsr.txtinfo.Accept = "127.0.0.1"
183 cfg.olsr[""] = "Interface"
184 cfg.olsr[""].Interface = "ff"
185 cfg.olsr[""].HelloInterval = "6.0"
186 cfg.olsr[""].HelloValidityTime = "108.0"
187 cfg.olsr[""].TcInterval = "4.0"
188 cfg.olsr[""].TcValidityTime = "324.0"
189 cfg.olsr[""].MidInterval = "18.0"
190 cfg.olsr[""].MidValidityTime = "324.0"
191 cfg.olsr[""].HnaInterval = "18.0"
192 cfg.olsr[""].HnaValidityTime = "108.0"
197 uci.foreach("wireless", "wifi-device",
199 local device = section[".name"]
201 if luci.http.formvalue("wifi."..iface) then
202 uci.foreach("wireless", "wifi-iface",
204 if section.device == device then
205 uci.delete("wireless", section[".name"])
210 cfg.wireless[device].disabled = "0"
211 cfg.wireless[device].mode = "11g"
212 cfg.wireless[device].txantenna = "1"
213 cfg.wireless[device].rxantenna = "1"
214 cfg.wireless[device].channel = cfg.freifunk.community.channel
216 cfg.wireless[""] = "wifi-iface"
217 cfg.wireless[""].device = iface
218 cfg.wireless[""].network = "ff"
219 cfg.wireless[""].mode = "adhoc"
220 cfg.wireless[""].ssid = cfg.freifunk.community.essid
221 cfg.wireless[""].bssid = cfg.freifunk.community.bssid
222 cfg.wireless[""].txpower = 13
229 luci.http.redirect(luci.dispatcher.build_url("admin", "uci", "changes"))