NIU:
authorSteven Barth <steven@midlink.org>
Sun, 22 Nov 2009 20:33:16 +0000 (20:33 +0000)
committerSteven Barth <steven@midlink.org>
Sun, 22 Nov 2009 20:33:16 +0000 (20:33 +0000)
Implemented WiFi-WAN
Overall improvements

14 files changed:
libs/cbi/luasrc/view/cbi/value.htm
modules/niu/luasrc/model/cbi/niu/network/assign1.lua
modules/niu/luasrc/model/cbi/niu/network/etherwan.lua
modules/niu/luasrc/model/cbi/niu/network/lan.lua
modules/niu/luasrc/model/cbi/niu/network/wan.lua
modules/niu/luasrc/model/cbi/niu/network/wandevice.lua
modules/niu/luasrc/model/cbi/niu/network/wlanwan.lua [new file with mode: 0644]
modules/niu/luasrc/model/cbi/niu/network/wlanwanscan.lua [new file with mode: 0644]
modules/niu/luasrc/model/cbi/niu/traffic/routes1.lua
modules/niu/luasrc/model/cbi/niu/wireless/ap.lua
modules/niu/luasrc/model/cbi/niu/wireless/ap1.lua
modules/niu/luasrc/model/cbi/niu/wireless/apdevice.lua
modules/niu/luasrc/niulib.lua [new file with mode: 0644]
modules/niu/luasrc/view/niu/network/wlanwanscan.htm [new file with mode: 0644]

index 11c89cf..8bdebd9 100644 (file)
@@ -27,7 +27,7 @@ $Id$
                        end
                -%>
                }, '<%- if not self.rmempty and not self.optional then -%>
-                       <%-:cbi_select-%>
+                       <%-: -- Please choose -- -%>
                <%- end -%>', '
                <%- if self.combobox_manual then -%>
                        <%-=self.combobox_manual-%>
index fdd0dc0..0fee331 100644 (file)
@@ -46,7 +46,7 @@ local function date_format(secs)
        end
 end
 
-m2 = Map("dhcp", "Display and Customize Address Assignment")
+m2 = Map("dhcp", "Manage Address Assignment")
 
 local leasefn, leasefp, leases
 uci:foreach("dhcp", "dnsmasq",
index c5fda15..f57b7f3 100644 (file)
@@ -14,9 +14,8 @@ $Id$
 ]]--
 
 local fs = require "nixio.fs"
-local nw = require "luci.model.network"
 
-local has_ipv6 = nw:has_ipv6()
+local has_ipv6  = fs.access("/proc/net/ipv6_route")
 local has_pptp  = fs.access("/usr/sbin/pptp")
 local has_pppd  = fs.access("/usr/sbin/pppd")
 local has_pppoe = fs.glob("/usr/lib/pppd/*/rp-pppoe.so")()
@@ -24,7 +23,6 @@ local has_pppoa = fs.glob("/usr/lib/pppd/*/pppoatm.so")()
 
 
 m = Map("network", "Configure Ethernet Adapter for Internet Connection")
-nw.init(m.uci)
 
 s = m:section(NamedSection, "wan", "interface")
 s.addremove = false
index 45f2381..feb213c 100644 (file)
@@ -5,8 +5,7 @@ d.allow_finish = true
 d.allow_back = true
 d.allow_cancel = true
 
-d:add("lan1", load("niu/network/lan1"))
-d:set("warnip", {Template("niu/network/warn_ip_change")})
+d:add("lan1", "niu/network/lan1")
 
 function d.on_cancel()
        cursor:revert("network")
index b7351ff..1724c4a 100644 (file)
@@ -5,6 +5,12 @@ if not cursor:get("network", "wan") then
        cursor:save("network")
 end
 
+if not cursor:get("wireless", "client") then
+       cursor:section("wireless", "wifi-iface", "client",
+               {device = "_", doth = "1", _niu = "1", mode = "sta"})
+       cursor:save("wireless")
+end
+
 local function deviceroute(self)
        cursor:unload("network")
        local wd = cursor:get("network", "wan", "_wandev") or ""
