summaryrefslogtreecommitdiffstats
path: root/openntpd-controller.lua
diff options
context:
space:
mode:
Diffstat (limited to 'openntpd-controller.lua')
-rw-r--r--openntpd-controller.lua37
1 files changed, 27 insertions, 10 deletions
diff --git a/openntpd-controller.lua b/openntpd-controller.lua
index 06b53b2..8b1fe04 100644
--- a/openntpd-controller.lua
+++ b/openntpd-controller.lua
@@ -3,6 +3,7 @@ module (..., package.seeall)
-- Cause an http redirect to our "read" action
-- We use the self.conf table because it already has prefix,controller,etc
-- The redir code is defined in the application error handler (acf-controller)
+require("posix")
local list_redir = function (self)
self.conf.action = "read"
self.conf.type = "redir"
@@ -17,25 +18,41 @@ mvc.on_load = function(self, parent)
end
-read = function (self)
+settings = function (self)
local cmd = self.clientdata.cmd
- if ( cmd == "start" ) then
- return ( {filecontent = self.model:get(), startup = self.model:startstop_service( cmd ), shutdown = "", url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } )
- elseif ( cmd == "stop" ) then
- return ( {filecontent = self.model:get(), shutdown = self.model:startstop_service( cmd ), startup = "", url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } )
+ local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller
+ if ( cmd ~= nil ) then
+ local startstop = self.model:startstop_service( cmd )
+ posix.sleep(1) -- Wait for the process to start|stop
+ local statusinfo = self.model:get()
+ return ( {startstop = startstop, statusinfo = statusinfo, url = url } )
else
- return ( {filecontent = self.model:get(), shutdown = "" , startup = "", url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } )
+ return ( {statusinfo = self.model:get(), startstop = "", url = url } )
end
end
+read = function (self)
+ local cmd = self.clientdata.cmd
+ local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller
+ return ( {statusinfo = self.model:get(), url = url } )
+end
+
advanced = function (self)
local filecontent = self.clientdata.modifications or ""
+ local cmd = self.clientdata.cmd
+ local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller
+
if ( filecontent ~= "") then
- local me = ( {filecontent = self.model:update_filecontent(filecontent), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } )
- list_redir(self)
+ local me = ( {filecontent = self.model:update_filecontent(filecontent), url = url } )
+ return ( {startstop = "", statusinfo = self.model:get(), filecontent = self.model:get_filecontent(), url = url } )
else
- local me = ( {filecontent = self.model:get_filecontent(), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } )
- return me
+ if ( cmd ~= nil ) then
+ local startstop = self.model:startstop_service( cmd )
+ posix.sleep(1) -- Wait for the process to start|stop
+ return ( {startstop = startstop, statusinfo = self.model:get(), filecontent = self.model:get_filecontent(), url = url } )
+ else
+ return ( {startstop = "", statusinfo = self.model:get(), filecontent = self.model:get_filecontent(), url = url } )
+ end
end
end