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 --- snort-model.lua | 74 ++++++++++++++++----------------------------------------- 1 file changed, 21 insertions(+), 53 deletions(-) (limited to 'snort-model.lua') 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 + -- cgit v1.2.3