connection-managers-settings.jsp 10.3 KB
Newer Older
Gaston Dombiak's avatar
Gaston Dombiak committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
<%--
  -	$RCSfile$
  -	$Revision: $
  -	$Date: $
  -
  - Copyright (C) 2006 Jive Software. All rights reserved.
  -
  - This software is published under the terms of the GNU Public License (GPL),
  - a copy of which is included in this distribution.
--%>

<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>

15
<%@ page import="org.jivesoftware.openfire.ConnectionManager,
16 17 18
                 org.jivesoftware.openfire.SessionManager,
                 org.jivesoftware.openfire.XMPPServer,
                 org.jivesoftware.openfire.multiplex.ConnectionMultiplexerManager,
19
                 org.jivesoftware.openfire.session.ConnectionMultiplexerSession,
20 21
                 org.jivesoftware.util.ParamUtils,
                 org.jivesoftware.util.StringUtils"
Gaston Dombiak's avatar
Gaston Dombiak committed
22 23
    errorPage="error.jsp"
%>
24
<%@ page import="java.util.Collection"%>
Gaston Dombiak's avatar
Gaston Dombiak committed
25
<%@ page import="java.util.HashMap"%>
26 27
<%@ page import="java.util.List"%>
<%@ page import="java.util.Map" %>
Gaston Dombiak's avatar
Gaston Dombiak committed
28 29

<html>
30 31 32
<head>
    <title>
        <fmt:message key="connection-manager.settings.title"/></title>
Gaston Dombiak's avatar
Gaston Dombiak committed
33 34 35 36 37 38 39 40 41 42 43 44
        <meta name="pageID" content="connection-managers-settings"/>
    </head>
    <body>

<%  // Get parameters
    boolean update = request.getParameter("update") != null;
    boolean managerEnabled = ParamUtils.getBooleanParameter(request,"managerEnabled");
    int port = ParamUtils.getIntParameter(request,"port", 0);
    String defaultSecret = ParamUtils.getParameter(request,"defaultSecret");
    String secret = ParamUtils.getParameter(request,"secret");
    boolean updateSucess = false;

45
    String serverName = XMPPServer.getInstance().getServerInfo().getXMPPDomain();
Gaston Dombiak's avatar
Gaston Dombiak committed
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
    ConnectionManager connectionManager = XMPPServer.getInstance().getConnectionManager();


    // Update the session kick policy if requested
    Map<String, String> errors = new HashMap<String, String>();
    if (update) {
        // Validate params
        if (managerEnabled) {
            if (defaultSecret == null || defaultSecret.trim().length() == 0) {
                errors.put("defaultSecret","");
            }
            if (port <= 0) {
                errors.put("port","");
            }
        }
        // If no errors, continue:
        if (errors.isEmpty()) {
            if (!managerEnabled) {
                connectionManager.enableConnectionManagerListener(false);
            }
            else {
                connectionManager.enableConnectionManagerListener(true);
                connectionManager.setConnectionManagerListenerPort(port);
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90

                // 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);
                    }
                }
Gaston Dombiak's avatar
Gaston Dombiak committed
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
            }
            updateSucess = true;
        }
    }

    // Set page vars
    if (errors.size() == 0) {
        managerEnabled = connectionManager.isConnectionManagerListenerEnabled();
        port = connectionManager.getConnectionManagerListenerPort();
        defaultSecret = ConnectionMultiplexerManager.getDefaultSecret();
        secret = "";
    }
    else {
        if (port == 0) {
            port = connectionManager.getConnectionManagerListenerPort();
        }
        if (defaultSecret == null) {
            defaultSecret = ConnectionMultiplexerManager.getDefaultSecret();
        }
        if (secret == null) {
            secret = "";
        }
    }
%>

<p>
<fmt:message key="connection-manager.settings.info">
    <fmt:param value="<%= "<a href='connection-manager-session-summary.jsp'>" %>" />
    <fmt:param value="<%= "</a>" %>" />
</fmt:message>
</p>

<%  if (!errors.isEmpty()) { %>

    <div class="jive-error">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
        <tr>
            <td class="jive-icon"><img src="images/error-16x16.gif" width="16" height="16" border="0"/></td>
            <td class="jive-icon-label">

            <% if (errors.get("port") != null) { %>
                <fmt:message key="connection-manager.settings.valid.port" />
            <% } else if (errors.get("defaultSecret") != null) { %>
                <fmt:message key="connection-manager.settings.valid.defaultSecret" />
            <% } %>
            </td>
        </tr>
    </tbody>
    </table>
    </div>
    <br>

<%  } else if (updateSucess) { %>

    <div class="jive-success">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
        <tr><td class="jive-icon"><img src="images/success-16x16.gif" width="16" height="16" border="0"></td>
        <td class="jive-icon-label">
        <fmt:message key="connection-manager.settings.confirm.updated" />
        </td></tr>
    </tbody>
    </table>
    </div><br>

<%  } %>

<form action="connection-managers-settings.jsp" method="post">

