X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=util-testing%2Fclub%2Fwpia%2Fgigi%2Fpages%2FManager.java;fp=util-testing%2Fclub%2Fwpia%2Fgigi%2Fpages%2FManager.java;h=7dabe4f2720e1836dfa5e383df61a433ae80310f;hp=bed50973a1bbef8d13c791cb514bd409f05080b4;hb=3889444cb95132e342e4b7156245dd032ed3b16b;hpb=c33cfdbb921ffee8dae0e1fdede9c7bff55e00f4;ds=sidebyside diff --git a/util-testing/club/wpia/gigi/pages/Manager.java b/util-testing/club/wpia/gigi/pages/Manager.java index bed50973..7dabe4f2 100644 --- a/util-testing/club/wpia/gigi/pages/Manager.java +++ b/util-testing/club/wpia/gigi/pages/Manager.java @@ -32,7 +32,6 @@ import club.wpia.gigi.Gigi; import club.wpia.gigi.GigiApiException; import club.wpia.gigi.crypto.SPKAC; import club.wpia.gigi.database.GigiPreparedStatement; -import club.wpia.gigi.database.GigiResultSet; import club.wpia.gigi.dbObjects.CATS; import club.wpia.gigi.dbObjects.CATS.CATSType; import club.wpia.gigi.dbObjects.Certificate; @@ -179,21 +178,14 @@ public class Manager extends Page { } private void expireCATS(User u, CATSType t) { - try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT `id` FROM `cats_passed` WHERE `user_id`=? AND `variant_id`=? AND `pass_date`>?")) { - ps.setInt(1, u.getId()); - ps.setInt(2, t.getId()); - ps.setTimestamp(3, new Timestamp(System.currentTimeMillis() - DayDate.MILLI_DAY * 366)); + try (GigiPreparedStatement ps = new GigiPreparedStatement("UPDATE `cats_passed` SET `pass_date`=? WHERE `user_id`=? AND `variant_id`=? AND `pass_date`>?")) { + ps.setTimestamp(1, new Timestamp(System.currentTimeMillis() - DayDate.MILLI_DAY * 367)); + ps.setInt(2, u.getId()); + ps.setInt(3, t.getId()); + ps.setTimestamp(4, new Timestamp(System.currentTimeMillis() - DayDate.MILLI_DAY * 366)); ps.execute(); - GigiResultSet rs = ps.executeQuery(); - while (rs.next()) { - GigiPreparedStatement ps1 = new GigiPreparedStatement("UPDATE `cats_passed` SET `pass_date`=? WHERE `id`=?"); - ps1.setTimestamp(1, new Timestamp(System.currentTimeMillis() - DayDate.MILLI_DAY * 367)); - ps1.setInt(2, rs.getInt(1)); - ps1.execute(); - ps1.close(); - } + ps.close(); } - } private static Manager instance; @@ -352,17 +344,17 @@ public class Manager extends Page { throw new Error(e); } } else if (req.getParameter("addpriv") != null || req.getParameter("delpriv") != null) { - User u = User.getByEmail(req.getParameter("email")); - if (u == null) { + User userByEmail = User.getByEmail(req.getParameter("email")); + if (userByEmail == null) { resp.getWriter().println("User not found."); return; } try { if (req.getParameter("addpriv") != null) { - u.grantGroup(getSupporter(), Group.getByString(req.getParameter("priv"))); + userByEmail.grantGroup(getSupporter(), Group.getByString(req.getParameter("priv"))); resp.getWriter().println("Privilege granted"); } else { - u.revokeGroup(getSupporter(), Group.getByString(req.getParameter("priv"))); + userByEmail.revokeGroup(getSupporter(), Group.getByString(req.getParameter("priv"))); resp.getWriter().println("Privilege revoked"); } } catch (GigiApiException e) { @@ -373,40 +365,52 @@ public class Manager extends Page { fetchMails(req, resp, mail); } else if (req.getParameter("cats") != null) { String mail = req.getParameter("catsEmail"); - String testId = req.getParameter("catsType"); + String catsTypeId = req.getParameter("catsType"); User byEmail = User.getByEmail(mail); if (byEmail == null) { resp.getWriter().println("User not found."); return; } - if (testId == null) { + if (catsTypeId == null) { resp.getWriter().println("No test given."); return; } - CATSType test = CATSType.values()[Integer.parseInt(testId)]; + CATSType test = null; + try { + test = CATSType.values()[Integer.parseInt(catsTypeId)]; + } catch (NumberFormatException e) { + resp.getWriter().println("No valid integer given."); + return; + } passCATS(byEmail, test); resp.getWriter().println("Test '" + test.getDisplayName() + "' was added to user account."); } else if (req.getParameter("catsexpire") != null) { String mail = req.getParameter("catsEmail"); - String testId = req.getParameter("catsType"); - User byEmail = User.getByEmail(mail); - if (byEmail == null) { + String catsTypeId = req.getParameter("catsType"); + User userByEmail = User.getByEmail(mail); + if (userByEmail == null) { resp.getWriter().println("User not found."); return; } - if (testId == null) { + if (catsTypeId == null) { resp.getWriter().println("No test given."); return; } - CATSType test = CATSType.values()[Integer.parseInt(testId)]; - expireCATS(byEmail, test); + CATSType test = null; + try { + test = CATSType.values()[Integer.parseInt(catsTypeId)]; + } catch (NumberFormatException e) { + resp.getWriter().println("No valid integer given."); + return; + } + expireCATS(userByEmail, test); resp.getWriter().println("Test '" + test.getDisplayName() + "' is set expired for user account."); } else if (req.getParameter("verify") != null) { String mail = req.getParameter("verifyEmail"); String verificationPoints = req.getParameter("verificationPoints"); - User byEmail = User.getByEmail(mail); + User userByEmail = User.getByEmail(mail); - if (byEmail == null) { + if (userByEmail == null) { resp.getWriter().println("User not found."); return; } @@ -423,16 +427,16 @@ public class Manager extends Page { vp = 0; } - int agentNumber = addVerificationPoints(vp, byEmail); + int agentNumber = addVerificationPoints(vp, userByEmail); while (vp > 0) { int currentVP = 10; if (vp < 10) { currentVP = vp; } - if (Notary.checkVerificationIsPossible(getAgent(agentNumber), byEmail.getPreferredName())) { + if (Notary.checkVerificationIsPossible(getAgent(agentNumber), userByEmail.getPreferredName())) { - Notary.verify(getAgent(agentNumber), byEmail, byEmail.getPreferredName(), byEmail.getDoB(), currentVP, "Testmanager Verify up code", validVerificationDateString(), VerificationType.FACE_TO_FACE, getRandomCountry()); + Notary.verify(getAgent(agentNumber), userByEmail, userByEmail.getPreferredName(), userByEmail.getDoB(), currentVP, "Testmanager Verify up code", validVerificationDateString(), VerificationType.FACE_TO_FACE, getRandomCountry()); vp -= currentVP; verifications += 1; @@ -463,14 +467,14 @@ public class Manager extends Page { resp.getWriter().println("Verification set to time past the limit."); } else if (req.getParameter("letverify") != null) { String mail = req.getParameter("letverifyEmail"); - User byEmail = User.getByEmail(mail); - if (byEmail == null || !byEmail.canVerify()) { + User userByEmail = User.getByEmail(mail); + if (userByEmail == null || !userByEmail.canVerify()) { resp.getWriter().println("User not found, or found user is not allowed to verify."); } else { try { for (int i = 0; i < 25; i++) { User a = getAgent(i); - Notary.verify(byEmail, a, a.getNames()[0], a.getDoB(), 10, "Testmanager exp up code", validVerificationDateString(), VerificationType.FACE_TO_FACE, getRandomCountry()); + Notary.verify(userByEmail, a, a.getNames()[0], a.getDoB(), 10, "Testmanager exp up code", validVerificationDateString(), VerificationType.FACE_TO_FACE, getRandomCountry()); } resp.getWriter().println("Successfully added experience points."); } catch (GigiApiException e) { @@ -478,9 +482,9 @@ public class Manager extends Page { } } } else if (req.getParameter("addEmail") != null) { - User u = User.getByEmail(req.getParameter("addEmailEmail")); + User userByEmail = User.getByEmail(req.getParameter("addEmailEmail")); try { - EmailAddress ea = new EmailAddress(u, req.getParameter("addEmailNew"), Locale.ENGLISH); + EmailAddress ea = new EmailAddress(userByEmail, req.getParameter("addEmailNew"), Locale.ENGLISH); verify(ea.getAddress(), ea); } catch (IllegalArgumentException e) { e.printStackTrace(); @@ -489,7 +493,7 @@ public class Manager extends Page { e.format(resp.getWriter(), Language.getInstance(Locale.ENGLISH), getDefaultVars(req)); } } else if (req.getParameter("addCert") != null) { - User u = User.getByEmail(req.getParameter("addCertEmail")); + User userByEmail = User.getByEmail(req.getParameter("addCertEmail")); try { KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA"); kpg.initialize(4096); @@ -500,10 +504,10 @@ public class Manager extends Page { byte[] res = s.getEncoded(sign); - CertificateRequest cr = new CertificateRequest(new AuthorizationContext(u, u, sessionAc.isStronglyAuthenticated()), Base64.getEncoder().encodeToString(res), "challenge"); - cr.update(CertificateRequest.DEFAULT_CN, Digest.SHA512.toString(), "client", null, "", "email:" + u.getEmail()); + CertificateRequest cr = new CertificateRequest(new AuthorizationContext(userByEmail, userByEmail, sessionAc.isStronglyAuthenticated()), Base64.getEncoder().encodeToString(res), "challenge"); + cr.update(CertificateRequest.DEFAULT_CN, Digest.SHA512.toString(), "client", null, "", "email:" + userByEmail.getEmail()); Certificate draft = cr.draft(); - draft.issue(null, "2y", u).waitFor(10000); + draft.issue(null, "2y", userByEmail).waitFor(10000); if (draft.getStatus() == CertificateStatus.ISSUED) { resp.getWriter().println("added certificate"); } else { @@ -527,19 +531,19 @@ public class Manager extends Page { resp.getWriter().println("Updated domains exempt from pings. Current set:
"); resp.getWriter().println(HTMLEncoder.encodeHTML(pingExempt.toString())); } else if (req.getParameter("makeAgent") != null) { - User u = User.getByEmail(req.getParameter("agentEmail")); - if (u == null) { + User userByEmail = User.getByEmail(req.getParameter("agentEmail")); + if (userByEmail == null) { resp.getWriter().println("User not found, or found user is not allowed to verify."); } else { - if (u.getVerificationPoints() < 100) { - addVerificationPoints(100, u); + if (userByEmail.getVerificationPoints() < 100) { + addVerificationPoints(100, userByEmail); } - if ( !u.hasPassedCATS()) { - passCATS(u, CATSType.AGENT_CHALLENGE); + if ( !userByEmail.hasPassedCATS()) { + passCATS(userByEmail, CATSType.AGENT_CHALLENGE); } - if ( !Contract.hasSignedContract(u, Contract.ContractType.RA_AGENT_CONTRACT)) { + if ( !Contract.hasSignedContract(userByEmail, Contract.ContractType.RA_AGENT_CONTRACT)) { try { - new Contract(u, Contract.ContractType.RA_AGENT_CONTRACT); + new Contract(userByEmail, Contract.ContractType.RA_AGENT_CONTRACT); } catch (GigiApiException e) { throw new Error(e); }