diff options
author | Ted Trask <ttrask01@yahoo.com> | 2008-06-05 14:06:22 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2008-06-05 14:06:22 +0000 |
commit | ab9e94b01060564436b9ba4eef0a2ab1465e7b83 (patch) | |
tree | 3fde3c8f315e234c51867fe946f6a48eb526b247 | |
parent | dfcf164b909dc654e42820cce73baf8aeb54a26b (diff) | |
download | acf-alpine-conf-ab9e94b01060564436b9ba4eef0a2ab1465e7b83.tar.bz2 acf-alpine-conf-ab9e94b01060564436b9ba4eef0a2ab1465e7b83.tar.xz |
Updated lbu to use new cfe model and components
git-svn-id: svn://svn.alpinelinux.org/acf/alpine-conf/trunk@1197 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r-- | lbu-commit-html.lsp | 45 | ||||
-rw-r--r-- | lbu-config-html.lsp | 63 | ||||
-rw-r--r-- | lbu-controller.lua | 255 | ||||
-rw-r--r-- | lbu-expert-html.lsp | 50 | ||||
-rw-r--r-- | lbu-model.lua | 400 | ||||
-rw-r--r-- | lbu-status-html.lsp | 38 | ||||
-rw-r--r-- | lbu.menu | 1 | ||||
-rw-r--r-- | lbu.roles | 5 |
8 files changed, 344 insertions, 513 deletions
diff --git a/lbu-commit-html.lsp b/lbu-commit-html.lsp deleted file mode 100644 index 672873e..0000000 --- a/lbu-commit-html.lsp +++ /dev/null @@ -1,45 +0,0 @@ -<? local form = ... -require("viewfunctions") -?> -<? ---[[ DEBUG INFORMATION -io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>") -io.write(html.cfe_unpack(form)) -io.write("</span>") ---]] -?> - -<H1>SYSTEM INFO</H1> -<DL> -<? -local myform = form.status -local tags = { "status", "version", } -displayinfo(myform,tags,"viewonly") -?> -</DL> - -<H2>PROGRAM SPECIFIC OPTIONS/INFORMATION</H2> -<DL> -<? -local myform = form.status -local tags = { "LBU_MEDIA", "ENCRYPTION", } -displayinfo(myform,tags,"viewonly") -?> -</DL> - -<H1>MANAGEMENT</H1> -<H2>Save to media</h2> -<form name="cmd" action="" method="POST"> -<DL> -<? -local tags = { "lbusimulate", "lbucommit", "lbucleanmedia", } -displayinfo(myform,tags) -?> - -<? if (form.cmdresult) then ?> - <dt>Result of previous action</dt> - <dd><pre><?= form.cmdresult ?></pre></DD> -<? end ?> - -</DL> -</form> diff --git a/lbu-config-html.lsp b/lbu-config-html.lsp index d9e1491..b8b10eb 100644 --- a/lbu-config-html.lsp +++ b/lbu-config-html.lsp @@ -1,4 +1,4 @@ -<? local form = ... +<? local form, viewlibrary = ... require("viewfunctions") ?> <? @@ -9,57 +9,18 @@ io.write("</span>") --]] ?> -<H1>SYSTEM INFO</H1> -<DL> -<? -local myform = form.status -local tags = { "status", "version", } -displayinfo(myform,tags,"viewonly") -?> -</DL> - -<H1>CONFIG</H1> -<form name="config" action="" method="POST"> -<H2>Advanced config</H2> -<H3>Storage media</H3> -<DL> <? -local myform = form.config -local tags = { "LBU_MEDIA", } -displayinfo(myform,tags) -?> -</DL> - -<H3>Included list</H3> -<DL> -<? -local tags = { "lbu_included","cmd_delete_included", "item_add_included", "cmd_add_included", } -displayinfo(myform,tags) -?> -</DL> - -<H3>Excluded list</H3> -<DL> -<? -local tags = { "lbu_excluded","cmd_delete_excluded", "item_add_excluded", "cmd_add_excluded", } -displayinfo(myform,tags) -?> -</DL> - -<H3>Security/Encryption</H3> -<DL> -<? -local tags = { "ENCRYPTION", "DEFAULT_CIPHER", "PASSWORD", } -displayinfo(myform,tags) + if viewlibrary and viewlibrary.dispatch_component then + viewlibrary.dispatch_component("basicstatus") + end ?> -</DL> +<H1>Config</H1> +<? + local order = { "LBU_MEDIA", "ENCRYPTION", "DEFAULT_CIPHER", "PASSWORD" } + displayform(form, order) -<H2>Save and apply above settings</H2> -<DL> -<? -local tags = { "config_submit" } -displayinfo(myform,tags) + if viewlibrary and viewlibrary.dispatch_component then + viewlibrary.dispatch_component("editincluded") + viewlibrary.dispatch_component("editexcluded") + end ?> -</DL> - -</form> diff --git a/lbu-controller.lua b/lbu-controller.lua index a5b6256..1d5c22b 100644 --- a/lbu-controller.lua +++ b/lbu-controller.lua @@ -5,192 +5,117 @@ module(..., package.seeall) default_action = "status" +function basicstatus (self) + return self.model.getstatus() +end + function status (self) - local cmd = self.clientdata.cmd - local url = self.conf.script .. self.conf.prefix .. self.conf.controller - local status, errors = self.model:getstatus() - return ( {status = status, - errors = errors, - lbustatus = self.model:list(), - url = url, } ) + return self.model.list() end function config (self) - local errors = {} - local cmdresult - if (self.clientdata.cmd_delete_excluded) and (self.clientdata.lbu_excluded) then - cmdresult = self.model:lbuincexcl("exclude", self.clientdata.lbu_excluded, "remove") - end - if (self.clientdata.cmd_delete_included) and (self.clientdata.lbu_included) then - cmdresult = self.model:lbuincexcl("include", self.clientdata.lbu_included, "remove") - end - if (self.clientdata.config_submit) then - local variables="ENCRYPTION LBU_MEDIA DEFAULT_CIPHER PASSWORD" - cmdresult = {} - for var in string.gmatch(variables, "%S+") do - cmdresult[var] = self.model:editconfig(var, self.clientdata[var], "change_value") + local config = self.model.getconfig() + if self.clientdata.Save then + config.errtxt = nil + for name,value in pairs(config.value) do + value.errtxt = nil + if value.type == "boolean" then + value.value = (self.clientdata[name]~=nil) + else + value.value = self.clientdata[name] or value.value + end + end + config = self.model.setconfig(config) + if not config.errtxt then + config.descr = "Configuration Set" end end - if (self.clientdata.cmd_add_included) and (self.clientdata.item_add_included) then - cmdresult = self.model:lbuincexcl("include", self.clientdata.item_add_included, "add") - end - if (self.clientdata.cmd_add_excluded) and (self.clientdata.item_add_excluded) then - cmdresult = self.model:lbuincexcl("exclude", self.clientdata.item_add_excluded, "add") - end + config.type = "form" + config.option = "Save" + config.label = "Edit Config" - local config = self.model:getconfig() - -- This needs to be done /after/ the editing of the config (done earlier in this code) - local status = self.model:getstatus() - - -- Add submit and other buttons - config["cmd_delete_included"] = cfe({ - name="cmd_delete_included", - value="Delete", - label="Delete selected included-item", - type="submit", - descr="Mark a item in '" .. config.lbu_included.label .. "'-list before pressing [Delete]", - }) - - config["item_add_included"] = cfe({ - name="item_add_included", - label="Item to add to included-list", - }) - - config["cmd_add_included"] = cfe({ - name="cmd_add_included", - value="Add", - label="Add the item into the included-list", - type="submit", - descr="Enter a value in '" .. config.item_add_included.label .. "'-input before pressing [Add]", - }) - - config["cmd_delete_excluded"] = cfe({ - name="cmd_delete_excluded", - value="Delete", - label="Delete selected excluded-item", - type="submit", - descr="Mark a item in '" .. config.lbu_excluded.label .. "'-list before pressing [Delete]", - }) - - config["item_add_excluded"] = cfe({ - name="item_add_excluded", - label="Item to add to excluded-list", - }) - - config["cmd_add_excluded"] = cfe({ - name="cmd_add_excluded", - value="Add", - label="Add the item into the excluded-list", - type="submit", - descr="Enter a value in '" .. config.item_add_excluded.label .. "'-input before pressing [Add]", - }) - - config["config_submit"] = cfe({ - name="config_submit", - value="Apply", - label="Apply above settings", - type="submit", - }) - if (self.clientdata.config_submit) then - config.config_submit.descr="* Changes has been saved!" - end - - - -- Disable buttons/commands that is usable for som reason - if (config.lbu_included.option) and (#config.lbu_included.option == 0) then - config.cmd_delete_included.disabled= "yes" - config.cmd_delete_included.descr= "" - end - if (config.lbu_excluded.option) and (#config.lbu_excluded.option == 0) then - config.cmd_delete_excluded.disabled= "yes" - config.cmd_delete_excluded.descr= "" + return config +end + +function editincluded (self) + local errtxt, descr + local included = self.model.getincluded() + if self.clientdata.Save then + included.errtxt = nil + included.value = self.clientdata.included + included = self.model.setincluded(included) + if included.errtxt then + errtxt = "Failed to set included files" + else + descr = "Included files set" + redirect_to_referrer(self) + end end + return cfe({ type="form", value={included=included}, option="Save", label="Edit included files", errtxt=errtxt, descr=descr }) +end - local url = self.conf.script .. self.conf.prefix .. self.conf.controller - return ( {status = status, - cmdresult = cmdresult, - errors = errors, - clientdata = self.clientdata, - config = config, - url = url, } ) +function editexcluded (self) + local errtxt, descr + local excluded = self.model.getexcluded() + if self.clientdata.Save then + excluded.errtxt = nil + excluded.value = self.clientdata.excluded + excluded = self.model.setexcluded(excluded) + if excluded.errtxt then + errtxt = "Failed to set excluded files" + else + descr = "Excluded files set" + redirect_to_referrer(self) + end + end + + return cfe({ type="form", value={excluded=excluded}, option="Save", label="Edit excluded files", errtxt=errtxt, descr=descr }) end function commit(self) - local cmdresult, cmderror - local url = self.conf.script .. self.conf.prefix .. self.conf.controller - local cmdflag = nil - if (self.clientdata.lbucleanmedia) then cmdflag = "-d" else cmdflag = "" end - if (self.clientdata.lbusimulate) then - cmdresult, cmderror = self.model:getsimulate(cmdflag) - end - if (self.clientdata.lbucommit) then - cmdresult, cmderror = self.model:getcommit(cmdflag) + local comm = self.model.getcommit() + if self.clientdata.Commit then + comm.errtxt = nil + for name,value in pairs(comm.value) do + value.errtxt = nil + value.value = (self.clientdata[name]~=nil) + end + comm = self.model.commit(comm) + self.sessiondata.commitresult = cfe({ value=comm.descr or "", errtxt=comm.errtxt }) + redirect_to_referrer(self) end - -- If no clientdata then do a dryrun and see if it's going to work else report - if not (cmdresult) then - tmp_cmdresult, cmderror = self.model:getsimulate() + if self.sessiondata.commitresult then + comm.descr = self.sessiondata.commitresult.value + comm.errtxt = self.sessiondata.commitresult.errtxt + self.sessiondata.commitresult = nil end - local status, errors = self.model:getstatus() - - -- Add buttons - status["lbusimulate"] = cfe({ - name="lbusimulate", - value="Simulate", - label="Simulate/Test a commit", - type="submit", - }) - - status["lbucommit"] = cfe({ - name="lbucommit", - value="Commit", - label="Actually commit and save changes", - type="submit", - }) - - if (cmderror["-d"]) then - status["lbucleanmedia"] = cfe({ - name="lbucleanmedia", - value="lbucleanmedia", - label="Remove existing apk.ovls from media", - type="checkbox", - }) - end + comm.type = "form" + comm.option = "Commit" + comm.label = "Commit changes" - return ( {status = status, - cmdresult = cmdresult, - cmdflag = cmdflag, - cmderror = cmderror, - clientdata = self.clientdata, - url = url, } ) + return comm end + function expert (self) - local modifications = self.clientdata.filecontent or "" - if ( self.clientdata.cmdsave) then - modifications = self.model:update_filecontent(modifications) + local filedetails = self.model.get_filedetails() + if self.clientdata.Save then + filedetails.value.filecontent.errtxt = nil + filedetails.value.filecontent.value = self.clientdata.filecontent + filedetails.value.filecontent = self.model.set_filecontent(filedetails.value.filecontent) + if filedetails.value.filecontent.errtxt then + filedetails.errtxt = "Failed to save config" + else + filedetails.descr = "Saved config" + end end - local status = self.model.getstatus() - local file = self.model:get_filedetails() - -- Add submit and other buttons - file["cmdsave"] = cfe({ - name="cmdsave", - value="Apply", - label="Apply settings", - type="submit", - }) - if (self.clientdata.cmdsave) then - file.cmdsave.descr="* Changes has been saved!" - end - - local url = self.conf.script .. self.conf.prefix .. self.conf.controller - - return { - file = file, - status = status, - clientdata = self.clientdata, - url = url, } + filedetails.type = "form" + filedetails.option = "Save" + filedetails.label = "Edit config file" + + return filedetails end diff --git a/lbu-expert-html.lsp b/lbu-expert-html.lsp index ed87ade..04dfd45 100644 --- a/lbu-expert-html.lsp +++ b/lbu-expert-html.lsp @@ -1,4 +1,4 @@ -<? local form = ... +<? local form, viewlibrary = ... require("viewfunctions") ?> <? @@ -9,40 +9,28 @@ io.write("</span>") --]] ?> -<H1>SYSTEM INFO</H1> -<DL> -<? -local myform = form.status -local tags = { "status", "version", } -displayinfo(myform,tags,"viewonly") -?> -</DL> - - -<h1>CONFIGURATION</h1> -<form name="myform" action="" method="POST"> +<? if viewlibrary and viewlibrary.dispatch_component then + viewlibrary.dispatch_component("basicstatus") +end ?> -<H2>EXPERT CONFIGURATION</H2> -<H3>FILE DETAILS</H3> +<h1>Configuration</h1> +<H2>File Details</H2> <DL> -<? -local myform = form.file -local tags = { "filename", "filesize", "mtime", "sumerrors" } -displayinfo(myform,tags,"viewonly") +<? +displayitem(form.value.filename) +displayitem(form.value.filesize) +displayitem(form.value.mtime) ?> </DL> -<H3>FILE CONTENT</H3> -<? -io.write(html.form[myform.filecontent.type](myform.filecontent)) -?> +<H2>File Content</H2> +<? if form.descr then ?><P CLASS='descr'><?= string.gsub(form.descr, "\n", "<BR>") ?></P><? end ?> +<? if form.errtxt then ?><P CLASS='error'><?= string.gsub(form.errtxt, "\n", "<BR>") ?></P><? end ?> +<form action="" method="POST"> +<textarea name="filecontent"> +<?= form.value.filecontent.value ?> +</textarea> +<? if form.value.filecontent.errtxt then ?><P CLASS='error'><?= string.gsub(form.value.filecontent.errtxt, "\n", "<BR>") ?></P><? end ?> -<H2>Save and apply above settings</H2> -<DL> -<? -local myform = form.file -local tags = { "cmdsave", } -displayinfo(myform,tags) -?> -</DL> +<DL><DT><input class="submit" type="submit" name="<?= form.option ?>" value="<?= form.option ?>"></DT></DL> </form> diff --git a/lbu-model.lua b/lbu-model.lua index 62e008f..7a7ff1e 100644 --- a/lbu-model.lua +++ b/lbu-model.lua @@ -8,6 +8,8 @@ require("daemoncontrol") -- Set variables local configfile = "/etc/lbu/lbu.conf" +local includefile = "/etc/lbu/include" +local excludefile = "/etc/lbu/exclude" -- ################################################################################ -- LOCAL FUNCTIONS @@ -83,266 +85,270 @@ local function getincexl(state) return incexl end +local function validateconfig(config) + -- Set errormessages when configs are wrong + config.value.LBU_MEDIA.errtxt = "Invalid Media" + for i,media in ipairs(config.value.LBU_MEDIA.option) do + if media == config.value.LBU_MEDIA.value then + config.value.LBU_MEDIA.errtxt = nil + break + end + end + + config.value.DEFAULT_CIPHER.errtxt = "Invalid Cipher" + for i,cipher in ipairs(config.value.DEFAULT_CIPHER.option) do + if cipher == config.value.DEFAULT_CIPHER.value then + config.value.DEFAULT_CIPHER.errtxt = nil + break + end + end + + if config.value.PASSWORD.value == "" and config.value.ENCRYPTION.value then + config.value.PASSWORD.errtxt = "Encryption without password is not allowed!\nDeactivate password protection or configure a password!" + end + + for name,value in pairs(config.value) do + if value.errtxt then + config.errtxt = "Invalid Config" + break + end + end + + return config +end + +local function replacestring (string, find, replace) + local count + string,count = string.gsub(string, find, replace) + if 0 == count then + string = string .. replace + end + return string +end + +local function validatefilelist(filelist) + local errors = {} + local files = {} + for line in string.gmatch(format.dostounix(filelist.value).."\n", "([^\n]*)\n") do + if not string.match(line, "^%s*$") then + local glob = posix.glob("/"..line) + if not glob then + errors[#errors+1] = '"' .. tostring(line) .. '" not a valid file/directory' + files[#files+1] = line + else + for i,value in pairs(glob) do + files[#files+1] = string.gsub(value, "^/+", "") + end + end + end + end + filelist.value = table.concat(files, "\n") + if #errors ~= 0 then + filelist.errtxt = table.concat(errors, "\n") + end + return filelist +end + +local function validatefilecontent (filecontent) + local config = getconfig(filecontent.value) + local errors = {} + for name,value in pairs(config.value) do + if value.errtxt then + errors[#errors+1] = value.errtxt + end + end + if #errors > 0 then + filecontent.errtxt = table.concat(errors, "\n") + end + + return filecontent +end + -- ################################################################################ -- PUBLIC FUNCTIONS function getstatus () - local path = configfile local status = {} - local statustxt - local descrtxt - if (#list() == 0) then - statustxt = "There is no uncommited files" - else - statustxt = "WARNING!" - descrtxt = "Until you commit, you will lose your changes at next reboot/shutdown!" - end - local config = getconfig() status["version"] = cfe({ - name="status", value=get_version(), label="Program version", }) - status["status"] = cfe({ - name="status", - value=statustxt, + status["committed"] = cfe({ + type="boolean", + value=(#list().value==0), descr=descrtxt, label="Program status", }) - status["LBU_MEDIA"] = config["LBU_MEDIA"] - if (config["ENCRYPTION"]["checked"]) then - status["ENCRYPTION"] = config["ENCRYPTION"] - status["ENCRYPTION"]["descr"] = "Using cipher '".. config.DEFAULT_CIPHER.value .. "' for encryption" + local config = getconfig() + status["LBU_MEDIA"] = config.value.LBU_MEDIA + if (config.value.ENCRYPTION.value) then + status["DEFAULT_CIPHER"] = config.value.DEFAULT_CIPHER end - return status + return cfe({ type="group", value=status, label="LBU Status" }) end -function list(self) +function list() local ret = {} local lbuStatus = getLbuStatus() for k,v in pairs(lbuStatus) do ret[#ret + 1] = { name=k, status=v } end table.sort(ret, function(a,b) return (a.name < b.name) end) - return ret -end - -function getcommit(self, flag) - --See to that only allowed flags are passed to the process - flag = string.match(flag or "", "%-%a") or "" - return getLbuCommit("-v " .. flag) -end -function getsimulate(self, flag) - --See to that only allowed flags are passed to the process - flag = string.match(flag or "", "%-%a") or "" - return getLbuCommit("-n " .. flag) + return cfe({ type="structure", value=ret, label="List of changes" }) end -function getconfig () - local path = configfile +function getconfig (configcontents) local config = {} local configopts = {} - local errors = {} - if (fs.is_file(path)) then - configopts = getopts.getoptsfromfile(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 + if configcontents then + configopts = getopts.getoptsfromfile(configcontents, "") or {} + elseif (fs.is_file(configfile)) then + configopts = getopts.getoptsfromfile(configfile, "") or {} 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)", + value=configopts.LBU_MEDIA or "", + label="Media for commit", type="select", - size=table.maxn(getincexl("include"))+1, + option=availablemedias() or {}, }) - 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", + value=(configopts.ENCRYPTION ~= nil), label="Password protected commits", - type="checkbox", + type="boolean", }) - 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", + value=configopts.DEFAULT_CIPHER or "", + label="Cipher to use for encryption", option=getciphers() or {}, type="select", }) config["PASSWORD"] = cfe({ - name="PASSWORD", - value=configopts["PASSWORD"], + value=configopts.PASSWORD or "", label="Password when encrypting", }) - -- Next section is to print errormessages when configs are wrong - if (configopts["LBU_MEDIA"] == "") or (configopts["LBU_MEDIA"] == nil) then - config.LBU_MEDIA.errtxt = "'Media' needs to be configured!" - end - if (configopts["PASSWORD"] == nil) and (configopts["ENCRYPTION"] ~= nil) then - config.PASSWORD.errtxt = "Encryption without password is not allowed!<BR> Deactivate 'Password protection' or configure a password!" - end - for k,v in pairs(errors) do - config["errors"] = v + retval = cfe({ type="group", value=config, label="LBU Config" }) + validateconfig(retval) + + return retval +end + +function setconfig (config) + validateconfig(config) + + if not config.errtxt then + local content = (fs.read_file(configfile) or "").."\n" + + -- LBU_MEDIA, ENCRYPTION, DEFAULT_CIPHER, PASSWORD + content = replacestring(content, "#*LBU_MEDIA=[^\n]*\n", "LBU_MEDIA="..config.value.LBU_MEDIA.value.."\n") + local newstring = "ENCRYPTION=$DEFAULT_CIPHER\n" + if not config.value.ENCRYPTION.value then + newstring = "#" .. newstring + end + content = replacestring(content, "#*ENCRYPTION=[^\n]*\n", newstring) + content = replacestring(content, "#*DEFAULT_CIPHER=[^\n]*\n", "DEFAULT_CIPHER="..config.value.DEFAULT_CIPHER.value.."\n") + content = replacestring(content, "#*PASSWORD=[^\n]*\n", "PASSWORD="..config.value.PASSWORD.value.."\n") + content = string.gsub(content,"\n*$","") + + -- Write changes to file + fs.write_file(configfile,content) end return config end -function lbuincexcl(self,state,value,addremove) - local incexl = nil - if (string.lower(addremove or "") == "add") then - addremove = "" - elseif (string.lower(addremove or "") == "remove") then - addremove = "-r" - else - return "Function setincexl() - Invalid option! Use add|remove when calling this function!" - end - if (string.lower(state) == "include") or (string.lower(state) == "exclude") then - local f = io.popen("/sbin/lbu " .. string.lower(state) .. " " .. addremove .. " -v " .. value .." 2>&1", "r") - if not (f) then return incexl end - incexl = f:read("*a") - f:close() - else - return "Function setincexl() - Invalid command! Use included|excluded when calling this function!" - end - return incexl +function getincluded () + local included = cfe({ + value=fs.read_file(includefile) or "", + label="Included item(s)", + type="longtext", + descr="List one file/directory per line\nAssumes root directory, no leading '/' necessary", + }) + + validatefilelist(included) + + return included end -function editconfig (self,variable,value) - local configfilecontent = nil - local path = configfile - local cmdoutput = nil - if not (fs.is_file(path)) then - fs.write_file(path,"") - end - local deactivate = "" - 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 +function setincluded (included) + validatefilelist(included) + if not included.errtxt then + fs.write_file(includefile, included.value) end + return included +end - -- Hardcode some parameters (e.g for some checkboxes) - 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 - if (string.match(v,"^%s*%#*%s*" .. variable)) then - cmdoutput = format.search_replace(configfilecontent,"^%s*%#*%s*" .. variable .. ".*$", deactivate .. variable .. "=" .. value) - break - end - end - --If variable is not changed (didn't exist) then create a new row with this variable - if not (cmdoutput) then - cmdoutput = configfilecontent - table.insert(cmdoutput,deactivate .. variable .. "=" .. (value or "")) +function getexcluded () + local excluded = cfe({ + value=fs.read_file(excludefile) or "", + label="Excluded item(s)", + type="longtext", + descr="List one file/directory per line\nAssumes root directory, no leading '/' necessary", + }) + + validatefilelist(excluded) + + return excluded +end + +function setexcluded (excluded) + validatefilelist(excluded) + if not excluded.errtxt then + fs.write_file(excludefile, excluded.value) end - -- Write changes to file - fs.write_file(path,table.concat(cmdoutput,"\n")) - return value + return excluded end + function get_filedetails() - local path = configfile - local file = {} - local filedetails = {} - local config = {} - local filenameerrtxt - if (fs.is_file(path)) then - filedetails = fs.stat(path) - config = getconfig(path) + 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 - config = {} - config.filename = {} - config["filename"]["errtxt"]="Config file '".. path .. "' is missing!" + filename.errtxt = "File not found" end - file["filename"] = cfe({ - name="filename", - label="File name", - value=path, - errtxt=filenameerrtxt - }) - file["filesize"] = cfe({ - name="filesize", - label="File size", - value=filedetails.size or 0, - }) - file["mtime"] = cfe({ - name="mtime", - label="File date", - value=filedetails.mtime or "---", - }) - file["filecontent"] = cfe({ - type="longtext", - name="filecontent", - label="File content", - value=fs.read_file(path), - }) + return cfe({ type="group", value={filename=filename, filecontent=filecontent, filesize=filesize, mtime=mtime}, label="Config file details" }) +end - -- Sum all errors into one cfe - local sumerrors = "" - for k,v in pairs(config) do - if (config[k]) and (config[k]["errtxt"]) and (config[k]["errtxt"] ~= "") then - sumerrors = sumerrors .. config[k]["errtxt"] .. "\n" - end - end - if (sumerrors ~= "") then - file["sumerrors"] = cfe ({ - name="sumerrors", - label = "Configuration errors", - errtxt = string.match(sumerrors, "(.-)\n$"), - }) +function set_filecontent (filecontent) + filecontent.value = format.dostounix(filecontent.value) + validatefilecontent(filecontent) + if not filecontent.errtxt then + fs.write_file(configfile, filecontent.value) end - - return file + return filecontent end -function update_filecontent (self, modifications) - local path = configfile - local file_result,err = fs.write_file(path, format.dostounix(modifications)) - return file_result, err + +function getcommit() + local simulate = cfe({ type="boolean", value=false, label="Simulate a commit" }) + local delete = cfe({ type="boolean", value=false, label="Remove existing overlays on commit" }) + return cfe({ type="group", value={simulate=simulate, delete=delete}, label="Commit changes" }) end +function commit(input) + if input.value.simulate.value and input.value.delete.value then + input.errtxt = "Cannot delete overlays when simulating" + else + local flag = "-v" + if input.value.simulate.value then flag=flag.." -n" end + if input.value.delete.value then flag=flag.." -d" end + input.descr = getLbuCommit(flag) + end + + return input +end diff --git a/lbu-status-html.lsp b/lbu-status-html.lsp index eb1997b..afe0164 100644 --- a/lbu-status-html.lsp +++ b/lbu-status-html.lsp @@ -1,33 +1,31 @@ -<? local form = ... +<? local view, viewlibrary, pageinfo, session = ... require("viewfunctions") ?> <? --[[ DEBUG INFORMATION io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>") -io.write(html.cfe_unpack(form)) +io.write(html.cfe_unpack(view)) io.write("</span>") --]] ?> -<H1>SYSTEM INFO</H1> -<DL> -<? -local myform = form.status -local tags = { "status", "version", } -displayinfo(myform,tags,"viewonly") -?> -</DL> - -<H2>PROGRAM SPECIFIC OPTIONS/INFORMATION</H2> -<DL> -<? -local tags = { "LBU_MEDIA","ENCRYPTION", } -displayinfo(myform,tags,"viewonly") -?> -</DL> +<? if viewlibrary and viewlibrary.dispatch_component then + viewlibrary.dispatch_component("basicstatus") + if session.permissions.lbu.commit then + viewlibrary.dispatch_component("commit") + end +end ?> -<H2>CHANGES SINCE LAST COMMIT</H2> +<H1>Changes Since Last Commit</H1> <DL> <dt>Files changed since last commit</dt> - <dd><pre><? for i = 1, table.maxn(form.lbustatus) do io.write(form.lbustatus[i]["status"] .. "\t" .. form.lbustatus[i]["name"] .. "\n") end ?><? if (#form.lbustatus == 0) then io.write("None") end ?></pre></DD> + <dd><pre><? + if (#view.value == 0) then + io.write("None") + else + for i,file in pairs(view.value) do + io.write(file.status .. "\t" .. file.name .. "\n") + end + end + ?></pre></DD> </DL> @@ -1,5 +1,4 @@ #CAT GROUP/DESC TAB ACTION System 99Local_backups Status status -System 99Local_backups Commit commit System 99Local_backups Config config System 99Local_backups Expert expert @@ -1,3 +1,2 @@ -READ=lbu:status -UPDATE=lbu:config,lbu:commit,lbu:expert -ALL=lbu:status +UPDATE=lbu:config,lbu:commit,lbu:expert,lbu:editincluded,lbu:editexcluded +ALL=lbu:basicstatus,lbu:status |