<%@ page contentType="text/html; charset=UTF-8" %> <%-- - - Copyright (C) 2005-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. --%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> <%@ taglib prefix="admin" uri="admin" %> <%@ page import="org.jivesoftware.openfire.ConnectionManager, org.jivesoftware.openfire.SessionManager, org.jivesoftware.openfire.XMPPServer, org.jivesoftware.openfire.multiplex.ConnectionMultiplexerManager, org.jivesoftware.openfire.session.ConnectionMultiplexerSession, org.jivesoftware.util.ParamUtils, org.jivesoftware.util.CookieUtils, org.jivesoftware.util.StringUtils" errorPage="error.jsp" %> <%@ page import="org.jivesoftware.openfire.spi.ConnectionType" %> <%@ page import="org.jivesoftware.openfire.spi.ConnectionConfiguration" %> <%@ page import="org.jivesoftware.openfire.spi.ConnectionListener" %> <%@ page import="java.util.*" %> <%@ page import="java.util.concurrent.ConcurrentHashMap" %> <% webManager.init(request, response, session, application, out); %> <fmt:message key="connection-manager.settings.title"/> <% final ConnectionType connectionType = ConnectionType.CONNECTION_MANAGER; final ConnectionManager manager = XMPPServer.getInstance().getConnectionManager(); final ConnectionConfiguration plaintextConfiguration = manager.getListener( connectionType, false ).generateConnectionConfiguration(); final ConnectionConfiguration directtlsConfiguration = manager.getListener( connectionType, true ).generateConnectionConfiguration(); // Get parameters boolean update = request.getParameter("update") != null; String defaultSecret = ParamUtils.getParameter(request,"defaultSecret"); final Map errors = new HashMap<>(); Cookie csrfCookie = CookieUtils.getCookie(request, "csrf"); String csrfParam = ParamUtils.getParameter(request, "csrf"); if (update) { if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) { update = false; errors.put("csrf", "CSRF Failure!"); } } csrfParam = StringUtils.randomString(15); CookieUtils.setCookie(request, response, "csrf", csrfParam, -1); pageContext.setAttribute("csrf", csrfParam); if (update) { // Validate params // plaintext final boolean plaintextEnabled = ParamUtils.getBooleanParameter( request, "plaintext-enabled" ); final int plaintextTcpPort = ParamUtils.getIntParameter( request, "plaintext-tcpPort", plaintextConfiguration.getPort() ); // Direct TLS final boolean directtlsEnabled = ParamUtils.getBooleanParameter( request, "directtls-enabled" ); final int directtlsTcpPort = ParamUtils.getIntParameter( request, "directtls-tcpPort", directtlsConfiguration.getPort() ); if (plaintextEnabled) { if (defaultSecret == null || defaultSecret.trim().isEmpty()) { errors.put("defaultSecret",""); } if (plaintextTcpPort <= 0) { errors.put("port",""); } } if (directtlsEnabled) { if (defaultSecret == null || defaultSecret.trim().isEmpty()) { errors.put("defaultSecret",""); } if (directtlsTcpPort <= 0) { errors.put("port",""); } } // If no errors, continue: if (errors.isEmpty()) { // Apply final ConnectionListener plaintextListener = manager.getListener( connectionType, false ); final ConnectionListener directtlsListener = manager.getListener( connectionType, true ); plaintextListener.enable( plaintextEnabled ); plaintextListener.setPort( plaintextTcpPort ); directtlsListener.enable( directtlsEnabled ); directtlsListener.setPort( directtlsTcpPort ); // Get hash value of existing default secret String existingHashDefaultSecret = ""; if (ConnectionMultiplexerManager.getDefaultSecret() != null) { existingHashDefaultSecret = StringUtils.hash(ConnectionMultiplexerManager.getDefaultSecret()); } // Check if the new default secret was changed. If it wasn't changed, then it is the original hashed // default secret // NOTE: if the new PLAIN default secret equals the previous HASHED default secret this fails, // but is unlikely. if (!existingHashDefaultSecret.equals(defaultSecret)) { // Hash the new default secret since it was changed String newHashDefaultSecret = ""; if (defaultSecret != null) { newHashDefaultSecret = StringUtils.hash(defaultSecret); } // Change default secret if hash values are different if (!existingHashDefaultSecret.equals(newHashDefaultSecret)) { ConnectionMultiplexerManager.setDefaultSecret(defaultSecret); } } webManager.logEvent( "Updated connection settings for " + connectionType, "plain: enabled=" + plaintextEnabled + ", port=" + plaintextTcpPort + "\nDirect TLS: enabled=" + directtlsEnabled+ ", port=" + directtlsTcpPort+ "\n" ); response.sendRedirect( "connection-managers-settings.jsp?success=true" ); } } final Collection connectionManagers = ConnectionMultiplexerManager.getInstance().getMultiplexers(); final Map> connectionManagerSessions = new ConcurrentHashMap<>(); final Map connectionManagerUserCounts = new ConcurrentHashMap<>(); for (final String managerName : connectionManagers) { connectionManagerSessions.put(managerName, SessionManager.getInstance().getConnectionMultiplexerSessions(managerName)); connectionManagerUserCounts.put(managerName, ConnectionMultiplexerManager.getInstance().getNumConnectedClients(managerName)); } // Set page vars pageContext.setAttribute("errors", errors); pageContext.setAttribute("plaintextConfiguration", plaintextConfiguration); pageContext.setAttribute("directtlsConfiguration", directtlsConfiguration); pageContext.setAttribute("defaultSecretHash", ConnectionMultiplexerManager.getDefaultSecret() != null && !ConnectionMultiplexerManager.getDefaultSecret().isBlank() ? StringUtils.hash(ConnectionMultiplexerManager.getDefaultSecret()) : ""); pageContext.setAttribute("connectionManagerSessions", connectionManagerSessions); pageContext.setAttribute("connectionManagerUserCounts", connectionManagerUserCounts); %>

: ()

...

...
">

Connection Manager /