libs/core: rework network model
This commit is contained in:
parent
6fa65fa9ec
commit
33378709a9
2 changed files with 422 additions and 1209 deletions
File diff suppressed because it is too large
Load diff
|
@ -1,162 +0,0 @@
|
|||
--[[
|
||||
LuCI - Network model - Wireless extension
|
||||
|
||||
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
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
]]--
|
||||
|
||||
local pairs, i18n, uci = pairs, luci.i18n, luci.model.uci
|
||||
|
||||
local iwi = require "iwinfo"
|
||||
local utl = require "luci.util"
|
||||
local uct = require "luci.model.uci.bind"
|
||||
|
||||
module "luci.model.network.wireless"
|
||||
|
||||
local ub = uct.bind("wireless")
|
||||
local st, ifs
|
||||
|
||||
function init(self, cursor)
|
||||
cursor:unload("wireless")
|
||||
cursor:load("wireless")
|
||||
ub:init(cursor)
|
||||
|
||||
st = uci.cursor_state()
|
||||
ifs = { }
|
||||
|
||||
local count = 0
|
||||
|
||||
ub.uci:foreach("wireless", "wifi-iface",
|
||||
function(s)
|
||||
count = count + 1
|
||||
|
||||
local device = s.device or "wlan0"
|
||||
local state = st:get_all("wireless", s['.name'])
|
||||
local name = device .. ".network" .. count
|
||||
|
||||
ifs[name] = {
|
||||
idx = count,
|
||||
name = name,
|
||||
rawname = state and state.ifname or name,
|
||||
flags = { },
|
||||
ipaddrs = { },
|
||||
ip6addrs = { },
|
||||
|
||||
type = "wifi",
|
||||
network = s.network,
|
||||
handler = self,
|
||||
wifi = state or s,
|
||||
sid = s['.name']
|
||||
}
|
||||
end)
|
||||
end
|
||||
|
||||
local function _mode(m)
|
||||
if m == "ap" then m = "AP"
|
||||
elseif m == "sta" then m = "Client"
|
||||
elseif m == "adhoc" then m = "Ad-Hoc"
|
||||
elseif m == "mesh" then m = "Mesh"
|
||||
elseif m == "monitor" then m = "Monitor"
|
||||
elseif m == "wds" then m = "WDS"
|
||||
end
|
||||
|
||||
return m or "Client"
|
||||
end
|
||||
|
||||
function shortname(self, iface)
|
||||
if iface.dev and iface.dev.wifi then
|
||||
return "%s %q" %{
|
||||
i18n.translate(_mode(iface.dev.wifi.mode)),
|
||||
iface.dev.wifi.ssid or iface.dev.wifi.bssid
|
||||
or i18n.translate("(hidden)")
|
||||
}
|
||||
else
|
||||
return iface:name()
|
||||
end
|
||||
end
|
||||
|
||||
function get_i18n(self, iface)
|
||||
if iface.dev and iface.dev.wifi then
|
||||
return "%s: %s %q" %{
|
||||
i18n.translate("Wireless Network"),
|
||||
i18n.translate(_mode(iface.dev.wifi.mode)),
|
||||
iface.dev.wifi.ssid or iface.dev.wifi.bssid
|
||||
or i18n.translate("(hidden)")
|
||||
}
|
||||
else
|
||||
return "%s: %q" %{ i18n.translate("Wireless Network"), iface:name() }
|
||||
end
|
||||
end
|
||||
|
||||
function rename_network(self, old, new)
|
||||
local i
|
||||
for i, _ in pairs(ifs) do
|
||||
if ifs[i].network == old then
|
||||
ifs[i].network = new
|
||||
end
|
||||
end
|
||||
|
||||
ub.uci:foreach("wireless", "wifi-iface",
|
||||
function(s)
|
||||
if s.network == old then
|
||||
if new then
|
||||
ub.uci:set("wireless", s['.name'], "network", new)
|
||||
else
|
||||
ub.uci:delete("wireless", s['.name'], "network")
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
function del_network(self, old)
|
||||
return self:rename_network(old, nil)
|
||||
end
|
||||
|
||||
function find_interfaces(self, iflist, brlist)
|
||||
local iface
|
||||
for iface, _ in pairs(ifs) do
|
||||
iflist[iface] = ifs[iface]
|
||||
end
|
||||
end
|
||||
|
||||
function ignore_interface(self, iface)
|
||||
if ifs and ifs[iface] then
|
||||
return false
|
||||
else
|
||||
return iwi.type(iface) and true or false
|
||||
end
|
||||
end
|
||||
|
||||
function add_interface(self, net, iface)
|
||||
if ifs and ifs[iface] and ifs[iface].sid then
|
||||
ub.uci:set("wireless", ifs[iface].sid, "network", net:name())
|
||||
ifs[iface].network = net:name()
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function del_interface(self, net, iface)
|
||||
if ifs and ifs[iface] and ifs[iface].sid then
|
||||
ub.uci:delete("wireless", ifs[iface].sid, "network")
|
||||
--return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
return _M
|
||||
|
Loading…
Reference in a new issue