X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2FGigi.java;h=bf6c32edc2404126276fcf140842cb18f80a0cab;hp=c70c913b5dc19f785218aac7f17001caad45fb6d;hb=d7be034f96e06985f57d86d2779c434276b5bd4d;hpb=4f97bf32fa55683442e6d80fe9b590ef0054505e diff --git a/src/org/cacert/gigi/Gigi.java b/src/org/cacert/gigi/Gigi.java index c70c913b..bf6c32ed 100644 --- a/src/org/cacert/gigi/Gigi.java +++ b/src/org/cacert/gigi/Gigi.java @@ -21,14 +21,13 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.cacert.gigi.database.DatabaseConnection; +import org.cacert.gigi.database.DatabaseConnection.Link; import org.cacert.gigi.dbObjects.CACertificate; -import org.cacert.gigi.dbObjects.CertificateOwner; import org.cacert.gigi.dbObjects.CertificateProfile; import org.cacert.gigi.dbObjects.DomainPingConfiguration; -import org.cacert.gigi.dbObjects.Organisation; -import org.cacert.gigi.dbObjects.User; import org.cacert.gigi.localisation.Language; import org.cacert.gigi.output.Menu; +import org.cacert.gigi.output.MenuCollector; import org.cacert.gigi.output.PageMenuItem; import org.cacert.gigi.output.SimpleMenuItem; import org.cacert.gigi.output.template.Form.CSRFException; @@ -39,13 +38,15 @@ import org.cacert.gigi.pages.LoginPage; import org.cacert.gigi.pages.LogoutPage; import org.cacert.gigi.pages.MainPage; import org.cacert.gigi.pages.Page; -import org.cacert.gigi.pages.PolicyIndex; +import org.cacert.gigi.pages.PasswordResetPage; import org.cacert.gigi.pages.RootCertPage; import org.cacert.gigi.pages.StaticPage; import org.cacert.gigi.pages.TestSecure; import org.cacert.gigi.pages.Verify; import org.cacert.gigi.pages.account.ChangePasswordPage; +import org.cacert.gigi.pages.account.History; import org.cacert.gigi.pages.account.MyDetails; +import org.cacert.gigi.pages.account.UserTrainings; import org.cacert.gigi.pages.account.certs.CertificateAdd; import org.cacert.gigi.pages.account.certs.Certificates; import org.cacert.gigi.pages.account.domain.DomainOverview; @@ -53,6 +54,7 @@ import org.cacert.gigi.pages.account.mail.MailOverview; import org.cacert.gigi.pages.admin.TTPAdminPage; import org.cacert.gigi.pages.admin.support.FindDomainPage; import org.cacert.gigi.pages.admin.support.FindUserPage; +import org.cacert.gigi.pages.admin.support.SupportEnterTicketPage; import org.cacert.gigi.pages.admin.support.SupportUserDetailsPage; import org.cacert.gigi.pages.error.AccessDenied; import org.cacert.gigi.pages.error.PageNotFound; @@ -60,13 +62,14 @@ import org.cacert.gigi.pages.main.RegisterPage; import org.cacert.gigi.pages.orga.CreateOrgPage; import org.cacert.gigi.pages.orga.ViewOrgPage; import org.cacert.gigi.pages.wot.AssurePage; +import org.cacert.gigi.pages.wot.MyListingPage; import org.cacert.gigi.pages.wot.MyPoints; import org.cacert.gigi.pages.wot.RequestTTPPage; import org.cacert.gigi.ping.PingerDaemon; import org.cacert.gigi.util.AuthorizationContext; import org.cacert.gigi.util.ServerConstants; -public class Gigi extends HttpServlet { +public final class Gigi extends HttpServlet { private class MenuBuilder { @@ -74,7 +77,7 @@ public class Gigi extends HttpServlet { private HashMap pages = new HashMap(); - private Menu rootMenu; + private MenuCollector rootMenu; public MenuBuilder() {} @@ -103,45 +106,59 @@ public class Gigi extends HttpServlet { return m; } - public Menu generateMenu() throws ServletException { + public MenuCollector generateMenu() throws ServletException { putPage("/denied", new AccessDenied(), null); putPage("/error", new PageNotFound(), null); - putPage("/login", new LoginPage("Password Login"), null); - getMenu("CAcert.org").addItem(new SimpleMenuItem("https://" + ServerConstants.getWwwHostNamePort() + "/login", "Password Login") { + putPage("/login", new LoginPage(), null); + getMenu("SomeCA.org").addItem(new SimpleMenuItem("https://" + ServerConstants.getWwwHostNamePort() + "/login", "Password Login") { @Override public boolean isPermitted(AuthorizationContext ac) { return ac == null; } }); - getMenu("CAcert.org").addItem(new SimpleMenuItem("https://" + ServerConstants.getSecureHostNamePort() + "/login", "Certificate Login") { + getMenu("SomeCA.org").addItem(new SimpleMenuItem("https://" + ServerConstants.getSecureHostNamePort() + "/login", "Certificate Login") { @Override public boolean isPermitted(AuthorizationContext ac) { return ac == null; } }); - putPage("/", new MainPage("CAcert - Home"), null); - putPage("/roots", new RootCertPage(truststore), "CAcert.org"); - putPage(ChangePasswordPage.PATH, new ChangePasswordPage(), "My Account"); - putPage(LogoutPage.PATH, new LogoutPage("Logout"), "My Account"); + putPage("/", new MainPage(), null); + putPage("/roots", new RootCertPage(truststore), "SomeCA.org"); + putPage("/secure", new TestSecure(), null); putPage(Verify.PATH, new Verify(), null); - putPage(AssurePage.PATH + "/*", new AssurePage(), "Web of Trust"); putPage(Certificates.PATH + "/*", new Certificates(), "Certificates"); - putPage(MyDetails.PATH, new MyDetails(), "My Account"); - putPage(RegisterPage.PATH, new RegisterPage(), "CAcert.org"); + putPage(RegisterPage.PATH, new RegisterPage(), "SomeCA.org"); putPage(CertificateAdd.PATH, new CertificateAdd(), "Certificates"); - putPage(MailOverview.DEFAULT_PATH, new MailOverview("My email addresses"), "Certificates"); - putPage(DomainOverview.PATH + "*", new DomainOverview("Domains"), "Certificates"); - putPage(MyPoints.PATH, new MyPoints("My Points"), "Web of Trust"); + putPage(MailOverview.DEFAULT_PATH, new MailOverview(), "Certificates"); + putPage(DomainOverview.PATH + "*", new DomainOverview(), "Certificates"); + + putPage(AssurePage.PATH + "/*", new AssurePage(), "Web of Trust"); + putPage(MyPoints.PATH, new MyPoints(), "Web of Trust"); + putPage(MyListingPage.PATH, new MyListingPage(), "Web of Trust"); putPage(RequestTTPPage.PATH, new RequestTTPPage(), "Web of Trust"); + putPage(TTPAdminPage.PATH + "/*", new TTPAdminPage(), "Admin"); putPage(CreateOrgPage.DEFAULT_PATH, new CreateOrgPage(), "Organisation Admin"); putPage(ViewOrgPage.DEFAULT_PATH + "/*", new ViewOrgPage(), "Organisation Admin"); - putPage(FindUserPage.PATH, new FindUserPage("Find User"), "System Admin"); - putPage(FindDomainPage.PATH, new FindDomainPage("Find Domain"), "System Admin"); - putPage(SupportUserDetailsPage.PATH + "*", new SupportUserDetailsPage("Support: User Details"), null); + + putPage(SupportEnterTicketPage.PATH, new SupportEnterTicketPage(), "Support Console"); + putPage(FindUserPage.PATH, new FindUserPage(), "Support Console"); + putPage(FindDomainPage.PATH, new FindDomainPage(), "Support Console"); + + putPage(SupportUserDetailsPage.PATH + "*", new SupportUserDetailsPage(), null); + putPage(ChangePasswordPage.PATH, new ChangePasswordPage(), "My Account"); + putPage(LogoutPage.PATH, new LogoutPage(), "My Account"); + putPage(History.PATH, new History(false), "My Account"); + putPage(History.SUPPORT_PATH, new History(true), null); + putPage(UserTrainings.PATH, new UserTrainings(false), "My Account"); + putPage(MyDetails.PATH, new MyDetails(), "My Account"); + putPage(UserTrainings.SUPPORT_PATH, new UserTrainings(true), null); + + putPage(PasswordResetPage.PATH, new PasswordResetPage(), null); + if (testing) { try { Class manager = Class.forName("org.cacert.gigi.pages.Manager"); @@ -159,30 +176,19 @@ public class Gigi extends HttpServlet { throw new ServletException(e); } baseTemplate = new Template(Gigi.class.getResource("Gigi.templ")); - rootMenu = new Menu("Main"); - Menu about = new Menu("About CAcert.org"); - categories.add(about); - - about.addItem(new SimpleMenuItem("//blog.cacert.org/", "CAcert News")); - about.addItem(new SimpleMenuItem("//wiki.cacert.org/", "Wiki Documentation")); - putPage(PolicyIndex.DEFAULT_PATH, new PolicyIndex(), "About CAcert.org"); - about.addItem(new SimpleMenuItem("//wiki.cacert.org/FAQ/Privileges", "Point System")); - about.addItem(new SimpleMenuItem("//bugs.cacert.org/", "Bug Database")); - about.addItem(new SimpleMenuItem("//wiki.cacert.org/Board", "CAcert Board")); - about.addItem(new SimpleMenuItem("//lists.cacert.org/wws", "Mailing Lists")); - about.addItem(new SimpleMenuItem("//blog.CAcert.org/feed", "RSS News Feed")); - - Menu languages = new Menu("Translations"); + rootMenu = new MenuCollector(); + + Menu languages = new Menu("Language"); for (Locale l : Language.getSupportedLocales()) { languages.addItem(new SimpleMenuItem("?lang=" + l.toString(), l.getDisplayName(l))); } categories.add(languages); for (Menu menu : categories) { menu.prepare(); - rootMenu.addItem(menu); + rootMenu.put(menu); } - rootMenu.prepare(); + // rootMenu.prepare(); return rootMenu; } @@ -213,7 +219,7 @@ public class Gigi extends HttpServlet { private boolean testing; - private Menu rootMenu; + private MenuCollector rootMenu; private Map pages; @@ -240,8 +246,12 @@ public class Gigi extends HttpServlet { return; } // ensure those static initializers are finished - CACertificate.getById(1); - CertificateProfile.getById(1); + try (Link l = DatabaseConnection.newLink(false)) { + CACertificate.getById(1); + CertificateProfile.getById(1); + } catch (InterruptedException e) { + throw new Error(e); + } MenuBuilder mb = new MenuBuilder(); rootMenu = mb.generateMenu(); @@ -264,17 +274,20 @@ public class Gigi extends HttpServlet { return page; } int idx = pathInfo.lastIndexOf('/'); + if (idx == -1 || idx == 0) { + return null; + } page = pages.get(pathInfo.substring(0, idx) + "/*"); if (page != null) { return page; } - - int lIdx = pathInfo.lastIndexOf('/', idx); + int lIdx = pathInfo.lastIndexOf('/', idx - 1); if (lIdx == -1) { return null; } - page = pages.get(pathInfo.substring(0, lIdx) + "/" + pathInfo.substring(idx)); + String lastResort = pathInfo.substring(0, lIdx) + "/*" + pathInfo.substring(idx); + page = pages.get(lastResort); return page; } @@ -293,6 +306,20 @@ public class Gigi extends HttpServlet { @Override protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { + if ("/error".equals(req.getPathInfo()) || "/denied".equals(req.getPathInfo())) { + if (DatabaseConnection.hasInstance()) { + serviceWithConnection(req, resp); + return; + } + } + try (DatabaseConnection.Link l = DatabaseConnection.newLink( !req.getMethod().equals("POST"))) { + serviceWithConnection(req, resp); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + protected void serviceWithConnection(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { boolean isSecure = req.isSecure(); addXSSHeaders(resp, isSecure); // Firefox only sends this, if it's a cross domain access; safari sends @@ -348,6 +375,8 @@ public class Gigi extends HttpServlet { return; } HashMap vars = new HashMap(); + // System.out.println(req.getMethod() + ": " + req.getPathInfo() + + // " -> " + p); Outputable content = new Outputable() { @Override @@ -382,14 +411,10 @@ public class Gigi extends HttpServlet { vars.put("year", Calendar.getInstance().get(Calendar.YEAR)); vars.put("content", content); if (currentAuthContext != null) { - CertificateOwner target = currentAuthContext.getTarget(); - User currentPageUser = LoginPage.getUser(req); - if (target != currentPageUser) { - vars.put("loggedInAs", ((Organisation) target).getName() + " (" + currentPageUser.getName().toString() + ")"); - } else { - vars.put("loggedInAs", currentPageUser.getName().toString()); - } - vars.put("loginMethod", lang.getTranslation((String) req.getSession().getAttribute(LOGIN_METHOD))); + // TODO maybe move this information into the AuthContext object + vars.put("loginMethod", req.getSession().getAttribute(LOGIN_METHOD)); + vars.put("authContext", currentAuthContext); + } resp.setContentType("text/html; charset=utf-8"); baseTemplate.output(resp.getWriter(), lang, vars); @@ -424,7 +449,7 @@ public class Gigi extends HttpServlet { csp.append(";script-src https://" + ServerConstants.getStaticHostNamePortSecure()); csp.append(";style-src https://" + ServerConstants.getStaticHostNamePortSecure()); csp.append(";form-action https://" + ServerConstants.getSecureHostNamePort() + " https://" + ServerConstants.getWwwHostNamePortSecure()); - csp.append(";report-url https://api.cacert.org/security/csp/report"); + // csp.append(";report-url https://api.cacert.org/security/csp/report"); return csp.toString(); } @@ -437,7 +462,7 @@ public class Gigi extends HttpServlet { csp.append(";script-src http://" + ServerConstants.getStaticHostNamePort()); csp.append(";style-src http://" + ServerConstants.getStaticHostNamePort()); csp.append(";form-action https://" + ServerConstants.getSecureHostNamePort() + " https://" + ServerConstants.getWwwHostNamePort()); - csp.append(";report-url http://api.cacert.org/security/csp/report"); + // csp.append(";report-url http://api.cacert.org/security/csp/report"); return csp.toString(); }