From 89d6fe43417668b06c24852c217a9487b1caa139 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Wed, 18 Apr 2012 16:03:38 +0000 Subject: Modified startstop to add Online and Offline buttons and remove custom view --- chrony-model.lua | 57 +++++++++++++++++++++++++++----------------------------- 1 file changed, 27 insertions(+), 30 deletions(-) (limited to 'chrony-model.lua') 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 <