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.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;
16 public class DomainOverview extends Page {
18 public static final String PATH = "/account/domains/";
20 public DomainOverview(String title) {
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()));
32 d = Domain.getById(i);
33 } catch (IllegalArgumentException e) {
34 resp.getWriter().println(getLanguage(req).getTranslation("Access denied"));
37 if (u.getId() != d.getOwner().getId()) {
38 resp.getWriter().println(getLanguage(req).getTranslation("Access denied"));
41 new DomainPinglogForm(req, d).output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
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));
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));
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()) {
73 int reping = Integer.parseInt(req.getParameter("configId"));
74 DomainPingConfiguration dpc = DomainPingConfiguration.getById(reping);
75 if (dpc.getTarget() != d) {
80 } catch (GigiApiException e) {
81 e.format(resp.getWriter(), getLanguage(req));
84 resp.sendRedirect(PATH + i);
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);
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);
97 super.doPost(req, resp);