-- acf model for displaying logfiles recusivly module (..., package.seeall) require("format") local function set_skins(skin) local cmd = "/bin/sed -i 's/skin=.*/skin=" .. format.escapespecialcharacters(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