diff options
author | Mika Havela <mika.havela@gmail.com> | 2008-01-22 14:34:18 +0000 |
---|---|---|
committer | Mika Havela <mika.havela@gmail.com> | 2008-01-22 14:34:18 +0000 |
commit | 3928babbc55caa5c8b3914fa0a4c26a916c0dbbb (patch) | |
tree | 68a15a0f87652886fbc504ceafd6c4ee728bea45 | |
parent | 7cf8d1ac44d78983252fc0279b955463c6dd68e6 (diff) | |
download | acf-alpine-conf-3928babbc55caa5c8b3914fa0a4c26a916c0dbbb.tar.bz2 acf-alpine-conf-3928babbc55caa5c8b3914fa0a4c26a916c0dbbb.tar.xz |
Now you can modify the configurations.
Committing and SimulatingCommit also works (still work in progress) Needs checks when creating encrypted archives.
git-svn-id: svn://svn.alpinelinux.org/acf/alpine-conf/trunk@626 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r-- | lbu-commit-html.lsp | 85 | ||||
-rw-r--r-- | lbu-config-html.lsp | 137 | ||||
-rw-r--r-- | lbu-controller.lua | 104 | ||||
-rw-r--r-- | lbu-model.lua | 63 | ||||
-rw-r--r-- | lbu-status-html.lsp | 31 |
5 files changed, 176 insertions, 244 deletions
diff --git a/lbu-commit-html.lsp b/lbu-commit-html.lsp index 1efc362..6164739 100644 --- a/lbu-commit-html.lsp +++ b/lbu-commit-html.lsp @@ -1,43 +1,48 @@ -<? -local view = ... - -local function packURL(script, prefix, controller, action, extra) - ret = script .. "/" .. prefix .. controller .. "/" .. action - sep = '?' - for k,v in pairs(extra) do - ret = ret .. sep .. k .. '=' .. v - sep = '&' - end - return ret -end -?> +<? local view = ... ?> -<h1><?= view.title?></h1> -<? if (table.maxn(view.data) > 0) then ?> - <h2>List</h2> -<? end ?> -<? for i,item in ipairs(view.note or {}) do ?> - <p class='error'><?= item.content ?></p> -<? end ?> -<? for i,item in ipairs(view.data) do ?> - <dt><?= item.name ?></dt><dd><?= item.status ?></dd> -<? end ?> +<h1>SYSTEM INFO</h1> + +<dl> + <dt>Program status</dt> + <dd><?= view.status.status or "" ?></dd> + <dt>Program version</dt> + <dd><?= view.status.version ?></dd> +</dl> + +<H2>PROGRAM SPECIFIC OPTIONS/INFORMATION</H2> +<dl> + <dt>Archives will be saved to</dt> + <dd><?= view.status.LBU_MEDIA or "" ?></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> + +<H1>MANAGEMENT</H1> -<h2>Functions</h2> -<dt>Save these changes</dt> -<dd><?= html.form.start { - method="POST", - action = packURL(view.script, view.prefix, - view.controller, view.action, {}) - }?> -<?= html.form.submit { name = view.action, value = view.action }?> -<?= html.form.stop() ?> -</dd> - -<? for i,item in ipairs(view.text) do - if item.label then ?> - <h2><?= item.label ?></h2> - <? end ?> - <pre><?= item.content ?></pre> +<H2>Save to media</h2> +<form name="cmd" action="" method="POST"> +<dl> + <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> +</dl> +</form> + + + + +<dl> +<? if (view.cmdresult) then ?> + <dt>Result of previous action</dt> + <dd><pre><?= view.cmdresult ?></pre></DD> <? end ?> -<? -- vim: set filetype=lua : ?> +</dl> + +<? +--[[ DEBUG INFORMATION +require("debugs") +io.write(debugs.variables(view)) +--]] +?> + diff --git a/lbu-config-html.lsp b/lbu-config-html.lsp index f0a07ea..76233a7 100644 --- a/lbu-config-html.lsp +++ b/lbu-config-html.lsp @@ -3,13 +3,10 @@ <h1>SYSTEM INFO</h1> <dl> -<dt>Program status</dt> -<dd><?= view.status.status or "" ?></dd> -</dl> - -<dl> -<dt>Program version</dt> -<dd><?= view.status.version ?></dd> + <dt>Program status</dt> + <dd><?= view.status.status or "" ?></dd> + <dt>Program version</dt> + <dd><?= view.status.version ?></dd> </dl> <H1>CONFIG</H1> @@ -17,107 +14,69 @@ <H2>Advanced config</H2> <H3>Storage media</H3> <dl> -<dt>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)) then io.write("selected='selected'") end?>> -<?= view.config.LBU_MEDIA_LIST[i]["name"] ?></option> -<? end ?> -</select></dd> + <dt>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> </dl> <H3>Include/exclude list</H3> <dl> -<dt>Included item(s)</dt> -<dd><select name="lbu_included" size="3"> -<? for i=1, table.maxn(view.config.lbu_included or {}) do ?> -<option value="<?= view.config.lbu_included[i] ?>"><?= view.config.lbu_included[i] ?></option> -<? end ?> -</select></dd> -</dl> - -<dl> -<dt>Delete selected include-item</dt> -<dd><input name="cmd_delete_included" class="submit" type="submit" value="Delete" > (see above)</dd> -</dl> - -<dl> -<dt>Add item to inlude list</dt> -<dd><input type="text" name="item_add_include" class="text" value=""> -<input name="cmd_add_include" class="submit" type="submit" value="Add"></dd> -</dl> - -<dl> -<dt>Excluded item(s)</dt> -<dd><select name="lbu_excluded" size="3"> -<? for i=1, table.maxn(view.config.lbu_excluded or {}) do ?> -<option value="<?= view.config.lbu_excluded[i] ?>"><?= view.config.lbu_excluded[i] ?></option> -<? end ?> -</select></dd> -</dl> - -<dl> -<dt>Delete selected exclude-item</dt> -<dd><input name="cmd_delete_excluded" class="submit" type="submit" value="Delete" > (see above)</dd> -</dl> - -<dl> -<dt>Add item to exclude list</dt> -<dd><input type="text" name="item_add_exclude" class="text" value=""> -<input name="cmd_add_exclude" class="submit" type="submit" value="Add"></dd> + <dt>Included item(s)</dt> + <dd><select name="lbu_included" size="3"> + <? for i=1, table.maxn(view.config.lbu_included or {}) do ?> + <option value="<?= view.config.lbu_included[i] ?>"><?= view.config.lbu_included[i] ?></option> + <? end ?> + </select></dd> + <dt>Delete selected include-item</dt> + <dd><input name="cmd_delete_included" class="submit" type="submit" value="Delete" > (see above)</dd> + <dt>Add item to inlude list</dt> + <dd><input type="text" name="item_add_include" class="text" value=""> + <input name="cmd_add_include" class="submit" type="submit" value="Add"></dd> + <dt>Excluded item(s)</dt> + <dd><select name="lbu_excluded" size="3"> + <? for i=1, table.maxn(view.config.lbu_excluded or {}) do ?> + <option value="<?= view.config.lbu_excluded[i] ?>"><?= view.config.lbu_excluded[i] ?></option> + <? end ?> + </select></dd> + <dt>Delete selected exclude-item</dt> + <dd><input name="cmd_delete_excluded" class="submit" type="submit" value="Delete" > (see above)</dd> + <dt>Add item to exclude list</dt> + <dd><input type="text" name="item_add_exclude" class="text" value=""> + <input name="cmd_add_exclude" class="submit" type="submit" value="Add"></dd> </dl> <H3>Security/Encryption</H3> - -<dl> -<dt>Password protected commits</dt> -<dd><input type="checkbox" name="ENCRYPTION" <? if (view.config.ENCRYPTION) then io.write("checked=yes") end ?>></dd> -</dl> - <dl> -<dt>Cipher to use at encryption</dt> -<dd><select name="DEFAULT_CIPHER" size="1"> -<? for i=1, table.maxn(view.config.DEFAULT_CIPHER_LIST) do ?> -<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> -</dl> - -<dl> -<dt>Password when encrypting</dt> -<dd><input type="text" class="text" value="<?= view.config.PASSWORD or "" ?>" name="PASSWORD"></dd> + <dt>Password protected commits</dt> + <dd><input type="checkbox" name="ENCRYPTION" <? if (view.config.ENCRYPTION) then io.write("checked=yes") end ?>></dd> + <dt>Cipher to use at encryption</dt> + <dd><select name="DEFAULT_CIPHER" size="1"> + <? for i=1, table.maxn(view.config.DEFAULT_CIPHER_LIST) do ?> + <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> </dl> <H2>Save and apply above settings</H2> <DL> -<DT>Apply settings</DT> -<DD><input class="submit" name="config_submit" type="submit" value="Apply" disabled /></DD> + <DT>Apply settings</DT> + <DD><input class="submit" name="config_submit" type="submit" value="Apply" /></DD> </DL> </form> -<H1>MANAGEMENT</H1> - -<dl> -<dt>Commit and save changes</dt> -<dd><form name="cmd" action="" method="POST"> -<input type=submit class="submit" name="cmd" value="commit" disabled> -</form></dd> -</dl> - -<? if (view.startstop) and (view.startstop.cmdresult) then ?> -<dl> -<dt>Previous action result</dt> -<dd><pre><?= view.startstop.cmdresult?></pre></dd> -</dl> -<? end ?> - - <? ----[[ DEBUG INFORMATION +--[[ DEBUG INFORMATION require("debugs") io.write(debugs.variables(view)) --]] ?> + <? -- vim: set filetype=lua : ?> diff --git a/lbu-controller.lua b/lbu-controller.lua index e6fa4f4..bd08d1d 100644 --- a/lbu-controller.lua +++ b/lbu-controller.lua @@ -25,6 +25,7 @@ status = function (self) end config = function (self) + 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 @@ -32,7 +33,15 @@ config = function (self) cmdresult = self.model:lbuincexcl("include", self.clientdata.lbu_included, "remove") end if (self.clientdata.config_submit) then - cmdresult = self.model:editconfig(self.clientdata) + local variables="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") + end + local variables="ENCRYPTION" + for var in string.gmatch(variables, "%S+") do + cmdresult[var] = self.model:editconfig(var, self.clientdata[var], "change_state") + 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") @@ -51,91 +60,18 @@ config = function (self) url = url, } ) end --- ################################################################################ --- OLD FUNCTIONS - ---[[ function commit(self) - local ret = { - script=ENV["SCRIPT_NAME"], - prefix=self.conf.prefix, - controller = self.conf.controller, - action="commit", - data={}, - title="LBU", - text={}, - } - if self.clientdata.commit then - local result, report = self.model:commit() - local label = result and "Report" or "Error" - ret.text[#ret.text + 1] = { label=label, content=report } - else - for i,v in ipairs(self.model:list(nil)) do - ret.data[#ret.data + 1] = { - status = v.status, - name = v.name, - } + local cmdresult + local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller + if (self.clientdata.lbusimulate) then + cmdresult = self.model:getsimulate() end - end - ret.note=getNotes(self) - return ret -end ---]] - ---[[ -local function getNotes(self) - ret = {} - for k,v in pairs(cfgfile.model:list(nil)) do - if v.status then - ret[#ret + 1] = { - content = "There are some configuration changes. Please do not forget to save." - } - break + if (self.clientdata.lbucommit) then + cmdresult = self.model:getcommit() end - end - return ret -end ---]] ---[[ -xxxstatus = function(self) - return { - list=cfgfile.model:list(function(x) return x.app == "lbu" end), - script=ENV["SCRIPT_NAME"], - prefix=self.conf.prefix, - controller=self.conf.controller, - action="update", - note=getNotes(self), - } + return ( {status = self.model:getstatus(), + cmdresult = cmdresult, + clientdata = self.clientdata, + url = url, } ) end ---]] - ---[[ -update = function(self) - local id = tonumber(self.clientdata.id) or -1 - local result - local data - - result, data = cfgfile.model:get(id) - if not result then return list_redir(self) end - - if self.clientdata.cmd then - for k,v in pairs (data) do - if self.clientdata[k] then - data[k].value = self.clientdata[k] - end - end - result, data = cfgfile.model:set(id, data) - if result then return list_redir(self) end - end - - data.cmd = cfe { type="action", value="save", label="action" } - return cfe{ type="form", - option={ script=ENV["SCRIPT_NAME"], - prefix=self.conf.prefix, - controller = self.conf.controller, - action = "update", - extra = ""}, - value = data} -end ---]] diff --git a/lbu-model.lua b/lbu-model.lua index c3d20c4..e239496 100644 --- a/lbu-model.lua +++ b/lbu-model.lua @@ -1,6 +1,7 @@ module (..., package.seeall) require("fs") +require("format") require("getopts") local configfile = "/etc/lbu/lbu.conf" @@ -17,7 +18,7 @@ end local function getLbuStatus() local ret = {} - local f = io.popen("/sbin/lbu status -v", "r") + local f = io.popen("/sbin/lbu status -v 2>&1", "r") if not (f) then return ret end for line in f:lines() do if (string.match(line, "^Include files")) then break end @@ -31,6 +32,13 @@ local function getLbuStatus() return ret end +local function getLbuCommit(flag) + local f = io.popen("/sbin/lbu commit " .. flag .. " 2>&1", "r") + local ret = f:read("*a") + f:close() + return ret +end + local function getciphers() local opensslciphers = {} local watchdog = nil @@ -61,6 +69,14 @@ local function getincexl(state) return incexl end +local function checkexistens(file,variable) + local filecontent = fs.read_file_as_array(file) + for k,v in ipairs(filecontent) do + return v + end + return nil +end + -- ################################################################################ -- PUBLIC FUNCTIONS @@ -93,6 +109,13 @@ function list(self) return ret end +function getcommit() + return getLbuCommit("-v") +end +function getsimulate() + return getLbuCommit("-n") +end + function getconfig () local path = configfile local config = {} @@ -111,7 +134,6 @@ end function lbuincexcl(self,state,value,addremove) local incexl = nil --- local addremove if (string.lower(addremove or "") == "add") then addremove = "" elseif (string.lower(addremove or "") == "remove") then @@ -129,15 +151,30 @@ function lbuincexcl(self,state,value,addremove) end return incexl end --- ################################################################################ --- OLD FUNCTIONS - ---[[ -function commit(self) - local f = io.popen("/sbin/lbu commit", 'r') - if not f then return false, "cannot run lbu" end - local ret = f:read("*a") - f:close() - return true, ret + +function editconfig (self,variable,value,state) + local configfilecontent = nil + local path = configfile + local cmdoutput = {} + if (state == "change_value" ) then + configfilecontent = fs.read_file_as_array(configfile) + if not (value) or (value == "") then + cmdoutput = format.search_replace(configfilecontent,"^%s*%#*%s*" .. variable, "#" .. variable) + else + cmdoutput = format.search_replace(configfilecontent,"^%s*%#*%s*" .. variable .. ".*$", variable .. "=" .. value) + end + fs.write_file(configfile,table.concat(cmdoutput,"\n")) + elseif (state == "change_state" ) then + configfilecontent = fs.read_file_as_array(configfile) + if not (value) or (value == "") then + cmdoutput = format.search_replace(configfilecontent,"^%s*%#*%s*" .. variable, "#" .. variable) + else + cmdoutput = format.search_replace(configfilecontent,"^%s*%#*%s*" .. variable, variable) + end + fs.write_file(configfile,table.concat(cmdoutput,"\n")) + else + return "Function ediconfig() - Wrong usage of this function! usage editconfig(variable,value,state)\nvariable=Name of the variable\nvalue=The new value (when adding)\nstate=change_value|change_state depending on if you want to add some value or remove some variable." + end + return cmdoutput end ---]] + diff --git a/lbu-status-html.lsp b/lbu-status-html.lsp index b7cd769..796212b 100644 --- a/lbu-status-html.lsp +++ b/lbu-status-html.lsp @@ -3,34 +3,29 @@ <h1>SYSTEM INFO</h1> <dl> -<dt>Program status</dt> -<dd><?= view.status.status or "" ?></dd> -</dl> - -<dl> -<dt>Program version</dt> -<dd><?= view.status.version ?></dd> + <dt>Program status</dt> + <dd><?= view.status.status or "" ?></dd> + <dt>Program version</dt> + <dd><?= view.status.version ?></dd> </dl> <H2>PROGRAM SPECIFIC OPTIONS/INFORMATION</H2> -<? if (view.status.LBU_MEDIA) then ?> <dl> -<dt>Archives will be saved to</dt> -<dd><?= view.status.LBU_MEDIA ?></DD> -</dl> +<? if (view.status.LBU_MEDIA) then ?> + <dt>Archives will be saved to</dt> + <dd><?= view.status.LBU_MEDIA ?></DD> <? end ?> - <? if (view.status.ENCRYPTION) then ?> -<dl> -<dt>Archives will be encrypted</dt> -<dd>yes <I>(Using cipher: <?= view.status.DEFAULT_CIPHER or "unknown" ?>)</I></DD> -</dl> + <dt>Archives will be encrypted</dt> + <dd>yes <I>(Using cipher: <?= view.status.DEFAULT_CIPHER or "unknown" ?>)</I></DD> <? end ?> +</dl> +<H2>CHANGES SINCE LAST COMMIT</H2> <dl> -<dt>Files changed since last commit</dt> -<dd><pre><? for i = 1, table.maxn(view.lbustatus) do io.write(view.lbustatus[i]["status"] .. "\t" .. view.lbustatus[i]["name"] .. "\n") end ?></pre></DD> + <dt>Files changed since last commit</dt> + <dd><pre><? for i = 1, table.maxn(view.lbustatus) do io.write(view.lbustatus[i]["status"] .. "\t" .. view.lbustatus[i]["name"] .. "\n") end ?></pre></DD> </dl> <? |