summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2008-11-17 19:47:28 +0000
committerTed Trask <ttrask01@yahoo.com>2008-11-17 19:47:28 +0000
commit6a6e0c812beafc4a2b6304c8b17fae317035a898 (patch)
treef320e6826e3677597b517ba2cbdae9c3f71e2793
parent63c4b0abf1bfb922d6497a816108c35b971a1d2d (diff)
downloadacf-core-release-0.4.12.tar.bz2
acf-core-release-0.4.12.tar.xz
Modified mvc to create a stack of self pointers as controllers are created. Modelfunctions write_file_with_audit uses the stack to find self for auditing.release-0.4.12
git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@1595 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r--lib/modelfunctions.lua105
-rwxr-xr-xwww/cgi-bin/mvc.lua14
2 files changed, 75 insertions, 44 deletions
diff --git a/lib/modelfunctions.lua b/lib/modelfunctions.lua
index 57897ad..ed92abd 100644
--- a/lib/modelfunctions.lua
+++ b/lib/modelfunctions.lua
@@ -107,9 +107,7 @@ function setfiledetails(filedetails, validatefilename, validatefiledetails)
end
if success then
--fs.write_file(filedetails.value.filename.value, filedetails.value.filecontent.value)
- -- NBA - FIXME? we pass the global "APP" to write_file_with_audit because it needs self
- -- is that correct? Is there a better way to do it?
- write_file_with_audit( APP, filedetails.value.filename.value, filedetails.value.filecontent.value)
+ write_file_with_audit(filedetails.value.filename.value, filedetails.value.filecontent.value)
filedetails = getfiledetails(filedetails.value.filename.value)
else
filedetails.errtxt = "Failed to set file"
@@ -142,53 +140,72 @@ function validatemulti(multi)
return true
end
-
function write_file_with_audit (self, path, str)
- local pre = ""
- local post = ""
- local tmpfile = (self.conf.sessiondir or "/tmp/") ..
- (self.sessiondata.userinfo.userid or "unknown") .. "-" ..
- os.time() .. ".tmp"
-
- if type(self.conf) == "table" then
- -- we make temporary globals for expand_bash_syntax_vars
- local a,b,c = TEMPFILE,CONFFILE,_G.self
- TEMPFILE=tmpfile
- CONFFILE=path
- _G.self=self
-
- pre = self.conf.audit_precommit or ""
- post = self.conf.audit_postcommit or ""
-
- local m = self.conf.app_hooks[self.conf.controller] or {}
- if m.audit_precommit then pre = m.audit_precommit end
- if m.audit_postcommit then post = m.audit_postcommit end
- m=nil
-
- if (type(pre) == "string") then
- pre = format.expand_bash_syntax_vars(pre)
- end
- if type (post) == "string" then
- post = format.expand_bash_syntax_vars(post)
+ -- if there are only two parameters, assume self was omitted
+ if not str then
+ str = path
+ path = self
+ self = nil
+ end
+ -- attempt to find self
+ if not self then
+ if SELF and #SELF > 0 then
+ self = SELF[#SELF]
+ elseif APP then
+ self = APP
end
- TEMPFILE,CONFFILE,_G.self = a,b,c
end
- fs.write_file(tmpfile,str)
-
- if (type(pre) == "string" and #pre) then
- os.execute(pre)
- elseif (type(pre) == "function") then
- pre(self, path, tmpfile)
- end
+ if self then
+ local pre = ""
+ local post = ""
+
+ local tmpfile = (self.conf.sessiondir or "/tmp/") ..
+ (self.sessiondata.userinfo.userid or "unknown") .. "-" ..
+ os.time() .. ".tmp"
- os.rename (tmpfile, path)
+ if type(self.conf) == "table" then
+ -- we make temporary globals for expand_bash_syntax_vars
+ local a,b,c = TEMPFILE,CONFFILE,_G.self
+ TEMPFILE=tmpfile
+ CONFFILE=path
+ _G.self=self
+
+ pre = self.conf.audit_precommit or ""
+ post = self.conf.audit_postcommit or ""
+
+ local m = self.conf.app_hooks[self.conf.controller] or {}
+ if m.audit_precommit then pre = m.audit_precommit end
+ if m.audit_postcommit then post = m.audit_postcommit end
+ m=nil
+
+ if (type(pre) == "string") then
+ pre = format.expand_bash_syntax_vars(pre)
+ end
+ if type (post) == "string" then
+ post = format.expand_bash_syntax_vars(post)
+ end
+ TEMPFILE,CONFFILE,_G.self = a,b,c
+ end
+
+ fs.write_file(tmpfile,str)
+
+ if (type(pre) == "string" and #pre) then
+ os.execute(pre)
+ elseif (type(pre) == "function") then
+ pre(self, path, tmpfile)
+ end
+
+ os.rename (tmpfile, path)
- if (type(post) == "string" and #post) then
- os.execute(post)
- elseif (type(post) == "function") then
- post(self, path, tmpfile)
+ if (type(post) == "string" and #post) then
+ os.execute(post)
+ elseif (type(post) == "function") then
+ post(self, path, tmpfile)
+ end
+ else
+ fs.write_file(path,str)
end
- return
+ return
end
diff --git a/www/cgi-bin/mvc.lua b/www/cgi-bin/mvc.lua
index 4ded73d..a36878c 100755
--- a/www/cgi-bin/mvc.lua
+++ b/www/cgi-bin/mvc.lua
@@ -93,6 +93,10 @@ new = function (self, modname)
c.worker.mvc.on_load = nil
end
+ -- save the new self on the SELF stack
+ if not SELF then SELF = {} end
+ SELF[#SELF + 1] = c
+
return c, worker_loaded, model_loaded
end
@@ -101,6 +105,16 @@ destroy = function (self)
self.worker.mvc.on_unload(self)
self.worker.mvc.on_unload = nil
end
+
+ -- remove the self from the SELF stack (should be at the end, but just in case)
+ if SELF then
+ for i,s in ipairs(SELF) do
+ if s == self then
+ table.remove(SELF, i)
+ break
+ end
+ end
+ end
end
-- This is a sample front controller/dispatch.