All mysql_-statments replaced by their corresponding mysqli_-statements
[cacert-devel.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 = mysqli_query($_SESSION['mconn'], $query);
25 if(mysqli_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 = mysqli_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 if($row['keytype'] == "VI"){
56 showheader(_("My CAcert.org Account!"));
57 echo "<pre>".$cert."</pre>";
58 showfooter();
59 } else {
60 showheader(_("My CAcert.org Account!"));
61 ?>
62 <h3><?=_("Installing your certificate")?></h3>
63
64 <p><?=_("Hit the 'Install your Certificate' button below to install the certificate into MS IE 5.x and above.")?>
65
66 <OBJECT classid="clsid:127698e4-e730-4e5c-a2b1-21490a70c8a1" codebase="/xenroll.cab#Version=5,131,3659,0" id="cec">
67 <?=_("You must enable ActiveX for this to work.")?>
68 </OBJECT>
69 <FORM >
70 <INPUT TYPE=BUTTON NAME="CertInst" VALUE="<?=_("Install Your Certificate")?>">
71 </FORM>
72
73 </P>
74
75 <SCRIPT LANGUAGE=VBS>
76 Sub CertInst_OnClick
77 certchain = _
78 <?
79 $lines = explode("\n", $cert);
80 if(is_array($lines))
81 foreach($lines as $line)
82 {
83 $line = trim($line);
84 if($line != "-----END CERTIFICATE-----")
85 echo "\"$line\" & _\n";
86 else {
87 echo "\"$line\"\n";
88 break;
89 }
90 }
91 ?>
92
93 On Error Resume Next
94 cec.DeleteRequestCert = FALSE
95 err.clear
96
97 cec.WriteCertToCSP = TRUE
98 cec.acceptPKCS7(certchain)
99 if err.number <> 0 Then
100 cec.WriteCertToCSP = FALSE
101 end if
102 err.clear
103 cec.acceptPKCS7(certchain)
104 if err.number <> 0 then
105 errorMsg = "<?=_("Certificate installation failed!")?>" & chr(13) & chr(10) & _
106 "(Error code " & err.number & ")"
107 msgRes = MsgBox(errorMsg, 0, "<?=_("Certificate Installation Error")?>")
108 else
109 okMsg = "<?=_("Personal Certificate Installed.")?>" & chr(13) & chr(10) & _
110 "See Tools->Internet Options->Content->Certificates"
111 msgRes = MsgBox(okMsg, 0, "<?=_("Certificate Installation Complete!")?>")
112 end if
113 End Sub
114 </SCRIPT>
115
116 <?
117 showfooter();
118 exit;
119 }
120 ?>