diff options
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 |