From 9ad995cea4060451485664a102657dfe82258dc8 Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Wed, 9 Jan 2008 12:27:39 +0000 Subject: 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 --- syslog-config-html.lsp | 38 +++++++++++-------- syslog-controller.lua | 41 ++++++++------------- syslog-model.lua | 99 ++++++++++++++++++++++++++++++++++++++++++++++++-- syslog-status-html.lsp | 13 +++++-- 4 files changed, 143 insertions(+), 48 deletions(-) diff --git a/syslog-config-html.lsp b/syslog-config-html.lsp index 0ced54f..b32d323 100644 --- a/syslog-config-html.lsp +++ b/syslog-config-html.lsp @@ -1,9 +1,9 @@ - +

System logging

System info

Process status
-
+
Daemon control
@@ -12,45 +12,52 @@
+ +
Previous action
+
+ +

Configuration

General settings

Log to given file
-
+

(default=/var/log/messages)

Set local log level
-
1 -2 -3 -4 -5 -

(1=Quiet, 5=Noisy)

+
>1 +>2 +>3 +>4 +>5 +>Default +

(1=Quiet, 5=Noisy, Default=Not specifyed any loglevel in the config)

Smaller logging output
-
+
/>

Save logs for a longer period

Max size (KB) before rotate
-
+

(default=200KB, 0=off)

Number of rotated logs to keep
-
+

(default=1, max=99, 0=purge)

Remote logging

-
Log to IP or hostname on PORT
+
Log to IP or hostname on PORT
+

(default PORT=514/UDP)

Save above settings

-
Apply settings
-
+
Save settings
+
@@ -61,3 +68,4 @@ require("debugs") io.write(debugs.variables(view)) --]] ?> + diff --git a/syslog-controller.lua b/syslog-controller.lua index 76089fb..8869fec 100644 --- a/syslog-controller.lua +++ b/syslog-controller.lua @@ -1,41 +1,30 @@ - module(..., package.seeall) ---require("privsep") -require("join") - --- those should go into acf.conf -local user="nobody" -local group="nobody" - --- drop privileges and put privileged model funcs in self.priv mvc = {} function mvc.on_load(self) --- self.priv = privsep.drop_privs(user, group, self.model.priv) end function status(self) + return self.model.getstatus() end + function config(self) - local ctl = {} - local opts = self.model.readopts() --- ctl.pidlist = self.priv.is_enabled() - if pidlist then - ctl.status = "enabled" - else - ctl.status = "Disabled" + 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 end - ctl.opts = opts - if opts and opts.remote then - ctl.remote = "checked" - ctl.host = opts.remote - else - ctl.remote = "" - ctl.host = "" - end - return ctl + + return { status = self.model.getstatus(), srvcmdresult=srvcmdresult, config= self.model.getconfig() } end + function expert(self) + return {status="Work in progress!"} end 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 - - diff --git a/syslog-status-html.lsp b/syslog-status-html.lsp index 32cb67e..62d497f 100644 --- a/syslog-status-html.lsp +++ b/syslog-status-html.lsp @@ -5,20 +5,25 @@

SYSTEM INFO

Program version
-
(Don't think this can be displayed)
+
Process status
-
[running|stopped]
+
+
Logfile
-
[/var/log/messages] (Hidden if -R and not -L)
+
+ +
Remote logging to
-
[1.2.3.4:514] (Hidden if not appliable)
+
+