X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2Fpages%2Faccount%2Fdomain%2FDomainOverview.java;h=12f3916a5d2689df2c09c42d55bbb7ab967d3ee4;hp=b12eb42323f40cace4c156aa3817209b89e9ad58;hb=2235626fdc2b4025bbce7844307b3bc6e4e301a1;hpb=74f10c9db6cf2fcb5002ef4d2fa7f3c43abd6fb0 diff --git a/src/org/cacert/gigi/pages/account/domain/DomainOverview.java b/src/org/cacert/gigi/pages/account/domain/DomainOverview.java index b12eb423..12f3916a 100644 --- a/src/org/cacert/gigi/pages/account/domain/DomainOverview.java +++ b/src/org/cacert/gigi/pages/account/domain/DomainOverview.java @@ -6,37 +6,42 @@ import java.util.HashMap; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.cacert.gigi.Gigi; import org.cacert.gigi.GigiApiException; +import org.cacert.gigi.dbObjects.CertificateOwner; import org.cacert.gigi.dbObjects.Domain; -import org.cacert.gigi.dbObjects.DomainPingConfiguration; import org.cacert.gigi.dbObjects.User; -import org.cacert.gigi.output.Form; +import org.cacert.gigi.output.template.Form; +import org.cacert.gigi.pages.LoginPage; import org.cacert.gigi.pages.Page; public class DomainOverview extends Page { public static final String PATH = "/account/domains/"; - public DomainOverview(String title) { - super(title); + public DomainOverview() { + super("Domains"); } @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { - User u = getUser(req); + 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 = Domain.getById(i); + 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()) { - System.out.println(u.getId()); - System.out.println(d.getOwner().getId()); + resp.getWriter().println(getLanguage(req).getTranslation("Access denied")); return; } new DomainPinglogForm(req, d).output(resp.getWriter(), getLanguage(req), new HashMap()); try { - new PingconfigForm(req, d).output(resp.getWriter(), getLanguage(req), new HashMap()); + new PingConfigForm(req, d).output(resp.getWriter(), getLanguage(req), new HashMap()); } catch (GigiApiException e) { e.format(resp.getWriter(), getLanguage(req)); } @@ -44,12 +49,13 @@ public class DomainOverview extends Page { } try { - DomainManagementForm domMan = new DomainManagementForm(req, u); - DomainAddForm domAdd = new DomainAddForm(req, u); + DomainManagementForm domMan = new DomainManagementForm(req, u, false); HashMap vars = new HashMap<>(); - vars.put("doms", u.getDomains()); vars.put("domainman", domMan); - vars.put("domainadd", domAdd); + if (u instanceof User) { + DomainAddForm domAdd = new DomainAddForm(req, (User) u); + vars.put("domainadd", domAdd); + } getDefaultTemplate().output(resp.getWriter(), getLanguage(req), vars); } catch (GigiApiException e) { e.format(resp.getWriter(), getLanguage(req)); @@ -58,31 +64,34 @@ public class DomainOverview extends Page { @Override public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { - User u = getUser(req); String pi = req.getPathInfo(); if (pi.length() - PATH.length() > 0) { - int i = Integer.parseInt(pi.substring(PATH.length())); - Domain d = Domain.getById(i); - if (u.getId() != d.getOwner().getId()) { - return; - } - int reping = Integer.parseInt(req.getParameter("configId")); - DomainPingConfiguration dpc = DomainPingConfiguration.getById(reping); - if (dpc.getTarget() != d) { + 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; } - dpc.requestReping(); - Gigi.notifyPinger(); - resp.sendRedirect(PATH + i); + + resp.sendRedirect(pi); } 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) { + } else if (req.getParameter("delete") != null) { DomainManagementForm f = Form.getForm(req, DomainManagementForm.class); - if (f.submit(resp.getWriter(), req)) { + if (f.submitProtected(resp.getWriter(), req)) { resp.sendRedirect(PATH); } }