muc-create-permission.jsp 11.9 KB
Newer Older
Derek DeMoro's avatar
Derek DeMoro committed
1
<%--
Matt Tucker's avatar
Matt Tucker committed
2 3
  -	$Revision$
  -	$Date$
Bill Lynch's avatar
Bill Lynch committed
4
  -
5
  - Copyright (C) 2004-2008 Jive Software. All rights reserved.
Bill Lynch's avatar
Bill Lynch committed
6
  -
7 8 9 10 11 12 13 14 15 16 17 18
  - 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.

Matt Tucker's avatar
Matt Tucker committed
19 20 21
--%>

<%@ page import="org.jivesoftware.util.*,
22 23
                 org.jivesoftware.openfire.group.Group,
                 org.jivesoftware.openfire.group.GroupJID,
Matt Tucker's avatar
Matt Tucker committed
24
                 java.util.*,
25
                 org.xmpp.packet.*,
26
                 org.jivesoftware.openfire.muc.MultiUserChatService"
Bill Lynch's avatar
Bill Lynch committed
27
    errorPage="error.jsp"
Matt Tucker's avatar
Matt Tucker committed
28
%>
29
<%@ page import="java.net.URLEncoder" %>
30
<%@ page import="java.net.URLDecoder" %>
Matt Tucker's avatar
Matt Tucker committed
31

32
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
33
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
34 35
<jsp:useBean id="webManager" class="org.jivesoftware.util.WebManager" />
<% webManager.init(request, response, session, application, out ); %>
Matt Tucker's avatar
Matt Tucker committed
36 37 38

<%  // Get parameters
    String userJID = ParamUtils.getParameter(request,"userJID");
39
    String[] groupNames = ParamUtils.getParameters(request, "groupNames");
Bill Lynch's avatar
Bill Lynch committed
40 41 42 43 44
    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;
Matt Tucker's avatar
Matt Tucker committed
45
    boolean delete = ParamUtils.getBooleanParameter(request,"delete");
Bill Lynch's avatar
Bill Lynch committed
46
    boolean openPerms = ParamUtils.getBooleanParameter(request,"openPerms");
47
    String mucname = ParamUtils.getParameter(request,"mucname");
Matt Tucker's avatar
Matt Tucker committed
48

49 50 51 52 53 54 55 56
    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;
    }

    // Get muc server
    MultiUserChatService mucService = webManager.getMultiUserChatManager().getMultiUserChatService(mucname);
Matt Tucker's avatar
Matt Tucker committed
57 58

    // Handle a save
59
    Map<String,String> errors = new HashMap<String,String>();
Bill Lynch's avatar
Bill Lynch committed
60 61 62
    if (save) {
        if (openPerms) {
            // Remove all users who have the ability to create rooms
63 64
            List<JID> removeables = new ArrayList<JID>();
            for (JID user : mucService.getUsersAllowedToCreate()) {
Bill Lynch's avatar
Bill Lynch committed
65 66
                removeables.add(user);
            }
67
            for (JID user : removeables) {
68
                mucService.removeUserAllowedToCreate(user);
Bill Lynch's avatar
Bill Lynch committed
69
            }
70
            mucService.setRoomCreationRestricted(false);
71
            // Log the event
72
            webManager.logEvent("set MUC room creation to restricted for service "+mucname, null);
73
            response.sendRedirect("muc-create-permission.jsp?success=true&mucname="+URLEncoder.encode(mucname, "UTF-8"));
74 75 76
            return;
        }
        else {
77
            mucService.setRoomCreationRestricted(true);
78
            // Log the event
79
            webManager.logEvent("set MUC room creation to not restricted for service "+mucname, null);
80
            response.sendRedirect("muc-create-permission.jsp?success=true&mucname="+URLEncoder.encode(mucname, "UTF-8"));
Bill Lynch's avatar
Bill Lynch committed
81 82 83 84
            return;
        }
    }

85
    List<JID> allowedJIDs = new ArrayList<JID>();
86
    try {
87
    	if (userJID != null && userJID.trim().length() > 0) {
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
    		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('@'), userJID.length());
                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, "UTF-8"));
    			allowedJIDs.add(groupJID);
    		}
108
    	}
109 110
    } catch (java.lang.IllegalArgumentException ex) {
        errors.put("userJID","userJID");
Matt Tucker's avatar
Matt Tucker committed
111 112
    }

113 114 115
    if (errors.size() == 0) {
	    // Handle an add
	    if (add) {
116 117 118 119 120
            mucService.addUsersAllowedToCreate(allowedJIDs);
            // 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, "UTF-8"));
            return;
121 122 123 124
	    }
	
	    if (delete) {
	        // Remove the user from the allowed list
125
	        mucService.removeUserAllowedToCreate(GroupJID.fromString(userJID));
126 127 128 129 130 131 132
	        // 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, "UTF-8"));
	        return;
	    }
	}
