diff options
author | ttrask <ttrask@ab2d0c66-481e-0410-8bed-d214d4d58bed> | 2009-03-17 20:39:56 +0000 |
---|---|---|
committer | ttrask <ttrask@ab2d0c66-481e-0410-8bed-d214d4d58bed> | 2009-03-17 20:39:56 +0000 |
commit | 2b516983f2168b85b6cc94c976a1b29cad0f95bb (patch) | |
tree | 32c00d880fcd6bda5fd525a934389355e950c69f | |
parent | f3260b34b21e5329a274af8e9caa8ecda505a3f1 (diff) | |
download | acf-chrony-2b516983f2168b85b6cc94c976a1b29cad0f95bb.tar.bz2 acf-chrony-2b516983f2168b85b6cc94c976a1b29cad0f95bb.tar.xz |
Changed the way startstop works in core to add a list of allowed actions. Modified all ACFs that don't use the standard functions to work with new library method.
git-svn-id: svn://svn.alpinelinux.org/acf/chrony/trunk@1730 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r-- | chrony-model.lua | 47 | ||||
-rw-r--r-- | chrony-startstop-html.lsp | 19 |
2 files changed, 35 insertions, 31 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() diff --git a/chrony-startstop-html.lsp b/chrony-startstop-html.lsp index 7ad44f3..6a420f6 100644 --- a/chrony-startstop-html.lsp +++ b/chrony-startstop-html.lsp @@ -1,6 +1,15 @@ <% local data, viewlibrary, page_info = ... %> <H1>Management</H1> + +<% if data.value.result then %> +<H2>Previous action result</H2> +<% if data.value.result.value ~= "" then %> +<P CLASS='descr'><%= string.gsub(html.html_escape(data.value.result.value), "\n", "<BR>") %></P> +<% end if data.value.result.errtxt then %> +<P CLASS='error'><%= string.gsub(html.html_escape(data.value.result.errtxt), "\n", "<BR>") %></P> +<% end end %> + <DL> <form action="<%= html.html_escape(page_info.script .. page_info.prefix .. page_info.controller .. "/" .. page_info.action) %>" method="POST"> <DT>Program control-panel</DT> @@ -15,14 +24,4 @@ <input class="submit" type="submit" name="action" value="Offline" <% if data.value.status.value== "Stopped" then io.write("disabled") end %>> </DD> </form> - -<% if data.value.result then %> -<DT>Previous action result</DT> -<DD> -<% if data.value.result.value ~= "" then %> -<P CLASS='descr'><%= string.gsub(html.html_escape(data.value.result.value), "\n", "<BR>") %></P> -<% end if data.value.result.errtxt then %> -<P CLASS='error'><%= string.gsub(html.html_escape(data.value.result.errtxt), "\n", "<BR>") %></P> -<% end end %> -</DD> </DL> |