-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathmuc-create-permission.jsp
More file actions
366 lines (331 loc) · 15.9 KB
/
Copy pathmuc-create-permission.jsp
File metadata and controls
366 lines (331 loc) · 15.9 KB
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
<%@ page contentType="text/html; charset=UTF-8" %>
<%--
-
- Copyright (C) 2004-2008 Jive Software, 2017-2026 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.util.*,
org.jivesoftware.openfire.group.Group,
org.jivesoftware.openfire.group.GroupJID,
java.util.*,
org.xmpp.packet.*,
org.jivesoftware.openfire.muc.MultiUserChatService"
errorPage="error.jsp"
%>
<%@ page import="java.net.URLEncoder" %>
<%@ page import="java.net.URLDecoder" %>
<%@ 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" %>
<jsp:useBean id="webManager" class="org.jivesoftware.util.WebManager" />
<% webManager.init(request, response, session, application, out ); %>
<% // Get parameters
String userJID = ParamUtils.getParameter(request,"userJID");
String[] groupNames = ParamUtils.getParameters(request, "groupNames");
boolean allowAllRegisteredUsers = ParamUtils.getBooleanParameter(request,"allowAllRegisteredUsers");
boolean add = request.getParameter("add") != null;
boolean save = request.getParameter("save") != null;
boolean success = request.getParameter("success") != null;
boolean addsuccess = request.getParameter("addsuccess") != null;
boolean deletesuccess = request.getParameter("deletesuccess") != null;
boolean delete = ParamUtils.getBooleanParameter(request,"delete");
String openPerms = ParamUtils.getParameter(request,"openPerms");
String mucname = ParamUtils.getParameter(request,"mucname");
if (!webManager.getMultiUserChatManager().isServiceRegistered(mucname)) {
// The requested service name does not exist so return to the list of the existing rooms
response.sendRedirect("muc-service-summary.jsp");
return;
}
Cookie csrfCookie = CookieUtils.getCookie(request, "csrf");
String csrfParam = ParamUtils.getParameter(request, "csrf");
if (save || add || delete) {
if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) {
save = false;
add = false;
delete = false;
}
}
csrfParam = StringUtils.randomString(15);
CookieUtils.setCookie(request, response, "csrf", csrfParam, -1);
pageContext.setAttribute("csrf", csrfParam);
// Get muc server
MultiUserChatService mucService = webManager.getMultiUserChatManager().getMultiUserChatService(mucname);
// Handle a save
Map<String,String> errors = new HashMap<>();
if (save) {
if ("anyone".equals(openPerms)) {
// Remove all users who have the ability to create rooms
for (JID user : mucService.getUsersAllowedToCreate()) {
mucService.removeUserAllowedToCreate(user);
}
mucService.setRoomCreationRestricted(false);
// Log the event
webManager.logEvent("set MUC room creation to not restricted for service "+mucname, null);
response.sendRedirect("muc-create-permission.jsp?success=true&mucname="+URLEncoder.encode(mucname, StandardCharsets.UTF_8));
return;
}
else if ("none".equals(openPerms)) {
// Remove all users who have the ability to create rooms
for (JID user : mucService.getUsersAllowedToCreate()) {
mucService.removeUserAllowedToCreate(user);
}
mucService.setRoomCreationRestricted(true);
mucService.setAllRegisteredUsersAllowedToCreate(false);
// Log the event
webManager.logEvent("set MUC room creation to restricted (none) for service "+mucname, null);
response.sendRedirect("muc-create-permission.jsp?success=true&mucname="+URLEncoder.encode(mucname, StandardCharsets.UTF_8));
return;
}
else if ("specific".equals(openPerms)) {
mucService.setRoomCreationRestricted(true);
mucService.setAllRegisteredUsersAllowedToCreate(allowAllRegisteredUsers);
// Log the event
webManager.logEvent("set MUC room creation to restricted for service "+mucname, null);
response.sendRedirect("muc-create-permission.jsp?success=true&mucname="+URLEncoder.encode(mucname, StandardCharsets.UTF_8));
return;
}else{
errors.put("openPerms", "openPerms");
}
}
List<JID> allowedJIDs = new ArrayList<>();
try {
if (userJID != null && !userJID.trim().isEmpty()) {
String allowedJID;
// do validation; could be a group jid
if (userJID.indexOf('@') == -1) {
String username = JID.escapeNode(userJID);
String domain = webManager.getXMPPServer().getServerInfo().getXMPPDomain();
allowedJID = username + '@' + domain;
}
else {
String username = JID.escapeNode(userJID.substring(0, userJID.indexOf('@')));
String rest = userJID.substring(userJID.indexOf('@'));
allowedJID = username + rest.trim();
}
allowedJIDs.add(GroupJID.fromString(allowedJID.trim()).asBareJID());
}
if (groupNames != null) {
// create a group JID for each group
for (String groupName : groupNames) {
GroupJID groupJID = new GroupJID(URLDecoder.decode(groupName, StandardCharsets.UTF_8));
allowedJIDs.add(groupJID);
}
}
} catch (java.lang.IllegalArgumentException ex) {
errors.put("userJID","userJID");
}
if (errors.isEmpty()) {
// Handle an add
if (add) {
mucService.addUsersAllowedToCreate(allowedJIDs);
mucService.setAllRegisteredUsersAllowedToCreate(allowAllRegisteredUsers);
mucService.setRoomCreationRestricted(true);
// Log the event
webManager.logEvent("updated MUC room creation permissions for service "+mucname, null);
response.sendRedirect("muc-create-permission.jsp?addsuccess=true&mucname="+URLEncoder.encode(mucname, StandardCharsets.UTF_8));
return;
}
// Handle delete
if (delete) {
// Remove the user from the allowed list
mucService.removeUserAllowedToCreate(GroupJID.fromString(userJID));
// Log the event
webManager.logEvent("removed MUC room creation permission from "+userJID+" for service "+mucname, null);
// done, return
response.sendRedirect("muc-create-permission.jsp?deletesuccess=true&mucname="+URLEncoder.encode(mucname, StandardCharsets.UTF_8));
return;
}
}
%>
<html>
<head>
<title><fmt:message key="muc.create.permission.title"/></title>
<meta name="subPageID" content="muc-perms"/>
<meta name="extraParams" content="<%= "mucname="+URLEncoder.encode(mucname, StandardCharsets.UTF_8) %>"/>
<meta name="helpPage" content="set_group_chat_room_creation_permissions.html"/>
<script>
function toggleAllowedUsers() {
const isRestricted = document.getElementById('restrictedPermissionsRadio').checked;
const container = document.getElementById('allowedUsersContainer');
const input = document.getElementById('userJIDtf');
if (isRestricted) {
container.style.display = 'block';
if (input) {
input.focus();
}
} else {
container.style.display = 'none';
}
}
function syncAllowAllRegistered() {
const cb = document.getElementById('allowAllRegisteredUsers');
const hidden = document.getElementById('allowAllRegisteredUsersHidden');
if (cb && hidden) {
hidden.value = cb.checked ? 'true' : 'false';
}
}
</script>
</head>
<body>
<p>
<fmt:message key="muc.create.permission.info" />
<fmt:message key="groupchat.service.settings_affect" /> <b><a href="muc-service-edit-form.jsp?mucname=<%= URLEncoder.encode(mucname, StandardCharsets.UTF_8) %>"><%= StringUtils.escapeHTMLTags(mucname) %></a></b>
</p>
<% if (!errors.isEmpty()) {
if (delete) {
userJID = null; // mask group jid on error
}
%>
<admin:infoBox type="error">
<fmt:message key="muc.create.permission.error" />
</admin:infoBox>
<% } else if (success) { %>
<admin:infoBox type="success">
<fmt:message key="muc.create.permission.update" />
</admin:infoBox>
<% } else if (addsuccess) { %>
<admin:infoBox type="success">
<fmt:message key="muc.create.permission.add_user" />
</admin:infoBox>
<% } else if (deletesuccess) { %>
<admin:infoBox type="success">
<fmt:message key="muc.create.permission.user_removed" />
</admin:infoBox>
<% } %>
<!-- BEGIN 'Permission Policy' -->
<form action="muc-create-permission.jsp?save" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<input type="hidden" name="mucname" value="<%= StringUtils.escapeForXML(mucname) %>" />
<input type="hidden" name="allowAllRegisteredUsers" id="allowAllRegisteredUsersHidden" value="<%= mucService.isAllRegisteredUsersAllowedToCreate() ? "true" : "false" %>" />
<div class="jive-contentBoxHeader">
<fmt:message key="muc.create.permission.policy" />
</div>
<div class="jive-contentBox">
<table>
<tbody>
<tr>
<td style="width: 1%">
<input type="radio" name="openPerms" value="anyone" id="rb01"
onchange="toggleAllowedUsers()"
<%= ((!mucService.isRoomCreationRestricted()) ? "checked" : "") %>>
</td>
<td>
<label for="rb01"><fmt:message key="muc.create.permission.anyone_created" /></label>
</td>
</tr>
<tr>
<td style="width: 1%">
<input type="radio" name="openPerms" value="specific" id="restrictedPermissionsRadio"
onchange="toggleAllowedUsers()"
<%= ((mucService.isRoomCreationRestricted() && (!mucService.getUsersAllowedToCreate().isEmpty() || mucService.isAllRegisteredUsersAllowedToCreate())) ? "checked" : "") %>>
</td>
<td>
<label for="restrictedPermissionsRadio"><fmt:message key="muc.create.permission.specific_created" /></label>
</td>
</tr>
<tr>
<td style="width: 1%">
<input type="radio" name="openPerms" value="none" id="nonePermissionsRadio"
onchange="toggleAllowedUsers()"
<%= ((mucService.isRoomCreationRestricted() && mucService.getUsersAllowedToCreate().isEmpty() && !mucService.isAllRegisteredUsersAllowedToCreate()) ? "checked" : "") %>>
</td>
<td>
<label for="nonePermissionsRadio"><fmt:message key="muc.create.permission.no_one_created" /></label>
</td>
</tr>
</tbody>
</table>
</div>
<input type="submit" value="<fmt:message key="global.save_settings" />">
</form>
<!-- END 'Permission Policy' -->
<br>
<div id="allowedUsersContainer" style="display: <%= (mucService.isRoomCreationRestricted() && (!mucService.getUsersAllowedToCreate().isEmpty() || mucService.isAllRegisteredUsersAllowedToCreate()) ? "block" : "none") %>">
<!-- BEGIN 'Allowed Users' -->
<form action="muc-create-permission.jsp?add" method="post">
<input type="hidden" name="csrf" value="${csrf}">
<input type="hidden" name="mucname" value="<%= StringUtils.escapeForXML(mucname) %>" />
<div class="jive-contentBoxHeader">
<fmt:message key="muc.create.permission.allowed_users" />
</div>
<div class="jive-contentBox">
<p>
<input type="checkbox" id="allowAllRegisteredUsers" name="allowAllRegisteredUsers" onchange="syncAllowAllRegistered()" <%=mucService.isAllRegisteredUsersAllowedToCreate()?"checked":""%>>
<label for="allowAllRegisteredUsers"><fmt:message key="muc.create.permission.allow_registered" /></label>
</p>
<p>
<label for="groupJIDs"><fmt:message key="muc.create.permission.add_group" /></label><br/>
<select name="groupNames" size="6" multiple style="width:400px;font-family:verdana,arial,helvetica,sans-serif;font-size:8pt;"
id="groupJIDs">
<% for (Group g : webManager.getGroupManager().getGroups()) { %>
<option value="<%= URLEncoder.encode(g.getName(), StandardCharsets.UTF_8) %>"
<%= (StringUtils.contains(groupNames, g.getName()) ? "selected" : "") %>
><%= StringUtils.escapeHTMLTags(g.getName()) %></option>
<% } %>
</select>
</p>
<p>
<label for="userJIDtf"><fmt:message key="muc.create.permission.add_jid" /></label>
<input type="text" name="userJID" size="30" maxlength="100" value="<%= StringUtils.escapeForXML(userJID != null ? userJID : "") %>"
id="userJIDtf">
<input type="submit" value="Add">
</p>
<div class="jive-table" style="width:400px;">
<table>
<thead>
<tr>
<th style="width: 99%">User/Group</th>
<th>Remove</th>
</tr>
</thead>
<tbody>
<% if (mucService.getUsersAllowedToCreate().isEmpty()) { %>
<tr>
<td colspan="2">
<fmt:message key="muc.create.permission.no_allowed_users" />
</td>
</tr>
<% } %>
<% for (JID jid : mucService.getUsersAllowedToCreate()) {
boolean isGroup = GroupJID.isGroup(jid);
String jidDisplay = isGroup ? ((GroupJID)jid).getGroupName() : jid.toString();
%>
<tr>
<td>
<% if (isGroup) { %>
<img src="images/group.gif" title="<fmt:message key="muc.create.permission.group" />" alt="<fmt:message key="muc.create.permission.group" />"/>
<% } else { %>
<img src="images/user.gif" title="<fmt:message key="muc.create.permission.user" />" alt="<fmt:message key="muc.create.permission.user" />"/>
<% } %>
<a href="<%= isGroup ? "group-edit.jsp?group=" + URLEncoder.encode(jidDisplay) : "user-properties.jsp?username=" + URLEncoder.encode(jid.getNode(), StandardCharsets.UTF_8) %>">
<%= jidDisplay %></a>
</td>
<td style="width: 1%; text-align: center">
<a href="muc-create-permission.jsp?userJID=<%= jid.toString() %>&delete=true&csrf=${csrf}&mucname=<%= URLEncoder.encode(mucname, StandardCharsets.UTF_8) %>"
title="<fmt:message key="muc.create.permission.click_title" />"
onclick="return confirm('<fmt:message key="muc.create.permission.confirm_remove" />');"
><img src="images/delete-16x16.gif" alt=""></a>
</td>
</tr>
<% } %>
</tbody>
</table>
</div>
</div>
</form>
<!-- END 'Allowed Users' -->
</div>
</body>
</html>