Matt Tucker's avatar
Matt Tucker committed
133 134
%>

135
<html>
136 137
<head>
<title><fmt:message key="muc.create.permission.title"/></title>
138 139
<meta name="subPageID" content="muc-perms"/>
<meta name="extraParams" content="<%= "mucname="+URLEncoder.encode(mucname, "UTF-8") %>"/>
140 141 142
<meta name="helpPage" content="set_group_chat_room_creation_permissions.html"/>
</head>
<body>
Matt Tucker's avatar
Matt Tucker committed
143

Bill Lynch's avatar
Bill Lynch committed
144
<p>
145
<fmt:message key="muc.create.permission.info" />
Sven Tantau's avatar
Sven Tantau committed
146
<fmt:message key="groupchat.service.settings_affect" /> <b><a href="muc-service-edit-form.jsp?mucname=<%= URLEncoder.encode(mucname, "UTF-8") %>"><%= StringUtils.escapeHTMLTags(mucname) %></a></b>
Bill Lynch's avatar
Bill Lynch committed
147
</p>
Matt Tucker's avatar
Matt Tucker committed
148

149 150 151 152 153
<%  if (errors.size() > 0) { 
	    if (delete) {
	    	userJID = null; // mask group jid on error
	    }
%>
Matt Tucker's avatar
Matt Tucker committed
154

Bill Lynch's avatar
Bill Lynch committed
155 156 157
    <div class="jive-error">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
158
        <tr><td class="jive-icon"><img src="images/error-16x16.gif" width="16" height="16" border="0" alt=""></td>
Bill Lynch's avatar
Bill Lynch committed
159
        <td class="jive-icon-label">
160
        <fmt:message key="muc.create.permission.error" />
Bill Lynch's avatar
Bill Lynch committed
161 162 163 164
        </td></tr>
    </tbody>
    </table>
    </div><br>
Matt Tucker's avatar
Matt Tucker committed
165

Bill Lynch's avatar
Bill Lynch committed
166
<%  } else if (success || addsuccess || deletesuccess) { %>
Matt Tucker's avatar
Matt Tucker committed
167

Bill Lynch's avatar
Bill Lynch committed
168 169 170
    <div class="jive-success">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
171
        <tr><td class="jive-icon"><img src="images/success-16x16.gif" width="16" height="16" border="0" alt=""></td>
Bill Lynch's avatar
Bill Lynch committed
172 173
        <td class="jive-icon-label">
        <%  if (success) { %>
Matt Tucker's avatar
Matt Tucker committed
174

175
            <fmt:message key="muc.create.permission.update" />
Matt Tucker's avatar
Matt Tucker committed
176

Bill Lynch's avatar
Bill Lynch committed
177
        <%  } else if (addsuccess) { %>
Matt Tucker's avatar
Matt Tucker committed
178

179
            <fmt:message key="muc.create.permission.add_user" />
Matt Tucker's avatar
Matt Tucker committed
180

Bill Lynch's avatar
Bill Lynch committed
181
        <%  } else if (deletesuccess) { %>
Matt Tucker's avatar
Matt Tucker committed
182

183
            <fmt:message key="muc.create.permission.user_removed" />
Matt Tucker's avatar
Matt Tucker committed
184

Bill Lynch's avatar
Bill Lynch committed
185 186 187 188 189
        <%  } %>
        </td></tr>
    </tbody>
    </table>
    </div><br>
Matt Tucker's avatar
Matt Tucker committed
190 191 192

<%  } %>

193
<!-- BEGIN 'Permission Policy' -->
Bill Lynch's avatar
Bill Lynch committed
194
<form action="muc-create-permission.jsp?save" method="post">
Sven Tantau's avatar
Sven Tantau committed
195
    <input type="hidden" name="mucname" value="<%= StringUtils.escapeForXML(mucname) %>" />
196
    <div class="jive-contentBoxHeader">
197 198 199 200
		<fmt:message key="muc.create.permission.policy" />
	</div>
	<div class="jive-contentBox">
		<table cellpadding="3" cellspacing="0" border="0">
Bill Lynch's avatar
Bill Lynch committed
201 202 203 204
        <tbody>
            <tr>
                <td width="1%">
                    <input type="radio" name="openPerms" value="true" id="rb01"
205
                     <%= ((!mucService.isRoomCreationRestricted()) ? "checked" : "") %>>
Bill Lynch's avatar
Bill Lynch committed
206 207
                </td>
                <td width="99%">
208
                    <label for="rb01"><fmt:message key="muc.create.permission.anyone_created" /></label>
