]> WPIA git - gigi.git/blob - src/org/cacert/gigi/pages/account/domain/DomainOverview.java
Fix: Beautify exception on invalid domain id
[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.template.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;
31             try {
32                 d = Domain.getById(i);
33             } catch (IllegalArgumentException e) {
34                 resp.getWriter().println(getLanguage(req).getTranslation("Access denied"));
35                 return;
36             }
37             if (u.getId() != d.getOwner().getId()) {
38                 resp.getWriter().println(getLanguage(req).getTranslation("Access denied"));
39                 return;
40             }
41             new DomainPinglogForm(req, d).output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
42             try {
43                 new PingConfigForm(req, d).output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
44             } catch (GigiApiException e) {
45                 e.format(resp.getWriter(), getLanguage(req));
46             }
47             return;
48
49         }
50         try {
51             DomainManagementForm domMan = new DomainManagementForm(req, u);
52             DomainAddForm domAdd = new DomainAddForm(req, u);
53             HashMap<String, Object> vars = new HashMap<>();
54             vars.put("doms", u.getDomains());
55             vars.put("domainman", domMan);
56             vars.put("domainadd", domAdd);
57             getDefaultTemplate().output(resp.getWriter(), getLanguage(req), vars);
58         } catch (GigiApiException e) {
59             e.format(resp.getWriter(), getLanguage(req));
60         }
61     }
62
63     @Override
64     public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
65         User u = getUser(req);
66         String pi = req.getPathInfo();
67         if (pi.length() - PATH.length() > 0) {
68             int i = Integer.parseInt(pi.substring(PATH.length()));
69             Domain d = Domain.getById(i);
70             if (u.getId() != d.getOwner().getId()) {
71                 return;
72             }
73             int reping = Integer.parseInt(req.getParameter("configId"));
74             DomainPingConfiguration dpc = DomainPingConfiguration.getById(reping);
75             if (dpc.getTarget() != d) {
76                 return;
77             }
78             try {
79                 dpc.requestReping();
80             } catch (GigiApiException e) {
81                 e.format(resp.getWriter(), getLanguage(req));
82                 return;
83             }
84             resp.sendRedirect(PATH + i);
85         }
86         if (req.getParameter("adddomain") != null) {
87             DomainAddForm f = Form.getForm(req, DomainAddForm.class);
88             if (f.submit(resp.getWriter(), req)) {
89                 resp.sendRedirect(PATH);
90             }
91         } else if (req.getParameter("domdel") != null) {
92             DomainManagementForm f = Form.getForm(req, DomainManagementForm.class);
93             if (f.submit(resp.getWriter(), req)) {
94                 resp.sendRedirect(PATH);
95             }
96         }
97         super.doPost(req, resp);
98     }
99 }