summaryrefslogtreecommitdiffstats
path: root/chrony-model.lua
diff options
context:
space:
mode:
Diffstat (limited to 'chrony-model.lua')
-rw-r--r--chrony-model.lua57
1 files changed, 27 insertions, 30 deletions
diff --git a/chrony-model.lua b/chrony-model.lua
index 3f3f9ed..0a4ab7c 100644
--- a/chrony-model.lua
+++ b/chrony-model.lua
@@ -68,44 +68,41 @@ end
-- PUBLIC FUNCTIONS
function get_startstop(clientdata)
- return modelfunctions.get_startstop(processname)
+ local retval = modelfunctions.get_startstop(processname)
+ retval.option[#retval.option+1] = "Online"
+ retval.option[#retval.option+1] = "Offline"
+ return retval
end
function startstop_service(startstop, action)
- return modelfunctions.startstop_service(startstop, action)
-end
-
-function old_startstop_service(action)
- 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"
+ local lower = action:lower()
+ if lower == "online" or lower == "offline" then
+ -- try to find the password
+ local config = get_config()
+ if config.value.keyfile.value == "" then
+ startstop.errtxt = "No key file defined"
+ elseif config.value.commandkey.value == "" then
+ startstop.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
+ startstop.errtxt = "Could not find password in key file"
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
- 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
+ local cmd = path.."chronyc <<EOF\npassword "..format.escapespecialcharacters(password).."\n"..lower.."\nEOF"
+ local f = io.popen(cmd)
+ startstop.descr = f:read("*a") or ""
+ f:close()
+ if (startstop.descr == "") then
+ startstop.descr = nil
+ startstop.errtxt = "Command failed"
end
end
end
+ else
+ startstop = modelfunctions.startstop_service(startstop, action)
end
- return result
+ return startstop
end
function getstatus()