available-plugins.jsp 18.9 KB
Newer Older
Gaston Dombiak's avatar
Gaston Dombiak committed
1 2 3 4 5 6 7
<%--
  - Copyright (C) 2006 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.
--%>

8 9
<%@ page errorPage="error.jsp" import="org.jivesoftware.util.ByteFormat,
                                       org.jivesoftware.util.Version,
10 11
                                       org.jivesoftware.openfire.XMPPServer,
                                       org.jivesoftware.openfire.container.Plugin"
12
    %>
13 14 15
<%@ page import="org.jivesoftware.openfire.container.PluginManager" %>
<%@ page import="org.jivesoftware.openfire.update.AvailablePlugin" %>
<%@ page import="org.jivesoftware.openfire.update.UpdateManager" %>
16 17 18 19
<%@ page import="java.io.File" %>
<%@ page import="java.net.URLEncoder" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Collections" %>
20
<%@ page import="java.util.Comparator" %>
21 22 23 24
<%@ page import="java.util.List" %>
<%@ page import="org.jivesoftware.util.JiveGlobals"%>
<%@ page import="java.util.Date"%>
<%@ page import="java.text.SimpleDateFormat"%>
25
<%@ page import="org.jivesoftware.util.WebManager"%><%@ page import="org.jivesoftware.util.LocaleUtils"%>
Gaston Dombiak's avatar
Gaston Dombiak committed
26 27 28 29

<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>

Derek DeMoro's avatar
Derek DeMoro committed
30 31 32
<%
    WebManager webManager = new WebManager();
%>
Gaston Dombiak's avatar
Gaston Dombiak committed
33 34 35 36 37 38

<%
    boolean downloadRequested = request.getParameter("download") != null;
    String url = request.getParameter("url");

    UpdateManager updateManager = XMPPServer.getInstance().getUpdateManager();
39 40
    List<AvailablePlugin> plugins = updateManager.getNotInstalledPlugins();

41
    String time = JiveGlobals.getProperty("update.lastCheck");
42
    // Sort plugins alphabetically
43 44 45
    Collections.sort(plugins, new Comparator<AvailablePlugin>() {
        public int compare(AvailablePlugin o1, AvailablePlugin o2) {
            return o1.getName().compareTo(o2.getName());
46 47
        }
    });
Gaston Dombiak's avatar
Gaston Dombiak committed
48 49 50 51 52 53 54 55 56

    if (downloadRequested) {
        // Download and install new plugin
        updateManager.downloadPlugin(url);
    }

%>

<html>
57 58 59
<head>
<title><fmt:message key="plugin.available.title"/></title>
<meta name="pageID" content="available-plugins"/>
60 61 62 63

<style type="text/css">

.light-gray-border {
64
    border-color: #ccc;
65 66 67
    border-style: solid;
    border-width: 1px 1px 1px 1px;
    padding: 5px;
68
	-moz-border-radius: 3px;
69 70
}

Derek DeMoro's avatar
Derek DeMoro committed
71

72 73 74 75 76 77

.table-header {
    text-align: left;
    font-family: verdana, arial, helvetica, sans-serif;
    font-size: 8pt;
    font-weight: bold;
78
    border-color: #ccc;
79 80 81 82 83
    border-style: solid;
    border-width: 1px 0px 1px 0px;
    padding: 5px;
}

84 85 86 87 88
.table-header-align-right {
    text-align: right;
    font-family: verdana, arial, helvetica, sans-serif;
    font-size: 8pt;
    font-weight: bold;
89
    border-color: #ccc;
90 91 92 93 94
    border-style: solid;
    border-width: 1px 0px 1px 0px;
    padding: 5px;
}

95 96 97 98 99
.row-header {
    text-align: left;
    font-family: verdana, arial, helvetica, sans-serif;
    font-size: 8pt;
    font-weight: bold;
100
    border-color: #ccc;
101 102 103 104 105 106 107 108 109 110
    border-style: solid;
    border-width: 1px 1px 1px 0px;
    padding: 5px;
}

.table-header-left {
    text-align: left;
    font-family: verdana, arial, helvetica, sans-serif;
    font-size: 8pt;
    font-weight: bold;
111
    border-color: #ccc;
112 113 114 115 116 117 118 119 120 121 122
    border-style: solid;
    border-width: 1px 0px 1px 1px;
    padding: 5px;

}

.table-header-right {
    text-align: left;
    font-family: verdana, arial, helvetica, sans-serif;
    font-size: 8pt;
    font-weight: bold;
123
    border-color: #ccc;
124 125 126 127 128 129 130 131
    border-style: solid;
    border-width: 1px 1px 1px 0px;
    padding: 5px;
}

.line-bottom-border {
    font-family: verdana, arial, helvetica, sans-serif;
    font-size: 9pt;
132
    border-color: #e3e3e3;
133 134 135 136 137 138 139 140
    border-style: solid;
    border-width: 0px 0px 1px 0px;
    padding: 5px;
}


</style>

141
<script src="dwr/engine.js" type="text/javascript"></script>
142 143
<script src="dwr/util.js" type="text/javascript"></script>
<script src="dwr/interface/downloader.js" type="text/javascript"></script>
144
<script type="text/javascript">
145 146

    var downloading;
147
    function downloadPlugin(url, id) {
148
        downloading = true;
149
        document.getElementById(id + "-image").innerHTML = '<img src="images/working-16x16.gif" border="0"/>';
Derek DeMoro's avatar
Derek DeMoro committed
150
        document.getElementById(id).style.background = "#FFFFCC";
151 152 153 154 155
        setTimeout("startDownload('" + url + "','" + id + "')", 5000);
    }

    function startDownload(url, id) {
        downloader.installPlugin(downloadComplete, url, id);
156 157
    }

158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
    function downloadComplete(status) {
        downloading = false;
        if (!status.successfull) {
            document.getElementById(status.hashCode + "-image").innerHTML = '<img src="images/add-16x16.gif" border="0"/>';
            document.getElementById(status.hashCode).style.background = "#FFFFFF";
            document.getElementById("errorMessage").style.display = '';
            document.getElementById(status.hashCode).style.display = '';
            document.getElementById(status.hashCode + "-row").style.display = 'none';
            setTimeout("closeErrorMessage()", 5000);
        }
        else {
            document.getElementById(status.hashCode).style.display = 'none';
            document.getElementById(status.hashCode + "-row").style.display = '';
            setTimeout("fadeIt('" + status.hashCode + "')", 3000);
        }
173 174
    }

175 176
    function closeErrorMessage(){
        Effect.Fade("errorMessage");
177 178 179 180 181
    }

    function fadeIt(id) {
        Effect.Fade(id + "-row");
    }
182 183


184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
    DWREngine.setErrorHandler(handleError);

    function handleError(error) {
    }

    // Handle leaving of page validation.
    window.onbeforeunload = function (evt) {
        if (!downloading) {
            return;
        }
        var message = '<fmt:message key="plugin.available.cancel.redirect" />';
        if (typeof evt == 'undefined') {
            evt = window.event;
        }
        if (evt) {
            evt.returnValue = message;
        }
        return message;
    }
203

Derek DeMoro's avatar
Derek DeMoro committed
204 205 206 207 208 209 210 211 212 213 214 215 216 217
    function updatePluginsList(){
        document.getElementById("reloaderID").innerHTML = '<img src="images/working-16x16.gif" border="0"/>';
        downloader.updatePluginsList(pluginsListUpdated);
    }

    function updatePluginsListNow(){
        document.getElementById("reloader2").innerHTML = '<img src="images/working-16x16.gif" border="0"/>';
        downloader.updatePluginsList(pluginsListUpdated);
    }

    function pluginsListUpdated(){
        window.location.href = "available-plugins.jsp";
    }

218

219 220 221 222
</script>
</head>

<body>
Gaston Dombiak's avatar
Gaston Dombiak committed
223 224

<p>
225
    <fmt:message key="plugin.available.info"/>
Gaston Dombiak's avatar
Gaston Dombiak committed
226
</p>
227

Gaston Dombiak's avatar
Gaston Dombiak committed
228 229
<p>

