external-components-settings.jsp 18.4 KB
Newer Older
Gaston Dombiak's avatar
Gaston Dombiak committed
1 2 3 4 5
<%--
  -	$RCSfile$
  -	$Revision$
  -	$Date$
  -
6
  - Copyright (C) 2004-2008 Jive Software. All rights reserved.
Gaston Dombiak's avatar
Gaston Dombiak committed
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.
Gaston Dombiak's avatar
Gaston Dombiak committed
19 20
--%>

21 22
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
Gaston Dombiak's avatar
Gaston Dombiak committed
23

24 25
<%@ page import="org.jivesoftware.openfire.XMPPServer,
                 org.jivesoftware.openfire.component.ExternalComponentConfiguration,
26
                 org.jivesoftware.openfire.component.ExternalComponentManager,
27
                 org.jivesoftware.util.ModificationNotAllowedException,
Sven Tantau's avatar
Sven Tantau committed
28
                 org.jivesoftware.util.StringUtils,
29
                 org.jivesoftware.util.ParamUtils,
Sven Tantau's avatar
Sven Tantau committed
30 31
                 java.util.Collection,
                 java.net.URLEncoder"
Gaston Dombiak's avatar
Gaston Dombiak committed
32 33
    errorPage="error.jsp"
%>
34 35 36
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.Map" %>
Gaston Dombiak's avatar
Gaston Dombiak committed
37

38 39 40
<jsp:useBean id="webManager" class="org.jivesoftware.util.WebManager" />
<% webManager.init(request, response, session, application, out ); %>

41
<html>
42 43 44 45 46
<head>
<title><fmt:message key="component.settings.title"/></title>
<meta name="pageID" content="external-components-settings"/>
</head>
<body>
Gaston Dombiak's avatar
Gaston Dombiak committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

<%  // Get parameters
    boolean update = request.getParameter("update") != null;
    boolean permissionUpdate = request.getParameter("permissionUpdate") != null;
    boolean componentEnabled = ParamUtils.getBooleanParameter(request,"componentEnabled");
    int port = ParamUtils.getIntParameter(request,"port", 0);
    String defaultSecret = ParamUtils.getParameter(request,"defaultSecret");
    String permissionFilter = ParamUtils.getParameter(request,"permissionFilter");
    String configToDelete = ParamUtils.getParameter(request,"deleteConf");
    boolean componentAllowed = request.getParameter("componentAllowed") != null;
    boolean componentBlocked = request.getParameter("componentBlocked") != null;
    String subdomain = ParamUtils.getParameter(request,"subdomain");
    String secret = ParamUtils.getParameter(request,"secret");
    boolean updateSucess = false;
    boolean allowSuccess = false;
    boolean blockSuccess = false;
    boolean deleteSuccess = false;
64
    boolean operationFailed = false;
65
    String operationFailedDetail = null;
Gaston Dombiak's avatar
Gaston Dombiak committed
66

67
    String serverName = XMPPServer.getInstance().getServerInfo().getXMPPDomain();
Gaston Dombiak's avatar
Gaston Dombiak committed
68 69

    // Update the session kick policy if requested
70
    Map<String, String> errors = new HashMap<String, String>();
Gaston Dombiak's avatar
Gaston Dombiak committed
71 72 73 74 75 76 77 78 79 80 81 82
    if (update) {
        // Validate params
        if (componentEnabled) {
            if (defaultSecret == null || defaultSecret.trim().length() == 0) {
                errors.put("defaultSecret","");
            }
            if (port <= 0) {
                errors.put("port","");
            }
        }
        // If no errors, continue:
        if (errors.isEmpty()) {
83 84 85
            try {
                if (!componentEnabled) {
                    ExternalComponentManager.setServiceEnabled(false);
86 87
                    // Log the event
                    webManager.logEvent("disabled external component service", null);
88 89 90 91 92
                }
                else {
                    ExternalComponentManager.setServiceEnabled(true);
                    ExternalComponentManager.setServicePort(port);
                    ExternalComponentManager.setDefaultSecret(defaultSecret);
93 94
                    // Log the event
                    webManager.logEvent("enabled external component service on port "+port, null);
95 96
                }
                updateSucess = true;
Gaston Dombiak's avatar
Gaston Dombiak committed
97
            }
98
            catch (ModificationNotAllowedException e) {
99
                operationFailedDetail = e.getMessage();
100
                operationFailed = true;
Gaston Dombiak's avatar
Gaston Dombiak committed
101 102 103 104 105
            }
        }
    }

    if (permissionUpdate) {
106 107
        try {
            ExternalComponentManager.setPermissionPolicy(permissionFilter);
108 109
            // Log the event
            webManager.logEvent("set external component permission policy", "filter = "+permissionFilter);
110 111 112
            updateSucess = true;
        }
        catch (ModificationNotAllowedException e) {
113
            operationFailedDetail = e.getMessage();
114 115
            operationFailed = true;
        }
Gaston Dombiak's avatar
Gaston Dombiak committed
116 117 118
    }

    if (configToDelete != null && configToDelete.trim().length() != 0) {
119 120
        try {
            ExternalComponentManager.deleteConfiguration(configToDelete);
121 122
            // Log the event
            webManager.logEvent("deleted a external component configuration", "config is "+configToDelete);
123 124 125
            deleteSuccess = true;
        }
        catch (ModificationNotAllowedException e) {
126
            operationFailedDetail = e.getMessage();
127 128
            operationFailed = true;
        }
Gaston Dombiak's avatar
Gaston Dombiak committed
129 130 131 132 133 134 135 136 137 138 139 140 141 142
    }

    if (componentAllowed) {
        // Validate params
        if (subdomain == null || subdomain.trim().length() == 0) {
            errors.put("subdomain","");
        }
        if (secret == null || secret.trim().length() == 0) {
            errors.put("secret","");
        }
        // If no errors, continue:
        if (errors.isEmpty()) {
            // Remove the hostname if the user is not sending just the subdomain
            subdomain = subdomain.replace("." + serverName, "");
143
            ExternalComponentConfiguration configuration = new ExternalComponentConfiguration(subdomain, false,
144 145 146
                    ExternalComponentConfiguration.Permission.allowed, secret);
            try {
                ExternalComponentManager.allowAccess(configuration);
147 148
                // Log the event
                webManager.logEvent("allowed external component access", "configuration = "+configuration);
149 150 151
                allowSuccess = true;
            }
            catch (ModificationNotAllowedException e) {
152
                operationFailedDetail = e.getMessage();
153 154
                operationFailed = true;
            }
Gaston Dombiak's avatar
Gaston Dombiak committed
155 156 157 158 159 160 161 162 163 164 165 166
        }
    }

    if (componentBlocked) {
        // Validate params
        if (subdomain == null || subdomain.trim().length() == 0) {
            errors.put("subdomain","");
        }
        // If no errors, continue:
        if (errors.isEmpty()) {
            // Remove the hostname if the user is not sending just the subdomain
            subdomain = subdomain.replace("." + serverName, "");
167 168
            try {
                ExternalComponentManager.blockAccess(subdomain);
169 170
                // Log the event
                webManager.logEvent("blocked external component access", "subdomain = "+subdomain);
171 172 173
                blockSuccess = true;
            }
            catch (ModificationNotAllowedException e) {
174
                operationFailedDetail = e.getMessage();
175 176
                operationFailed = true;
            }
Gaston Dombiak's avatar
Gaston Dombiak committed
177 178 179 180
        }
    }

    // Set page vars
181
    componentEnabled = ExternalComponentManager.isServiceEnabled();
Gaston Dombiak's avatar
Gaston Dombiak committed
182
    if (errors.size() == 0) {
183
        port = ExternalComponentManager.getServicePort();
Gaston Dombiak's avatar
Gaston Dombiak committed
184 185 186 187 188 189 190
        defaultSecret = ExternalComponentManager.getDefaultSecret();
        permissionFilter = ExternalComponentManager.getPermissionPolicy().toString();
        subdomain = "";
        secret = "";
    }
    else {
        if (port == 0) {
191
            port = ExternalComponentManager.getServicePort();
Gaston Dombiak's avatar
Gaston Dombiak committed
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
        }
        if (defaultSecret == null) {
            defaultSecret = ExternalComponentManager.getDefaultSecret();
        }
        if (permissionFilter == null) {
            permissionFilter = ExternalComponentManager.getPermissionPolicy().toString();
        }
        if (subdomain == null) {
            subdomain = "";
        }
        if (secret == null) {
            secret = "";
        }
    }
