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.Gigi;
10 import org.cacert.gigi.GigiApiException;
11 import org.cacert.gigi.dbObjects.Domain;
12 import org.cacert.gigi.dbObjects.DomainPingConfiguration;
13 import org.cacert.gigi.dbObjects.User;
14 import org.cacert.gigi.output.template.Form;
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 User u = getUser(req);
28 String pi = req.getPathInfo();
29 if (pi.length() - PATH.length() > 0) {
30 int i = Integer.parseInt(pi.substring(PATH.length()));
31 Domain d = Domain.getById(i);
32 if (u.getId() != d.getOwner().getId()) {
33 System.out.println(u.getId());
34 System.out.println(d.getOwner().getId());
37 new DomainPinglogForm(req, d).output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
39 new PingConfigForm(req, d).output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
40 } catch (GigiApiException e) {
41 e.format(resp.getWriter(), getLanguage(req));
47 DomainManagementForm domMan = new DomainManagementForm(req, u);
48 DomainAddForm domAdd = new DomainAddForm(req, u);
49 HashMap<String, Object> vars = new HashMap<>();
50 vars.put("doms", u.getDomains());
51 vars.put("domainman", domMan);
52 vars.put("domainadd", domAdd);
53 getDefaultTemplate().output(resp.getWriter(), getLanguage(req), vars);
54 } catch (GigiApiException e) {
55 e.format(resp.getWriter(), getLanguage(req));
60 public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
61 User u = getUser(req);
62 String pi = req.getPathInfo();
63 if (pi.length() - PATH.length() > 0) {
64 int i = Integer.parseInt(pi.substring(PATH.length()));
65 Domain d = Domain.getById(i);
66 if (u.getId() != d.getOwner().getId()) {
69 int reping = Integer.parseInt(req.getParameter("configId"));
70 DomainPingConfiguration dpc = DomainPingConfiguration.getById(reping);
71 if (dpc.getTarget() != d) {
76 resp.sendRedirect(PATH + i);
78 if (req.getParameter("adddomain") != null) {
79 DomainAddForm f = Form.getForm(req, DomainAddForm.class);
80 if (f.submit(resp.getWriter(), req)) {
81 resp.sendRedirect(PATH);
83 } else if (req.getParameter("domdel") != null) {
84 DomainManagementForm f = Form.getForm(req, DomainManagementForm.class);
85 if (f.submit(resp.getWriter(), req)) {
86 resp.sendRedirect(PATH);
89 super.doPost(req, resp);