summaryrefslogtreecommitdiffstats
path: root/chrony-model.lua
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2009-01-07 21:58:00 +0000
committerTed Trask <ttrask01@yahoo.com>2009-01-07 21:58:00 +0000
commitaef4c4ae706483964aaa7569dff7fb9458552ab8 (patch)
treeddba29a84686d3b021b547d261b26bf7c4f6a567 /chrony-model.lua
parent03af194d9cd96d5cc840dc780fab76d741bf4b50 (diff)
downloadacf-chrony-aef4c4ae706483964aaa7569dff7fb9458552ab8.tar.bz2
acf-chrony-aef4c4ae706483964aaa7569dff7fb9458552ab8.tar.xz
Modified chrony to add online/offline buttons to startstop. part 1
git-svn-id: svn://svn.alpinelinux.org/acf/chrony/trunk@1669 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'chrony-model.lua')
-rw-r--r--chrony-model.lua24
1 files changed, 24 insertions, 0 deletions
diff --git a/chrony-model.lua b/chrony-model.lua
index 517efa4..269b96c 100644
--- a/chrony-model.lua
+++ b/chrony-model.lua
@@ -53,6 +53,30 @@ end
-- PUBLIC FUNCTIONS
function startstop_service(action)
+ local lower = action:lower()
+ if lower == "online" or lower == "offline" then
+ local retval = cfe({ label="Start/Stop result" })
+ -- try to find the password
+ local config = get_config()
+ if config.value.keyfile.value == "" then
+ retval.errtxt = "No key file defined"
+ elseif config.value.commandkey.value == "" then
+ retval.errtxt = "No command key defined"
+ else
+ local content = fs.read_file(config.value.keyfile.value) or ""
+ local password = string.match("\n"..content, "\n"..config.value.commandkey.value.."%s+(%S+)")
+ if not password then
+ retval.errtxt = "Could not find password in key file"
+ else
+ local cmd = path.."chronyc <<EOF\npassword "..password.."\n"..lower.."\nEOF"
+ local f = io.popen(cmd)
+ retval.value = f:read("*a")
+ f:close()
+ if not retval.value then retval.errtxt = "Command failed" end
+ end
+ end
+ return retval
+ end
return modelfunctions.startstop_service(processname, action)
end