Commit 14e744ed authored by Ted Trask's avatar Ted Trask

Removed redirect_to_referrer and changed viewcert to a form

parent 17afeb7c
......@@ -27,7 +27,7 @@ function listcerts(self)
end
function deletecert(self)
return self:redirect_to_referrer(self.model.delete_cert(self.clientdata.cert))
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)
......@@ -35,5 +35,5 @@ function uploadcert (self)
end
function viewcert(self)
return self.model.view_cert(self.clientdata.cert)
return self.handle_form(self, self.model.get_view_cert, self.model.view_cert, self.clientdata, "View", "View Certificate")
end
......@@ -15,9 +15,9 @@
<% for i,cert in ipairs(view.value) do %>
<TR>
<TD style="padding-right:20px;white-space:nowrap;">
<%= html.link{value=page_info.script..page_info.prefix..page_info.controller.."/deletecert?cert="..cert.."&redir="..page_info.orig_action, label="Delete "} %>
<%= html.link{value=page_info.script..page_info.prefix..page_info.controller.."/deletecert?submit=true&cert="..cert, label="Delete "} %>
<% if not string.find(cert, "%-key") then %>
<%= html.link{value=page_info.script..page_info.prefix..page_info.controller.."/viewcert?cert="..cert.."&redir="..page_info.orig_action, label="View "} %>
<%= html.link{value=page_info.script..page_info.prefix..page_info.controller.."/viewcert?cert="..cert, label="View "} %>
<% end %>
</TD>
<TD style="white-space:nowrap;"><%= html.html_escape(cert) %></TD>
......
......@@ -163,18 +163,25 @@ function list_certs()
return cfe({ type="list", value=list, label="IPSEC Certificates" })
end
function delete_cert(certname)
function 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()
local retval = cfe({ label="Delete Certificate result", errtxt="Invalid cert name" })
delcert.value.cert.errtxt = "Invalid cert name"
delcert.errtxt = "Failed to delete Certificate"
for i,cert in ipairs(list.value) do
if cert == certname then
os.remove(baseurl..certname)
retval.value = "Certificate deleted"
retval.errtxt = nil
if cert == delcert.value.cert.value then
os.remove(baseurl..cert)
delcert.value.cert.errtxt = nil
delcert.errtxt = nil
break
end
end
return retval
return delcert
end
function new_upload_cert()
......@@ -260,16 +267,27 @@ function upload_cert(self, newcert)
return newcert
end
view_cert = function(certname)
function 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()
local cmdresult = "Invalid cert name"
viewcert.value.cert.errtxt = "Invalid cert name"
viewcert.errtxt = "Failed to find cert"
for i,cert in ipairs(list.value) do
if cert == certname then
local cmd = path .. "openssl x509 -in "..baseurl..format.escapespecialcharacters(certname).." -noout -text"
if cert == viewcert.value.cert.value then
local cmd = path .. "openssl x509 -in "..baseurl..format.escapespecialcharacters(cert).." -noout -text"
local f = io.popen(cmd)
cmdresult = f:read("*a")
local cmdresult = f:read("*a")
f:close()
viewcert.value.result = cfe({ type="longtext", value=cmdresult, label="Certificate", readonly=true })
viewcert.errtxt = nil
viewcert.value.cert.errtxt = nil
break
end
end
return cfe({ type="table", value={name=certname, value=cmdresult}, label="Certificate" })
return viewcert
end
<% local view, viewlibrary = ... %>
<% local view, viewlibrary, page_info, session = ... %>
<% require("htmlviewfunctions") %>
<% if view.value.result then %>
<H1>Certificate Details</H1>
<pre><%= html.html_escape(view.value.value) %></pre>
<% htmlviewfunctions.displayitem(view.value.cert, 1, page_info) %>
<pre><%= html.html_escape(view.value.result.value) %></pre>
<% else
htmlviewfunctions.displayitem(view, 1, page_info)
end %>
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