external-components-settings.jsp 18.2 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 23
--%>

<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>

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

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

39
<html>
40 41 42 43 44
<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
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61

<%  // 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;
62
    boolean operationFailed = false;
63
    String operationFailedDetail = null;
Gaston Dombiak's avatar
Gaston Dombiak committed
64

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

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

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

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

    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, "");
141
            ExternalComponentConfiguration configuration = new ExternalComponentConfiguration(subdomain, false,
142 143 144
                    ExternalComponentConfiguration.Permission.allowed, secret);
            try {
                ExternalComponentManager.allowAccess(configuration);
145 146
                // Log the event
                webManager.logEvent("allowed external component access", "configuration = "+configuration);
147 148 149
                allowSuccess = true;
            }
            catch (ModificationNotAllowedException e) {
150
                operationFailedDetail = e.getMessage();
151 152
                operationFailed = true;
            }
Gaston Dombiak's avatar
Gaston Dombiak committed
153 154 155 156 157 158 159 160 161 162 163 164
        }
    }

    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, "");
165 166
            try {
                ExternalComponentManager.blockAccess(subdomain);
167 168
                // Log the event
                webManager.logEvent("blocked external component access", "subdomain = "+subdomain);
169 170 171
                blockSuccess = true;
            }
            catch (ModificationNotAllowedException e) {
172
                operationFailedDetail = e.getMessage();
173 174
                operationFailed = true;
            }
Gaston Dombiak's avatar
Gaston Dombiak committed
175 176 177 178
        }
    }

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

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

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

    <div class="jive-error">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
        <tr>
219
            <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
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
            <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>

238 239 240 241 242 243
<%  } else if (operationFailed) { %>

    <div class="jive-error">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
        <tr>
244
            <td class="jive-icon"><img src="images/error-16x16.gif" width="16" height="16" border="0" alt=""/></td>
245
            <td class="jive-icon-label">
246
                <fmt:message key="component.settings.modification.denied" /> <%= operationFailedDetail != null ? operationFailedDetail : ""%>
247 248 249 250 251 252 253
            </td>
        </tr>
    </tbody>
    </table>
    </div>
    <br>

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

    <div class="jive-success">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
259
        <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
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
        <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>

<%  } %>


280 281 282 283 284 285 286 287
<!-- 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
288 289
			<tr>
				<td width="1%" valign="top" nowrap>
290 291 292 293 294 295 296 297 298
					<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
299 300
			<tr>
				<td width="1%" valign="top" nowrap>
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
					<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"
							 value="<%= ((defaultSecret != null) ? defaultSecret : "") %>">
						</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
341
</form>
342
<!-- END 'Services Enabled' -->
Gaston Dombiak's avatar
Gaston Dombiak committed
343

Matt Tucker's avatar
Matt Tucker committed
344 345
<% if (componentEnabled) { %>

Gaston Dombiak's avatar
Gaston Dombiak committed
346 347
<br>

348 349 350 351 352 353 354 355
<!-- 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
356

Matt Tucker's avatar
Matt Tucker committed
357
			<tr valign="top">
358 359 360 361 362 363 364 365 366 367
				<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
368
			<tr valign="top">
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
				<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>
					<%= configuration.getSubdomain() %>
				</td>
				<td>
					<%= configuration.getSecret() %>
				</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" />"
419
					 ><img src="images/delete-16x16.gif" width="16" height="16" border="0" alt=""></a>
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
				</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
453

454
<br>
Gaston Dombiak's avatar
Gaston Dombiak committed
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
<!-- 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" />"
497
					 ><img src="images/delete-16x16.gif" width="16" height="16" border="0" alt=""></a>
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
				</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
521

Matt Tucker's avatar
Matt Tucker committed
522
<% } %>
Gaston Dombiak's avatar
Gaston Dombiak committed
523

524
</body>
525
</html>