From 13d27723c1b8400cdfec8227199d596e1b0a8949 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Tue, 1 Jan 2013 21:16:29 +0000 Subject: Replace io.popen with modelfunctions.run_executable --- openssh-model.lua | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/openssh-model.lua b/openssh-model.lua index 2ca966c..b7cde44 100644 --- a/openssh-model.lua +++ b/openssh-model.lua @@ -12,7 +12,6 @@ local configfile = "/etc/ssh/sshd_config" local processname = "sshd" local packagename = "openssh" local header = "SSH" -local path="PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin " -- ################################################################################ -- LOCAL FUNCTIONS @@ -130,12 +129,10 @@ function list_conn_peers() local ps = {} local who = {} config = read_config() - 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' ) - local glines = format.search_for_lines(g:read("*a") or "", "ESTABLISHED") - g:close() + local f = modelfunctions.run_executable({"netstat", "-lnaW"}) + local flines = format.search_for_lines(f, "ESTABLISHED") + local g = modelfunctions.run_executable({"netstat", "-laW"}) + local glines = format.search_for_lines(g, "ESTABLISHED") for i,line in ipairs(flines) do local loc, peer = string.match(line, "^%S+%s+%S+%s+%S+%s+(%S+)%s+(%S+)") if loc then @@ -151,15 +148,12 @@ function list_conn_peers() end end - local f = io.popen( path .. 'ps' ) - for i,line in ipairs(format.search_for_lines(f:read("*a") or "", "sshd:")) do + f = modelfunctions.run_executable({"ps"}) + for i,line in ipairs(format.search_for_lines(f, "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() + local who = modelfunctions.run_executable({"who"}) for peer,v in pairs(netstat) do if not (netstat[peer].tty) then netstat[peer].tty = {} end for line in string.gmatch(who, "[^\n]+") do -- cgit v1.2.3