%@ page contentType="text/html; charset=UTF-8" %>
<%--
-
- Copyright (C) 2004-2008 Jive Software, 2017-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.group.Group,
org.jivesoftware.openfire.group.GroupAlreadyExistsException,
org.jivesoftware.openfire.security.SecurityAuditManager,
org.jivesoftware.util.StringUtils"
errorPage="error.jsp"
%>
<%@ page import="org.jivesoftware.util.ParamUtils"%>
<%@ page import="org.jivesoftware.util.CookieUtils"%>
<%@ page import="java.net.URLEncoder"%>
<%@ page import="java.util.HashMap"%>
<%@ page import="java.util.Map" %>
<%@ page import="org.slf4j.LoggerFactory" %>
<%@ 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" %>
<% webManager.init(request, response, session, application, out); %>
<% // Get parameters //
String groupName = ParamUtils.getParameter(request, "group");
boolean create = request.getParameter("create") != null;
boolean edit = request.getParameter("edit") != null;
boolean cancel = request.getParameter("cancel") != null;
String name = ParamUtils.getParameter(request, "name");
String description = ParamUtils.getParameter(request, "description", true);
Map errors = new HashMap<>();
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
if (create || edit) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
create = false;
edit = false;
errors.put("csrf", "CSRF Failure!");
}
}
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
// Handle a cancel
if (cancel) {
if (groupName == null) {
response.sendRedirect("group-summary.jsp");
}
else {
response.sendRedirect("group-edit.jsp?group=" + URLEncoder.encode(groupName, StandardCharsets.UTF_8));
}
return;
}
// Handle a request to create a group:
if (create) {
// Validate
if (name == null) {
errors.put("name", "");
}
// do a create if there were no errors
if (errors.isEmpty()) {
try {
Group newGroup = webManager.getGroupManager().createGroup(name);
if (description != null) {
newGroup.setDescription(description);
}
if (!SecurityAuditManager.getSecurityAuditProvider().blockGroupEvents()) {
// Log the event
webManager.logEvent("created new group "+name, "description = "+description);
}
// Successful, so redirect
response.sendRedirect("group-edit.jsp?creategroupsuccess=true&group=" + URLEncoder.encode(newGroup.getName(), StandardCharsets.UTF_8));
return;
}
catch (GroupAlreadyExistsException e) {
errors.put("groupAlreadyExists", "");
}
catch (Exception e) {
errors.put("general", "");
LoggerFactory.getLogger("group-create.jsp").warn("Problem creating group '{}' in admin console.", groupName, e);
}
}
}
// Handle a request to edit a group:
if (edit) {
// Validate
if (name == null) {
errors.put("name", "");
}
// do a create if there were no errors
if (errors.isEmpty()) {
try {
Group group = webManager.getGroupManager().getGroup(groupName);
group.setName(name);
if (description != null) {
group.setDescription(description);
}
if (!SecurityAuditManager.getSecurityAuditProvider().blockGroupEvents()) {
// Log the event
webManager.logEvent("edited group "+groupName, "description = "+description);
}
// Successful, so redirect
response.sendRedirect("group-edit.jsp?groupChanged=true&group=" + URLEncoder.encode(group.getName(), StandardCharsets.UTF_8));
return;
}
catch (Exception e) {
errors.put("general", "");
LoggerFactory.getLogger("group-create.jsp").warn("Problem editing group '{}' in admin console.", groupName, e);
}
}
}
pageContext.setAttribute("groupName", groupName);
if (groupName != null) {
pageContext.setAttribute("group", webManager.getGroupManager().getGroup(groupName));
}
pageContext.setAttribute( "errors", errors );
pageContext.setAttribute( "name", name );
pageContext.setAttribute( "description", description );
%>