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-connectedpeers-html.lsp | 47 +++++++++++++++++++++++++++++++++++++++++ openssh-controller.lua | 5 +++++ openssh-model.lua | 47 ++++++++++++++++++++++++++++++++++++++++- openssh-status-html.lsp | 3 ++- openssh-welcome-html.lsp | 10 +++++++++ openssh.menu | 2 +- openssh.roles | 2 +- 7 files changed, 112 insertions(+), 4 deletions(-) create mode 100644 openssh-connectedpeers-html.lsp create mode 100644 openssh-welcome-html.lsp diff --git a/openssh-connectedpeers-html.lsp b/openssh-connectedpeers-html.lsp new file mode 100644 index 0000000..6cf24b1 --- /dev/null +++ b/openssh-connectedpeers-html.lsp @@ -0,0 +1,47 @@ +<% local data = ... +require("viewfunctions") +--[[ +io.write("

DEBUGGING

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(data)) +io.write("
") +--]] +%> + +

Connected peers

+
+<% +local col1="180px" +for k,v in pairs(data) do + io.write("

" .. (tostring(v.host) or "unkown") .. "

") + io.write("") + for i=1, v.cnt do + io.write("") + if (v.tty[i]) then + io.write("") + io.write("") + + else + io.write("") + io.write("") + end + io.write("") + end + io.write("
") + io.write("") + io.write("") + io.write("") + io.write("") + + io.write("
Session TTY:".. tostring(v.tty[i]['tty']) .. "
Session Started:".. tostring(v.tty[i]['time']) .. "
Session Idle:".. tostring(v.tty[i]['idle']) .. "
") + io.write("
") + io.write("") + io.write("") + io.write("") + io.write("") + io.write("") + + io.write("
Session TTY:No records
Session Started:No records
Session Idle:No records
Other:This could be a sshfs session
") + io.write("
") +end +%> +
diff --git a/openssh-controller.lua b/openssh-controller.lua index c5b199a..30800f5 100644 --- a/openssh-controller.lua +++ b/openssh-controller.lua @@ -91,3 +91,8 @@ function expert(self) return controllerfunctions.handle_form(self, self.model.getconfigfile, self.model.setconfigfile, self.clientdata, "Save", "Edit Config", "Configuration Saved") end +function connectedpeers(self) + return self.model.list_conn_peers() +end +function welcome(self) +end 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 diff --git a/openssh-status-html.lsp b/openssh-status-html.lsp index a9ab0d3..c126d2e 100644 --- a/openssh-status-html.lsp +++ b/openssh-status-html.lsp @@ -1,4 +1,4 @@ -<% local data = ... +<% local data, viewlibrary, page_info, session = ... require("viewfunctions") --[[ io.write("

DEBUGGING

DEBUG INFO: CFE

") @@ -15,3 +15,4 @@ displayitem(data.value.version) displayitem(data.value.autostart) %> + diff --git a/openssh-welcome-html.lsp b/openssh-welcome-html.lsp new file mode 100644 index 0000000..d627bd6 --- /dev/null +++ b/openssh-welcome-html.lsp @@ -0,0 +1,10 @@ +<% local data, viewlibrary, page_info, session = ... +%> + +<% if viewlibrary and viewlibrary.dispatch_component and session.permissions[page_info.controller].connectedpeers then + viewlibrary.dispatch_component("status") +end %> + +<% if viewlibrary and viewlibrary.dispatch_component and session.permissions[page_info.controller].connectedpeers then + viewlibrary.dispatch_component("connectedpeers") +end %> diff --git a/openssh.menu b/openssh.menu index 324f80a..173160d 100644 --- a/openssh.menu +++ b/openssh.menu @@ -1,5 +1,5 @@ #CAT GROUP/DESC TAB ACTION -Networking 20SSH Status status +Networking 20SSH Status welcome Networking 20SSH Config config Networking 20SSH Expert expert #Networking 20SSH Logfile logfile diff --git a/openssh.roles b/openssh.roles index 534a776..5ff2469 100644 --- a/openssh.roles +++ b/openssh.roles @@ -1,2 +1,2 @@ -READ=openssh:status,openssh:logfile +READ=openssh:status,openssh:logfile,openssh:connectedpeers,openssh:welcome, UPDATE=openssh:expert,openssh:config,openssh:startstop, -- cgit v1.2.3