diff options
author | Ted Trask <ttrask01@yahoo.com> | 2014-09-15 17:55:41 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2014-09-15 17:55:41 +0000 |
commit | bb693ddd74d12f55487b16eab7da40fc2ff13988 (patch) | |
tree | 99cdf8d225fe94dee1b33491baaac5933f4b5bdb /freeradius3-model.lua | |
parent | 47c61e5dd2476f6eab7d50b1794d29412759858f (diff) | |
download | acf-freeradius3-bb693ddd74d12f55487b16eab7da40fc2ff13988.tar.bz2 acf-freeradius3-bb693ddd74d12f55487b16eab7da40fc2ff13988.tar.xz |
Implement deletepasswdentry action
Diffstat (limited to 'freeradius3-model.lua')
-rw-r--r-- | freeradius3-model.lua | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/freeradius3-model.lua b/freeradius3-model.lua index fdc246c..d3c9ca8 100644 --- a/freeradius3-model.lua +++ b/freeradius3-model.lua @@ -166,7 +166,7 @@ local mksalt = function() return str end -local get_passwd_file = function(self, clientdata) +local get_passwd_file = function(self, clientdata, readonly) local retval = cfe({ type="group", value={}, label="Freeradius passwd file" }) retval.value.filename = cfe({ type="select", label="File name", option ={}, key=true, seq=1 }) local files,configs,passwdconfig @@ -179,7 +179,7 @@ local get_passwd_file = function(self, clientdata) for i,f in ipairs(files) do if f == retval.value.filename.value then retval.value.filename.errtxt = nil - retval.value.filename.readonly = true + if readonly then retval.value.filename.readonly = true end passwdconfig = parse_passwd_config(configs[i]) break end @@ -192,7 +192,7 @@ local get_passwd_file = function(self, clientdata) end local get_passwd_entry_private = function(self, clientdata, create) - local retval,passwdconfig = get_passwd_file(self, clientdata) + local retval,passwdconfig = get_passwd_file(self, clientdata, true) retval.label = "Freeradius passwd entry" local entry = 0 local entryline = {} @@ -405,7 +405,7 @@ function mymodule.list_passwd_files() end function mymodule.view_passwd_file(self, clientdata) - local retval,passwdconfig = get_passwd_file(self, clientdata) + local retval,passwdconfig = get_passwd_file(self, clientdata, true) if passwdconfig then -- We have a valid filename, now parse the file using the format from the config retval.value.fields = cfe({ type="structure", value=passwdconfig.fields, label="Fields" }) @@ -434,8 +434,34 @@ function mymodule.create_passwd_entry(self, entry) return update_passwd_entry_private(self, entry, true) end -function mymodule.get_passwd(self, clientdata) +function mymodule.get_delete_passwd_entry(self, clientdata) local retval,passwdconfig = get_passwd_file(self, clientdata) + retval.label = "Delete Freeradius passwd entry" + retval.value.filename.key = nil + retval.value.entry = cfe({ label="Entry index", seq=2 }) + return retval +end + +function mymodule.delete_passwd_entry(self, entry) + local success = modelfunctions.validateselect(entry.value.filename) + if success then + local contenttable = fs.read_file_as_array(entry.value.filename.value) or {} + if contenttable[tonumber(entry.value.entry.value) or 0] then + table.remove(contenttable, tonumber(entry.value.entry.value)) + fs.write_file(entry.value.filename.value, table.concat(contenttable, "\n")) + else + success = false + entry.value.entry.errtxt = "Invalid entry" + end + end + if not success then + entry.errtxt = "Failed to delete entry" + end + return entry +end + +function mymodule.get_passwd(self, clientdata) + local retval,passwdconfig = get_passwd_file(self, clientdata, true) retval.label = "Freeradius password" retval.value.entry = cfe({ label="Entry index", key=true, seq=2 }) self.handle_clientdata(retval, clientdata) |