<fieldset>
    <div>
    <table cellpadding="3" cellspacing="0" border="0" width="100%">
    <tbody>
        <tr valign="middle">
            <td width="1%" nowrap>
                <input type="radio" name="managerEnabled" value="false" id="rb01"
                 <%= (!managerEnabled ? "checked" : "") %>>
            </td>
            <td width="99%">
                <label for="rb01">
                <b><fmt:message key="connection-manager.settings.label_disable" /></b> - <fmt:message key="connection-manager.settings.label_disable_info" />
                </label>
            </td>
        </tr>
        <tr valign="middle">
            <td width="1%" nowrap>
                <input type="radio" name="managerEnabled" value="true" id="rb02"
                 <%= (managerEnabled ? "checked" : "") %>>
            </td>
            <td width="99%">
                <label for="rb02">
                <b><fmt:message key="connection-manager.settings.label_enable" /></b> - <fmt:message key="connection-manager.settings.label_enable_info" />
                </label>
            </td>
        </tr>
        <tr valign="top">
            <td width="1%" nowrap>
                &nbsp;
            </td>
            <td width="99%">
192
                <table cellpadding="3" cellspacing="0" border="0">
Gaston Dombiak's avatar
Gaston Dombiak committed
193
                <tr valign="top">
194
                    <td width="1%" align="right" nowrap class="c1">
Gaston Dombiak's avatar
Gaston Dombiak committed
195 196 197 198 199 200 201 202
                        <fmt:message key="connection-manager.settings.port" />
                    </td>
                    <td width="99%">
                        <input type="text" size="10" maxlength="50" name="port"
                         value="<%= port %>">
                    </td>
                </tr>
                <tr valign="top">
203
                    <td width="1%" nowrap align="right" class="c1">
Gaston Dombiak's avatar
Gaston Dombiak committed
204 205 206
                        <fmt:message key="connection-manager.settings.defaultSecret" />
                    </td>
                    <td width="99%">
207 208
                        <input type="password" size="30" maxlength="150" name="defaultSecret"
                         value="<%= ((defaultSecret != null) ? StringUtils.hash(defaultSecret) : "") %>">
Gaston Dombiak's avatar
Gaston Dombiak committed
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
                    </td>
                </tr>
                </table>
            </td>
        </tr>
    </tbody>
    </table>
    </div>
</fieldset>
<br>

<input type="submit" name="update" value="<fmt:message key="global.save_settings" />">

</form>

Matt Tucker's avatar
Matt Tucker committed
224 225
<% if (managerEnabled) { %>

Gaston Dombiak's avatar
Gaston Dombiak committed
226 227
<br>

228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
<style type="text/css">
.connectionManagers {
	margin-top: 8px;
	border: 1px solid #DCDCDC;
	border-bottom: none;
	}
.connectionManagers tr.head {
	background-color: #F3F7FA;
	border-bottom: 1px solid red;
	}
.connectionManagers tr.head td {
	padding: 3px 6px 3px 6px;
	border-bottom: 1px solid #DCDCDC;
	}
.connectionManagers tr td {
	padding: 3px;
	border-bottom: 1px solid #DCDCDC;
	}
.connectionManagers tr td img {
	margin: 3px;
	}
</style>
<b><fmt:message key="connection-manager.details.title" >
251
        <fmt:param value="<%= XMPPServer.getInstance().getServerInfo().getXMPPDomain() %>" />
252 253 254 255 256 257 258 259
    </fmt:message>
</b>
<br>
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="connectionManagers">
    <tr class="head">
        <td><strong><fmt:message key="connection-manager.details.name" /></strong></td>
        <td><strong><fmt:message key="connection-manager.details.address" /></strong></td>
        <td align="center" width="15%"><strong><fmt:message key="connection-manager.details.sessions" /></strong></td>
Gaston Dombiak's avatar
Gaston Dombiak committed
260
    </tr>
261 262 263 264 265 266 267 268 269 270
<tbody>
<%
    ConnectionMultiplexerManager multiplexerManager = ConnectionMultiplexerManager.getInstance();
    SessionManager sessionManager = SessionManager.getInstance();
    Collection<String> connectionManagers = multiplexerManager.getMultiplexers();
    if (connectionManagers.isEmpty()) {
%>
    <tr>
        <td width="100%" colspan="3" align="center" nowrap><fmt:message key="connection-manager.details.no-managers-connected" /></td>
    </tr>
271 272 273 274 275 276 277 278
<% } else {
    for (String managerName : connectionManagers) {
        List<ConnectionMultiplexerSession> sessions = sessionManager.getConnectionMultiplexerSessions(managerName);
        if (sessions.isEmpty()) {
            continue;
        }
        String hostAddress = sessions.get(0).getHostAddress();
        String hostName = sessions.get(0).getHostName();
279 280
%>
<tr>
281
    <td><img src="images/connection-manager_16x16.gif" width="16" height="16" border="0" alt="" align="absmiddle"><%= managerName%></td>
282
    <td><%= hostAddress %> / <%= hostName %></td>
283
    <td align="center"><%= multiplexerManager.getNumConnectedClients(managerName)%></td>
284 285 286 287 288 289
</tr>
<%
        }
    }
%>
</tbody>
Gaston Dombiak's avatar
Gaston Dombiak committed
290 291
</table>

Matt Tucker's avatar
Matt Tucker committed
292 293 294

<% } %>

295
</body>
Gaston Dombiak's avatar
Gaston Dombiak committed
296
</html>