session-summary.jsp 9.48 KB
Newer Older
Bill Lynch's avatar
Bill Lynch committed
1
<%--
Matt Tucker's avatar
Matt Tucker committed
2 3
  -	$Revision$
  -	$Date$
Bill Lynch's avatar
Bill Lynch committed
4
  -
5
  - Copyright (C) 2004-2008 Jive Software. All rights reserved.
Bill Lynch's avatar
Bill Lynch 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.
Matt Tucker's avatar
Matt Tucker committed
18 19
--%>

20
<%@ page import="org.jivesoftware.openfire.SessionManager,
21 22
                 org.jivesoftware.openfire.SessionResultFilter,
                 org.jivesoftware.openfire.session.ClientSession,
23 24
                 org.jivesoftware.util.JiveGlobals,
                 org.jivesoftware.util.ParamUtils,
25
                 java.util.Collection"
Bill Lynch's avatar
Bill Lynch committed
26 27
    errorPage="error.jsp"
%>
28
<%@ page import="java.util.Date" %>
Matt Tucker's avatar
Matt Tucker committed
29

30 31
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
32 33 34 35 36 37
<%!
    static final String NONE = LocaleUtils.getLocalizedString("global.none");

    final int DEFAULT_RANGE = 15;
    final int[] RANGE_PRESETS = {15, 25, 50, 75, 100};

38 39
    static final int[] REFRESHES = {0, 10, 30, 60, 90};
    static final String[] REFRESHES_LABELS = {NONE,"10","30","60","90"};
40
%>
41 42
<jsp:useBean id="webManager" class="org.jivesoftware.util.WebManager"  />
<% webManager.init(request, response, session, application, out ); %>
Matt Tucker's avatar
Matt Tucker committed
43 44 45

<%  // Get parameters
    int start = ParamUtils.getIntParameter(request,"start",0);
46 47
    int range = ParamUtils.getIntParameter(request,"range",webManager.getRowsPerPage("session-summary", DEFAULT_RANGE));
    int refresh = ParamUtils.getIntParameter(request,"refresh",webManager.getRefreshValue("session-summary", 0));
Matt Tucker's avatar
Matt Tucker committed
48
    boolean close = ParamUtils.getBooleanParameter(request,"close");
49 50
    int order = ParamUtils.getIntParameter(request, "order",
            webManager.getPageProperty("session-summary", "console.order", SessionResultFilter.ASCENDING));
Matt Tucker's avatar
Matt Tucker committed
51 52
    String jid = ParamUtils.getParameter(request,"jid");

53
    if (request.getParameter("range") != null) {
54
        webManager.setRowsPerPage("session-summary", range);
55 56
    }

57
    if (request.getParameter("refresh") != null) {
58
        webManager.setRefreshValue("session-summary", refresh);
59 60
    }

61 62 63 64
    if (request.getParameter("order") != null) {
        webManager.setPageProperty("session-summary", "console.order", order);
    }

Matt Tucker's avatar
Matt Tucker committed
65
    // Get the user manager
66
    SessionManager sessionManager = webManager.getSessionManager();
Matt Tucker's avatar
Matt Tucker committed
67 68

    // Get the session count
Gaston Dombiak's avatar
Gaston Dombiak committed
69
    int sessionCount = sessionManager.getUserSessionsCount(false);
Matt Tucker's avatar
Matt Tucker committed
70 71 72

    // Close a connection if requested
    if (close) {
Derek DeMoro's avatar
Derek DeMoro committed
73
        JID address = new JID(jid);
Matt Tucker's avatar
Matt Tucker committed
74 75
        try {
            Session sess = sessionManager.getSession(address);
76
            sess.close();
77 78
            // Log the event
            webManager.logEvent("closed session for address "+address, null);
Matt Tucker's avatar
Matt Tucker committed
79 80 81 82 83 84
            // wait one second
            Thread.sleep(1000L);
        }
        catch (Exception ignored) {
            // Session might have disappeared on its own
        }
85
        // Redirect back to this page
Matt Tucker's avatar
Matt Tucker committed
86 87 88 89 90 91 92
        response.sendRedirect("session-summary.jsp?close=success");
        return;
    }

    // paginator vars
    int numPages = (int)Math.ceil((double)sessionCount/(double)range);
    int curPage = (start/range) + 1;
93 94 95 96 97
    // Check that we are not out of bounds
    if (curPage > numPages && numPages > 0){
      curPage = numPages;
      start = (numPages-1)*range;
    }
Matt Tucker's avatar
Matt Tucker committed
98
%>
Bill Lynch's avatar
Bill Lynch committed
99

100 101 102 103 104 105 106
<html>
    <head>
        <title><fmt:message key="session.summary.title"/></title>
        <meta name="pageID" content="session-summary"/>
        <meta name="helpPage" content="view_active_client_sessions.html"/>
    </head>
    <body>
Matt Tucker's avatar
Matt Tucker committed
107

108
<%  if ("success".equals(request.getParameter("close"))) { %>
Matt Tucker's avatar
Matt Tucker committed
109

110 111
    <p class="jive-success-text">
    <fmt:message key="session.summary.close" />
Matt Tucker's avatar
Matt Tucker committed
112 113 114 115
    </p>

<%  } %>

116 117 118 119
<%  if (refresh > 0) { %>
    <meta http-equiv="refresh" content="<%= refresh %>">
<%  } %>

120 121 122 123 124 125 126 127 128
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tbody>
<form action="session-summary.jsp" method="get">
    <tr valign="top">
        <td width="99%">
            <fmt:message key="session.summary.active" />: <b><%= sessionCount %></b>

            <%  if (numPages > 1) { %>

129
                -- <fmt:message key="global.showing" /> <%= (start+1) %>-<%= (start+range) %>
130 131 132 133 134 135

            <%  } %>

            <%  if (numPages > 1) { %>

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

                <%  } %>
                ]

            <%  } %>
150
            -- <fmt:message key="session.summary.sessions_per_page" />:
151 152
            <select size="1" name="range" onchange="this.form.submit();">

153
                <% for (int aRANGE_PRESETS : RANGE_PRESETS) { %>
154

155 156
                <option value="<%= aRANGE_PRESETS %>"<%= (aRANGE_PRESETS == range ? "selected" : "") %>><%= aRANGE_PRESETS %>
                </option>
157

158
                <% } %>
159 160 161 162 163 164 165

            </select>
        </td>
        <td width="1%" nowrap>
            <fmt:message key="global.refresh" />:
            <select size="1" name="refresh" onchange="this.form.submit();">
            <%  for (int j=0; j<REFRESHES.length; j++) {
166
                    String selected = REFRESHES[j] == refresh ? " selected" : "";
167
            %>
168
                <option value="<%= REFRESHES[j] %>"<%= selected %>><%= REFRESHES_LABELS[j] %>
169 170 171 172 173 174 175 176 177 178 179

            <%  } %>
            </select>
            (<fmt:message key="global.seconds" />)

        </td>
    </tr>
</form>
</tbody>
</table>
<br>
Matt Tucker's avatar
Matt Tucker committed
180

181 182 183 184 185
 <% // Get the iterator of sessions, print out session info if any exist.
     SessionResultFilter filter = SessionResultFilter.createDefaultSessionFilter();
     filter.setSortOrder(order);
     filter.setStartIndex(start);
     filter.setNumResults(range);
186
     Collection<ClientSession> sessions = sessionManager.getSessions(filter);
187
 %>
188

Bill Lynch's avatar
Bill Lynch committed
189 190 191
<div class="jive-table">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<thead>
Matt Tucker's avatar
Matt Tucker committed
192
    <tr>
Bill Lynch's avatar
Bill Lynch committed
193
        <th>&nbsp;</th>
