1 package org.cacert.gigi.pages.admin.support;
3 import java.io.IOException;
4 import java.security.GeneralSecurityException;
6 import java.util.HashMap;
9 import javax.servlet.http.HttpServletRequest;
10 import javax.servlet.http.HttpServletResponse;
12 import org.cacert.gigi.dbObjects.Certificate;
13 import org.cacert.gigi.dbObjects.CertificateProfile;
14 import org.cacert.gigi.dbObjects.EmailAddress;
15 import org.cacert.gigi.dbObjects.User;
16 import org.cacert.gigi.localisation.Language;
17 import org.cacert.gigi.output.DateSelector;
18 import org.cacert.gigi.output.template.IterableDataset;
19 import org.cacert.gigi.pages.Page;
21 public class SupportUserDetailsPage extends Page {
23 public static final String PATH = "/support/user/";
25 public SupportUserDetailsPage(String title) {
30 public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
32 String[] idP = req.getPathInfo().split("/");
33 id = Integer.parseInt(idP[idP.length - 1]);
34 final User user = User.getById(id);
35 SupportUserDetailsForm f = new SupportUserDetailsForm(req, user);
36 HashMap<String, Object> vars = new HashMap<String, Object>();
37 vars.put("details", f);
38 final EmailAddress[] addrs = user.getEmails();
39 vars.put("emails", new IterableDataset() {
44 public boolean next(Language l, Map<String, Object> vars) {
45 String address = addrs[i].getAddress();
46 if ( !address.equals(user.getEmail())) {
47 vars.put("secmail", address);
50 return i != addrs.length - 1;
53 final Certificate[] certs = user.getCertificates(true);
54 final CertificateProfile[] profiles = CertificateProfile.getAll();
55 vars.put("types", new IterableDataset() {
60 public boolean next(Language l, Map<String, Object> vars) {
61 if (typeIndex > profiles.length - 1) {
66 long lastExpire = Long.MIN_VALUE;
67 for (int i = 0; i < certs.length; i++) {
69 if (certs[i].getProfile().getId() != profiles[typeIndex].getId()) {
73 certs[i].cert().checkValidity();
74 lastExpire = Math.max(lastExpire, certs[i].cert().getNotAfter().getTime());
76 } catch (GeneralSecurityException | IOException e) {
80 vars.put("total", total);
81 vars.put("profile", profiles[typeIndex].getVisibleName());
82 vars.put("valid", valid);
83 vars.put("exp", total - valid);
84 vars.put("rev", "TODO");
85 if (lastExpire == Long.MIN_VALUE) {
86 vars.put("lastdate", "-");
88 vars.put("lastdate", DateSelector.getDateFormat().format(new Date(lastExpire)));
94 getDefaultTemplate().output(resp.getWriter(), getLanguage(req), vars);