summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2008-06-02 19:27:56 +0000
committerTed Trask <ttrask01@yahoo.com>2008-06-02 19:27:56 +0000
commitaed2d1a213fa8366a72e65a2f56e031df4b843f4 (patch)
tree40776f5898306019c36533d25ad11c7de446f30f
parent1ad185d3004918e3fabf86f4c752093ff369ea81 (diff)
downloadacf-alpine-baselayout-aed2d1a213fa8366a72e65a2f56e031df4b843f4.tar.bz2
acf-alpine-baselayout-aed2d1a213fa8366a72e65a2f56e031df4b843f4.tar.xz
Modified skins to use cfe's more properly.
git-svn-id: svn://svn.alpinelinux.org/acf/alpine-baselayout/trunk@1194 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r--skins-controller.lua5
-rw-r--r--skins-model.lua41
-rw-r--r--skins-read-html.lsp10
3 files changed, 23 insertions, 33 deletions
diff --git a/skins-controller.lua b/skins-controller.lua
index a07d141..ee4ff9c 100644
--- a/skins-controller.lua
+++ b/skins-controller.lua
@@ -5,13 +5,12 @@ module (..., package.seeall)
default_action = "read"
read = function (self )
- return ({skin = self.model:get(), url = self.conf.script .. self.conf.prefix .. self.conf.controller} )
+ return self.model.get()
end
update = function (self )
local newskin = self.clientdata.skin or ""
- local updated = self.model:update(newskin)
+ local updated = self.model.update(newskin)
redirect(self)
--- return ({skin = self.model:get(), updated=self.model:update(newskin), url = self.conf.script .. self.conf.prefix .. self.conf.controller} )
end
diff --git a/skins-model.lua b/skins-model.lua
index ad323a6..e637023 100644
--- a/skins-model.lua
+++ b/skins-model.lua
@@ -1,49 +1,40 @@
-- acf model for displaying logfiles recusivly
module (..., package.seeall)
--- no initializer in model - use controller.init for that
-
local function set_skins(skin)
- cmdtxt = "/bin/sed -i 's/skin=.*/skin=" .. skin .. "/' /etc/acf/acf.conf"
- local cmd, error = io.popen ( cmdtxt )
- local cmdoutput = cmd:read("*a")
- cmd:close()
- return cmdtxt
+ local cmd = "/bin/sed -i 's/skin=.*/skin=" .. skin .. "/' /etc/acf/acf.conf"
+ local f, errtxt = io.popen(cmd)
+ local cmdoutput = f:read("*a")
+ f:close()
+ return cfe({ value=cmdoutput, errtxt=errtxt, label="Set skin result" })
end
local function list_skins()
local path = "/usr/share/acf/www/skins/"
local skinarray = {}
- local skins = {}
- local k,v
- for k,v in pairs(posix.dir(path) or {}) do
+ for i,file in ipairs(posix.dir(path) or {}) do
-- Ignore files that begins with a '.' and 'cgi-bin' and only list folders
- if not ((string.match(v, "^%.")) or (string.match(v, "^cgi[-]bin")) or (string.match(v, "^static")) or (posix.stat(path .. v).type ~= "directory")) then
- local f = v
+ if not ((string.match(file, "^%.")) or (string.match(file, "^cgi[-]bin")) or (string.match(file, "^static")) or (posix.stat(path .. file).type ~= "directory")) then
+ local entry = cfe({ value=file, label="Skin name" })
local current = conf.skin
- if (current == f) then
- table.insert(skinarray, {name=f, inuse="In use"})
- else
- table.insert(skinarray, {name=f})
- end
+ entry.inuse = (file == current)
+ table.insert(skinarray, entry)
end
end
- return skinarray
+ return cfe({ type="list", value=skinarray, label="Skins" })
end
-get = function (self)
+get = function ()
return list_skins()
end
-update = function (self,skin)
+update = function (newskin)
-- Make sure no one can inject code into the model.
local availableskins = list_skins()
- for i = 1 , table.maxn(availableskins) do
- if ( availableskins[i].name == skin) and (skin ~= nil) then
- return set_skins(skin)
+ for i,skin in ipairs(availableskins.value) do
+ if ( skin.value == newskin) then
+ return set_skins(newskin)
end
end
end
-
-
diff --git a/skins-read-html.lsp b/skins-read-html.lsp
index 6cca742..78f19d7 100644
--- a/skins-read-html.lsp
+++ b/skins-read-html.lsp
@@ -4,12 +4,12 @@
<h1>Available skins</h1>
<DL>
-<? for i = 1, table.maxn(view.skin) do ?>
- <dt><?= view.skin[i].name ?></dt>
- <? if (view.skin[i].inuse) then ?>
- <dd><?= view.skin[i].inuse ?></dd>
+<? for i,skin in ipairs(view.value) do ?>
+ <dt><?= skin.value ?></dt>
+ <? if (skin.inuse) then ?>
+ <dd>in use</dd>
<? else ?>
- <dd>[<a href="update?skin=<?= view.skin[i].name ?>">use this skin</a>]</dd>
+ <dd>[<a href="update?skin=<?= skin.value ?>">use this skin</a>]</dd>
<? end ?>
<? end ?>
</DL>