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-commit-html.lsp | 91 +++++++++++++++----------- lbu-config-html.lsp | 136 +++++++++++++++++++-------------------- lbu-controller.lua | 114 ++++++++++++++++++++++++++++++--- lbu-expert-html.lsp | 83 ++++++++++++++++-------- lbu-model.lua | 179 +++++++++++++++++++++++++++++++++++++++++----------- lbu-status-html.lsp | 64 +++++++++++++------ 6 files changed, 472 insertions(+), 195 deletions(-) diff --git a/lbu-commit-html.lsp b/lbu-commit-html.lsp index f86bef1..a23b907 100644 --- a/lbu-commit-html.lsp +++ b/lbu-commit-html.lsp @@ -1,53 +1,72 @@ - - -

SYSTEM INFO

+ +DEBUGGING

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(form)) +io.write("
") +--]] +?> +") + for k,v in pairs(tags) do + if (myform[v]) and (myform[v]["value"]) then + local val = myform[v] + io.write("\t 0) then + val.class = "error" + io.write(" class='error'") + end + io.write(">" .. val.label .. "\n") + if (viewonly) then + io.write("\t\t
" .. val.value .. "\n") + else + io.write("\t\t
" .. html.form[val.type](val) .. "\n") + end + if (val.descr) and (#val.descr > 0) then io.write("\t\t

" .. string.gsub(val.descr, "\n", "
") .. "

\n") end + if (#val.errtxt > 0) then io.write("\t\t

" .. string.gsub(val.errtxt, "\n", "
") .. "

\n") end + io.write("\t\t
\n") + end + end + io.write("") +end +?> -
-
Program status
-
-
Program version
-
-
+

SYSTEM INFO

+

PROGRAM SPECIFIC OPTIONS/INFORMATION

-
-
Archives will be saved to
-
No default - (Needs to be configured)

" ?>
-
Archives will be encrypted
-
(Using cipher: " .. view.status.DEFAULT_CIPHER .. ")") else io.write("No") end ?>
-
+

MANAGEMENT

-

Save to media

-
-
Simulate/Test a commit
-
-
Actually Commit and save changes
-
- -
Remove existing apk.ovls from media
-
-

By checking this box, you remove all existing archives from the when commiting (adding the '-d' flag to the commit action).
This needs to be done when you want/dont want to encrypt your archive and there already exists archives on the media.
There can only be one sort of arcive on the media.

If you dont remove existing apk.ovls from media, your commit will most likely fail.

- -
+
- - - -
- +
+
Result of previous action
-
+
-
+
DEBUGGING

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(form)) +io.write("
") --]] ?> diff --git a/lbu-config-html.lsp b/lbu-config-html.lsp index 13e94c3..22c1405 100644 --- a/lbu-config-html.lsp +++ b/lbu-config-html.lsp @@ -1,85 +1,85 @@ - - -

SYSTEM INFO

+ +DEBUGGING

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(form)) +io.write("
") +--]] +?> +") + for k,v in pairs(tags) do + if (myform[v]) and (myform[v]["value"]) then + local val = myform[v] + io.write("\t 0) then + val.class = "error" + io.write(" class='error'") + end + io.write(">" .. val.label .. "\n") + if (viewonly) then + io.write("\t\t
" .. val.value .. "\n") + else + io.write("\t\t
" .. html.form[val.type](val) .. "\n") + end + if (val.descr) and (#val.descr > 0) then io.write("\t\t

" .. string.gsub(val.descr, "\n", "
") .. "

\n") end + if (#val.errtxt > 0) then io.write("\t\t

" .. string.gsub(val.errtxt, "\n", "
") .. "

\n") end + io.write("\t\t
\n") + end + end + io.write("") +end +?> -
-
Program status
-
-
Program version
-
-
+

SYSTEM INFO

+

CONFIG

Advanced config

Storage media

-
-
>Default media for commit
-
-

-
+ -

Include/exclude list

-
-
Included item(s)
-
-
Delete selected include-item
-
(see above)
-
Add item to inlude list
-
-
-
Excluded item(s)
-
-
Delete selected exclude-item
-
(see above)
-
Add item to exclude list
-
-
-
+

Included list

+ + +

Excluded list

+

Security/Encryption

-
-
Password protected commits
-
>
-
Cipher to use at encryption
-
-
>Password when encrypting
-
" name="PASSWORD"> -

-
+

Save and apply above settings

-
-
Apply settings
-
-
+ + +
DEBUGGING

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(form)) +io.write("
") --]] ?> - - diff --git a/lbu-controller.lua b/lbu-controller.lua index 04b729a..8dbaccb 100644 --- a/lbu-controller.lua +++ b/lbu-controller.lua @@ -42,22 +42,84 @@ config = function (self) cmdresult[var] = self.model:editconfig(var, self.clientdata[var], "change_value") end end - if (self.clientdata.cmd_add_include) and (self.clientdata.item_add_include) then - cmdresult = self.model:lbuincexcl("include", self.clientdata.item_add_include, "add") + 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_exclude) and (self.clientdata.item_add_exclude) then - cmdresult = self.model:lbuincexcl("exclude", self.clientdata.item_add_exclude, "add") + 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 + local config = self.model:getconfig() -- This needs to be done /after/ the editing of the config (done earlier in this code) - local status,errors = self.model:getstatus() + 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", + }) + + -- 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= "" + end + local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller return ( {status = status, cmdresult = cmdresult, errors = errors, clientdata = self.clientdata, - config = self.model:getconfig(), + config = config, url = url, } ) end @@ -79,13 +141,37 @@ function commit(self) end local status, errors = self.model:getstatus() - if (errors.last) then +--[[ if (errors.last) then self.conf.action = "config" self.conf.type = "redir" return config(self) end +--]] + -- 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 + return ( {status = status, - errors = errors, cmdresult = cmdresult, cmdflag = cmdflag, cmderror = cmderror, @@ -99,9 +185,19 @@ expert = function (self) 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", + }) + local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller - return { file = self.model:get_filedetails(), + return { + file = file, status = status, clientdata = self.clientdata, url = url, } diff --git a/lbu-expert-html.lsp b/lbu-expert-html.lsp index 29c3bdd..cea7e4c 100644 --- a/lbu-expert-html.lsp +++ b/lbu-expert-html.lsp @@ -1,45 +1,76 @@ - + +DEBUGGING

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(form)) +io.write("
") +--]] +?> -

SYSTEM INFO

+") + for k,v in pairs(tags) do + if (myform[v]) and (myform[v]["value"]) then + local val = myform[v] + io.write("\t 0) then + val.class = "error" + io.write(" class='error'") + end + io.write(">" .. val.label .. "\n") + if (viewonly) then + io.write("\t\t
" .. val.value .. "\n") + else + io.write("\t\t
" .. html.form[val.type](val) .. "\n") + end + if (val.descr) and (#val.descr > 0) then io.write("\t\t

" .. string.gsub(val.descr, "\n", "
") .. "

\n") end + if (#val.errtxt > 0) then io.write("\t\t

" .. string.gsub(val.errtxt, "\n", "
") .. "

\n") end + io.write("\t\t
\n") + end + end + io.write("") +end +?> -
-
Program status
-
+

SYSTEM INFO

+ -
Program version
-
-

CONFIGURATION

Expert config

File details

-
-
File name
-
- -
File size
-
+ -
Last modified
-
-

File content

-
- - +

Save and apply above settings

-
-
Apply settings
-
-
+ +
DEBUGGING

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(form)) +io.write("
") --]] ?> 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) diff --git a/lbu-status-html.lsp b/lbu-status-html.lsp index 852bdb8..99d1dbe 100644 --- a/lbu-status-html.lsp +++ b/lbu-status-html.lsp @@ -1,33 +1,59 @@ - - -

SYSTEM INFO

+ +DEBUGGING

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(form)) +io.write("
") +--]] +?> +") + for k,v in pairs(tags) do + if (myform[v]) and (myform[v]["value"]) then + local val = myform[v] + io.write("\t 0) then io.write(" class='error'") end + io.write(">" .. val.label .. "\n") + if (viewonly) then + io.write("\t\t
" .. val.value .. "\n") + else + io.write("\t\t
" .. html.form[val.type](val) .. "\n") + end + if (val.descr) and (#val.descr > 0) then io.write("\t\t

" .. string.gsub(val.descr, "\n", "
") .. "

\n") end + if (#val.errtxt > 0) then io.write("\t\t

" .. string.gsub(val.errtxt, "\n", "
") .. "

\n") end + io.write("\t\t
\n") + end + end + io.write("") +end +?> -
-
Program status
-
-
Program version
-
-
+

SYSTEM INFO

+

PROGRAM SPECIFIC OPTIONS/INFORMATION

- -
-
Archives will be saved to
-

-
Archives will be encrypted
-
(Using cipher: " ..view.status.DEFAULT_CIPHER .. ")") else io.write("No") end ?>

-
+

CHANGES SINCE LAST COMMIT

Files changed since last commit
-
+
+ DEBUGGING

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(form)) +io.write("
") --]] ?> -- cgit v1.2.3