summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2009-01-24 16:52:21 +0000
committerTed Trask <ttrask01@yahoo.com>2009-01-24 16:52:21 +0000
commitb8c478b7b6d9f10dad720d219f712d880386a34f (patch)
treea81462617d613614b4437eeeb377a12dd41757b7
parent122567867020d9f3976e66dd6fc4f642b31941d7 (diff)
downloadacf-openssh-b8c478b7b6d9f10dad720d219f712d880386a34f.tar.bz2
acf-openssh-b8c478b7b6d9f10dad720d219f712d880386a34f.tar.xz
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
-rw-r--r--openssh-model.lua44
1 files changed, 24 insertions, 20 deletions
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