modules/admin-full: convert controller to new network model
This commit is contained in:
parent
185eacba4b
commit
a3e66af2a3
1 changed files with 72 additions and 61 deletions
|
@ -11,6 +11,7 @@ You may obtain a copy of the License at
|
|||
|
||||
$Id$
|
||||
]]--
|
||||
|
||||
module("luci.controller.admin.network", package.seeall)
|
||||
|
||||
function index()
|
||||
|
@ -136,32 +137,28 @@ end
|
|||
|
||||
function wifi_add()
|
||||
local dev = luci.http.formvalue("device")
|
||||
local uci = require "luci.model.uci".cursor()
|
||||
local wlm = require "luci.model.wireless"
|
||||
local ntm = require "luci.model.network".init()
|
||||
|
||||
dev = dev and ntm:get_wifidev(dev)
|
||||
|
||||
if dev then
|
||||
wlm.init(uci)
|
||||
|
||||
local net = wlm:add_network({
|
||||
device = dev,
|
||||
local net = dev:add_wifinet({
|
||||
mode = "ap",
|
||||
ssid = "OpenWrt",
|
||||
encryption = "none"
|
||||
})
|
||||
|
||||
uci:save("wireless")
|
||||
luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless", dev, net:name()))
|
||||
ntm:save("wireless")
|
||||
luci.http.redirect(net:adminlink())
|
||||
end
|
||||
end
|
||||
|
||||
function wifi_delete(network)
|
||||
local uci = require "luci.model.uci".cursor()
|
||||
local wlm = require "luci.model.wireless"
|
||||
local ntm = require "luci.model.network".init()
|
||||
|
||||
wlm.init(uci)
|
||||
wlm:del_network(network)
|
||||
ntm:del_network(network)
|
||||
ntm:save("wireless")
|
||||
|
||||
uci:save("wireless")
|
||||
luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless"))
|
||||
end
|
||||
|
||||
|
@ -200,17 +197,19 @@ end
|
|||
|
||||
function iface_status()
|
||||
local path = luci.dispatcher.context.requestpath
|
||||
local iface = path[#path]
|
||||
local data = { }
|
||||
local info
|
||||
local x = luci.model.uci.cursor_state()
|
||||
local rv = { }
|
||||
|
||||
local iface
|
||||
for iface in path[#path]:gmatch("[%w%.%-]+") do
|
||||
local dev = x:get("network", iface, "device") or ""
|
||||
if #dev == 0 or dev:match("^%d") or dev:match("%W") then
|
||||
dev = x:get("network", iface, "ifname") or ""
|
||||
dev = dev:match("%S+")
|
||||
end
|
||||
|
||||
local info
|
||||
local data = { }
|
||||
for _, info in ipairs(nixio.getifaddrs()) do
|
||||
local name = info.name:match("[^:]+")
|
||||
if name == dev then
|
||||
|
@ -240,8 +239,13 @@ function iface_status()
|
|||
end
|
||||
|
||||
if next(data) then
|
||||
rv[#rv+1] = data
|
||||
end
|
||||
end
|
||||
|
||||
if #rv > 0 then
|
||||
luci.http.prepare_content("application/json")
|
||||
jsondump(data)
|
||||
jsondump(rv)
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -250,9 +254,11 @@ end
|
|||
|
||||
function wifi_status()
|
||||
local path = luci.dispatcher.context.requestpath
|
||||
local dev = path[#path]
|
||||
local iw = luci.sys.wifi.getiwinfo(dev)
|
||||
local rv = { }
|
||||
|
||||
local dev
|
||||
for dev in path[#path]:gmatch("[%w%.%-]+") do
|
||||
local iw = luci.sys.wifi.getiwinfo(dev)
|
||||
if iw then
|
||||
local f
|
||||
local j = { }
|
||||
|
@ -264,8 +270,13 @@ function wifi_status()
|
|||
j[f] = iw[f]
|
||||
end
|
||||
|
||||
rv[#rv+1] = j
|
||||
end
|
||||
end
|
||||
|
||||
if #rv > 0 then
|
||||
luci.http.prepare_content("application/json")
|
||||
jsondump(j)
|
||||
jsondump(rv)
|
||||
return
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue