From b8c478b7b6d9f10dad720d219f712d880386a34f Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Sat, 24 Jan 2009 16:52:21 +0000 Subject: Started process of removing as many io.popen calls as possible. Not complete. git-svn-id: svn://svn.alpinelinux.org/acf/openssh/trunk@1695 ab2d0c66-481e-0410-8bed-d214d4d58bed --- openssh-model.lua | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) (limited to 'openssh-model.lua') diff --git a/openssh-model.lua b/openssh-model.lua index 23987d4..12f3f6a 100644 --- a/openssh-model.lua +++ b/openssh-model.lua @@ -125,11 +125,11 @@ function list_conn_peers() local ps = {} local who = {} config = read_config() - local f = io.popen( path .. 'netstat -lnaW | grep "ESTABLISHED"' ) - local flines = format.string_to_table(f:read("*a"), "\n") + local f = io.popen( path .. 'netstat -lnaW' ) + local flines = format.search_for_lines(f:read("*a") or "", "ESTABLISHED") f:close() - local g = io.popen( path .. 'netstat -laW | grep "ESTABLISHED"' ) - local glines = format.string_to_table(g:read("*a"), "\n") + local g = io.popen( path .. 'netstat -laW' ) + local glines = format.search_for_lines(g:read("*a") or "", "ESTABLISHED") g:close() for i,line in ipairs(flines) do local loc, peer = string.match(line, "^%S+%s+%S+%s+%S+%s+(%S+)%s+(%S+)") @@ -146,29 +146,33 @@ function list_conn_peers() end end - local f = io.popen( path .. 'ps | grep "sshd:" | grep -v "grep"' ) - for line in f:lines() do + local f = io.popen( path .. 'ps' ) + for i,line in ipairs(format.search_for_lines(f:read("*a") or "", "sshd:")) do table.insert(ps, string.match(line,"@(%S+)")) end f:close() + local f = io.popen( path .. 'who' ) + local who = f:read("*a") or "" + f:close() for peer,v in pairs(netstat) do if not (netstat[peer].tty) then netstat[peer].tty = {} end - local cmd = path .. 'who | egrep "' .. peer - if v.name and v.name ~= "" then cmd = cmd .. '|' .. v.name end - cmd = cmd .. '" | egrep "' .. table.concat(ps, "|") .. '"' - local f = io.popen( cmd ) - 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, - }) + for line in string.gmatch(who, "[^\n]+") do + if string.find(line, peer) or (v.name ~= "" and string.find(line, v.name)) then + for j,l in ipairs(ps) do + if string.find(line, l) then + 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, + }) + break + end + end + end end - f:close() table.insert(output, v) output[#output]['host'] = peer end -- cgit v1.2.3