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.User;
12 import org.cacert.gigi.output.template.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()));
31 d = Domain.getById(i);
32 } catch (IllegalArgumentException e) {
33 resp.getWriter().println(getLanguage(req).getTranslation("Access denied"));
36 if (u.getId() != d.getOwner().getId()) {
37 resp.getWriter().println(getLanguage(req).getTranslation("Access denied"));
40 new DomainPinglogForm(req, d).output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
42 new PingConfigForm(req, d).output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
43 } catch (GigiApiException e) {
44 e.format(resp.getWriter(), getLanguage(req));
50 DomainManagementForm domMan = new DomainManagementForm(req, u);
51 DomainAddForm domAdd = new DomainAddForm(req, u);
52 HashMap<String, Object> vars = new HashMap<>();
53 vars.put("doms", u.getDomains());
54 vars.put("domainman", domMan);
55 vars.put("domainadd", domAdd);
56 getDefaultTemplate().output(resp.getWriter(), getLanguage(req), vars);
57 } catch (GigiApiException e) {
58 e.format(resp.getWriter(), getLanguage(req));
63 public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
64 String pi = req.getPathInfo();
65 if (pi.length() - PATH.length() > 0) {
67 if (req.getParameter("configId") != null) {
68 if ( !Form.getForm(req, DomainPinglogForm.class).submit(resp.getWriter(), req)) {
73 if ( !Form.getForm(req, PingConfigForm.class).submit(resp.getWriter(), req)) {
77 } catch (GigiApiException e) {
78 e.format(resp.getWriter(), getLanguage(req));
82 resp.sendRedirect(pi);
84 if (req.getParameter("adddomain") != null) {
85 DomainAddForm f = Form.getForm(req, DomainAddForm.class);
86 if (f.submit(resp.getWriter(), req)) {
87 resp.sendRedirect(PATH);
89 } else if (req.getParameter("domdel") != null) {
90 DomainManagementForm f = Form.getForm(req, DomainManagementForm.class);
91 if (f.submit(resp.getWriter(), req)) {
92 resp.sendRedirect(PATH);
95 super.doPost(req, resp);