upd: add exception handling
[gigi.git] / util-testing / club / wpia / gigi / pages / Manager.java
1 package club.wpia.gigi.pages;
2
3 import java.io.IOException;
4 import java.io.PrintWriter;
5 import java.lang.reflect.Field;
6 import java.security.GeneralSecurityException;
7 import java.security.KeyPair;
8 import java.security.KeyPairGenerator;
9 import java.security.Signature;
10 import java.sql.Timestamp;
11 import java.text.SimpleDateFormat;
12 import java.util.Base64;
13 import java.util.Calendar;
14 import java.util.Date;
15 import java.util.GregorianCalendar;
16 import java.util.HashMap;
17 import java.util.Iterator;
18 import java.util.LinkedList;
19 import java.util.List;
20 import java.util.Locale;
21 import java.util.Map;
22 import java.util.Properties;
23 import java.util.Random;
24 import java.util.TreeSet;
25 import java.util.regex.Matcher;
26 import java.util.regex.Pattern;
27
28 import javax.servlet.http.HttpServletRequest;
29 import javax.servlet.http.HttpServletResponse;
30
31 import club.wpia.gigi.Gigi;
32 import club.wpia.gigi.GigiApiException;
33 import club.wpia.gigi.crypto.SPKAC;
34 import club.wpia.gigi.database.GigiPreparedStatement;
35 import club.wpia.gigi.dbObjects.CATS;
36 import club.wpia.gigi.dbObjects.CATS.CATSType;
37 import club.wpia.gigi.dbObjects.Certificate;
38 import club.wpia.gigi.dbObjects.Certificate.CertificateStatus;
39 import club.wpia.gigi.dbObjects.CertificateOwner;
40 import club.wpia.gigi.dbObjects.Contract;
41 import club.wpia.gigi.dbObjects.Contract.ContractType;
42 import club.wpia.gigi.dbObjects.Country;
43 import club.wpia.gigi.dbObjects.Digest;
44 import club.wpia.gigi.dbObjects.Domain;
45 import club.wpia.gigi.dbObjects.DomainPingConfiguration;
46 import club.wpia.gigi.dbObjects.DomainPingExecution;
47 import club.wpia.gigi.dbObjects.DomainPingType;
48 import club.wpia.gigi.dbObjects.EmailAddress;
49 import club.wpia.gigi.dbObjects.Group;
50 import club.wpia.gigi.dbObjects.NamePart;
51 import club.wpia.gigi.dbObjects.NamePart.NamePartType;
52 import club.wpia.gigi.dbObjects.User;
53 import club.wpia.gigi.dbObjects.Verification.VerificationType;
54 import club.wpia.gigi.email.DelegateMailProvider;
55 import club.wpia.gigi.email.EmailProvider;
56 import club.wpia.gigi.localisation.Language;
57 import club.wpia.gigi.output.template.IterableDataset;
58 import club.wpia.gigi.output.template.Template;
59 import club.wpia.gigi.pages.account.certs.CertificateRequest;
60 import club.wpia.gigi.ping.DomainPinger;
61 import club.wpia.gigi.ping.PingerDaemon;
62 import club.wpia.gigi.util.AuthorizationContext;
63 import club.wpia.gigi.util.DayDate;
64 import club.wpia.gigi.util.DomainAssessment;
65 import club.wpia.gigi.util.HTMLEncoder;
66 import club.wpia.gigi.util.Notary;
67 import club.wpia.gigi.util.TimeConditions;
68 import sun.security.x509.X509Key;
69
70 public class Manager extends Page {
71
72     public static String validVerificationDateString() {
73         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
74         Calendar c = Calendar.getInstance();
75         c.setTimeInMillis(System.currentTimeMillis());
76         c.add(Calendar.MONTH, -Notary.LIMIT_MAX_MONTHS_VERIFICATION + 1);
77         return sdf.format(new Date(c.getTimeInMillis()));
78     }
79
80     public static Country getRandomCountry() {
81         List<Country> cc = Country.getCountries();
82         int rnd = new Random().nextInt(cc.size());
83         return cc.get(rnd);
84     }
85
86     public static final String PATH = "/manager";
87
88     private static HashMap<DomainPingType, DomainPinger> dps;
89
90     private Manager() {
91         super("Test Manager");
92
93         try {
94             Field gigiInstance = Gigi.class.getDeclaredField("instance");
95             gigiInstance.setAccessible(true);
96             Gigi g = (Gigi) gigiInstance.get(null);
97
98             Field gigiPinger = Gigi.class.getDeclaredField("pinger");
99             gigiPinger.setAccessible(true);
100             PingerDaemon pd = (PingerDaemon) gigiPinger.get(g);
101
102             Field f = PingerDaemon.class.getDeclaredField("pingers");
103             f.setAccessible(true);
104             dps = (HashMap<DomainPingType, DomainPinger>) f.get(pd);
105             HashMap<DomainPingType, DomainPinger> pingers = new HashMap<>();
106             for (DomainPingType dpt : DomainPingType.values()) {
107                 pingers.put(dpt, new PingerFetcher(dpt));
108             }
109             f.set(pd, pingers);
110         } catch (ReflectiveOperationException e) {
111             e.printStackTrace();
112         }
113     }
114
115     public User getSupporter() {
116         if (supporter != null) {
117             return supporter;
118         }
119         try {
120             User u = createAgent( -1);
121             if ( !u.isInGroup(Group.SUPPORTER)) {
122                 try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO `user_groups` SET `user`=?, `permission`=?::`userGroup`, `grantedby`=?")) {
123                     ps.setInt(1, u.getId());
124                     ps.setString(2, Group.SUPPORTER.getDBName());
125                     ps.setInt(3, u.getId());
126                     ps.execute();
127                 }
128                 u.refreshGroups();
129             }
130             supporter = u;
131         } catch (ReflectiveOperationException | GigiApiException e) {
132             e.printStackTrace();
133         }
134         return supporter;
135     }
136
137     public User getAgent(int i) {
138         if (agents[i] != null) {
139             return agents[i];
140         }
141         try {
142             User u = createAgent(i);
143             agents[i] = u;
144
145         } catch (ReflectiveOperationException | GigiApiException e) {
146             e.printStackTrace();
147         }
148         return agents[i];
149     }
150
151     private User createAgent(int i) throws GigiApiException, IllegalAccessException {
152         try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO `notary` SET `from`=?, `to`=?, `points`=?, `location`=?, `date`=?, `country`=?")) {
153             String mail = "test-agent" + i + "@example.com";
154             User u = User.getByEmail(mail);
155             if (u == null) {
156                 System.out.println("Creating RA-Agent");
157                 createUser(mail);
158                 u = User.getByEmail(mail);
159                 passCATS(u, CATSType.AGENT_CHALLENGE);
160                 ps.setInt(1, u.getId());
161                 ps.setInt(2, u.getPreferredName().getId());
162                 ps.setInt(3, 100);
163                 ps.setString(4, "Manager init code");
164                 ps.setString(5, "1990-01-01");
165                 ps.setString(6, getRandomCountry().getCode());
166                 ps.execute();
167             }
168             new Contract(u, ContractType.RA_AGENT_CONTRACT);
169             return u;
170         }
171     }
172
173     private void passCATS(User u, CATSType t) {
174         CATS.enterResult(u, t, new Date(System.currentTimeMillis()), "en_EN", "1");
175     }
176
177     private void expireCATS(User u, CATSType t) {
178         try (GigiPreparedStatement ps = new GigiPreparedStatement("UPDATE `cats_passed` SET `pass_date`=? WHERE `user_id`=? AND `variant_id`=? AND `pass_date`>?")) {
179             ps.setTimestamp(1, new Timestamp(System.currentTimeMillis() - DayDate.MILLI_DAY * 367));
180             ps.setInt(2, u.getId());
181             ps.setInt(3, t.getId());
182             ps.setTimestamp(4, new Timestamp(System.currentTimeMillis() - DayDate.MILLI_DAY * 366));
183             ps.execute();
184             ps.close();
185         }
186     }
187
188     private static Manager instance;
189
190     private static final Template t = new Template(Manager.class.getResource("ManagerMails.templ"));
191
192     HashMap<String, LinkedList<String>> emails = new HashMap<>();
193
194     private static TreeSet<String> pingExempt = new TreeSet<>();
195
196     public static Manager getInstance() {
197         if (instance == null) {
198             instance = new Manager();
199         }
200         return instance;
201     }
202
203     public static class MailFetcher extends DelegateMailProvider {
204
205         Pattern[] toForward;
206
207         public MailFetcher(Properties props) {
208             super(props, props.getProperty("emailProvider.manager.target"));
209             String str = props.getProperty("emailProvider.manager.filter");
210             if (str == null) {
211                 toForward = new Pattern[0];
212             } else {
213                 String[] parts = str.split(" ");
214                 toForward = new Pattern[parts.length];
215                 for (int i = 0; i < parts.length; i++) {
216                     toForward[i] = Pattern.compile(parts[i]);
217                 }
218             }
219         }
220
221         @Override
222         public String checkEmailServer(int forUid, String address) throws IOException {
223             return OK;
224         }
225
226         @Override
227         public synchronized void sendMail(String to, String subject, String message, String replyto, String toname, String fromname, String errorsto, boolean extra) throws IOException {
228             HashMap<String, LinkedList<String>> mails = Manager.getInstance().emails;
229             LinkedList<String> hismails = mails.get(to);
230             if (hismails == null) {
231                 mails.put(to, hismails = new LinkedList<>());
232             }
233             hismails.addFirst(subject + "\n" + message);
234             for (int i = 0; i < toForward.length; i++) {
235                 if (toForward[i].matcher(to).matches()) {
236                     super.sendMail(to, subject, message, replyto, toname, fromname, errorsto, extra);
237                     return;
238                 }
239             }
240         }
241
242     }
243
244     public class PingerFetcher extends DomainPinger {
245
246         private DomainPingType dpt;
247
248         public PingerFetcher(DomainPingType dpt) {
249             this.dpt = dpt;
250         }
251
252         @Override
253         public DomainPingExecution ping(Domain domain, String configuration, CertificateOwner target, DomainPingConfiguration conf) {
254             System.err.println("TestManager: " + domain.getSuffix());
255             if (pingExempt.contains(domain.getSuffix())) {
256                 return enterPingResult(conf, DomainPinger.PING_SUCCEDED, "Succeeded by TestManager pass-by", null);
257             } else {
258                 DomainPinger pinger = dps.get(dpt);
259                 System.err.println("Forward to old pinger: " + pinger);
260                 return pinger.ping(domain, configuration, target, conf);
261             }
262         }
263
264     }
265
266     public void batchCreateUsers(String mailPrefix, String domain, int amount, PrintWriter out) {
267
268         try {
269             if (amount > 100) {
270                 out.print("100 at most, please.");
271                 return;
272             }
273             for (int i = 0; i < amount; i++) {
274                 String email = mailPrefix + i + "@" + domain;
275                 createUser(email);
276             }
277         } catch (ReflectiveOperationException e) {
278             out.println("failed");
279             e.printStackTrace();
280         } catch (GigiApiException e) {
281             out.println("failed: " + e.getMessage());
282             e.printStackTrace();
283         }
284     }
285
286     private void createUser(String email) throws GigiApiException, IllegalAccessException {
287         Calendar gc = GregorianCalendar.getInstance();
288         gc.setTimeInMillis(0);
289         gc.set(1990, 0, 1);
290
291         Country country = getRandomCountry();
292
293         User u = new User(email, "xvXV12°§", new DayDate(gc.getTime().getTime()), Locale.ENGLISH, country, //
294                 new NamePart(NamePartType.FIRST_NAME, "Först"), new NamePart(NamePartType.FIRST_NAME, "Müddle"), //
295                 new NamePart(NamePartType.LAST_NAME, "Läst"), new NamePart(NamePartType.SUFFIX, "Süffix"));
296         EmailAddress ea = u.getEmails()[0];
297         verify(email, ea);
298     }
299
300     private void verify(String email, EmailAddress ea) throws GigiApiException {
301         LinkedList<String> i = emails.get(email);
302         while (i.size() > 0 && !ea.isVerified()) {
303             String lst = i.getLast();
304             Pattern p = Pattern.compile("hash=([a-zA-Z0-9]+)");
305             Matcher m = p.matcher(lst);
306             if (m.find()) {
307                 ea.verify(m.group(1));
308             }
309             i.removeLast();
310         }
311         // ea.verify(hash);
312     }
313
314     User[] agents = new User[25];
315
316     User supporter;
317
318     @Override
319     public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
320         AuthorizationContext sessionAc = (AuthorizationContext) req.getSession().getAttribute(Gigi.AUTH_CONTEXT);
321         if (req.getParameter("create") != null) {
322             String prefix = req.getParameter("prefix");
323             String domain = req.getParameter("suffix");
324             try {
325                 if (null == prefix) {
326                     throw new GigiApiException("No prefix given.");
327                 }
328                 if (null == domain) {
329                     throw new GigiApiException("No domain given.");
330                 }
331
332                 DomainAssessment.checkCertifiableDomain(domain, false, true);
333
334                 if ( !EmailProvider.isValidMailAddress(prefix + "@" + domain)) {
335                     throw new GigiApiException("Invalid email address template.");
336                 }
337
338                 batchCreateUsers(prefix, domain, Integer.parseInt(req.getParameter("amount")), resp.getWriter());
339                 resp.getWriter().println("User batch created.");
340             } catch (GigiApiException e) {
341                 throw new Error(e);
342             }
343         } else if (req.getParameter("addpriv") != null || req.getParameter("delpriv") != null) {
344             User userByEmail = User.getByEmail(req.getParameter("email"));
345             if (userByEmail == null) {
346                 resp.getWriter().println("User not found.");
347                 return;
348             }
349             try {
350                 if (req.getParameter("addpriv") != null) {
351                     userByEmail.grantGroup(getSupporter(), Group.getByString(req.getParameter("priv")));
352                     resp.getWriter().println("Privilege granted");
353                 } else {
354                     userByEmail.revokeGroup(getSupporter(), Group.getByString(req.getParameter("priv")));
355                     resp.getWriter().println("Privilege revoked");
356                 }
357             } catch (GigiApiException e) {
358                 throw new Error(e);
359             }
360         } else if (req.getParameter("fetch") != null) {
361             String mail = req.getParameter("femail");
362             fetchMails(req, resp, mail);
363         } else if (req.getParameter("cats") != null) {
364             String mail = req.getParameter("catsEmail");
365             String catsTypeId = req.getParameter("catsType");
366             User byEmail = User.getByEmail(mail);
367             if (byEmail == null) {
368                 resp.getWriter().println("User not found.");
369                 return;
370             }
371             if (catsTypeId == null) {
372                 resp.getWriter().println("No test given.");
373                 return;
374             }
375             CATSType test = null;
376             try {
377                 test = CATSType.values()[Integer.parseInt(catsTypeId)];
378             } catch (NumberFormatException e) {
379                 resp.getWriter().println("No valid integer given.");
380                 return;
381             }
382             passCATS(byEmail, test);
383             resp.getWriter().println("Test '" + test.getDisplayName() + "' was added to user account.");
384         } else if (req.getParameter("catsexpire") != null) {
385             String mail = req.getParameter("catsEmail");
386             String catsTypeId = req.getParameter("catsType");
387             User userByEmail = User.getByEmail(mail);
388             if (userByEmail == null) {
389                 resp.getWriter().println("User not found.");
390                 return;
391             }
392             if (catsTypeId == null) {
393                 resp.getWriter().println("No test given.");
394                 return;
395             }
396             CATSType test = null;
397             try {
398                 test = CATSType.values()[Integer.parseInt(catsTypeId)];
399             } catch (NumberFormatException e) {
400                 resp.getWriter().println("No valid integer given.");
401                 return;
402             }
403             expireCATS(userByEmail, test);
404             resp.getWriter().println("Test '" + test.getDisplayName() + "' is set expired for user account.");
405         } else if (req.getParameter("verify") != null) {
406             String mail = req.getParameter("verifyEmail");
407             String verificationPoints = req.getParameter("verificationPoints");
408             User userByEmail = User.getByEmail(mail);
409
410             if (userByEmail == null) {
411                 resp.getWriter().println("User not found.");
412                 return;
413             }
414
415             int vp = 0;
416             int verifications = 0;
417             String info = "";
418
419             try {
420                 try {
421                     vp = Integer.parseInt(verificationPoints);
422                 } catch (NumberFormatException e) {
423                     resp.getWriter().println("The value for Verification Points must be an integer.</br>");
424                     vp = 0;
425                 }
426
427                 int agentNumber = addVerificationPoints(vp, userByEmail);
428
429                 while (vp > 0) {
430                     int currentVP = 10;
431                     if (vp < 10) {
432                         currentVP = vp;
433                     }
434                     if (Notary.checkVerificationIsPossible(getAgent(agentNumber), userByEmail.getPreferredName())) {
435
436                         Notary.verify(getAgent(agentNumber), userByEmail, userByEmail.getPreferredName(), userByEmail.getDoB(), currentVP, "Testmanager Verify up code", validVerificationDateString(), VerificationType.FACE_TO_FACE, getRandomCountry());
437                         vp -= currentVP;
438                         verifications += 1;
439
440                     }
441                     agentNumber += 1;
442                     if (agentNumber >= agents.length) {
443                         info = "<br/>The limit of agents is reached. You cannot add any more Verification Points to the preferred name of this user using this method.";
444                         break;
445                     }
446                 }
447
448             } catch (GigiApiException e) {
449                 throw new Error(e);
450             }
451
452             resp.getWriter().println("User has been verified " + verifications + " times." + info);
453
454         } else if (req.getParameter("letverify") != null) {
455             String mail = req.getParameter("letverifyEmail");
456             User userByEmail = User.getByEmail(mail);
457             if (userByEmail == null || !userByEmail.canVerify()) {
458                 resp.getWriter().println("User not found, or found user is not allowed to verify.");
459             } else {
460                 try {
461                     for (int i = 0; i < 25; i++) {
462                         User a = getAgent(i);
463                         Notary.verify(userByEmail, a, a.getNames()[0], a.getDoB(), 10, "Testmanager exp up code", validVerificationDateString(), VerificationType.FACE_TO_FACE, getRandomCountry());
464                     }
465                     resp.getWriter().println("Successfully added experience points.");
466                 } catch (GigiApiException e) {
467                     throw new Error(e);
468                 }
469             }
470         } else if (req.getParameter("addEmail") != null) {
471             User userByEmail = User.getByEmail(req.getParameter("addEmailEmail"));
472             try {
473                 EmailAddress ea = new EmailAddress(userByEmail, req.getParameter("addEmailNew"), Locale.ENGLISH);
474                 verify(ea.getAddress(), ea);
475             } catch (IllegalArgumentException e) {
476                 e.printStackTrace();
477                 resp.getWriter().println("An internal error occured.");
478             } catch (GigiApiException e) {
479                 e.format(resp.getWriter(), Language.getInstance(Locale.ENGLISH), getDefaultVars(req));
480             }
481         } else if (req.getParameter("addCert") != null) {
482             User userByEmail = User.getByEmail(req.getParameter("addCertEmail"));
483             try {
484                 KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
485                 kpg.initialize(4096);
486                 KeyPair kp = kpg.generateKeyPair();
487                 SPKAC s = new SPKAC((X509Key) kp.getPublic(), "challenge");
488                 Signature sign = Signature.getInstance("SHA512withRSA");
489                 sign.initSign(kp.getPrivate());
490
491                 byte[] res = s.getEncoded(sign);
492
493                 CertificateRequest cr = new CertificateRequest(new AuthorizationContext(userByEmail, userByEmail, sessionAc.isStronglyAuthenticated()), Base64.getEncoder().encodeToString(res), "challenge");
494                 cr.update(CertificateRequest.DEFAULT_CN, Digest.SHA512.toString(), "client", null, "", "email:" + userByEmail.getEmail());
495                 Certificate draft = cr.draft();
496                 draft.issue(null, "2y", userByEmail).waitFor(10000);
497                 if (draft.getStatus() == CertificateStatus.ISSUED) {
498                     resp.getWriter().println("added certificate");
499                 } else {
500                     resp.getWriter().println("signer failed");
501                 }
502             } catch (GeneralSecurityException e1) {
503                 e1.printStackTrace();
504                 resp.getWriter().println("error");
505             } catch (GigiApiException e) {
506                 e.format(resp.getWriter(), Language.getInstance(Locale.ENGLISH), getDefaultVars(req));
507             }
508
509         } else if (req.getParameter("addExDom") != null) {
510             String dom = req.getParameter("exemptDom");
511             pingExempt.add(dom);
512             resp.getWriter().println("Updated domains exempt from pings. Current set: <br/>");
513             resp.getWriter().println(HTMLEncoder.encodeHTML(pingExempt.toString()));
514         } else if (req.getParameter("delExDom") != null) {
515             String dom = req.getParameter("exemptDom");
516             pingExempt.remove(dom);
517             resp.getWriter().println("Updated domains exempt from pings. Current set: <br/>");
518             resp.getWriter().println(HTMLEncoder.encodeHTML(pingExempt.toString()));
519         } else if (req.getParameter("makeAgent") != null) {
520             User userByEmail = User.getByEmail(req.getParameter("agentEmail"));
521             if (userByEmail == null) {
522                 resp.getWriter().println("User not found, or found user is not allowed to verify.");
523             } else {
524                 if (userByEmail.getVerificationPoints() < 100) {
525                     addVerificationPoints(100, userByEmail);
526                 }
527                 if ( !userByEmail.hasPassedCATS()) {
528                     passCATS(userByEmail, CATSType.AGENT_CHALLENGE);
529                 }
530                 if ( !Contract.hasSignedContract(userByEmail, Contract.ContractType.RA_AGENT_CONTRACT)) {
531                     try {
532                         new Contract(userByEmail, Contract.ContractType.RA_AGENT_CONTRACT);
533                     } catch (GigiApiException e) {
534                         throw new Error(e);
535                     }
536                 }
537                 resp.getWriter().println("User has all requirements to be an RA Agent");
538             }
539         }
540         resp.getWriter().println("<br/><a href='" + PATH + "'>Go back</a>");
541     }
542
543     private int addVerificationPoints(int vp, User byEmail) throws Error {
544         int agentNumber = 0;
545
546         try {
547             if (vp > 100) { // only allow max 100 Verification points
548                 vp = 100;
549             }
550
551             while (vp > 0) {
552                 int currentVP = 10;
553                 if (vp < 10) {
554                     currentVP = vp;
555                 }
556                 Notary.verify(getAgent(agentNumber), byEmail, byEmail.getPreferredName(), byEmail.getDoB(), currentVP, "Testmanager Verify up code", validVerificationDateString(), VerificationType.FACE_TO_FACE, getRandomCountry());
557                 agentNumber += 1;
558                 vp -= currentVP;
559             }
560
561         } catch (GigiApiException e) {
562             throw new Error(e);
563         }
564         return agentNumber;
565     }
566
567     private void fetchMails(HttpServletRequest req, HttpServletResponse resp, String mail) throws IOException {
568         final LinkedList<String> mails = emails.get(mail);
569         HashMap<String, Object> vars = new HashMap<>();
570         vars.put("mail", mail);
571         if (mails != null) {
572             vars.put("mails", new IterableDataset() {
573
574                 Iterator<String> s = mails.iterator();
575
576                 @Override
577                 public boolean next(Language l, Map<String, Object> vars) {
578                     if ( !s.hasNext()) {
579                         return false;
580                     }
581                     vars.put("body", s.next().replaceAll("(https?://\\S+)", "<a href=\"$1\">$1</a>"));
582                     return true;
583                 }
584             });
585         }
586         t.output(resp.getWriter(), getLanguage(req), vars);
587         if (mails == null) {
588             resp.getWriter().println("No mails");
589
590         }
591     }
592
593     private static final Template form = new Template(Manager.class.getResource("Manager.templ"));
594
595     @Override
596     public boolean needsLogin() {
597         return false;
598     }
599
600     @Override
601     public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
602         String pi = req.getPathInfo().substring(PATH.length());
603         if (pi.length() > 1 && pi.startsWith("/fetch-")) {
604             String mail = pi.substring(pi.indexOf('-', 2) + 1);
605             fetchMails(req, resp, mail);
606             return;
607         }
608         HashMap<String, Object> vars = new HashMap<>();
609         vars.put("cats_types", new IterableDataset() {
610
611             CATSType[] type = CATSType.values();
612
613             int i = 0;
614
615             @Override
616             public boolean next(Language l, Map<String, Object> vars) {
617                 if (i >= type.length) {
618                     return false;
619                 }
620                 CATSType t = type[i++];
621                 vars.put("id", i - 1);
622                 vars.put("name", t.getDisplayName());
623                 return true;
624             }
625         });
626
627         vars.put("testValidMonths", TimeConditions.getInstance().getTestMonths());
628         vars.put("reverificationDays", TimeConditions.getInstance().getVerificationLimitDays());
629         vars.put("verificationFreshMonths", TimeConditions.getInstance().getVerificationMonths());
630         vars.put("verificationMaxAgeMonths", TimeConditions.getInstance().getVerificationMaxAgeMonths());
631         vars.put("emailPingMonths", TimeConditions.getInstance().getEmailPingMonths());
632
633         form.output(resp.getWriter(), getLanguage(req), vars);
634     }
635 }