From 2e2e16a50fad3a9a99fa8021d235de77556bdad9 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Thu, 8 Jan 2009 19:04:51 +0000 Subject: Modified chrony to add key file functionality. git-svn-id: svn://svn.alpinelinux.org/acf/chrony/trunk@1671 ab2d0c66-481e-0410-8bed-d214d4d58bed --- chrony-controller.lua | 8 ++++++++ chrony-keyfile-html.lsp | 21 +++++++++++++++++++++ chrony-model.lua | 40 ++++++++++++++++++++++++++++++++++++++++ chrony.menu | 1 + chrony.roles | 5 +++-- 5 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 chrony-keyfile-html.lsp diff --git a/chrony-controller.lua b/chrony-controller.lua index 4870690..9d5a77e 100644 --- a/chrony-controller.lua +++ b/chrony-controller.lua @@ -20,6 +20,14 @@ function config(self) return controllerfunctions.handle_form(self, self.model.get_config, self.model.update_config, self.clientdata, "Save", "Edit Config", "Configuration Set") end +function keyfile(self) + return controllerfunctions.handle_form(self, self.model.get_keyfiledetails, self.model.update_keyfiledetails, self.clientdata, "Save", "Edit Key File", "Key File Saved") +end + +function enablekeyfile(self) + return self:redirect_to_referrer(self.model.enable_keyfile()) +end + function expert(self) return controllerfunctions.handle_form(self, self.model.get_filedetails, self.model.update_filedetails, self.clientdata, "Save", "Edit Config File", "Configuration Set") end diff --git a/chrony-keyfile-html.lsp b/chrony-keyfile-html.lsp new file mode 100644 index 0000000..9d1188c --- /dev/null +++ b/chrony-keyfile-html.lsp @@ -0,0 +1,21 @@ +<% local form, viewlibrary, page_info, session = ... %> +<% require("viewfunctions") %> + +<% displaycommandresults({"enablekeyfile"}, session) %> + +

Key File Status

+
+<% + displayitem(form.value.status) + if form.value.status.errtxt then %> +
"> +
+<% end +%> +
+ +<% +local pattern = string.gsub(page_info.prefix..page_info.controller, "[%(%)%.%%%+%-%*%?%[%]%^%$]", "%%%1") +local func = haserl.loadfile(page_info.viewfile:gsub(pattern..".*$", "/") .. "filedetails-html.lsp") +func(form, viewlibrary, page_info, session) +%> diff --git a/chrony-model.lua b/chrony-model.lua index 269b96c..ec0301d 100644 --- a/chrony-model.lua +++ b/chrony-model.lua @@ -49,6 +49,20 @@ function validate_config(config) return success, config end +local function get_keyfilestatus(filedetails) + filedetails.value.filecontent.descr = "List of password numbers and passwords (ie. '10 cronpass')" + + -- 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() + if config.value.keyfile.value ~= keyfile then + filedetails.value.status.value = "" + filedetails.value.status.errtxt = "Key file is not in use" + end + + return filedetails +end + -- ################################################################################ -- PUBLIC FUNCTIONS @@ -184,6 +198,32 @@ function update_config(config) return config end +function get_keyfiledetails() + return get_keyfilestatus(modelfunctions.getfiledetails(keyfile)) +end + +function update_keyfiledetails(filedetails) + return get_keyfilestatus(modelfunctions.setfiledetails(filedetails, {keyfile})) +end + +function enable_keyfile() + local result = cfe({ value="Enabled key file", label="Enable Key file result" }) + local config = get_config() + config.value.keyfile.value = keyfile + config = update_config(config) + if config.errtxt then + result.value = "" + result.errtxt = {config.errtxt} + for name,val in pairs(config.value) do + if val.errtxt then + table.insert(result.errtxt, name.." - "..val.errtxt) + end + end + result.errtxt = table.concat(result.errtxt, "\n") + end + return result +end + function get_filedetails() -- FIXME validate return modelfunctions.getfiledetails(configfile) diff --git a/chrony.menu b/chrony.menu index 03a0722..7f5f233 100644 --- a/chrony.menu +++ b/chrony.menu @@ -1,5 +1,6 @@ #CAT GROUP/DESC TAB ACTION Networking 20NTP(chrony) Status details Networking 20NTP(chrony) Config config +Networking 20NTP(chrony) Keys keyfile Networking 20NTP(chrony) Expert expert Networking 20NTP(chrony) Logfile logfile diff --git a/chrony.roles b/chrony.roles index 7d7bad9..f1c891a 100644 --- a/chrony.roles +++ b/chrony.roles @@ -1,4 +1,5 @@ USER=chrony:status,chrony:logfile,chrony:details,chrony:startstop EDITOR=chrony:config -EXPERT=chrony:expert -ADMIN=chrony:status,chrony:logfile,chrony:details,chrony:startstop,chrony:config,chrony:expert +EXPERT=chrony:keyfile,chrony:enablekeyfile,chrony:expert +ADMIN=chrony:status,chrony:logfile,chrony:details,chrony:startstop,chrony:config,chrony:keyfile,chrony:enablekeyfile,chrony:expert + -- cgit v1.2.3