summaryrefslogtreecommitdiffstats
path: root/lbu-model.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lbu-model.lua')
-rw-r--r--lbu-model.lua48
1 files changed, 20 insertions, 28 deletions
diff --git a/lbu-model.lua b/lbu-model.lua
index 3ae6c87..0ff1b96 100644
--- a/lbu-model.lua
+++ b/lbu-model.lua
@@ -1,10 +1,10 @@
module (..., package.seeall)
-- Load libraries
+require("modelfunctions")
require("fs")
require("format")
require("getopts")
-require("daemoncontrol")
require("validator")
-- Set variables
@@ -308,13 +308,15 @@ function getincluded ()
validatefilelist(included)
- return included
+ return cfe({ type="group", value={included = included} })
end
function setincluded (included)
- validatefilelist(included)
- if not included.errtxt then
- fs.write_file(includefile, included.value)
+ validatefilelist(included.value.included)
+ if not included.value.included.errtxt then
+ fs.write_file(includefile, included.value.included.value)
+ else
+ included.errtxt = "Failed to set included"
end
return included
end
@@ -329,44 +331,34 @@ function getexcluded ()
validatefilelist(excluded)
- return excluded
+ return cfe({ type="group", value={excluded = excluded} })
end
function setexcluded (excluded)
- validatefilelist(excluded)
- if not excluded.errtxt then
- fs.write_file(excludefile, excluded.value)
+ validatefilelist(excluded.value.excluded)
+ if not excluded.value.excluded.errtxt then
+ fs.write_file(excludefile, excluded.value.excluded.value)
+ else
+ excluded.errtxt = "Failed to set excluded"
end
return excluded
end
function get_filedetails()
- local filename = cfe({ value=configfile, label="File name" })
- local filecontent = cfe({ type="longtext", label="Config file" })
- local filesize = cfe({ value="0", label="File size" })
- local mtime = cfe({ value="---", label="File date" })
-
- if fs.is_file(configfile) then
- local filedetails = fs.stat(configfile)
- filecontent.value = fs.read_file(configfile)
- filesize.value = filedetails.size
- mtime.value = filedetails.mtime
-
- validatefilecontent(filecontent)
- else
- filename.errtxt = "File not found"
- end
-
- return cfe({ type="group", value={filename=filename, filecontent=filecontent, filesize=filesize, mtime=mtime}, label="Config file details" })
+ return modelfunctions.getfiledetails(configfile)
end
-function set_filecontent (filecontent)
+function set_filedetails(filedetails)
+ local filecontent = filedetails.value.filecontent
filecontent.value = format.dostounix(filecontent.value)
+ filecontent.value = filecontent.value:gsub("\n+$", "")
validatefilecontent(filecontent)
if not filecontent.errtxt then
fs.write_file(configfile, filecontent.value)
+ else
+ filedetails.errtxt = "Failed to set config"
end
- return filecontent
+ return filedetails
end
function getcommit()