3 local uci = require "luci.model.uci".cursor()
4 local sys = require "luci.sys"
5 local util = require "luci.util"
6 local ip = require "luci.ip"
8 local community = "profile_" .. (uci:get("freifunk", "community", "name") or "Freifunk")
9 mesh_network = ip.IPv4(uci:get_first(community, "community", "mesh_network") or "10.0.0.0/8")
11 m = Map("meshwizard", translate("Wizard"), translate("This wizard will assist you in setting up your router for Freifunk " ..
12 "or another similar wireless community network."))
13 --m:chain("meshwizard")
15 n = m:section(TypedSection, "netconfig", translate("Interfaces"))
20 function cbi_configure(device)
21 local configure = n:taboption(device, Flag, device .. "_config", translate("Configure this interface"))
24 function cbi_ip4addr(device)
25 local ip4addr = n:taboption(device, Value, device .. "_ip4addr", translate("Mesh IP address"),
26 translate("This is a unique address in the mesh (e.g. 10.1.1.1) and has to be registered at your local community."))
27 ip4addr:depends(device .. "_config", 1)
28 ip4addr.datatype = "ip4addr"
29 function ip4addr.validate(self, value)
30 local x = ip.IPv4(value)
31 if mesh_network:contains(x) then
34 return nil, translate("The given IP address is not inside the mesh network range ") ..
35 "(" .. mesh_network:string() .. ")."
40 function cbi_dhcp(device)
41 local dhcp = n:taboption(device, Flag, device .. "_dhcp", translate("Enable DHCP"),
42 translate("DHCP will automatically assign ip addresses to clients"))
43 dhcp:depends(device .. "_config", 1)
47 function cbi_dhcprange(device)
48 local dhcprange = n:taboption(device, Value, device .. "_dhcprange", translate("DHCP IP range"),
49 translate("The IP range from which clients are assigned ip addresses (e.g. 10.1.2.1/28). " ..
50 "If this is a range inside your mesh network range, then it will be announced as HNA. Any other range will use NAT. " ..
51 "If left empty then the defaults from the community profile will be used."))
52 dhcprange:depends(device .. "_dhcp", "1")
53 dhcprange.rmempty = true
54 dhcprange.datatype = "ip4addr"
56 -- create tabs and config for wireless
58 uci:foreach("wireless", "wifi-device", function(section)
59 local device = section[".name"]
60 table.insert(nets, device)
64 uci:foreach("network", "interface", function(section)
65 local device = section[".name"]
66 if not util.contains(nets, device) and device ~= "loopback" then
67 table.insert(nets, device)
68 table.insert(wired_nets, device)
72 for _, net in util.spairs(nets, function(a,b) return (nets[a] < nets[b]) end) do
76 -- create cbi config for wireless
77 uci:foreach("wireless", "wifi-device", function(section)
78 local device = section[".name"]
79 local hwtype = section.type
80 local syscc = section.country or uci:get(community, "wifi_device", "country") or
81 uci:get("freifunk", "wifi_device", "country")
87 if hwtype == "atheros" then
88 local cc = util.trim(sys.exec("grep -i '" .. syscc .. "' /lib/wifi/cc_translate.txt |cut -d ' ' -f 2")) or 0
89 sys.exec('"echo " .. cc .. " > /proc/sys/dev/" .. device .. "/countrycode"')
90 elseif hwtype == "mac80211" then
91 sys.exec("iw reg set " .. syscc)
92 elseif hwtype == "broadcom" then
93 sys.exec ("wlc country " .. syscc)
96 local chan = n:taboption(device, ListValue, device .. "_channel", translate("Channel"),
97 translate("Your device and neighbouring nodes have to use the same channel."))
98 chan:depends(device .. "_config", 1)
101 for _, f in ipairs(sys.wifi.channels(device)) do
102 if not f.restricted then
103 chan:value(f.channel)
113 cbi_dhcprange(device)
116 if hwtype == "atheros" then
117 local vap = n:taboption(device, Flag, device .. "_vap", translate("Virtual Access Point (VAP)"),
118 translate("This will setup a new virtual wireless interface in Access Point mode."))
119 vap:depends(device .. "_dhcp", "1")
124 for _, device in pairs(wired_nets) do
125 cbi_configure(device)
128 cbi_dhcprange(device)
131 g = m:section(TypedSection, "general", translate("General Settings"))
134 local cleanup = g:option(Flag, "cleanup", translate("Cleanup config"),
135 translate("If this is selected then config is cleaned before setting new config options."))
136 cleanup.default = "1"
138 local restrict = g:option(Flag, "local_restrict", translate("Protect LAN"),
139 translate("Check this to protect your LAN from other nodes or clients") .. " (" .. translate("recommended") .. ").")
141 local share = g:option(Flag, "sharenet", translate("Share your internet connection"),
142 translate("Select this to allow others to use your connection to access the internet."))
145 --function m.on_after_commit (self)
146 -- sys.call("/usr/bin/mesh-wizard/wizard.sh >/dev/null")