session-summary.jsp 8.59 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-2005 Jive Software. All rights reserved.
Bill Lynch's avatar
Bill Lynch committed
6 7 8
  -
  - This software is published under the terms of the GNU Public License (GPL),
  - a copy of which is included in this distribution.
Matt Tucker's avatar
Matt Tucker committed
9 10
--%>

11
<%@ page import="org.jivesoftware.openfire.SessionManager,
12 13
                 org.jivesoftware.openfire.SessionResultFilter,
                 org.jivesoftware.openfire.session.ClientSession,
14 15
                 org.jivesoftware.util.JiveGlobals,
                 org.jivesoftware.util.ParamUtils,
16
                 java.util.Collection"
Bill Lynch's avatar
Bill Lynch committed
17 18
    errorPage="error.jsp"
%>
19
<%@ page import="java.util.Date" %>
Matt Tucker's avatar
Matt Tucker committed
20

21
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
22
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
23 24 25 26 27 28
<%!
    static final String NONE = LocaleUtils.getLocalizedString("global.none");

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

29 30
    static final int[] REFRESHES = {0, 10, 30, 60, 90};
    static final String[] REFRESHES_LABELS = {NONE,"10","30","60","90"};
31
%>
32 33
<jsp:useBean id="webManager" class="org.jivesoftware.util.WebManager"  />
<% webManager.init(request, response, session, application, out ); %>
Matt Tucker's avatar
Matt Tucker committed
34 35 36

<%  // Get parameters
    int start = ParamUtils.getIntParameter(request,"start",0);
37 38
    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
39
    boolean close = ParamUtils.getBooleanParameter(request,"close");
40 41
    int order = ParamUtils.getIntParameter(request, "order",
            webManager.getPageProperty("session-summary", "console.order", SessionResultFilter.ASCENDING));
Matt Tucker's avatar
Matt Tucker committed
42 43
    String jid = ParamUtils.getParameter(request,"jid");

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

48
    if (request.getParameter("refresh") != null) {
49
        webManager.setRefreshValue("session-summary", refresh);
50 51
    }

52 53 54 55
    if (request.getParameter("order") != null) {
        webManager.setPageProperty("session-summary", "console.order", order);
    }

Matt Tucker's avatar
Matt Tucker committed
56
    // Get the user manager
57
    SessionManager sessionManager = webManager.getSessionManager();
Matt Tucker's avatar
Matt Tucker committed
58 59

    // Get the session count
Gaston Dombiak's avatar
Gaston Dombiak committed
60
    int sessionCount = sessionManager.getUserSessionsCount(false);
Matt Tucker's avatar
Matt Tucker committed
61 62 63

    // Close a connection if requested
    if (close) {
Derek DeMoro's avatar
Derek DeMoro committed
64
        JID address = new JID(jid);
Matt Tucker's avatar
Matt Tucker committed
65 66
        try {
            Session sess = sessionManager.getSession(address);
67
            sess.close();
Matt Tucker's avatar
Matt Tucker committed
68 69 70 71 72 73
            // wait one second
            Thread.sleep(1000L);
        }
        catch (Exception ignored) {
            // Session might have disappeared on its own
        }
74
        // Redirect back to this page
Matt Tucker's avatar
Matt Tucker committed
75 76 77 78 79 80 81 82
        response.sendRedirect("session-summary.jsp?close=success");
        return;
    }

    // paginator vars
    int numPages = (int)Math.ceil((double)sessionCount/(double)range);
    int curPage = (start/range) + 1;
%>
Bill Lynch's avatar
Bill Lynch committed
83

84 85 86 87 88 89 90
<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
91

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

94 95
    <p class="jive-success-text">
    <fmt:message key="session.summary.close" />
Matt Tucker's avatar
Matt Tucker committed
96 97 98 99
    </p>

<%  } %>

100 101 102 103
<%  if (refresh > 0) { %>
    <meta http-equiv="refresh" content="<%= refresh %>">
<%  } %>

