summaryrefslogtreecommitdiffstats
path: root/skins-model.lua
blob: 441298ed71651da49feb897a33c857ca4a731703 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
-- acf model for displaying logfiles recusivly 
module (..., package.seeall)

local function set_skins(skin)
	local cmd = "/bin/sed -i 's/skin=.*/skin=" .. skin .. "/' /etc/acf/acf.conf"
	local f, errtxt = io.popen(cmd)
	local cmdoutput = f:read("*a")
	if cmdoutput == "" then cmdoutput = "New skin selected" end
	f:close()
	return cmdoutput, errtxt
end

local function list_skins()
	local path = "/usr/share/acf/www/skins/"
	local skinarray = {}
	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(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
			entry.inuse = (file == current)
			table.insert(skinarray, entry)
		end
	end
	return cfe({ type="list", value=skinarray, label="Skins" })
end


get = function ()
	return list_skins()
end

update = function (newskin)
	-- Make sure no one can inject code into the model.
	local availableskins = list_skins()
	local cmdoutput = "Failed to set skin"
	local errtxt = "Invalid selection"
	for i,skin in ipairs(availableskins.value) do
		if ( skin.value == newskin) then
			cmdoutput, errtxt = set_skins(newskin)
		end
	end
	return cfe({ value=cmdoutput, errtxt=errtxt, label="Set skin result" })
end