module (..., package.seeall) require("fs") require("getopts") local configfile = "/etc/lbu/lbu.conf" -- ################################################################################ -- LOCAL FUNCTIONS local function get_version () local f,error = io.popen("/sbin/lbu 2>&1") local programversion = f:read("*l") f:close() return programversion end local function getLbuStatus() local ret = {} local f = io.popen("/sbin/lbu status -v", "r") if not (f) then return ret end for line in f:lines() do if (string.match(line, "^Include files")) then break end if (string.match(line, "^Exclude files")) then break end local status, name = string.match(line, "^(%S+)%s+(.+)$") if (status) and (name) then ret[string.gsub('/' .. name, "/+", "/")] = status end end f:close() return ret end local function getciphers() local opensslciphers = {} local watchdog = nil local f = io.popen("/usr/bin/openssl -v 2>&1", "r") if not (f) then return ciphers end for line in f:lines() do if (watchdog) then for cipher in string.gmatch(line, "(%S+)") do table.insert(opensslciphers,tostring(cipher)) end end if (string.match(line, "^Cipher commands")) then watchdog="yes" end end f:close() return opensslciphers end local function getincexl(state) local incexl = {} if (string.lower(state) == "include") or (string.lower(state) == "exclude") then local f = io.popen("/sbin/lbu " .. state .. " -l 2>&1", "r") if not (f) then return ciphers end for line in f:lines() do table.insert(incexl,tostring(line)) end f:close() end return incexl end -- ################################################################################ -- PUBLIC FUNCTIONS function getstatus () local path = configfile local status = {} local statustxt = nil local lbustatus = list() if (#lbustatus == 0) then statustxt = "OK! (There is no uncommited files)" else statustxt = "WARNING! (Until you commit, you will lose your changes at next reboot/shutdown!)" end local config = getopts.getoptsfromfile(path) 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 end function list(self) local ret = {} local lbuStatus = getLbuStatus() for k,v in pairs(lbuStatus) do ret[#ret + 1] = { name=k, status=v } end table.sort(ret, function(a,b) return (a.name < b.name) end) return ret end function getconfig () local path = configfile local config = {} local lbumedias = {} table.insert(lbumedias, {name="No default", value=""}) table.insert(lbumedias, {name="floppy", value="floppy"}) table.insert(lbumedias, {name="usb", value="usb"}) config = getopts.getoptsfromfile(path) config["lbu_included"]= getincexl("include") config["lbu_excluded"]= getincexl("exclude") config["LBU_MEDIA_LIST"]= lbumedias config["DEFAULT_CIPHER_LIST"]= getciphers() -- config["debug"] = getciphers() return config 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 end --]]