]> WPIA git - gigi.git/blob - src/org/cacert/gigi/pages/account/domain/DomainOverview.java
Move email/certs/mail to their own packages
[gigi.git] / src / org / cacert / gigi / pages / account / domain / DomainOverview.java
1 package org.cacert.gigi.pages.account.domain;
2
3 import java.io.IOException;
4 import java.util.HashMap;
5
6 import javax.servlet.http.HttpServletRequest;
7 import javax.servlet.http.HttpServletResponse;
8
9 import org.cacert.gigi.GigiApiException;
10 import org.cacert.gigi.dbObjects.Domain;
11 import org.cacert.gigi.dbObjects.DomainPingConfiguration;
12 import org.cacert.gigi.dbObjects.User;
13 import org.cacert.gigi.output.Form;
14 import org.cacert.gigi.pages.Page;
15
16 public class DomainOverview extends Page {
17
18     public static final String PATH = "/account/domains/";
19
20     public DomainOverview(String title) {
21         super(title);
22     }
23
24     @Override
25     public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
26         User u = getUser(req);
27         String pi = req.getPathInfo();
28         if (pi.length() - PATH.length() > 0) {
29             int i = Integer.parseInt(pi.substring(PATH.length()));
30             Domain d = Domain.getById(i);
31             if (u.getId() != d.getOwner().getId()) {
32                 System.out.println(u.getId());
33                 System.out.println(d.getOwner().getId());
34                 return;
35             }
36             new DomainPinglogForm(req, d).output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
37             try {
38                 new PingconfigForm(req, d).output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
39             } catch (GigiApiException e) {
40                 e.format(resp.getWriter(), getLanguage(req));
41             }
42             return;
43
44         }
45         try {
46             DomainManagementForm domMan = new DomainManagementForm(req, u);
47             DomainAddForm domAdd = new DomainAddForm(req, u);
48             HashMap<String, Object> vars = new HashMap<>();
49             vars.put("doms", u.getDomains());
50             vars.put("domainman", domMan);
51             vars.put("domainadd", domAdd);
52             getDefaultTemplate().output(resp.getWriter(), getLanguage(req), vars);
53         } catch (GigiApiException e) {
54             e.format(resp.getWriter(), getLanguage(req));
55         }
56     }
57
58     @Override
59     public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
60         User u = getUser(req);
61         String pi = req.getPathInfo();
62         if (pi.length() - PATH.length() > 0) {
63             int i = Integer.parseInt(pi.substring(PATH.length()));
64             Domain d = Domain.getById(i);
65             if (u.getId() != d.getOwner().getId()) {
66                 return;
67             }
68             int reping = Integer.parseInt(req.getParameter("configId"));
69             DomainPingConfiguration dpc = DomainPingConfiguration.getById(reping);
70             if (dpc.getTarget() != d) {
71                 return;
72             }
73             System.out.println("Would now reping: " + dpc.getInfo());
74         }
75         if (req.getParameter("adddomain") != null) {
76             DomainAddForm f = Form.getForm(req, DomainAddForm.class);
77             if (f.submit(resp.getWriter(), req)) {
78                 resp.sendRedirect(PATH);
79             }
80         } else if (req.getParameter("domdel") != null) {
81             DomainManagementForm f = Form.getForm(req, DomainManagementForm.class);
82             if (f.submit(resp.getWriter(), req)) {
83                 resp.sendRedirect(PATH);
84             }
85         }
86         super.doPost(req, resp);
87     }
88 }