diff --git a/xmppserver/src/main/webapp/user-groups.jsp b/xmppserver/src/main/webapp/user-groups.jsp index 1d848172d1..21c56a3bd4 100644 --- a/xmppserver/src/main/webapp/user-groups.jsp +++ b/xmppserver/src/main/webapp/user-groups.jsp @@ -1,7 +1,7 @@ <%@ page contentType="text/html; charset=UTF-8" %> <%-- - - - Copyright (C) 2005-2008 Jive Software, 2017-2025 Ignite Realtime Foundation. All rights reserved. + - Copyright (C) 2005-2008 Jive Software, 2017-2026 Ignite Realtime Foundation. All rights reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. @@ -40,24 +40,26 @@ <% // Get parameters - String add = StringUtils.escapeHTMLTags(ParamUtils.getParameter(request, "add")); - String delete = StringUtils.escapeHTMLTags(ParamUtils.getParameter(request, "delete")); - boolean success = ParamUtils.getBooleanParameter(request,"updatesuccess"); - String username = StringUtils.escapeHTMLTags(ParamUtils.getParameter(request, "username")); + String add = ParamUtils.getParameter(request, "add"); + String delete = ParamUtils.getParameter(request, "delete"); + String username = ParamUtils.getParameter(request, "username"); JID jid = webManager.getXMPPServer().createJID(username, null); - Cookie csrfCookie = CookieUtils.getCookie(request, "csrf"); - String csrfParam = ParamUtils.getParameter(request, "csrf"); + Cookie csrfCookie = CookieUtils.getCookie(request, "csrf"); + String csrfParam = ParamUtils.getParameter(request, "csrf"); - if (add != null || delete != null) { - if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) { - add = null; - delete = null; - } + Map errors = new HashMap<>(); + pageContext.setAttribute("errors", errors); + if (add != null || delete != null) { + if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) { + add = null; + delete = null; + errors.put("csrf", "CSRF security check failed! Please reload page and try again."); } - csrfParam = StringUtils.randomString(15); - CookieUtils.setCookie(request, response, "csrf", csrfParam, -1); - pageContext.setAttribute("csrf", csrfParam); + } + csrfParam = StringUtils.randomString(15); + CookieUtils.setCookie(request, response, "csrf", csrfParam, -1); + pageContext.setAttribute("csrf", csrfParam); if(add != null) { @@ -92,7 +94,10 @@ Collection userGroups = webManager.getGroupManager().getGroups(user); int start = ParamUtils.getIntParameter(request,"start",0); int range = ParamUtils.getIntParameter(request,"range",15); - + if (range <= 0) { + range = 15; + } + if (request.getParameter("range") != null) { webManager.setRowsPerPage("group-summary", range); } @@ -101,55 +106,75 @@ // Remove already joined groups groups.removeAll(userGroups); - int groupCount = groups.size(); - int groupIndex = start + range; String search = null; if (webManager.getGroupManager().isSearchSupported() && request.getParameter("search") != null && !request.getParameter("search").trim().isEmpty()) { search = request.getParameter("search"); - search = StringUtils.escapeHTMLTags(search); // Use the search terms to get the list of groups. groups = new ArrayList<>(webManager.getGroupManager().search(search)); - // Count already joined groups in the search result - int userGroupCount = 0; - for(Group group : groups) { - if(userGroups.contains(group)) { - userGroupCount++; - } - } groups.removeAll(userGroups); - groupCount = groups.size() - userGroupCount; } - - if(groupIndex >= groupCount) { - groupIndex = groupCount; + + int groupCount = groups.size(); + + if (start < 0) { + start = 0; } + if (start >= groupCount) { + start = Math.max(0, ((groupCount - 1) / range) * range); + } + int end = Math.min(start + range, groupCount); + List pagedGroups = groups.subList(start, end); // paginator vars - int numPages = (int)Math.ceil((double)groupCount/(double)range); - int curPage = (start/range) + 1; - - if(success) { -%> - - - -<% - } + int numPages = groupCount == 0 ? 1 : (int)Math.ceil((double)groupCount / range); + int curPage = groupCount == 0 ? 1 : (start / range) + 1; + + pageContext.setAttribute("username", username); + pageContext.setAttribute("userGroups", userGroups); + pageContext.setAttribute("groupCount", groupCount); + pageContext.setAttribute("pagedGroups", pagedGroups); + pageContext.setAttribute("numPages", numPages); + pageContext.setAttribute("start", start); + pageContext.setAttribute("curPage", curPage); + pageContext.setAttribute("range", range); + pageContext.setAttribute("search", search); %> - -<fmt:message key="user.groups.title" /> - - + <fmt:message key="user.groups.title" /> + + + + + + + + + + + + : + + () + + + + + + + + + + + +

- <%=username%>. + .

@@ -161,41 +186,30 @@ - <% - // Print the list of groups - if (userGroups.isEmpty()) { - %> - - - - - <% - } - int x = 0; - for (Group group : userGroups) { - String groupName = URLEncoder.encode(group.getName(), StandardCharsets.UTF_8); - x++; - %> - - - - - - - <% - } - %> + + + + + + + + + + + + + + + +
<%=x%><%=StringUtils.escapeHTMLTags(group.getName())%> - <% - if (group.getDescription() != null) { - %>
<%=StringUtils.escapeHTMLTags(group.getDescription())%> - <% - } - %>
"><fmt:message key=">
+ +
+
+
"><fmt:message key=">
@@ -203,76 +217,50 @@

- <%=username%>. -

- <% - if (webManager.getGroupManager().isSearchSupported()) { - %> - -
- - - - - -
<%=groupCount%>
- -
- - - - <% - } - // Otherwise, searching is not supported. - else { - %> -

- - <%=groupCount%> - <% - if (numPages > 1) { - %> - - , - - <%=(start + 1)%>-<%=(start + range)%> - - <% - } - %> + .

- <% - } - %> - - <% - if (numPages > 1) { - %> - -

- - [ - <% - for (int i = 0; i < numPages; i++) { - String sep = ((i + 1) < numPages) ? " " : ""; - boolean isCurrent = (i + 1) == curPage; - %> - " - class="<%=((isCurrent) ? "jive-current" : "")%>"><%=(i + 1)%><%=sep%> - - <% - } - %> - ] -

- - <% - } - %> + + +
+ + + + + +
+ + +
+ + +
+ +

+ + + + , + + - + +

+
+
+ + +

+ + [ + + + + + + ] +

+
@@ -284,71 +272,47 @@ - - <% - // Print the list of groups - if (groups.isEmpty()) { - %> - - - - - <% - } - int i = 0; - for (Group group : groups.subList(start, groupIndex)) { - String groupName = URLEncoder.encode(group.getName(), StandardCharsets.UTF_8); - i++; - %> - - - - - - - <% - } - %> + + + + + + + + + + + + + + + +
<%=i%><%=StringUtils.escapeHTMLTags(group.getName())%> - <% - if (group.getDescription() != null) { - %>
<%=StringUtils.escapeHTMLTags(group.getDescription())%> - <% - } - %>
"> <fmt:message key=">
+ +
+
+
"> <fmt:message key=">
- <% - if (numPages > 1) { - %> -
-

- - [ - <% - for (i = 0; i < numPages; i++) { - String sep = ((i + 1) < numPages) ? " " : ""; - boolean isCurrent = (i + 1) == curPage; - %> - " - class="<%=((isCurrent) ? "jive-current" : "")%>"><%=(i + 1)%><%=sep%> - - <% - } - %> - ] -

- - <% - } - %> + +
+

+ + [ + + + + + + ] +

+