diff options
-rw-r--r-- | syslog-config-html.lsp | 12 | ||||
-rw-r--r-- | syslog-controller.lua | 25 | ||||
-rw-r--r-- | syslog-expert-html.lsp | 56 | ||||
-rw-r--r-- | syslog-model.lua | 18 |
4 files changed, 58 insertions, 53 deletions
diff --git a/syslog-config-html.lsp b/syslog-config-html.lsp index 6c1d6c3..3b13297 100644 --- a/syslog-config-html.lsp +++ b/syslog-config-html.lsp @@ -90,14 +90,20 @@ </DL> +<H2>Save and apply above settings</H2> +<DL> + <DT>Apply settings</DT> + <DD><input class="submit" type="submit" name="cmdsave" value="Apply" disabled/></DD> +</DL> + <H1>MANAGEMENT</H1> <dl> <dt>Program controll-panel</dt> <dd><form name="cmd" action="" method="POST"> -<input type=submit class="submit" name="cmd" value="start" disabled> -<input type=submit class="submit" name="cmd" value="stop" disabled> -<input type=submit class="submit" name="cmd" value="restart" disabled> +<input type=submit class="submit" name="cmddaemon" value="start"> +<input type=submit class="submit" name="cmddaemon" value="stop"> +<input type=submit class="submit" name="cmddaemon" value="restart"> </form></dd> </dl> diff --git a/syslog-controller.lua b/syslog-controller.lua index 77cd0ab..05ed0d3 100644 --- a/syslog-controller.lua +++ b/syslog-controller.lua @@ -18,23 +18,18 @@ function status(self) end function config(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 --- end + + if ( self.clientdata.cmddaemon) then + startstop = self.model:startstop_service( self.clientdata.cmddaemon ) + end + local status = self.model.getstatus() local config, errors = self.model.getconfig() local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller return { status = status, --- srvcmdresult = srvcmdresult, + startstop = startstop, config = config, errors = errors, url = url, } @@ -42,15 +37,21 @@ end function expert(self) local modifications = self.clientdata.modifications or "" - if ( modifications ~= "") then + if ( self.clientdata.cmdsave) then modifications = self.model:update_filecontent(modifications) end + if ( self.clientdata.cmddaemon) then + startstop = self.model:startstop_service( self.clientdata.cmddaemon ) + end + local status = self.model.getstatus() local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller return { file = self.model:get_filedetails(), status = status, + startstop = startstop, + clientdata = self.clientdata, url = url, } end diff --git a/syslog-expert-html.lsp b/syslog-expert-html.lsp index 97dd3d5..694ea7c 100644 --- a/syslog-expert-html.lsp +++ b/syslog-expert-html.lsp @@ -3,34 +3,26 @@ <h1>SYSTEM INFO</h1> <DL> -<dt>Program status</dt> -<DD><? if (view.status.enabled) then io.write('Enabled') else io.write('Disabled') end ?></DD> -</DL> + <dt>Program status</dt> + <DD><? if (view.status.enabled) then io.write('Enabled') else io.write('Disabled') end ?></DD> -<DL> -<dt>Program version</dt> -<dd><?= view.status.version ?></dd> + <dt>Program version</dt> + <dd><?= view.status.version ?></dd> </DL> <h1>CONFIGURATION</h1> - <H2>Expert config</H2> - <h3>File details</h3> <DL> -<dt>File name</dt> -<dd><?= view.file.details.path ?></dd> -</DL> + <dt>File name</dt> + <dd><?= view.file.details.path ?></dd> -<DL> -<dt>File size</dt> -<dd><?= view.file.details.size ?></dd> -</DL> + <dt>File size</dt> + <dd><?= view.file.details.size ?></dd> -<DL> -<dt>Last modified</dt> -<dd><?= view.file.details.mtime ?></dd> + <dt>Last modified</dt> + <dd><?= view.file.details.mtime ?></dd> </DL> <h3>File content</h3> @@ -41,27 +33,25 @@ <H2>Save and apply above settings</H2> <DL> -<DT>Apply settings</DT> -<DD><input class="submit" type="submit" value="Apply"/></DD> + <DT>Apply settings</DT> + <DD><input class="submit" type="submit" name="cmdsave" value="Apply"/></DD> </DL> <H1>MANAGEMENT</H1> <dl> -<dt>Program controll-panel</dt> -<dd><form name="cmd" action="" method="POST"> -<input type=submit class="submit" name="cmd" value="start" disabled> -<input type=submit class="submit" name="cmd" value="stop" disabled> -<input type=submit class="submit" name="cmd" value="restart" disabled> -</form></dd> -</dl> - -<? if (view.startstop) and (view.startstop.cmdresult) then ?> -<dl> -<dt>Previous action result</dt> -<dd><pre><?= view.startstop.cmdresult?></pre></dd> + <dt>Program controll-panel</dt> + <dd><form name="cmd" action="" method="POST"> + <input type=submit class="submit" name="cmddaemon" value="start"/> + <input type=submit class="submit" name="cmddaemon" value="stop"/> + <input type=submit class="submit" name="cmddaemon" value="restart"/> + </form> + </dd> + <? if (view.startstop) and (view.startstop.cmdresult) then ?> + <dt>Previous action result</dt> + <dd><pre><?= view.startstop.cmdresult?></pre></dd> + <? end ?> </dl> -<? end ?> <? --[[ DEBUG INFORMATION diff --git a/syslog-model.lua b/syslog-model.lua index 6fa4bce..2e7cae2 100644 --- a/syslog-model.lua +++ b/syslog-model.lua @@ -4,6 +4,7 @@ require("fs") require("procps") require("getopts") require("format") +require("daemoncontrol") local configfile = "/etc/conf.d/syslog" local config = {} @@ -26,6 +27,10 @@ end -- ################################################################################ -- PUBLIC FUNCTIONS +function startstop_service ( self, state ) + return daemoncontrol.daemoncontrol("syslog", state) +end + function getstatus() local opts = getconfig() local status = {} @@ -43,29 +48,32 @@ end function get_filedetails() local filedetails = {} local path = configfile + filedetails.details = {path=path, size="0",mtime=""} + filedetails.content = "" if (fs.is_file(path)) then filedetails.details = fs.stat(path) filedetails.content = fs.read_file(path) - else - filedetails.details = {path="File is missing", size="0",mtime=""} - filedetails.content = "" end return filedetails end function getconfig() + local config = {} + config['SYSLOGD_OPTS']={} local errors = {} errors["SYSLOGD_OPTS"] = {} errors["KLOGD_OPTS"] = {} if (fs.is_file(configfile)) then - config = getopts.getoptsfromfile(configfile) + config = getopts.getoptsfromfile(configfile) or config else - config['SYSLOGD_OPTS']={} + errors["configfile"] = "Config file '".. configfile .. "' is missing!" end + -- Next section is to set/show default values when a option is not configured in the configfile config["SYSLOGD_OPTS"]["-O"] = config["SYSLOGD_OPTS"]["-O"] or "/var/log/messages" config["SYSLOGD_OPTS"]["-l_list"] = getloglevels() config["SYSLOGD_OPTS"]["-R"] = config["SYSLOGD_OPTS"]["-R"] or "" config["SYSLOGD_OPTS"]["-s"] = config["SYSLOGD_OPTS"]["-s"] or "" config["SYSLOGD_OPTS"]["-b"] = config["SYSLOGD_OPTS"]["-b"] or "" + -- Next section is to print errormessages when configs are wrong if (config["SYSLOGD_OPTS"]["-l"]) and ((tonumber(config["SYSLOGD_OPTS"]["-l"]) == nil) or (tonumber(config["SYSLOGD_OPTS"]["-l"]) > 8)) then errors["SYSLOGD_OPTS"]["-l"] = "Log value is out of range. Please select one of the above." |