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