diff options
author | Mika Havela <mika.havela@gmail.com> | 2008-08-23 10:14:19 +0000 |
---|---|---|
committer | Mika Havela <mika.havela@gmail.com> | 2008-08-23 10:14:19 +0000 |
commit | 86885e32ea98ae7fc18c207052e2108f7cdba833 (patch) | |
tree | 6faa1fceac08bcb39db750db078921b17cc64dbf /openssh-model.lua | |
parent | 78e8b8fa00908ea30a002331bad4cb59d6eb7016 (diff) | |
download | acf-openssh-86885e32ea98ae7fc18c207052e2108f7cdba833.tar.bz2 acf-openssh-86885e32ea98ae7fc18c207052e2108f7cdba833.tar.xz |
Added status information about which peers are currently connected to sshd
git-svn-id: svn://svn.alpinelinux.org/acf/openssh/trunk@1403 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'openssh-model.lua')
-rw-r--r-- | openssh-model.lua | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/openssh-model.lua b/openssh-model.lua index 0ebce53..2f657f9 100644 --- a/openssh-model.lua +++ b/openssh-model.lua @@ -12,6 +12,7 @@ local configfile = "/etc/ssh/sshd_config" local processname = "sshd" local packagename = "openssh-server" local header = "SSH" +local path="PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin " local default = { Port = 22, @@ -97,7 +98,8 @@ function read_config() end -function startstop_service(action) +function startstop_service(action)require("getopts") + return modelfunctions.startstop_service(processname, action) end @@ -159,3 +161,46 @@ function write_config(config) return true end +function list_conn_peers() + local output = {} + local netstat = {} + local ps = {} + local who = {} + config = read_config() + local f = io.popen( path .. 'netstat -lna | grep ' .. tostring(config.Port) .. ' | grep "ESTABLISHED"' ) + for line in f:lines() do + local peer = string.match(line, "^.-:.-:.-:.-:.-:.-:.-:(.-):.-$") + if not (netstat[peer]) then netstat[peer] = {cnt=0} end + netstat[peer]['cnt'] = (tonumber(netstat[peer]['cnt']) + 1) + end + f:close() + + local f = io.popen( path .. 'ps | grep "sshd:" | grep -v "grep"' ) + for line in f:lines() do + table.insert(ps, string.match(line,".-%@(%S*)$")) + end + f:close() + + for peer,v in pairs(netstat) do + if not (netstat[peer]['tty']) then netstat[peer]['tty'] = {} end + local f = io.popen( path .. 'who | grep "' .. tostring(peer) .. '" | egrep "' .. table.concat(ps, "|") .. '"' ) + for line in f:lines() do + local user,tty,idle,time = string.match(line, "^(%S*)%s*(%S*)%s*(%S*)%s*(%S*%s*%S*%s*%S*)") + + table.insert(netstat[peer]['tty'], { + user=user, + tty=tty, + idle=idle, + time=time, + }) + end + f:close() + end + + for k,v in pairs(netstat) do + table.insert(output, v) + output[#output]['host'] = k + end + + return output +end |