bug 782: Actually show the expiry date not the revocation date
[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 $certid = 0; if(array_key_exists('cert',$_REQUEST)) $certid=intval($_REQUEST['cert']);
20
21 // $query = "select * from `emailcerts` where `id`='$certid' and `memid`='".intval($_SESSION['profile']['id'])."'";
22 $query = "select UNIX_TIMESTAMP(`emailcerts`.`created`) as `created`,
23 UNIX_TIMESTAMP(`emailcerts`.`expire`) - UNIX_TIMESTAMP() as `timeleft`,
24 UNIX_TIMESTAMP(`emailcerts`.`expire`) as `expired`,
25 `emailcerts`.`expire` as `expires`,
26 `emailcerts`.`revoked` as `revoke`,
27 UNIX_TIMESTAMP(`emailcerts`.`revoked`) as `revoked`,
28 `emailcerts`.`id`,
29 `emailcerts`.`CN`,
30 `emailcerts`.`serial`,
31 `emailcerts`.`disablelogin` as `disablelogin`,
32 `emailcerts`.`crt_name`,
33 `emailcerts`.`keytype`,
34 `emailcerts`.`description`
35 from `emailcerts`
36 where `emailcerts`.`id`='$certid' and `emailcerts`.`memid`='".intval($_SESSION['profile']['id'])."'";
37
38
39 $res = mysql_query($query);
40 if(mysql_num_rows($res) <= 0)
41 {
42 showheader(_("My CAcert.org Account!"));
43 echo _("No such certificate attached to your account.");
44 showfooter();
45 exit;
46 }
47 $row = mysql_fetch_assoc($res);
48
49 $crtname=escapeshellarg($row['crt_name']);
50 $cert = `/usr/bin/openssl x509 -in $crtname`;
51
52 if($row['keytype'] == "NS")
53 {
54 if(array_key_exists('install',$_REQUEST) && $_REQUEST['install'] == 1)
55 {
56 header("Content-Type: application/x-x509-user-cert");
57 header("Content-Length: ".strlen($cert));
58 $fname=sanitizeFilename($row['CN']);
59 if($fname=="") $fname="certificate";
60 header('Content-Disposition: inline; filename="'.$fname.'.crt"');
61 echo $cert;
62 exit;
63 } else {
64 showheader(_("My CAcert.org Account!"));
65 echo "<h3>"._("Installing your certificate")."</h3>\n";
66 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";
67 echo "<p><a href='account.php?id=6&amp;cert=$certid&amp;install=1'>"._("Click here")."</a> "._("to install your certificate.")."</p>\n";
68 showfooter();
69 exit;
70 }
71 } else {
72 showheader(_("My CAcert.org Account!"));
73 ?>
74 <h3><?=_("Installing your certificate")?></h3>
75
76 <p><?=_("Hit the 'Install your Certificate' button below to install the certificate into MS IE 5.x and above.")?>
77
78 <OBJECT classid="clsid:127698e4-e730-4e5c-a2b1-21490a70c8a1" codebase="/xenroll.cab#Version=5,131,3659,0" id="cec">
79 <?=_("You must enable ActiveX for this to work.")?>
80 </OBJECT>
81 <FORM >
82 <INPUT TYPE=BUTTON NAME="CertInst" VALUE="<?=_("Install Your Certificate")?>">
83 </FORM>
84
85 </P>
86
87 <SCRIPT LANGUAGE=VBS>
88 Sub CertInst_OnClick
89 certchain = _
90 <?
91 $lines = explode("\n", $cert);
92 if(is_array($lines))
93 foreach($lines as $line)
94 {
95 $line = trim($line);
96 if($line != "-----END CERTIFICATE-----")
97 echo "\"$line\" & _\n";
98 else {
99 echo "\"$line\"\n";
100 break;
101 }
102 }
103 ?>
104
105 On Error Resume Next
106
107 Dim obj
108 Set obj=CreateObject("X509Enrollment.CX509Enrollment")
109 If IsObject(obj) Then
110 obj.Initialize(1)
111 obj.InstallResponse 0,certchain,0,""
112 if err.number<>0 then
113 msgbox err.Description
114 else
115 msgbox "<?=_("Certificate installed successfully. Please don't forget to backup now")?>"
116 end if
117 else
118
119
120
121
122 cec.DeleteRequestCert = FALSE
123 err.clear
124
125 cec.WriteCertToCSP = TRUE
126 cec.acceptPKCS7(certchain)
127 if err.number <> 0 Then
128 cec.WriteCertToCSP = FALSE
129 end if
130 err.clear
131 cec.acceptPKCS7(certchain)
132 if err.number <> 0 then
133 errorMsg = "<?=_("Certificate installation failed!")?>" & chr(13) & chr(10) & _
134 "(Error code " & err.number & ")"
135 msgRes = MsgBox(errorMsg, 0, "<?=_("Certificate Installation Error")?>")
136 else
137 okMsg = "<?=_("Personal Certificate Installed.")?>" & chr(13) & chr(10) & _
138 "See Tools->Internet Options->Content->Certificates"
139 msgRes = MsgBox(okMsg, 0, "<?=_("Certificate Installation Complete!")?>")
140 end if
141 End If
142 End Sub
143 </SCRIPT>
144
145 <p><?=_("Your certificate:")?></p>
146 <pre><?=$cert?></pre>
147
148 <form method="post" action="account.php">
149 <table align="center" valign="middle" border="0" cellspacing="0" cellpadding="0" class="wrapper">
150 <tr>
151 <td colspan="2" class="title"><?=_("Information about the certificte")?></td>
152 </tr>
153 <?
154 if($row['timeleft'] > 0)
155 $verified = _("Valid");
156 if($row['timeleft'] < 0)
157 $verified = _("Expired");
158 if($row['expired'] == 0)
159 $verified = _("Pending");
160 if($row['revoked'] > 0)
161 $verified = _("Revoked");
162 if($row['revoked'] == 0)
163 $row['revoke'] = _("Not Revoked");
164 ?>
165 <tr>
166 <td class="DataTD"><?=_("Renew/Revoke/Delete")?></td>
167 <? if($verified != _("Pending") && $verified != _("Revoked")) { ?>
168 <td class="DataTD"><input type="checkbox" name="revokeid[<?=$row['id']?>]" ></td>
169 <? } else if($verified != _("Revoked")) { ?>
170 <td class="DataTD"><input type="checkbox" name="delid[<?=$row['id']?>]"></td>
171 <? } else { ?>
172 <td class="DataTD">&nbsp;</td>
173 <? } ?>
174 </tr>
175 <tr>
176 <td class="DataTD"><?=_("Status")?></td>
177 <td class="DataTD"><?=$verified?></td>
178 </tr>
179 <tr>
180 <td class="DataTD"><?=_("Email Address")?></td>
181 <td class="DataTD"><?=(trim($row['CN'])=="" ? _("empty") : $row['CN'])?></td>
182 </tr>
183 <tr>
184 <td class="DataTD"><?=_("SerialNumber")?></td>
185 <td class="DataTD"><?=$row['serial']?></td>
186 </tr>
187 <tr>
188 <td class="DataTD"><?=_("Revoked")?></td>
189 <td class="DataTD"><?=$row['revoke']?></td>
190 </tr>
191 <tr>
192 <td class="DataTD"><?=_("Expires")?></td>
193 <td class="DataTD"><?=$row['expires']?></td>
194 </tr>
195 <tr>
196 <td class="DataTD"><?=_("Login")?></td>
197 <td class="DataTD">
198 <input type="checkbox" name="disablelogin" value="1" <?=$row['disablelogin']?"":"checked='checked'"?>/>
199 </td>
200 </tr>
201 <tr>
202 <td class="DataTD"><?=_("Comment")?></td>
203 <td class="DataTD"><input type="text" name="description" maxlength="100" size=100 value="<?=htmlspecialchars($row['description'])?>"></td>
204 </tr>
205 <tr>
206 <td class="DataTD" colspan="2"><input type="submit" name="change" value="<?=_("Change settings")?>"> </td>
207 </tr>
208 </table>
209 <input type="hidden" name="oldid" value="6">
210 <input type="hidden" name="certid" value="<?=$certid?>">
211 </form>
212
213 <?
214 showfooter();
215 exit;
216 }