summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrony-controller.lua20
-rw-r--r--chrony-model.lua37
2 files changed, 30 insertions, 27 deletions
diff --git a/chrony-controller.lua b/chrony-controller.lua
index 16962bb..eedffb5 100644
--- a/chrony-controller.lua
+++ b/chrony-controller.lua
@@ -1,31 +1,33 @@
-module(..., package.seeall)
+local mymodule = {}
-default_action = "status"
+mymodule.default_action = "status"
-function status(self)
+function mymodule.status(self)
return self.model.getstatus()
end
-function details(self)
+function mymodule.details(self)
return self.model.getdetails()
end
-function startstop(self)
+function mymodule.startstop(self)
return self.handle_form(self, self.model.get_startstop, self.model.startstop_service, self.clientdata)
end
-function config(self)
+function mymodule.config(self)
return self.handle_form(self, self.model.get_config, self.model.update_config, self.clientdata, "Save", "Edit Config", "Configuration Set")
end
-function keyfile(self)
+function mymodule.keyfile(self)
return self.handle_form(self, self.model.get_keyfiledetails, self.model.update_keyfiledetails, self.clientdata, "Save", "Edit Key File", "Key File Saved")
end
-function enablekeyfile(self)
+function mymodule.enablekeyfile(self)
return self.handle_form(self, self.model.get_enable_keyfile, self.model.enable_keyfile, self.clientdata, "Enable", "Enabled Key File", "Enabled key file")
end
-function expert(self)
+function mymodule.expert(self)
return self.handle_form(self, self.model.get_filedetails, self.model.update_filedetails, self.clientdata, "Save", "Edit Config File", "Configuration Set")
end
+
+return mymodule
diff --git a/chrony-model.lua b/chrony-model.lua
index b2ee1ae..a1b937f 100644
--- a/chrony-model.lua
+++ b/chrony-model.lua
@@ -1,4 +1,4 @@
-module(..., package.seeall)
+local mymodule = {}
-- Load libraries
modelfunctions = require("modelfunctions")
@@ -17,7 +17,7 @@ local keyfile = "/etc/chrony/chrony.keys"
-- ################################################################################
-- LOCAL FUNCTIONS
-function validate_config(config)
+local function validate_config(config)
local success = true
for i,val in ipairs(config.value.server.value) do
if string.find(val, "[^%w%s.-]") then
@@ -54,7 +54,7 @@ local function get_keyfilestatus(filedetails)
-- check to see if the file is being used
filedetails.value.status = cfe({ value="Key file in use", label="Key file status" })
- local config = get_config()
+ local config = mymodule.get_config()
if config.value.keyfile.value ~= keyfile then
filedetails.value.status.value = ""
filedetails.value.status.errtxt = "Key file is not in use"
@@ -66,18 +66,18 @@ end
-- ################################################################################
-- PUBLIC FUNCTIONS
-function get_startstop(self, clientdata)
+function mymodule.get_startstop(self, clientdata)
local retval = modelfunctions.get_startstop(processname)
retval.option[#retval.option+1] = "Online"
retval.option[#retval.option+1] = "Offline"
return retval
end
-function startstop_service(self, startstop, action)
+function mymodule.startstop_service(self, startstop, action)
local lower = action:lower()
if lower == "online" or lower == "offline" then
-- try to find the password
- local config = get_config()
+ local config = mymodule.get_config()
if config.value.keyfile.value == "" then
startstop.errtxt = "No key file defined"
elseif config.value.commandkey.value == "" then
@@ -97,11 +97,11 @@ function startstop_service(self, startstop, action)
return startstop
end
-function getstatus()
+function mymodule.getstatus()
return modelfunctions.getstatus(processname, packagename, "Chrony Status")
end
-function getdetails()
+function mymodule.getdetails()
local details = {}
details.time = cfe({ value=os.date(), label="Current Time" })
details.sources = cfe({ type="longtext", value="Unavailable", label="Sources" })
@@ -118,7 +118,7 @@ function getdetails()
return cfe({ type="group", value=details, label="Chrony Status Details" })
end
-function get_config()
+function mymodule.get_config()
local output = {}
output.server = cfe({ type="list", value={}, label="Servers", descr="List of NTP servers by name or IP (ie. 0.pool.ntp.org). If infrequent Internet connection, follow name/IP with 'offline'.", seq=1 })
output.allow = cfe({ type="list", value={}, label="Allow", descr="List of allowed clients by name/subnet/IP or 'all'.", seq=2 })
@@ -142,7 +142,7 @@ function get_config()
return cfe({ type="group", value=output, label="Chrony Config" })
end
-function update_config(self, config)
+function mymodule.update_config(self, config)
local success, config = validate_config(config)
if success then
@@ -192,23 +192,23 @@ function update_config(self, config)
return config
end
-function get_keyfiledetails()
+function mymodule.get_keyfiledetails()
return get_keyfilestatus(modelfunctions.getfiledetails(keyfile))
end
-function update_keyfiledetails(self, filedetails)
+function mymodule.update_keyfiledetails(self, filedetails)
return get_keyfilestatus(modelfunctions.setfiledetails(self, filedetails, {keyfile}))
end
-function get_enable_keyfile()
+function mymodule.get_enable_keyfile()
local result = {}
return cfe({ type="group", value=result, label="Enable Key File" })
end
-function enable_keyfile(self, enablerequest)
- local config = get_config()
+function mymodule.enable_keyfile(self, enablerequest)
+ local config = mymodule.get_config()
config.value.keyfile.value = keyfile
- config = update_config(self, config)
+ config = mymodule.update_config(self, config)
if config.errtxt then
enablerequest.errtxt = {config.errtxt}
for name,val in pairs(config.value) do
@@ -221,13 +221,14 @@ function enable_keyfile(self, enablerequest)
return enablerequest
end
-function get_filedetails()
+function mymodule.get_filedetails()
-- FIXME validate
return modelfunctions.getfiledetails(configfile)
end
-function update_filedetails(self, filedetails)
+function mymodule.update_filedetails(self, filedetails)
-- FIXME validate
return modelfunctions.setfiledetails(self, filedetails, {configfile})
end
+return mymodule