1 package org.cacert.gigi.pages.account;
3 import java.io.IOException;
4 import java.util.HashMap;
5 import javax.servlet.http.HttpServletRequest;
6 import javax.servlet.http.HttpServletResponse;
8 import org.cacert.gigi.GigiApiException;
9 import org.cacert.gigi.dbObjects.Domain;
10 import org.cacert.gigi.dbObjects.DomainPingConfiguration;
11 import org.cacert.gigi.dbObjects.User;
12 import org.cacert.gigi.output.Form;
13 import org.cacert.gigi.pages.Page;
15 public class DomainOverview extends Page {
17 public static final String PATH = "/account/domains/";
19 public DomainOverview(String title) {
24 public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
25 User u = getUser(req);
26 String pi = req.getPathInfo();
27 if (pi.length() - PATH.length() > 0) {
28 int i = Integer.parseInt(pi.substring(PATH.length()));
29 Domain d = Domain.getById(i);
30 if (u.getId() != d.getOwner().getId()) {
31 System.out.println(u.getId());
32 System.out.println(d.getOwner().getId());
35 new DomainPinglogForm(req, d).output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
37 new PingconfigForm(req, d).output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
38 } catch (GigiApiException e) {
39 e.format(resp.getWriter(), getLanguage(req));
45 DomainManagementForm domMan = new DomainManagementForm(req, u);
46 DomainAddForm domAdd = new DomainAddForm(req, u);
47 HashMap<String, Object> vars = new HashMap<>();
48 vars.put("doms", u.getDomains());
49 vars.put("domainman", domMan);
50 vars.put("domainadd", domAdd);
51 getDefaultTemplate().output(resp.getWriter(), getLanguage(req), vars);
52 } catch (GigiApiException e) {
53 e.format(resp.getWriter(), getLanguage(req));
58 public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
59 User u = getUser(req);
60 String pi = req.getPathInfo();
61 if (pi.length() - PATH.length() > 0) {
62 int i = Integer.parseInt(pi.substring(PATH.length()));
63 Domain d = Domain.getById(i);
64 if (u.getId() != d.getOwner().getId()) {
67 int reping = Integer.parseInt(req.getParameter("configId"));
68 DomainPingConfiguration dpc = DomainPingConfiguration.getById(reping);
69 if (dpc.getTarget() != d) {
72 System.out.println("Would now reping: " + dpc.getInfo());
74 if (req.getParameter("adddomain") != null) {
75 DomainAddForm f = Form.getForm(req, DomainAddForm.class);
76 if (f.submit(resp.getWriter(), req)) {
77 resp.sendRedirect(PATH);
79 } else if (req.getParameter("domdel") != null) {
80 DomainManagementForm f = Form.getForm(req, DomainManagementForm.class);
81 if (f.submit(resp.getWriter(), req)) {
82 resp.sendRedirect(PATH);
85 super.doPost(req, resp);