From 4bac51eb98c5b5c184b697dcb5af63ec8b999db2 Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Tue, 15 Jan 2008 16:03:10 +0000 Subject: 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 --- Makefile | 1 - snort-controller.lua | 35 +++++++++++++----------- snort-expert-html.lsp | 49 +++++++++++++++++++++++++++++----- snort-model.lua | 74 +++++++++++++++------------------------------------ snort-status-html.lsp | 25 ++++++----------- snort-view-html.lsp | 7 ----- 6 files changed, 90 insertions(+), 101 deletions(-) delete mode 100644 snort-view-html.lsp 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 @@ -

CONFIGURATION

+

SYSTEM INFO

+ +
+
Program status +
+
-

Enable/Disable

-
Change status for this program
-
>Enable - >Disable
+
+
Program version
+
+
+ +

CONFIGURATION

Expert config

File details

+
File name
+
+
File size
+
+
Last modified
-
+
+

File content

@@ -27,8 +40,29 @@

Save and apply above settings

+
Apply settings
-
+
+
+ + +

MANAGEMENT

+ +
+
Program controll-panel
+
+ + + +
+
+ + +
+
Previous action result
+
+
+ + 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 @@

SYSTEM INFO

+
Program status
-
+
+
+
Program version
+
+

PROGRAM SPECIFIC OPTIONS/INFORMATION

+
Counted alerts
alert(s)
- - - -
Daemon control
-
- - -
-
- -
Previous action
-
- - - - +

ALERT LIST

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 @@ - - - -

View file

- - - -- cgit v1.2.3