diff options
author | Manuel Munz <freifunk@somakoma.de> | 2011-01-25 21:04:57 +0000 |
---|---|---|
committer | Manuel Munz <freifunk@somakoma.de> | 2011-01-25 21:04:57 +0000 |
commit | c36fd44de2db30c08848bf326365a1e372b7879c (patch) | |
tree | aa34a63d3270b4d9ba953c5bed9000aa961de745 /applications/luci-ffwizard | |
parent | 9c03a76fc28dac4efe4714f0e61bb41bf2784ef7 (diff) |
applications/ffwizard: Massive changes to the ffwizard to make it more generic. Also introduces changes to the community profiles. ffwizard replaces ffwizard-leipzig now. It is not completely finished yet, but should work in most cases.
Diffstat (limited to 'applications/luci-ffwizard')
-rw-r--r-- | applications/luci-ffwizard/luasrc/controller/ffwizard.lua | 10 | ||||
-rw-r--r-- | applications/luci-ffwizard/luasrc/model/cbi/freifunk/ffwizard.lua (renamed from applications/luci-ffwizard/luasrc/model/cbi/ffwizard.lua) | 379 | ||||
-rw-r--r-- | applications/luci-ffwizard/luasrc/view/freifunk/ffwizard_error.htm | 27 | ||||
-rwxr-xr-x | applications/luci-ffwizard/root/etc/uci-defaults/device-defaults | 5 |
4 files changed, 135 insertions, 286 deletions
diff --git a/applications/luci-ffwizard/luasrc/controller/ffwizard.lua b/applications/luci-ffwizard/luasrc/controller/ffwizard.lua index 428962d4be..5ad48eeabe 100644 --- a/applications/luci-ffwizard/luasrc/controller/ffwizard.lua +++ b/applications/luci-ffwizard/luasrc/controller/ffwizard.lua @@ -18,6 +18,10 @@ $Id$ module "luci.controller.ffwizard" function index() - entry({"admin", "freifunk", "ffwizard"}, form("ffwizard"), "Freifunkassistent", 1) - assign({"mini", "freifunk", "ffwizard"}, {"admin", "freifunk", "ffwizard"}, "Freifunkassistent", 1) -end
\ No newline at end of file + entry({"admin", "freifunk", "ffwizard"}, form("freifunk/ffwizard"), "Freifunkassistent", 40) + assign({"mini", "freifunk", "ffwizard"}, {"admin", "freifunk", "ffwizard"}, "Freifunkassistent", 40) + + entry({"admin", "freifunk", "ffwizard_error"}, template("freifunk/ffwizard_error")) + assign({"mini", "freifunk", "ffwizard_error"}, {"admin", "freifunk", "ffwizard_error"}) +end + diff --git a/applications/luci-ffwizard/luasrc/model/cbi/ffwizard.lua b/applications/luci-ffwizard/luasrc/model/cbi/freifunk/ffwizard.lua index 47118d19b7..3047ec37a9 100644 --- a/applications/luci-ffwizard/luasrc/model/cbi/ffwizard.lua +++ b/applications/luci-ffwizard/luasrc/model/cbi/freifunk/ffwizard.lua @@ -4,15 +4,13 @@ LuCI - Lua Configuration Interface Copyright 2008 Steven Barth <steven@midlink.org> Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net> Copyright 2011 Patrick Grimm <patrick@pberg.freifunk.net> +Copyright 2011 Manuel Munz <freifunk at somakoma dot de> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - -$Id$ - ]]-- @@ -33,9 +31,19 @@ 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") +local community = "profile_" .. (uci:get("freifunk", "community", "name") or "na") +local lat = uci:get_first("system", "system", "latitude") +local lon = uci:get_first("system", "system", "longitude") +local suffix = uci:get_first(community, "community", "suffix") or "olsr" luci.i18n.loadc("freifunk") +-- Check if all necessary variables are available +if not (community ~= "profile_na" and lat and lon) then + luci.http.redirect(luci.dispatcher.build_url(unpack(luci.dispatcher.context.requested.path), "freifunk", "ffwizard_error")) + return +end + function get_mac(ix) if string.find(ix, "radio") then ix = string.gsub(ix,"radio", 'wlan') @@ -52,6 +60,7 @@ function get_mac(ix) end return "?" end + function get_ula(imac) if string.len(imac) == 17 then local mac1 = string.sub(imac,4,8) @@ -62,6 +71,33 @@ function get_ula(imac) return "?" end +function gen_dhcp_range(n) + local subnet_prefix = tonumber(uci:get_first(community, "community", "splash_prefix")) or 27 + local pool_network = uci:get_first(community, "community", "splash_network") or "10.104.0.0/16" + local pool = luci.ip.IPv4(pool_network) + local ip = tostring(n) + if pool and ip then + local hosts_per_subnet = 2^(32 - subnet_prefix) + local number_of_subnets = (2^pool:prefix())/hosts_per_subnet + local seed1, seed2 = ip:match("(%d+)%.(%d+)$") + if seed1 and seed2 then + math.randomseed((seed1+1)*(seed2+1)) + end + local subnet = pool:add(hosts_per_subnet * math.random(number_of_subnets)) + dhcp_ip = subnet:network(subnet_prefix):add(1):string() + dhcp_mask = subnet:mask(subnet_prefix):string() + end + return "?" +end + +function hbconf(dev) + if has_hb then + local ifacelist = uci:get_list("manager", "heartbeat", "interface") or {} + table.insert(ifacelist,dev .. "dhcp") + uci:set_list("manager", "heartbeat", "interface", ifacelist) + uci:save("manager") + end +end -------------------- View -------------------- f = SimpleForm("ffwizward", "Freifunkassistent", @@ -82,80 +118,31 @@ if sys.exec("diff /rom/etc/passwd /etc/passwd") == "" then end end -net = f:field(ListValue, "net", "Freifunk Community", "Nutzen Sie die Einstellungen der Freifunk Gemeinschaft in ihrer Nachbarschaft.") -net.rmempty = false -net.optional = false -uci:foreach("freifunk", "community", function(s) - net:value(s[".name"], "%s (%s)" % {s.name, s.mesh_network or "?"}) -end) -function net.cfgvalue(self, section) - return uci:get("freifunk", "wizard", "net") -end -function net.write(self, section, value) - uci:set("freifunk", "wizard", "net", value) - uci:save("freifunk") -end -net_lat = f:field(ListValue, "net_lat", "", "") -net_lat:depends("net", "0") -net_lon = f:field(ListValue, "net_lon", "", "") -net_lon:depends("net", "0") - -uci:foreach("freifunk", "community", function(s) - if s.latitude then - net_lat:value(s[".name"], "%s" % {s.latitude or "?"}) - end - if s.longitude then - net_lon:value(s[".name"], "%s" % {s.longitude or "?"}) - end -end) - --- hostname -hostname = f:field(Value, "hostname", "Knoten Name", "Geben Sie Ihrem Freifunk Router einen Namen. Wenn Sie dieses Feld leer lassen, wird der Name automatisch aus der Mesh IP generiert.") -hostname.rmempty = true -hostname.optional = false -function hostname.cfgvalue(self, section) - return sys.hostname() -end -function hostname.write(self, section, value) - uci:set("freifunk", "wizard", "hostname", value) - uci:save("freifunk") -end -function hostname.validate(self, value) - 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 - end -end +-- main netconfig --- location -location = f:field(Value, "location", "Standort", "Geben Sie den Standort ihres Gerätes an") -location.rmempty = false -location.optional = false -function location.cfgvalue(self, section) - return uci:get("freifunk", "contact", "location") -end -function location.write(self, section, value) - uci:set("freifunk", "contact", "location", value) - uci:save("freifunk") -end +local cc = uci:get(community, "wifi_device", "country") or "DE" --- mail -mail = f:field(Value, "mail", "E-Mail", "Bitte hinterlegen Sie eine Kontaktadresse.") -mail.rmempty = false -mail.optional = false -function mail.cfgvalue(self, section) - return uci:get("freifunk", "contact", "mail") -end -function mail.write(self, section, value) - uci:set("freifunk", "contact", "mail", value) - uci:save("freifunk") -end --- main netconfig main = f:field(Flag, "netconfig", "Netzwerk einrichten", "Setzen Sie den Haken, wenn Sie Ihr Freifunk Netzwerk einrichten wollen.") uci:foreach("wireless", "wifi-device", function(section) local device = section[".name"] + local hwtype = section.type + + local syscc = uci:get("wireless", device, "country") + if not syscc then + if hwtype == "atheros" then + cc = sys.exec("grep -i '" .. cc .. "' /lib/wifi/cc_translate.txt |cut -d ' ' -f 2") or 0 + sys.exec("echo " .. cc .. " > /proc/sys/dev/" .. device .. "/countrycode") + elseif hwtype == "mac80211" then + sys.exec("iw reg set " .. cc) + elseif hwtype == "broadcom" then + -- verify that ot works! + sys.exec ("wlc country " .. cc) + end + else + cc = syscc + end + local dev = f:field(Flag, "device_" .. device , "<b>Drahtloses Netzwerk \"" .. device:upper() .. "\"</b> ", "Konfigurieren Sie Ihre drahtlose " .. device:upper() .. "Schnittstelle (WLAN).") dev:depends("netconfig", "1") dev.rmempty = false @@ -189,7 +176,7 @@ uci:foreach("wireless", "wifi-device", 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) @@ -201,12 +188,6 @@ uci:foreach("wireless", "wifi-device", end function meship.write(self, sec, value) uci:set("freifunk", "wizard", "meship_" .. device, value) - local new_ip = ip.IPv4(value) - if new_ip then - local new_hostname = new_ip:string():gsub("%.", "-") - uci:set("freifunk", "wizard", "hostname", new_hostname) - uci:save("freifunk") - end end if has_ipv6 then local meship6 = f:field(Value, "meship6_" .. device, device:upper() .. " Mesh IPv6 Adresse einrichten", "Ihre Mesh IP Adresse wird automatisch berechnet") @@ -219,7 +200,7 @@ uci:foreach("wireless", "wifi-device", local client = f:field(Flag, "client_" .. device, device:upper() .. " DHCP anbieten", "DHCP weist verbundenen Benutzern automatisch eine Adresse zu. Diese Option sollten Sie unbedingt aktivieren, wenn Sie Nutzer an der drahtlosen Schnittstelle erwarten.") client:depends("device_" .. device, "1") - client.rmempty = false + client.rmempty = true function client.cfgvalue(self, section) return uci:get("freifunk", "wizard", "client_" .. device) end @@ -320,93 +301,6 @@ uci:foreach("network", "interface", end end) - -local syslat = uci:get("freifunk", "wizard", "latitude") or 52 -local syslon = uci:get("freifunk", "wizard", "longitude") or 10 -uci:foreach("system", "system", function(s) - if s.latitude then - syslat = s.latitude - end - if s.longitude then - syslon = s.longitude - end -end) -uci:foreach("olsrd", "LoadPlugin", function(s) - if s.library == "olsrd_nameservice.so.0.3" then - if s.lat then - syslat = s.lat - end - if s.lon then - syslon = s.lon - end - end -end) - -lat = f:field(Value, "lat", "geographischer Breitengrad", "Setzen Sie den Breitengrad (Latitude) Ihres Geräts.") -lat:depends("netconfig", "1") -function lat.cfgvalue(self, section) - return syslat -end -function lat.write(self, section, value) - uci:set("freifunk", "wizard", "latitude", value) - uci:save("freifunk") -end - -lon = f:field(Value, "lon", "geograpischer Längengrad", "Setzen Sie den Längengrad (Longitude) Ihres Geräts.") -lon:depends("netconfig", "1") -function lon.cfgvalue(self, section) - return syslon -end -function lon.write(self, section, value) - uci:set("freifunk", "wizard", "longitude", value) - uci:save("freifunk") -end - ---[[ -*Opens an OpenStreetMap iframe or popup -*Makes use of resources/OSMLatLon.htm and htdocs/resources/osm.js -(is that the right place for files like these?) -]]-- - -local class = util.class - -OpenStreetMapLonLat = class(AbstractValue) - -function OpenStreetMapLonLat.__init__(self, ...) - AbstractValue.__init__(self, ...) - self.template = "cbi/osmll_value" - self.latfield = nil - self.lonfield = nil - self.centerlat = "" - self.centerlon = "" - self.zoom = "0" - self.width = "100%" --popups will ignore the %-symbol, "100%" is interpreted as "100" - self.height = "600" - self.popup = false - self.displaytext="OpenStreetMap" --text on button, that loads and displays the OSMap - self.hidetext="X" -- text on button, that hides OSMap -end - -osm = f:field(OpenStreetMapLonLat, "latlon", "Geokoordinaten mit OpenStreetMap ermitteln:", "Klicken Sie auf Ihren Standort in der Karte. Diese Karte funktioniert nur, wenn das Gerät bereits eine Verbindung zum Internet hat.") -osm:depends("netconfig", "1") -osm.latfield = "lat" -osm.lonfield = "lon" -osm.centerlat = syslat -osm.centerlon = syslon -osm.width = "100%" -osm.height = "600" -osm.popup = false -syslatlengh = string.len(syslat) -if syslatlengh > 7 then - osm.zoom = "15" -elseif syslatlengh > 5 then - osm.zoom = "12" -else - osm.zoom = "6" -end -osm.displaytext="OpenStreetMap anzeigen" -osm.hidetext="OpenStreetMap verbergen" - share = f:field(Flag, "sharenet", "Eigenen Internetzugang freigeben", "Geben Sie Ihren Internetzugang im Freifunknetz frei.") share.rmempty = false share:depends("netconfig", "1") @@ -420,8 +314,8 @@ end wanproto = f:field(ListValue, "wanproto", "Protokoll des Internetzugangs", "Geben Sie das Protokol an ueber das eine Internet verbindung hergestellt werden kann.") wanproto:depends("sharenet", "1") -wanproto:value("static", translate("manual", "manual")) -wanproto:value("dhcp", translate("automatic", "automatic")) +wanproto:value("static", translate("static", "static")) +wanproto:value("dhcp", translate("dhcp", "dhcp")) if has_pppoe then wanproto:value("pppoe", "PPPoE") end if has_pptp then wanproto:value("pptp", "PPTP") end function wanproto.cfgvalue(self, section) @@ -587,7 +481,6 @@ function f.handle(self, state, data) uci:commit("luci_splash") uci:commit("firewall") uci:commit("system") - uci:commit("uhttpd") uci:commit("olsrd") uci:commit("manager") if has_autoipv6 then @@ -603,7 +496,7 @@ function f.handle(self, state, data) uci:commit("radvd") end - 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 &") + sys.exec("for s in network dnsmasq luci_splash firewall 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 @@ -630,8 +523,8 @@ function main.write(self, section, value) return end -- Collect IP-Address - local community = net:formvalue(section) - suffix = uci:get("freifunk", community, "suffix") or "olsr" + uci:set("freifunk", "wizard", "net", uci:get_first(community, "community", "mesh_network")) + uci:save("freifunk") -- Invalidate fields if not community then @@ -642,17 +535,14 @@ function main.write(self, section, value) uci:set("freifunk", "wizard", "netconfig", "1") uci:save("freifunk") - local external - external = uci:get("freifunk", community, "external") or "" - local netname = "wireless" local network - network = ip.IPv4(uci:get("freifunk", community, "mesh_network") or "104.0.0.0/8") + network = ip.IPv4(uci:get_first(community, "community", "mesh_network") or "104.0.0.0/8") -- Tune community settings - if community and uci:get("freifunk", community) then - uci:tset("freifunk", "community", uci:get_all("freifunk", community)) - end +-- if community and uci:get("freifunk", community) then +-- uci:get_all(community) +-- end -- Cleanup uci:delete_all("firewall","zone", {name="freifunk"}) @@ -668,14 +558,14 @@ function main.write(self, section, value) uci:foreach("freifunk", "fw_forwarding", function(section) uci:section("firewall", "forwarding", nil, section) end) - uci:foreach(external, "fw_forwarding", function(section) + uci:foreach(community, "fw_forwarding", function(section) uci:section("firewall", "forwarding", nil, section) end) uci:foreach("freifunk", "fw_rule", function(section) uci:section("firewall", "rule", nil, section) end) - uci:foreach(external, "fw_rule", function(section) + uci:foreach(community, "fw_rule", function(section) uci:section("firewall", "rule", nil, section) end) end @@ -688,7 +578,7 @@ function main.write(self, section, value) uci:delete_all("olsrd", "olsrd") local olsrbase olsrbase = uci:get_all("freifunk", "olsrd") or {} - util.update(olsrbase, uci:get_all(external, "olsrd") or {}) + util.update(olsrbase, uci:get_all(community, "olsrd") or {}) if has_ipv6 then olsrbase.IpVersion='6and4' else @@ -765,12 +655,12 @@ function main.write(self, section, value) end -- New Config -- Tune wifi device - local ssid = uci:get("freifunk", community, "ssid") or "olsr.freifunk.net" + local ssid = uci:get_first(community, "community", "ssid") or "olsr.freifunk.net" local devconfig = uci:get_all("freifunk", "wifi_device") - util.update(devconfig, uci:get_all(external, "wifi_device") or {}) + util.update(devconfig, uci:get_all(community, "wifi_device") or {}) local channel = luci.http.formvalue("cbid.ffwizward.1.chan_" .. device) local hwmode = "11bg" - local bssid = uci:get_all(external, "wifi_iface", "bssid") or "02:CA:FF:EE:BA:BE" + local bssid = uci:get_all(community, "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 @@ -786,23 +676,21 @@ function main.write(self, section, value) elseif chan >= 36 and chan <= 64 then hwmode = "11a" mrate = "" - outdoor = 0 bssid = "00:" .. channel ..":CA:FF:EE:EE" elseif chan >= 100 and chan <= 140 then hwmode = "11a" mrate = "" - outdoor = 1 bssid = "01:" .. string.sub(channel, 2) .. ":CA:FF:EE:EE" end devconfig.hwmode = hwmode - devconfig.outdoor = outdoor end + devconfig.country = cc ssid = ssid .. " - ch" .. channel end uci:tset("wireless", device, devconfig) -- Create wifi iface local ifconfig = uci:get_all("freifunk", "wifi_iface") - util.update(ifconfig, uci:get_all(external, "wifi_iface") or {}) + util.update(ifconfig, uci:get_all(community, "wifi_iface") or {}) ifconfig.device = device ifconfig.network = nif ifconfig.ssid = ssid @@ -810,7 +698,7 @@ function main.write(self, section, value) ifconfig.encryption="none" -- Read Preset local netconfig = uci:get_all("freifunk", "interface") - util.update(netconfig, uci:get_all(external, "interface") or {}) + util.update(netconfig, uci:get_all(community, "interface") or {}) netconfig.proto = "static" netconfig.ipaddr = node_ip:string() if has_ipv6 then @@ -834,14 +722,11 @@ function main.write(self, section, value) }) uci:save("radvd") end - local new_hostname = node_ip:string():gsub("%.", "-") - uci:set("freifunk", "wizard", "hostname", new_hostname) - uci:save("freifunk") tools.firewall_zone_add_interface("freifunk", nif) uci:save("firewall") -- Write new olsrv4 interface local olsrifbase = uci:get_all("freifunk", "olsr_interface") - util.update(olsrifbase, uci:get_all(external, "olsr_interface") or {}) + util.update(olsrifbase, uci:get_all(community, "olsr_interface") or {}) olsrifbase.interface = nif olsrifbase.ignore = "0" uci:section("olsrd", "Interface", nil, olsrifbase) @@ -849,12 +734,15 @@ function main.write(self, section, value) 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)) + hbconf(nif) + --[[ 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 @@ -883,26 +771,12 @@ function main.write(self, section, value) end end) else - local subnet_prefix = tonumber(uci:get("freifunk", community, "splash_prefix")) or 27 - local pool_network = uci:get("freifunk", community, "splash_network") or "10.104.0.0/16" - local pool = luci.ip.IPv4(pool_network) - local ip = tostring(node_ip) - if pool and ip then - local hosts_per_subnet = 2^(32 - subnet_prefix) - local number_of_subnets = (2^pool:prefix())/hosts_per_subnet - local seed1, seed2 = ip:match("(%d+)%.(%d+)$") - if seed1 and seed2 then - math.randomseed(seed1 * seed2) - end - local subnet = pool:add(hosts_per_subnet * math.random(number_of_subnets)) - dhcp_ip = subnet:network(subnet_prefix):add(1):string() - dhcp_mask = subnet:mask(subnet_prefix):string() - end + gen_dhcp_range(netconfig.ipaddr) end if dhcp_ip and dhcp_mask then -- Create alias local aliasbase = uci:get_all("freifunk", "alias") - util.update(aliasbase, uci:get_all(external, "alias") or {}) + util.update(aliasbase, uci:get_all(community, "alias") or {}) aliasbase.ipaddr = dhcp_ip aliasbase.netmask = dhcp_mask aliasbase.proto = "static" @@ -943,7 +817,7 @@ function main.write(self, section, value) end -- Create dhcp local dhcpbase = uci:get_all("freifunk", "dhcp") - util.update(dhcpbase, uci:get_all(external, "dhcp") or {}) + util.update(dhcpbase, uci:get_all(community, "dhcp") or {}) dhcpbase.interface = nif .. "dhcp" dhcpbase.force = 1 uci:section("dhcp", "dhcp", nif .. "dhcp", dhcpbase) @@ -1011,9 +885,9 @@ function main.write(self, section, value) end if device ~= "loopback" and not string.find(device, "wifi") and not string.find(device, "wl") and not string.find(device, "wlan") and not string.find(device, "wireless") and not string.find(device, "radio") then local node_ip - node_ip = luci.http.formvalue("cbid.ffwizward.1.meship_" .. device) and ip.IPv4(luci.http.formvalue("cbid.ffwizward.1.meship_" .. device)) + node_ip = luci.http.formvalue("cbid.ffwizward.1.meship_" .. device) --and ip.IPv4(luci.http.formvalue("cbid.ffwizward.1.meship_" .. device)) if has_ipv6 then - node_ip6 = luci.http.formvalue("cbid.ffwizward.1.meship6_" .. device) and ip.IPv6(luci.http.formvalue("cbid.ffwizward.1.meship6_" .. device)) + node_ip6 = luci.http.formvalue("cbid.ffwizward.1.meship6_" .. device) --and ip.IPv6(luci.http.formvalue("cbid.ffwizward.1.meship6_" .. device)) end if not node_ip or not network or not network:contains(node_ip) then meship.tag_missing[section] = true @@ -1039,7 +913,7 @@ function main.write(self, section, value) end -- New Config local netconfig = uci:get_all("freifunk", "interface") - util.update(netconfig, uci:get_all(external, "interface") or {}) + util.update(netconfig, uci:get_all(community, "interface") or {}) netconfig.proto = "static" netconfig.ipaddr = node_ip:string() if has_ipv6 then @@ -1064,14 +938,11 @@ function main.write(self, section, value) }) uci:save("radvd") end - local new_hostname = node_ip:string():gsub("%.", "-") - uci:set("freifunk", "wizard", "hostname", new_hostname) - uci:save("freifunk") tools.firewall_zone_add_interface("freifunk", device) uci:save("firewall") -- Write new olsrv4 interface local olsrifbase = uci:get_all("freifunk", "olsr_interface") - util.update(olsrifbase, uci:get_all(external, "olsr_interface") or {}) + util.update(olsrifbase, uci:get_all(community, "olsr_interface") or {}) olsrifbase.interface = device olsrifbase.ignore = "0" uci:section("olsrd", "Interface", nil, olsrifbase) @@ -1080,12 +951,17 @@ function main.write(self, section, value) 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)) + hbconf(device) +--[[ if has_hb then + hbconf(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") + end +]] if dhcpmeshnet then if not dhcpmeshnet:minhost() or not dhcpmeshnet:mask() then dhcpmesh.tag_missing[section] = true @@ -1108,26 +984,12 @@ function main.write(self, section, value) end end) else - local subnet_prefix = tonumber(uci:get("freifunk", community, "splash_prefix")) or 27 - local pool_network = uci:get("freifunk", community, "splash_network") or "10.104.0.0/16" - local pool = luci.ip.IPv4(pool_network) - local ip = tostring(node_ip) - if pool and ip then - local hosts_per_subnet = 2^(32 - subnet_prefix) - local number_of_subnets = (2^pool:prefix())/hosts_per_subnet - local seed1, seed2 = ip:match("(%d+)%.(%d+)$") - if seed1 and seed2 then - math.randomseed(seed1 * seed2) - end - local subnet = pool:add(hosts_per_subnet * math.random(number_of_subnets)) - dhcp_ip = subnet:network(subnet_prefix):add(1):string() - dhcp_mask = subnet:mask(subnet_prefix):string() - end + gen_dhcp_range(netconfig.ipaddr) end if dhcp_ip and dhcp_mask then -- Create alias local aliasbase = uci:get_all("freifunk", "alias") - util.update(aliasbase, uci:get_all(external, "alias") or {}) + util.update(aliasbase, uci:get_all(community, "alias") or {}) aliasbase.interface = device aliasbase.ipaddr = dhcp_ip aliasbase.netmask = dhcp_mask @@ -1135,7 +997,7 @@ function main.write(self, section, value) uci:section("network", "alias", device .. "dhcp", aliasbase) -- Create dhcp local dhcpbase = uci:get_all("freifunk", "dhcp") - util.update(dhcpbase, uci:get_all(external, "dhcp") or {}) + util.update(dhcpbase, uci:get_all(community, "dhcp") or {}) dhcpbase.interface = device .. "dhcp" dhcpbase.force = 1 uci:section("dhcp", "dhcp", device .. "dhcp", dhcpbase) @@ -1226,9 +1088,6 @@ function main.write(self, section, value) uci:save("firewall") uci:save("dhcp") - local new_hostname = uci:get("freifunk", "wizard", "hostname") - local old_hostname = sys.hostname() - if has_hb then local dhcphb = hb:formvalue(section) if dhcphb then @@ -1243,7 +1102,6 @@ function main.write(self, section, value) uci:save("manager") end - local custom_hostname = hostname:formvalue(section) uci:foreach("system", "system", function(s) -- Make crond silent @@ -1251,18 +1109,6 @@ function main.write(self, section, value) -- Make set timzone and zonename uci:set("system", s['.name'], "zonename", "Europe/Berlin") uci:set("system", s['.name'], "timezone", 'CET-1CEST,M3.5.0,M10.5.0/3') - -- Set hostname - if custom_hostname then - uci:set("system", s['.name'], "hostname", custom_hostname) - sys.hostname(custom_hostname) - else - if new_hostname then - if old_hostname == "OpenWrt" or old_hostname:match("^%d+-%d+-%d+-%d+$") then - uci:set("system", s['.name'], "hostname", new_hostname) - sys.hostname(new_hostname) - end - end - end end) -- Create time rdate_servers @@ -1275,29 +1121,6 @@ function main.write(self, section, value) uci:section("system", "rdate", nil, rdate) uci:save("system") - -- Create http splash port 8082 - uci:set_list("uhttpd","main","listen_http",{"80"}) - uci:set_list("uhttpd","main","listen_https",{"443"}) - uci:save("uhttpd") - - -- Read geos - local latval = tonumber(lat:formvalue(section)) - local lonval = tonumber(lon:formvalue(section)) - - -- Save latlon to system too - if latval and lonval then - uci:foreach("system", "system", function(s) - uci:set("system", s[".name"], "latlon",string.format("%.15f %.15f", latval, lonval)) - uci:set("system", s[".name"], "latitude",string.format("%.15f", latval)) - uci:set("system", s[".name"], "longitude",string.format("%.15f", lonval)) - end) - else - uci:foreach("system", "system", function(s) - uci:delete("system", s[".name"], "latlon") - uci:delete("system", s[".name"], "latitude") - uci:delete("system", s[".name"], "longitude") - end) - end -- Delete old watchdog settings uci:delete_all("olsrd", "LoadPlugin", {library="olsrd_watchdog.so.0.1"}) -- Write new watchdog settings @@ -1315,8 +1138,8 @@ function main.write(self, section, value) suffix = "." .. suffix , hosts_file = "/var/etc/hosts.olsr", latlon_file = "/var/run/latlon.js", - lat = latval and string.format("%.15f", latval) or "", - lon = lonval and string.format("%.15f", lonval) or "", + lat = lat and string.format("%.15f", lat) or "", + lon = lon and string.format("%.15f", lon) or "", services_file = "/var/etc/services.olsr" }) @@ -1416,11 +1239,11 @@ function main.write(self, section, value) uci:delete_all("l2gvpn", "supernode") -- Write olsr tunnel interface options local olsr_gvpnifbase = uci:get_all("freifunk", "olsr_gvpninterface") - util.update(olsr_gvpnifbase, uci:get_all(external, "olsr_gvpninterface") or {}) + util.update(olsr_gvpnifbase, uci:get_all(community, "olsr_gvpninterface") or {}) uci:section("olsrd", "Interface", nil, olsr_gvpnifbase) local vpnip = gvpnip:formvalue(section) local gvpnif = uci:get_all("freifunk", "gvpn_node") - util.update(gvpnif, uci:get_all(external, "gvpn_node") or {}) + util.update(gvpnif, uci:get_all(community, "gvpn_node") or {}) if gvpnif and gvpnif.tundev and vpnip then uci:section("network", "interface", gvpnif.tundev, { ifname =gvpnif.tundev , diff --git a/applications/luci-ffwizard/luasrc/view/freifunk/ffwizard_error.htm b/applications/luci-ffwizard/luasrc/view/freifunk/ffwizard_error.htm new file mode 100644 index 0000000000..2364ff2adb --- /dev/null +++ b/applications/luci-ffwizard/luasrc/view/freifunk/ffwizard_error.htm @@ -0,0 +1,27 @@ +<%+header%> + +<% +local uci = require "luci.model.uci".cursor() +local basicsurl = luci.dispatcher.build_url(luci.dispatcher.context.path[1], "freifunk", "basics") +local hostname = uci:get_first ("system", "system", "hostname") +local latitude = uci:get_first ("system", "system", "latitude") +local longitude = uci:get_first ("system", "system", "longitude") +local location = uci:get_first ("system", "system", "location") +%> + +<h2><%:Error%></h2> + +<%:You can not use the wizard because some necessary values are not set.%> +<p/> + +<% +local co = uci:get("freifunk", "community", "name") +if not (co and hostname and latitude and longitude and location) then +%> +<%:Basic settings are missing. Please go to this page and fill all required fields: %> +<a href='<%=basicsurl%>'><%:Basic settings%></a> +<p/> +<% end %> + + +<%+footer%> diff --git a/applications/luci-ffwizard/root/etc/uci-defaults/device-defaults b/applications/luci-ffwizard/root/etc/uci-defaults/device-defaults index bbad46ea2e..011148d592 100755 --- a/applications/luci-ffwizard/root/etc/uci-defaults/device-defaults +++ b/applications/luci-ffwizard/root/etc/uci-defaults/device-defaults @@ -13,9 +13,6 @@ set_default_config() set freifunk.wifi_device.rxantenna=1 set freifunk.wifi_device.disabled=0 set freifunk.wifi_device.txpower="" - set freifunk.wifi_device.country=276 - set freifunk.wifi_device.regdomain="0x37" - set freifunk.wifi_device.outdoor="1" set freifunk.wifi_device.hwmode=11g set freifunk.wifi_device.distance=1000 set freifunk.wifi_iface=defaults @@ -33,7 +30,6 @@ set_default_config() set freifunk.wifi_device.diversity="" set freifunk.wifi_device.disabled=0 set freifunk.wifi_device.txpower="" - set freifunk.wifi_device.country=DE set freifunk.wifi_device.distance=1000 set freifunk.wifi_device.htmode='HT40-' set freifunk.wifi_device.hwmode=11ng @@ -50,7 +46,6 @@ set_default_config() set freifunk.wifi_device.diversity="" set freifunk.wifi_device.disabled=0 set freifunk.wifi_device.txpower="" - set freifunk.wifi_device.country=DE set freifunk.wifi_device.txantenna=0 set freifunk.wifi_device.rxantenna=0 set freifunk.wifi_device.hwmode=11g |