diff options
author | Ted Trask <ttrask01@yahoo.com> | 2012-04-18 16:03:38 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2012-04-18 16:03:38 +0000 |
commit | 89d6fe43417668b06c24852c217a9487b1caa139 (patch) | |
tree | d05cd69035d6502953a47174dc322a1c97195f2b /chrony-model.lua | |
parent | 014a64f9b06cae003da8c2a5905277922807f5f1 (diff) | |
download | acf-chrony-89d6fe43417668b06c24852c217a9487b1caa139.tar.bz2 acf-chrony-89d6fe43417668b06c24852c217a9487b1caa139.tar.xz |
Modified startstop to add Online and Offline buttons and remove custom view
Diffstat (limited to 'chrony-model.lua')
-rw-r--r-- | chrony-model.lua | 57 |
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() |