diff options
author | Ted Trask <ttrask01@yahoo.com> | 2008-07-07 19:16:11 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2008-07-07 19:16:11 +0000 |
commit | 80b754148dd765622006cc602218c88307e42043 (patch) | |
tree | 9351cce3c811929981f37282dd8063c52f662b3a | |
parent | dbb622fd1e6c7621281bd14c7a6f88a6a3c7cd10 (diff) | |
download | acf-openssl-80b754148dd765622006cc602218c88307e42043.tar.bz2 acf-openssl-80b754148dd765622006cc602218c88307e42043.tar.xz |
Update openssl to use controllerfunctions and modelfunctions.
git-svn-id: svn://svn.alpinelinux.org/acf/openssl/trunk@1287 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r-- | openssl-checkenvironment-html.lsp | 6 | ||||
-rw-r--r-- | openssl-controller.lua | 131 | ||||
-rw-r--r-- | openssl-editconfigfile-html.lsp | 5 | ||||
-rw-r--r-- | openssl-editdefaults-html.lsp | 3 | ||||
-rw-r--r-- | openssl-generatecacert-html.lsp | 4 | ||||
-rw-r--r-- | openssl-html.lsp | 8 | ||||
-rw-r--r-- | openssl-model.lua | 138 | ||||
-rw-r--r-- | openssl-putcacert-html.lsp | 5 | ||||
-rw-r--r-- | openssl-request-html.lsp | 3 |
9 files changed, 107 insertions, 196 deletions
diff --git a/openssl-checkenvironment-html.lsp b/openssl-checkenvironment-html.lsp index 3775402..9b8848c 100644 --- a/openssl-checkenvironment-html.lsp +++ b/openssl-checkenvironment-html.lsp @@ -1,4 +1,4 @@ -<? local form, viewlibrary = ... ?> +<? local form, viewlibrary, page_info = ... ?> <? require("viewfunctions") ?> <? --[[ DEBUG INFORMATION @@ -9,7 +9,7 @@ io.write(html.cfe_unpack(form)) <DL> <? displayitem(form.value.status) ?> <? if form.value.status.errtxt then ?> -<form action="checkenvironment" method="POST"> -<DT><input class="submit" type="submit" name="<?= form.option ?>" value="<?= form.option ?>"></DT> +<form action="<?= page_info.script .. page_info.prefix .. page_info.controller .. "/" .. page_info.action ?>" method="POST"> +<DT></DT><DD><input class="submit" type="submit" name="<?= form.option ?>" value="<?= form.option ?>"></DD> <? end ?> </DL> diff --git a/openssl-controller.lua b/openssl-controller.lua index 2caa20f..83cdf9e 100644 --- a/openssl-controller.lua +++ b/openssl-controller.lua @@ -1,21 +1,12 @@ -- the openssl certificates controller module (..., package.seeall) -require("getopts") +require("controllerfunctions") default_action = "status" local sslstatus -local handle_req_clientdata = function(clientdata, defaults) - -- Put the user values into the table - for name,value in pairs(clientdata) do - if defaults.value[name] then - defaults.value[name].value = value - end - end -end - mvc={} mvc.pre_exec = function(self) sslstatus = self.model.getstatus() @@ -35,65 +26,31 @@ end -- View all pending and approved requests and revoked certificates readall = function(self) - local cmdresult = self.sessiondata.cmdresult - self.sessiondata.cmdresult = nil local pending = self.model.listrequests() local approved = self.model.listcerts() local revoked = self.model.listrevoked() - local result = cfe({ type="list", value={cmdresult=cmdresult, pending=pending, approved=approved, revoked=revoked} }) + local result = cfe({ type="list", value={pending=pending, approved=approved, revoked=revoked} }) return result end -- Return all certificates (pending, approved, and revoked) for this user read = function(self) - local cmdresult = self.sessiondata.cmdresult - self.sessiondata.cmdresult = nil local user = cfe({ value=self.sessiondata.userinfo.userid, label="User Name" }) local pending = self.model.listrequests(self.sessiondata.userinfo.userid) local approved = self.model.listcerts(self.sessiondata.userinfo.userid) local revoked = self.model.listrevoked() - local result = cfe({ type="list", value={cmdresult=cmdresult, user=user, pending=pending, approved=approved, revoked=revoked} }) + local result = cfe({ type="list", value={user=user, pending=pending, approved=approved, revoked=revoked} }) return result end -- Form to request a new cert request = function(self) - local request = self.model.getnewrequest() - if self.clientdata.Submit then - handle_req_clientdata(self.clientdata, request) - -- Try to submit the request - request = self.model.submitrequest(request, self.sessiondata.userinfo.userid) - if not request.errtxt then - cmdresult = cfe({ value="Request submitted", label="Request result" }) - self.sessiondata.cmdresult = cmdresult - --request.descr = "Submitted request" - redirect(self, "read") - end - end - - request.type = "form" - request.label = "Request Certificate" - request.option = "Submit" - - return request + return controllerfunctions.handle_form(self, self.model.getnewrequest, function(value) return self.model.submitrequest(value, self.sessiondata.userinfo.userid) end, self.clientdata, "Submit", "Request Certificate", "Request Submitted", "read") end -- Form to edit request defaults editdefaults = function(self) - local defaults = self.model.getreqdefaults() - if self.clientdata.Save then - handle_req_clientdata(self.clientdata, defaults) - defaults = self.model.setreqdefaults(defaults) - if not defaults.errtxt then - defaults.descr = "Defaults set" - end - end - - defaults.type = "form" - defaults.label = "Edit certificate defaults" - defaults.option = "Save" - - return defaults + return controllerfunctions.handle_form(self, self.model.getreqdefaults, self.model.setreqdefaults, self.clientdata, "Save", "Edit Certificate Defaults", "Defaults Set") end -- View request details @@ -103,23 +60,17 @@ end -- Approve the specified request approve = function(self) - local cmdresult = self.model.approverequest(self.clientdata.request) - self.sessiondata.cmdresult = cmdresult - redirect_to_referrer(self) + return self:redirect_to_referrer(self.model.approverequest(self.clientdata.request)) end -- Delete the specified request deleterequest = function(self) - local cmdresult = self.model.deleterequest(self.clientdata.request) - self.sessiondata.cmdresult = cmdresult - redirect_to_referrer(self) + return self:redirect_to_referrer(self.model.deleterequest(self.clientdata.request)) end -- Delete the specified request deletemyrequest = function(self) - local cmdresult = self.model.deleterequest(self.clientdata.request, self.sessiondata.userinfo.userid) - self.sessiondata.cmdresult = cmdresult - redirect_to_referrer(self) + return self:redirect_to_referrer(self.model.deleterequest(self.clientdata.request, self.sessiondata.userinfo.userid)) end -- View certificate details @@ -135,30 +86,22 @@ end -- Revoke the specified cert revoke = function(self) - local cmdresult = self.model.revokecert(self.clientdata.cert) - self.sessiondata.cmdresult = cmdresult - redirect_to_referrer(self) + return self:redirect_to_referrer(self.model.revokecert(self.clientdata.cert)) end -- Delete the specified certificate deletecert = function(self) - local cmdresult = self.model.deletecert(self.clientdata.cert) - self.sessiondata.cmdresult = cmdresult - redirect_to_referrer(self) + return self:redirect_to_referrer(self.model.deletecert(self.clientdata.cert)) end -- Submit request to renew the specified certificate requestrenewcert = function(self) - local cmdresult = self.model.renewcert(self.clientdata.cert) - self.sessiondata.cmdresult = cmdresult - redirect_to_referrer(self) + return self:redirect_to_referrer(self.model.renewcert(self.clientdata.cert)) end -- Renew the specified certificate renewcert = function(self) - local cmdresult = self.model.renewcert(self.clientdata.cert, true) - self.sessiondata.cmdresult = cmdresult - redirect_to_referrer(self) + return self:redirect_to_referrer(self.model.renewcert(self.clientdata.cert, true)) end -- Get the revoked list @@ -169,60 +112,24 @@ end -- Put the CA cert putcacert = function(self) - local retval = self.model.putca(self.clientdata.ca, self.clientdata.password, self.clientdata.Upload) - if self.clientdata.Upload then - if not retval.errtxt then - redirect(self) - end - end - retval.type = "form" - retval.label = "Upload CA Certificate" - retval.option = "Upload" - - return retval + return controllerfunctions.handle_form(self, self.model.getnewputca, self.model.putca, self.clientdata, "Upload", "Upload CA Certificate", "Certificate Uploaded", "status") end -- Generate a self-signed CA generatecacert = function(self) - local request = self.model.getnewcarequest() - if self.clientdata.Generate then - handle_req_clientdata(self.clientdata, request) - -- Try to submit the request - request = self.model.generateca(request) - if not request.errtxt then - redirect(self) - end - end - - request.type = "form" - request.label = "Generate CA Certificate" - request.option = "Generate" - - return request + return controllerfunctions.handle_form(self, self.model.getnewcarequest, self.model.generateca, self.clientdata, "Generate", "Gererate CA Certificate", "Certificate Generated", "status") end editconfigfile = function(self) - local saved = false - if self.clientdata.Save then - saved = self.model.setconfigfile(self.clientdata.filecontent) - end - local configfile = self.model.getconfigfile() - configfile.type = "form" - configfile.option = "Save" - configfile.label = "Edit config file" - if saved then - configfile.descr = "Saved config file" - elseif self.clientdata.Save then - configfile.errtxt = "Failed to save config file" - end - return configfile + return controllerfunctions.handle_form(self, self.model.getconfigfile, self.model.setconfigfile, self.clientdata, "Save", "Edit Config File", "Config File Saved") end checkenvironment = function(self) local form = cfe({ type="form", value={}, label="Check Environment", option="Configure" }) - form.value.status = self.model.checkenvironment(self.clientdata.Configure) - if self.clientdata.Configure and not form.value.status.errtxt then - redirect_to_referrer(self) + if self.clientdata.Configure then + form.value.status = self:redirect_to_referrer(self.model.checkenvironment(self.clientdata.Configure)) + else + form.value.status = self:redirect_to_referrer() or self.model.checkenvironment(self.clientdata.Configure) end return form end diff --git a/openssl-editconfigfile-html.lsp b/openssl-editconfigfile-html.lsp index 890909c..46f820b 100644 --- a/openssl-editconfigfile-html.lsp +++ b/openssl-editconfigfile-html.lsp @@ -18,12 +18,13 @@ displayitem(form.value.mtime) <H2>File Content</H1> <? if form.descr then ?><P CLASS='descr'><?= string.gsub(form.descr, "\n", "<BR>") ?></P><? end ?> <? if form.errtxt then ?><P CLASS='error'><?= string.gsub(form.errtxt, "\n", "<BR>") ?></P><? end ?> -<form action="" method="POST"> +<form action="<?= page_info.script .. page_info.prefix .. page_info.controller .. "/" .. page_info.action ?>" method="POST"> <textarea name="filecontent"> <?= form.value.filecontent.value ?> </textarea> +<? if form.value.filecontent.errtxt then ?><P CLASS='error'><?= string.gsub(form.value.filecontent.errtxt, "\n", "<BR>") ?></P><? end ?> -<DL><DT><input class="submit" type="submit" name="<?= form.option ?>" value="<?= form.option ?>"></DT></DL> +<DL><DT></DT><DD><input class="submit" type="submit" name="<?= form.option ?>" value="<?= form.option ?>"></DD></DL> </form> <? if viewlibrary and viewlibrary.dispatch_component and session.permissions.openssl.checkenvironment then diff --git a/openssl-editdefaults-html.lsp b/openssl-editdefaults-html.lsp index 46bc44a..e678ec4 100644 --- a/openssl-editdefaults-html.lsp +++ b/openssl-editdefaults-html.lsp @@ -1,4 +1,4 @@ -<? local form, viewlibrary = ... ?> +<? local form, viewlibrary, page_info = ... ?> <? require("viewfunctions") ?> <? --[[ DEBUG INFORMATION @@ -7,6 +7,7 @@ io.write(html.cfe_unpack(form)) <H1><?= form.label ?></H1> <? + form.action = page_info.script .. page_info.prefix .. page_info.controller .. "/" .. page_info.action local order = { "countryName", "stateOrProvinceName", "localityName", "organizationName", "organizationalUnitName", "commonName", "emailAddress", "certtype" } displayform(form, order) diff --git a/openssl-generatecacert-html.lsp b/openssl-generatecacert-html.lsp index 465f53f..3f251f5 100644 --- a/openssl-generatecacert-html.lsp +++ b/openssl-generatecacert-html.lsp @@ -1,4 +1,4 @@ -<? local form, viewlibrary = ... ?> +<? local form, viewlibrary, page_info = ... ?> <? require("viewfunctions") ?> <? --[[ DEBUG INFORMATION @@ -7,7 +7,7 @@ io.write(html.cfe_unpack(form)) <H1><?= form.label ?></H1> <? - form.action = "generatecacert" + form.action = page_info.script .. page_info.prefix .. page_info.controller .. "/" .. page_info.action local order = { "countryName", "stateOrProvinceName", "localityName", "organizationName", "organizationalUnitName", "commonName", "emailAddress" } displayform(form, order) diff --git a/openssl-html.lsp b/openssl-html.lsp index 97b4a97..abf71a7 100644 --- a/openssl-html.lsp +++ b/openssl-html.lsp @@ -1,4 +1,5 @@ <? local view, viewlibrary, pageinfo, session = ... ?> +<? require("viewfunctions") ?> <? --[[ DEBUG INFORMATION io.write(html.cfe_unpack(view)) @@ -15,12 +16,7 @@ io.write(html.cfe_unpack(view)) }); </script> -<? if view.value.cmdresult then ?> -<H1>Command Result</H1> -<DL> -<?= string.gsub(view.value.cmdresult.value, "\n", "<BR>") ?> -</DL> -<? end ?> +<? displaycommandresults({"approve", "deleterequest", "deletemyrequest", "renewcert", "requestrenewcert", "revoke", "deletecert"}, session) ?> <H1>Pending certificate requests<? if view.value.user then?> for <?= view.value.user.value ?><? end ?></H1> <? if not view.value.pending or #view.value.pending.value == 0 then ?> diff --git a/openssl-model.lua b/openssl-model.lua index 3d1f1f6..d0c669d 100644 --- a/openssl-model.lua +++ b/openssl-model.lua @@ -1,6 +1,7 @@ module(..., package.seeall) -require("html") +require("modelfunctions") +require("getopts") require("validator") -- There are two options of how to allow users to specify the type of certificate they want - the request extensions @@ -583,63 +584,69 @@ getcrl = function(crltype) return crlfile end -putca = function(file, pword, set) +getnewputca = function() local ca = cfe({ type="raw", value=0, label="CA Certificate", descr='File must be a password protected ".pfx" file' }) local password = cfe({ label="Certificate Password" }) - local retval = cfe({ type="group", value={ca=ca, password=password} }) - if file and pword and set then - local success = true - -- Trying to upload a cert/key - -- The way haserl works, file contains the temporary file name - -- First, get the cert - local cmd = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin openssl pkcs12 -in "..file.." -out "..file.."cert.pem -password pass:"..pword.." -nokeys 2>&1" - local f = io.popen(cmd) - local cmdresult = f:read("*a") + return cfe({ type="group", value={ca=ca, password=password} }) +end + +putca = function(newca) + local success = true + -- Trying to upload a cert/key + -- The way haserl works, ca contains the temporary file name + -- First, get the cert + local cmd = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin openssl pkcs12 -in "..newca.value.ca.value.." -out "..newca.value.ca.value.."cert.pem -password pass:"..newca.value.password.value.." -nokeys 2>&1" + local f = io.popen(cmd) + local cmdresult = f:read("*a") + f:close() + local filestats = posix.stat(newca.value.ca.value.."cert.pem") + if not filestats or filestats.size == 0 then + newca.value.ca.errtxt = "Could not open certificate\n"..cmdresult + success = false + end + + -- Since -cacerts doesn't seem to work, we have to check to make sure we got a CA + if success then + cmd = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin openssl x509 -in "..newca.value.ca.value.."cert.pem -noout -text" + f = io.popen(cmd) + cmdresult = f:read("*a") f:close() - local filestats = posix.stat(file.."cert.pem") - if not filestats or filestats.size == 0 then - ca.errtxt = "Could not open certificate\n"..cmdresult + if not string.find(cmdresult, "CA:TRUE") then + newca.value.ca.errtxt = "Could not find CA Certificate" success = false end - - -- Since -cacerts doesn't seem to work, we have to check to make sure we got a CA - if success then - cmd = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin openssl x509 -in "..file.."cert.pem -noout -text" - f = io.popen(cmd) - cmdresult = f:read("*a") - f:close() - if not string.find(cmdresult, "CA:TRUE") then - ca.errtxt = "Could not find CA Certificate" - success = false - end - end + end - -- Now, get the key - if success then - cmd = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin openssl pkcs12 -in "..file.." -out "..file.."key.pem -password pass:"..pword.." -nocerts -nodes 2>&1" - f = io.popen(cmd) - cmdresult = f:read("*a") - f:close() - filestats = posix.stat(file.."key.pem") - if not filestats or filestats.size == 0 then - ca.errtxt = "Could not find CA key\n"..cmdresult - success = false - end - end - - if success then - -- copy the keys - copyca(file.."cert.pem", file.."key.pem") - else - retval.errtxt = "Failed to upload CA certificate" - end - - -- Delete the temporary files - cmd = "rm "..file.."*" + -- Now, get the key + if success then + cmd = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin openssl pkcs12 -in "..newca.value.ca.value.." -out "..newca.value.ca.value.."key.pem -password pass:"..newca.value.password.value.." -nocerts -nodes 2>&1" f = io.popen(cmd) + cmdresult = f:read("*a") f:close() + filestats = posix.stat(newca.value.ca.value.."key.pem") + if not filestats or filestats.size == 0 then + newca.value.ca.errtxt = "Could not find CA key\n"..cmdresult + success = false + end end - return retval + + if success then + -- copy the keys + copyca(newca.value.ca.value.."cert.pem", newca.value.ca.value.."key.pem") + else + newca.errtxt = "Failed to upload CA certificate" + end + + -- Delete the temporary files + cmd = "rm "..newca.value.ca.value.."*" + f = io.popen(cmd) + f:close() + + -- Clear the values + newca.value.ca.value = "" + newca.value.password.value = "" + + return newca end getnewcarequest = function() @@ -690,28 +697,25 @@ generateca = function(defaults) end getconfigfile = function() - local filename = cfe({ value=configfile, label="File Name" }) - local filecontent = cfe({ type="longtext", label="Config file" }) - local filesize = cfe({ value="0", label="File size" }) - local mtime = cfe({ value="---", label="File date" }) - if fs.is_file(configfile) then - local filedetails = fs.stat(configfile) - filecontent.value=fs.read_file(configfile) - filesize.value = filedetails.size - mtime.value = filedetails.mtime - else - filename.errtxt = "File not found" - end - return cfe({ type="group", value={filename=filename, filecontent=filecontent, filesize=filesize, mtime=mtime}, label="Config file details" }) + return modelfunctions.getfiledetails(configfile) end -setconfigfile = function(file) - if file and type(file)=="string" and #file>0 then - fs.write_file(configfile, file) +setconfigfile = function(filedetails) + filedetails.value.filename.value = configfile + filedetails.value.filecontent.value = string.gsub(format.dostounix(filedetails.value.filecontent.value), "\n+$", "") + + -- validate + local success = true + + if success then + fs.write_file(configfile, filedetails.value.filecontent.value) + filedetails = getconfigfile() config = nil - return true + else + filedetails.errtxt = "Failed to set configuration file" end - return false + + return filedetails end checkenvironment = function(set) diff --git a/openssl-putcacert-html.lsp b/openssl-putcacert-html.lsp index ed3ab02..2a2cfb7 100644 --- a/openssl-putcacert-html.lsp +++ b/openssl-putcacert-html.lsp @@ -1,4 +1,4 @@ -<? local form = ... ?> +<? local form, viewlibrary, page_info = ... ?> <? require("viewfunctions") ?> <? --[[ DEBUG INFORMATION @@ -7,7 +7,8 @@ io.write(html.cfe_unpack(form)) <H1><?= form.label ?></H1> <? - form.action = 'putcacert" enctype="multipart/form-data' + -- This is a kludge to get file upload working + form.action = page_info.script .. page_info.prefix .. page_info.controller .. "/" .. page_info.action .. '" enctype="multipart/form-data' form.value.ca.type="file" form.value.password.type="password" local order = {"ca", "password"} diff --git a/openssl-request-html.lsp b/openssl-request-html.lsp index ea0655a..ff27023 100644 --- a/openssl-request-html.lsp +++ b/openssl-request-html.lsp @@ -1,4 +1,4 @@ -<? local form, viewlibrary = ... ?> +<? local form, viewlibrary, page_info = ... ?> <? require("viewfunctions") ?> <? --[[ DEBUG INFORMATION @@ -7,6 +7,7 @@ io.write(html.cfe_unpack(form)) <H1><?= form.label ?></H1> <? + form.action = page_info.script .. page_info.prefix .. page_info.controller .. "/" .. page_info.action local order = { "countryName", "stateOrProvinceName", "localityName", "organizationName", "organizationalUnitName", "commonName", "emailAddress", "certtype", "password", "password_confirm" } |