summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMika Havela <mika.havela@gmail.com>2008-01-16 17:01:00 +0000
committerMika Havela <mika.havela@gmail.com>2008-01-16 17:01:00 +0000
commit773a0952af828389e84c4cc94f1bff15e4f7f09b (patch)
treee6faf2c97e84915c6b6a0204fd7b1c06a2bf25ad
parentf2ff77a050a092c3677746a31fe061477e2cc85d (diff)
downloadacf-alpine-conf-773a0952af828389e84c4cc94f1bff15e4f7f09b.tar.bz2
acf-alpine-conf-773a0952af828389e84c4cc94f1bff15e4f7f09b.tar.xz
Moving around things in LBU to get a grip on how it could look and work
git-svn-id: svn://svn.alpinelinux.org/acf/lbu/trunk@592 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r--lbu-config-html.lsp77
-rw-r--r--lbu-controller.lua85
-rw-r--r--lbu-html.lsp27
-rw-r--r--lbu-model.lua70
-rw-r--r--lbu-read-html.lsp25
-rw-r--r--lbu-status-html.lsp30
-rw-r--r--lbu.cfg11
7 files changed, 213 insertions, 112 deletions
diff --git a/lbu-config-html.lsp b/lbu-config-html.lsp
new file mode 100644
index 0000000..24ef5a1
--- /dev/null
+++ b/lbu-config-html.lsp
@@ -0,0 +1,77 @@
+<? local view = ... ?>
+
+<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>
+</dl>
+
+<H1>CONFIG</H1>
+<H2>Advanced config</H2>
+<H3>Storage media</H3>
+<dl>
+<dt>Default media for commit</dt>
+<dd><select name="LBU_MEDIA" size="1">
+<option value="">No default</option>
+<option value="floppy">floppy</option>
+<option value="usb">usb</option>
+</select></dd>
+</dl>
+
+<H3>Security/Encryption</H3>
+
+<dl>
+<dt>Password protected commits</dt>
+<dd><input type="checkbox" name="settings_startup"></dd>
+</dl>
+
+<dl>
+<dt>Cipher to use at encryption</dt>
+<dd><select name="hosts_list" size="1">
+<option value="">aes-256-cbc</option>
+</select>
+(For possible ciphers, try: openssl -v)</dd>
+</dl>
+
+<dl>
+<dt>Password when encrypting</dt>
+<dd><input type="text" class="text" name="settings_startup"></dd>
+</dl>
+
+<H2>Save and apply above settings</H2>
+<DL>
+<DT>Apply settings</DT>
+<DD><input class="submit" type="submit" value="Apply" disabled/></DD>
+</DL>
+
+<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
+require("debugs")
+io.write(debugs.variables(view))
+--]]
+?>
+
+<? -- vim: set filetype=lua : ?>
diff --git a/lbu-controller.lua b/lbu-controller.lua
index 51a0538..079bf4c 100644
--- a/lbu-controller.lua
+++ b/lbu-controller.lua
@@ -1,7 +1,7 @@
module(..., package.seeall)
local list_redir = function(self)
- self.conf.action = "read"
+ self.conf.action = "status"
self.conf.type = "redir"
error(self.conf)
end
@@ -16,9 +16,52 @@ mvc.on_load = function(self, parent)
end
end
--- Public methods
--- <prefix>/hostname/get
+status = function (self)
+ local cmd = self.clientdata.cmd
+ local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller
+ return ( {status = self.model:getstatus(),
+ lbustatus = self.model:list(),
+ url = url, } )
+end
+
+config = function (self)
+ local cmd = self.clientdata.cmd
+ local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller
+ return ( {status = self.model:getstatus(), 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,
+ }
+ end
+ end
+ ret.note=getNotes(self)
+ return ret
+end
+--]]
+--[[
local function getNotes(self)
ret = {}
for k,v in pairs(cfgfile.model:list(nil)) do
@@ -31,8 +74,9 @@ local function getNotes(self)
end
return ret
end
-
-read = function(self)
+--]]
+--[[
+xxxstatus = function(self)
return {
list=cfgfile.model:list(function(x) return x.app == "lbu" end),
script=ENV["SCRIPT_NAME"],
@@ -43,6 +87,9 @@ read = function(self)
}
end
+--]]
+
+--[[
update = function(self)
local id = tonumber(self.clientdata.id) or -1
local result
@@ -70,30 +117,4 @@ update = function(self)
extra = ""},
value = data}
end
-
-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,
- }
- end
- end
- ret.note=getNotes(self)
- return ret
-end
-
+--]]
diff --git a/lbu-html.lsp b/lbu-html.lsp
deleted file mode 100644
index 4ca2cbe..0000000
--- a/lbu-html.lsp
+++ /dev/null
@@ -1,27 +0,0 @@
-<? local form = ... ?>
-<h1>Edit <?= form.value.name.value?></h1>
-
-<?= html.form.start{
- method="POST",
- action= form.option.script .. "/" .. form.option.prefix
- .. form.option.controller .. "/" .. form.option.action ..
- form.option.extra } ?>
-
-<?
-local myform = form.value
-local tags = {
- { "content", "longtext" },
- { "cmd", "action" },
- { "id", "hidden" },
-}
-
-for i,v in pairs(tags) do
- local name = v[1]
- local val = myform[name]
- val.type = v[2]
- if val.name == "" then val.name = name end
-?>
-<?= html.form[val.type](val)?>
-<? end ?>
-<?= html.form.stop() ?>
-
diff --git a/lbu-model.lua b/lbu-model.lua
index 276ef85..8a362ce 100644
--- a/lbu-model.lua
+++ b/lbu-model.lua
@@ -1,30 +1,66 @@
module (..., package.seeall)
require "fs"
+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
- local status, name = string.match(line, "^(%S+)%s+(.+)$")
- if status and name then
- ret[string.gsub('/' .. name, "/+", "/")] = status
+ 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
- end
- f:close()
- return ret
+ f:close()
+ return ret
+end
+
+
+-- ################################################################################
+-- PUBLIC FUNCTIONS
+
+function getstatus ()
+ 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 loose your changes at next reboot/shutdown!)"
+ end
+ 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
- return ret
+ 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
+-- ################################################################################
+-- OLD FUNCTIONS
+
+--[[
function commit(self)
local f = io.popen("/sbin/lbu commit", 'r')
if not f then return false, "cannot run lbu" end
@@ -32,4 +68,4 @@ function commit(self)
f:close()
return true, ret
end
-
+--]]
diff --git a/lbu-read-html.lsp b/lbu-read-html.lsp
deleted file mode 100644
index bfd986a..0000000
--- a/lbu-read-html.lsp
+++ /dev/null
@@ -1,25 +0,0 @@
-<? local view = ... ?>
-
-<h1>LBU</h1>
-
-<h2>Settings</h2>
-<? for i,item in ipairs(view.note or {}) do ?>
- <p class='error'><?= item.content ?></p>
-<? end ?>
-
-<? for i,item in ipairs(view.list) do ?>
- <DT><?= item.descr or '' ?></DT>
- <DD><?= html.link{
- value = view.script .. view.prefix .. view.controller .. "/"
- .. view.action .. "?id=" .. tostring(item.id),
- label=item.name
- } ?></DD>
-<? end ?>
-
-<h2>Functions</h2>
-<DT>Commit changes</DT>
-<DD><?= html.link{
- value = view.script .. view.prefix .. view.controller .. "/commit",
- label="commit" } ?></DD>
-
-<? -- vim: set filetype=lua : ?>
diff --git a/lbu-status-html.lsp b/lbu-status-html.lsp
new file mode 100644
index 0000000..fad2b2a
--- /dev/null
+++ b/lbu-status-html.lsp
@@ -0,0 +1,30 @@
+<? local view = ... ?>
+
+<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>
+</dl>
+
+<H2>PROGRAM SPECIFIC OPTIONS/INFORMATION</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>
+</dl>
+
+<?
+--[[ DEBUG INFORMATION
+require("debugs")
+io.write(debugs.variables(view))
+--]]
+?>
+
+<? -- vim: set filetype=lua : ?>
diff --git a/lbu.cfg b/lbu.cfg
deleted file mode 100644
index fc22ed6..0000000
--- a/lbu.cfg
+++ /dev/null
@@ -1,11 +0,0 @@
--- /* vim: set filetype=lua : */
-{ app="lbu", section="general",
- name="include", filename="/etc/lbu/include",
- descr="Include list" },
-{ app="lbu", section="general",
- name="exclude", filename="/etc/lbu/exclude",
- descr="Exclude list" },
-{ app="lbu", section="general",
- name="packages", filename="/etc/lbu/packages.list",
- descr="Remembered list of installed packages" },
-