From 3928babbc55caa5c8b3914fa0a4c26a916c0dbbb Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Tue, 22 Jan 2008 14:34:18 +0000 Subject: 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 --- lbu-commit-html.lsp | 85 +++++++++++++++++--------------- lbu-config-html.lsp | 137 ++++++++++++++++++---------------------------------- lbu-controller.lua | 104 ++++++++------------------------------- lbu-model.lua | 63 +++++++++++++++++++----- 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 @@ - + -

- 0) then ?> -

List

- - -

- - -
- +

SYSTEM INFO

+ +
+
Program status
+
+
Program version
+
+
+ +

PROGRAM SPECIFIC OPTIONS/INFORMATION

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

MANAGEMENT

-

Functions

-
Save these changes
-
- - -
- - -

- -
+

Save to media

+
+
+
Simulate/Test a commit
+
+
Actually Commit and save changes
+
+
+
+ + + + +
+ +
Result of previous action
+
- +
+ + + 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 @@

SYSTEM INFO

-
Program status
-
-
- -
-
Program version
-
+
Program status
+
+
Program version
+

CONFIG

@@ -17,107 +14,69 @@

Advanced config

Storage media

-
Default media for commit
-
+
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 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
+
+

Security/Encryption

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

Save and apply above settings

-
Apply settings
-
+
Apply settings
+
-

MANAGEMENT

- -
-
Commit and save changes
-
- -
-
- - -
-
Previous action result
-
-
- - - + 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 @@

SYSTEM INFO

-
Program status
-
-
- -
-
Program version
-
+
Program status
+
+
Program version
+

PROGRAM SPECIFIC OPTIONS/INFORMATION

-
-
Archives will be saved to
-
-
+ +
Archives will be saved to
+
- -
-
Archives will be encrypted
-
yes (Using cipher: )
-
+
Archives will be encrypted
+
yes (Using cipher: )
+ +

CHANGES SINCE LAST COMMIT

-
Files changed since last commit
-
+
Files changed since last commit
+