]> WPIA git - gigi.git/blob - src/org/cacert/gigi/pages/admin/support/SupportRevokeCertificatesForm.java
UPD: SE: Extracted revokeCertificateForm from the page
[gigi.git] / src / org / cacert / gigi / pages / admin / support / SupportRevokeCertificatesForm.java
1 package org.cacert.gigi.pages.admin.support;
2
3 import java.io.IOException;
4 import java.io.PrintWriter;
5 import java.security.GeneralSecurityException;
6 import java.util.Date;
7 import java.util.Map;
8
9 import javax.servlet.http.HttpServletRequest;
10
11 import org.cacert.gigi.GigiApiException;
12 import org.cacert.gigi.dbObjects.Certificate;
13 import org.cacert.gigi.dbObjects.CertificateProfile;
14 import org.cacert.gigi.dbObjects.User;
15 import org.cacert.gigi.localisation.Language;
16 import org.cacert.gigi.output.DateSelector;
17 import org.cacert.gigi.output.template.Form;
18 import org.cacert.gigi.output.template.IterableDataset;
19 import org.cacert.gigi.output.template.Template;
20
21 public class SupportRevokeCertificatesForm extends Form {
22
23     private static Template t;
24
25     private User user;
26     static {
27         t = new Template(SupportRevokeCertificatesForm.class.getResource("SupportRevokeCertificatesForm.templ"));
28     }
29
30     public SupportRevokeCertificatesForm(HttpServletRequest hsr, User user) {
31         super(hsr);
32         this.user = user;
33     }
34
35     @Override
36     public boolean submit(PrintWriter out, HttpServletRequest req) throws GigiApiException {
37         return false;
38     }
39
40     @Override
41     protected void outputContent(PrintWriter out, Language l, Map<String, Object> vars) {
42         final Certificate[] certs = user.getCertificates(true);
43         final CertificateProfile[] profiles = CertificateProfile.getAll();
44         vars.put("types", new IterableDataset() {
45
46             int typeIndex = 0;
47
48             @Override
49             public boolean next(Language l, Map<String, Object> vars) {
50                 if (typeIndex > profiles.length - 1) {
51                     return false;
52                 }
53                 int valid = 0;
54                 int total = 0;
55                 long lastExpire = Long.MIN_VALUE;
56                 for (int i = 0; i < certs.length; i++) {
57                     try {
58                         if (certs[i].getProfile().getId() != profiles[typeIndex].getId()) {
59                             continue;
60                         }
61                         total++;
62                         certs[i].cert().checkValidity();
63                         lastExpire = Math.max(lastExpire, certs[i].cert().getNotAfter().getTime());
64                         valid++;
65                     } catch (GeneralSecurityException | IOException e) {
66                         continue;
67                     }
68                 }
69                 vars.put("total", total);
70                 vars.put("profile", profiles[typeIndex].getVisibleName());
71                 vars.put("valid", valid);
72                 vars.put("exp", total - valid);
73                 vars.put("rev", "TODO");
74                 if (lastExpire == Long.MIN_VALUE) {
75                     vars.put("lastdate", "-");
76                 } else {
77                     vars.put("lastdate", DateSelector.getDateFormat().format(new Date(lastExpire)));
78                 }
79                 typeIndex++;
80                 return true;
81             }
82         });
83         t.output(out, l, vars);
84     }
85
86 }