From e87110a3692c44b508e017809bc0d9582d72295d Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Mon, 7 Jul 2008 17:14:08 +0000 Subject: Implemented opennhrp config and validation. git-svn-id: svn://svn.alpinelinux.org/acf/opennhrp/trunk@1286 ab2d0c66-481e-0410-8bed-d214d4d58bed --- opennhrp-config-html.lsp | 3 +- opennhrp-controller.lua | 4 +- opennhrp-model.lua | 147 ++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 136 insertions(+), 18 deletions(-) diff --git a/opennhrp-config-html.lsp b/opennhrp-config-html.lsp index d079d72..509236d 100644 --- a/opennhrp-config-html.lsp +++ b/opennhrp-config-html.lsp @@ -16,7 +16,8 @@ end ?>

Config

/dev/null" local f = io.popen( cmd ) - show.value = f:read("*a") or "" + show.value = f:read("*a") + if not show.value or show.value == "" then + show.value = "No report available" + end return show end -function getconfig() - return cfe({ type="table", value={}, label="Edit Config" }) +function getconfig(self) + local config = parseconfigfile(self, configfile) + local result, config = validateconfig(config) + return config end -function setconfig(config) +function setconfig(self, config) + local success, config = validateconfig(config) + if success then + fs.write_file(configfile, generateconfigfile(config)) + else + config.errtxt = "Failed to set configuration" + end return config end -function getconfigfile() +function getconfigfile(self) local filedetails = modelfunctions.getfiledetails(configfile) - - -- Validate - + local result, filedetails = validateconfigfile(self, filedetails) return filedetails end -function setconfigfile(filedetails) - -- Validate - --local result, filedetails = validateconfigfile(filedetails) - local result = true - - if result then - fs.write_file(configfile, format.dostounix(filedetails.value.filecontent.value)) +function setconfigfile(self, filedetails) + filedetails.value.filename.value = configfile + filedetails.value.filecontent.value = string.gsub(format.dostounix(filedetails.value.filecontent.value), "\n+$", "") + local success, filedetails = validateconfigfile(self, filedetails) + if success then + fs.write_file(configfile, filedetails.value.filecontent.value) + filedetails = getconfigfile(self) + else + filedetails.errtxt = "Failed to set configuration file" end return filedetails -- cgit v1.2.3