summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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>