1 package org.cacert.gigi.pages.account.domain;
3 import java.io.IOException;
4 import java.util.HashMap;
6 import javax.servlet.http.HttpServletRequest;
7 import javax.servlet.http.HttpServletResponse;
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;
17 public class DomainOverview extends Page {
19 public static final String PATH = "/account/domains/";
21 public DomainOverview(String title) {
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()));
33 d = Domain.getById(i);
34 } catch (IllegalArgumentException e) {
35 resp.getWriter().println(getLanguage(req).getTranslation("Access denied"));
38 if (u.getId() != d.getOwner().getId()) {
39 resp.getWriter().println(getLanguage(req).getTranslation("Access denied"));
42 new DomainPinglogForm(req, d).output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
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));
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);
60 getDefaultTemplate().output(resp.getWriter(), getLanguage(req), vars);
61 } catch (GigiApiException e) {
62 e.format(resp.getWriter(), getLanguage(req));
67 public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
68 String pi = req.getPathInfo();
69 if (pi.length() - PATH.length() > 0) {
71 if (req.getParameter("configId") != null) {
72 if ( !Form.getForm(req, DomainPinglogForm.class).submit(resp.getWriter(), req)) {
77 if ( !Form.getForm(req, PingConfigForm.class).submit(resp.getWriter(), req)) {
81 } catch (GigiApiException e) {
82 e.format(resp.getWriter(), getLanguage(req));
86 resp.sendRedirect(pi);
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);
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);
99 super.doPost(req, resp);