summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMika Havela <mika.havela@gmail.com>2008-01-30 16:18:58 +0000
committerMika Havela <mika.havela@gmail.com>2008-01-30 16:18:58 +0000
commit86e67c5e0f5622b36ce792a6065e485b083e0f47 (patch)
treeffa975a6d0c41903a4873d61427975cc6fe6b81c
parent9e5cf48cfb22cf85cca230e13312254dbf651e51 (diff)
downloadacf-alpine-baselayout-86e67c5e0f5622b36ce792a6065e485b083e0f47.tar.bz2
acf-alpine-baselayout-86e67c5e0f5622b36ce792a6065e485b083e0f47.tar.xz
Redoing mostly everything trying to present things as cfe (my own fault when not doing this from start)
git-svn-id: svn://svn.alpinelinux.org/acf/alpine-baselayout/trunk@666 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r--syslog-config-html.lsp14
-rw-r--r--syslog-controller.lua17
-rw-r--r--syslog-expert-html.lsp2
-rw-r--r--syslog-model.lua45
-rw-r--r--syslog-status-html.lsp21
5 files changed, 74 insertions, 25 deletions
diff --git a/syslog-config-html.lsp b/syslog-config-html.lsp
index af69007..3782147 100644
--- a/syslog-config-html.lsp
+++ b/syslog-config-html.lsp
@@ -15,9 +15,6 @@
<H1>CONFIGURATION</H1>
<form name="config" action="" method="POST">
-<H2>Guided config</H2>
-
-<!--
<H2>Advanced config</H2>
<H3>General settings</H3>
@@ -74,10 +71,9 @@
</DD>
</DL>
--->
<H3>Remote logging</H3>
<DL>
-<!--
+
<? var = "-L" ?>
<DT <? if (view.errors) and (view.errors["SYSLOGD_OPTS"][var]) then io.write("class='error'") end ?>>Log locally and via network</DT>
<DD><input type="checkbox" name="<?= var ?>" <? if (view.config["SYSLOGD_OPTS"][var]) then io.write('checked=yes') end ?> />
@@ -86,7 +82,7 @@
io.write("<p class='error'>",view.errors["SYSLOGD_OPTS"][var] ,"</p>")
end ?>
</DD>
--->
+
<? var = "-R" ?>
<DT <? if (view.errors) and (view.errors["SYSLOGD_OPTS"][var]) then io.write("class='error'") end ?>>Log to IP or hostname on PORT</DT>
<DD><input type="text" class="text" name="<?= var ?>" value="<?= view.config["SYSLOGD_OPTS"][var] ?>"/>
@@ -103,6 +99,10 @@
<DL>
<DT>Apply settings</DT>
<DD><input class="submit" type="submit" name="cmdsave" value="Apply" /></DD>
+ <? if (view.cmderrors) then ?>
+ <dt class='error'>Errors in previous action</dt>
+ <dd><pre class='error'><?= view.cmderrors?></pre></dd>
+ <? end ?>
</DL>
</form>
<H1>MANAGEMENT</H1>
@@ -123,7 +123,7 @@
<?
---[[ DEBUG INFORMATION
+---[[ DEBUG INFORMATION
require("debugs")
io.write(debugs.variables(view))
--]]
diff --git a/syslog-controller.lua b/syslog-controller.lua
index 553b765..b183a89 100644
--- a/syslog-controller.lua
+++ b/syslog-controller.lua
@@ -24,7 +24,8 @@ function config(self)
startstop = self.model:startstop_service( self.clientdata.cmddaemon )
end
if ( self.clientdata.cmdsave) then
- local variables="-O -l -S -s -b -L -R"
+ local variables="-O -l -S -s -b -L -R" -- Advanced-config options
+ --local variables="-R" -- Guided-config options
for var in string.gmatch(variables, "%S+") do
-- Send nil instead of "" causes the parameter to be removed/deleted/empty/unset
if (self.clientdata[var] == "") then self.clientdata[var] = nil end
@@ -35,6 +36,18 @@ function config(self)
local status = self.model.getstatus()
local config, errors = self.model.getconfig()
local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller
+
+ local cmderrors_str = ""
+ for k,v in pairs(cmderrors) do
+ if (type(v) ~= "table") then
+ cmderrors_str = v.. "\n" .. cmderrors_str
+ else
+ for kk,vv in pairs(v) do
+ cmderrors_str = tostring(vv) .. "\n" .. tostring(cmderrors_str)
+ end
+ end
+ end
+ if (cmderrors_str == "") then cmderrors_str = nil end
return {
status = status,
@@ -43,7 +56,7 @@ function config(self)
cmdresult = cmdresult,
config = config,
errors = errors,
- cmderrors = cmderrors,
+ cmderrors = cmderrors_str,
url = url, }
end
diff --git a/syslog-expert-html.lsp b/syslog-expert-html.lsp
index 694ea7c..ca629a0 100644
--- a/syslog-expert-html.lsp
+++ b/syslog-expert-html.lsp
@@ -54,7 +54,7 @@
</dl>
<?
---[[ DEBUG INFORMATION
+---[[ DEBUG INFORMATION
require("debugs")
io.write(debugs.variables(view))
--]]
diff --git a/syslog-model.lua b/syslog-model.lua
index f8563fc..2013b76 100644
--- a/syslog-model.lua
+++ b/syslog-model.lua
@@ -5,6 +5,7 @@ require("procps")
require("getopts")
require("format")
require("daemoncontrol")
+require("validator")
local configfile = "/etc/conf.d/syslog"
local config = {}
@@ -24,6 +25,13 @@ local function getloglevels()
end
return loglevels
end
+local function isrunning(process)
+ if (procps.pidof("syslogd")) then
+ return "Enabled"
+ else
+ return "Disabled"
+ end
+end
-- ################################################################################
-- PUBLIC FUNCTIONS
@@ -34,14 +42,23 @@ end
function getstatus()
local opts = getconfig()
local status = {}
- status.version = get_version()
- status.enabled = procps.pidof("syslogd")
+ status.version = cfe({ name="Program version",
+ value=get_version(),
+ })
+ status.status = cfe({ name="Program status",
+ value=isrunning("syslogd"),
+ })
if (opts["SYSLOGD_OPTS"]) and not ((opts["SYSLOGD_OPTS"]["-R"] ~= "") and not (opts["SYSLOGD_OPTS"]["-L"])) then
- status.logfile = opts["SYSLOGD_OPTS"]["-O"]
+ status.logfile = cfe({ name="Locally logging to",
+ value=opts["SYSLOGD_OPTS"]["-O"],
+ })
end
if (opts["SYSLOGD_OPTS"]) and (opts["SYSLOGD_OPTS"]["-R"]) and (opts["SYSLOGD_OPTS"]["-R"] ~= "") then
- status.remote = opts["SYSLOGD_OPTS"]["-R"]
+ status.remote = cfe({ name="Remote logging to",
+ value=opts["SYSLOGD_OPTS"]["-R"],
+ })
end
+--]]
return status
end
@@ -113,14 +130,30 @@ service_control = function ( self, srvcmd )
end
function setconfigs(self,variable,parameter,value)
+ if (errors == nil) then
+ errors = {}
+ end
--TODO: Validate so that user cant add values with '-' (could cause major breakage next time you do getopts)
--If file is missing... then create a new one
-- if not (fs.is_file(configfile)) then fs.write_file(configfile, "SYSLOGD_OPTS=\"\"\nKLOGD_OPTS=\"\"") end
if not (variable) or not (parameter) then return nil, "Usage setconfigs(variable,parameter,value)" end
if not (string.find(parameter, "-%a$")) then return nil, "Parameter must be formated '-a' (where a is one upper/lowercase letter [a-z])" end
- -- Set specific variables (and their values
+ if (value) and (parameter == "-O") then
+ value, errors["-O"] = validator.is_valid_filename(value, "/var/log" )
+ end
+ if (value) and (parameter == "-R") then
+ local port = string.match(value, ":(.-)$")
+ local host = string.match(value, "^(.-):?")
+ if (port) and not (validator.is_port(port)) then
+ errors["-R"] = "Port:'" .. tostring(port) .. "' is not a valid portnumber!"
+ end
+ errors["-R"] = "Port:'" .. tostring(port) .. "' Host:" .. tostring(host)
+ end
+
+ -- Set specific variables (and their values)
if (value) and ((parameter == "-S") or (parameter == "-L")) then value = "" end
- local retval, errors = getopts.setoptsinfile(configfile,variable,parameter,value)
+ local retval, errorscmd = getopts.setoptsinfile(configfile,variable,parameter,value)
+ errors["commit"] = errorscmd
return retval, errors
end
diff --git a/syslog-status-html.lsp b/syslog-status-html.lsp
index 845abec..c5b1c0d 100644
--- a/syslog-status-html.lsp
+++ b/syslog-status-html.lsp
@@ -3,29 +3,32 @@
<h1>SYSTEM INFO</h1>
<DL>
- <dt>Program status</dt>
- <DD><? if (view.status.enabled) then io.write('Enabled') else io.write('Disabled') end ?></DD>
+ <dt><?= view.status.status.name ?></dt>
+ <dd><?= view.status.status.value ?><p class='error'><?= view.status.status.errtxt ?></p></dd>
- <dt>Program version</dt>
- <dd><?= view.status.version ?></dd>
+ <dt><?= view.status.version.name ?></dt>
+ <dd><?= view.status.version.value ?><p class='error'><?= view.status.version.errtxt ?></p></dd>
</DL>
<H2>PROGRAM SPECIFIC OPTIONS/INFORMATION</H2>
<DL>
<? if (view.status.logfile) then ?>
- <dt>Locally logging to</dt>
- <dd><?= view.status.logfile ?></dd>
+ <dt><?= view.status.logfile.name ?></dt>
+ <dd><?= view.status.logfile.value ?><p class='error'><?= view.status.logfile.errtxt ?></p></dd>
<? end ?>
<? if (view.status.remote) then ?>
- <dt>Remote logging to</dt>
- <dd><?= view.status.remote ?></dd>
+ <dt><?= view.status.remote.name ?></dt>
+ <dd><?= view.status.remote.value ?><p class='error'><?= view.status.remote.errtxt ?></p></dd>
<? end ?>
</DL>
+<H1>DEBUGGING</H1>
+<H2>CFE debugging</H2>
+<?= html.cfe_unpack(view) ?>
<?
---[[ DEBUG INFORMATION
+---[[ DEBUG INFORMATION
require("debugs")
io.write(debugs.variables(view))
--]]