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 local mesh_network = ip.IPv4(uci:get_first(community, "community", "mesh_network") or "10.0.0.0/8")
10 local community_ipv6 = uci:get_first(community, "community", "ipv6") or 0
11 local community_ipv6mode = uci:get_first(community, "community", "ipv6_config") or "static"
12 local meshkit_ipv6 = uci:get("meshwizard", "ipv6", "enabled") or 0
14 m = Map("meshwizard", translate("Wizard"), translate("This wizard will assist you in setting up your router for Freifunk " ..
15 "or another similar wireless community network."))
17 n = m:section(NamedSection, "netconfig", nil, translate("Interfaces"))
22 function cbi_configure(device)
23 local configure = n:taboption(device, Flag, device .. "_config", translate("Configure this interface"),
24 translate("Note: this will setup this interface for mesh operation, i.e. add to zone 'freifunk' and enable olsr."))
27 function cbi_ip4addr(device)
28 local ip4addr = n:taboption(device, Value, device .. "_ip4addr", translate("Mesh IP address"),
29 translate("This is a unique address in the mesh (e.g. 10.1.1.1) and has to be registered at your local community."))
30 ip4addr:depends(device .. "_config", 1)
31 ip4addr.datatype = "ip4addr"
32 function ip4addr.validate(self, value)
33 local x = ip.IPv4(value)
34 if mesh_network:contains(x) then
37 return nil, translate("The given IP address is not inside the mesh network range ") ..
38 "(" .. mesh_network:string() .. ")."
43 function cbi_ip6addr(device)
44 local ip6addr = n:taboption(device, Value, device .. "_ip6addr", translate("Mesh IPv6 address"),
45 translate("This is a unique IPv6 address in CIDR notation (e.g. 2001:1:2:3::1/64) and has to be registered at your local community."))
46 ip6addr:depends(device .. "_config", 1)
47 ip6addr.datatype = "ip6addr"
51 function cbi_dhcp(device)
52 local dhcp = n:taboption(device, Flag, device .. "_dhcp", translate("Enable DHCP"),
53 translate("DHCP will automatically assign ip addresses to clients"))
54 dhcp:depends(device .. "_config", 1)
58 function cbi_ra(device)
59 local ra = n:taboption(device, Flag, device .. "_ipv6ra", translate("Enable RA"),
60 translate("Send router advertisements on this device."))
61 ra:depends(device .. "_config", 1)
65 function cbi_dhcprange(device)
66 local dhcprange = n:taboption(device, Value, device .. "_dhcprange", translate("DHCP IP range"),
67 translate("The IP range from which clients are assigned ip addresses (e.g. 10.1.2.1/28). " ..
68 "If this is a range inside your mesh network range, then it will be announced as HNA. Any other range will use NAT. " ..
69 "If left empty then the defaults from the community profile will be used."))
70 dhcprange:depends(device .. "_dhcp", "1")
71 dhcprange.rmempty = true
72 dhcprange.datatype = "ip4addr"
74 -- create tabs and config for wireless
76 uci:foreach("wireless", "wifi-device", function(section)
77 local device = section[".name"]
78 table.insert(nets, device)
82 uci:foreach("network", "interface", function(section)
83 local device = section[".name"]
84 if not util.contains(nets, device) and device ~= "loopback" and not device:find("wireless") then
85 table.insert(nets, device)
86 table.insert(wired_nets, device)
90 for _, net in util.spairs(nets, function(a,b) return (nets[a] < nets[b]) end) do
94 -- create cbi config for wireless
95 uci:foreach("wireless", "wifi-device", function(section)
96 local device = section[".name"]
97 local hwtype = section.type
98 local syscc = section.country or uci:get(community, "wifi_device", "country") or
99 uci:get("freifunk", "wifi_device", "country")
101 cbi_configure(device)
105 if hwtype == "atheros" then
106 local cc = util.trim(sys.exec("grep -i '" .. syscc .. "' /lib/wifi/cc_translate.txt |cut -d ' ' -f 2")) or 0
107 sys.exec('"echo " .. cc .. " > /proc/sys/dev/" .. device .. "/countrycode"')
108 elseif hwtype == "mac80211" then
109 sys.exec("iw reg set " .. syscc)
110 elseif hwtype == "broadcom" then
111 sys.exec ("wlc country " .. syscc)
114 local chan = n:taboption(device, ListValue, device .. "_channel", translate("Channel"),
115 translate("Your device and neighbouring nodes have to use the same channel."))
116 chan:depends(device .. "_config", 1)
117 chan:value('default')
119 local iwinfo = sys.wifi.getiwinfo(device)
121 for _, f in ipairs(iwinfo.freqlist) do
122 if not f.restricted then
123 chan:value(f.channel)
134 cbi_dhcprange(device)
137 if community_ipv6 == "1" then
138 if community_ipv6mode == "static" then
145 local supports_vap = 0
146 if sys.call("/usr/bin/meshwizard/helpers/supports_vap.sh " .. device .. " " .. hwtype) == 0 then
149 if supports_vap == 1 then
150 local vap = n:taboption(device, Flag, device .. "_vap", translate("Virtual Access Point (VAP)"),
151 translate("This will setup a new virtual wireless interface in Access Point mode."))
152 vap:depends(device .. "_dhcp", "1")
157 for _, device in pairs(wired_nets) do
158 cbi_configure(device)
161 cbi_dhcprange(device)
163 if community_ipv6 == "1" then
164 if community_ipv6mode == "static" then
172 g = m:section(TypedSection, "general", translate("General Settings"))
175 local cleanup = g:option(Flag, "cleanup", translate("Cleanup config"),
176 translate("If this is selected then config is cleaned before setting new config options."))
177 cleanup.default = "1"
179 local restrict = g:option(Flag, "local_restrict", translate("Protect LAN"),
180 translate("Check this to protect your LAN from other nodes or clients") .. " (" .. translate("recommended") .. ").")
182 local share = g:option(Flag, "sharenet", translate("Share your internet connection"),
183 translate("Select this to allow others to use your connection to access the internet."))
187 if community_ipv6 == "1" then
188 v6 = m:section(NamedSection, "ipv6", nil, translate("IPv6 Settings"))
189 local enabled = v6:option(Flag, "enabled", translate("Enabled"),
190 translate("Activate or deactivate IPv6 config globally."))
191 enabled.default = meshkit_ipv6
192 enabled.rmempty = false