import org.cacert.gigi.GigiApiException;
import org.cacert.gigi.dbObjects.CertificateOwner;
-import org.cacert.gigi.dbObjects.Domain;
import org.cacert.gigi.dbObjects.User;
import org.cacert.gigi.output.template.Form;
+import org.cacert.gigi.output.template.Form.CSRFException;
import org.cacert.gigi.pages.LoginPage;
-import org.cacert.gigi.pages.Page;
+import org.cacert.gigi.pages.ManagedMultiFormPage;
-public class DomainOverview extends Page {
+public class DomainOverview extends ManagedMultiFormPage {
- public static final String PATH = "/account/domains/";
+ public static final String PATH = "/account/domains";
public DomainOverview() {
super("Domains");
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
CertificateOwner u = LoginPage.getAuthorizationContext(req).getTarget();
- String pi = req.getPathInfo();
- if (pi.length() - PATH.length() > 0) {
- int i = Integer.parseInt(pi.substring(PATH.length()));
- Domain d;
- try {
- d = Domain.getById(i);
- } catch (IllegalArgumentException e) {
- resp.getWriter().println(getLanguage(req).getTranslation("Access denied"));
- return;
- }
- if (u.getId() != d.getOwner().getId()) {
- resp.getWriter().println(getLanguage(req).getTranslation("Access denied"));
- return;
- }
- new DomainPinglogForm(req, d).output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
- try {
- new PingConfigForm(req, d).output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
- } catch (GigiApiException e) {
- e.format(resp.getWriter(), getLanguage(req));
- }
- return;
-
- }
try {
DomainManagementForm domMan = new DomainManagementForm(req, u, false);
HashMap<String, Object> vars = new HashMap<>();
}
@Override
- public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
- String pi = req.getPathInfo();
- if (pi.length() - PATH.length() > 0) {
- try {
- if (req.getParameter("configId") != null) {
- if ( !Form.getForm(req, DomainPinglogForm.class).submit(resp.getWriter(), req)) {
- // error?
- }
-
- } else {
- if ( !Form.getForm(req, PingConfigForm.class).submit(resp.getWriter(), req)) {
-
- }
- }
- } catch (GigiApiException e) {
- e.format(resp.getWriter(), getLanguage(req));
- return;
- }
-
- resp.sendRedirect(pi);
- }
+ public Form getForm(HttpServletRequest req) throws CSRFException {
if (req.getParameter("adddomain") != null) {
- DomainAddForm f = Form.getForm(req, DomainAddForm.class);
- if (f.submit(resp.getWriter(), req)) {
- resp.sendRedirect(PATH);
- }
- } else if (req.getParameter("domdel") != null) {
- DomainManagementForm f = Form.getForm(req, DomainManagementForm.class);
- if (f.submit(resp.getWriter(), req)) {
- resp.sendRedirect(PATH);
- }
+ return Form.getForm(req, DomainAddForm.class);
+ } else if (req.getParameter("delete") != null) {
+ return Form.getForm(req, DomainManagementForm.class);
}
- super.doPost(req, resp);
+ return null;
}
}