summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMika Havela <mika.havela@gmail.com>2008-01-23 14:31:44 +0000
committerMika Havela <mika.havela@gmail.com>2008-01-23 14:31:44 +0000
commitb6c2c25e5e99b6d8515a777a00f5a97c1f6b1d23 (patch)
tree8d38ec02518e736922c41961545d8123191641b0
parent8d5450a1ad2402c0e5b764a5e033cd9134dd4d23 (diff)
downloadacf-alpine-conf-b6c2c25e5e99b6d8515a777a00f5a97c1f6b1d23.tar.bz2
acf-alpine-conf-b6c2c25e5e99b6d8515a777a00f5a97c1f6b1d23.tar.xz
Forcing user to enter valid options in the config-tab before making a commit.
Displaying current errors in the config/settings. git-svn-id: svn://svn.alpinelinux.org/acf/alpine-conf/trunk@628 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r--lbu-commit-html.lsp10
-rw-r--r--lbu-config-html.lsp11
-rw-r--r--lbu-controller.lua33
-rw-r--r--lbu-model.lua30
-rw-r--r--lbu-status-html.lsp6
5 files changed, 66 insertions, 24 deletions
diff --git a/lbu-commit-html.lsp b/lbu-commit-html.lsp
index ffba7a4..f86bef1 100644
--- a/lbu-commit-html.lsp
+++ b/lbu-commit-html.lsp
@@ -12,7 +12,7 @@
<H2>PROGRAM SPECIFIC OPTIONS/INFORMATION</H2>
<dl>
<dt>Archives will be saved to</dt>
- <dd><?= view.status.LBU_MEDIA or "" ?></dd>
+ <dd><?= view.status.LBU_MEDIA or "<p class=error>No default - (Needs to be configured)</p>" ?></DD>
<dt>Archives will be encrypted</dt>
<dd><? if (view.status.ENCRYPTION) then io.write("yes <I>(Using cipher: " .. view.status.DEFAULT_CIPHER .. ")</I>") else io.write("No") end ?></DD>
</dl>
@@ -22,13 +22,15 @@
<H2>Save to media</h2>
<form name="cmd" action="" method="POST">
<dl>
- <dt>Remove existing apk.ovls from media</dt>
- <dd><input type="checkbox" class="checkbox" name="lbucleanmedia" >
-<p class=attention>Attention!</p><p>By checking this box, you remove all existing archives from the <?= view.status.LBU_MEDIA ?> when commiting (adding the '-d' flag to the commit action).<br>This needs to be done when you want/dont want to encrypt your archive and there already exists archives on the media.<BR>There can only be one sort of arcive on the media.</dd>
<dt>Simulate/Test a commit</dt>
<dd><input type=submit class="submit" name="lbusimulate" value="simulate" ></dd>
<dt>Actually Commit and save changes</dt>
<dd><input type=submit class="submit" name="lbucommit" value="commit" ></dd>
+<? if (view.cmderror) and (view.cmderror["-d"]) then ?>
+ <dt class=error>Remove existing apk.ovls from media</dt>
+ <dd><input type="checkbox" class="checkbox" name="lbucleanmedia" >
+<p>By checking this box, you remove all existing archives from the <?= view.status.LBU_MEDIA ?> when commiting (adding the '-d' flag to the commit action).<br>This needs to be done when you want/dont want to encrypt your archive and there already exists archives on the media.<BR>There can only be one sort of arcive on the media.</p><p>If you dont remove existing apk.ovls from media, your commit will most likely fail.</p></dd>
+<? end ?>
</dl>
</form>
diff --git a/lbu-config-html.lsp b/lbu-config-html.lsp
index 76233a7..9d9f872 100644
--- a/lbu-config-html.lsp
+++ b/lbu-config-html.lsp
@@ -14,14 +14,15 @@
<H2>Advanced config</H2>
<H3>Storage media</H3>
<dl>
- <dt>Default media for commit</dt>
+ <dt <? if (view.errors) and (view.errors.LBU_MEDIA) then io.write("class='error'") end ?>>Default media for commit</dt>
<dd><select name="LBU_MEDIA" size="1">
<? for i=1, table.maxn(view.config.LBU_MEDIA_LIST) do ?>
<option value="<?= view.config.LBU_MEDIA_LIST[i]["value"] ?>"
<? if (string.lower(view.config.LBU_MEDIA_LIST[i]["value"]) == string.lower(view.config.LBU_MEDIA or "")) then io.write("selected='selected'") end?>>
<?= view.config.LBU_MEDIA_LIST[i]["name"] ?></option>
<? end ?>
- </select></dd>
+ </select>
+ <p class=error><?= view.errors.LBU_MEDIA or "" ?></p></dd>
</dl>
<H3>Include/exclude list</H3>
@@ -60,8 +61,9 @@
<option value="<?= view.config.DEFAULT_CIPHER_LIST[i] ?>" <? if (string.lower(view.config.DEFAULT_CIPHER_LIST[i]) == string.lower(view.config.DEFAULT_CIPHER)) then io.write("selected='selected'") end?>><?= view.config.DEFAULT_CIPHER_LIST[i] ?></option>
<? end ?>
</select></dd>
- <dt>Password when encrypting</dt>
- <dd><input type="text" class="text" value="<?= view.config.PASSWORD or "" ?>" name="PASSWORD"></dd>
+ <dt <? if (view.errors) and (view.errors.PASSWORD) then io.write("class='error'") end ?>>Password when encrypting</dt>
+ <dd><input type="text" class="text" value="<?= view.config.PASSWORD or "" ?>" name="PASSWORD">
+ <p class=error><?= view.errors.PASSWORD or "" ?></p></dd>
</dl>
<H2>Save and apply above settings</H2>
@@ -79,4 +81,5 @@ io.write(debugs.variables(view))
?>
+
<? -- vim: set filetype=lua : ?>
diff --git a/lbu-controller.lua b/lbu-controller.lua
index c13bc5c..d8703e9 100644
--- a/lbu-controller.lua
+++ b/lbu-controller.lua
@@ -19,12 +19,15 @@ end
status = function (self)
local cmd = self.clientdata.cmd
local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller
- return ( {status = self.model:getstatus(),
+ local status, errors = self.model:getstatus()
+ return ( {status = status,
+ errors = errors,
lbustatus = self.model:list(),
url = url, } )
end
config = function (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")
@@ -50,30 +53,46 @@ config = function (self)
cmdresult = self.model:lbuincexcl("exclude", self.clientdata.item_add_exclude, "add")
end
-
+ -- This needs to be done /after/ the editing of the config (done earlier in this code)
+ local status,errors = self.model:getstatus()
local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller
- return ( {status = self.model:getstatus(),
+ return ( {status = status,
cmdresult = cmdresult,
+ errors = errors,
clientdata = self.clientdata,
config = self.model:getconfig(),
url = url, } )
end
function commit(self)
- local cmdresult
+ local cmdresult, cmderror
local url = ENV["SCRIPT_NAME"] .. 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 = self.model:getsimulate(cmdflag)
+ cmdresult, cmderror = self.model:getsimulate(cmdflag)
end
if (self.clientdata.lbucommit) then
- cmdresult = self.model:getcommit(cmdflag)
+ cmdresult, cmderror = self.model:getcommit(cmdflag)
+ 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()
+ end
+
+ local status, errors = self.model:getstatus()
+ if (errors.last) then
+ self.conf.action = "config"
+ self.conf.type = "redir"
+ return config(self)
end
- return ( {status = self.model:getstatus(),
+ return ( {status = status,
+ errors = errors,
cmdresult = cmdresult,
cmdflag = cmdflag,
+ cmderror = cmderror,
clientdata = self.clientdata,
url = url, } )
end
diff --git a/lbu-model.lua b/lbu-model.lua
index b0f5cf7..3b804ee 100644
--- a/lbu-model.lua
+++ b/lbu-model.lua
@@ -33,10 +33,18 @@ local function getLbuStatus()
end
local function getLbuCommit(flag)
+ local err = {}
+ local ret = ""
local f = io.popen("/sbin/lbu commit " .. flag .. " 2>&1", "r")
- local ret = f:read("*a")
+-- local ret = f:read("*a")
+ for line in f:lines() do
+ ret = ret .. line .. "\n"
+ --Look for error messages in output
+ local searchrow, search = string.match(line, "^(lbu.*(%-%a).*)")
+ if (search) then err[search] = searchrow end
+ end
f:close()
- return ret
+ return ret, err
end
local function getciphers()
@@ -83,6 +91,7 @@ end
function getstatus ()
local path = configfile
local status = {}
+ local errors = {}
local statustxt = nil
local lbustatus = list()
if (#lbustatus == 0) then
@@ -96,7 +105,16 @@ function getstatus ()
status["DEFAULT_CIPHER"] = config["DEFAULT_CIPHER"]
status["version"] = get_version()
status["status"] = statustxt
- return status
+ if (status["LBU_MEDIA"] == "") or (status["LBU_MEDIA"] == nil) then
+ errors["LBU_MEDIA"] = "'Media' needs to be configured!"
+ end
+ if (config["PASSWORD"] == nil) and (config["ENCRYPTION"] ~= nil) then
+ errors["PASSWORD"] = "Encryption without password is not allowed!<BR> Deactivate 'Password protection' or configure a password!"
+ end
+ for k,v in pairs(errors) do
+ errors["last"] = v
+ end
+ return status, errors
end
function list(self)
@@ -110,11 +128,13 @@ function list(self)
end
function getcommit(self, flag)
- if flag ~= "-d" then flag = "" end
+ --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)
- if flag ~= "-d" then flag = "" end
+ --See to that only allowed flags are passed to the process
+ flag = string.match(flag or "", "%-%a") or ""
return getLbuCommit("-n " .. flag)
end
diff --git a/lbu-status-html.lsp b/lbu-status-html.lsp
index 856a050..852bdb8 100644
--- a/lbu-status-html.lsp
+++ b/lbu-status-html.lsp
@@ -12,12 +12,10 @@
<H2>PROGRAM SPECIFIC OPTIONS/INFORMATION</H2>
<dl>
-<? if (view.status.LBU_MEDIA) then ?>
<dt>Archives will be saved to</dt>
- <dd><?= view.status.LBU_MEDIA ?></DD>
-<? end ?>
+ <dd><?= view.status.LBU_MEDIA or "No default" ?><? if (view.errors.LBU_MEDIA) then ?><p class=error><?= view.errors.LBU_MEDIA ?></p><? end ?></DD>
<dt>Archives will be encrypted</dt>
- <dd><? if (view.status.ENCRYPTION) then io.write("yes <I>(Using cipher: " ..view.status.DEFAULT_CIPHER .. ")</I>") else io.write("No") end ?></DD>
+ <dd><? if (view.status.ENCRYPTION) then io.write("yes <I>(Using cipher: " ..view.status.DEFAULT_CIPHER .. ")</I>") else io.write("No") end ?><? if (view.errors.PASSWORD) then ?><p class=error><?= view.errors.PASSWORD ?></p><? end ?></DD>
</dl>
<H2>CHANGES SINCE LAST COMMIT</H2>