84554998eb746754de47e11e0dfc7c3be82a7fc0
[cacert.git] / pages / account / 6.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 // Get certificate information
20 $certid = 0;
21 if(array_key_exists('cert',$_REQUEST)) {
22 $certid = intval($_REQUEST['cert']);
23 }
24
25 $query = "select UNIX_TIMESTAMP(`emailcerts`.`created`) as `created`,
26 UNIX_TIMESTAMP(`emailcerts`.`expire`) - UNIX_TIMESTAMP() as `timeleft`,
27 UNIX_TIMESTAMP(`emailcerts`.`expire`) as `expired`,
28 `emailcerts`.`expire` as `expires`,
29 `emailcerts`.`revoked` as `revoke`,
30 UNIX_TIMESTAMP(`emailcerts`.`revoked`) as `revoked`,
31 `emailcerts`.`id`,
32 `emailcerts`.`CN`,
33 `emailcerts`.`serial`,
34 `emailcerts`.`disablelogin` as `disablelogin`,
35 `emailcerts`.`crt_name`,
36 `emailcerts`.`keytype`,
37 `emailcerts`.`description`
38 from `emailcerts`
39 where `emailcerts`.`id`='$certid' and
40 `emailcerts`.`memid`='".intval($_SESSION['profile']['id'])."'";
41
42 $res = mysql_query($query);
43 if(mysql_num_rows($res) <= 0) {
44 showheader(_("My CAcert.org Account!"));
45 echo _("No such certificate attached to your account.");
46 showfooter();
47 exit;
48 }
49 $row = mysql_fetch_assoc($res);
50
51
52 if (array_key_exists('format', $_REQUEST)) {
53 // Which output format?
54 if ($_REQUEST['format'] === 'der') {
55 $outform = '-outform DER';
56 $extension = 'cer';
57 } else {
58 $outform = '-outform PEM';
59 $extension = 'crt';
60 }
61
62 $crtname=escapeshellarg($row['crt_name']);
63 $cert = `/usr/bin/openssl x509 -in $crtname $outform`;
64
65 header("Content-Type: application/pkix-cert");
66 header("Content-Length: ".strlen($cert));
67
68 $fname = sanitizeFilename($row['CN']);
69 if ($fname=="") $fname="certificate";
70 header("Content-Disposition: attachment; filename=\"${fname}.${extension}\"");
71
72 echo $cert;
73 exit;
74
75 } elseif (array_key_exists('install', $_REQUEST)) {
76 if (array_key_exists('HTTP_USER_AGENT',$_SERVER) &&
77 strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
78
79 // Handle IE
80 //TODO
81
82 } else {
83 // All other browsers
84 $crtname=escapeshellarg($row['crt_name']);
85 $cert = `/usr/bin/openssl x509 -in $crtname -outform DER`;
86
87 header("Content-Type: application/x-x509-user-cert");
88 header("Content-Length: ".strlen($cert));
89
90 $fname = sanitizeFilename($row['CN']);
91 if ($fname=="") $fname="certificate";
92 header("Content-Disposition: inline; filename=\"${fname}.cer\"");
93
94 echo $cert;
95 exit;
96 }
97
98 } else {
99 showheader(_("My CAcert.org Account!"), _("Install your certificate"));
100 echo '<ul class="no_indent">';
101 echo "<li><a href='account.php?id=$id&amp;cert=$certid&amp;install'>".
102 _("Install the certificate into your browser").
103 "</a></li>\n";
104
105 echo "<li><a href='account.php?id=$id&amp;cert=$certid&amp;format=pem'>".
106 _("Download the certificate in PEM format")."</a></li>\n";
107
108 echo "<li><a href='account.php?id=$id&amp;cert=$certid&amp;format=der'>".
109 _("Download the certificate in DER format")."</a></li>\n";
110 echo '</ul>';
111
112 // Allow to directly copy and paste the cert in PEM format
113 $crtname=escapeshellarg($row['crt_name']);
114 $cert = `/usr/bin/openssl x509 -in $crtname -outform PEM`;
115 echo "<pre>$cert</pre>";
116
117 ?>
118 <table align="center" valign="middle" border="0" cellspacing="0" cellpadding="0" class="wrapper">
119 <tr>
120 <td colspan="2" class="title"><?=_("Information about the certificate")?></td>
121 </tr>
122 <?
123 if($row['timeleft'] > 0)
124 $verified = _("Valid");
125 if($row['timeleft'] < 0)
126 $verified = _("Expired");
127 if($row['expired'] == 0)
128 $verified = _("Pending");
129 if($row['revoked'] > 0)
130 $verified = _("Revoked");
131 if($row['revoked'] == 0)
132 $row['revoke'] = _("Not Revoked");
133 ?>
134 <tr>
135 <td class="DataTD"><?=_("Status")?></td>
136 <td class="DataTD"><?=$verified?></td>
137 </tr>
138 <tr>
139 <td class="DataTD"><?=_("Email Address")?></td>
140 <td class="DataTD"><?=(trim($row['CN'])=="" ? _("empty") : $row['CN'])?></td>
141 </tr>
142 <tr>
143 <td class="DataTD"><?=_("SerialNumber")?></td>
144 <td class="DataTD"><?=$row['serial']?></td>
145 </tr>
146 <tr>
147 <td class="DataTD"><?=_("Revoked")?></td>
148 <td class="DataTD"><?=$row['revoke']?></td>
149 </tr>
150 <tr>
151 <td class="DataTD"><?=_("Expires")?></td>
152 <td class="DataTD"><?=$row['expires']?></td>
153 </tr>
154 <tr>
155 <td class="DataTD"><?=_("Login")?></td>
156 <td class="DataTD">
157 <input type="checkbox" name="disablelogin" disabled="disabled" value="1" <?=$row['disablelogin']?"":"checked='checked'"?>/>
158 </td>
159 </tr>
160 <tr>
161 <td class="DataTD"><?=_("Comment")?></td>
162 <td class="DataTD"><?=htmlspecialchars($row['description'])?></td>
163 </tr>
164 </table>
165 <?
166 showfooter();
167 exit;
168 }