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

21
<%@ page import="org.jivesoftware.openfire.SessionManager,
22 23
                 org.jivesoftware.openfire.session.ComponentSession,
                 org.jivesoftware.openfire.session.Session,
24
                 org.jivesoftware.util.JiveGlobals,
Sven Tantau's avatar
Sven Tantau committed
25
                 org.jivesoftware.util.StringUtils,
26
                 org.jivesoftware.util.ParamUtils,
27
                 java.net.URLEncoder"
Gaston Dombiak's avatar
Gaston Dombiak committed
28 29
    errorPage="error.jsp"
%>
30 31 32 33
<%@ page import="java.util.ArrayList"%>
<%@ page import="java.util.Calendar"%>
<%@ page import="java.util.Collection"%>
<%@ page import="java.util.Date"%>
Gaston Dombiak's avatar
Gaston Dombiak committed
34

35 36
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
37 38 39 40 41
<%!
    final int DEFAULT_RANGE = 15;
    final int[] RANGE_PRESETS = {15, 25, 50, 75, 100};
%>

Gaston Dombiak's avatar
Gaston Dombiak committed
42 43 44
<jsp:useBean id="admin" class="org.jivesoftware.util.WebManager"  />
<% admin.init(request, response, session, application, out ); %>

45 46 47 48 49 50
<% // Get parameters
    int start = ParamUtils.getIntParameter(request, "start", 0);
    int range = ParamUtils
            .getIntParameter(request, "range", admin.getRowsPerPage("component-session-summary", DEFAULT_RANGE));
    boolean close = ParamUtils.getBooleanParameter(request, "close");
    String jid = ParamUtils.getParameter(request, "jid");
Gaston Dombiak's avatar
Gaston Dombiak committed
51

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

56
    // Get the session manager
Gaston Dombiak's avatar
Gaston Dombiak committed
57 58
    SessionManager sessionManager = admin.getSessionManager();

59 60
    Collection<ComponentSession> sessions = sessionManager.getComponentSessions();

Gaston Dombiak's avatar
Gaston Dombiak committed
61
    // Get the session count
62
    int sessionCount = sessions.size();
Gaston Dombiak's avatar
Gaston Dombiak committed
63

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

89 90 91 92 93 94
<html>
    <head>
        <title><fmt:message key="component.session.summary.title"/></title>
        <meta name="pageID" content="component-session-summary"/>
    </head>
    <body>
Gaston Dombiak's avatar
Gaston Dombiak committed
95

96 97 98 99 100 101 102 103
<%  if ("success".equals(request.getParameter("close"))) { %>

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

<%  } %>

104
<p>
105 106 107 108 109 110 111 112 113 114
<fmt:message key="component.session.summary.active" />: <b><%= sessions.size() %></b>

<%  if (numPages > 1) { %>

    - <fmt:message key="global.showing" /> <%= (start+1) %>-<%= (start+range) %>

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

115
    <% for (int aRANGE_PRESETS : RANGE_PRESETS) { %>
116

117 118 119
    <option value="<%= aRANGE_PRESETS %>"
            <%= (aRANGE_PRESETS == range ? "selected" : "") %>><%= aRANGE_PRESETS %>
    </option>
120

121
    <% } %>
122 123

</select>
124
</p>
125 126 127 128

<%  if (numPages > 1) { %>

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

    <%  } %>
    ]
    </p>

<%  } %>

<p>
146
<fmt:message key="component.session.summary.info">
147
    <fmt:param value="<a href=\"connection-settings-external-components.jsp\">" />
148
    <fmt:param value="</a>" />
149
</fmt:message>
150 151 152 153 154 155 156 157
</p>

<div class="jive-table">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<thead>
    <tr>
        <th>&nbsp;</th>
        <th nowrap><fmt:message key="component.session.label.domain" /></th>
158
        <th>&nbsp;</th>
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
        <th nowrap><fmt:message key="component.session.label.name" /></th>
        <th nowrap><fmt:message key="component.session.label.category" /></th>
        <th nowrap><fmt:message key="component.session.label.type" /></th>
        <th nowrap><fmt:message key="component.session.label.creation" /></th>
        <th nowrap><fmt:message key="component.session.label.last_active" /></th>
        <th nowrap><fmt:message key="component.session.label.close_connect" /></th>
    </tr>
