server2server-settings.jsp 17.6 KB
Newer Older
Gaston Dombiak's avatar
Gaston Dombiak committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<%--
  -	$Revision$
  -	$Date$
  -
  - Copyright (C) 2004 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.
--%>

<%@ 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.util.*,
                 java.util.Iterator,
16
                 org.jivesoftware.wildfire.*,
Gaston Dombiak's avatar
Gaston Dombiak committed
17
                 java.util.*,
18 19
                 org.jivesoftware.wildfire.server.RemoteServerManager,
                 org.jivesoftware.wildfire.server.RemoteServerConfiguration"
Gaston Dombiak's avatar
Gaston Dombiak committed
20 21 22
    errorPage="error.jsp"
%>

23 24
<jsp:useBean id="webManager" class="org.jivesoftware.util.WebManager"  />
<% webManager.init(request, response, session, application, out ); %>
Gaston Dombiak's avatar
Gaston Dombiak committed
25 26

<%  // Get parameters
27 28 29
    boolean update = request.getParameter("update") != null;
    boolean s2sEnabled = ParamUtils.getBooleanParameter(request,"s2sEnabled");
    int port = ParamUtils.getIntParameter(request,"port", 0);
Gaston Dombiak's avatar
Gaston Dombiak committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
    boolean closeEnabled = ParamUtils.getBooleanParameter(request,"closeEnabled");
    String idletime = ParamUtils.getParameter(request,"idletime");
    boolean closeSettings = request.getParameter("closeSettings") != null;
    boolean closeSettingsSuccess = request.getParameter("closeSettingsSuccess") != null;
    boolean permissionUpdate = request.getParameter("permissionUpdate") != null;
    String permissionFilter = ParamUtils.getParameter(request,"permissionFilter");
    String configToDelete = ParamUtils.getParameter(request,"deleteConf");
    boolean serverAllowed = request.getParameter("serverAllowed") != null;
    boolean serverBlocked = request.getParameter("serverBlocked") != null;
    String domain = ParamUtils.getParameter(request,"domain");
    String remotePort = ParamUtils.getParameter(request,"remotePort");
    boolean updateSucess = false;
    boolean allowSuccess = false;
    boolean blockSuccess = false;
    boolean deleteSuccess = false;

    // Get muc server
47
    SessionManager sessionManager = webManager.getSessionManager();
48
    ConnectionManager connectionManager = XMPPServer.getInstance().getConnectionManager();
Gaston Dombiak's avatar
Gaston Dombiak committed
49

50
    Map<String, String> errors = new HashMap<String, String>();
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
    if (update) {
        // Validate params
        if (s2sEnabled) {
            if (port <= 0) {
                errors.put("port","");
            }
        }
        // If no errors, continue:
        if (errors.isEmpty()) {
            if (!s2sEnabled) {
                connectionManager.enableServerListener(false);
            }
            else {
                connectionManager.enableServerListener(true);
                connectionManager.setServerListenerPort(port);
            }
            updateSucess = true;
        }
    }

Gaston Dombiak's avatar
Gaston Dombiak committed
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
    // Handle an update of the kicking task settings
    if (closeSettings) {
       if (!closeEnabled) {
           // Disable kicking users by setting a value of -1
           sessionManager.setServerSessionIdleTime(-1);
           response.sendRedirect("server2server-settings.jsp?closeSettingsSuccess=true");
           return;
       }
       // do validation
       if (idletime == null) {
           errors.put("idletime","idletime");
       }
       int idle = 0;
       // Try to obtain an int from the provided strings
       if (errors.size() == 0) {
           try {
               idle = Integer.parseInt(idletime) * 1000 * 60;
           }
           catch (NumberFormatException e) {
               errors.put("idletime","idletime");
           }
           if (idle < 0) {
               errors.put("idletime","idletime");
           }
       }

       if (errors.size() == 0) {
           sessionManager.setServerSessionIdleTime(idle);
           response.sendRedirect("server2server-settings.jsp?closeSettingsSuccess=true");
           return;
       }
    }

    if (permissionUpdate) {
        RemoteServerManager.setPermissionPolicy(permissionFilter);
        updateSucess = true;
    }

    if (configToDelete != null && configToDelete.trim().length() != 0) {
        RemoteServerManager.deleteConfiguration(configToDelete);
        deleteSuccess = true;
    }

    if (serverAllowed) {
        int intRemotePort = 0;
        // Validate params
        if (domain == null || domain.trim().length() == 0) {
            errors.put("domain","");
        }
        if (remotePort == null || remotePort.trim().length() == 0 ||  "0".equals(remotePort)) {
            errors.put("remotePort","");
        }
        else {
            try {
                intRemotePort = Integer.parseInt(remotePort);
            }
            catch (NumberFormatException e) {
                errors.put("remotePort","");
            }
        }
        // If no errors, continue:
        if (errors.isEmpty()) {
            RemoteServerConfiguration configuration = new RemoteServerConfiguration(domain);
            configuration.setRemotePort(intRemotePort);
            configuration.setPermission(RemoteServerConfiguration.Permission.allowed);
            RemoteServerManager.allowAccess(configuration);
            allowSuccess = true;
        }
    }

    if (serverBlocked) {
        // Validate params
        if (domain == null || domain.trim().length() == 0) {
            errors.put("domain","");
        }
        // If no errors, continue:
        if (errors.isEmpty()) {
            RemoteServerManager.blockAccess(domain);
            blockSuccess = true;
        }
    }

    // Set page vars
    if (errors.size() == 0) {
155 156
        s2sEnabled = connectionManager.isServerListenerEnabled();
        port = connectionManager.getServerListenerPort();
Gaston Dombiak's avatar
Gaston Dombiak committed
157 158 159 160 161
        permissionFilter = RemoteServerManager.getPermissionPolicy().toString();
        domain = "";
        remotePort = "0";
    }
    else {
162 163 164
        if (port == 0) {
            port = connectionManager.getServerListenerPort();
        }
Gaston Dombiak's avatar
Gaston Dombiak committed
165 166 167 168 169 170 171 172 173 174 175 176
        if (permissionFilter == null) {
            permissionFilter = RemoteServerManager.getPermissionPolicy().toString();
        }
        if (domain == null) {
            domain = "";
        }
        if (remotePort == null) {
            remotePort = "0";
        }
    }
%>

177 178 179 180 181 182
<html>
    <head>
        <title><fmt:message key="server2server.settings.title"/></title>
        <meta name="pageID" content="server2server-settings"/>
    </head>
    <body>
Gaston Dombiak's avatar
Gaston Dombiak committed
183 184

<p>
185 186 187 188
<fmt:message key="server2server.settings.info">
    <fmt:param value="<%= "<a href='server-session-summary.jsp'>" %>" />
    <fmt:param value="<%= "</a>" %>" />
</fmt:message>
Gaston Dombiak's avatar
Gaston Dombiak committed
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
</p>

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

    <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"/></td>
            <td class="jive-icon-label">

            <% if (errors.get("idletime") != null) { %>
                <fmt:message key="server2server.settings.valid.idle_minutes" />
            <% } else if (errors.get("domain") != null) { %>
                <fmt:message key="server2server.settings.valid.domain" />
            <% } else if (errors.get("remotePort") != null) { %>
                <fmt:message key="server2server.settings.valid.remotePort" />
            <% } %>
            </td>
        </tr>
    </tbody>
    </table>
    </div>
    <br>

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

    <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"></td>
        <td class="jive-icon-label">
        <% if (updateSucess) { %>
            <fmt:message key="server2server.settings.confirm.updated" />
        <% } else if (allowSuccess) { %>
            <fmt:message key="server2server.settings.confirm.allowed" />
        <% } else if (blockSuccess) { %>
            <fmt:message key="server2server.settings.confirm.blocked" />
        <% } else if (deleteSuccess) { %>
            <fmt:message key="server2server.settings.confirm.deleted" />
        <% } else if (closeSettingsSuccess) { %>
            <fmt:message key="server2server.settings.update" />
        <%
            }
        %>
        </td></tr>
    </tbody>
    </table>
    </div><br>

<%  } %>

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
<form action="server2server-settings.jsp" method="post">

<fieldset>
    <legend><fmt:message key="server2server.settings.enabled.legend" /></legend>
    <div>
    <table cellpadding="3" cellspacing="0" border="0" width="100%">
    <tbody>
        <tr valign="middle">
            <td width="1%" nowrap>
                <input type="radio" name="s2sEnabled" value="false" id="rb01"
                 <%= (!s2sEnabled ? "checked" : "") %>>
            </td>
            <td width="99%">
                <label for="rb01">
                <b><fmt:message key="server2server.settings.label_disable" /></b> - <fmt:message key="server2server.settings.label_disable_info" />
                </label>
            </td>
        </tr>
        <tr valign="middle">
            <td width="1%" nowrap>
                <input type="radio" name="s2sEnabled" value="true" id="rb02"
                 <%= (s2sEnabled ? "checked" : "") %>>
            </td>
            <td width="99%">
                <label for="rb02">
                <b><fmt:message key="server2server.settings.label_enable" /></b> - <fmt:message key="server2server.settings.label_enable_info" />
Matt Tucker's avatar
Matt Tucker committed
267
                </label>  <input type="text" size="5" maxlength="10" name="port" value="<%= port %>">
268 269 270 271 272 273 274 275 276 277 278 279 280 281
            </td>
        </tr>
    </tbody>
    </table>
    </div>
</fieldset>
<br>

<input type="submit" name="update" value="<fmt:message key="global.save_settings" />">

