From 3459e6bf19a13f35e419b0adabf8c3456a0a5025 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Tue, 25 Nov 2008 19:27:55 +0000 Subject: Rewrite of openvpn to use cfes and new style. Added ability to edit/create/delete configs. Combined three view functions into one. Added a new status and moved old status to listconfigs. Still needs work, including ability to start/stop/restart. git-svn-id: svn://svn.alpinelinux.org/acf/openvpn/trunk@1611 ab2d0c66-481e-0410-8bed-d214d4d58bed --- openvpn-controller.lua | 62 +++++++++++++++----------------------------------- 1 file changed, 18 insertions(+), 44 deletions(-) (limited to 'openvpn-controller.lua') diff --git a/openvpn-controller.lua b/openvpn-controller.lua index 54a28e2..047e7df 100644 --- a/openvpn-controller.lua +++ b/openvpn-controller.lua @@ -1,63 +1,37 @@ --- the hostname controller - module (..., package.seeall) +require("controllerfunctions") + default_action = "status" status = function (self) - -- FIXME: If return 1 rows go direct to that config-page - return ( {conflistfiles = self.model:get_conflist(), url = self.conf.script .. self.conf.prefix .. self.conf.controller, version = self.model:openvpn_version()} ) + return self.model.getstatus() +end + +listconfigs = function (self) + return self.model.get_conflist() end +editconfig = function (self) + return controllerfunctions.handle_form(self, function() return self.model.get_filecontent(self.clientdata.name) end, self.model.update_filecontent, self.clientdata, "Save", "Edit Config File", "Config File Saved") +end -serverconfig = function (self) - local configname = self.clientdata.name or "" - return ( {config = self.model:get_config(configname), url = self.conf.script .. self.conf.prefix .. self.conf.controller} ) +createconfig = function ( self ) + return controllerfunctions.handle_form(self, self.model.create_new_config, self.model.create_config, self.clientdata, "Create", "Create new config", "New config Created") end -clientconfig = function (self) - local configname = self.clientdata.name or "" - return ( {config = self.model:get_config(configname), url = self.conf.script .. self.conf.prefix .. self.conf.controller} ) +deleteconfig = function(self) + return self:redirect_to_referrer(self.model.delete_config(self.clientdata.name)) end -peminfo = function (self) +viewconfig = function(self) + return self.model.get_config(self.clientdata.name) end statusinfo = function (self) - local configname = self.clientdata.name or "" - return ( {clientlist = self.model:clientlist(configname), url = self.conf.script .. self.conf.prefix .. self.conf.controller} ) -end - -unknownconfig = function (self) - local filename = self.clientdata.name or "" - local filecontent = self.clientdata.modifications or "" - ----[[ - if ( filecontent ~= "") then - local me = ( {configfilecontent = self.model:update_filecontent(filename,filecontent), url = self.conf.script .. self.conf.prefix .. self.conf.controller } ) - if ( me.configfilecontent == nil ) then - redirect(self) - else - return me - end - else ----[=[ - local me = ( {configfilecontent = self.model:get_filecontent(filename), url = self.conf.script .. self.conf.prefix .. self.conf.controller } ) - if ( me.configfilecontent == nil ) then - redirect(self) - else - return me - end ---]=] --- return ( {configfilecontent = self.model:get_filecontent(filename), url = self.conf.script .. self.conf.prefix .. self.conf.controller} ) - - end ---]] - + return self.model.getclientinfo(self.clientdata.name) end logfile = function (self) - local configname = self.clientdata.name or "" - -- FIXME: If return 0 rows, goto read - return ( {logfilecontent = self.model:get_logfile(configname), url = self.conf.script .. self.conf.prefix .. self.conf.controller } ) + return self.model.get_logfile(self.clientdata.name) end -- cgit v1.2.3