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