From 9ae856d2dc847fbaa89ebb822b8c9c0abed88c17 Mon Sep 17 00:00:00 2001
From: Ted Trask
Date: Tue, 13 May 2008 20:02:56 +0000
Subject: Rewrote syslog to use components and remove view-specific code from
controller. Also made sure not to write to conf file unless all variables
pass validation.
git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@1116 ab2d0c66-481e-0410-8bed-d214d4d58bed
---
app/acf_www-controller.lua | 29 +++++++++++++++++++----------
lib/daemoncontrol.lua | 2 +-
lib/viewfunctions.lua | 32 +++++++++++++++++++++++++++-----
3 files changed, 47 insertions(+), 16 deletions(-)
diff --git a/app/acf_www-controller.lua b/app/acf_www-controller.lua
index bd99f8c..8f2a33f 100644
--- a/app/acf_www-controller.lua
+++ b/app/acf_www-controller.lua
@@ -60,7 +60,7 @@ local function build_menus(self)
end
-- This function is made available within the view to allow loading of components
-local dispatch_component = function(action, controller, prefix, clientdata)
+local dispatch_component = function(str, clientdata)
-- Before we call dispatch, we have to set up conf and clientdata like it was really called for this component
self = APP
local tempconf = self.conf
@@ -73,7 +73,10 @@ local dispatch_component = function(action, controller, prefix, clientdata)
self.clientdata = clientdata or {}
self.clientdata.sessionid = tempclientdata.sessionid
- self.dispatch(self, prefix or self.conf.prefix, controller or self.conf.controller, action or "")
+ local prefix, controller, action = self.parse_path_info("/" .. str)
+ if prefix == "/" then prefix = self.conf.prefix end
+ if controller == "" then controller = self.conf.controller end
+ self.dispatch(self, prefix, controller, action)
-- Revert to the old conf and clientdata
self.conf = nil
@@ -321,18 +324,22 @@ exception_handler = function (self, message )
if type(message) == "table" then
if message.type == "redir" and self.conf.component == true then
io.write ("Component cannot be found")
- elseif message.type == "redir" then
+ elseif message.type == "redir" or message.type == "redir_to_referrer" then
if sessiondata.id then logevent("Redirecting " .. sessiondata.id) end
io.write ("Status: 302 Moved\n")
- io.write ("Location: " .. ENV["SCRIPT_NAME"] ..
+ if message.type == "redir" then
+ io.write ("Location: " .. ENV["SCRIPT_NAME"] ..
message.prefix .. message.controller ..
"/" .. message.action ..
(message.extra or "" ) .. "\n")
- if self.sessiondata.id then
- io.write (html.cookie.set("sessionid", self.sessiondata.id))
- else
- io.write (html.cookie.unset("sessionid"))
- end
+ else
+ io.write ("Location: " .. ENV.HTTP_REFERER .. "\n")
+ end
+ if self.sessiondata.id then
+ io.write (html.cookie.set("sessionid", self.sessiondata.id))
+ else
+ io.write (html.cookie.unset("sessionid"))
+ end
io.write ( "Content-Type: text/html\n\n" )
elseif message.type == "dispatch" then
parent_exception_handler(self, message)
@@ -360,4 +367,6 @@ logevent = function ( message )
conf.logfile:write (string.format("%s: %s\n", os.date(), message))
end
-
+redirect_to_referrer = function(self)
+ error({type="redir_to_referrer"})
+end
diff --git a/lib/daemoncontrol.lua b/lib/daemoncontrol.lua
index 27564ef..db9423c 100644
--- a/lib/daemoncontrol.lua
+++ b/lib/daemoncontrol.lua
@@ -5,7 +5,7 @@ function daemoncontrol (process, action)
local cmdmessage = ""
if (string.lower(action) == "start") or (string.lower(action) == "stop") or (string.lower(action) == "restart") then
local file = io.popen( "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin /etc/init.d/" ..
- process .. " " .. action .. " 2>&1" )
+ process .. " " .. string.lower(action) .. " 2>&1" )
if file ~= nil then
cmdmessage = file:read( "*a" )
file:close()
diff --git a/lib/viewfunctions.lua b/lib/viewfunctions.lua
index 5080a34..bb6e6ec 100644
--- a/lib/viewfunctions.lua
+++ b/lib/viewfunctions.lua
@@ -75,7 +75,24 @@ function displaymanagement (myform,tags)
end
end
-function displayitem(myitem, viewtype)
+function displayitem(myitem)
+ if not myitem then return end
+ io.write("" .. myitem.label .. "\n")
+ io.write("")
+ io.write(myitem.value .. "\n")
+ if myitem.descr then io.write("" .. string.gsub(myitem.descr, "\n", "
") .. "
\n") end
+ if myitem.errtxt then io.write("" .. string.gsub(myitem.errtxt, "\n", "
") .. "
\n") end
+ io.write("\n")
+end
+
+function displayformitem(myitem, name, viewtype)
+ if not myitem then return end
+ if name then myitem.name = name end
io.write("" .. string.gsub(myitem.descr, "\n", "
") .. "
\n") end
if myitem.errtxt then io.write("" .. string.gsub(myitem.errtxt, "\n", "
") .. "
\n") end
@@ -113,6 +134,7 @@ function displayitem(myitem, viewtype)
end
function displayform(myform, order)
+ if not myform then return end
if myform.descr then io.write("" .. string.gsub(myform.descr, "\n", "
") .. "
\n") end
if myform.errtxt then io.write("" .. string.gsub(myform.errtxt, "\n", "
") .. "
\n") end
io.write('')
end
--
cgit v1.2.3