From 86885e32ea98ae7fc18c207052e2108f7cdba833 Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Sat, 23 Aug 2008 10:14:19 +0000 Subject: 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 --- openssh-model.lua | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'openssh-model.lua') 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 -- cgit v1.2.3