From 68bb42a9a8664aee80f56c2b67cdd9e73f39890f Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Fri, 28 Mar 2008 13:59:36 +0000 Subject: Added info about autostart sequence. Bugfix on version numbering when program is not installed. git-svn-id: svn://svn.alpinelinux.org/acf/snort/trunk@862 ab2d0c66-481e-0410-8bed-d214d4d58bed --- snort-model.lua | 44 ++++++++++++++++++++++++++++++++++++-------- snort-status-html.lsp | 2 +- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/snort-model.lua b/snort-model.lua index 3666e6e..06809b7 100644 --- a/snort-model.lua +++ b/snort-model.lua @@ -16,11 +16,31 @@ local configfile = "/etc/snort/snort.conf" -- LOCAL FUNCTIONS local function get_version() - local cmd = "/sbin/apk_version -v -s " .. processname .. " | cut -d ' ' -f 1" - local cmd_output = io.popen( cmd ) - local cmd_output_result = cmd_output:read("*a") or "" - cmd_output:close() - return cmd_output_result + local cmd_output_result, cmd_output_error + local cmd = "/sbin/apk_version -vs " .. processname .." 2>/dev/null" + local f = io.popen( cmd ) + local cmdresult = f:read("*l") + if (cmdresult) and (#cmdresult > 0) then + cmd_output_result = string.match(cmdresult,"^%S*") or "Unknown" + else + cmd_output_error = "Program not installed" + end + f:close() + return cmd_output_result,cmd_output_error +end + +local function autostarts() + local cmd_output_result, cmd_output_error + local cmd = "/sbin/rc_status | egrep '^S' | egrep '" .. processname .."' 2>/dev/null" + local f = io.popen( cmd ) + local cmdresult = f:read("*a") + if (cmdresult) and (#cmdresult > 0) then + cmd_output_result = "Process will autostart at next boot (at sequence '" .. string.match(cmdresult,"^%a+(%d%d)") .. "')" + else + cmd_output_error = "Not programmed to autostart" + end + f:close() + return cmd_output_result,cmd_output_error end -- ################################################################################ @@ -29,10 +49,11 @@ end function getstatus () local status = {} - status.version = cfe({ - name = "version", + local value, errtxt = get_version() + status.version = cfe({ name = "version", label="Program version", - value=get_version(), + value=value, + errtxt=errtxt, }) status.status = cfe({ @@ -41,6 +62,13 @@ function getstatus () value=procps.pidof(processname) or "", }) + local autostart_sequense, autostart_errtxt = autostarts() + status.autostart = cfe({ name="autostart", + label="Autostart sequence", + value=autostart_sequense, + errtxt=autostart_errtxt, + }) + return status end diff --git a/snort-status-html.lsp b/snort-status-html.lsp index c7c8cef..9233f84 100644 --- a/snort-status-html.lsp +++ b/snort-status-html.lsp @@ -28,7 +28,7 @@ end
-- cgit v1.2.3