]> WPIA git - gigi.git/blob - src/org/cacert/gigi/pages/account/domain/EditDomain.java
fix: ResultSet.getDate is often wrong as it fetches day-precision times
[gigi.git] / src / org / cacert / gigi / pages / account / domain / EditDomain.java
1 package org.cacert.gigi.pages.account.domain;
2
3 import java.io.IOException;
4 import java.util.HashMap;
5
6 import javax.servlet.http.HttpServletRequest;
7 import javax.servlet.http.HttpServletResponse;
8
9 import org.cacert.gigi.GigiApiException;
10 import org.cacert.gigi.dbObjects.CertificateOwner;
11 import org.cacert.gigi.dbObjects.Domain;
12 import org.cacert.gigi.output.template.Form;
13 import org.cacert.gigi.output.template.Form.CSRFException;
14 import org.cacert.gigi.pages.LoginPage;
15 import org.cacert.gigi.pages.ManagedMultiFormPage;
16
17 public class EditDomain extends ManagedMultiFormPage {
18
19     public static final String PATH = "/account/domains/";
20
21     public EditDomain() {
22         super("Domain");
23     }
24
25     @Override
26     public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
27         CertificateOwner u = LoginPage.getAuthorizationContext(req).getTarget();
28         String pi = req.getPathInfo();
29         if (pi.length() - PATH.length() <= 0) {
30             return;
31         }
32         Form.printFormErrors(req, resp.getWriter());
33         int i = Integer.parseInt(pi.substring(PATH.length()));
34         Domain d;
35         try {
36             d = Domain.getById(i);
37         } catch (IllegalArgumentException e) {
38             resp.getWriter().println(getLanguage(req).getTranslation("Access denied"));
39             return;
40         }
41         if (d == null || u.getId() != d.getOwner().getId()) {
42             resp.getWriter().println(getLanguage(req).getTranslation("Access denied"));
43             return;
44         }
45         new DomainPinglogForm(req, d).output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
46         try {
47             new PingConfigForm(req, d).output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
48         } catch (GigiApiException e) {
49             e.format(resp.getWriter(), getLanguage(req));
50         }
51
52     }
53
54     @Override
55     public Form getForm(HttpServletRequest req) throws CSRFException {
56         String pi = req.getPathInfo();
57         if (pi.length() - PATH.length() <= 0) {
58             return null;
59         }
60         if (req.getParameter("configId") != null) {
61             return Form.getForm(req, DomainPinglogForm.class);
62         } else {
63             return Form.getForm(req, PingConfigForm.class);
64         }
65     }
66
67 }