summaryrefslogtreecommitdiffstats
path: root/chrony-model.lua
diff options
context:
space:
mode:
authorttrask <ttrask@ab2d0c66-481e-0410-8bed-d214d4d58bed>2009-03-17 20:39:56 +0000
committerttrask <ttrask@ab2d0c66-481e-0410-8bed-d214d4d58bed>2009-03-17 20:39:56 +0000
commit2b516983f2168b85b6cc94c976a1b29cad0f95bb (patch)
tree32c00d880fcd6bda5fd525a934389355e950c69f /chrony-model.lua
parentf3260b34b21e5329a274af8e9caa8ecda505a3f1 (diff)
downloadacf-chrony-2b516983f2168b85b6cc94c976a1b29cad0f95bb.tar.bz2
acf-chrony-2b516983f2168b85b6cc94c976a1b29cad0f95bb.tar.xz
Changed the way startstop works in core to add a list of allowed actions. Modified all ACFs that don't use the standard functions to work with new library method.
git-svn-id: svn://svn.alpinelinux.org/acf/chrony/trunk@1730 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'chrony-model.lua')
-rw-r--r--chrony-model.lua47
1 files changed, 26 insertions, 21 deletions
diff --git a/chrony-model.lua b/chrony-model.lua
index c1001ed..14e8082 100644
--- a/chrony-model.lua
+++ b/chrony-model.lua
@@ -67,31 +67,36 @@ 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"
+ local result = modelfunctions.startstop_service(processname, action)
+ table.insert(result.value.actions.value, "online")
+ table.insert(result.value.actions.value, "offline")
+ if action then
+ local lower = action:lower()
+ if lower == "online" or lower == "offline" then
+ result.value.result.value = ""
+ result.value.result.errtxt = nil
+ -- try to find the password
+ local config = get_config()
+ if config.value.keyfile.value == "" then
+ result.value.result.errtxt = "No key file defined"
+ elseif config.value.commandkey.value == "" then
+ result.value.result.errtxt = "No command key defined"
else
- local cmd = path.."chronyc <<EOF\npassword "..format.escapespecialcharacters(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
+ 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
+ result.value.result.errtxt = "Could not find password in key file"
+ else
+ local cmd = path.."chronyc <<EOF\npassword "..format.escapespecialcharacters(password).."\n"..lower.."\nEOF"
+ local f = io.popen(cmd)
+ result.value.result.value = f:read("*a") or ""
+ f:close()
+ if (result.value.result.value == "") then result.value.result.errtxt = "Command failed" end
+ end
end
end
- return retval
end
- return modelfunctions.startstop_service(processname, action)
+ return result
end
function getstatus()