summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lbu-config-html.lsp1
-rw-r--r--lbu-controller.lua13
-rw-r--r--lbu-model.lua72
-rw-r--r--lbu.roles2
4 files changed, 86 insertions, 2 deletions
diff --git a/lbu-config-html.lsp b/lbu-config-html.lsp
index b8b10eb..6749785 100644
--- a/lbu-config-html.lsp
+++ b/lbu-config-html.lsp
@@ -22,5 +22,6 @@ io.write("</span>")
if viewlibrary and viewlibrary.dispatch_component then
viewlibrary.dispatch_component("editincluded")
viewlibrary.dispatch_component("editexcluded")
+ viewlibrary.dispatch_component("listbackups")
end
?>
diff --git a/lbu-controller.lua b/lbu-controller.lua
index 4a755fb..4072740 100644
--- a/lbu-controller.lua
+++ b/lbu-controller.lua
@@ -120,3 +120,16 @@ function expert (self)
return filedetails
end
+function listbackups(self)
+ return self.model.getbackupfiles()
+end
+
+function deletebackup(self)
+ self.model.deletebackupfile(self.clientdata.backup)
+ redirect_to_referrer(self)
+end
+
+function selectbackup(self)
+ self.model.selectbackupfile(self.clientdata.backup)
+ redirect_to_referrer(self)
+end
diff --git a/lbu-model.lua b/lbu-model.lua
index f5a40c0..81236eb 100644
--- a/lbu-model.lua
+++ b/lbu-model.lua
@@ -5,6 +5,7 @@ require("fs")
require("format")
require("getopts")
require("daemoncontrol")
+require("validator")
-- Set variables
local configfile = "/etc/lbu/lbu.conf"
@@ -107,6 +108,10 @@ local function validateconfig(config)
config.value.PASSWORD.errtxt = "Encryption without password is not allowed!\nDeactivate password protection or configure a password!"
end
+ if not validator.is_integer(config.value.BACKUP_LIMIT.value) then
+ config.value.BACKUP_LIMIT.errtxt = "Must be an integer"
+ end
+
for name,value in pairs(config.value) do
if value.errtxt then
config.errtxt = "Invalid Config"
@@ -163,7 +168,31 @@ local function validatefilecontent (filecontent)
return filecontent
end
-
+
+local was_mounted
+local mnt
+local function mount()
+ local configopts = getopts.getoptsfromfile(configfile, "") or {}
+ mnt = "/media/"..configopts.LBU_MEDIA
+ local f = io.popen("grep "..mnt.." /proc/mounts")
+ local cmdresult = f:read("*a")
+ f:close()
+ if cmdresult ~= "" then
+ was_mounted = true
+ else
+ local g = io.popen("mount "..mnt)
+ g:close()
+ was_mounted = false
+ end
+end
+
+local function unmount()
+ if not was_mounted then
+ local g = io.popen("umount "..mnt)
+ g:close()
+ end
+end
+
-- ################################################################################
-- PUBLIC FUNCTIONS
@@ -233,6 +262,11 @@ function getconfig (configcontents)
label="Password when encrypting",
})
+ config["BACKUP_LIMIT"] = cfe({
+ value=configopts.BACKUP_LIMIT or "0",
+ label="Backup archive limit",
+ })
+
retval = cfe({ type="group", value=config, label="LBU Config" })
validateconfig(retval)
@@ -254,6 +288,7 @@ function setconfig (config)
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 = replacestring(content, "#*BACKUP_LIMIT=[^\n]*\n", "BACKUP_LIMIT="..config.value.BACKUP_LIMIT.value.."\n")
content = string.gsub(content,"\n*$","")
-- Write changes to file
@@ -352,3 +387,38 @@ function commit(input)
return input
end
+
+function getbackupfiles()
+ mount()
+ local files = {}
+ local selected
+ local f = io.popen("ls "..mnt.."/*.[0-9]*[0-9].tar.gz")
+ for line in f:lines() do
+ files[#files + 1] = line
+ end
+ f:close()
+ if #files then
+ f = io.popen("date -u -r "..mnt.."/*.apkovl.tar.gz +%Y%m%d%H%m%S")
+ selected = string.match(files[1], "^[^.]*.") .. f:read("*l") .. ".tar.gz"
+ end
+ unmount()
+ return cfe({ type="list", value=files, label="Backup archive list", selected = selected })
+end
+
+function selectbackupfile(file)
+ mount()
+ if string.find(file, "^"..mnt) and fs.is_file(file) then
+ local f = io.popen("cp -p "..file.." "..string.match(file, "^[^.]*.").."apkovl.tar.gz")
+ f:close()
+ end
+ unmount()
+end
+
+function deletebackupfile(file)
+ mount()
+ if string.find(file, "^"..mnt) and fs.is_file(file) then
+ local f = io.popen("rm "..file)
+ f:close()
+ end
+ unmount()
+end
diff --git a/lbu.roles b/lbu.roles
index cc87af1..525df12 100644
--- a/lbu.roles
+++ b/lbu.roles
@@ -1,2 +1,2 @@
-UPDATE=lbu:config,lbu:commit,lbu:expert,lbu:editincluded,lbu:editexcluded
+UPDATE=lbu:config,lbu:commit,lbu:expert,lbu:editincluded,lbu:editexcluded,lbu:listbackups,lbu:deletebackup,lbu:selectbackup
ALL=lbu:basicstatus,lbu:status