]> WPIA git - gigi.git/blob - src/org/cacert/gigi/pages/account/DomainOverview.java
Convert Pinglog into form.
[gigi.git] / src / org / cacert / gigi / pages / account / DomainOverview.java
1 package org.cacert.gigi.pages.account;
2
3 import java.io.IOException;
4 import java.util.HashMap;
5 import javax.servlet.http.HttpServletRequest;
6 import javax.servlet.http.HttpServletResponse;
7
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;
14
15 public class DomainOverview extends Page {
16
17     public static final String PATH = "/account/domains/";
18
19     public DomainOverview(String title) {
20         super(title);
21     }
22
23     @Override
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());
33                 return;
34             }
35             new DomainPinglogForm(req, d).output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
36             try {
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));
40             }
41             return;
42
43         }
44         try {
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));
54         }
55     }
56
57     @Override
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()) {
65                 return;
66             }
67             int reping = Integer.parseInt(req.getParameter("configId"));
68             DomainPingConfiguration dpc = DomainPingConfiguration.getById(reping);
69             if (dpc.getTarget() != d) {
70                 return;
71             }
72             System.out.println("Would now reping: " + dpc.getInfo());
73         }
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);
78             }
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);
83             }
84         }
85         super.doPost(req, resp);
86     }
87 }