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