summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMika Havela <mika.havela@gmail.com>2008-01-15 16:03:10 +0000
committerMika Havela <mika.havela@gmail.com>2008-01-15 16:03:10 +0000
commit4bac51eb98c5b5c184b697dcb5af63ec8b999db2 (patch)
treed3828f733330c0b4a5fa6fe7dcfaf2010de0db40
parent9c3419edaf3086aa1828be9fc2998e8cf090dd8b (diff)
downloadacf-snort-4bac51eb98c5b5c184b697dcb5af63ec8b999db2.tar.bz2
acf-snort-4bac51eb98c5b5c184b697dcb5af63ec8b999db2.tar.xz
Cleaned up code and used lib's instead.
Added functionallity to change the config-file. git-svn-id: svn://svn.alpinelinux.org/acf/snort/trunk@579 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r--Makefile1
-rw-r--r--snort-controller.lua35
-rw-r--r--snort-expert-html.lsp49
-rw-r--r--snort-model.lua74
-rw-r--r--snort-status-html.lsp25
-rw-r--r--snort-view-html.lsp7
6 files changed, 90 insertions, 101 deletions
diff --git a/Makefile b/Makefile
index f9e6ef3..50cdbe9 100644
--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,6 @@ APP_DIST=\
snort-model.lua \
snort-expert-html.lsp \
snort-status-html.lsp \
- snort-view-html.lsp \
snort.menu \
EXTRA_DIST=README Makefile config.mk
diff --git a/snort-controller.lua b/snort-controller.lua
index 199ac4e..19d55ea 100644
--- a/snort-controller.lua
+++ b/snort-controller.lua
@@ -16,18 +16,11 @@ mvc.on_load = function(self, parent)
end
end
--- Public methods
-
-status = function (self)
+function status(self)
local srvcmdresult = nil
local srvcmd = self.clientdata.srvcmd
if (srvcmd ~= nil) then
- srvcmdresult = self.model:service_control(srvcmd)
- if (srvcmd == "stop") or (srvcmd == "restart") then
- posix.sleep(3) -- Wait for the process to start|stop
- else
- posix.sleep(1) -- Wait for the process to start|stop
- end
+ srvcmdresult = self.model:startstop_service(srvcmd)
end
local alerts,alertresult = self.model:read_alert()
return ({status = self.model:getstatus(),
@@ -37,13 +30,23 @@ status = function (self)
url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller} )
end
---[[
-function config(self)
- return { status = self.model.getstatus() }
-end
---]]
-
function expert(self)
- return { file = self.model:get_filedetails(), status = self.model.getstatus(),}
+ 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
+ modifications = self.model:update_filecontent(modifications)
+ end
+
+ if ( cmd ~= nil ) then
+ startstop = self.model:startstop_service( cmd )
+ end
+
+ return ( {startstop = startstop,
+ status = self.model:getstatus(),
+ file = self.model:get_filedetails(),
+ modifications = modifications,
+ url = url, } )
end
diff --git a/snort-expert-html.lsp b/snort-expert-html.lsp
index 5f5d6ec..9de9b0f 100644
--- a/snort-expert-html.lsp
+++ b/snort-expert-html.lsp
@@ -1,24 +1,37 @@
<? local view = ... ?>
-<h1>CONFIGURATION</h1>
+<h1>SYSTEM INFO</h1>
+
+<dl>
+<dt>Program status
+<dd><? if (view.status.enabled) then io.write('Enabled') else io.write('Disabled') end ?></dd>
+</dl>
-<H2>Enable/Disable</H2>
-<DT>Change status for this program</DT>
-<DD><input class="radio" type="radio" name="enabled" value="2" <? if (view.status.enabled) then io.write('checked') end ?> >Enable
-<input class="radio" type="radio" name="enabled" value="3" <? if not (view.status.enabled) then io.write('checked') end ?> >Disable</DD>
+<dl>
+<dt>Program version</dt>
+<dd><?= view.status.version ?></dd>
+</dl>
+
+<h1>CONFIGURATION</h1>
<H2>Expert config</H2>
<h3>File details</h3>
+<DL>
<dt>File name</dt>
<dd><?= view.file.details.path ?></dd>
+</DL>
+<DL>
<dt>File size</dt>
<dd><?= view.file.details.size ?></dd>
+</DL>
+<DL>
<dt>Last modified</dt>
-<dd><?= view.file.details.mtimelong ?></dd>
+<dd><?= view.file.details.mtime ?></dd>
+</DL>
<h3>File content</h3>
@@ -27,8 +40,29 @@
<textarea name="modifications"><?= view.file.content ?></textarea>
<H2>Save and apply above settings</H2>
+<DL>
<DT>Apply settings</DT>
-<DD><input class="submitxxx" type="submit" value="Apply"/></DD>
+<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) and (view.startstop.cmdresult) then ?>
+<dl>
+<dt>Previous action result</dt>
+<dd><pre><?= view.startstop.cmdresult?></pre></dd>
+</dl>
+<? end ?>
<?
--[[ DEBUG INFORMATION
@@ -36,3 +70,4 @@ require("debugs")
io.write(debugs.variables(view))
--]]
?>
+
diff --git a/snort-model.lua b/snort-model.lua
index c52ce49..97e08ba 100644
--- a/snort-model.lua
+++ b/snort-model.lua
@@ -6,28 +6,13 @@ module (..., package.seeall)
require("fs")
require("posix")
require("procps")
+require("daemoncontrol")
+require("format")
-local function file_info ( path )
- local filedetails = posix.stat(path)
- filedetails["owner"]=rawget((posix.getpasswd(filedetails["uid"])),"name")
- filedetails["group"]=rawget((posix.getgroup(filedetails["gid"])),"name")
- filedetails["atimelong"]=os.date("%c", filedetails["atime"])
- filedetails["mtimelong"]=os.date("%c", filedetails["mtime"])
- filedetails["path"]=path
- filedetails["name"]=basename(path)
+local configfile = "/etc/snort/snort.conf"
- if ( filedetails["size"] > 1073741824 ) then
- filedetails["size"]=((filedetails["size"]/1073741824) - (filedetails["size"]/1073741824%0.1)) .. "G"
- elseif ( filedetails["size"] > 1048576 ) then
- filedetails["size"]=((filedetails["size"]/1048576) - (filedetails["size"]/1048576%0.1)) .. "M"
- elseif ( filedetails["size"] > 1024 ) then
- filedetails["size"]=((filedetails["size"]/1024) - (filedetails["size"]/1024%0.1)) .. "k"
- else
- filedetails["size"]=filedetails["size"]
- end
- return filedetails
-
-end
+-- ################################################################################
+-- LOCAL FUNCTIONS
local function get_version()
local cmd = "snort -V 2>&1 | grep Version | sed 's/.*ersion\ /snort-/'"
@@ -37,52 +22,29 @@ local function get_version()
return cmd_output_result
end
-local is_running = function( process )
- local statusreport = nil
- if (procps.pidof(process)) then
- statusreport = "Yes"
- end
- return statusreport
-end
-
-- ################################################################################
-- PUBLIC FUNCTIONS
-getstatus = function (self)
+function getstatus ()
local status = {}
- local version = get_version()
- status.version = version
- status.enabled = is_running("snort")
+ status["version"] = string.match(get_version(), "^(%S*)" )
+ status["enabled"] = procps.pidof("snort")
return status
end
+
function get_filedetails()
local filedetails = {}
- local path = "/etc/snort/snort.conf"
- filedetails.details = file_info(path)
+ local path = configfile
+ filedetails.details = fs.stat(path)
filedetails.content = fs.read_file(path)
return filedetails
end
-service_control = function ( self, srvcmd )
- local srvcmd = string.lower(srvcmd)
- local retval = ""
- local line = ""
- if (srvcmd == "start") or (srvcmd == "stop") or (srvcmd == "restart") then
- local file = io.popen( "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin /etc/init.d/snort " .. srvcmd .. " 2>&1" )
- if file ~= nil then
- line = file:read( "*l" )
- while line ~= nil do
- retval = retval .. "\n" .. line
- line = file:read( "*l" )
- end
- file:close()
- end
- else
- retval = "Unknown command!"
- end
- return retval
+
+function startstop_service ( self, state )
+ return daemoncontrol.daemoncontrol("ntpd", state)
end
-read_alert = function ()
+function read_alert()
local alertfile = "/var/log/snort/alert"
local alertcount = 0
local alertpriority = {}
@@ -140,3 +102,9 @@ read_alert = function ()
return alertcount,sorted_table
end
+function update_filecontent (self, modifications)
+ local path = configfile
+ local file_result,err = fs.write_file(path, format.dostounix(modifications))
+ return file_result
+end
+
diff --git a/snort-status-html.lsp b/snort-status-html.lsp
index 66d00c1..0eac963 100644
--- a/snort-status-html.lsp
+++ b/snort-status-html.lsp
@@ -2,31 +2,22 @@
<h1>SYSTEM INFO</h1>
+<dl>
<dt>Program status</dt>
-<dd><? if (view.status.enabled) then io.write('Enabled') else io.write('Disabled') end ?></dd>
+<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>
+
<H2>PROGRAM SPECIFIC OPTIONS/INFORMATION</H2>
+<DL>
<dt>Counted alerts</dt>
<dd><?= view.alerts ?> alert(s)</dd>
-
-
-<? --[[ ?>
-<dt>Daemon control</dt>
-<dd><form action="" method="POST">
-<input type=submit name="srvcmd" value="start" class="submit">
-<input type=submit name="srvcmd" value="stop" class="submit">
-<input type=submit name="srvcmd" value="restart" class="submit"></form>
-</dd>
-<? if (view.srvcmdresult) then ?>
-<dt>Previous action</dt>
-<dd><pre><?= view.srvcmdresult ?></pre></dd>
-<? end ?>
-<? --]] ?>
-
-
+</DL>
<h1>ALERT LIST</h1>
diff --git a/snort-view-html.lsp b/snort-view-html.lsp
deleted file mode 100644
index f148b86..0000000
--- a/snort-view-html.lsp
+++ /dev/null
@@ -1,7 +0,0 @@
-<? local view = ... ?>
-<html>
-<body>
-<h1>View file</h1>
-<textarea name=""><? io.write(view.logfile.value) ?></textarea>
-</body>
-</html>