module(..., package.seeall) require("controllerfunctions") require("validator") mvc = {} mvc.on_load = function(self, parent) self.model.set_processname(string.match(self.conf.prefix, "[^/]+")) end default_action = "status" function status(self) return self.model.getstatus() end function view(self) return self.model.getconfigobjects(self, self.clientdata.filename, sessiondata.userinfo.userid) end function startstop(self) return controllerfunctions.handle_startstop(self, self.model.startstop_service, self.clientdata) end function config(self) return controllerfunctions.handle_form(self, self.model.getconfig, function(value) return self.model.setconfig(self, value) end, self.clientdata, "Save", "Edit Configuration", "Configuration Saved") end function newfile(self) return controllerfunctions.handle_form(self, self.model.getnewconfigfile, function(value) return self.model.createconfigfile(self, value, sessiondata.userinfo.userid) end, self.clientdata, "Create", "Create New Config File", "Config File Created") end function listfiles(self) local configfiles = self.model.getfilelist(self, sessiondata.userinfo.userid) local config = {} for k,v in pairs(configfiles.value) do local filedetails = self.model.get_filedetails(self, v, sessiondata.userinfo.userid) table.insert(config,filedetails) end return cfe({ type="list", value=config, label="Config files" }) end function edit(self) return editfile(self) end function editfile(self) config = controllerfunctions.handle_form(self, function() return self.model.get_filedetails(self, self.clientdata.filename, sessiondata.userinfo.userid) end, function(value) return self.model.set_filedetails(self, value, sessiondata.userinfo.userid) end, self.clientdata, "Save", "Edit Config File", "Config File Saved") if self.clientdata.linenumber and validator.is_integer(self.clientdata.linenumber) then config.value.filecontent.linenumber = self.clientdata.linenumber end return config end function delete(self) return self:redirect_to_referrer(self.model.remove_file(self, self.clientdata.filename, sessiondata.userinfo.userid)) end function listpermissions(self) return self.model:getpermissionslist() end function edituserpermissions(self) return controllerfunctions.handle_form(self, function() return self.model:getuserpermissions(self.clientdata.userid) end, function(value) return self.model:setuserpermissions(value) end, self.clientdata, "Save", "Edit User Permissions", "User permissions set") end function editrolepermissions(self) return controllerfunctions.handle_form(self, function() return self.model:getrolepermissions(self.clientdata.role) end, function(value) return self.model:setrolepermissions(value) end, self.clientdata, "Save", "Edit Role Permissions", "Role permissions set") end