Commit 8e520ca7 authored by Ted Trask's avatar Ted Trask

Remove all calls to 'module' in preparation for move to Lua 5.2

Use mymodule parameter for module definition.
This was also helpful in revealing places where the code relied on the global environment.
parent 2e549160
module(..., package.seeall)
local mymodule = {}
default_action = "status"
mymodule.default_action = "status"
function status(self)
function mymodule.status(self)
return self.model.getstatus()
end
function startstop(self)
function mymodule.startstop(self)
return self.handle_form(self, self.model.get_startstop, self.model.startstop_service, self.clientdata)
end
function details(self)
function mymodule.details(self)
return self.model.getstatusdetails()
end
function editracoon (self)
function mymodule.editracoon (self)
return self.handle_form(self, self.model.get_racoonfiledetails, self.model.update_racoonfiledetails, self.clientdata, "Save", "Edit Racoon Config", "Configuration Set")
end
function editipsec (self)
function mymodule.editipsec (self)
return self.handle_form(self, self.model.get_ipsecfiledetails, self.model.update_ipsecfiledetails, self.clientdata, "Save", "Edit IPSec Config", "Configuration Set")
end
function listcerts(self)
function mymodule.listcerts(self)
return self.model.list_certs()
end
function deletecert(self)
function mymodule.deletecert(self)
return self.handle_form(self, self.model.get_delete_cert, self.model.delete_cert, self.clientdata, "Delete", "Delete Certificate", "Certificate Deleted")
end
function uploadcert (self)
function mymodule.uploadcert (self)
return self.handle_form(self, self.model.new_upload_cert, self.model.upload_cert, self.clientdata, "Upload", "Upload Certificate", "Certificate Uploaded")
end
function viewcert(self)
function mymodule.viewcert(self)
return self.handle_form(self, self.model.get_view_cert, self.model.view_cert, self.clientdata, "View", "View Certificate")
end
return mymodule
module(..., package.seeall)
local mymodule = {}
-- Load libraries
posix = require("posix")
......@@ -109,19 +109,19 @@ end
-- ################################################################################
-- PUBLIC FUNCTIONS
function get_startstop(self, clientdata)
function mymodule.get_startstop(self, clientdata)
return modelfunctions.get_startstop(processname)
end
function startstop_service(self, startstop, action)
function mymodule.startstop_service(self, startstop, action)
return modelfunctions.startstop_service(startstop, action)
end
function getstatus()
function mymodule.getstatus()
return modelfunctions.getstatus(processname, packagename, "Racoon Status")
end
function getstatusdetails()
function mymodule.getstatusdetails()
local status = {}
status.show_isakmp = cfe({ type="list", value=racoonctl_table(), label="Tunnels" })
status.ip_xfrm_policy = cfe({ type="longtext", label="ip xfrm policy" })
......@@ -130,23 +130,23 @@ function getstatusdetails()
return cfe({ type="group", value=status, label="Racoon Status Details" })
end
function get_racoonfiledetails()
function mymodule.get_racoonfiledetails()
return modelfunctions.getfiledetails(configfile)
end
function update_racoonfiledetails(self, filedetails)
function mymodule.update_racoonfiledetails(self, filedetails)
return modelfunctions.setfiledetails(self, filedetails, {configfile})
end
function get_ipsecfiledetails()
function mymodule.get_ipsecfiledetails()
return modelfunctions.getfiledetails(configfile2)
end
function update_ipsecfiledetails(self, filedetails)
function mymodule.update_ipsecfiledetails(self, filedetails)
return modelfunctions.setfiledetails(self, filedetails, {configfile2})
end
function list_certs()
function mymodule.list_certs()
local list = {}
for file in fs.find(".*%.pem", baseurl) do
list[#list+1] = posix.basename(file)
......@@ -154,14 +154,14 @@ function list_certs()
return cfe({ type="list", value=list, label="IPSEC Certificates" })
end
function get_delete_cert(self, clientdata)
function mymodule.get_delete_cert(self, clientdata)
local retval = {}
retval.cert = cfe({ value=clientdata.cert or "", label="IPSEC Certificate" })
return cfe({ type="group", value=retval, label="Delete Certificate" })
end
function delete_cert(self, delcert)
local list = list_certs()
function mymodule.delete_cert(self, delcert)
local list = mymodule.list_certs()
delcert.value.cert.errtxt = "Invalid cert name"
delcert.errtxt = "Failed to delete Certificate"
for i,cert in ipairs(list.value) do
......@@ -175,7 +175,7 @@ function delete_cert(self, delcert)
return delcert
end
function new_upload_cert()
function mymodule.new_upload_cert()
local value = {}
value.cert = cfe({ type="raw", value=0, label="Certificate", descr='File must be a password protected ".pfx" file' })
value.password = cfe({ label="Certificate Password" })
......@@ -183,7 +183,7 @@ function new_upload_cert()
return cfe({ type="group", value=value })
end
function upload_cert(self, newcert)
function mymodule.upload_cert(self, newcert)
local success = true
-- Trying to upload a cert/key
-- The way haserl works, cert contains the temporary file name
......@@ -249,14 +249,14 @@ function upload_cert(self, newcert)
return newcert
end
function get_view_cert(self, clientdata)
function mymodule.get_view_cert(self, clientdata)
local retval = {}
retval.cert = cfe({ value=clientdata.cert or "", label="IPSEC Certificate" })
return cfe({ type="group", value=retval, label="View Certificate" })
end
view_cert = function(self, viewcert)
local list = list_certs()
mymodule.view_cert = function(self, viewcert)
local list = mymodule.list_certs()
viewcert.value.cert.errtxt = "Invalid cert name"
viewcert.errtxt = "Failed to find cert"
for i,cert in ipairs(list.value) do
......@@ -270,3 +270,5 @@ view_cert = function(self, viewcert)
end
return viewcert
end
return mymodule
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment