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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
<%--
- $Revision$
- $Date$
-
- Copyright (C) 2005 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.
--%>
<%@ page import="org.jivesoftware.stringprep.Stringprep,
org.jivesoftware.util.JiveGlobals,
org.jivesoftware.util.LocaleUtils,
org.jivesoftware.util.Log,
org.jivesoftware.util.ParamUtils,
org.jivesoftware.wildfire.group.Group,
org.jivesoftware.wildfire.group.GroupManager"
%>
<%@ page import="org.jivesoftware.wildfire.user.UserManager"%>
<%@ page import="org.xmpp.packet.JID"%>
<%@ page import="java.io.UnsupportedEncodingException"%>
<%@ page import="java.net.URLDecoder"%>
<%@ page import="java.net.URLEncoder"%>
<%@ page import="java.util.*"%>
<%@ page import="org.xmpp.packet.Presence"%>
<%@ page import="org.jivesoftware.wildfire.PresenceManager"%>
<%@ page import="org.jivesoftware.wildfire.user.User"%>
<%@ page import="org.jivesoftware.wildfire.user.UserNotFoundException"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
<!-- Define Administration Bean -->
<jsp:useBean id="webManager" class="org.jivesoftware.util.WebManager"/>
<% webManager.init(pageContext); %>
<jsp:useBean id="errors" class="java.util.HashMap"/>
<% // Get parameters
boolean add = request.getParameter("add") != null;
boolean delete = request.getParameter("remove") != null;
boolean update = request.getParameter("save") != null;
boolean cancel = request.getParameter("cancel") != null;
String users = ParamUtils.getParameter(request, "users");
String [] adminIDs = ParamUtils.getParameters(request, "admin");
String [] deleteMembers = ParamUtils.getParameters(request, "delete");
String groupName = ParamUtils.getParameter(request, "group");
GroupManager groupManager = webManager.getGroupManager();
boolean edit = ParamUtils.getBooleanParameter(request, "edit", false);
String newName = ParamUtils.getParameter(request, "newName");
String newDescription = ParamUtils.getParameter(request, "newDescription");
boolean groupInfoChanged = ParamUtils.getBooleanParameter(request, "groupChanged", false);
// Get the presence manager
PresenceManager presenceManager = webManager.getPresenceManager();
UserManager userManager = webManager.getUserManager();
boolean enableRosterGroups = ParamUtils.getBooleanParameter(request,"enableRosterGroups");
String groupDisplayName = ParamUtils.getParameter(request,"groupDisplayName");
String showGroup = ParamUtils.getParameter(request,"showGroup");
String[] groupNames = ParamUtils.getParameters(request, "groupNames");
edit = true;
Group group = groupManager.getGroup(groupName);
boolean success = false;
StringBuffer errorBuf = new StringBuffer();
if (cancel) {
response.sendRedirect("group-summary.jsp");
return;
}
if (newName != null && newName.length() > 0) {
if (enableRosterGroups && (groupDisplayName == null || groupDisplayName.trim().length() == 0)) {
errors.put("groupDisplayName", "");
}
if (errors.isEmpty()) {
group.setName(newName);
group.setDescription(newDescription);
if (enableRosterGroups) {
if ("spefgroups".equals(showGroup)) {
showGroup = "onlyGroup";
}
else {
groupNames = new String[] {};
}
group.getProperties().put("sharedRoster.showInRoster", showGroup);
if (groupDisplayName != null) {
group.getProperties().put("sharedRoster.displayName", groupDisplayName);
}
group.getProperties().put("sharedRoster.groupList", toList(groupNames, "UTF-8"));
}
else {
group.getProperties().put("sharedRoster.showInRoster", "nobody");
group.getProperties().put("sharedRoster.displayName", "");
group.getProperties().put("sharedRoster.groupList", "");
}
groupName = newName;
groupInfoChanged = true;
// Get admin list and compare it the admin posted list.
response.sendRedirect("group-edit.jsp?group=" + URLEncoder.encode(groupName, "UTF-8") + "&groupChanged=true");
return;
}
else {
// Continue editing since there are some errors
edit = true;
update = false;
}
}
if (update) {
Set<JID> adminIDSet = new HashSet<JID>();
for (int i = 0; i < adminIDs.length; i++) {
JID newAdmin = new JID(adminIDs[i]);
adminIDSet.add(newAdmin);
boolean isAlreadyAdmin = group.getAdmins().contains(newAdmin);
if (!isAlreadyAdmin) {
// Add new admin
group.getAdmins().add(newAdmin);
}
}
Iterator<JID> groupIter = Collections.unmodifiableCollection(group.getAdmins()).iterator();
Set<JID> removeList = new HashSet<JID>();
while (groupIter.hasNext()) {
JID m = (JID) groupIter.next();
if (!adminIDSet.contains(m)) {
removeList.add(m);
}
}
Iterator<JID> i = removeList.iterator();
while (i.hasNext()) {
JID m = (JID) i.next();
group.getMembers().add(m);
}
// Get admin list and compare it the admin posted list.
response.sendRedirect("group-edit.jsp?group=" + URLEncoder.encode(groupName, "UTF-8") + "&updatesuccess=true");
return;
}
else if (add && users != null) {
StringTokenizer tokenizer = new StringTokenizer(users, ", \t\n\r\f");
int count = 0;
while (tokenizer.hasMoreTokens()) {
String username = tokenizer.nextToken();
username = username.trim();
username = username.toLowerCase();
// Add to group as member by default.
try {
boolean added = false;
if (username.indexOf('@') == -1) {
// No @ was found so assume this is a JID of a local user
username = Stringprep.nodeprep(username);
UserManager.getInstance().getUser(username);
added = group.getMembers().add(webManager.getXMPPServer().createJID(username, null));
}
else {
// Admin entered a JID. Add the JID directly to the list of group members
added = group.getMembers().add(new JID(username));
}
if (added) {
count++;
}
else {
errorBuf.append("<br>").append(
LocaleUtils.getLocalizedString("group.edit.already_user", Arrays.asList(username)));
}
}
catch (Exception e) {
Log.debug("Problem adding new user to existing group", e);
errorBuf.append("<br>").append(
LocaleUtils.getLocalizedString("group.edit.inexistent_user", Arrays.asList(username)));
}
}
if (count > 0) {
response.sendRedirect("group-edit.jsp?group=" +
URLEncoder.encode(groupName, "UTF-8") + "&success=true");
return;
}
else {
success = false;
add = true;
}
}
else if(add && users == null){
add = false;
}
else if (delete) {
for (int i = 0; i < deleteMembers.length; i++) {
JID member = new JID(deleteMembers[i]);
group.getMembers().remove(member);
group.getAdmins().remove(member);
}
response.sendRedirect("group-edit.jsp?group=" + URLEncoder.encode(groupName, "UTF-8") + "&deletesuccess=true");
return;
}
success = groupInfoChanged || "true".equals(request.getParameter("success")) ||
"true".equals(request.getParameter("deletesuccess")) ||
"true".equals(request.getParameter("updatesuccess")) ||
"true".equals(request.getParameter("creategroupsuccess"));
if (errors.size() == 0) {
enableRosterGroups = !"nobody".equals(group.getProperties().get("sharedRoster.showInRoster"));
showGroup = group.getProperties().get("sharedRoster.showInRoster");
if ("onlyGroup".equals(showGroup)) {
String glist = group.getProperties().get("sharedRoster.groupList");
List l = new ArrayList();
if (glist != null) {
StringTokenizer tokenizer = new StringTokenizer(glist,",\t\n\r\f");
while (tokenizer.hasMoreTokens()) {
String tok = tokenizer.nextToken().trim();
l.add(tok.trim());
}
}
groupNames = (String[])l.toArray(new String[]{});
}
groupDisplayName = group.getProperties().get("sharedRoster.displayName");
}
%>
<html>
<head>
<title><fmt:message key="group.edit.title"/></title>
<meta name="subPageID" content="group-edit"/>
<meta name="extraParams" content="<%= "group="+URLEncoder.encode(groupName, "UTF-8") %>"/>
<meta name="helpPage" content="edit_group_properties.html"/>
</head>
<body>
<p>
<fmt:message key="group.edit.form_info" />
</p>
<%
if (success) {
%>
<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">
<% if (groupInfoChanged) { %>
<fmt:message key="group.edit.update" />
<% } else if ("true".equals(request.getParameter("success"))) { %>
<fmt:message key="group.edit.update_add_user" />
<% } else if ("true".equals(request.getParameter("deletesuccess"))) { %>
<fmt:message key="group.edit.update_del_user" />
<% } else if ("true".equals(request.getParameter("updatesuccess"))) { %>
<fmt:message key="group.edit.update_user" />
<% } else if ("true".equals(request.getParameter("creategroupsuccess"))) { %>
<fmt:message key="group.edit.update_success" />
<%
}
%>
</td></tr>
</tbody>
</table>
</div><br>
<%
}
else if(!success && add){
%>
<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(add) { %>
<fmt:message key="group.edit.not_update" />
<%= errorBuf %>
<% } %>
</td></tr>
</tbody>
</table>
</div><br>
<% } %>
<form name="ff" action="group-edit.jsp">
<input type="hidden" name="group" value="<%= groupName %>"/>
<fieldset>
<legend>
<fmt:message key="group.edit.group_summary" />
</legend>
<table cellpadding="3" cellspacing="1" border="0">
<tr>
<td width="1%" nowrap>
<fmt:message key="group.edit.group_name" />
</td>
<% if(!edit) { %>
<td align=left nowrap width="1%">
<b><%= group.getName() %></b>
</td>
<td>
<a href="group-edit.jsp?edit=true&group=<%= URLEncoder.encode(groupName, "UTF-8") %>">
<img src="images/edit-16x16.gif" border="0" alt="">
</a>
</td>
<% } else { %>
<td>
<input type="text" name="newName" value="<%= group.getName() %>">
</td>
<% } %>
</tr>
<tr>
<td width="1%" nowrap>
<fmt:message key="group.edit.group_description" />
</td>
<% if(!edit) { %>
<td colspan="2">
<%= ((group.getDescription() != null) ? group.getDescription() : "<i>"+LocaleUtils.getLocalizedString("group.edit.group_not_description")+"</i>") %>
</td>
<% } else { %>
<td>
<textarea name="newDescription" cols="40" rows="4"><%= group.getDescription() != null ? group.getDescription() : "" %></textarea>
</td>
<% } %>
</tr>
</table>
<br>
<p><fmt:message key="group.edit.group_share_title" /></p>
<p>
<fmt:message key="group.edit.group_share_content" />
</p>
<table cellpadding="3" cellspacing="0" border="0" width="100%">
<tbody>
<tr>
<td width="1%">
<input type="radio" name="enableRosterGroups" value="false" id="rb201" <%= !enableRosterGroups ? "checked" : "" %>>
</td>
<td width="99%">
<label for="rb201"><fmt:message key="group.edit.group_share_not_in_rosters" /></label>
</td>
</tr>
<tr>
<td width="1%">
<input type="radio" name="enableRosterGroups" value="true" id="rb202" <%= enableRosterGroups ? "checked" : "" %>>
</td>
<td width="99%">
<label for="rb202"><fmt:message key="group.edit.group_share_in_rosters" /></label>
</td>
</tr>
<tr>
<td width="1%">
</td>
<td width="99%">
<table cellpadding="3" cellspacing="0" border="0" width="100%">
<tbody>
<tr>
<td width="1%" nowrap>
<fmt:message key="group.edit.group_display_name" />
</td>
<td width="99%">
<input type="text" name="groupDisplayName" size="30" maxlength="100" value="<%= (groupDisplayName != null ? groupDisplayName : "") %>"
onchange="this.form.enableRosterGroups[1].checked=true;">
<% if (errors.get("groupDisplayName") != null) { %>
<span class="jive-error-text"><fmt:message key="group.create.enter_a_group_name" /></span>
<% } %>
</td>
</tr>
</tbody>
</table>
<table cellpadding="3" cellspacing="0" border="0" width="100%">
<tbody>
<tr>
<td width="1%" nowrap>
<input type="radio" name="showGroup" value="everybody" id="rb002"
onclick="this.form.enableRosterGroups[1].checked=true;"
<%= ("everybody".equals(showGroup) || "nobody".equals(showGroup) ? "checked" : "") %>>
</td>
<td width="99%">
<label for="rb002"><fmt:message key="group.edit.show_groups_in_all_user" /></label>
</td>
</tr>
<tr>
<td width="1%" nowrap>
<input type="radio" name="showGroup" value="onlyGroup" id="rb001"
onclick="this.form.enableRosterGroups[1].checked=true;"
<%= ("onlyGroup".equals(showGroup) && (groupNames == null || groupNames.length == 0) ? "checked" : "") %>>
</td>
<td width="99%">
<label for="rb001"><fmt:message key="group.edit.show_groups_in_groups_members" /></label>
</td>
</tr>
<tr>
<td width="1%" nowrap>
<input type="radio" name="showGroup" value="spefgroups" id="rb003"
onclick="this.form.enableRosterGroups[1].checked=true;"
<%= (groupNames != null && groupNames.length > 0) ? "checked" : "" %>>
</td>
<td width="99%">
<label for="rb003"><fmt:message key="group.edit.show_group_in_roster_group" /></label>
</td>
</tr>
<tr>
<td width="1%" nowrap>
</td>
<td width="99%">
<select name="groupNames" size="6" onclick="this.form.showGroup[2].checked=true;this.form.enableRosterGroups[1].checked=true;"
multiple style="width:300px;font-family:verdana,arial,helvetica,sans-serif;font-size:8pt;">
<% for (Group g : webManager.getGroupManager().getGroups()) { %>
<option value="<%= URLEncoder.encode(g.getName(), "UTF-8") %>"
<%= (contains(groupNames, g.getName()) ? "selected" : "") %>
><%= g.getName() %></option>
<% } %>
</select>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</fieldset>
<br>
<% if (edit) { %>
<input type="submit" name="save" value="<fmt:message key="global.save_settings" />">
<input type="submit" name="cancel" value="<fmt:message key="global.cancel" />">
<% } %>
</form>
<br><br>
<form action="group-edit.jsp" method="post" name="f">
<input type="hidden" name="group" value="<%= groupName %>">
<input type="hidden" name="add" value="Add"/>
<table cellpadding="3" cellspacing="1" border="0">
<tr>
<td nowrap width="1%">
<fmt:message key="group.edit.add_user" />
</td>
<td nowrap class="c1" align="left">
<input type="text" size="40" name="users"/>
<input type="submit" name="addbutton" value="<fmt:message key="global.add" />">
</td>
</tr>
</table>
</form>
<form action="group-edit.jsp" method="post" name="main">
<input type="hidden" name="group" value="<%= groupName %>">
<table class="jive-table" cellpadding="3" cellspacing="0" border="0" width="600">
<tr>
<th colspan="2" nowrap><fmt:message key="group.edit.username" /></th>
<th width="1%" nowrap><fmt:message key="group.edit.admin" /></th>
<th width="1%" nowrap><fmt:message key="group.edit.remove" /></th>
</tr>
<!-- Add admins first -->
<%
int memberCount = group.getMembers().size() + group.getAdmins().size();
boolean showUpdateButtons = memberCount > 0;
boolean showRemoteJIDsWarning = false;
if (memberCount == 0) {
%>
<tr>
<td align="center" colspan="4">
<br>
<fmt:message key="group.edit.user_hint" />
<br>
<br>
</td>
</tr>
<%
}
else {
// Sort the list of members.
ArrayList<JID> allMembers = new ArrayList<JID>(memberCount);
allMembers.addAll(group.getMembers());
Collection<JID> admins = group.getAdmins();
allMembers.addAll(admins);
Collections.sort(allMembers);
for (JID jid:allMembers) {
boolean isLocal = webManager.getXMPPServer().isLocal(jid);
User user = null;
if (isLocal) {
try {
user = userManager.getUser(jid.getNode());
}
catch (UserNotFoundException unfe) {
// Ignore.
}
}
%>
<tr>
<td width="1%">
<% if (user != null && presenceManager.isAvailable(user)) {
Presence presence = presenceManager.getPresence(user);
%>
<% if (presence.getShow() == null) { %>
<img src="images/user-green-16x16.gif" width="16" height="16" border="0" title="<fmt:message key="user.properties.available" />" alt="<fmt:message key="user.properties.available" />">
<% } %>
<% if (presence.getShow() == Presence.Show.chat) { %>
<img src="images/user-green-16x16.gif" width="16" height="16" border="0" title="<fmt:message key="session.details.chat_available" />" alt="<fmt:message key="session.details.chat_available" />">
<% } %>
<% if (presence.getShow() == Presence.Show.away) { %>
<img src="images/user-yellow-16x16.gif" width="16" height="16" border="0" title="<fmt:message key="session.details.away" />" alt="<fmt:message key="session.details.away" />">
<% } %>
<% if (presence.getShow() == Presence.Show.xa) { %>
<img src="images/user-yellow-16x16.gif" width="16" height="16" border="0" title="<fmt:message key="session.details.extended" />" alt="<fmt:message key="session.details.extended" />">
<% } %>
<% if (presence.getShow() == Presence.Show.dnd) { %>
<img src="images/user-red-16x16.gif" width="16" height="16" border="0" title="<fmt:message key="session.details.not_disturb" />" alt="<fmt:message key="session.details.not_disturb" />">
<% } %>
<% } else { %>
<img src="images/user-clear-16x16.gif" width="16" height="16" border="0" title="<fmt:message key="user.properties.offline" />" alt="<fmt:message key="user.properties.offline" />">
<% } %>
</td>
<% if (user != null) { %>
<td><a href="user-properties.jsp?username=<%= URLEncoder.encode(user.getUsername(), "UTF-8") %>"><%= user.getUsername() %></a><% if (!isLocal) { showRemoteJIDsWarning = true; %> <font color="red"><b>*</b></font><%}%></td>
<% } else { %>
<td><%= jid %><% showRemoteJIDsWarning = true; %> <font color="red"><b>*</b></font></td>
<% } %>
<td align="center">
<input type="checkbox" name="admin" value="<%= jid %>" <% if (admins.contains(jid)) { %>checked<% } %>>
</td>
<td align="center">
<input type="checkbox" name="delete" value="<%= jid %>">
</td>
</tr>
<%
}
}
if (showUpdateButtons) {
%>
<tr>
<td colspan="2">
</td>
<td align="center">
<input type="submit" name="save" value="Update">
</td>
<td align="center">
<input type="submit" name="remove" value="Remove">
</td>
</tr>
<%
}
if (showRemoteJIDsWarning) {
%>
<tr>
<td colspan="4">
<font color="red">* <fmt:message key="group.edit.note" /></font>
</td>
</tr>
<%
}
%>
</table>
</div>
</form>
<script type="text/javascript">
document.f.users.focus();
</script>
</body>
</html>
<%!
private static String toList(String[] array, String enc) {
if (array == null || array.length == 0) {
return "";
}
StringBuffer buf = new StringBuffer();
String sep = "";
for (int i=0; i<array.length; i++) {
String item;
try {
item = URLDecoder.decode(array[i], enc);
}
catch (UnsupportedEncodingException e) {
item = array[i];
}
buf.append(sep).append(item);
sep = ",";
}
return buf.toString();
}
private static boolean contains(String[] array, String item) {
if (array == null || array.length == 0 || item == null) {
return false;
}
for (int i=0; i<array.length; i++) {
if (item.equals(array[i])) {
return true;
}
}
return false;
}
%>