summaryrefslogtreecommitdiffstats
path: root/syslog-model.lua
diff options
context:
space:
mode:
authorMika Havela <mika.havela@gmail.com>2008-01-09 12:27:39 +0000
committerMika Havela <mika.havela@gmail.com>2008-01-09 12:27:39 +0000
commit9ad995cea4060451485664a102657dfe82258dc8 (patch)
treea7d82dce97c313c445fce9bccba0890d87a28460 /syslog-model.lua
parent8b44052f3210ffaca4b4e51506b5eec295f16fda (diff)
downloadacf-alpine-baselayout-9ad995cea4060451485664a102657dfe82258dc8.tar.bz2
acf-alpine-baselayout-9ad995cea4060451485664a102657dfe82258dc8.tar.xz
Showing current config starting to work (still some problems with RegExpr in model). Saving changes still doesn't work.
git-svn-id: svn://svn.alpinelinux.org/acf/alpine-baselayout/trunk@519 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'syslog-model.lua')
-rw-r--r--syslog-model.lua99
1 files changed, 96 insertions, 3 deletions
diff --git a/syslog-model.lua b/syslog-model.lua
index af41c70..3413ccd 100644
--- a/syslog-model.lua
+++ b/syslog-model.lua
@@ -3,6 +3,101 @@ module(..., package.seeall)
--require("pidof")
require("split")
+local function get_version()
+ local cmd = "/sbin/apk_version -v -s busybox | 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
+end
+
+local is_running = function( process )
+ local statusreport = nil
+ local cmdoutput = {}
+ local cmd, error = io.popen("pidof " .. process ,r)
+ local cmdoutput = string.gsub(cmd:read("*a"), "%s", "")
+ cmd:close()
+ if (cmdoutput ~= "") then
+ statusreport = "Running"
+ else
+ statusreport = "Stopped"
+ end
+ return statusreport
+end
+
+-- ################################################################################
+-- EXPERIMENTAL LOCAL FUNCTIONS
+
+local function readopts(optname)
+ local opts = {}
+ local line
+ local f = io.open("/etc/conf.d/syslog", "r")
+ if f == nil then
+ return nil
+ end
+ for line in f:lines() do
+ local optstr = string.match(line, "^" .. optname .. "=\"?(.*)\"?")
+ if optstr then
+ local t = {}
+ for k, v in string.gmatch(optstr, "(-%S+)%s+(%S+)") do
+ opts[k] = v
+ end
+ end
+ end
+ return opts
+end
+
+-- ################################################################################
+-- PUBLIC FUNCTIONS
+
+function getstatus()
+ local opts = readopts("SYSLOGD_OPTS")
+ local status = {}
+ local version = get_version()
+ status.version = version
+ local isrunning = is_running("syslogd")
+ status.status = isrunning
+ status.logfile = opts["-O"] or "/var/log/messages"
+ status.remote = opts["-R"]
+ return status
+end
+
+function getconfig()
+ local opts = readopts("SYSLOGD_OPTS")
+ local config = {}
+ config.debug = opts
+ config.logfile = opts["-O"] or ""
+ config.loglevel = opts["-l"] or ""
+ config.smallog = opts["-S"] --FIXME: DOESNT WORK!!!
+ config.maxsize = opts["-s"] or ""
+ config.logrotate = opts["-b"] or ""
+ config.remote = opts["-R"] or ""
+ return config
+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/syslog " .. 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
+end
+
+-- ################################################################################
+-- OTHER FUNCTIONS
+
-- we actually need root permissions to get the process list
--[[
priv = {}
@@ -25,7 +120,7 @@ end
--]]
-- this func does not need privileges
-function readopts()
+local function readopts()
local opts = {}
local line
local f = io.open("/etc/conf.d/syslog", "r")
@@ -41,5 +136,3 @@ function readopts()
end
return opts
end
-
-