summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2008-07-02 15:56:04 +0000
committerTed Trask <ttrask01@yahoo.com>2008-07-02 15:56:04 +0000
commit997b4dcd33463841aa8f1ca6d59dea7bc9d38ae9 (patch)
tree31555c8bdf9da14b96e146569b4c5dab3138d6f6
parent9a0afb466ef66b0d27fd12652c3fe198d4fcfe6d (diff)
downloadacf-core-997b4dcd33463841aa8f1ca6d59dea7bc9d38ae9.tar.bz2
acf-core-997b4dcd33463841aa8f1ca6d59dea7bc9d38ae9.tar.xz
Modified core to create model and controller function libraries and some common html views. Moved cfe to a library. Modified redirect_to_referrer function - may break some pages.
git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@1267 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r--app/Makefile4
-rw-r--r--app/acf_cli-controller.lua15
-rw-r--r--app/acf_www-controller.lua30
-rw-r--r--app/expert-html.lsp15
-rw-r--r--app/filedetails-html.lsp25
-rw-r--r--app/startstop-html.lsp23
-rw-r--r--app/status-html.lsp12
-rw-r--r--lib/Makefile4
-rw-r--r--lib/cfe.lua15
-rw-r--r--lib/controllerfunctions.lua51
-rw-r--r--lib/modelfunctions.lua62
11 files changed, 227 insertions, 29 deletions
diff --git a/app/Makefile b/app/Makefile
index ef25865..6a3664f 100644
--- a/app/Makefile
+++ b/app/Makefile
@@ -27,6 +27,10 @@ APP_DIST= \
welcome-html.lsp\
dispatcherror-html.lsp\
exception-html.lsp\
+ status-html.lsp\
+ startstop-html.lsp\
+ filedetails-html.lsp\
+ expert-html.lsp\
EXTRA_DIST=README Makefile
DISTFILES=$(APP_DIST) $(EXTRA_DIST)
diff --git a/app/acf_cli-controller.lua b/app/acf_cli-controller.lua
index dad6b85..672af25 100644
--- a/app/acf_cli-controller.lua
+++ b/app/acf_cli-controller.lua
@@ -16,6 +16,7 @@ mvc.on_load = function (self, parent)
-- this sets the package path for us and our children
package.path= self.conf.libdir .. "?.lua;" .. package.path
+ require ("cfe")
self.session = {}
local x=require("session")
@@ -38,20 +39,6 @@ exception_handler = function (self, message )
print(message)
end
--- create a Configuration Framework Entity (cfe)
--- returns a table with at least "value", "type", and "label"
-cfe = function ( optiontable )
- optiontable = optiontable or {}
- me = { value="",
- type="text",
- label="" }
- for key,value in pairs(optiontable) do
- me[key] = value
- end
- return me
-end
-
-
-- syslog something
logit = function ( ... )
os.execute ( "logger \"" .. ... .. "\"" )
diff --git a/app/acf_www-controller.lua b/app/acf_www-controller.lua
index 55f529f..6b1bc6e 100644
--- a/app/acf_www-controller.lua
+++ b/app/acf_www-controller.lua
@@ -234,6 +234,7 @@ mvc.on_load = function (self, parent)
-- this sets the package path for us and our children
package.path= self.conf.libdir .. "?.lua;" .. package.path
+ require ("cfe")
sessionlib=require ("session")
@@ -464,21 +465,22 @@ redirect = function (self, str)
error(self.conf)
end
-redirect_to_referrer = function(self)
- error({type="redir_to_referrer"})
-end
-
--- create a Configuration Framework Entity (cfe)
--- returns a table with at least "value", "type", and "label"
-cfe = function ( optiontable )
- optiontable = optiontable or {}
- me = { value="",
- type="text",
- label="" }
- for key,value in pairs(optiontable) do
- me[key] = value
+-- If we've done something, cause a redirect to the referring page (assuming it's different)
+-- Also handles retrieving the result of a previously redirected action
+redirect_to_referrer = function(self, result)
+ -- If we have a result, then we did something, so we might have to redirect
+ if result then
+ local prefix, controller, action = self.parse_path_info(ENV.HTTP_REFERER)
+ if controller ~= self.conf.controller or action ~= self.conf.action then
+ self.sessiondata[self.conf.action.."result"] = result
+ error({type="redir_to_referrer"})
+ end
+ -- If we don't have a result, then we might be a component redirected as above
+ elseif self.sessiondata[self.conf.action.."result"] then
+ result = self.sessiondata[self.conf.action.."result"]
+ self.sessiondata[self.conf.action.."result"] = nil
end
- return me
+ return result
end
-- FIXME - need to think more about this..
diff --git a/app/expert-html.lsp b/app/expert-html.lsp
new file mode 100644
index 0000000..c4a76cd
--- /dev/null
+++ b/app/expert-html.lsp
@@ -0,0 +1,15 @@
+<? local form, viewlibrary, page_info, session = ... ?>
+<? require("viewfunctions") ?>
+
+<? if viewlibrary and viewlibrary.dispatch_component then
+ viewlibrary.dispatch_component("status")
+end ?>
+
+<?
+local func = haserl.loadfile(page_info.viewfile:gsub(page_info.prefix..page_info.controller..".*$", "/") .. "filedetails-html.lsp")
+func(form, viewlibrary, page_info, session)
+?>
+
+<? if viewlibrary and viewlibrary.dispatch_component then
+ viewlibrary.dispatch_component("startstop")
+end ?>
diff --git a/app/filedetails-html.lsp b/app/filedetails-html.lsp
new file mode 100644
index 0000000..34c8803
--- /dev/null
+++ b/app/filedetails-html.lsp
@@ -0,0 +1,25 @@
+<? local form, viewlibrary, page_info = ... ?>
+<? require("viewfunctions") ?>
+
+<H1>Configuration</H1>
+<H2>Expert Configuration</H2>
+<H3>File Details</H3>
+<DL>
+<?
+displayitem(form.value.filename)
+displayitem(form.value.filesize)
+displayitem(form.value.mtime)
+?>
+</DL>
+
+<H3>File Content</H3>
+<? if form.descr then ?><P CLASS='descr'><?= string.gsub(form.descr, "\n", "<BR>") ?></P><? end ?>
+<? if form.errtxt then ?><P CLASS='error'><?= string.gsub(form.errtxt, "\n", "<BR>") ?></P><? end ?>
+<form action="<?= page_info.script .. page_info.prefix .. page_info.controller .. "/" .. page_info.action ?>" method="POST">
+<textarea name="filecontent">
+<?= form.value.filecontent.value ?>
+</textarea>
+<? if form.value.filecontent.errtxt then ?><P CLASS='error'><?= string.gsub(form.value.filecontent.errtxt, "\n", "<BR>") ?></P><? end ?>
+
+<DL><DT></DT><DD><input class="submit" type="submit" name="<?= form.option ?>" value="<?= form.option ?>"></DD></DL>
+</form>
diff --git a/app/startstop-html.lsp b/app/startstop-html.lsp
new file mode 100644
index 0000000..c0ead72
--- /dev/null
+++ b/app/startstop-html.lsp
@@ -0,0 +1,23 @@
+<? local data, viewlibrary, page_info = ... ?>
+
+<H1>Management</H1>
+<DL>
+<form action="<?= page_info.script .. page_info.prefix .. page_info.controller .. "/" .. page_info.action ?>" method="POST">
+<DT>Program control-panel</DT>
+<DD>
+<input class="submit" type="submit" name="action" value="Start" <? if data.value.status.value== "Enabled" then io.write("disabled") end ?>>
+<input class="submit" type="submit" name="action" value="Stop" <? if data.value.status.value== "Disabled" then io.write("disabled") end ?>>
+<input class="submit" type="submit" name="action" value="Restart" <? if data.value.status.value== "Disabled" then io.write("disabled") end ?>>
+</DD>
+</form>
+
+<? if data.value.result then ?>
+<DT>Previous action result</DT>
+<DD>
+<? if data.value.result.descr then ?>
+<P CLASS='descr'><?= string.gsub(data.value.result.descr, "\n", "<BR>") ?></P>
+<? end if data.value.result.errtxt then ?>
+<P CLASS='error'><?= string.gsub(data.value.result.errtxt, "\n", "<BR>") ?></P>
+<? end end ?>
+</DD>
+</DL>
diff --git a/app/status-html.lsp b/app/status-html.lsp
new file mode 100644
index 0000000..6cb9eea
--- /dev/null
+++ b/app/status-html.lsp
@@ -0,0 +1,12 @@
+<? local data = ...
+require("viewfunctions")
+?>
+
+<H1>System Info</H1>
+<DL>
+<?
+displayitem(data.value.status)
+displayitem(data.value.version)
+displayitem(data.value.autostart)
+?>
+</DL>
diff --git a/lib/Makefile b/lib/Makefile
index 62a34d6..855e551 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -19,7 +19,9 @@ LIB_DIST=fs.lua\
roles.lua\
processinfo.lua\
viewfunctions.lua\
-
+ controllerfunctions.lua\
+ modelfunctions.lua\
+ cfe.lua\
EXTRA_DIST=README Makefile
DISTFILES=$(LIB_DIST) $(EXTRA_DIST)
diff --git a/lib/cfe.lua b/lib/cfe.lua
new file mode 100644
index 0000000..34a249d
--- /dev/null
+++ b/lib/cfe.lua
@@ -0,0 +1,15 @@
+module(..., package.seeall)
+
+-- create a Configuration Framework Entity (cfe)
+-- returns a table with at least "value", "type", and "label"
+cfe = function ( optiontable )
+ optiontable = optiontable or {}
+ me = { value="",
+ type="text",
+ label="" }
+ for key,value in pairs(optiontable) do
+ me[key] = value
+ end
+ return me
+end
+_G.cfe = cfe
diff --git a/lib/controllerfunctions.lua b/lib/controllerfunctions.lua
new file mode 100644
index 0000000..23e57d4
--- /dev/null
+++ b/lib/controllerfunctions.lua
@@ -0,0 +1,51 @@
+module(..., package.seeall)
+
+function handle_form(self, getFunction, setFunction, clientdata, option, label, descr)
+ local form = getFunction()
+
+ if clientdata[option] then
+ form.errtxt = nil
+ for name,value in pairs(form.value) do
+ value.errtxt = nil
+ if value.type == "boolean" then
+ value.value = (clientdata[name] ~= nil)
+ elseif value.type == "list" then
+ value.value = {}
+ if clientdata[name] and clientdata[name] ~= "" then
+ for ip in string.gmatch(clientdata[name].."\n", "%s*(%S[^\n]*%S)%s*\n") do
+ table.insert(value.value, ip)
+ end
+ end
+ else
+ value.value = clientdata[name] or value.value
+ end
+ end
+ form = setFunction(form)
+ if not form.errtxt then
+ form.descr = descr
+ end
+ form = self:redirect_to_referrer(form)
+ else
+ form = self:redirect_to_referrer() or form
+ end
+
+ form.type = "form"
+ form.option = option
+ form.label = label
+
+ return form
+end
+
+function handle_startstop(self, startstopfunction, getstatusfunction, clientdata)
+ local result
+ if clientdata.action then
+ result = startstopfunction(clientdata.action)
+ end
+ result = self:redirect_to_referrer(result)
+
+ local status = getstatusfunction()
+ status = status.value.status
+
+ return cfe({ type="group", value={status=status, result=result} })
+end
+
diff --git a/lib/modelfunctions.lua b/lib/modelfunctions.lua
new file mode 100644
index 0000000..84c690b
--- /dev/null
+++ b/lib/modelfunctions.lua
@@ -0,0 +1,62 @@
+module(..., package.seeall)
+
+-- Load libraries
+require("procps")
+require("daemoncontrol")
+require("processinfo")
+
+local function process_status_text(procname)
+ local t = procps.pidof(procname)
+ if (t) and (#t > 0) then
+ return "Enabled"
+ else
+ return "Disabled"
+ end
+end
+
+function startstop_service(processname, action)
+ -- action is validated in daemoncontrol
+ local cmdresult,cmdmessage,cmderror,cmdaction = daemoncontrol.daemoncontrol(processname, action)
+ return cfe({ type="boolean", value=cmdresult, descr=cmdmessage, errtxt=cmderror, label="Start/Stop result" })
+end
+
+function getstatus(processname, packagename, label)
+ local status = {}
+
+ local value, errtxt = processinfo.package_version(packagename)
+ status.version = cfe({
+ label="Program version",
+ value=value,
+ errtxt=errtxt,
+ })
+
+ status.status = cfe({
+ label="Program status",
+ value=process_status_text(processname),
+ })
+
+ local autostart_sequence, autostart_errtxt = processinfo.process_botsequence(processname)
+ status.autostart = cfe({
+ label="Autostart sequence",
+ value=autostart_sequence,
+ errtxt=autostart_errtxt,
+ })
+
+ return cfe({ type="group", value=status, label=label })
+end
+
+function getfiledetails(file)
+ local filename = cfe({ value=file, label="File name" })
+ local filecontent = cfe({ type="longtext", label="File content" })
+ local filesize = cfe({ value="0", label="File size" })
+ local mtime = cfe({ value="---", label="File date" })
+ if fs.is_file(file) then
+ local filedetails = fs.stat(file)
+ filecontent.value = fs.read_file(file)
+ filesize.value = filedetails.size
+ mtime.value = filedetails.mtime
+ else
+ filename.errtxt = "File not found"
+ end
+ return cfe({ type="group", value={filename=filename, filecontent=filecontent, filesize=filesize, mtime=mtime}, label="Config file details" })
+end