summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMika Havela <mika.havela@gmail.com>2008-03-03 14:55:02 +0000
committerMika Havela <mika.havela@gmail.com>2008-03-03 14:55:02 +0000
commitf14ce45bcdcbbe99cb5693966019d0deb39371e5 (patch)
tree72d6db9d18f64c9f938c43000481595316e79389
parent1c331f9c3a09d3f50c98a129db3a5dd77abc348e (diff)
downloadacf-snort-f14ce45bcdcbbe99cb5693966019d0deb39371e5.tar.bz2
acf-snort-f14ce45bcdcbbe99cb5693966019d0deb39371e5.tar.xz
Some changes to get 'save' button to work in expert-tab
git-svn-id: svn://svn.alpinelinux.org/acf/snort/trunk@785 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r--snort-controller.lua105
-rw-r--r--snort-expert-html.lsp120
-rw-r--r--snort-model.lua59
-rw-r--r--snort-status-html.lsp42
4 files changed, 242 insertions, 84 deletions
diff --git a/snort-controller.lua b/snort-controller.lua
index 19d55ea..926bab3 100644
--- a/snort-controller.lua
+++ b/snort-controller.lua
@@ -4,7 +4,7 @@ require("posix")
-- We use the self.conf table because it already has prefix,controller,etc
-- The redir code is defined in the application error handler (acf-controller)
local list_redir = function (self)
- self.conf.action = "read"
+ self.conf.action = "status"
self.conf.type = "redir"
error (self.conf)
end
@@ -16,36 +16,115 @@ mvc.on_load = function(self, parent)
end
end
+local function getstatus(self)
+ local status = self.model.getstatus()
+ if (#status.status.value > 0) then
+ status.status.value = "Enabled"
+ else
+ status.status.value = "Disabled"
+ end
+ return status
+end
+
+local function displaycmdmanagement(disablestart,disablestop,disablerestart)
+ -- Add a management buttons
+ local management = {}
+ management.start = cfe({ name="cmdmanagement",
+ label="Program control-panel",
+ value="Start",
+ type="submit",
+ })
+ management.stop = cfe({ name="cmdmanagement",
+ label="Program control-panel",
+ value="Stop",
+ type="submit",
+ })
+ management.restart = cfe({ name="cmdmanagement",
+ label="Program control-panel",
+ value="Restart",
+ type="submit",
+ })
+
+ -- Disable management buttons based on if the process is running or not
+ if (disablestart) then management.start.disabled = "yes" end
+ if (disablestop) then management.stop.disabled = "yes" end
+ if (disablerestart) then management.restart.disabled = "yes" end
+
+ return management
+end
+
function status(self)
local srvcmdresult = nil
local srvcmd = self.clientdata.srvcmd
- if (srvcmd ~= nil) then
- srvcmdresult = self.model:startstop_service(srvcmd)
- end
+ local status = getstatus(self)
+
local alerts,alertresult = self.model:read_alert()
- return ({status = self.model:getstatus(),
- srvcmdresult=srvcmdresult,
+ return ({
+ status = status,
alerts=alerts,
alertresult=alertresult,
url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller} )
end
function expert(self)
- local modifications = self.clientdata.modifications or ""
local cmd = self.clientdata.cmd
local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller
- if ( modifications ~= "") then
+ local modifications = self.clientdata.filecontent or ""
+ if ( self.clientdata.cmdsave ) then
modifications = self.model:update_filecontent(modifications)
end
- if ( cmd ~= nil ) then
- startstop = self.model:startstop_service( cmd )
+ -- Start/Stop/Restart process
+ local cmdmanagement
+ if ( self.clientdata.cmdmanagement) then
+ cmdmanagement = cfe({
+ name="cmdmanagement",
+ label="Previous action result",
+ action=cfe({
+ name="cmdmanagement",
+ value=string.lower(self.clientdata.cmdmanagement), -- This row contains start/stop/restart (one of these commands)
+ }),
+ })
+ local actionresult, cmdmanagement = self.model:startstop_service( cmdmanagement.action )
+ end
+
+ local status = getstatus(self)
+ local file = self.model:get_filedetails()
+
+ -- Add buttons
+ file.cmdsave = cfe ({
+ name="cmdsave",
+ label="Apply settings",
+ value="Apply",
+ type="submit",
+ })
+ if (self.clientdata.cmdsave) then
+ file.cmdsave.descr="* Changes has been saved!"
+ end
+
+ -- Management buttons
+ local disablestart,disablestop,disablerestart
+ -- Disable management buttons based on if the process is running or not
+ if (string.lower(status.status.value) == "enabled" ) then
+ disablestart = "yes"
+ else
+ disablestop = "yes"
end
+ -- Display management buttons
+ local management = displaycmdmanagement(disablestart,disablestop,disablerestart)
+
+
+
+-- if ( cmd ~= nil ) then
+-- startstop = self.model:startstop_service( cmd )
+-- end
- return ( {startstop = startstop,
- status = self.model:getstatus(),
- file = self.model:get_filedetails(),
+ return ( {
+ management = management,
+ cmdmanagement = cmdmanagement,
+ status = status,
+ file = file,
modifications = modifications,
url = url, } )
end
diff --git a/snort-expert-html.lsp b/snort-expert-html.lsp
index ab2ee56..2217089 100644
--- a/snort-expert-html.lsp
+++ b/snort-expert-html.lsp
@@ -6,69 +6,91 @@ io.write(html.cfe_unpack(view))
io.write("</span>")
--]]
?>
-<h1>SYSTEM INFO</h1>
-
-<dl>
-<dt>Program status
-<dd><? if (view.status.enabled) then io.write('Enabled') else io.write('Disabled') end ?></dd>
-</dl>
+<?
+function displayinfo(myform,tags,viewonly)
+ for k,v in pairs(tags) do
+ if (myform[v]) and (myform[v]["value"]) then
+ local val = myform[v]
+ io.write("\t<DT")
+ if (#val.errtxt > 0) then
+ val.class = "error"
+ io.write(" class='error'")
+ end
+ io.write(">" .. val.label .. "</DT>\n")
+ if (viewonly) then
+ io.write("\t\t<DD>" .. val.value .. "\n")
+ else
+ io.write("\t\t<DD>" .. html.form[val.type](val) .. "\n")
+ end
+ if (val.descr) and (#val.descr > 0) then io.write("\t\t<P CLASS='descr'>" .. string.gsub(val.descr, "\n", "<BR>") .. "</P>\n") end
+ if (#val.errtxt > 0) then io.write("\t\t<P CLASS='error'>" .. string.gsub(val.errtxt, "\n", "<BR>") .. "</P>\n") end
+ io.write("\t\t</DD>\n")
+ end
+ end
+end
+?>
-<dl>
-<dt>Program version</dt>
-<dd><?= view.status.version ?></dd>
-</dl>
+<H1>SYSTEM INFO</H1>
+<DL>
+<?
+local myform = view.status
+local tags = { "status", "version", }
+displayinfo(myform,tags,"viewonly")
+?>
+</DL>
+<form name="myform" action="" method="POST">
<h1>CONFIGURATION</h1>
-
<H2>Expert config</H2>
-
<h3>File details</h3>
-
<DL>
-<dt>File name</dt>
-<dd><?= view.file.details.path ?></dd>
+<?
+local myform = view.file
+local tags = { "filename", "filesize", "mtime", "sumerrors", }
+displayinfo(myform,tags,"viewonly")
+?>
</DL>
-<DL>
-<dt>File size</dt>
-<dd><?= view.file.details.size ?></dd>
-</DL>
+<H3>FILE CONTENT</H3>
+<?
+local myform = view.file
+io.write(html.form[myform.filecontent.type](myform.filecontent))
+?>
+<H2>SAVE AND APPLY ABOVE SETTINGS</H2>
<DL>
-<dt>Last modified</dt>
-<dd><?= view.file.details.mtime ?></dd>
+<?
+local tags = { "cmdsave", }
+displayinfo(myform,tags)
+?>
</DL>
-<h3>File content</h3>
-
-<form name="myform" action="" method="POST">
-<input name="name" type=hidden value="">
-<textarea name="modifications"><?= view.file.content ?></textarea>
-
-<H2>Save and apply above settings</H2>
-<DL>
-<DT>Apply settings</DT>
-<DD><input class="submit" type="submit" value="Apply"/></DD>
-</DL>
</form>
-<H1>MANAGEMENT</H1>
-
-<dl>
-<dt>Program controll-panel</dt>
-<dd><form name="cmd" action="" method="POST">
-<input type=submit class="submit" name="cmd" value="start">
-<input type=submit class="submit" name="cmd" value="stop">
-<input type=submit class="submit" name="cmd" value="restart">
-</form></dd>
-</dl>
-
-<? if (view.startstop) then ?>
-<dl>
-<dt>Previous action result</dt>
-<dd><pre><?= view.startstop?></pre></dd>
-</dl>
-<? end ?>
+<? -- MANAGEMENT BUTTONS
+local cmdform = view.management
+local cmdresult = view.cmdmanagement
+local tags = { "start", "stop", "restart" }
+if (cmdform) and (cmdform[tags[1]]) then
+
+ io.write('<form name="management" action="" method="POST">')
+ io.write('<H1>MANAGEMENT</H1>')
+ io.write('<dl>')
+ io.write('<dt>' .. cmdform[tags[1]]["label"] .. '</dt>')
+ io.write('<dd>')
+ for k,v in pairs(tags) do
+ if (cmdform[v]) then
+ io.write(html.form[cmdform[v].type](cmdform[v]))
+ end
+ end
+ io.write('</dd>')
+
+ if (cmdresult) and (cmdresult.action) and (#cmdresult.action.descr > 0) then
+ io.write('<dt>' .. cmdresult.label .. '</dt>')
+ io.write('<dd><pre>' .. cmdresult.action.descr .. '</pre></dd>')
+ end
+ io.write('</dl></form>')
+end ?>
<?
--[[ DEBUG INFORMATION
diff --git a/snort-model.lua b/snort-model.lua
index 02c5a1e..3666e6e 100644
--- a/snort-model.lua
+++ b/snort-model.lua
@@ -10,14 +10,13 @@ require("daemoncontrol")
require("format")
local processname = "snort"
-
local configfile = "/etc/snort/snort.conf"
-- ################################################################################
-- LOCAL FUNCTIONS
local function get_version()
- local cmd = "snort -V 2>&1 | grep Version | sed 's/.*ersion\ /snort-/'"
+ 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()
@@ -29,22 +28,60 @@ end
function getstatus ()
local status = {}
- status["version"] = string.match(get_version(), "^(%S*)" )
- status["enabled"] = procps.pidof("snort")
+
+ status.version = cfe({
+ name = "version",
+ label="Program version",
+ value=get_version(),
+ })
+
+ status.status = cfe({
+ name="status",
+ label="Program status",
+ value=procps.pidof(processname) or "",
+ })
+
return status
end
function get_filedetails()
- local filedetails = {}
local path = configfile
- filedetails.details = fs.stat(path)
- filedetails.content = fs.read_file(path)
- return filedetails
+ local filedetails = fs.stat(path)
+ local file = {}
+
+ file["filename"] = cfe({
+ name="filename",
+ label="File name",
+ value=path,
+ })
+ file["filesize"] = cfe({
+ name="filesize",
+ label="File size",
+ value=filedetails.size or 0,
+ })
+ file["mtime"] = cfe({
+ name="mtime",
+ label="File date",
+ value=filedetails.mtime or "---",
+ })
+ file["filecontent"] = cfe({
+ type="longtext",
+ name="filecontent",
+ label="File content",
+ value=fs.read_file(path),
+ })
+ return file
end
-function startstop_service ( self, state )
- local cmdresult,cmdmessage,cmderror,cmdaction = daemoncontrol.daemoncontrol(processname, state)
- return cmdmessage
+
+-- action should be a CFE
+function startstop_service ( self, action )
+ local cmd = action.value
+ local cmdresult,cmdmessage,cmderror,cmdaction = daemoncontrol.daemoncontrol("snort", cmd)
+ action.descr=cmdmessage
+ action.errtxt=cmderror
+ -- Reporting back (true|false, the original acition)
+ return cmdresult,action
end
function read_alert()
diff --git a/snort-status-html.lsp b/snort-status-html.lsp
index 5c35e30..c7c8cef 100644
--- a/snort-status-html.lsp
+++ b/snort-status-html.lsp
@@ -1,17 +1,37 @@
<? local view = ... ?>
-<h1>SYSTEM INFO</h1>
-
-<dl>
-<dt>Program status</dt>
-<DD><? if (view.status.enabled) then io.write('Enabled') else io.write('Disabled') end ?></DD>
-</dl>
-
-<dl>
-<dt>Program version</dt>
-<dd><?= view.status.version ?></dd>
-</dl>
+<?
+function displayinfo(myform,tags,viewonly)
+ for k,v in pairs(tags) do
+ if (myform[v]) and (myform[v]["value"]) then
+ local val = myform[v]
+ io.write("\t<DT")
+ if (#val.errtxt > 0) then
+ val.class = "error"
+ io.write(" class='error'")
+ end
+ io.write(">" .. val.label .. "</DT>\n")
+ if (viewonly) then
+ io.write("\t\t<DD>" .. val.value .. "\n")
+ else
+ io.write("\t\t<DD>" .. html.form[val.type](val) .. "\n")
+ end
+ if (val.descr) and (#val.descr > 0) then io.write("\t\t<P CLASS='descr'>" .. string.gsub(val.descr, "\n", "<BR>") .. "</P>\n") end
+ if (#val.errtxt > 0) then io.write("\t\t<P CLASS='error'>" .. string.gsub(val.errtxt, "\n", "<BR>") .. "</P>\n") end
+ io.write("\t\t</DD>\n")
+ end
+ end
+end
+?>
+<H1>SYSTEM INFO</H1>
+<DL>
+<?
+local myform = view.status
+local tags = { "status", "version", }
+displayinfo(myform,tags,"viewonly")
+?>
+</DL>
<H2>PROGRAM SPECIFIC OPTIONS/INFORMATION</H2>
<DL>