@@ -22,11 +28,18 @@ local function deviceroute(self)
        end
        
        if wd:find("wlan:") == 1 then
-       
+               local widev = wd:sub(6)
+               if cursor:get("wireless", "client", "device") ~= widev then
+                       cursor:delete("wireless", "client", "network")
+                       cursor:set("wireless", "client", "device", widev)
+               end
+               self:set_route("wlanwan1", "wlanwan2")
        else
-               cursor:delete_all("wireless", "wifi-iface", {network = "wan"}) 
+               cursor:delete("wireless", "client", "device")
+               cursor:delete("wireless", "client", "network")
        end
        
+       
        cursor:save("wireless")
        cursor:save("network")
 end
@@ -37,9 +50,11 @@ d.allow_finish = true
 d.allow_back = true
 d.allow_cancel = true
 
-d:add("device", load("niu/network/wandevice"))
+d:add("device", "niu/network/wandevice")
 d:add("deviceroute", deviceroute)
-d:set("etherwan", load("niu/network/etherwan"))
+d:set("etherwan", "niu/network/etherwan")
+d:set("wlanwan1", "niu/network/wlanwanscan")
+d:set("wlanwan2", "niu/network/wlanwan")
 
 function d.on_cancel()
        cursor:revert("network")
index db7d902..9287ba8 100644 (file)
@@ -12,9 +12,7 @@ You may obtain a copy of the License at
 $Id$
 ]]--
 
-local cursor = require "luci.model.uci".inst_state
-local nw = require "luci.model.network"
-nw.init(cursor)
+local niulib = require "luci.niulib"
 
 m = Map("network", "Configure Internet Connection")
 s = m:section(NamedSection, "wan", "interface", "Internet Connection Device")
@@ -23,16 +21,15 @@ s.addremove = false
 
 l = s:option(ListValue, "_wandev", "Internet Connection via")
 
-for _, iface in ipairs(nw.get_interfaces()) do
-       if iface:name():find("eth") == 1 then
-               local net = iface:get_network()
-               if not net or net:name() == "wan" or os.getenv("LUCI_SYSROOT") then
-                       l:value("ethernet:%s" % iface:name(),
-                               "Cable / DSL / Ethernet Adapter (%s)" % iface:name())
-               end
-       end
+for _, ifc in ipairs(niulib.eth_get_available("wan")) do
+       l:value("ethernet:%s" % ifc, "Cable / DSL / Ethernet-Adapter (%s)" % ifc)
 end
 
+for _, wifi in ipairs(niulib.wifi_get_available("client")) do
+       l:value("wlan:%s" % wifi, "WLAN-Adapter (%s)" % wifi)
+end
+
+
 l:value("none", "No Internet Connection")
 
 return m