</form>

<br>

Gaston Dombiak's avatar
Gaston Dombiak committed
282 283 284 285 286 287 288 289 290
<form action="server2server-settings.jsp?closeSettings" method="post">

<fieldset>
    <legend><fmt:message key="server2server.settings.close_settings" /></legend>
    <div>
    <table cellpadding="3" cellspacing="0" border="0" width="100%">
    <tbody>
        <tr valign="middle">
            <td width="1%" nowrap>
291
                <input type="radio" name="closeEnabled" value="false" id="rb03"
292
                 <%= ((webManager.getSessionManager().getServerSessionIdleTime() < 0) ? "checked" : "") %>>
Gaston Dombiak's avatar
Gaston Dombiak committed
293 294
            </td>
            <td width="99%">
295
                <label for="rb03"><fmt:message key="server2server.settings.never_close" /></label>
Gaston Dombiak's avatar
Gaston Dombiak committed
296 297 298 299
            </td>
        </tr>
        <tr valign="middle">
            <td width="1%" nowrap>
300
                <input type="radio" name="closeEnabled" value="true" id="rb04"
301
                 <%= ((webManager.getSessionManager().getServerSessionIdleTime() > -1) ? "checked" : "") %>>
Gaston Dombiak's avatar
Gaston Dombiak committed
302 303
            </td>
            <td width="99%">
304
                    <label for="rb04"><fmt:message key="server2server.settings.close_session" /></label>
Gaston Dombiak's avatar
Gaston Dombiak committed
305 306
                     <input type="text" name="idletime" size="5" maxlength="5"
                         onclick="this.form.closeEnabled[1].checked=true;"
307
                         value="<%= webManager.getSessionManager().getServerSessionIdleTime() == -1 ? 30 : webManager.getSessionManager().getServerSessionIdleTime() / 1000 / 60 %>">
Gaston Dombiak's avatar
Gaston Dombiak committed
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
                     <fmt:message key="global.minutes" />.
            </td>
        </tr>
    </tbody>
    </table>
    </div>
</fieldset>

<br>

<input type="submit" value="<fmt:message key="global.save_settings" />">

</form>

<br>

<fieldset>
    <legend><fmt:message key="server2server.settings.allowed" /></legend>
    <div>
    <form action="server2server-settings.jsp" method="post">
    <table cellpadding="3" cellspacing="0" border="0" width="100%">
    <tbody>

        <tr valign="middle">
            <td width="1%" nowrap>
333
                <input type="radio" name="permissionFilter" value="<%= RemoteServerManager.PermissionPolicy.blacklist %>" id="rb05"
Gaston Dombiak's avatar
Gaston Dombiak committed
334 335 336
                 <%= (RemoteServerManager.PermissionPolicy.blacklist.toString().equals(permissionFilter) ? "checked" : "") %>>
            </td>
            <td width="99%">
337
                <label for="rb05">
Gaston Dombiak's avatar
Gaston Dombiak committed
338 339 340 341 342 343
                <b><fmt:message key="server2server.settings.anyone" /></b> - <fmt:message key="server2server.settings.anyone_info" />
                </label>
            </td>
        </tr>
        <tr valign="middle">
            <td width="1%" nowrap>
344
                <input type="radio" name="permissionFilter" value="<%= RemoteServerManager.PermissionPolicy.whitelist %>" id="rb06"
Gaston Dombiak's avatar
Gaston Dombiak committed
345 346 347
                 <%= (RemoteServerManager.PermissionPolicy.whitelist.toString().equals(permissionFilter) ? "checked" : "") %>>
            </td>
            <td width="99%">
348
                <label for="rb06">
Gaston Dombiak's avatar
Gaston Dombiak committed
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
                <b><fmt:message key="server2server.settings.whitelist" /></b> - <fmt:message key="server2server.settings.whitelist_info" />
                </label>
            </td>
        </tr>
    </tbody>
    </table>
    <br>
    <input type="submit" name="permissionUpdate" value="<fmt:message key="global.save_settings" />">
    </form>

    <table class="jive-table" cellpadding="0" cellspacing="0" border="0" width="100%">
    <thead>
        <tr>
            <th width="1%">&nbsp;</th>
            <th width="50%" nowrap><fmt:message key="server2server.settings.domain" /></th>
            <th width="49%" nowrap><fmt:message key="server2server.settings.remotePort" /></th>
            <th width="10%" nowrap><fmt:message key="global.delete" /></th>
        </tr>
    </thead>
    <tbody>
    <% Collection<RemoteServerConfiguration> configs = RemoteServerManager.getAllowedServers();
       if (configs.isEmpty()) { %>
        <tr>
            <td align="center" colspan="7"><fmt:message key="server2server.settings.empty_list" /></td>
        </tr>
       <% }
        else {
        int count = 1;
        for (Iterator<RemoteServerConfiguration> it=configs.iterator(); it.hasNext(); count++) {
            RemoteServerConfiguration configuration = it.next();
       %>
	    <tr class="jive-<%= (((count%2)==0) ? "even" : "odd") %>">
	        <td>
	            <%= count %>
	        </td>
	        <td>
	            <%= configuration.getDomain() %>
	        </td>
	        <td>
	            <%= configuration.getRemotePort() %>
	        </td>
	        <td align="center" style="border-right:1px #ccc solid;">
	            <a href="#" onclick="if (confirm('<fmt:message key="server2server.settings.confirm_delete" />')) { location.replace('server2server-settings.jsp?deleteConf=<%= configuration.getDomain() %>'); } "
	             title="<fmt:message key="global.click_delete" />"
	             ><img src="images/delete-16x16.gif" width="16" height="16" border="0"></a>
	        </td>
	    </tr>
       <% }
       }
    %>
    </tbody>
    </table>
    <br>
    <table cellpadding="3" cellspacing="1" border="0" width="100%">
    <form action="server2server-settings.jsp" method="post">
    <tr>
