local has_autoipv6 = fs.access("/usr/bin/auto-ipv6")
local has_qos = fs.access("/etc/init.d/qos")
local has_ipv6 = fs.access("/proc/sys/net/ipv6")
+local has_hb = fs.access("/sbin/heartbeat")
luci.i18n.loadc("freifunk")
-------------------- View --------------------
f = SimpleForm("ffwizward", "Freifunkassistent",
"Dieser Assistent unterstützt Sie bei der Einrichtung des Routers für das Freifunknetz.")
--- main netconfig
-local newpsswd = has_rom and sys.exec("diff /rom/etc/passwd /etc/passwd")
-if newpsswd ~= "" then
- pw = f:field(Flag, "pw", "Router Passwort", "Setzen Sie den Haken, um Ihr Passwort zu ändern.")
- function pw.cfgvalue(self, section)
- return 1
- end
-end
-pw1 = f:field(Value, "pw1", translate("password"))
-pw1.password = true
-pw1.rmempty = false
+-- if password is not set or default then force the user to set a new one
+if sys.exec("diff /rom/etc/passwd /etc/passwd") == "" then
+ pw1 = f:field(Value, "pw1", translate("password"))
+ pw1.password = true
+ pw1.rmempty = false
-pw2 = f:field(Value, "pw2", translate("confirmation"))
-pw2.password = true
-pw2.rmempty = false
+ pw2 = f:field(Value, "pw2", translate("confirmation"))
+ pw2.password = true
+ pw2.rmempty = false
-function pw2.validate(self, value, section)
- return pw1:formvalue(section) == value and value
-end
-
-if newpsswd ~= "" then
- pw1:depends("pw", "1")
- pw2:depends("pw", "1")
+ function pw2.validate(self, value, section)
+ return pw1:formvalue(section) == value and value
+ end
end
net = f:field(ListValue, "net", "Freifunk Community", "Nutzen Sie die Einstellungen der Freifunk Gemeinschaft in ihrer Nachbarschaft.")
uci:save("freifunk")
end
function hostname.validate(self, value)
- if (#value > 16) then
- return
- elseif (string.find(value, "[^%w%_%-]")) then
+ if (#value > 24) or string.find(value, "[^%w%.%-]") or string.find(string.sub(value, value:len()), "[%.%-]") or string.find(string.sub(value, 1), "[%.%-]") then
return
else
return value
function chan.cfgvalue(self, section)
return uci:get("freifunk", "wizard", "chan_" .. device)
end
+
chan:value('default')
- for i = 1, 14, 1 do
- chan:value(i)
- end
- for i = 36, 64, 4 do
- chan:value(i)
- end
- for i = 100, 140, 4 do
- chan:value(i)
+ for _, f in ipairs(sys.wifi.channels(device)) do
+ if not f.restricted then
+ chan:value(f.channel)
+ end
end
+
function chan.write(self, sec, value)
if value then
uci:set("freifunk", "wizard", "chan_" .. device, value)
uci:save("freifunk")
end
end
- local meship = f:field(Value, "meship_" .. device, device:upper() .. " Mesh IP Adresse einrichten", "Ihre Mesh IP Adresse erhalten Sie von der Freifunk Gemeinschaft in Ihrer Nachbarschaft. Es ist eine netzweit eindeutige Identifikation, z.B. 104.1.1.1.")
+
+ local meship = f:field(Value, "meship_" .. device, device:upper() .. " Mesh IP Adresse einrichten", "Ihre Mesh IP Adresse erhalten Sie von der Freifunk Gemeinschaft in Ihrer Nachbarschaft. Es ist eine netzweit eindeutige Identifikation, z.B. 104.1.1.1.")
meship:depends("device_" .. device, "1")
meship.rmempty = true
function meship.cfgvalue(self, section)
end
end
-hb = f:field(Flag, "hb", "Heartbeat aktivieren","Dem Gerät erlauben anonyme Statistiken zu übertragen. (empfohlen)")
-hb.rmempty = false
-hb:depends("netconfig", "1")
-function hb.cfgvalue(self, section)
- return uci:get("freifunk", "wizard", "hb")
-end
-function hb.write(self, section, value)
- uci:set("freifunk", "wizard", "hb", value)
- uci:save("freifunk")
+if has_hb then
+ hb = f:field(Flag, "hb", "Heartbeat aktivieren","Dem Gerät erlauben anonyme Statistiken zu übertragen. (empfohlen)")
+ hb.rmempty = false
+ hb:depends("netconfig", "1")
+ function hb.cfgvalue(self, section)
+ return uci:get("freifunk", "wizard", "hb")
+ end
+ function hb.write(self, section, value)
+ uci:set("freifunk", "wizard", "hb", value)
+ uci:save("freifunk")
+ end
end
-------------------- Control --------------------
else
if data.pw1 then
local stat = luci.sys.user.setpasswd("root", data.pw1) == 0
--- if stat then
--- f.message = translate("a_s_changepw_changed")
--- else
--- f.errmessage = translate("unknownerror")
- end
+ end
data.pw1 = nil
data.pw2 = nil
uci:commit("freifunk")
if has_radvd then
uci:commit("radvd")
end
--- the following line didn't work without admin-mini, for now i just replaced it with sys.exec... soma
--- luci.http.redirect(luci.dispatcher.build_url(unpack(luci.dispatcher.context.requested.path), "system", "reboot") .. "?reboot=1")
- sys.exec("reboot")
+
+ sys.exec("for s in network dnsmasq luci_splash firewall uhttpd olsrd radvd l2gvpn; do [ -x /etc/init.d/$s ] && /etc/init.d/$s restart;done > /dev/null &")
+ luci.http.redirect(luci.dispatcher.build_url(luci.dispatcher.context.path[1], "freifunk", "ffwizard"))
end
return false
elseif state == FORM_INVALID then
end)
end
uci:save("firewall")
- uci:delete("manager", "heartbeat", "interface")
- uci:save("manager")
+ if has_hb then
+ uci:delete("manager", "heartbeat", "interface")
+ uci:save("manager")
+ end
-- Delete olsrdv4
uci:delete_all("olsrd", "olsrd")
local olsrbase
end
-- New Config
-- Tune wifi device
- local ssiduci = uci:get("freifunk", community, "ssid")
- local ssiddot = string.find(ssiduci,'%..*')
- local ssidshort
- if ssiddot then
- ssidshort = string.sub(ssiduci,ssiddot)
- else
- ssidshort = ssiduci
- end
+ local ssid = uci:get("freifunk", community, "ssid") or "olsr.freifunk.net"
local devconfig = uci:get_all("freifunk", "wifi_device")
util.update(devconfig, uci:get_all(external, "wifi_device") or {})
- local ssid = uci:get("freifunk", community, "ssid")
local channel = luci.http.formvalue("cbid.ffwizward.1.chan_" .. device)
local hwmode = "11bg"
- local bssid = "02:CA:FF:EE:BA:BE"
+ local bssid = uci:get_all(external, "wifi_iface", "bssid") or "02:CA:FF:EE:BA:BE"
local mrate = 5500
+ -- set bssid, see https://kifuse02.pberg.freifunk.net/moin/channel-bssid-essid for schema
if channel and channel ~= "default" then
if devconfig.channel ~= channel then
devconfig.channel = channel
local chan = tonumber(channel)
if chan >= 0 and chan < 10 then
bssid = channel .. "2:CA:FF:EE:BA:BE"
- ssid = "ch" .. channel .. ssidshort
- elseif chan == 10 then
- bssid = "02:CA:FF:EE:BA:BE"
- ssid = "ch" .. channel .. ssidshort
+ elseif chan == 10 then
+ bssid = "02:CA:FF:EE:BA:BE"
elseif chan >= 11 and chan <= 14 then
bssid = string.format("%X",channel) .. "2:CA:FF:EE:BA:BE"
- ssid = "ch" .. channel .. ssidshort
elseif chan >= 36 and chan <= 64 then
hwmode = "11a"
mrate = ""
outdoor = 0
bssid = "00:" .. channel ..":CA:FF:EE:EE"
- ssid = "ch" .. channel .. ssidshort
elseif chan >= 100 and chan <= 140 then
hwmode = "11a"
mrate = ""
outdoor = 1
bssid = "01:" .. string.sub(channel, 2) .. ":CA:FF:EE:EE"
- ssid = "ch" .. channel .. ssidshort
end
devconfig.hwmode = hwmode
devconfig.outdoor = outdoor
end
+ ssid = ssid .. " - ch" .. channel
end
uci:tset("wireless", device, devconfig)
-- Create wifi iface
util.update(ifconfig, uci:get_all(external, "wifi_iface") or {})
ifconfig.device = device
ifconfig.network = nif
- if ssid then
- -- See Table https://kifuse02.pberg.freifunk.net/moin/channel-bssid-essid
- ifconfig.ssid = ssid
- else
- ifconfig.ssid = "olsr.freifunk.net"
- end
- -- See Table https://kifuse02.pberg.freifunk.net/moin/channel-bssid-essid
+ ifconfig.ssid = ssid
ifconfig.bssid = bssid
ifconfig.encryption="none"
-- Read Preset
local client = luci.http.formvalue("cbid.ffwizward.1.client_" .. device)
if client then
local dhcpmeshnet = luci.http.formvalue("cbid.ffwizward.1.dhcpmesh_" .. device) and ip.IPv4(luci.http.formvalue("cbid.ffwizward.1.dhcpmesh_" .. device))
- local ifacelist = uci:get_list("manager", "heartbeat", "interface") or {}
- table.insert(ifacelist,nif .. "dhcp")
- uci:set_list("manager", "heartbeat", "interface", ifacelist)
- uci:save("manager")
+ if has_hb then
+ local ifacelist = uci:get_list("manager", "heartbeat", "interface") or {}
+ table.insert(ifacelist,nif .. "dhcp")
+ uci:set_list("manager", "heartbeat", "interface", ifacelist)
+ uci:save("manager")
+ end
if dhcpmeshnet then
if not dhcpmeshnet:minhost() or not dhcpmeshnet:mask() then
dhcpmesh.tag_missing[section] = true
device =device,
mode ="ap",
encryption ="none",
- network =nif.."dhcp",
- ssid ="AP"..ssidshort
+ network =nif .. "dhcp",
+ ssid ="AP-" .. ssid
})
if has_radvd then
uci:section("radvd", "interface", nil, {
local client = luci.http.formvalue("cbid.ffwizward.1.client_" .. device)
if client then
local dhcpmeshnet = luci.http.formvalue("cbid.ffwizward.1.dhcpmesh_" .. device) and ip.IPv4(luci.http.formvalue("cbid.ffwizward.1.dhcpmesh_" .. device))
- local ifacelist = uci:get_list("manager", "heartbeat", "interface") or {}
- table.insert(ifacelist,device .. "dhcp")
- uci:set_list("manager", "heartbeat", "interface", ifacelist)
- uci:save("manager")
+ if has_hb then
+ local ifacelist = uci:get_list("manager", "heartbeat", "interface") or {}
+ table.insert(ifacelist,device .. "dhcp")
+ uci:set_list("manager", "heartbeat", "interface", ifacelist)
+ uci:save("manager")
+ end
if dhcpmeshnet then
if not dhcpmeshnet:minhost() or not dhcpmeshnet:mask() then
dhcpmesh.tag_missing[section] = true
local new_hostname = uci:get("freifunk", "wizard", "hostname")
local old_hostname = sys.hostname()
- local dhcphb = hb:formvalue(section)
- if dhcphb then
- uci:set("manager", "heartbeat", "enabled", "1")
- -- Make sure that heartbeat is enabled
- sys.init.enable("machash")
-
- else
- uci:set("manager", "heartbeat", "enabled", "0")
- -- Make sure that heartbeat is enabled
- sys.init.disable("machash")
+ if has_hb then
+ local dhcphb = hb:formvalue(section)
+ if dhcphb then
+ uci:set("manager", "heartbeat", "enabled", "1")
+ -- Make sure that heartbeat is enabled
+ sys.init.enable("machash")
+ else
+ uci:set("manager", "heartbeat", "enabled", "0")
+ -- Make sure that heartbeat is enabled
+ sys.init.disable("machash")
+ end
+ uci:save("manager")
end
- uci:save("manager")
local custom_hostname = hostname:formvalue(section)
uci:foreach("system", "system",
uci:save("olsrd")
uci:save("dhcp")
-- Import hosts and set domain
- uci:foreach("dhcp", "dnsmasq", function(s)
- uci:set_list("dhcp", s[".name"], "addnhosts", "/var/etc/hosts.olsr")
- end)
-
if has_ipv6 then
uci:foreach("dhcp", "dnsmasq", function(s)
- uci:set_list("dhcp", s[".name"], "addnhosts", "/var/etc/hosts.olsr.ipv6")
+ uci:set_list("dhcp", s[".name"], "addnhosts", {"/var/etc/hosts.olsr","/var/etc/hosts.olsr.ipv6"})
end)
+ else
+ uci:foreach("dhcp", "dnsmasq", function(s)
+ uci:set_list("dhcp", s[".name"], "addnhosts", "/var/etc/hosts.olsr")
+ end)
end
-
uci:save("dhcp")
-- Internet sharing