diff --git a/modules/niu/luasrc/model/cbi/niu/network/wlanwan.lua b/modules/niu/luasrc/model/cbi/niu/network/wlanwan.lua
new file mode 100644 (file)
index 0000000..dc8bfbd
--- /dev/null
@@ -0,0 +1,254 @@
+--[[
+LuCI - Lua Configuration Interface
+
+Copyright 2009 Steven Barth <steven@midlink.org>
+Copyright 2009 Jo-Philipp Wich <xm@subsignal.org>
+
+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 fs = require "nixio.fs"
+local uci = require "luci.model.uci"
+local nixio = require "nixio"
+local iwinfo = require "iwinfo"
+
+local cursor = uci.inst
+local state = uci.inst_state
+cursor:unload("wireless")
+state:unload("wireless")
+
+local has_ipv6 = fs.access("/proc/net/ipv6_route")
+local device = cursor:get("wireless", "client", "device")
+local hwtype = cursor:get("wireless", device, "type")
+
+
+-- Bring up interface and scan --
+
+if not state:get("wireless", "client", "network") then
+       local olduci = uci.cursor(nil, "")
+       local oldcl = olduci:get_all("wireless", "client")
+       olduci:unload("wireless")
+       
+       local newuci = uci.cursor()
+       local newcl = newuci:get_all("wireless", "client")
+       newcl.network = "wan"
+       
+       local proc = nixio.fork()
+       if proc == 0 then
+               newuci:delete("wireless", "client", "ssid")
+               newuci:commit("wireless")
+               nixio.exec("/sbin/wifi", "up", device)
+               os.exit(1) 
+       end
+       nixio.wait(proc)
+       
+       newuci:delete("wireless", "client")
+       newuci:section("wireless", "wifi-iface", "client", oldcl)
+       newuci:commit("wireless")
+       newuci:tset("wireless", "client", newcl)
+       newuci:save("wireless")
+       newuci:unload("wireless")
+
+       state:unload("wireless")
+end
+local ifname = state:get("wireless", "client", "ifname") or "wlan0dummy"
+local iwlib = iwinfo.type(ifname) and iwinfo[iwinfo.type(ifname)]
+local suggest = {}
+local encrdep = {
+       none = {{["!default"] = 1}},
+       wep = {{["!default"] = 1}},
+       psk = {{["!default"] = 1}},
+       psk2 = {{["!default"] = 1}},
+       wpa = {{["!default"] = 1}},
+       wpa2 = {{["!default"] = 1}}
+}
+
+if iwlib then
+       suggest = iwlib.scanlist(ifname)
+end
+
+
+
+-- Form definition --
+
+m2 = Map("wireless", "Configure WLAN-Adapter for Internet Connection")
+
+s = m2:section(NamedSection, "client", "wifi-iface", "Wireless Settings")
+s.addremove = false
+
+s:tab("general", translate("General Settings"))
+s:tab("expert", translate("Expert Settings"))
+
+local ssid = s:taboption("general", Value, "ssid", translate("Network Name (<abbr title=\"Extended Service Set Identifier\">ESSID</abbr>)"))
+ssid.rmempty = false
+
+for _, v in ipairs(suggest) do
+       if v.mode == "Master" then
+               ssid:value(v.ssid)
+               
+               if not v.wep then
+                       encrdep.wep[#encrdep.wep+1] = {ssid = v.ssid, ["!reverse"] = 1}
+               end
+               if v.wpa ~= 1 or (v.wpa == 1 and v.auth_suites[1] ~= "802.1x") then
+                       encrdep.wpa[#encrdep.wpa+1] = {ssid = v.ssid, ["!reverse"] = 1}
+               end
+               if v.wpa ~= 1 or (v.wpa == 1 and v.auth_suites[1] ~= "PSK") then                
+                       encrdep.psk[#encrdep.psk+1] = {ssid = v.ssid, ["!reverse"] = 1}
+               end
+               if not v.wpa or v.wpa < 2 or (v.wpa >= 2 and v.auth_suites[1] ~= "802.1x") then
+                       encrdep.wpa2[#encrdep.wpa2+1] = {ssid = v.ssid, ["!reverse"] = 1}
+               end
+               if not v.wpa or v.wpa < 2 or (v.wpa >= 2 and v.auth_suites[1] ~= "PSK") then
+                       encrdep.psk2[#encrdep.psk2+1] = {ssid = v.ssid, ["!reverse"] = 1}
+               end
+               if v.wpa or v.wep then
+                       encrdep.none[#encrdep.none+1] = {ssid = v.ssid, ["!reverse"] = 1} 
+               end
+       end
+end
+
+encr = s:taboption("general", ListValue, "encryption", translate("Encryption"))
+
+
+if hwtype == "mac80211" then
+       s:taboption("expert", Flag, "powersave", "Enable Powersaving")
+elseif hwtype == "atheros" then
+       s:taboption("expert", Flag, "bursting", translate("Allow Burst Transmissions"))
+end
+
+
+
+-- Encryption --
+
+encr.override_values = true
+encr.override_depends = true
+encr:value("none", "No Encryption", unpack(encrdep.none))
+encr:value("wep", "WEP", unpack(encrdep.wep))
+
+if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
+       local supplicant = fs.access("/usr/sbin/wpa_supplicant") or os.getenv("LUCI_SYSROOT")
+       if supplicant then              
+               encr:value("psk", "WPA", unpack(encrdep.psk))
+               encr:value("wpa", "WPA-EAP", unpack(encrdep.wpa))
+               encr:value("psk2", "WPA2", unpack(encrdep.psk2))
+               encr:value("wpa2", "WPA2-EAP (802.11i)", unpack(encrdep.wpa2))
+       end
+elseif hwtype == "broadcom" then
+       encr:value("psk", "WPA", unpack(encrdep.psk))
+       encr:value("psk2", "WPA2", unpack(encrdep.psk2))
+end
+
+key = s:taboption("general", Value, "key", translate("Password"))
+key:depends("encryption", "wep")
+key:depends("encryption", "psk")
+key:depends("encryption", "psk2")
+key.rmempty = true
+key.password = true
+
+if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
+       eaptype = s:taboption("general", ListValue, "eap_type", translate("EAP-Method"))
+       eaptype:value("TLS")
+       eaptype:value("TTLS")
+       eaptype:value("PEAP")
+       eaptype:depends({encryption="wpa"})
+       eaptype:depends({encryption="wpa2"})
+
+       cacert = s:taboption("general", FileUpload, "ca_cert", translate("Path to CA-Certificate"))
+       cacert:depends({encryption="wpa"})
+       cacert:depends({encryption="wpa2"})
+
+       privkey = s:taboption("general", FileUpload, "priv_key", translate("Path to Private Key"))
+       privkey:depends({eap_type="TLS", encryption="wpa2"})
+       privkey:depends({eap_type="TLS", encryption="wpa"})
+
+       privkeypwd = s:taboption("general", Value, "priv_key_pwd", translate("Password of Private Key"))
+       privkeypwd:depends({eap_type="TLS", encryption="wpa2"})
+       privkeypwd:depends({eap_type="TLS", encryption="wpa"})
+
+
+       auth = s:taboption("general", Value, "auth", translate("Authentication"))
+       auth:value("PAP")
+       auth:value("CHAP")
+       auth:value("MSCHAP")
+       auth:value("MSCHAPV2")
+       auth:depends({eap_type="PEAP", encryption="wpa2"})
+       auth:depends({eap_type="PEAP", encryption="wpa"})
+       auth:depends({eap_type="TTLS", encryption="wpa2"})
+       auth:depends({eap_type="TTLS", encryption="wpa"})
+
+
+       identity = s:taboption("general", Value, "identity", translate("Identity"))
+       identity:depends({eap_type="PEAP", encryption="wpa2"})
+       identity:depends({eap_type="PEAP", encryption="wpa"})
+       identity:depends({eap_type="TTLS", encryption="wpa2"})
+       identity:depends({eap_type="TTLS", encryption="wpa"})
+
+       password = s:taboption("general", Value, "password", translate("Password"))
+       password:depends({eap_type="PEAP", encryption="wpa2"})
+       password:depends({eap_type="PEAP", encryption="wpa"})
+       password:depends({eap_type="TTLS", encryption="wpa2"})
+       password:depends({eap_type="TTLS", encryption="wpa"})
+end
+
+
+
+
+
+m = Map("network")
+
+s = m:section(NamedSection, "wan", "interface", translate("Address Settings"))
+s.addremove = false
+
+s:tab("general", translate("General Settings"))
+s:tab("expert", translate("Expert Settings"))
+
+p = s:taboption("general", ListValue, "proto", "Connection Type")
+p.override_scheme = true
+p.default = "dhcp"
+p:value("dhcp", "Automatic Configuration (DHCP)")
+p:value("static", "Static Configuration")
+
+
+
+ipaddr = s:taboption("general", Value, "ipaddr", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Address"))
+ipaddr.rmempty = true
+ipaddr:depends("proto", "static")
+
+nm = s:taboption("general", Value, "netmask", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Netmask"))
+nm.rmempty = true
+nm:depends("proto", "static")
+nm:value("255.255.255.0")
+nm:value("255.255.0.0")
+nm:value("255.0.0.0")
+
+gw = s:taboption("general", Value, "gateway", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Gateway"))
+gw:depends("proto", "static")
+gw.rmempty = true
+
+bcast = s:taboption("expert", Value, "bcast", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Broadcast"))
+bcast:depends("proto", "static")
+
+if has_ipv6 then
+       ip6addr = s:taboption("expert", Value, "ip6addr", translate("<abbr title=\"Internet Protocol Version 6\">IPv6</abbr>-Address"), translate("<abbr title=\"Classless Inter-Domain Routing\">CIDR</abbr>-Notation: address/prefix"))
+       ip6addr:depends("proto", "static")
+
+       ip6gw = s:taboption("expert", Value, "ip6gw", translate("<abbr title=\"Internet Protocol Version 6\">IPv6</abbr>-Gateway"))
+       ip6gw:depends("proto", "static")
+end
+
+dns = s:taboption("expert", Value, "dns", translate("<abbr title=\"Domain Name System\">DNS</abbr>-Server"))
+dns:depends("peerdns", "")
+
+mtu = s:taboption("expert", Value, "mtu", "MTU")
+mtu.isinteger = true
+
+mac = s:taboption("expert", Value, "macaddr", translate("<abbr title=\"Media Access Control\">MAC</abbr>-Address"))
+
+return m2, m
diff --git a/modules/niu/luasrc/model/cbi/niu/network/wlanwanscan.lua b/modules/niu/luasrc/model/cbi/niu/network/wlanwanscan.lua
new file mode 100644 (file)
index 0000000..4035ff4
--- /dev/null
@@ -0,0 +1,12 @@
+local t = Template("niu/network/wlanwanscan")
+function t.parse(self, ...)
+       local state = Template.parse(self, ...)
+       if Map.formvalue({readinput = true}, "cbi.delg.back") then
+               return FORM_SKIP
+       end 
+       if state == FORM_NODATA then
+               self.delegator.disallow_pageactions = true
+       end
+       return state
+end
+return t
\ No newline at end of file
index 094831e..f09cf07 100644 (file)
@@ -12,7 +12,7 @@ You may obtain a copy of the License at
 $Id$
 ]]--
 
-m = Map("network", translate("Display and Customize Routing"),
+m = Map("network", translate("Manage Traffic Routing"),
 translate("With additional static routes you allow computers on your network to reach unannounced remote hosts or networks."))
 
 local routes6 = luci.sys.net.routes6()
index 54f510d..08cc565 100644 (file)
@@ -2,7 +2,7 @@ local cursor = require "luci.model.uci".cursor()
 
 if not cursor:get("wireless", "ap") then
        cursor:section("wireless", "wifi-iface", "ap",
-               {device = "_", doth = "1", wmm = "1", _niu = "1", mode = "ap"})
+               {device = "_", doth = "1", _niu = "1", mode = "ap"})
        cursor:save("wireless")
 end
 
@@ -15,7 +15,6 @@ local function deviceroute(self)
                end)
                cursor:set("wireless", d, "disabled", 0)
                cursor:set("wireless", "ap", "network", "lan")
-               self:set("ap1", load("niu/wireless/ap1"))
                self:set_route("ap1")
        else
                cursor:delete("wireless", "ap", "network")
@@ -29,8 +28,9 @@ d.allow_finish = true
 d.allow_back = true
 d.allow_cancel = true
 
-d:add("device", load("niu/wireless/apdevice"))
+d:add("device", "niu/wireless/apdevice")
 d:add("deviceroute", deviceroute)
+d:set("ap1", "niu/wireless/ap1")
 
 function d.on_cancel()
        cursor:revert("wireless")
index df36eef..8df31e8 100644 (file)
@@ -234,7 +234,7 @@ encr.default = "wep" -- Early default
 encr.override_values = true
 encr.override_depends = true
 encr:value("none", "No Encryption")
-encr:value("wep", "WEP", {mode="ap"}, {mode="sta"})
+encr:value("wep", "WEP", {mode="ap"})
 
 if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
        local hostapd = fs.access("/usr/sbin/hostapd") or os.getenv("LUCI_SYSROOT")
index 930371e..b9e0fa5 100644 (file)
@@ -11,10 +11,7 @@ You may obtain a copy of the License at
 
 $Id$
 ]]--
-
-local iwinfo = require "iwinfo"
-local cursor = require "luci.model.uci".inst
-cursor:unload("wireless")
+local niulib = require "luci.niulib"
 
 m = Map("wireless", "Configure Private Access Point")
 s = m:section(NamedSection, "ap", "interface", "Wireless Radio Device",
@@ -27,25 +24,9 @@ s.addremove = false
 
 l = s:option(ListValue, "device", "Device providing Access Point")
 
-local used = {}
-cursor:foreach("wireless", "wifi-iface", function(s)
-       if s[".name"] ~= "ap" and s._niu == 1 then
-               used[s.device] = 1
-       end
-end)
-
-for k in pairs(used) do
-       local t = iwinfo.type(k)
-       if t and iwinfo[t] then
-               used[k] = (iwinfo[t].mbssid_support() < 1)
-       end
+for _, wifi in ipairs(niulib.wifi_get_available("ap")) do
+       l:value(wifi, "WLAN-Adapter (%s)" % wifi)
 end
-
-cursor:foreach("wireless", "wifi-device", function(s)
-       if not used[s[".name"]] then
-               l:value(s[".name"], "Radio %s" % s[".name"])
-       end
-end)
 l:value("none", "Disable Private Access Point")
 
 return m
diff --git a/modules/niu/luasrc/niulib.lua b/modules/niu/luasrc/niulib.lua
new file mode 100644 (file)
index 0000000..2a46355
--- /dev/null
@@ -0,0 +1,65 @@
+--[[
+LuCI - Lua Configuration Interface
+
+Copyright 2009 Steven Barth <steven@midlink.org>
+
+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 ipairs, pairs, require = ipairs, pairs, require
+local os = require "os"
+
+local cursor = require "luci.model.uci".inst
+
+
+module "luci.niulib"
+
+function eth_get_available(except)
+       local nw = require "luci.model.network"
+       nw.init(cursor)
+
+       local ifs = {}
+       for _, iface in ipairs(nw.get_interfaces()) do
+               if iface:name():find("eth") == 1 then
+                       local net = iface:get_network()
+                       if not net or net:name() == except or os.getenv("LUCI_SYSROOT") then
+                               ifs[#ifs+1] = iface:name()
+                       end
+               end
+       end
+       return ifs
+end
+
+function wifi_get_available(except)
+       cursor:unload("wireless")
+
+       local iwinfo = require "iwinfo"
+       local used = {}
+       cursor:foreach("wireless", "wifi-iface", function(s)
+               if s[".name"] ~= except and s._niu == 1 then
+                       used[s.device] = 1
+               end
+       end)
+
+       for k in pairs(used) do
+               local t = iwinfo.type(k)
+               if t and iwinfo[t] then
+                       used[k] = (iwinfo[t].mbssid_support() < 1)
+               end
+       end
+
+       local wifis = {}
+       cursor:foreach("wireless", "wifi-device", function(s)
+               if not used[s[".name"]] then
+                       wifis[#wifis+1] = s[".name"]
+               end
+       end)
+       return wifis
+end
+
diff --git a/modules/niu/luasrc/view/niu/network/wlanwanscan.htm b/modules/niu/luasrc/view/niu/network/wlanwanscan.htm
new file mode 100644 (file)
index 0000000..f02b32f
--- /dev/null
@@ -0,0 +1,7 @@
+<div style="margin: auto">
+<h2>Scanning for wireless networks in range</h2>
+<div>This may take a few seconds. Please wait...</div>
+</div>
+<script type="text/javascript">
+setTimeout(function() { document.forms.cbi.submit(); }, 100);
+</script>
\ No newline at end of file