Matt Tucker's avatar
Matt Tucker committed
405
        <td nowrap>
Gaston Dombiak's avatar
Gaston Dombiak committed
406 407
            <fmt:message key="server2server.settings.domain" />
            <input type="text" size="40" name="domain" value="<%= serverAllowed ?  domain : "" %>"/>
Matt Tucker's avatar
Matt Tucker committed
408
            &nbsp;
Gaston Dombiak's avatar
Gaston Dombiak committed
409
            <fmt:message key="server2server.settings.remotePort" />
Matt Tucker's avatar
Matt Tucker committed
410
            <input type="text" size="5" name="remotePort"value="<%= serverAllowed ?  remotePort : "5269" %>"/>
Gaston Dombiak's avatar
Gaston Dombiak committed
411 412 413 414 415 416 417 418 419 420 421 422 423 424
            <input type="submit" name="serverAllowed" value="<fmt:message key="server2server.settings.allow" />">
        </td>
    </tr>
    </form>
    </table>

    </div>
</fieldset>

<br><br>

<fieldset>
    <legend><fmt:message key="server2server.settings.disallowed" /></legend>
    <div>
Matt Tucker's avatar
Matt Tucker committed
425 426 427 428 429
    <table cellpadding="3" cellspacing="1" border="0" width="100%"><tr><td>
    <fmt:message key="server2server.settings.disallowed.info" />
    </td></tr></table>
    <p>
    <table class="jive-table" cellpadding="3" cellspacing="0" border="0" width="100%">
Gaston Dombiak's avatar
Gaston Dombiak committed
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
    <thead>
        <tr>
            <th width="1%">&nbsp;</th>
            <th width="89%" nowrap><fmt:message key="server2server.settings.domain" /></th>
            <th width="10%" nowrap><fmt:message key="global.delete" /></th>
        </tr>
    </thead>
    <tbody>
    <% Collection<RemoteServerConfiguration> blockedComponents = RemoteServerManager.getBlockedServers();
       if (blockedComponents.isEmpty()) { %>
        <tr>
            <td align="center" colspan="7"><fmt:message key="server2server.settings.empty_list" /></td>
        </tr>
       <% }
        else {
        int count = 1;
        for (Iterator<RemoteServerConfiguration> it=blockedComponents.iterator(); it.hasNext(); count++) {
            RemoteServerConfiguration configuration = it.next();
       %>
	    <tr class="jive-<%= (((count%2)==0) ? "even" : "odd") %>">
	        <td>
	            <%= count %>
	        </td>
	        <td>
	            <%= configuration.getDomain() %>
	        </td>
	        <td align="center" style="border-right:1px #ccc solid;">
	            <a href="#" onclick="if (confirm('<fmt:message key="server2server.settings.confirm_delete" />')) { location.replace('server2server-settings.jsp?deleteConf=<%= configuration.getDomain() %>'); } "
	             title="<fmt:message key="global.click_delete" />"
	             ><img src="images/delete-16x16.gif" width="16" height="16" border="0"></a>
	        </td>
	    </tr>
       <% }
       }
    %>
    </tbody>
    </table>
    <br>
    <table cellpadding="3" cellspacing="1" border="0" width="100%">
    <form action="server2server-settings.jsp" method="post">
    <tr>
        <td nowrap width="1%">
            <fmt:message key="server2server.settings.domain" />
        </td>
        <td>
            <input type="text" size="40" name="domain" value="<%= serverBlocked ?  domain : "" %>"/>&nbsp;
            <input type="submit" name="serverBlocked" value="<fmt:message key="server2server.settings.block" />">
        </td>
    </tr>
    </form>
    </table>
    </div>
</fieldset>

484 485
    </body>
</html>