summaryrefslogtreecommitdiffhomepage
path: root/applications
diff options
context:
space:
mode:
authorManuel Munz <freifunk@somakoma.de>2011-01-25 21:04:57 +0000
committerManuel Munz <freifunk@somakoma.de>2011-01-25 21:04:57 +0000
commitc36fd44de2db30c08848bf326365a1e372b7879c (patch)
treeaa34a63d3270b4d9ba953c5bed9000aa961de745 /applications
parent9c03a76fc28dac4efe4714f0e61bb41bf2784ef7 (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')
-rw-r--r--applications/luci-ffwizard-leipzig/Makefile4
-rw-r--r--applications/luci-ffwizard-leipzig/luasrc/controller/ffwizard.lua21
-rw-r--r--applications/luci-ffwizard-leipzig/luasrc/model/cbi/ffwizard.lua493
-rw-r--r--applications/luci-ffwizard-leipzig/luasrc/tools/ffwizard.lua149
-rw-r--r--applications/luci-ffwizard/luasrc/controller/ffwizard.lua10
-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.htm27
-rwxr-xr-xapplications/luci-ffwizard/root/etc/uci-defaults/device-defaults5
8 files changed, 135 insertions, 953 deletions
diff --git a/applications/luci-ffwizard-leipzig/Makefile b/applications/luci-ffwizard-leipzig/Makefile
deleted file mode 100644
index a4f7c76ef..000000000
--- a/applications/luci-ffwizard-leipzig/Makefile
+++ /dev/null
@@ -1,4 +0,0 @@
-PO =
-
-include ../../build/config.mk
-include ../../build/module.mk
diff --git a/applications/luci-ffwizard-leipzig/luasrc/controller/ffwizard.lua b/applications/luci-ffwizard-leipzig/luasrc/controller/ffwizard.lua
deleted file mode 100644
index 9a9f883ef..000000000
--- a/applications/luci-ffwizard-leipzig/luasrc/controller/ffwizard.lua
+++ /dev/null
@@ -1,21 +0,0 @@
---[[
-LuCI - Lua Configuration Interface
-
-Copyright 2008 Steven Barth <steven@midlink.org>
-Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
-
-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$
-
-]]--
-
-module "luci.controller.ffwizard"
-
-function index()
- entry({"admin", "freifunk", "ffwizard"}, form("ffwizard"), "Freifunkassistent", 50)
-end \ No newline at end of file
diff --git a/applications/luci-ffwizard-leipzig/luasrc/model/cbi/ffwizard.lua b/applications/luci-ffwizard-leipzig/luasrc/model/cbi/ffwizard.lua
deleted file mode 100644
index 780316c4a..000000000
--- a/applications/luci-ffwizard-leipzig/luasrc/model/cbi/ffwizard.lua
+++ /dev/null
@@ -1,493 +0,0 @@
---[[
-LuCI - Lua Configuration Interface
-
-Copyright 2008 Steven Barth <steven@midlink.org>
-Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
-
-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$
-
-]]--
-
-
-local uci = require "luci.model.uci".cursor()
-local tools = require "luci.tools.ffwizard"
-local util = require "luci.util"
-local sys = require "luci.sys"
-local ip = require "luci.ip"
-
-local function mksubnet(community, meship)
- 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)
-
- if pool then
- local hosts_per_subnet = 2^(32 - subnet_prefix)
- local number_of_subnets = (2^pool:prefix())/hosts_per_subnet
-
- local seed1, seed2 = meship:match("(%d+)%.(%d+)$")
- math.randomseed(seed1 * seed2)
-
- local subnet = pool:add(hosts_per_subnet * math.random(number_of_subnets))
-
- local subnet_ipaddr = subnet:network(subnet_prefix):add(1):string()
- local subnet_netmask = subnet:mask(subnet_prefix):string()
-
- return subnet_ipaddr, subnet_netmask
- end
-end
-
-
--------------------- View --------------------
-f = SimpleForm("ffwizward", "Freifunkassistent",
- "Dieser Assistent unterstüzt bei der Einrichtung des Routers für das Freifunknetz.")
-
-
-dev = f:field(ListValue, "device", "WLAN-Gerät")
-uci:foreach("wireless", "wifi-device",
- function(section)
- dev:value(section[".name"])
- end)
-
-
-main = f:field(Flag, "wifi", "Freifunkzugang einrichten")
-
-net = f:field(Value, "net", "Freifunk Community", "Mesh Netzbereich")
-net.rmempty = true
-net:depends("wifi", "1")
-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
-
-meship = f:field(Value, "meship", "Mesh IP Adresse", "Netzweit eindeutige Identifikation")
-meship.rmempty = true
-meship:depends("wifi", "1")
-function meship.cfgvalue(self, section)
- return uci:get("freifunk", "wizard", "meship")
-end
-function meship.write(self, section, value)
- uci:set("freifunk", "wizard", "meship", value)
- uci:save("freifunk")
-end
-function meship.validate(self, value)
- local x = ip.IPv4(value)
- return ( x and x:prefix() == 32 ) and x:string() or ""
-end
-
-client = f:field(Flag, "client", "WLAN-DHCP anbieten")
-client:depends("wifi", "1")
-client.rmempty = false
-function client.cfgvalue(self, section)
- return uci:get("freifunk", "wizard", "dhcp_splash") or "0"
-end
-
-olsr = f:field(Flag, "olsr", "OLSR einrichten")
-olsr.rmempty = true
-
-lat = f:field(Value, "lat", "Latitude")
-lat:depends("olsr", "1")
-function lat.cfgvalue(self, section)
- return uci:get("freifunk", "wizard", "latitude")
-end
-function lat.write(self, section, value)
- uci:set("freifunk", "wizard", "latitude", value)
- uci:save("freifunk")
-end
-
-lon = f:field(Value, "lon", "Longitude")
-lon:depends("olsr", "1")
-function lon.cfgvalue(self, section)
- return uci:get("freifunk", "wizard", "longitude")
-end
-function lon.write(self, section, value)
- uci:set("freifunk", "wizard", "longitude", value)
- uci:save("freifunk")
-end
-
-share = f:field(Flag, "sharenet", "Eigenen Internetzugang freigeben")
-share.rmempty = true
-
-wansec = f:field(Flag, "wansec", "WAN-Zugriff auf Gateway beschränken")
-wansec.rmempty = false
-wansec:depends("sharenet", "1")
-function wansec.cfgvalue(self, section)
- return uci:get("freifunk", "wizard", "wan_security")
-end
-function wansec.write(self, section, value)
- uci:set("freifunk", "wizard", "wan_security", value)
- uci:save("freifunk")
-end
-
--------------------- Control --------------------
-function f.handle(self, state, data)
- if state == FORM_VALID then
- luci.http.redirect(luci.dispatcher.build_url("admin", "uci", "changes"))
- return false
- elseif state == FORM_INVALID then
- self.errmessage = "Ungültige Eingabe: Bitte die Formularfelder auf Fehler prüfen."
- end
- return true
-end
-
-local function _strip_internals(tbl)
- tbl = tbl or {}
- for k, v in pairs(tbl) do
- if k:sub(1, 1) == "." then
- tbl[k] = nil
- end
- end
- return tbl
-end
-
--- Configure Freifunk checked
-function main.write(self, section, value)
- if value == "0" then
- return
- end
-
- local device = dev:formvalue(section)
- local node_ip, external
-
- -- Collect IP-Address
- local community = net:formvalue(section)
-
- -- Invalidate fields
- if not community then
- net.tag_missing[section] = true
- else
- external = uci:get("freifunk", community, "external") or ""
- network = ip.IPv4(uci:get("freifunk", community, "mesh_network") or "104.0.0.0/8")
- node_ip = meship:formvalue(section) and ip.IPv4(meship:formvalue(section))
-
- if not node_ip or not network or not network:contains(node_ip) then
- meship.tag_missing[section] = true
- node_ip = nil
- end
- end
-
- if not node_ip then return end
-
-
- -- Cleanup
- tools.wifi_delete_ifaces(device)
- tools.network_remove_interface(device)
- tools.firewall_zone_remove_interface("freifunk", device)
-
- -- Tune community settings
- if community and uci:get("freifunk", community) then
- uci:tset("freifunk", "community", uci:get_all("freifunk", community))
- end
-
- -- Tune wifi device
- local devconfig = uci:get_all("freifunk", "wifi_device")
- util.update(devconfig, uci:get_all(external, "wifi_device") or {})
- 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 {})
- ifconfig.device = device
- ifconfig.network = device
- ifconfig.ssid = uci:get("freifunk", community, "ssid")
- uci:section("wireless", "wifi-iface", nil, ifconfig)
-
- -- Save wifi
- uci:save("wireless")
-
- -- Create firewall zone and add default rules (first time)
- local newzone = tools.firewall_create_zone("freifunk", "REJECT", "ACCEPT", "REJECT", true)
- if newzone then
- uci:foreach("freifunk", "fw_forwarding", function(section)
- uci:section("firewall", "forwarding", nil, section)
- end)
- uci:foreach(external, "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:section("firewall", "rule", nil, section)
- end)
- end
-
- -- Enforce firewall include
- local has_include = false
- uci:foreach("firewall", "include",
- function(section)
- if section.path == "/etc/firewall.freifunk" then
- has_include = true
- end
- end)
-
- if not has_include then
- uci:section("firewall", "include", nil,
- { path = "/etc/firewall.freifunk" })
- end
-
- -- Allow state: invalid packets
- uci:foreach("firewall", "defaults",
- function(section)
- uci:set("firewall", section[".name"], "drop_invalid", "0")
- end)
-
- -- Prepare advanced config
- local has_advanced = false
- uci:foreach("firewall", "advanced",
- function(section) has_advanced = true end)
-
- if not has_advanced then
- uci:section("firewall", "advanced", nil,
- { tcp_ecn = "0", ip_conntrack_max = "8192", tcp_westwood = "1" })
- end
-
- uci:save("firewall")
-
-
- -- Create network interface
- local netconfig = uci:get_all("freifunk", "interface")
- util.update(netconfig, uci:get_all(external, "interface") or {})
- netconfig.proto = "static"
- netconfig.ipaddr = node_ip:string()
- uci:section("network", "interface", device, netconfig)
-
- uci:save("network")
-
- tools.firewall_zone_add_interface("freifunk", device)
-
-
- local new_hostname = node_ip:string():gsub("%.", "-")
- local old_hostname = sys.hostname()
-
- uci:foreach("system", "system",
- function(s)
- -- Make crond silent
- uci:set("system", s['.name'], "cronloglevel", "10")
-
- -- Set hostname
- 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)
-
- uci:save("system")
-end
-
-
-function olsr.write(self, section, value)
- if value == "0" then
- return
- end
-
-
- local device = dev:formvalue(section)
-
- local community = net:formvalue(section)
- local external = community and uci:get("freifunk", community, "external") or ""
-
- local latval = tonumber(lat:formvalue(section))
- local lonval = tonumber(lon:formvalue(section))
-
-
- -- Delete old interface
- uci:delete_all("olsrd", "Interface", {interface=device})
-
- -- Write new interface
- local olsrbase = uci:get_all("freifunk", "olsr_interface")
- util.update(olsrbase, uci:get_all(external, "olsr_interface") or {})
- olsrbase.interface = device
- olsrbase.ignore = "0"
- uci:section("olsrd", "Interface", nil, olsrbase)
-
- -- Delete old watchdog settings
- uci:delete_all("olsrd", "LoadPlugin", {library="olsrd_watchdog.so.0.1"})
-
- -- Write new watchdog settings
- uci:section("olsrd", "LoadPlugin", nil, {
- library = "olsrd_watchdog.so.0.1",
- file = "/var/run/olsrd.watchdog",
- interval = "30"
- })
-
- -- Delete old nameservice settings
- uci:delete_all("olsrd", "LoadPlugin", {library="olsrd_nameservice.so.0.3"})
-
- -- Write new nameservice settings
- uci:section("olsrd", "LoadPlugin", nil, {
- library = "olsrd_nameservice.so.0.3",
- suffix = ".olsr",
- 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 ""
- })
-
- -- 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))
- end)
- else
- uci:foreach("system", "system", function(s)
- uci:delete("system", s[".name"], "latlon")
- end)
- end
-
- -- Import hosts
- uci:foreach("dhcp", "dnsmasq", function(s)
- uci:set("dhcp", s[".name"], "addnhosts", "/var/etc/hosts.olsr")
- end)
-
- -- Make sure that OLSR is enabled
- sys.exec("/etc/init.d/olsrd enable")
-
- uci:save("olsrd")
- uci:save("dhcp")
-end
-
-
-function share.write(self, section, value)
- uci:delete_all("firewall", "forwarding", {src="freifunk", dest="wan"})
- uci:delete_all("olsrd", "LoadPlugin", {library="olsrd_dyn_gw_plain.so.0.4"})
- uci:foreach("firewall", "zone",
- function(s)
- if s.name == "wan" then
- uci:delete("firewall", s['.name'], "local_restrict")
- return false
- end
- end)
-
- if value == "1" then
- uci:section("firewall", "forwarding", nil, {src="freifunk", dest="wan"})
- uci:section("olsrd", "LoadPlugin", nil, {library="olsrd_dyn_gw_plain.so.0.4"})
-
- if wansec:formvalue(section) == "1" then
- uci:foreach("firewall", "zone",
- function(s)
- if s.name == "wan" then
- uci:set("firewall", s['.name'], "local_restrict", "1")
- return false
- end
- end)
- end
- end
-
- uci:save("firewall")
- uci:save("olsrd")
- uci:save("system")
-end
-
-
-function client.write(self, section, value)
- if value == "0" then
- uci:delete("freifunk", "wizard", "dhcp_splash")
- uci:save("freifunk")
- return
- end
-
- local device = dev:formvalue(section)
-
- -- Collect IP-Address
- local node_ip = meship:formvalue(section)
-
- if not node_ip then return end
-
- local community = net:formvalue(section)
- local external = community and uci:get("freifunk", community, "external") or ""
- local splash_ip, splash_mask = mksubnet(community, node_ip)
-
- -- Delete old alias
- uci:delete("network", device .. "dhcp")
-
- -- Create alias
- local aliasbase = uci:get_all("freifunk", "alias")
- util.update(aliasbase, uci:get_all(external, "alias") or {})
- aliasbase.interface = device
- aliasbase.ipaddr = splash_ip
- aliasbase.netmask = splash_mask
- aliasbase.proto = "static"
- uci:section("network", "alias", device .. "dhcp", aliasbase)
- uci:save("network")
-
-
- -- Create dhcp
- local dhcpbase = uci:get_all("freifunk", "dhcp")
- util.update(dhcpbase, uci:get_all(external, "dhcp") or {})
- dhcpbase.interface = device .. "dhcp"
- dhcpbase.start = dhcpbeg
- dhcpbase.limit = limit
- dhcpbase.force = 1
-
- uci:section("dhcp", "dhcp", device .. "dhcp", dhcpbase)
- uci:save("dhcp")
-
- uci:delete_all("firewall", "rule", {
- src="freifunk",
- proto="udp",
- dest_port="53"
- })
- uci:section("firewall", "rule", nil, {
- src="freifunk",
- proto="udp",
- dest_port="53",
- target="ACCEPT"
- })
- uci:delete_all("firewall", "rule", {
- src="freifunk",
- proto="udp",
- src_port="68",
- dest_port="67"
- })
- uci:section("firewall", "rule", nil, {
- src="freifunk",
- proto="udp",
- src_port="68",
- dest_port="67",
- target="ACCEPT"
- })
- uci:delete_all("firewall", "rule", {
- src="freifunk",
- proto="tcp",
- dest_port="8082",
- })
- uci:section("firewall", "rule", nil, {
- src="freifunk",
- proto="tcp",
- dest_port="8082",
- target="ACCEPT"
- })
-
- uci:save("firewall")
-
- -- Delete old splash
- uci:delete_all("luci_splash", "iface", {network=device.."dhcp", zone="freifunk"})
-
- -- Register splash
- uci:section("luci_splash", "iface", nil, {network=device.."dhcp", zone="freifunk"})
- uci:save("luci_splash")
-
- -- Make sure that luci_splash is enabled
- sys.exec("/etc/init.d/luci_splash enable")
-
- -- Remember state
- uci:set("freifunk", "wizard", "dhcp_splash", "1")
- uci:save("freifunk")
-end
-
-return f
diff --git a/applications/luci-ffwizard-leipzig/luasrc/tools/ffwizard.lua b/applications/luci-ffwizard-leipzig/luasrc/tools/ffwizard.lua
deleted file mode 100644
index 217cd44bb..000000000
--- a/applications/luci-ffwizard-leipzig/luasrc/tools/ffwizard.lua
+++ /dev/null
@@ -1,149 +0,0 @@
---[[
-LuCI - Lua Configuration Interface
-
-Copyright 2008 Steven Barth <steven@midlink.org>
-Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
-
-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$
-
-]]--
-
-local uci = require "luci.model.uci"
-local util = require "luci.util"
-local table = require "table"
-
-local type = type
-
-module "luci.tools.ffwizard"
-
--- Deletes all references of a wifi device
-function wifi_delete_ifaces(device)
- local cursor = uci.cursor()
- cursor:delete_all("wireless", "wifi-iface", {device=device})
- cursor:save("wireless")
-end
-
--- Deletes a network interface and all occurences of it in firewall zones and dhcp
-function network_remove_interface(iface)
- local cursor = uci.cursor()
-
- if not cursor:delete("network", iface) then
- return false
- end
-
- local aliases = {iface}
- cursor:foreach("network", "alias",
- function(section)
- if section.interface == iface then
- table.insert(aliases, section[".name"])
- end
- end)
-
- -- Delete Aliases and Routes
- cursor:delete_all("network", "route", {interface=iface})
- cursor:delete_all("network", "alias", {interface=iface})
-
- -- Delete DHCP sections
- cursor:delete_all("dhcp", "dhcp",
- function(section)
- return util.contains(aliases, section.interface)
- end)
-
- -- Remove OLSR sections
- cursor:delete_all("olsrd", "Interface", {Interface=iface})
-
- -- Remove Splash sections
- cursor:delete_all("luci-splash", "iface", {network=iface})
-
- cursor:save("network")
- cursor:save("olsr")
- cursor:save("dhcp")
- cursor:save("luci-splash")
-end
-
--- Creates a firewall zone
-function firewall_create_zone(zone, input, output, forward, masq)
- local cursor = uci.cursor()
- if not firewall_find_zone(zone) then
- local stat = cursor:section("firewall", "zone", nil, {
- input = input,
- output = output,
- forward = forward,
- masq = masq and "1",
- name = zone
- })
- cursor:save("firewall")
- return stat
- end
-end
-
--- Adds interface to zone, creates zone on-demand
-function firewall_zone_add_interface(name, interface)
- local cursor = uci.cursor()
- local zone = firewall_find_zone(name)
- local net = cursor:get("firewall", zone, "network")
- local old = net or (cursor:get("network", name) and name)
- cursor:set("firewall", zone, "network", (old and old .. " " or "") .. interface)
- cursor:save("firewall")
-end
-
--- Removes interface from zone
-function firewall_zone_remove_interface(name, interface)
- local cursor = uci.cursor()
- local zone = firewall_find_zone(name)
- if zone then
- local net = cursor:get("firewall", zone, "network")
- local new = remove_list_entry(net, interface)
- if new then
- if #new > 0 then
- cursor:set("firewall", zone, "network", new)
- else
- cursor:delete("firewall", zone, "network")
- end
- cursor:save("firewall")
- end
- end
-end
-
-
--- Finds the firewall zone with given name
-function firewall_find_zone(name)
- local find
-
- uci.cursor():foreach("firewall", "zone",
- function (section)
- if section.name == name then
- find = section[".name"]
- end
- end)
-
- return find
-end
-
-
-
--- Helpers --
-
--- Removes a listentry, handles real and pseduo lists transparently
-function remove_list_entry(value, entry)
- if type(value) == "nil" then
- return nil
- end
-
- local result = type(value) == "table" and value or util.split(value, " ")
- local key = util.contains(result, entry)
-
- while key do
- table.remove(result, key)
- key = util.contains(result, entry)
- end
-
- result = type(value) == "table" and result or table.concat(result, " ")
- return result ~= value and result
-end
diff --git a/applications/luci-ffwizard/luasrc/controller/ffwizard.lua b/applications/luci-ffwizard/luasrc/controller/ffwizard.lua
index 428962d4b..5ad48eeab 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 47118d19b..3047ec37a 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 000000000..2364ff2ad
--- /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 bbad46ea2..011148d59 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