diff options
author | Alexander Poslavsky <alexander.poslavsky@gmail.com> | 2007-11-02 13:08:51 +0000 |
---|---|---|
committer | Alexander Poslavsky <alexander.poslavsky@gmail.com> | 2007-11-02 13:08:51 +0000 |
commit | 1448b0049d94eb830c2e6ac17a6f1038f76de076 (patch) | |
tree | acc7f5090239bd28da98f0bb8fae2c4d48862365 | |
download | acf-alpine-conf-1448b0049d94eb830c2e6ac17a6f1038f76de076.tar.bz2 acf-alpine-conf-1448b0049d94eb830c2e6ac17a6f1038f76de076.tar.xz |
lbu acf module work-in-progress
git-svn-id: svn://svn.alpinelinux.org/acf/lbu/trunk@259 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r-- | Makefile | 53 | ||||
-rw-r--r-- | config.mk | 11 | ||||
-rw-r--r-- | lbu-commit-html.lsp | 52 | ||||
-rw-r--r-- | lbu-controller.lua | 99 | ||||
-rw-r--r-- | lbu-html.lsp | 41 | ||||
-rw-r--r-- | lbu-model.lua | 35 | ||||
-rw-r--r-- | lbu-read-html.lsp | 27 | ||||
-rw-r--r-- | lbu.cfg | 11 | ||||
-rw-r--r-- | lbu.menu | 2 |
9 files changed, 331 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f702d16 --- /dev/null +++ b/Makefile @@ -0,0 +1,53 @@ +APP_NAME=lbu +PACKAGE=acf-$(APP_NAME) +VERSION=0.1 + +APP_DIST=\ + lbu-commit-html.lsp \ + lbu-controller.lua \ + lbu-html.lsp \ + lbu-model.lsp \ + lbu-read-html.lsp \ + lbu.menu + +APP_CFG=\ + lbu.cfg + +EXTRA_DIST=Makefile config.mk + +DISTFILES=$(APP_DIST) $(EXTRA_DIST) + +TAR=tar + +P=$(PACKAGE)-$(VERSION) +tarball=$(P).tar.bz2 +install_dir=$(DESTDIR)/$(appdir)/$(APP_NAME) + +all: +clean: + rm -rf $(tarball) $(P) + +dist: $(tarball) + +install: + mkdir -p "$(install_dir)" + cp -a $(APP_DIST) "$(install_dir)" + mkdir -p "$(cfgdir)" + cp -a $(APP_CFG) "$(cfgdir)" + +$(tarball): $(DISTFILES) + rm -rf $(P) + mkdir -p $(P) + cp $(DISTFILES) $(P) + $(TAR) -jcf $@ $(P) + rm -rf $(P) + +# target that creates a tar package, unpacks is and install from package +dist-install: $(tarball) + $(TAR) -jxf $(tarball) + $(MAKE) -C $(P) install DESTDIR=$(DESTDIR) + rm -rf $(P) + +include config.mk + +.PHONY: all clean dist install dist-install diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..f67accc --- /dev/null +++ b/config.mk @@ -0,0 +1,11 @@ +prefix=/usr +datadir=${prefix}/share +sysconfdir=${prefix}/etc +localstatedir=${prefix}/var +acfdir=${datadir}/acf +wwwdir=${acfdir}/www +cgibindir=${acfdir}/cgi-bin +appdir=${acfdir}/app +cfgdir=${appdir}/cfgfile +acflibdir=${acfdir}/lib +sessionsdir=${localstatedir}/lib/acf/sessions diff --git a/lbu-commit-html.lsp b/lbu-commit-html.lsp new file mode 100644 index 0000000..c5e1ff2 --- /dev/null +++ b/lbu-commit-html.lsp @@ -0,0 +1,52 @@ +<? +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 + +--[[ +view + script, prefix, controller, action + data[] + name, + status + title + text[] + label + content +--]] +?><h1><?= view.title +?></h1><? + +--Status Block + for i,item in ipairs(view.note or {}) do + ?><p class='error'><?= item.content ?></p><? + end + +?><table><? +for i,item in ipairs(view.data) do + ?><tr><td><?= item.status ?><td><?= item.name ?><? +end +?></table><? +?><?= 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() ?><? +for i,item in ipairs(view.text) do + if item.label then + ?><h2><?= item.label ?></h2><? + end + ?><pre><?= item.content ?></pre><? +end +-- vim: set filetype=lua : +?> diff --git a/lbu-controller.lua b/lbu-controller.lua new file mode 100644 index 0000000..51a0538 --- /dev/null +++ b/lbu-controller.lua @@ -0,0 +1,99 @@ +module(..., package.seeall) + +local list_redir = function(self) + self.conf.action = "read" + self.conf.type = "redir" + error(self.conf) +end + +local cfgfile + +mvc={} +mvc.on_load = function(self, parent) + cfgfile = self:new("cfgfile") + if (self.worker[self.conf.action] == nil) or (self.conf.action == "init") then + self.worker[self.conf.action] = list_redir(self) + end +end + +-- Public methods +-- <prefix>/hostname/get + +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 + end + end + return ret +end + +read = 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), + } +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 + +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 new file mode 100644 index 0000000..efb1c38 --- /dev/null +++ b/lbu-html.lsp @@ -0,0 +1,41 @@ +<? +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 +} +?><table><? +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] + ?><tr><td><? +--[[ + if val.label then + io.write(val.label) + elseif val.type ~= "hidden" then + io.write(name) + end +--]] + ?></td><td><? + if val.name == "" then val.name = name end + if val.type == "longtext" then + val.cols = 80 + val.rows = 24 + end + ?><?= html.form[val.type](val) + ?></td></tr><? +end +?></table><?= html.form.stop() +?> + diff --git a/lbu-model.lua b/lbu-model.lua new file mode 100644 index 0000000..276ef85 --- /dev/null +++ b/lbu-model.lua @@ -0,0 +1,35 @@ +module (..., package.seeall) + +require "fs" + +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 + end + end + f:close() + return ret +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 +end + +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 + diff --git a/lbu-read-html.lsp b/lbu-read-html.lsp new file mode 100644 index 0000000..0ea1ec8 --- /dev/null +++ b/lbu-read-html.lsp @@ -0,0 +1,27 @@ +<? local view = ... ?> + +<h1>Edit</h1> + +<? --Status Block + for i,item in ipairs(view.note or {}) do + ?><p class='error'><?= item.content ?></p><? + end +?> + +<table border=0> +<? local sct="" +for i,item in ipairs(view.list) do + if item.section ~= sct then + ?><tr><td colspan='3'><h2><?= item.section ?></td></tr><? + sct = item.section + end + ?><tr><td><?= item.status or '' ?><? + ?><td><?= html.link{ + value = view.script .. view.prefix .. view.controller .. "/" + .. view.action .. "?id=" .. tostring(item.id), + label=item.name + } + ?></td><td><?= item.descr + ?></td></tr><? +end -- vim: set filetype=lua : ?> +</table> @@ -0,0 +1,11 @@ +-- /* 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" }, + diff --git a/lbu.menu b/lbu.menu new file mode 100644 index 0000000..01bd02b --- /dev/null +++ b/lbu.menu @@ -0,0 +1,2 @@ +System LBU Define read + |