summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--logfiles-model.lua22
-rw-r--r--syslog-model.lua41
2 files changed, 31 insertions, 32 deletions
diff --git a/logfiles-model.lua b/logfiles-model.lua
index 41c2308..d255256 100644
--- a/logfiles-model.lua
+++ b/logfiles-model.lua
@@ -73,18 +73,18 @@ local do_grep = function(filecontent, grep)
end
get_filedetails = function (path, grep)
- local filedetails
local available_files = get()
- for i,file in ipairs(available_files.value) do
- if ( file.value.filename.value == path ) then
- filedetails = modelfunctions.getfiledetails(path)
- do_grep(filedetails.value.filecontent, grep)
- break
- end
- end
- if not filedetails then
- filedetails = modelfunctions.getfiledetails("")
- filedetails.value.filename.value = path
+ local filedetails = modelfunctions.getfiledetails(path,
+ function(filename)
+ for i,file in ipairs(available_files.value) do
+ if file.value.filename.value == filename then
+ return true
+ end
+ end
+ return false
+ end)
+ if not filedetails.errtxt then
+ do_grep(filedetails.value.filecontent, grep)
end
filedetails.value.grep = cfe({ value=grep or "", label="Grep" })
return filedetails
diff --git a/syslog-model.lua b/syslog-model.lua
index 541d541..380b300 100644
--- a/syslog-model.lua
+++ b/syslog-model.lua
@@ -131,6 +131,25 @@ local validateconfig = function(config)
return success, config
end
+local validate_configfile = function(filedetails)
+ local success = true
+
+ local configcontent = format.opts_to_table(string.sub((format.parse_ini_file(filedetails.value.filecontent.value, "", "SYSLOGD_OPTS") or ""),2,-2))
+ local config = makeconfig(configcontent)
+ success, config = validateconfig(config)
+ if not success then
+ local errormessages = {}
+ for x,y in pairs(config.value) do
+ if y.errtxt then
+ errormessages[#errormessages + 1] = y.label .. " - " .. y.errtxt
+ end
+ end
+ filedetails.value.filecontent.errtxt = table.concat(errormessages, "\n")
+ end
+
+ return success, filedetails
+end
+
-- ################################################################################
-- PUBLIC FUNCTIONS
@@ -199,25 +218,5 @@ function updateconfig (config)
end
function update_filedetails (filedetails)
- -- Validation before writing
- filedetails.value.filecontent.value = string.gsub(format.dostounix(filedetails.value.filecontent.value), "\n+$", "")
- local configcontent = format.opts_to_table(string.sub((format.parse_ini_file(filedetails.value.filecontent.value, "", "SYSLOGD_OPTS") or ""),2,-2))
- local config = makeconfig(configcontent)
- local success, errtxt
- success, config = validateconfig(config)
- if success == true then
- fs.write_file(configfile, filedetails.value.filecontent.value)
- filedetails = get_filedetails()
- else
- local errormessages = {}
- for x,y in pairs(config.value) do
- if y.errtxt then
- errormessages[#errormessages + 1] = y.label .. " - " .. y.errtxt
- end
- end
- filedetails.value.filecontent.errtxt = table.concat(errormessages, "\n")
- filedetails.errtxt = "Failed to set configuration"
- end
-
- return filedetails
+ return modelfunctions.setfiledetails(filedetails, {configfile}, validate_configfile)
end