summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorttrask <ttrask@ab2d0c66-481e-0410-8bed-d214d4d58bed>2009-03-17 20:39:56 +0000
committerttrask <ttrask@ab2d0c66-481e-0410-8bed-d214d4d58bed>2009-03-17 20:39:56 +0000
commitc700c97cb992cdc3eb62d93a52e1bf56ed5ea585 (patch)
treefb6446b8fbe31833808ab1319d845b0614047fee
parent5dc15abba740eae84b4202a6a7319cad163fe87c (diff)
downloadacf-core-c700c97cb992cdc3eb62d93a52e1bf56ed5ea585.tar.bz2
acf-core-c700c97cb992cdc3eb62d93a52e1bf56ed5ea585.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/core/trunk@1730 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r--app/startstop-html.lsp29
-rw-r--r--lib/controllerfunctions.lua10
-rw-r--r--lib/modelfunctions.lua13
-rw-r--r--lib/processinfo.lua12
4 files changed, 39 insertions, 25 deletions
diff --git a/app/startstop-html.lsp b/app/startstop-html.lsp
index ab9b8ac..924f14d 100644
--- a/app/startstop-html.lsp
+++ b/app/startstop-html.lsp
@@ -1,23 +1,30 @@
<% local data, viewlibrary, page_info = ... %>
+<% local reverseactions = {}
+data.value.actions = data.value.actions or {}
+local actions = data.value.actions.value or {"start", "stop", "restart"}
+for i,act in ipairs(actions) do
+ reverseactions[act] = i
+end %>
+
<H1>Management</H1>
-<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>
-<DD>
-<input class="submit" type="submit" name="action" value="Start" <% if data.value.status.value== "Running" then io.write("disabled") end %>>
-<input class="submit" type="submit" name="action" value="Stop" <% if data.value.status.value== "Stopped" then io.write("disabled") end %>>
-<input class="submit" type="submit" name="action" value="Restart" <% if data.value.status.value== "Stopped" then io.write("disabled") end %>>
-</DD>
-</form>
<% if data.value.result then %>
-<DT>Previous action result</DT>
-<DD>
+<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>
+<DD>
+<% if reverseactions.start then %><input class="submit" type="submit" name="action" value="Start" <% if data.value.status.value== "Running" then io.write("disabled") end %>><% end %>
+<% if reverseactions.stop then %><input class="submit" type="submit" name="action" value="Stop" <% if data.value.status.value== "Stopped" then io.write("disabled") end %>><% end %>
+<% if reverseactions.restart then %><input class="submit" type="submit" name="action" value="Restart" <% if data.value.status.value== "Stopped" then io.write("disabled") end %>><% end %>
+<% if reverseactions.reload then %><input class="submit" type="submit" name="action" value="Reload" <% if data.value.status.value== "Stopped" then io.write("disabled") end %>><% end %>
</DD>
+</form>
</DL>
diff --git a/lib/controllerfunctions.lua b/lib/controllerfunctions.lua
index 90d31a4..dbdfd19 100644
--- a/lib/controllerfunctions.lua
+++ b/lib/controllerfunctions.lua
@@ -78,15 +78,13 @@ function handle_form(self, getFunction, setFunction, clientdata, option, label,
end
function handle_startstop(self, startstopfunction, getstatusfunction, clientdata)
- local result
- if clientdata.action then
- result = startstopfunction(clientdata.action)
- end
- result = self:redirect_to_referrer(result)
+ local result = startstopfunction(clientdata.action)
+ result.value.result = self:redirect_to_referrer(result.value.result)
local status = getstatusfunction()
if status.value.status then status = status.value.status end
+ result.value.status = status
- return cfe({ type="group", value={status=status, result=result} })
+ return result
end
diff --git a/lib/modelfunctions.lua b/lib/modelfunctions.lua
index 076d1bb..d7be73d 100644
--- a/lib/modelfunctions.lua
+++ b/lib/modelfunctions.lua
@@ -16,10 +16,15 @@ function getenabled(processname)
return result
end
-function startstop_service(servicename, action)
- -- action is validated in daemoncontrol
- local cmdmessage,cmderror = processinfo.daemoncontrol(servicename, action)
- return cfe({ value=cmdmessage or "", errtxt=cmderror, label="Start/Stop result" })
+function startstop_service(servicename, action, actions)
+ -- action is validated against actions in daemoncontrol
+ local result = {}
+ result.actions = cfe({ type="list", value=actions or {"start", "stop", "restart"}, label="Start/Stop actions" })
+ if action then
+ local cmdmessage,cmderror = processinfo.daemoncontrol(servicename, action, result.actions.value)
+ result.result = cfe({ value=cmdmessage or "", errtxt=cmderror, label="Start/Stop result" })
+ end
+ return cfe({ type="group", value=result, label="Start/Stop result" })
end
function getstatus(processname, packagename, label, servicename)
diff --git a/lib/processinfo.lua b/lib/processinfo.lua
index f41e62f..35ea42f 100644
--- a/lib/processinfo.lua
+++ b/lib/processinfo.lua
@@ -112,14 +112,18 @@ function delete_startupsequence(servicename)
return cmdresult,cmderrors
end
-function daemoncontrol (process, action)
+function daemoncontrol (process, action, actions)
+ actions = actions or {"start", "stop", "restart"}
+ local reverseactions = {}
+ for i,act in ipairs(actions) do reverseactions[string.lower(act)] = i end
+
local cmdresult = ""
local cmderrors
if not process then
cmderrors = "Invalid service name"
- elseif (string.lower(action) == "start") or (string.lower(action) == "stop") or (string.lower(action) == "restart") then
+ elseif reverseactions[string.lower(action)] then
local file = io.popen( "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin /etc/init.d/" ..
- format.escapespecialcharacters(process) .. " " .. string.lower(action) .. " 2>&1" )
+ format.escapespecialcharacters(process) .. " " .. format.escapespecialcharacters(string.lower(action)) .. " 2>&1" )
if file ~= nil then
cmdresult = file:read( "*a" )
file:close()
@@ -128,7 +132,7 @@ function daemoncontrol (process, action)
else
cmderrors = "Unknown command!"
end
- return cmdresult,cmderrors
+ return cmdresult,cmderrors,actions
end
-- the following methods are available: