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.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()));
30 Domain d = Domain.getById(i);
31 if (u.getId() != d.getOwner().getId()) {
32 System.out.println(u.getId());
33 System.out.println(d.getOwner().getId());
36 new DomainPinglogForm(req, d).output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
38 new PingconfigForm(req, d).output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
39 } catch (GigiApiException e) {
40 e.format(resp.getWriter(), getLanguage(req));
46 DomainManagementForm domMan = new DomainManagementForm(req, u);
47 DomainAddForm domAdd = new DomainAddForm(req, u);
48 HashMap<String, Object> vars = new HashMap<>();
49 vars.put("doms", u.getDomains());
50 vars.put("domainman", domMan);
51 vars.put("domainadd", domAdd);
52 getDefaultTemplate().output(resp.getWriter(), getLanguage(req), vars);
53 } catch (GigiApiException e) {
54 e.format(resp.getWriter(), getLanguage(req));
59 public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
60 User u = getUser(req);
61 String pi = req.getPathInfo();
62 if (pi.length() - PATH.length() > 0) {
63 int i = Integer.parseInt(pi.substring(PATH.length()));
64 Domain d = Domain.getById(i);
65 if (u.getId() != d.getOwner().getId()) {
68 int reping = Integer.parseInt(req.getParameter("configId"));
69 DomainPingConfiguration dpc = DomainPingConfiguration.getById(reping);
70 if (dpc.getTarget() != d) {
73 System.out.println("Would now reping: " + dpc.getInfo());
75 if (req.getParameter("adddomain") != null) {
76 DomainAddForm f = Form.getForm(req, DomainAddForm.class);
77 if (f.submit(resp.getWriter(), req)) {
78 resp.sendRedirect(PATH);
80 } else if (req.getParameter("domdel") != null) {
81 DomainManagementForm f = Form.getForm(req, DomainManagementForm.class);
82 if (f.submit(resp.getWriter(), req)) {
83 resp.sendRedirect(PATH);
86 super.doPost(req, resp);