</thead>
<tbody>
    <%  // Check if no out/in connection to/from a remote server exists
        if (sessions.isEmpty()) {
    %>
        <tr>
            <td colspan="9">

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

            </td>
        </tr>

    <%  } %>

    <%  int count = 0;
        sessions = new ArrayList<ComponentSession>(sessions).subList(start, maxIndex);
        for (ComponentSession componentSession : sessions) {
            count++;
    %>
    <tr class="jive-<%= (((count % 2) == 0) ? "even" : "odd") %>">
        <td width="1%" nowrap><%= count %></td>
        <td width="43%" nowrap>
            <a href="component-session-details.jsp?jid=<%= URLEncoder.encode(componentSession.getAddress().toString(), "UTF-8") %>" title="<fmt:message key="session.row.cliked" />"><%= componentSession.getAddress() %></a>
        </td>
191 192 193 194 195 196 197 198 199 200 201 202
        <td width="1%">
            <%  if (componentSession.isSecure()) {
                if (componentSession.getPeerCertificates() != null && componentSession.getPeerCertificates().length > 0) { %>
            <img src="images/lock_both.gif" width="16" height="16" border="0" title="<fmt:message key='session.row.cliked_ssl' /> (mutual authentication)" alt="<fmt:message key='session.row.cliked_ssl' /> (mutual authentication)">
            <%      } else { %>
            <img src="images/lock.gif" width="16" height="16" border="0" title="<fmt:message key='session.row.cliked_ssl' />" alt="<fmt:message key='session.row.cliked_ssl' />">
            <%      }
            } else { %>
            <img src="images/blank.gif" width="1" height="1" alt="">
            <%     } %>
        </td>
        <td width="15%" nowrap>
Sven Tantau's avatar
Sven Tantau committed
203
            <%= StringUtils.escapeHTMLTags(componentSession.getExternalComponent().getName()) %>
204
        </td>
205
        <td width="10%" nowrap>
Sven Tantau's avatar
Sven Tantau committed
206
            <%= StringUtils.escapeHTMLTags(componentSession.getExternalComponent().getCategory()) %>
207
        </td>
208
        <td width="10%" nowrap>
Gaston Dombiak's avatar
Gaston Dombiak committed
209 210
            <table border="0">
            <tr valign="center">
211 212
            <% if ("gateway".equals(componentSession.getExternalComponent().getCategory())) {
                if ("msn".equals(componentSession.getExternalComponent().getType())) { %>
Gaston Dombiak's avatar
Gaston Dombiak committed
213
                <td><img src="images/msn.gif" width="16" height="16" border="0" alt="MSN"></td>
214 215
             <% }
                else if ("aim".equals(componentSession.getExternalComponent().getType())) { %>
Gaston Dombiak's avatar
Gaston Dombiak committed
216
                <td><img src="images/aim.gif" width="16" height="16" border="0" alt="AIM"></td>
217 218
             <% }
                else if ("yahoo".equals(componentSession.getExternalComponent().getType())) { %>
Gaston Dombiak's avatar
Gaston Dombiak committed
219
                <td><img src="images/yahoo.gif" width="22" height="16" border="0" alt="Yahoo!"></td>
220 221
             <% }
                else if ("icq".equals(componentSession.getExternalComponent().getType())) { %>
Gaston Dombiak's avatar
Gaston Dombiak committed
222
                <td><img src="images/icq.gif" width="16" height="16" border="0" alt="ICQ"></td>
223 224
             <% }
                else if ("irc".equals(componentSession.getExternalComponent().getType())) { %>
Gaston Dombiak's avatar
Gaston Dombiak committed
225
                <td><img src="images/irc.gif" width="16" height="16" border="0" alt="IRC"></td>
Matt Tucker's avatar
Matt Tucker committed
226 227
             <% }
               }
228
            %>
Sven Tantau's avatar
Sven Tantau committed
229
            <td><%= StringUtils.escapeHTMLTags(componentSession.getExternalComponent().getType()) %></td>
Gaston Dombiak's avatar
Gaston Dombiak committed
230
            </tr></table>
231 232 233 234 235 236 237 238 239 240 241 242 243 244
        </td>
        <%  Date creationDate = componentSession.getCreationDate();
            Calendar creationCal = Calendar.getInstance();
            creationCal.setTime(creationDate);

            Date lastActiveDate = componentSession.getLastActiveDate();
            Calendar lastActiveCal = Calendar.getInstance();
            lastActiveCal.setTime(lastActiveDate);

            Calendar nowCal = Calendar.getInstance();

            boolean sameCreationDay = nowCal.get(Calendar.DAY_OF_YEAR) == creationCal.get(Calendar.DAY_OF_YEAR) && nowCal.get(Calendar.YEAR) == creationCal.get(Calendar.YEAR);
            boolean sameActiveDay = nowCal.get(Calendar.DAY_OF_YEAR) == lastActiveCal.get(Calendar.DAY_OF_YEAR) && nowCal.get(Calendar.YEAR) == lastActiveCal.get(Calendar.YEAR);
        %>
245
        <td width="9%" nowrap>
246 247
            <%= sameCreationDay ? JiveGlobals.formatTime(creationDate) : JiveGlobals.formatDateTime(creationDate) %>
        </td>
248
        <td width="9%" nowrap>
249 250 251 252 253 254 255
            <%= sameActiveDay ? JiveGlobals.formatTime(lastActiveDate) : JiveGlobals.formatDateTime(lastActiveDate) %>
        </td>

        <td width="1%" nowrap align="center" style="border-right:1px #ccc solid;">
            <a href="component-session-summary.jsp?jid=<%= URLEncoder.encode(componentSession.getAddress().toString(), "UTF-8") %>&close=true"
             title="<fmt:message key="session.row.cliked_kill_session" />"
             onclick="return confirm('<fmt:message key="session.row.confirm_close" />');"
256
             ><img src="images/delete-16x16.gif" width="16" height="16" border="0" alt=""></a>
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
        </td>
    </tr>
    <%  } %>

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

<%  if (numPages > 1) { %>

    <p>
    <fmt:message key="global.pages" />:
    [
    <%  for (int i=0; i<numPages; i++) {
            String sep = ((i+1)<numPages) ? " " : "";
            boolean isCurrent = (i+1) == curPage;
    %>
        <a href="component-session-summary.jsp?start=<%= (i*range) %>"
         class="<%= ((isCurrent) ? "jive-current" : "") %>"
         ><%= (i+1) %></a><%= sep %>

    <%  } %>
    ]
    </p>

<%  } %>

<br>
<p>
<fmt:message key="component.session.summary.last_update" />: <%= JiveGlobals.formatDateTime(new Date()) %>
</p>
Gaston Dombiak's avatar
Gaston Dombiak committed
288

289
    </body>
Sven Tantau's avatar
Sven Tantau committed
290
</html>