194 195 196 197 198 199 200 201 202 203 204
        <th nowrap>
        <%
            if (filter.getSortField() == SessionResultFilter.SORT_USER) {
                if (filter.getSortOrder() == SessionResultFilter.DESCENDING) {
        %>
        <table border="0"><tr valign="middle"><th>
        <a href="session-summary.jsp?order=<%=SessionResultFilter.ASCENDING %>">
        <fmt:message key="session.details.name" /></a>
        </th><th>
        <a href="session-summary.jsp?order=<%=SessionResultFilter.ASCENDING %>">
        <img src="images/sort_descending.gif" border="0" width="16" height="16" alt=""></a>
205
        </th></tr></table>
206 207 208 209 210 211 212 213 214 215
        <%
                }
                else {
        %>
        <table border="0"><tr valign="middle"><th>
        <a href="session-summary.jsp?order=<%=SessionResultFilter.DESCENDING %>">
        <fmt:message key="session.details.name" /></a>
        </th><th>
        <a href="session-summary.jsp?order=<%=SessionResultFilter.DESCENDING %>">
        <img src="images/sort_ascending.gif" width="16" height="16" border="0" alt=""></a>
216
        </th></tr></table>
217 218 219 220 221 222 223 224 225 226
        <%
                }
            }
            else {
        %>
            <fmt:message key="session.details.name" />
        <%
            }
        %>
        </th>
Bill Lynch's avatar
Bill Lynch committed
227
        <th nowrap><fmt:message key="session.details.resource" /></th>
228
        <th nowrap><fmt:message key="session.details.node" /></th>
229 230
        <th nowrap colspan="2"><fmt:message key="session.details.status" /></th>
        <th nowrap colspan="2"><fmt:message key="session.details.presence" /></th>
231
        <th nowrap><fmt:message key="session.details.priority" /></th>
232 233
        <th nowrap><fmt:message key="session.details.clientip" /></th>
        <th nowrap><fmt:message key="session.details.close_connect" /></th>
Bill Lynch's avatar
Bill Lynch committed
234 235 236
    </tr>
</thead>
<tbody>
237
    <%
Matt Tucker's avatar
Matt Tucker committed
238
        if (sessions.isEmpty()) {
Bill Lynch's avatar
Bill Lynch committed
239 240
    %>
        <tr>
241
            <td colspan="11">
Matt Tucker's avatar
Matt Tucker committed
242

243
                <fmt:message key="session.summary.not_session" />
Matt Tucker's avatar
Matt Tucker committed
244

Bill Lynch's avatar
Bill Lynch committed
245 246
            </td>
        </tr>
Matt Tucker's avatar
Matt Tucker committed
247

Bill Lynch's avatar
Bill Lynch committed
248
    <%  } %>
Matt Tucker's avatar
Matt Tucker committed
249

Bill Lynch's avatar
Bill Lynch committed
250 251 252
    <%  int count = start;
        boolean current = false; // needed in session-row.jspf
        String linkURL = "session-details.jsp";
253
        for (ClientSession sess : sessions) {
254 255
        	try { // skip invalid sessions (OF-590)
        		if (!sess.validate()) continue;
256
        	} catch (Exception ex) {
257 258
        		continue;
        	}
Bill Lynch's avatar
Bill Lynch committed
259 260 261 262
            count++;
    %>
        <%@ include file="session-row.jspf" %>
    <%  } %>
Matt Tucker's avatar
Matt Tucker committed
263

Bill Lynch's avatar
Bill Lynch committed
264
</tbody>
Matt Tucker's avatar
Matt Tucker committed
265 266 267 268 269 270
</table>
</div>

<%  if (numPages > 1) { %>

    <p>
271
    <fmt:message key="global.pages" />:
Matt Tucker's avatar
Matt Tucker committed
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
    [
    <%  for (int i=0; i<numPages; i++) {
            String sep = ((i+1)<numPages) ? " " : "";
            boolean isCurrent = (i+1) == curPage;
    %>
        <a href="session-summary.jsp?start=<%= (i*range) %>"
         class="<%= ((isCurrent) ? "jive-current" : "") %>"
         ><%= (i+1) %></a><%= sep %>

    <%  } %>
    ]
    </p>

<%  } %>

Matt Tucker's avatar
Matt Tucker committed
287
<br>
Matt Tucker's avatar
Matt Tucker committed
288
<p>
Matt Tucker's avatar
Matt Tucker committed
289
<fmt:message key="session.summary.last_update" />: <%= JiveGlobals.formatDateTime(new Date()) %>
Matt Tucker's avatar
Matt Tucker committed
290 291
</p>

292
    </body>
Sven Tantau's avatar
Sven Tantau committed
293
</html>