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.Group;
16 import org.cacert.gigi.dbObjects.User;
17 import org.cacert.gigi.localisation.Language;
18 import org.cacert.gigi.output.DateSelector;
19 import org.cacert.gigi.output.template.IterableDataset;
20 import org.cacert.gigi.pages.Page;
22 public class SupportUserDetailsPage extends Page {
24 public static final String PATH = "/support/user/";
26 public SupportUserDetailsPage(String title) {
31 public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
33 String[] idP = req.getPathInfo().split("/");
34 id = Integer.parseInt(idP[idP.length - 1]);
35 final User user = User.getById(id);
36 SupportUserDetailsForm f = new SupportUserDetailsForm(req, user);
37 HashMap<String, Object> vars = new HashMap<String, Object>();
38 vars.put("details", f);
39 final EmailAddress[] addrs = user.getEmails();
40 vars.put("emails", new IterableDataset() {
45 public boolean next(Language l, Map<String, Object> vars) {
46 String address = addrs[i].getAddress();
47 if ( !address.equals(user.getEmail())) {
48 vars.put("secmail", address);
51 return i != addrs.length - 1;
54 final Certificate[] certs = user.getCertificates(true);
55 final CertificateProfile[] profiles = CertificateProfile.getAll();
56 vars.put("types", new IterableDataset() {
61 public boolean next(Language l, Map<String, Object> vars) {
62 if (typeIndex > profiles.length - 1) {
67 long lastExpire = Long.MIN_VALUE;
68 for (int i = 0; i < certs.length; i++) {
70 if (certs[i].getProfile().getId() != profiles[typeIndex].getId()) {
74 certs[i].cert().checkValidity();
75 lastExpire = Math.max(lastExpire, certs[i].cert().getNotAfter().getTime());
77 } catch (GeneralSecurityException | IOException e) {
81 vars.put("total", total);
82 vars.put("profile", profiles[typeIndex].getVisibleName());
83 vars.put("valid", valid);
84 vars.put("exp", total - valid);
85 vars.put("rev", "TODO");
86 if (lastExpire == Long.MIN_VALUE) {
87 vars.put("lastdate", "-");
89 vars.put("lastdate", DateSelector.getDateFormat().format(new Date(lastExpire)));
95 getDefaultTemplate().output(resp.getWriter(), getLanguage(req), vars);
99 public boolean isPermitted(User u) {
103 return u.isInGroup(Group.getByString("supporter"));