1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
<%--
- $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" %>
<%@ 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.StringUtils"
errorPage="error.jsp"
%>
<%@ page import="java.util.Collection"%>
<%@ page import="java.util.HashMap"%>
<%@ page import="java.util.List"%>
<%@ page import="java.util.Map" %>
<jsp:useBean id="webManager" class="org.jivesoftware.util.WebManager" />
<% webManager.init(request, response, session, application, out); %>
<html>
<head>
<title>
<fmt:message key="connection-manager.settings.title"/></title>
<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");
boolean updateSucess = false;
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);
// Log the event
webManager.logEvent("disabled connection manager settings", null);
}
else {
connectionManager.enableConnectionManagerListener(true);
connectionManager.setConnectionManagerListenerPort(port);
// 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);
}
}
// Log the event
webManager.logEvent("enabled connection manager settings", "port = "+port);
}
updateSucess = true;
}
}
// Set page vars
if (errors.size() == 0) {
managerEnabled = connectionManager.isConnectionManagerListenerEnabled();
port = connectionManager.getConnectionManagerListenerPort();
defaultSecret = ConnectionMultiplexerManager.getDefaultSecret();
}
else {
if (port == 0) {
port = connectionManager.getConnectionManagerListenerPort();
}
if (defaultSecret == null) {
defaultSecret = ConnectionMultiplexerManager.getDefaultSecret();
}
}
%>
<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" alt=""/></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" alt=""></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>
</td>
<td width="99%">
<table cellpadding="3" cellspacing="0" border="0">
<tr valign="top">
<td width="1%" align="right" nowrap class="c1">
<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">
<td width="1%" nowrap align="right" class="c1">
<fmt:message key="connection-manager.settings.defaultSecret" />
</td>
<td width="99%">
<input type="password" size="30" maxlength="150" name="defaultSecret"
value="<%= ((defaultSecret != null) ? StringUtils.hash(defaultSecret) : "") %>">
</td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</fieldset>
<br>
<input type="submit" name="update" value="<fmt:message key="global.save_settings" />">
</form>
<% if (managerEnabled) { %>
<br>
<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" >
<fmt:param value="<%= XMPPServer.getInstance().getServerInfo().getXMPPDomain() %>" />
</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>
</tr>
<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>
<% } 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();
%>
<tr>
<td><img src="images/connection-manager_16x16.gif" width="16" height="16" border="0" alt="" align="absmiddle"><%= managerName%></td>
<td><%= hostAddress %> / <%= hostName %></td>
<td align="center"><%= multiplexerManager.getNumConnectedClients(managerName)%></td>
</tr>
<%
}
}
%>
</tbody>
</table>
<% } %>
</body>
</html>