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