959111fb2fd66c26322de0785c99aba1e0fab9c8
[cacert.git] / pages / account / 19.php
1 <? /*
2 LibreSSL - CAcert web application
3 Copyright (C) 2004-2008 CAcert Inc.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; version 2 of the License.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */ ?>
18 <?
19 $certid = 0; if(array_key_exists('cert',$_REQUEST)) $certid=intval($_REQUEST['cert']);
20
21 $query = "select * from `orgemailcerts`,`org` where `orgemailcerts`.`id`='".intval($certid)."' and
22 `org`.`memid`='".intval($_SESSION['profile']['id'])."' and
23 `org`.`orgid`=`orgemailcerts`.`orgid`";
24 $res = mysql_query($query);
25 if(mysql_num_rows($res) <= 0)
26 {
27 showheader(_("My CAcert.org Account!"));
28 echo _("No such certificate attached to your account.");
29 showfooter();
30 exit;
31 }
32 $row = mysql_fetch_assoc($res);
33 $crtname=escapeshellarg($row['crt_name']);
34 $cert = shell_exec("/usr/bin/openssl x509 -in $crtname");
35
36 if($row['keytype'] == "NS")
37 {
38 if(array_key_exists('install',$_REQUEST) && $_REQUEST['install'] == 1)
39 {
40 header("Content-Type: application/x-x509-user-cert");
41 header("Content-Length: ".strlen($cert));
42 $fname=sanitizeFilename($row['CN']);
43 if($fname=="") $fname="certificate";
44 header('Content-Disposition: inline; filename="'.$fname.'.crt"');
45 echo $cert;
46 exit;
47 } else {
48 showheader(_("My CAcert.org Account!"));
49 echo "<h3>"._("Installing your certificate")."</h3>\n";
50 echo "<p>"._("You are about to install a certificate, if you are using mozilla/netscape based browsers you will not be informed that the certificate was installed successfully, you can go into the options dialog box, security and manage certificates to view if it was installed correctly however.")."</p>\n";
51 echo "<p><a href='account.php?id=19&amp;cert=$certid&amp;install=1'>"._("Click here")."</a> "._("to install your certificate.")."</p>\n";
52 showfooter();
53 exit;
54 }
55 } else {
56 showheader(_("My CAcert.org Account!"));
57 ?>
58 <h3><?=_("Installing your certificate")?></h3>
59
60 <p><?=_("Hit the 'Install your Certificate' button below to install the certificate into MS IE 5.x and above.")?>
61
62 <OBJECT classid="clsid:127698e4-e730-4e5c-a2b1-21490a70c8a1" codebase="/xenroll.cab#Version=5,131,3659,0" id="cec">
63 <?=_("You must enable ActiveX for this to work.")?>
64 </OBJECT>
65 <FORM >
66 <INPUT TYPE=BUTTON NAME="CertInst" VALUE="<?=_("Install Your Certificate")?>">
67 </FORM>
68
69 </P>
70
71 <SCRIPT LANGUAGE=VBS>
72 Sub CertInst_OnClick
73 certchain = _
74 <?
75 $lines = explode("\n", $cert);
76 if(is_array($lines))
77 foreach($lines as $line)
78 {
79 $line = trim($line);
80 if($line != "-----END CERTIFICATE-----")
81 echo "\"$line\" & _\n";
82 else {
83 echo "\"$line\"\n";
84 break;
85 }
86 }
87 ?>
88
89 On Error Resume Next
90 cec.DeleteRequestCert = FALSE
91 err.clear
92
93 cec.WriteCertToCSP = TRUE
94 cec.acceptPKCS7(certchain)
95 if err.number <> 0 Then
96 cec.WriteCertToCSP = FALSE
97 end if
98 err.clear
99 cec.acceptPKCS7(certchain)
100 if err.number <> 0 then
101 errorMsg = "<?=_("Certificate installation failed!")?>" & chr(13) & chr(10) & _
102 "(Error code " & err.number & ")"
103 msgRes = MsgBox(errorMsg, 0, "<?=_("Certificate Installation Error")?>")
104 else
105 okMsg = "<?=_("Personal Certificate Installed.")?>" & chr(13) & chr(10) & _
106 "See Tools->Internet Options->Content->Certificates"
107 msgRes = MsgBox(okMsg, 0, "<?=_("Certificate Installation Complete!")?>")
108 end if
109 End Sub
110 </SCRIPT>
111
112 <?
113 showfooter();
114 exit;
115 }
116 ?>