%>

<p>
209
<fmt:message key="component.settings.info">
210 211
    <fmt:param value="<a href=\"component-session-summary.jsp\">'" />
    <fmt:param value="</a>" />
212
</fmt:message>
Gaston Dombiak's avatar
Gaston Dombiak committed
213 214 215 216 217 218 219 220
</p>

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

    <div class="jive-error">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
        <tr>
221
            <td class="jive-icon"><img src="images/error-16x16.gif" width="16" height="16" border="0" alt=""/></td>
Gaston Dombiak's avatar
Gaston Dombiak committed
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
            <td class="jive-icon-label">

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

240 241 242 243 244 245
<%  } else if (operationFailed) { %>

    <div class="jive-error">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
        <tr>
246
            <td class="jive-icon"><img src="images/error-16x16.gif" width="16" height="16" border="0" alt=""/></td>
247
            <td class="jive-icon-label">
Sven Tantau's avatar
Sven Tantau committed
248
                <fmt:message key="component.settings.modification.denied" /> <%= operationFailedDetail != null ? StringUtils.escapeHTMLTags(operationFailedDetail) : ""%>
249 250 251 252 253 254 255
            </td>
        </tr>
    </tbody>
    </table>
    </div>
    <br>

Gaston Dombiak's avatar
Gaston Dombiak committed
256 257 258 259 260
<%  } else if (updateSucess || allowSuccess || blockSuccess || deleteSuccess) { %>

    <div class="jive-success">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
261
        <tr><td class="jive-icon"><img src="images/success-16x16.gif" width="16" height="16" border="0" alt=""></td>
Gaston Dombiak's avatar
Gaston Dombiak committed
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
        <td class="jive-icon-label">
        <% if (updateSucess) { %>
            <fmt:message key="component.settings.confirm.updated" />
        <% } else if (allowSuccess) { %>
            <fmt:message key="component.settings.confirm.allowed" />
        <% } else if (blockSuccess) { %>
            <fmt:message key="component.settings.confirm.blocked" />
        <% } else if (deleteSuccess) { %>
            <fmt:message key="component.settings.confirm.deleted" />
        <%
            }
        %>
        </td></tr>
    </tbody>
    </table>
    </div><br>

<%  } %>


282 283 284 285 286 287 288 289
<!-- BEGIN 'Services Enabled' -->
<form action="external-components-settings.jsp" method="post">
	<div class="jive-contentBoxHeader">
		<fmt:message key="component.settings.enabled.legend" />
	</div>
	<div class="jive-contentBox">
		<table cellpadding="3" cellspacing="0" border="0">
		<tbody>
Matt Tucker's avatar
Matt Tucker committed
290 291
			<tr>
				<td width="1%" valign="top" nowrap>
292 293 294 295 296 297 298 299 300
					<input type="radio" name="componentEnabled" value="false" id="rb01"
					 <%= (!componentEnabled ? "checked" : "") %>>
				</td>
				<td width="99%">
					<label for="rb01">
					<b><fmt:message key="component.settings.label_disable" /></b> - <fmt:message key="component.settings.label_disable_info" />
					</label>
				</td>
			</tr>
Matt Tucker's avatar
Matt Tucker committed
301 302
			<tr>
				<td width="1%" valign="top" nowrap>
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
					<input type="radio" name="componentEnabled" value="true" id="rb02"
					 <%= (componentEnabled ? "checked" : "") %>>
				</td>
				<td width="99%">
					<label for="rb02">
					<b><fmt:message key="component.settings.label_enable" /></b> - <fmt:message key="component.settings.label_enable_info" />
					</label>
				</td>
			</tr>
			<tr valign="top">
				<td width="1%" nowrap>
					&nbsp;
				</td>
				<td width="99%">
					<table cellpadding="3" cellspacing="0" border="0" width="100%">
					<tr valign="top">
						<td width="1%" nowrap class="c1">
							<fmt:message key="component.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 class="c1">
							<fmt:message key="component.settings.defaultSecret" />
						</td>
						<td width="99%">
							<input type="text" size="15" maxlength="70" name="defaultSecret"
