From 422d93b32eb1c30d9a684146d258ed01ab99a850 Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Thu, 14 Feb 2008 15:33:20 +0000 Subject: Rebuilt LBU so it uses cfe instead. git-svn-id: svn://svn.alpinelinux.org/acf/alpine-conf/trunk@719 ab2d0c66-481e-0410-8bed-d214d4d58bed --- lbu-model.lua | 179 ++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 142 insertions(+), 37 deletions(-) (limited to 'lbu-model.lua') diff --git a/lbu-model.lua b/lbu-model.lua index f38d34d..044d877 100644 --- a/lbu-model.lua +++ b/lbu-model.lua @@ -33,6 +33,10 @@ local function getLbuStatus() return ret end +local function availablemedias() + return {"floppy","usb"} +end + local function getLbuCommit(flag) local err = {} local ret = "" @@ -84,19 +88,35 @@ end function getstatus () local path = configfile local status = {} - local statustxt = nil + local statustxt + local descrtxt if (#list() == 0) then - statustxt = "OK! (There is no uncommited files)" + statustxt = "There is no uncommited files" else - statustxt = "WARNING! (Until you commit, you will lose your changes at next reboot/shutdown!)" + statustxt = "WARNING!" + descrtxt = "Until you commit, you will lose your changes at next reboot/shutdown!" end - local config, errors = getconfig() + local config = getconfig() + status["version"] = cfe({ + name="status", + value=get_version(), + label="Program version", + }) + + status["status"] = cfe({ + name="status", + value=statustxt, + descr=descrtxt, + label="Program status", + }) + status["LBU_MEDIA"] = config["LBU_MEDIA"] - status["ENCRYPTION"] = config["ENCRYPTION"] - status["DEFAULT_CIPHER"] = config["DEFAULT_CIPHER"] - status["version"] = get_version() - status["status"] = statustxt - return status, errors + if (config["ENCRYPTION"]["checked"]) then + status["ENCRYPTION"] = config["ENCRYPTION"] + status["ENCRYPTION"]["descr"] = "Using cipher '".. config.DEFAULT_CIPHER.value .. "' for encryption" + end + + return status end function list(self) @@ -123,32 +143,84 @@ end function getconfig () local path = configfile local config = {} + local configopts local errors = {} - local lbumedias = {} - table.insert(lbumedias, {name="floppy", value="floppy"}) - table.insert(lbumedias, {name="usb", value="usb"}) if (fs.is_file(path)) then - config = getopts.getoptsfromfile(path) or {} - end - config["lbu_included"]= getincexl("include") or {} - config["lbu_excluded"]= getincexl("exclude") or {} - config["LBU_MEDIA_LIST"]= lbumedias or {} - config["DEFAULT_CIPHER_LIST"]= getciphers() or {} - -- Next section is to set/show default values when a option is not configured in the configfile - config["LBU_MEDIA"] = config["LBU_MEDIA"] or "" - config["DEFAULT_CIPHER"] = config["DEFAULT_CIPHER"] or "" + configopts = getopts.getoptsfromfile_onperline(path) or {} + end + local lbumedias = availablemedias() + if not (configopts.LBU_MEDIA) then + local lbumessage = "No default" + table.insert(lbumedias, lbumessage) + config.LBU_MEDIA = lbumessage + else + config.LBU_MEDIA = configopts.LBU_MEDIA + end + config["debug"] = configopts + config["LBU_MEDIA"] = cfe({ + name="LBU_MEDIA", + value=config["LBU_MEDIA"], + label="Default media for commit", + type="select", + option=lbumedias, + }) + + config["lbu_included"]= cfe({ + name="lbu_included", + option=getincexl("include") or {}, + label="Included item(s)", + type="select", + size=table.maxn(getincexl("include"))+1, + }) + if (config["lbu_included"]["size"] == 1) then config["lbu_included"]["size"] = 2 end + + config["lbu_excluded"]= cfe({ + name="lbu_excluded", + option=getincexl("exclude") or {}, + label="Excluded item(s)", + type="select", + size=table.maxn(getincexl("exclude"))+1, + }) + if (config["lbu_excluded"]["size"] == 1) then config["lbu_excluded"]["size"] = 2 end + + config["ENCRYPTION"] = cfe({ + name="ENCRYPTION", + value="yes", + label="Password protected commits", + type="checkbox", + }) + if (configopts["ENCRYPTION"]) and (#configopts["ENCRYPTION"] ~= 0) then + config["ENCRYPTION"]["checked"] = "yes" + end + + config["DEFAULT_CIPHER"] = cfe({ + name="DEFAULT_CIPHER", + value=configopts["DEFAULT_CIPHER"], + label="Cipher to use at encryption", + option=getciphers() or {}, + type="select", + }) + + config["PASSWORD"] = cfe({ + name="PASSWORD", + value=configopts["PASSWORD"], + label="Password when encrypting", + }) + +---[[ + -- Next section is to print errormessages when configs are wrong - if (config["LBU_MEDIA"] == "") or (config["LBU_MEDIA"] == nil) then - errors["LBU_MEDIA"] = "'Media' needs to be configured!" + if (configopts["LBU_MEDIA"] == "") or (configopts["LBU_MEDIA"] == nil) then + config.LBU_MEDIA.errtxt = "'Media' needs to be configured!" end - if (config["PASSWORD"] == nil) and (config["ENCRYPTION"] ~= nil) then - errors["PASSWORD"] = "Encryption without password is not allowed!
Deactivate 'Password protection' or configure a password!" + if (configopts["PASSWORD"] == nil) and (configopts["ENCRYPTION"] ~= nil) then + config.PASSWORD.errtxt = "Encryption without password is not allowed!
Deactivate 'Password protection' or configure a password!" end for k,v in pairs(errors) do - errors["last"] = v + config["errors"] = v end - - return config, errors +--]] + return config end function lbuincexcl(self,state,value,addremove) @@ -166,7 +238,7 @@ function lbuincexcl(self,state,value,addremove) incexl = f:read("*a") f:close() else - return "Function setincexl() - Invalid command! Use include|exclude when calling this function!" + return "Function setincexl() - Invalid command! Use included|excluded when calling this function!" end return incexl end @@ -182,8 +254,21 @@ function editconfig (self,variable,value) if not (value) or (value == "") then deactivate = "#" end + if (variable == "LBU_MEDIA") then + local errtxt + local lbumedias = availablemedias() + for k,v in pairs(lbumedias) do + errtxt = "" + if (value == v) then break end + errtxt = "Not a valid media!" + end + if (#errtxt > 0) then + return errtxt + end + end + -- Hardcode some parameters (e.g for some checkboxes) - if (variable == "ENCRYPTION") then value = "$DEFAULT_CIPHER" end + if (variable == "ENCRYPTION") then value = "DEFAULT_CIPHER" end configfilecontent = fs.read_file_as_array(path) or {} -- Search if the variable is defined in the file for k,v in pairs(configfilecontent) do @@ -199,17 +284,37 @@ function editconfig (self,variable,value) end -- Write changes to file fs.write_file(path,table.concat(cmdoutput,"\n")) - return cmdoutput + return value 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) - end + local filestats = fs.stat(path) + filedetails.name = cfe ({ + name="name", + value=path, + label="File name" + }) + + filedetails.size = cfe ({ + name="size", + value=filestats.size or "0", + label="File size", + }) + + filedetails.mtime = cfe ({ + name="mtime", + value=filestats.mtime or "---", + label="File modified", + }) + + filedetails.modifications = cfe ({ + name="modifications", + value=fs.read_file(path), + label="File content", + type="longtext", + }) + return filedetails end function update_filecontent (self, modifications) -- cgit v1.2.3