blob: dc3df5ed43de47e8d42f8dcdfff22e95e2bf255d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
--[[
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 uci = require "luci.model.uci"
local cursor = uci.inst
local state = uci.inst_state
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 eth_get_bridged(except)
local devs = state:get("network", except, "device")
local ifs = {}
local cnt = 0
for x in devs:gmatch("[^ ]+") do
cnt = cnt + 1
if x:find("eth") == 1 then
ifs[#ifs+1] = x
end
end
return cnt > 1 and ifs or {}
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(k) < 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
|