104 105 106 107 108 109 110 111 112
<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) { %>

113
                -- <fmt:message key="global.showing" /> <%= (start+1) %>-<%= (start+range) %>
114 115 116 117 118 119

            <%  } %>

            <%  if (numPages > 1) { %>

                <p>
120
                <fmt:message key="global.pages" />:
121 122 123 124 125 126 127 128 129 130 131 132 133
                [
                <%  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 %>

                <%  } %>
                ]

            <%  } %>
134
            -- <fmt:message key="session.summary.sessions_per_page" />:
135 136 137 138 139 140 141 142 143 144 145 146 147 148
            <select size="1" name="range" onchange="this.form.submit();">

                <%  for (int i=0; i<RANGE_PRESETS.length; i++) { %>

                    <option value="<%= RANGE_PRESETS[i] %>"<%= (RANGE_PRESETS[i] == range ? "selected" : "") %>><%= RANGE_PRESETS[i] %></option>

                <%  } %>

            </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++) {
149
                    String selected = REFRESHES[j] == refresh ? " selected" : "";
150
            %>
151
                <option value="<%= REFRESHES[j] %>"<%= selected %>><%= REFRESHES_LABELS[j] %>
152 153 154 155 156 157 158 159 160 161 162

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

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

164 165 166 167 168
 <% // 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);
169
     Collection<ClientSession> sessions = sessionManager.getSessions(filter);
170
 %>
171

Bill Lynch's avatar
Bill Lynch committed
172 173 174
<div class="jive-table">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<thead>
Matt Tucker's avatar
Matt Tucker committed
175
    <tr>
Bill Lynch's avatar
Bill Lynch committed
176
        <th>&nbsp;</th>
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
        <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>
        </th></tr></table></div>
        <%
                }
                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>
        </th></tr></table></div>
        <%
                }
            }
            else {
        %>
            <fmt:message key="session.details.name" />
        <%
            }
        %>
        </th>
Bill Lynch's avatar
Bill Lynch committed
210
        <th nowrap><fmt:message key="session.details.resource" /></th>
211 212
        <th nowrap colspan="2"><fmt:message key="session.details.status" /></th>
        <th nowrap colspan="2"><fmt:message key="session.details.presence" /></th>
213
        <th nowrap><fmt:message key="session.details.priority" /></th>
214 215
        <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
216 217 218
    </tr>
</thead>
<tbody>
219
    <%
Matt Tucker's avatar
Matt Tucker committed
220
        if (sessions.isEmpty()) {
Bill Lynch's avatar
Bill Lynch committed
221 222
    %>
        <tr>
223
            <td colspan="10">
Matt Tucker's avatar
Matt Tucker committed
224

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

Bill Lynch's avatar
Bill Lynch committed
227 228
            </td>
        </tr>
Matt Tucker's avatar
Matt Tucker committed
229

Bill Lynch's avatar
Bill Lynch committed
230
    <%  } %>
Matt Tucker's avatar
Matt Tucker committed
231

Bill Lynch's avatar
Bill Lynch committed
232 233 234
    <%  int count = start;
        boolean current = false; // needed in session-row.jspf
        String linkURL = "session-details.jsp";
235
        for (ClientSession sess : sessions) {
Bill Lynch's avatar
Bill Lynch committed
236 237 238 239
            count++;
    %>
        <%@ include file="session-row.jspf" %>
    <%  } %>
Matt Tucker's avatar
Matt Tucker committed
240

Bill Lynch's avatar
Bill Lynch committed
241
</tbody>
Matt Tucker's avatar
Matt Tucker committed
242 243 244 245 246 247
</table>
</div>

<%  if (numPages > 1) { %>

    <p>
248
    <fmt:message key="global.pages" />:
Matt Tucker's avatar
Matt Tucker committed
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
    [
    <%  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
264
<br>
Matt Tucker's avatar
Matt Tucker committed
265
<p>
Matt Tucker's avatar
Matt Tucker committed
266
<fmt:message key="session.summary.last_update" />: <%= JiveGlobals.formatDateTime(new Date()) %>
Matt Tucker's avatar
Matt Tucker committed
267 268
</p>

269 270
    </body>
</html>