diff options
Diffstat (limited to 'chrony-model.lua')
-rw-r--r-- | chrony-model.lua | 47 |
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() |