Sven Tantau's avatar
Sven Tantau committed
333
							 value="<%= ((defaultSecret != null) ? StringUtils.escapeForXML(defaultSecret) : "") %>">
334 335 336 337 338 339 340 341 342
						</td>
					</tr>
					</table>
				</td>
			</tr>
		</tbody>
		</table>
		<input type="submit" name="update" value="<fmt:message key="global.save_settings" />">
	</div>
Gaston Dombiak's avatar
Gaston Dombiak committed
343
</form>
344
<!-- END 'Services Enabled' -->
Gaston Dombiak's avatar
Gaston Dombiak committed
345

Matt Tucker's avatar
Matt Tucker committed
346 347
<% if (componentEnabled) { %>

Gaston Dombiak's avatar
Gaston Dombiak committed
348 349
<br>

350 351 352 353 354 355 356 357
<!-- BEGIN 'Allowed to Connect' -->
	<div class="jive-contentBoxHeader">
		<fmt:message key="component.settings.allowed" />
	</div>
	<div class="jive-contentBox">
		<form action="external-components-settings.jsp" method="post">
		<table cellpadding="3" cellspacing="0" border="0">
		<tbody>
Gaston Dombiak's avatar
Gaston Dombiak committed
358

Matt Tucker's avatar
Matt Tucker committed
359
			<tr valign="top">
360 361 362 363 364 365 366 367 368 369
				<td width="1%" nowrap>
					<input type="radio" name="permissionFilter" value="<%= ExternalComponentManager.PermissionPolicy.blacklist %>" id="rb03"
					 <%= (ExternalComponentManager.PermissionPolicy.blacklist.toString().equals(permissionFilter) ? "checked" : "") %>>
				</td>
				<td width="99%">
					<label for="rb03">
					<b><fmt:message key="component.settings.anyone" /></b> - <fmt:message key="component.settings.anyone_info" />
					</label>
				</td>
			</tr>
Matt Tucker's avatar
Matt Tucker committed
370
			<tr valign="top">
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
				<td width="1%" nowrap>
					<input type="radio" name="permissionFilter" value="<%= ExternalComponentManager.PermissionPolicy.whitelist %>" id="rb04"
					 <%= (ExternalComponentManager.PermissionPolicy.whitelist.toString().equals(permissionFilter) ? "checked" : "") %>>
				</td>
				<td width="99%">
					<label for="rb04">
					<b><fmt:message key="component.settings.whitelist" /></b> - <fmt:message key="component.settings.whitelist_info" />
					</label>
				</td>
			</tr>
		</tbody>
		</table>
		<br>
		<input type="submit" name="permissionUpdate" value="<fmt:message key="global.save_settings" />">
		</form>
		<br>
		<table class="jive-table" cellpadding="0" cellspacing="0" border="0">
		<thead>
			<tr>
				<th width="1%">&nbsp;</th>
				<th width="50%" nowrap><fmt:message key="component.settings.subdomain" /></th>
				<th width="49%" nowrap><fmt:message key="component.settings.secret" /></th>
				<th width="10%" nowrap><fmt:message key="global.delete" /></th>
			</tr>
		</thead>
		<tbody>
		<% Collection<ExternalComponentConfiguration> configs = ExternalComponentManager.getAllowedComponents();
		   if (configs.isEmpty()) { %>
			<tr>
				<td align="center" colspan="7"><fmt:message key="component.settings.empty_list" /></td>
			</tr>
		   <% }
			else {
			int count = 1;
			for (Iterator<ExternalComponentConfiguration> it=configs.iterator(); it.hasNext(); count++) {
				ExternalComponentConfiguration configuration = it.next();
		   %>
			<tr class="jive-<%= (((count%2)==0) ? "even" : "odd") %>">
				<td>
					<%= count %>
				</td>
				<td>
Sven Tantau's avatar
Sven Tantau committed
413
					<%= StringUtils.escapeHTMLTags(configuration.getSubdomain()) %>
414 415 416 417 418
				</td>
				<td>
					<%= configuration.getSecret() %>
				</td>
				<td align="center" style="border-right:1px #ccc solid;">
Sven Tantau's avatar
Sven Tantau committed
419
					<a href="#" onclick="if (confirm('<fmt:message key="component.settings.confirm_delete" />')) { location.replace('external-components-settings.jsp?deleteConf=<%= URLEncoder.encode(configuration.getSubdomain(),"UTF-8") %>'); } "
420
					 title="<fmt:message key="global.click_delete" />"
421
					 ><img src="images/delete-16x16.gif" width="16" height="16" border="0" alt=""></a>
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
				</td>
			</tr>
		   <% }
		   }
		%>
		</tbody>
		</table>
		<br>
		<table cellpadding="3" cellspacing="1" border="0">
		<form action="external-components-settings.jsp" method="post">
		<tr>
			<td nowrap width="1%">
				<fmt:message key="component.settings.subdomain" />
			</td>
			<td>
				<input type="text" size="40" name="subdomain" value="<%= componentAllowed ?  subdomain : "" %>"/>
			</td>
			<td nowrap width="1%">
				<fmt:message key="component.settings.secret" />
			</td>
			<td>
				<input type="text" size="15" name="secret"value="<%= componentAllowed ?  secret : "" %>"/>
			</td>
		</tr>
		<tr align="center">
			<td colspan="4">
				<input type="submit" name="componentAllowed" value="<fmt:message key="component.settings.allow" />">
			</td>
		</tr>
		</form>
		</table>
	</div>
<!-- END 'Allowed to Connect' -->
Gaston Dombiak's avatar
Gaston Dombiak committed
455

456
<br>
Gaston Dombiak's avatar
Gaston Dombiak committed
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
<!-- BEGIN 'Not Allowed to Connect' -->
	<div class="jive-contentBoxHeader">
		<fmt:message key="component.settings.disallowed" />
	</div>
	<div class="jive-contentBox">
		<table cellpadding="3" cellspacing="0" border="0" >
		<tbody>
			<tr><td><p><fmt:message key="component.settings.disallowed.info" /></p></td></tr>
		</tbody>
		</table>
		<br><br>
		<table class="jive-table" cellpadding="3" cellspacing="0" border="0" >
		<thead>
			<tr>
				<th width="1%">&nbsp;</th>
				<th width="89%" nowrap><fmt:message key="component.settings.subdomain" /></th>
				<th width="10%" nowrap><fmt:message key="global.delete" /></th>
			</tr>
		</thead>
		<tbody>
		<% Collection<ExternalComponentConfiguration> blockedComponents = ExternalComponentManager.getBlockedComponents();
		   if (blockedComponents.isEmpty()) { %>
			<tr>
				<td align="center" colspan="7"><fmt:message key="component.settings.empty_list" /></td>
			</tr>
		   <% }
			else {
			int count = 1;
			for (Iterator<ExternalComponentConfiguration> it=blockedComponents.iterator(); it.hasNext(); count++) {
				ExternalComponentConfiguration configuration = it.next();
		   %>
			<tr class="jive-<%= (((count%2)==0) ? "even" : "odd") %>">
				<td>
					<%= count %>
				</td>
				<td>
					<%= configuration.getSubdomain() %>
				</td>
				<td align="center" style="border-right:1px #ccc solid;">
					<a href="#" onclick="if (confirm('<fmt:message key="component.settings.confirm_delete" />')) { location.replace('external-components-settings.jsp?deleteConf=<%= configuration.getSubdomain() %>'); } "
					 title="<fmt:message key="global.click_delete" />"
499
					 ><img src="images/delete-16x16.gif" width="16" height="16" border="0" alt=""></a>
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522
				</td>
			</tr>
		   <% }
		   }
		%>
		</tbody>
		</table>
		<br>
		<table cellpadding="3" cellspacing="1" border="0">
		<form action="external-components-settings.jsp" method="post">
		<tr>
			<td nowrap width="1%">
				<fmt:message key="component.settings.subdomain" />
			</td>
			<td>
				<input type="text" size="40" name="subdomain" value="<%= componentBlocked ?  subdomain : "" %>"/>&nbsp;
				<input type="submit" name="componentBlocked" value="<fmt:message key="component.settings.block" />">
			</td>
		</tr>
		</form>
		</table>
	</div>
<!-- END 'Not Allowed to Connect' -->
Gaston Dombiak's avatar
Gaston Dombiak committed
523

Matt Tucker's avatar
Matt Tucker committed
524
<% } %>
Gaston Dombiak's avatar
Gaston Dombiak committed
525

526
</body>
527
</html>