1 package org.cacert.gigi.pages.admin.support;
3 import java.io.IOException;
4 import java.io.PrintWriter;
5 import java.security.GeneralSecurityException;
9 import javax.servlet.http.HttpServletRequest;
11 import org.cacert.gigi.GigiApiException;
12 import org.cacert.gigi.dbObjects.Certificate;
13 import org.cacert.gigi.dbObjects.Certificate.CertificateStatus;
14 import org.cacert.gigi.dbObjects.CertificateProfile;
15 import org.cacert.gigi.dbObjects.SupportedUser;
16 import org.cacert.gigi.localisation.Language;
17 import org.cacert.gigi.output.template.Form;
18 import org.cacert.gigi.output.template.IterableDataset;
19 import org.cacert.gigi.output.template.Outputable;
20 import org.cacert.gigi.output.template.Template;
21 import org.cacert.gigi.output.template.TranslateCommand;
23 public class SupportRevokeCertificatesForm extends Form {
25 private static final Template t = new Template(SupportRevokeCertificatesForm.class.getResource("SupportRevokeCertificatesForm.templ"));
27 private SupportedUser user;
29 public SupportRevokeCertificatesForm(HttpServletRequest hsr, SupportedUser user) {
35 public boolean submit(PrintWriter out, HttpServletRequest req) throws GigiApiException {
36 if (user.getTicket() != null) {
37 user.revokeAllCertificates();
38 String subject = "Revoke certificates";
39 Outputable message = new TranslateCommand("All certificates in the account have been revoked.");
40 user.sendSupportNotification(subject, message);
47 protected void outputContent(PrintWriter out, Language l, Map<String, Object> vars) {
48 final Certificate[] certs = user.getCertificates(true);
49 final CertificateProfile[] profiles = CertificateProfile.getAll();
50 vars.put("types", new IterableDataset() {
55 public boolean next(Language l, Map<String, Object> vars) {
56 if (typeIndex > profiles.length - 1) {
62 long lastExpire = Long.MIN_VALUE;
63 for (int i = 0; i < certs.length; i++) {
65 if (certs[i].getProfile().getId() != profiles[typeIndex].getId()) {
69 if (certs[i].getStatus() == CertificateStatus.DRAFT) {
72 if (certs[i].getStatus() == CertificateStatus.REVOKED) {
76 certs[i].cert().checkValidity();
77 lastExpire = Math.max(lastExpire, certs[i].cert().getNotAfter().getTime());
79 } catch (GeneralSecurityException | IOException e) {
83 vars.put("total", total);
84 vars.put("profile", profiles[typeIndex].getVisibleName());
85 vars.put("valid", valid);
86 vars.put("exp", total - valid);
87 vars.put("rev", revoked);
88 if (lastExpire == Long.MIN_VALUE) {
89 vars.put("lastdate", "-");
91 vars.put("lastdate", new Date(lastExpire));
97 t.output(out, l, vars);