bug 1239: fixed typo for title
[cacert-devel.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 <form method="post" action="account.php">
119 <table align="center" valign="middle" border="0" cellspacing="0" cellpadding="0" class="wrapper">
120 <tr>
121 <td colspan="2" class="title"><?=_("Information about the certificate")?></td>
122 </tr>
123 <?
124 if($row['timeleft'] > 0)
125 $verified = _("Valid");
126 if($row['timeleft'] < 0)
127 $verified = _("Expired");
128 if($row['expired'] == 0)
129 $verified = _("Pending");
130 if($row['revoked'] > 0)
131 $verified = _("Revoked");
132 if($row['revoked'] == 0)
133 $row['revoke'] = _("Not Revoked");
134 ?>
135 <tr>
136 <td class="DataTD"><?=_("Renew/Revoke/Delete")?></td>
137 <? if($verified != _("Pending") && $verified != _("Revoked")) { ?>
138 <td class="DataTD"><input type="checkbox" name="revokeid[<?=$row['id']?>]" ></td>
139 <? } else if($verified != _("Revoked")) { ?>
140 <td class="DataTD"><input type="checkbox" name="delid[<?=$row['id']?>]"></td>
141 <? } else { ?>
142 <td class="DataTD">&nbsp;</td>
143 <? } ?>
144 </tr>
145 <tr>
146 <td class="DataTD"><?=_("Status")?></td>
147 <td class="DataTD"><?=$verified?></td>
148 </tr>
149 <tr>
150 <td class="DataTD"><?=_("Email Address")?></td>
151 <td class="DataTD"><?=(trim($row['CN'])=="" ? _("empty") : $row['CN'])?></td>
152 </tr>
153 <tr>
154 <td class="DataTD"><?=_("SerialNumber")?></td>
155 <td class="DataTD"><?=$row['serial']?></td>
156 </tr>
157 <tr>
158 <td class="DataTD"><?=_("Revoked")?></td>
159 <td class="DataTD"><?=$row['revoke']?></td>
160 </tr>
161 <tr>
162 <td class="DataTD"><?=_("Expires")?></td>
163 <td class="DataTD"><?=$row['expires']?></td>
164 </tr>
165 <tr>
166 <td class="DataTD"><?=_("Login")?></td>
167 <td class="DataTD">
168 <input type="checkbox" name="disablelogin" value="1" <?=$row['disablelogin']?"":"checked='checked'"?>/>
169 </td>
170 </tr>
171 <tr>
172 <td class="DataTD"><?=_("Comment")?></td>
173 <td class="DataTD"><input type="text" name="description" maxlength="100" size=100 value="<?=htmlspecialchars($row['description'])?>"></td>
174 </tr>
175 <tr>
176 <td class="DataTD" colspan="2"><input type="submit" name="change" value="<?=_("Change settings")?>"> </td>
177 </tr>
178 </table>
179 <input type="hidden" name="oldid" value="6">
180 <input type="hidden" name="certid" value="<?=$certid?>">
181 </form>
182
183 <?
184 showfooter();
185 exit;
186 }