%@ page contentType="text/html; charset=UTF-8" %>
<%--
-
- Copyright (C) 2024-2025 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.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--%>
<%@ page import="org.jivesoftware.openfire.muc.MultiUserChatService" %>
<%@ page import="java.net.URLEncoder" %>
<%@ page import="java.util.Collection" %>
<%@ page import="org.jivesoftware.util.*" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="org.jivesoftware.openfire.muc.MUCRoomRetiree" %>
<%@ page import="java.nio.charset.StandardCharsets" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib prefix="admin" uri="admin" %>
<%
// Initialize paging
final int DEFAULT_RANGE = 100;
final int[] RANGE_PRESETS = {25, 50, 75, 100, 500, 1000};
webManager.init(request, response, session, application, out);
// Get parameters
String mucname = ParamUtils.getParameter(request, "mucname");
int start = ParamUtils.getIntParameter(request, "start", 0);
int range = ParamUtils.getIntParameter(request, "range", webManager.getRowsPerPage("retirees-summary", DEFAULT_RANGE));
boolean delete = ParamUtils.getBooleanParameter(request, "delete");
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
// Validate range is one of the allowed presets, reset to default if invalid
boolean validRange = false;
for (int preset : RANGE_PRESETS) {
if (preset == range) {
validRange = true;
break;
}
}
if (!validRange) {
range = DEFAULT_RANGE;
}
// CSRF check
if (delete) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
delete = false;
}
}
// Handle deletion
if (delete) {
String service = ParamUtils.getParameter(request, "service");
String name = ParamUtils.getParameter(request, "name");
if (service != null && name != null) {
webManager.getMultiUserChatManager().deleteRetiree(service, name);
response.sendRedirect("muc-room-retirees.jsp?mucname=" + URLEncoder.encode(service, StandardCharsets.UTF_8) + "&deletesuccess=true");
return;
}
}
// Set up CSRF protection for subsequent requests
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
// Handle range parameter
if (request.getParameter("range") != null) {
webManager.setRowsPerPage("retirees-summary", range);
}
// Get MUC service
MultiUserChatService mucService = null;
if (mucname != null && webManager.getMultiUserChatManager().isServiceRegistered(mucname)) {
mucService = webManager.getMultiUserChatManager().getMultiUserChatService(mucname);
} else {
for (MultiUserChatService muc : webManager.getMultiUserChatManager().getMultiUserChatServices()) {
if (!muc.isHidden()) {
mucService = muc;
break;
}
}
}
// Redirect if no service exists
if (mucService == null) {
response.sendRedirect("muc-service-summary.jsp");
return;
}
// Get retiree information
int retireeCount = webManager.getMultiUserChatManager().getRetireeCount(mucService.getServiceName());
int numPages = (int)Math.ceil((double) retireeCount / (double)range);
int curPage = (start/range) + 1;
// Get list of services for dropdown
Collection mucServices = new ArrayList<>();
for (MultiUserChatService service : webManager.getMultiUserChatManager().getMultiUserChatServices()) {
if (!service.isHidden()) {
mucServices.add(service);
}
}
// Get retirees for current page
Collection retirees = webManager.getMultiUserChatManager().getRetirees(mucService.getServiceName(), start, range);
// Set attributes for JSTL
request.setAttribute("mucService", mucService);
request.setAttribute("mucServices", mucServices);
request.setAttribute("retireeCount", retireeCount);
request.setAttribute("numPages", numPages);
request.setAttribute("curPage", curPage);
request.setAttribute("start", start);
request.setAttribute("range", range);
request.setAttribute("rangePresets", RANGE_PRESETS);
request.setAttribute("retirees", retirees);
request.setAttribute("csrf", csrfParam);
%>