server-session-summary.jsp 6.91 KB
Newer Older
Gaston Dombiak's avatar
Gaston Dombiak committed
1 2 3 4
<%--
  -	$Revision$
  -	$Date$
  -
5
  - Copyright (C) 2004-2008 Jive Software. All rights reserved.
Gaston Dombiak's avatar
Gaston Dombiak committed
6
  -
7 8 9 10 11 12 13 14 15 16 17
  - 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
18 19
--%>

20
<%@ page import="org.jivesoftware.openfire.SessionManager,
21 22
                 org.jivesoftware.openfire.session.OutgoingServerSession,
                 org.jivesoftware.openfire.session.Session,
23
                 org.jivesoftware.util.ParamUtils,
24
                 java.util.*"
Gaston Dombiak's avatar
Gaston Dombiak committed
25 26 27
    errorPage="error.jsp"
%>

28 29
<%@ 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
30 31 32 33 34
<%!
    final int DEFAULT_RANGE = 15;
    final int[] RANGE_PRESETS = {15, 25, 50, 75, 100};
%>

35 36
<jsp:useBean id="webManager" class="org.jivesoftware.util.WebManager"  />
<% webManager.init(request, response, session, application, out ); %>
Gaston Dombiak's avatar
Gaston Dombiak committed
37 38 39

<%  // Get parameters
    int start = ParamUtils.getIntParameter(request,"start",0);
40
    int range = ParamUtils.getIntParameter(request,"range",webManager.getRowsPerPage("server-session-summary", DEFAULT_RANGE));
Gaston Dombiak's avatar
Gaston Dombiak committed
41 42 43
    boolean close = ParamUtils.getBooleanParameter(request,"close");
    String hostname = ParamUtils.getParameter(request,"hostname");

44
    if (request.getParameter("range") != null) {
45
        webManager.setRowsPerPage("server-session-summary", range);
46 47
    }

Gaston Dombiak's avatar
Gaston Dombiak committed
48
    // Get the user manager
49
    SessionManager sessionManager = webManager.getSessionManager();
Gaston Dombiak's avatar
Gaston Dombiak committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

    Collection<String> hostnames = new TreeSet<String>();
    // Get the incoming session hostnames
    Collection<String> inHostnames = sessionManager.getIncomingServers();
    hostnames.addAll(inHostnames);
    // Get the outgoing session hostnames
    Collection<String> outHostnames = sessionManager.getOutgoingServers();
    hostnames.addAll(outHostnames);

    // Get the session count
    int sessionCount = hostnames.size();

    // Close all connections related to the specified host
    if (close) {
        try {
65
            for (Session sess : sessionManager.getIncomingServerSessions(hostname)) {
66
                sess.close();
Gaston Dombiak's avatar
Gaston Dombiak committed
67
            }
68 69

            Session sess = sessionManager.getOutgoingServerSession(hostname);
Gaston Dombiak's avatar
Gaston Dombiak committed
70
            if (sess != null) {
71
                sess.close();
Gaston Dombiak's avatar
Gaston Dombiak committed
72
            }
73 74
            // Log the event
            webManager.logEvent("closed server session for "+hostname, null);
Gaston Dombiak's avatar
Gaston Dombiak committed
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
            // wait one second
            Thread.sleep(1000L);
        }
        catch (Exception ignored) {
            // Session might have disappeared on its own
        }
        // redirect back to this page
        response.sendRedirect("server-session-summary.jsp?close=success");
        return;
    }
    // paginator vars
    int numPages = (int)Math.ceil((double)sessionCount/(double)range);
    int curPage = (start/range) + 1;
    int maxIndex = (start+range <= sessionCount ? start+range : sessionCount);
%>

91 92 93 94 95 96 97
<html>
    <head>
        <title><fmt:message key="server.session.summary.title"/></title>
        <meta name="pageID" content="server-session-summary"/>
        <meta name="helpPage" content="view_active_server_sessions.html"/>
    </head>
    <body>
Gaston Dombiak's avatar
Gaston Dombiak committed
98 99 100 101 102 103 104 105 106

<%  if ("success".equals(request.getParameter("close"))) { %>

    <p class="jive-success-text">
    <fmt:message key="server.session.summary.close" />
    </p>

<%  } %>

107
<p>
Gaston Dombiak's avatar
Gaston Dombiak committed
108 109 110 111
<fmt:message key="server.session.summary.active" />: <b><%= hostnames.size() %></b>

<%  if (numPages > 1) { %>

112
    - <fmt:message key="global.showing" /> <%= (start+1) %>-<%= (start+range) %>
Gaston Dombiak's avatar
Gaston Dombiak committed
113 114 115 116 117

<%  } %>
 - <fmt:message key="server.session.summary.sessions_per_page" />:
<select size="1" onchange="location.href='server-session-summary.jsp?start=0&range=' + this.options[this.selectedIndex].value;">

118
    <% for (int aRANGE_PRESETS : RANGE_PRESETS) { %>
Gaston Dombiak's avatar
Gaston Dombiak committed
119

120 121 122
    <option value="<%= aRANGE_PRESETS %>"
            <%= (aRANGE_PRESETS == range ? "selected" : "") %>><%= aRANGE_PRESETS %>
    </option>
Gaston Dombiak's avatar
Gaston Dombiak committed
123

124
    <% } %>
Gaston Dombiak's avatar
Gaston Dombiak committed
125 126

</select>
127
</p>
Gaston Dombiak's avatar
Gaston Dombiak committed
128 129 130 131

<%  if (numPages > 1) { %>

    <p>
132
    <fmt:message key="global.pages" />:
Gaston Dombiak's avatar
Gaston Dombiak committed
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
    [
    <%  for (int i=0; i<numPages; i++) {
            String sep = ((i+1)<numPages) ? " " : "";
            boolean isCurrent = (i+1) == curPage;
    %>
        <a href="server-session-summary.jsp?start=<%= (i*range) %>"
         class="<%= ((isCurrent) ? "jive-current" : "") %>"
         ><%= (i+1) %></a><%= sep %>

    <%  } %>
    ]
    </p>

<%  } %>

<p>
149
<fmt:message key="server.session.summary.info">
150 151
    <fmt:param value="<a href=\"server2server-settings.jsp\">" />
    <fmt:param value="</a>" />
152
</fmt:message>
Gaston Dombiak's avatar
Gaston Dombiak committed
153 154 155 156 157 158 159 160
</p>

<div class="jive-table">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<thead>
    <tr>
        <th>&nbsp;</th>
        <th nowrap><fmt:message key="server.session.label.host" /></th>
161
        <th nowrap colspan="3"><fmt:message key="server.session.label.connection" /></th>
Gaston Dombiak's avatar
Gaston Dombiak committed
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
        <th nowrap><fmt:message key="server.session.label.creation" /></th>
        <th nowrap><fmt:message key="server.session.label.last_active" /></th>
        <th nowrap><fmt:message key="server.session.label.close_connect" /></th>
    </tr>
</thead>
<tbody>
    <%  // Check if no out/in connection to/from a remote server exists
        if (hostnames.isEmpty()) {
    %>
        <tr>
            <td colspan="9">

                <fmt:message key="server.session.summary.not_session" />

            </td>
        </tr>

    <%  } %>

181
    <% int count = 0;
Gaston Dombiak's avatar
Gaston Dombiak committed
182 183 184
        hostnames = new ArrayList<String>(hostnames).subList(start, maxIndex);
        for (String host : hostnames) {
            count++;
185
            List<IncomingServerSession> inSessions = sessionManager.getIncomingServerSessions(host);
Gaston Dombiak's avatar
Gaston Dombiak committed
186
            OutgoingServerSession outSession = sessionManager.getOutgoingServerSession(host);
187
            if (inSessions.isEmpty() && outSession == null) {
Gaston Dombiak's avatar
Gaston Dombiak committed
188 189 190 191 192 193 194 195 196 197 198 199 200 201
                // If the connections were just closed then skip this host
                continue;
            }
    %>
        <%@ include file="server-session-row.jspf" %>
    <%  } %>

</tbody>
</table>
</div>

<%  if (numPages > 1) { %>

    <p>
202
    <fmt:message key="global.pages" />:
Gaston Dombiak's avatar
Gaston Dombiak committed
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
    [
    <%  for (int i=0; i<numPages; i++) {
            String sep = ((i+1)<numPages) ? " " : "";
            boolean isCurrent = (i+1) == curPage;
    %>
        <a href="server-session-summary.jsp?start=<%= (i*range) %>"
         class="<%= ((isCurrent) ? "jive-current" : "") %>"
         ><%= (i+1) %></a><%= sep %>

    <%  } %>
    ]
    </p>

<%  } %>

<br>
<p>
<fmt:message key="server.session.summary.last_update" />: <%= JiveGlobals.formatDateTime(new Date()) %>
</p>

223 224
    </body>
</html>