summaryrefslogtreecommitdiffstats
path: root/chrony-model.lua
diff options
context:
space:
mode:
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