From c91120a07c16044b1073b124646cb812d13e658e Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Tue, 16 Sep 2014 00:51:46 +0000 Subject: Implement editmacauthfile action --- freeradius3-controller.lua | 4 ++ freeradius3-editmacauthfile-html.lsp | 96 +++++++++++++++++++++++++++++++++++ freeradius3-listmacauthfiles-html.lsp | 2 + freeradius3-model.lua | 38 ++++++++++++-- freeradius3.roles | 4 +- 5 files changed, 138 insertions(+), 6 deletions(-) create mode 100644 freeradius3-editmacauthfile-html.lsp diff --git a/freeradius3-controller.lua b/freeradius3-controller.lua index a107b21..f268fb4 100644 --- a/freeradius3-controller.lua +++ b/freeradius3-controller.lua @@ -54,4 +54,8 @@ function mymodule.listmacauthfiles(self) return self.model.list_macauth_files() end +function mymodule.editmacauthfile(self) + return self.handle_form(self, self.model.get_macauth_file, self.model.update_macauth_file, self.clientdata, "Save", "Edit File", "File Saved") +end + return mymodule diff --git a/freeradius3-editmacauthfile-html.lsp b/freeradius3-editmacauthfile-html.lsp new file mode 100644 index 0000000..756abf3 --- /dev/null +++ b/freeradius3-editmacauthfile-html.lsp @@ -0,0 +1,96 @@ +<% local form, viewlibrary, page_info = ... %> +<% htmlviewfunctions = require("htmlviewfunctions") %> +<% html = require("acf.html") %> + + + + + +<% +local header_level = htmlviewfunctions.displaysectionstart(cfe({label="Edit MAC Authentication File"}), page_info) +htmlviewfunctions.displayitem(form.value.filename) +htmlviewfunctions.displayitem(form.value.filesize) +htmlviewfunctions.displayitem(form.value.mtime) +local header_level2 = htmlviewfunctions.displaysectionstart(cfe({label="Entries"}), page_info, htmlviewfunctions.incrementheader(header_level)) + htmlviewfunctions.displayformstart(form, page_info) + form.value.filename.type = "hidden" + htmlviewfunctions.displayformitem(form.value.filename, "filename") + form.value.filecontent.type = "hidden" + htmlviewfunctions.displayformitem(form.value.filecontent, "filecontent") +%> + +<% for line in string.gmatch(html.html_escape(form.value.filecontent.value), "([^\n]*)\n?") do %> + +<% end %> +
<%= line %>
+<% + htmlviewfunctions.displayinfo(form.value.filecontent) + htmlviewfunctions.displayformend(form) +htmlviewfunctions.displaysectionend(header_level2) +htmlviewfunctions.displaysectionend(header_level) +%> diff --git a/freeradius3-listmacauthfiles-html.lsp b/freeradius3-listmacauthfiles-html.lsp index a70a207..fcb1363 100644 --- a/freeradius3-listmacauthfiles-html.lsp +++ b/freeradius3-listmacauthfiles-html.lsp @@ -35,6 +35,8 @@ end }); +<% htmlviewfunctions.displaycommandresults({"editmacauthfile"}, session) %> + <% local header_level = htmlviewfunctions.displaysectionstart(cfe({label="MAC Authentication Configuration"}), page_info) %> diff --git a/freeradius3-model.lua b/freeradius3-model.lua index df85118..4ec9037 100644 --- a/freeradius3-model.lua +++ b/freeradius3-model.lua @@ -17,6 +17,7 @@ local group = "root" local config local configtable +local macauthfiles -- ################################################################################ -- LOCAL FUNCTIONS @@ -297,11 +298,14 @@ local update_passwd_entry_private = function(self, entry, create) end local get_macauth_files = function() - local files + if macauthfiles then + return macauthfiles + end + local result,errtxt = get_config() if result then -- Find the files by searching for modules / files / usersfile where key="%{Calling-Station-Id}" - files = {} + macauthfiles = {} for i,first in ipairs(configtable) do if string.find(first.name, "^modules$") then for j,second in ipairs(first.value) do @@ -314,7 +318,7 @@ local get_macauth_files = function() key = true end if key and file then - files[#files+1] = file + macauthfiles[#macauthfiles+1] = file break end end @@ -323,7 +327,19 @@ local get_macauth_files = function() end end end - return files, errtxt + return macauthfiles, errtxt +end + +local is_valid_macauth_filename = function(filename) + macauthfiles = macauthfiles or get_macauth_files() + if macauthfiles then + for i,f in ipairs(macauthfiles) do + if filename == f then + return true + end + end + end + return false end -- ################################################################################ @@ -603,4 +619,18 @@ function mymodule.list_macauth_files() return cfe({ type="structure", value=retval, label="List of Freeradius MAC authentication files", errtxt=errtxt }) end +function mymodule.get_macauth_file(self, clientdata) + local filename = clientdata.filename + return modelfunctions.getfiledetails(filename, is_valid_macauth_filename) +end + +function mymodule.update_macauth_file(self, filedetails) + local ret = modelfunctions.setfiledetails(self, filedetails, is_valid_macauth_filename) + if not ret.errtxt then + posix.chmod(filedetails.value.filename.value, "rw-r-----") + posix.chown(filedetails.value.filename.value, posix.getpasswd(owner, "uid") or 0, posix.getpasswd(group, "gid") or 0) + end + return ret +end + return mymodule diff --git a/freeradius3.roles b/freeradius3.roles index bd204ac..b159597 100644 --- a/freeradius3.roles +++ b/freeradius3.roles @@ -1,3 +1,3 @@ USER=freeradius3:status,freeradius3:startstop,freeradius3:logfile -EXPERT=freeradius3:listfiles,freeradius3:editfile,freeradius3:createfile,freeradius3:deletefile,freeradius3:listpasswdfiles,freeradius3:viewpasswdfile,freeradius3:editpasswdentry,freeradius3:createpasswdentry,freeradius3:deletepasswdentry,freeradius3:editpasswd,freeradius3:listmacauthfiles -ADMIN=freeradius3:status,freeradius3:startstop,freeradius3:logfile,freeradius3:listfiles,freeradius3:editfile,freeradius3:createfile,freeradius3:deletefile,freeradius3:listpasswdfiles,freeradius3:viewpasswdfile,freeradius3:editpasswdentry,freeradius3:createpasswdentry,freeradius3:deletepasswdentry,freeradius3:editpasswd,freeradius3:listmacauthfiles +EXPERT=freeradius3:listfiles,freeradius3:editfile,freeradius3:createfile,freeradius3:deletefile,freeradius3:listpasswdfiles,freeradius3:viewpasswdfile,freeradius3:editpasswdentry,freeradius3:createpasswdentry,freeradius3:deletepasswdentry,freeradius3:editpasswd,freeradius3:listmacauthfiles,freeradius3:editmacauthfile +ADMIN=freeradius3:status,freeradius3:startstop,freeradius3:logfile,freeradius3:listfiles,freeradius3:editfile,freeradius3:createfile,freeradius3:deletefile,freeradius3:listpasswdfiles,freeradius3:viewpasswdfile,freeradius3:editpasswdentry,freeradius3:createpasswdentry,freeradius3:deletepasswdentry,freeradius3:editpasswd,freeradius3:listmacauthfiles,freeradius3:editmacauthfile -- cgit v1.2.3