summaryrefslogtreecommitdiffstats
path: root/lib/modelfunctions.lua
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 /lib/modelfunctions.lua
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
Diffstat (limited to 'lib/modelfunctions.lua')
-rw-r--r--lib/modelfunctions.lua62
1 files changed, 62 insertions, 0 deletions
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