diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2011-03-13 13:54:43 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2011-03-13 13:54:43 +0000 |
commit | adc2ba97d13c175a257832143176ffdeb7839e8d (patch) | |
tree | 736b7a8b52ec8067fe97df7e53dd44405d1ac194 /modules | |
parent | 63bfe23eabacdaec291f4f832ee6658c6079d44b (diff) |
modules/admin-core: add tools.status helper class
Diffstat (limited to 'modules')
-rw-r--r-- | modules/admin-core/luasrc/tools/status.lua | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/modules/admin-core/luasrc/tools/status.lua b/modules/admin-core/luasrc/tools/status.lua new file mode 100644 index 0000000000..e3276800d4 --- /dev/null +++ b/modules/admin-core/luasrc/tools/status.lua @@ -0,0 +1,94 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2011 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$ +]]-- + +module("luci.tools.status", package.seeall) + +local uci = require "luci.model.uci".cursor() + +function dhcp_leases() + local rv = { } + local nfs = require "nixio.fs" + local leasefile = "/var/dhcp.leases" + + uci:foreach("dhcp", "dnsmasq", + function(s) + if s.leasefile and nfs.access(s.leasefile) then + leasefile = s.leasefile + return false + end + end) + + local fd = io.open(leasefile, "r") + if fd then + while true do + local ln = fd:read("*l") + if not ln then + break + else + local ts, mac, ip, name = ln:match("^(%d+) (%S+) (%S+) (%S+)") + if ts and mac and ip and name then + rv[#rv+1] = { + expires = os.difftime(tonumber(ts) or 0, os.time()), + macaddr = mac, + ipaddr = ip, + hostname = (name ~= "*") and name + } + end + end + end + fd:close() + end + + return rv +end + +function wifi_networks() + local rv = { } + local ntm = require "luci.model.network".init() + + local dev + for _, dev in ipairs(ntm:get_wifidevs()) do + local rd = { + up = dev:is_up(), + device = dev:name(), + name = dev:get_i18n(), + networks = { } + } + + local net + for _, net in ipairs(dev:get_wifinets()) do + rd.networks[#rd.networks+1] = { + name = net:shortname(), + link = net:adminlink(), + up = net:is_up(), + mode = net:active_mode(), + ssid = net:active_ssid(), + bssid = net:active_bssid(), + encryption = net:active_encryption(), + frequency = net:frequency(), + channel = net:channel(), + signal = net:signal(), + quality = net:signal_percent(), + noise = net:noise(), + bitrate = net:bitrate(), + ifname = net:ifname(), + assoclist = net:assoclist() + } + end + + rv[#rv+1] = rd + end + + return rv +end |