<%-- - $RCSfile$ - $Revision$ - $Date$ - - Copyright (C) 2004-2008 Jive Software. 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. --%> <%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %> <%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %> <%@ page import="org.jivesoftware.openfire.XMPPServer, org.jivesoftware.openfire.component.ExternalComponentConfiguration, org.jivesoftware.openfire.component.ExternalComponentManager, org.jivesoftware.util.ModificationNotAllowedException, org.jivesoftware.util.ParamUtils, java.util.Collection" errorPage="error.jsp" %> <%@ page import="java.util.HashMap" %> <%@ page import="java.util.Iterator" %> <%@ page import="java.util.Map" %> <% webManager.init(request, response, session, application, out ); %> <fmt:message key="component.settings.title"/> <% // 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; boolean operationFailed = false; String operationFailedDetail = null; String serverName = XMPPServer.getInstance().getServerInfo().getXMPPDomain(); // Update the session kick policy if requested Map errors = new HashMap(); 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()) { try { if (!componentEnabled) { ExternalComponentManager.setServiceEnabled(false); // Log the event webManager.logEvent("disabled external component service", null); } else { ExternalComponentManager.setServiceEnabled(true); ExternalComponentManager.setServicePort(port); ExternalComponentManager.setDefaultSecret(defaultSecret); // Log the event webManager.logEvent("enabled external component service on port "+port, null); } updateSucess = true; } catch (ModificationNotAllowedException e) { operationFailedDetail = e.getMessage(); operationFailed = true; } } } if (permissionUpdate) { try { ExternalComponentManager.setPermissionPolicy(permissionFilter); // Log the event webManager.logEvent("set external component permission policy", "filter = "+permissionFilter); updateSucess = true; } catch (ModificationNotAllowedException e) { operationFailedDetail = e.getMessage(); operationFailed = true; } } if (configToDelete != null && configToDelete.trim().length() != 0) { try { ExternalComponentManager.deleteConfiguration(configToDelete); // Log the event webManager.logEvent("deleted a external component configuration", "config is "+configToDelete); deleteSuccess = true; } catch (ModificationNotAllowedException e) { operationFailedDetail = e.getMessage(); operationFailed = true; } } 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, ""); ExternalComponentConfiguration configuration = new ExternalComponentConfiguration(subdomain, false, ExternalComponentConfiguration.Permission.allowed, secret); try { ExternalComponentManager.allowAccess(configuration); // Log the event webManager.logEvent("allowed external component access", "configuration = "+configuration); allowSuccess = true; } catch (ModificationNotAllowedException e) { operationFailedDetail = e.getMessage(); operationFailed = true; } } } 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, ""); try { ExternalComponentManager.blockAccess(subdomain); // Log the event webManager.logEvent("blocked external component access", "subdomain = "+subdomain); blockSuccess = true; } catch (ModificationNotAllowedException e) { operationFailedDetail = e.getMessage(); operationFailed = true; } } } // Set page vars componentEnabled = ExternalComponentManager.isServiceEnabled(); if (errors.size() == 0) { port = ExternalComponentManager.getServicePort(); defaultSecret = ExternalComponentManager.getDefaultSecret(); permissionFilter = ExternalComponentManager.getPermissionPolicy().toString(); subdomain = ""; secret = ""; } else { if (port == 0) { port = ExternalComponentManager.getServicePort(); } if (defaultSecret == null) { defaultSecret = ExternalComponentManager.getDefaultSecret(); } if (permissionFilter == null) { permissionFilter = ExternalComponentManager.getPermissionPolicy().toString(); } if (subdomain == null) { subdomain = ""; } if (secret == null) { secret = ""; } } %>

" %>" /> " %>" />

<% if (!errors.isEmpty()) { %>
<% if (errors.get("port") != null) { %> <% } else if (errors.get("defaultSecret") != null) { %> <% } else if (errors.get("subdomain") != null) { %> <% } else if (errors.get("secret") != null) { %> <% } %>

<% } else if (operationFailed) { %>
<%= operationFailedDetail != null ? operationFailedDetail : ""%>

<% } else if (updateSucess || allowSuccess || blockSuccess || deleteSuccess) { %>
<% if (updateSucess) { %> <% } else if (allowSuccess) { %> <% } else if (blockSuccess) { %> <% } else if (deleteSuccess) { %> <% } %>

<% } %>
>
>
 
">
">
<% if (componentEnabled) { %>
>
>

">

<% Collection configs = ExternalComponentManager.getAllowedComponents(); if (configs.isEmpty()) { %> <% } else { int count = 1; for (Iterator it=configs.iterator(); it.hasNext(); count++) { ExternalComponentConfiguration configuration = it.next(); %> "> <% } } %>
 
<%= count %> <%= configuration.getSubdomain() %> <%= configuration.getSecret() %> ')) { location.replace('external-components-settings.jsp?deleteConf=<%= configuration.getSubdomain() %>'); } " title="" >

"/> "/>
">



<% Collection blockedComponents = ExternalComponentManager.getBlockedComponents(); if (blockedComponents.isEmpty()) { %> <% } else { int count = 1; for (Iterator it=blockedComponents.iterator(); it.hasNext(); count++) { ExternalComponentConfiguration configuration = it.next(); %> "> <% } } %>
 
<%= count %> <%= configuration.getSubdomain() %> ')) { location.replace('external-components-settings.jsp?deleteConf=<%= configuration.getSubdomain() %>'); } " title="" >

"/>  ">
<% } %>