230
<%if(time == null){ %>
231
<div style="padding:10px;background:#FFEBB5;border:1px solid #DEB24A;width:75%;">
Derek DeMoro's avatar
Derek DeMoro committed
232
    <fmt:message key="plugin.available.no.list" />&nbsp;<span id="reloaderID"><a href="javascript:updatePluginsList();"><fmt:message key="plugin.available.list" /></a></span>
233 234
</div>
<br/>
235
<div style="width:75%;">
236 237 238 239 240 241 242 243 244 245 246
    <p>
   <fmt:message key="plugin.available.no.list.description" />
</p>

<% if(!updateManager.isServiceEnabled()){ %>
<fmt:message key="plugin.available.auto.update.currently" /> <b><fmt:message key="plugin.available.auto.update.currently.disabled" /></b>. <a href="manage-updates.jsp"><fmt:message key="plugin.available.click.here" /></a> <fmt:message key="plugin.available.change" />
<% } %>
</div>
<% } else {%>


247 248 249
<div id="errorMessage" class="error" style="display:none;">
    <fmt:message key="plugin.available.error.downloading" />
</div>
250 251


252
<div class="light-gray-border" style="padding:10px;">
Gaston Dombiak's avatar
Gaston Dombiak committed
253 254
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<thead>
255
    <tr style="background:#eee;">
256
        <td class="table-header-left">&nbsp;</td>
Derek DeMoro's avatar
Derek DeMoro committed
257
        <td nowrap colspan="2" class="table-header"><fmt:message key="plugin.available.open_source"/></td>
258 259 260 261 262
        <td nowrap class="table-header"><fmt:message key="plugin.available.description"/></td>
        <td nowrap class="table-header"><fmt:message key="plugin.available.version"/></td>
        <td nowrap class="table-header"><fmt:message key="plugin.available.author"/></td>
        <td nowrap class="table-header">File Size</td>
        <td nowrap class="table-header-right"><fmt:message key="plugin.available.install"/></td>
Gaston Dombiak's avatar
Gaston Dombiak committed
263 264 265 266 267
    </tr>
</thead>
<tbody>

<%
268
    // If only the admin plugin is installed, show "none".
Gaston Dombiak's avatar
Gaston Dombiak committed
269 270
    if (plugins.isEmpty()) {
%>
271 272 273
<tr>
    <td align="center" colspan="8"><fmt:message key="plugin.available.no_plugin"/></td>
</tr>
Gaston Dombiak's avatar
Gaston Dombiak committed
274 275 276 277 278 279 280 281
<%
    }

    for (AvailablePlugin plugin : plugins) {
        String pluginName = plugin.getName();
        String pluginDescription = plugin.getDescription();
        String pluginAuthor = plugin.getAuthor();
        String pluginVersion = plugin.getLatestVersion();
282 283 284 285 286 287
        ByteFormat byteFormat = new ByteFormat();
        String fileSize = byteFormat.format(plugin.getFileSize());

        if (plugin.isCommercial()) {
            continue;
        }
Gaston Dombiak's avatar
Gaston Dombiak committed
288
%>
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
<tr id="<%= plugin.hashCode()%>">
    <td width="1%" class="line-bottom-border">
        <% if (plugin.getIcon() != null) { %>
        <img src="<%= plugin.getIcon() %>" width="16" height="16" alt="Plugin">
        <% }
        else { %>
        <img src="images/plugin-16x16.gif" width="16" height="16" alt="Plugin">
        <% } %>
    </td>
    <td width="20%" nowrap class="line-bottom-border">
        <%= (pluginName != null ? pluginName : "") %> &nbsp;
    </td>
    <td nowrap valign="top" class="line-bottom-border">
        <% if (plugin.getReadme() != null) { %>
        <a href="<%= plugin.getReadme() %>"
            ><img src="images/doc-readme-16x16.gif" width="16" height="16" border="0" alt="README"></a>
        <% }
        else { %> &nbsp; <% } %>
        <% if (plugin.getChangelog() != null) { %>
        <a href="<%= plugin.getChangelog() %>"
            ><img src="images/doc-changelog-16x16.gif" width="16" height="16" border="0" alt="changelog"></a>
        <% }
        else { %> &nbsp; <% } %>
    </td>
    <td width="60%" class="line-bottom-border">
        <%= pluginDescription != null ? pluginDescription : "" %>
    </td>
    <td width="5%" align="center" valign="top" class="line-bottom-border">
        <%= pluginVersion != null ? pluginVersion : "" %>
    </td>
    <td width="15%" nowrap valign="top" class="line-bottom-border">
        <%= pluginAuthor != null ? pluginAuthor : "" %>  &nbsp;
    </td>
322
    <td width="15%" nowrap valign="top" class="line-bottom-border" align="right">
323 324 325 326 327 328 329 330 331 332 333 334 335
        <%= fileSize %>
    </td>
    <td width="1%" align="center" valign="top" class="line-bottom-border">
        <%
            String updateURL = plugin.getURL();
            if (updateManager.isPluginDownloaded(updateURL)) {
        %>
        &nbsp;
        <%  }
        else { %>
        <%

        %>
336 337
        <a href="javascript:downloadPlugin('<%=updateURL%>', '<%= plugin.hashCode()%>')"><span id="<%= plugin.hashCode() %>-image"><img src="images/add-16x16.gif" width="16" height="16" border="0"
                                                                                                                                        alt="<fmt:message key="plugin.available.download" />"></span></a>
338 339 340 341

        <% } %>
    </td>
</tr>
342
<tr id="<%= plugin.hashCode()%>-row" style="display:none;background: #E7FBDE;">
343 344 345
    <td width="1%" class="line-bottom-border">
        <img src="<%= plugin.getIcon()%>" width="16" height="16"/>
    </td>
346
    <td colspan="6" nowrap class="line-bottom-border"><%= plugin.getName()%> <fmt:message key="plugin.available.installation.success" /></td>
347 348 349 350
    <td class="line-bottom-border" align="center">
        <img src="images/success-16x16.gif" height="16" width="16"/>
    </td>
</tr>
351 352 353
<%
    }
%>
354
<tr><td><br/></td></tr>
355
<tr style="background:#f3f7fa;">
356
    <td class="table-header-left">&nbsp;</td>
Derek DeMoro's avatar
Derek DeMoro committed
357
    <td nowrap colspan="7" class="row-header"><fmt:message key="plugin.available.commercial_plugins" /></td>
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 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
</tr>
<%
    for (AvailablePlugin plugin : plugins) {
        String pluginName = plugin.getName();
        String pluginDescription = plugin.getDescription();
        String pluginAuthor = plugin.getAuthor();
        String pluginVersion = plugin.getLatestVersion();
        ByteFormat byteFormat = new ByteFormat();
        String fileSize = byteFormat.format(plugin.getFileSize());

        if (!plugin.isCommercial()) {
            continue;
        }
%>
<tr id="<%= plugin.hashCode()%>">
    <td width="1%" class="line-bottom-border">
        <% if (plugin.getIcon() != null) { %>
        <img src="<%= plugin.getIcon() %>" width="16" height="16" alt="Plugin">
        <% }
        else { %>
        <img src="images/plugin-16x16.gif" width="16" height="16" alt="Plugin">
        <% } %>
    </td>
    <td width="20%" nowrap class="line-bottom-border">
        <%= (pluginName != null ? pluginName : "") %> &nbsp;
    </td>
    <td nowrap valign="top" class="line-bottom-border">
        <% if (plugin.getReadme() != null) { %>
        <a href="<%= plugin.getReadme() %>"
            ><img src="images/doc-readme-16x16.gif" width="16" height="16" border="0" alt="README"></a>
        <% }
        else { %> &nbsp; <% } %>
        <% if (plugin.getChangelog() != null) { %>
        <a href="<%= plugin.getChangelog() %>"
            ><img src="images/doc-changelog-16x16.gif" width="16" height="16" border="0" alt="changelog"></a>
        <% }
        else { %> &nbsp; <% } %>
    </td>
    <td width="60%" class="line-bottom-border">
        <%= pluginDescription != null ? pluginDescription : "" %>
    </td>
    <td width="5%" align="center" valign="top" class="line-bottom-border">
        <%= pluginVersion != null ? pluginVersion : "" %>
    </td>
    <td width="15%" nowrap valign="top" class="line-bottom-border">
        <%= pluginAuthor != null ? pluginAuthor : "" %>  &nbsp;
    </td>
    <td width="15%" nowrap valign="top" class="line-bottom-border">
        <%= fileSize  %>
    </td>
    <td width="1%" align="center" valign="top" class="line-bottom-border">
        <%
            String updateURL = plugin.getURL();
            if (updateManager.isPluginDownloaded(updateURL)) {
        %>
        &nbsp;
        <%  }
        else { %>

        <span id="<%= plugin.hashCode() %>-image"><a href="javascript:downloadPlugin('<%=updateURL%>', '<%= plugin.hashCode()%>')"><img src="images/add-16x16.gif" width="16" height="16" border="0"
                                                                                                                                        alt="<fmt:message key="plugin.available.download" />"></a></span>
        <% } %>
    </td>
</tr>
422 423
<tr id="<%= plugin.hashCode()%>-row" style="display:none;background: #E7FBDE;">
     <td width="1%" class="line-bottom-border">
424 425
        <img src="<%= plugin.getIcon()%>" width="16" height="16"/>
    </td>
426 427
    <td colspan="6" nowrap class="line-bottom-border"><%= plugin.getName()%> <fmt:message key="plugin.available.installation.success" /></td>
    <td class="line-bottom-border" align="center">
428 429 430
        <img src="images/success-16x16.gif" height="16" width="16"/>
    </td>
</tr>
431
<%
Gaston Dombiak's avatar
Gaston Dombiak committed
432 433
    }
%>
434

Gaston Dombiak's avatar
Gaston Dombiak committed
435 436
</tbody>
</table>
437

Gaston Dombiak's avatar
Gaston Dombiak committed
438 439
</div>

440 441 442 443 444 445 446 447
<br/>


<%
    final XMPPServer server = XMPPServer.getInstance();
    Version version = server.getServerInfo().getVersion();
    List<Plugin> outdatedPlugins = new ArrayList<Plugin>();
    for (Plugin plugin : server.getPluginManager().getPlugins()) {
448
        String pluginVersion = server.getPluginManager().getMinServerVersion(plugin);
449 450 451 452 453 454 455 456
        if (pluginVersion != null && pluginVersion.compareTo(version.getVersionString()) > 0) {
            outdatedPlugins.add(plugin);
        }
    }

    if (outdatedPlugins.size() > 0) {
%>
    <div class="light-gray-border" style="padding:10px;">
457
    <p><fmt:message key="plugin.available.outdated" /><a href="http://www.igniterealtime.org/projects/openfire/" target="_blank"><fmt:message key="plugin.available.outdated.update" /></a></p>
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
    <table cellpadding="0" cellspacing="0" border="0" width="100%">


        <%
            PluginManager pluginManager = server.getPluginManager();
            for (Plugin plugin : outdatedPlugins) {
                String pluginName = pluginManager.getName(plugin);
                String pluginDescription = pluginManager.getDescription(plugin);
                String pluginAuthor = pluginManager.getAuthor(plugin);
                String pluginVersion = pluginManager.getVersion(plugin);
                File pluginDir = pluginManager.getPluginDirectory(plugin);
                File icon = new File(pluginDir, "logo_small.png");
                boolean readmeExists = new File(pluginDir, "readme.html").exists();
                boolean changelogExists = new File(pluginDir, "changelog.html").exists();
                if (!icon.exists()) {
                    icon = new File(pluginDir, "logo_small.gif");
                }
        %>
        <tr>
            <td class="line-bottom-border" width="1%">
                <% if (icon.exists()) { %>
479
                <img src="/geticon?plugin=<%= URLEncoder.encode(pluginDir.getName(), "utf-8") %>&showIcon=true&decorator=none" width="16" height="16" alt="Plugin">
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516
                <% }
                else { %>
                <img src="images/plugin-16x16.gif" width="16" height="16" alt="Plugin">
                <% } %>
            </td>
            <td class="line-bottom-border" width="1%" nowrap>
                <%= pluginName%>
            </td>
            <td nowrap class="line-bottom-border">
                <p><% if (readmeExists) { %>
                    <a href="plugin-admin.jsp?plugin=<%= URLEncoder.encode(pluginDir.getName(), "utf-8") %>&showReadme=true&decorator=none"
                        ><img src="images/doc-readme-16x16.gif" width="16" height="16" border="0" alt="README"></a>
                    <% }
                    else { %> &nbsp; <% } %>
                    <% if (changelogExists) { %>
                    <a href="plugin-admin.jsp?plugin=<%= URLEncoder.encode(pluginDir.getName(), "utf-8") %>&showChangelog=true&decorator=none"
                        ><img src="images/doc-changelog-16x16.gif" width="16" height="16" border="0" alt="changelog"></a>
                    <% }
                    else { %> &nbsp; <% } %></p>
            </td>
            <td class="line-bottom-border">
                <%= pluginDescription %>
            </td>
            <td class="line-bottom-border">
                <%= pluginVersion%>
            </td>
            <td class="line-bottom-border">
                <%= pluginAuthor%>
            </td>
        </tr>
        <% }%>
  </table>

        <%} %>

</div>
<br/>
517
 <%
518
        if(time != null){
519 520
            Date date = new Date(Long.parseLong(time));
            time = JiveGlobals.formatDate(date);
521
        }
522 523
    %>
       <p>
524
           <% if(time != null) { %>
525
        <fmt:message key="plugin.available.autoupdate" /> <%= time%>.
526
           <% } %>
527
           <% if(updateManager.isServiceEnabled()){%>
528 529 530 531
              <fmt:message key="plugin.available.autoupdate.on" />
           <% } else { %>
                <fmt:message key="plugin.available.autoupdate.off" />
           <% } %>
Derek DeMoro's avatar
Derek DeMoro committed
532
           &nbsp;<span id="reloader2"><a href="javascript:updatePluginsListNow()"><fmt:message key="plugin.available.manual.update" /></a></span>
533 534
        </p>
           <% } %>
535

536
</body>
Gaston Dombiak's avatar
Gaston Dombiak committed
537
</html>