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