add wpa widget
This commit is contained in:
parent
8e2c35474e
commit
e5630c1c1a
|
@ -83,6 +83,12 @@ vicious.contrib.rss
|
|||
vicious.contrib.sensors
|
||||
-
|
||||
|
||||
vicious.contrib.wpa
|
||||
- provides information about the wifi status
|
||||
- requires 'wpa_cli' from wpa_supplicant
|
||||
- takes the interface as an argument, i.e "wlan0" or "wlan1"
|
||||
- returns a table with string keys: {ssid}, {qual}, {ip}, {bssid}
|
||||
|
||||
|
||||
Usage examples
|
||||
--------------
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
---------------------------------------------------
|
||||
-- Licensed under the GNU General Public License v2
|
||||
-- * (c) 2012, jinleileiking. <jinleileiking@gmail.com>
|
||||
---------------------------------------------------
|
||||
|
||||
-- {{{ Grab environment
|
||||
local tonumber = tonumber
|
||||
local math = { ceil = math.ceil }
|
||||
local setmetatable = setmetatable
|
||||
local helpers = require("vicious.helpers")
|
||||
local io = {
|
||||
open = io.open,
|
||||
popen = io.popen
|
||||
}
|
||||
local string = {
|
||||
find = string.find,
|
||||
match = string.match
|
||||
}
|
||||
-- }}}
|
||||
|
||||
|
||||
-- Wifi: provides wireless information for a requested interface
|
||||
module("vicious.contrib.wpa")
|
||||
|
||||
local info = {
|
||||
["{ssid}"] = "N/A",
|
||||
["{bssid}"] = "N/A",
|
||||
["{ip}"] = "N/A",
|
||||
["{qual}"] = "N/A",
|
||||
}
|
||||
|
||||
-- {{{ Wireless widget type
|
||||
local function worker(format, warg)
|
||||
if not warg then return info end
|
||||
|
||||
local wpa_cmd = "wpa_cli -i'" .. warg .. "' status 2>&1"
|
||||
local f = io.popen(wpa_cmd)
|
||||
local output = f:read("*all")
|
||||
f:close()
|
||||
|
||||
if not output then return info end
|
||||
|
||||
state = string.match(output, 'wpa_state=([%a]+)') or 'N/A'
|
||||
info["{bssid}"] = string.match(output, 'bssid=([%d%a:]+)') or 'N/A'
|
||||
info["{ssid}"] = string.match(output, 'ssid=([%a]+)') or 'N/A'
|
||||
info["{ip}"] = string.match(output, 'ip_address=([%d.]+)') or 'N/A'
|
||||
|
||||
if not state == 'COMPLETED' then
|
||||
return info
|
||||
end
|
||||
|
||||
local wpa_cmd = "wpa_cli -i'" .. warg .. "' bss " .. bssid .. " 2>&1"
|
||||
local f = io.popen(wpa_cmd)
|
||||
local output = f:read("*all")
|
||||
f:close()
|
||||
|
||||
if not output then return info end
|
||||
|
||||
info["{qual}"] = string.match(output, 'qual=([%d]+)')
|
||||
|
||||
return info
|
||||
end
|
||||
-- }}}
|
||||
|
||||
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
|
||||
|
||||
|
Loading…
Reference in New Issue