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() {
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 Form.printFormErrors(req, resp.getWriter());
31 int i = Integer.parseInt(pi.substring(PATH.length()));
34 d = Domain.getById(i);
35 } catch (IllegalArgumentException e) {
36 resp.getWriter().println(getLanguage(req).getTranslation("Access denied"));
39 if (d == null || u.getId() != d.getOwner().getId()) {
40 resp.getWriter().println(getLanguage(req).getTranslation("Access denied"));
43 new DomainPinglogForm(req, d).output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
45 new PingConfigForm(req, d).output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
46 } catch (GigiApiException e) {
47 e.format(resp.getWriter(), getLanguage(req));
53 DomainManagementForm domMan = new DomainManagementForm(req, u, false);
54 HashMap<String, Object> vars = new HashMap<>();
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 boolean beforePost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
68 String pi = req.getPathInfo();
69 if (pi.length() - PATH.length() > 0) {
70 if (req.getParameter("configId") != null) {
71 if (Form.getForm(req, DomainPinglogForm.class).submitExceptionProtected(req)) {
72 resp.sendRedirect(pi);
77 if (Form.getForm(req, PingConfigForm.class).submitExceptionProtected(req)) {
78 resp.sendRedirect(pi);
84 return super.beforePost(req, resp);
88 public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
89 if (req.getParameter("adddomain") != null) {
90 DomainAddForm f = Form.getForm(req, DomainAddForm.class);
91 if (f.submitProtected(resp.getWriter(), req)) {
92 resp.sendRedirect(PATH);
94 } else if (req.getParameter("delete") != null) {
95 DomainManagementForm f = Form.getForm(req, DomainManagementForm.class);
96 if (f.submitProtected(resp.getWriter(), req)) {
97 resp.sendRedirect(PATH);
100 super.doPost(req, resp);