Bill Lynch's avatar
Bill Lynch committed
209 210 211 212 213 214
                </td>
            </tr>
            <tr>
                <td width="1%">
                    <input type="radio" name="openPerms" value="false" id="rb02"
                     onfocus="this.form.userJID.focus();"
215
                     <%= ((mucService.isRoomCreationRestricted()) ? "checked" : "") %>>
Bill Lynch's avatar
Bill Lynch committed
216 217
                </td>
                <td width="99%">
218
                    <label for="rb02"><fmt:message key="muc.create.permission.specific_created" /></label>
Bill Lynch's avatar
Bill Lynch committed
219 220 221 222
                </td>
            </tr>
        </tbody>
        </table>
223
	</div>
Matt Tucker's avatar
Matt Tucker committed
224
    <input type="submit" value="<fmt:message key="global.save_settings" />">
225
</form>
226
<!-- END 'Permission Policy' -->
Bill Lynch's avatar
Bill Lynch committed
227

228
<br>
Bill Lynch's avatar
Bill Lynch committed
229

230

231
<%  if (mucService.isRoomCreationRestricted()) { %>
232 233
<!-- BEGIN 'Allowed Users' -->
<form action="muc-create-permission.jsp?add" method="post">
Sven Tantau's avatar
Sven Tantau committed
234
    <input type="hidden" name="mucname" value="<%= StringUtils.escapeForXML(mucname) %>" />
235
    <div class="jive-contentBoxHeader">
236 237 238
		<fmt:message key="muc.create.permission.allowed_users" />
	</div>
	<div class="jive-contentBox">
239 240 241 242 243 244 245 246 247 248 249
	    <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;" 
		 onclick="this.form.openPerms[1].checked=true;" id="groupJIDs">
		<%  for (Group g : webManager.getGroupManager().getGroups()) {	%>
			<option value="<%= URLEncoder.encode(g.getName(), "UTF-8") %>"
			 <%= (StringUtils.contains(groupNames, g.getName()) ? "selected" : "") %>
			 ><%= StringUtils.escapeHTMLTags(g.getName()) %></option>
		<%  } %>
		</select>
		</p>
250
		<p>
251
        <label for="userJIDtf"><fmt:message key="muc.create.permission.add_jid" /></label>
252
        <input type="text" name="userJID" size="30" maxlength="100" value="<%= (userJID != null ? userJID : "") %>"
Bill Lynch's avatar
Bill Lynch committed
253 254
         onclick="this.form.openPerms[1].checked=true;" id="userJIDtf">
        <input type="submit" value="Add">
255 256 257
        </p>

        <div class="jive-table" style="width:400px;">
258 259 260
			<table cellpadding="0" cellspacing="0" border="0" width="100%">
			<thead>
				<tr>
261
					<th width="99%">User/Group</th>
262 263 264 265
					<th width="1%">Remove</th>
				</tr>
			</thead>
			<tbody>
266
				<%  if (mucService.getUsersAllowedToCreate().size() == 0) { %>
267 268 269 270 271 272 273 274 275

					<tr>
						<td colspan="2">
							<fmt:message key="muc.create.permission.no_allowed_users" />
						</td>
					</tr>

				<%  } %>

276
				<%  for (JID jid : mucService.getUsersAllowedToCreate()) {
277 278
                	    boolean isGroup = GroupJID.isGroup(jid);
                	    String jidDisplay = isGroup ? ((GroupJID)jid).getGroupName() : jid.toString();
279 280 281
				%>
					<tr>
						<td width="99%">
282 283 284 285 286 287 288
		                  <% if (isGroup) { %>
		                	<img src="images/group.gif" width="16" height="16" align="top" title="<fmt:message key="muc.create.permission.group" />" alt="<fmt:message key="muc.create.permission.group" />"/>
		                  <% } else { %>
		                	<img src="images/user.gif" width="16" height="16" align="top" 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()) %>">
						  <%= jidDisplay %></a>
289 290
						</td>
						<td width="1%" align="center">
291
							<a href="muc-create-permission.jsp?userJID=<%= jid.toString() %>&delete=true&mucname=<%= URLEncoder.encode(mucname, "UTF-8") %>"
292 293
							 title="<fmt:message key="muc.create.permission.click_title" />"
							 onclick="return confirm('<fmt:message key="muc.create.permission.confirm_remove" />');"
294
							 ><img src="images/delete-16x16.gif" width="16" height="16" border="0" alt=""></a>
295 296 297 298 299 300
						</td>
					</tr>

				<%  } %>
			</tbody>
			</table>
301
        </div>
302 303 304
	</div>
</form>
<!-- END 'Allowed Users' -->
305 306

<%  } %>
Matt Tucker's avatar
Matt Tucker committed
307

308 309

</body>
Sven Tantau's avatar
Sven Tantau committed
310
</html>
311