plugin-admin.jsp 21.2 KB
Newer Older
1
<%--
2
  - Copyright (C) 2005-2008 Jive Software. All rights reserved.
3
  -
4 5 6 7 8 9 10 11 12 13 14
  - 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.
15 16
--%>

17
<%@ page import="org.jivesoftware.util.ParamUtils,
18 19 20 21
                 org.jivesoftware.openfire.XMPPServer,
                 org.jivesoftware.openfire.container.Plugin,
                 org.jivesoftware.openfire.container.PluginManager,
                 org.jivesoftware.openfire.update.Update"
22
        %>
23
<%@ page import="org.jivesoftware.openfire.update.UpdateManager" %>
24 25 26 27 28
<%@ page import="java.net.URLEncoder" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Collections" %>
<%@ page import="java.util.Comparator" %>
<%@ page import="java.util.List" %>
29 30 31 32 33 34 35 36
<%@ page import="java.io.*" %>
<%@ page import="org.jivesoftware.util.JiveGlobals" %>
<%@ page import="org.jivesoftware.util.Log" %>
<%@ page import="org.apache.commons.fileupload.FileItemFactory" %>
<%@ page import="org.apache.commons.fileupload.disk.DiskFileItemFactory" %>
<%@ page import="org.apache.commons.fileupload.servlet.ServletFileUpload" %>
<%@ page import="org.apache.commons.fileupload.FileItem" %>
<%@ page import="org.apache.commons.fileupload.FileUploadException" %>
37

38 39
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
40

41 42 43
<jsp:useBean id="webManager" class="org.jivesoftware.util.WebManager"  />
<% webManager.init(request, response, session, application, out ); %>

44 45 46
<%
    String deletePlugin = ParamUtils.getParameter(request, "deleteplugin");
    String reloadPlugin = ParamUtils.getParameter(request, "reloadplugin");
47 48
    boolean showReadme = ParamUtils.getBooleanParameter(request, "showReadme", false);
    boolean showChangelog = ParamUtils.getBooleanParameter(request, "showChangelog", false);
49
    boolean downloadRequested = request.getParameter("download") != null;
50
    boolean uploadPlugin = request.getParameter("uploadplugin") != null;
51
    String url = request.getParameter("url");
52
    Boolean uploadEnabled = JiveGlobals.getBooleanProperty("plugins.upload.enabled", true);
53

54
    final PluginManager pluginManager = webManager.getXMPPServer().getPluginManager();
55 56 57

    List<Plugin> plugins = new ArrayList<Plugin>(pluginManager.getPlugins());

58 59
    UpdateManager updateManager = XMPPServer.getInstance().getUpdateManager();

60 61 62 63 64 65 66
    if (plugins != null) {
        Collections.sort(plugins, new Comparator<Plugin>() {
            public int compare(Plugin p1, Plugin p2) {
                return pluginManager.getName(p1).compareTo(pluginManager.getName(p2));
            }
        });
    }
67

68 69 70
    if (downloadRequested) {
        // Download and install new version of plugin
        updateManager.downloadPlugin(url);
71 72
        // Log the event
        webManager.logEvent("downloaded plugin from "+url, null);
73 74
    }

75 76
    if (deletePlugin != null) {
        File pluginDir = pluginManager.getPluginDirectory(pluginManager.getPlugin(deletePlugin));
77
        File pluginJar = new File(pluginDir.getParent(), pluginDir.getName() + ".jar");
78 79 80 81 82
        // Also try the .war extension.
        if (!pluginJar.exists()) {
            pluginJar = new File(pluginDir.getParent(), pluginDir.getName() + ".war");
        }
        pluginJar.delete();
83
        pluginManager.unloadPlugin(pluginDir.getName());
84 85
        // Log the event
        webManager.logEvent("deleted plugin "+deletePlugin, null);
86
        response.sendRedirect("plugin-admin.jsp?deletesuccess=true");
87
        return;
88 89 90 91
    }

    if (reloadPlugin != null) {
        for (Plugin plugin : plugins) {
92
            File pluginDir = pluginManager.getPluginDirectory(plugin);
93 94
            if (reloadPlugin.equals(pluginDir.getName())) {
                pluginManager.unloadPlugin(reloadPlugin);
95 96
                // Log the event
                webManager.logEvent("reloaded plugin "+reloadPlugin, null);
97
                response.sendRedirect("plugin-admin.jsp?reloadsuccess=true");
98
                return;
99 100 101
            }
        }
    }
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126

    if (uploadEnabled && uploadPlugin) {
        Boolean installed = false;

        // Create a factory for disk-based file items
        FileItemFactory factory = new DiskFileItemFactory();

        // Create a new file upload handler
        ServletFileUpload upload = new ServletFileUpload(factory);

        try {
            // Parse the request
            List items = upload.parseRequest(request);

            for (Object objItem : items) {
                FileItem item = (FileItem)objItem;
                String fileName = item.getName();
                if (fileName != null) {
                    InputStream is = item.getInputStream();
                    if (is != null) {
                        installed = XMPPServer.getInstance().getPluginManager().installPlugin(is, fileName);
                        if (!installed) {
                            Log.error("Plugin manager failed to install plugin: " + fileName);
                        }
                        is.close();
127 128
                        // Log the event
                        webManager.logEvent("uploaded plugin "+fileName, null);
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
                    }
                    else {
                        Log.error("Unable to open file stream for uploaded file: " + fileName);
                    }
                }
                else {
                    Log.error("No filename specified for file upload.");
                }
            }
        }
        catch (FileUploadException e) {
            Log.error("Unable to upload plugin file.", e);
        }
        if (installed) {
            response.sendRedirect("plugin-admin.jsp?uploadsuccess=true");
            return;
        } else {
            response.sendRedirect("plugin-admin.jsp?uploadsuccess=false");
            return;
        }
    }
150 151
%>

152
<% if (showReadme) {
153 154
    String pluginName = ParamUtils.getParameter(request, "plugin");
    Plugin plugin = pluginManager.getPlugin(pluginName);
155
    StringBuilder readmeString = new StringBuilder();
156 157 158 159 160
    if (plugin != null) {
        File readme = new File(pluginManager.getPluginDirectory(plugin), "readme.html");
        if (readme.exists()) {
            BufferedReader in = null;
            try {
161
                in = new BufferedReader(new InputStreamReader(new FileInputStream(readme), "UTF8"));
162 163
                String line;
                while ((line = in.readLine()) != null) {
164 165
                	readmeString.append(line);
                	readmeString.append(System.getProperty("line.separator"));
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
                    }
                }
                catch (IOException ioe) {
                    ioe.printStackTrace();
                }
                finally {
                    if (in != null) {
                        try {
                            in.close();
                        }
                        catch (Exception e) {
                        }
                    }
                }
            }
        }
182 183 184
%>
<%=readmeString%>
<%
185 186
        return;
    }
187 188
%>
<% if (showChangelog) {
189 190
    String pluginName = ParamUtils.getParameter(request, "plugin");
    Plugin plugin = pluginManager.getPlugin(pluginName);
191
    StringBuilder changelogString = new StringBuilder();
192 193 194 195 196
    if (plugin != null) {
        File changelog = new File(pluginManager.getPluginDirectory(plugin), "changelog.html");
        if (changelog.exists()) {
            BufferedReader in = null;
            try {
197
                in = new BufferedReader(new InputStreamReader(new FileInputStream(changelog), "UTF8"));
198 199
                String line;
                while ((line = in.readLine()) != null) {
200 201
                	changelogString.append(line);
                	changelogString.append(System.getProperty("line.separator"));
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
                    }
                }
                catch (IOException ioe) {

                }
                finally {
                    if (in != null) {
                        try {
                            in.close();
                        }
                        catch (Exception e) {
                        }
                    }
                }
            }
        }
218 219 220
%>
<%=changelogString%>
<%
221
        return;
222 223 224
    }
%>

225
<html>
226 227 228 229 230 231 232
<head>
<title><fmt:message key="plugin.admin.title"/></title>
<meta name="pageID" content="plugin-settings"/>
<meta name="helpPage" content="manage_system_plugins.html"/>
<script src="dwr/engine.js" type="text/javascript"></script>
<script src="dwr/util.js" type="text/javascript"></script>
<script src="dwr/interface/downloader.js" type="text/javascript"></script>
233

234 235
<script type="text/javascript" >
    DWREngine.setErrorHandler(handleError);
236

237 238
    function handleError(error) {
    }
239 240
</script>

241
<style type="text/css">
242

243 244 245 246 247 248
.textfield {
    font-size: 11px;
    font-family: verdana;
    padding: 3px 2px;
    background: #efefef;
}
249 250 251

.text {
    font-size: 11px;
252
    font-family: verdana, arial, helvetica, sans-serif;
253 254 255 256 257
}

.small-label {
    font-size: 11px;
    font-weight: bold;
258
    font-family: verdana, arial, helvetica, sans-serif;
259 260
}

261 262 263 264 265 266 267
.small-label-link {
    font-size: 11px;
    font-weight: bold;
    font-family: verdana;
    text-decoration: underline;
}

268
.light-gray-border {
269
    border-color: #ccc;
270 271 272
    border-style: solid;
    border-width: 1px 1px 1px 1px;
    padding: 5px;
273
	-moz-border-radius: 3px;
274 275
}

276 277 278 279 280 281
.light-gray-border-bottom {
    border-color: #dcdcdc;
    border-style: solid;
    border-width: 0px 0px 1px 0px;
}

282 283 284 285 286
.table-header {
    text-align: left;
    font-family: verdana, arial, helvetica, sans-serif;
    font-size: 8pt;
    font-weight: bold;
287
    border-color: #ccc;
288
    border-style: solid;
289
    border-width: 1px 0 1px 0;
290 291 292 293 294 295 296 297
    padding: 5px;
}

.table-header-left {
    text-align: left;
    font-family: verdana, arial, helvetica, sans-serif;
    font-size: 8pt;
    font-weight: bold;
298
    border-color: #ccc;
299
    border-style: solid;
300
    border-width: 1px 0 1px 1px;
301 302 303 304 305 306 307 308 309
    padding: 5px;

}

.table-header-right {
    text-align: left;
    font-family: verdana, arial, helvetica, sans-serif;
    font-size: 8pt;
    font-weight: bold;
310
    border-color: #ccc;
311
    border-style: solid;
312
    border-width: 1px 1px 1px 0;
313 314 315 316 317 318 319 320 321 322 323 324 325 326
    padding: 5px;
}

.table-font {
    font-family: verdana, arial, helvetica, sans-serif;
    font-size: 8pt;
}

.update {
    font-family: verdana, arial, helvetica, sans-serif;
    font-size: 8pt;
    background: #E7FBDE;
    border-color: #73CB73;
    border-style: solid;
327
    border-width: 0 1px 1px 1px;
328 329 330 331 332 333 334 335 336 337 338
    padding: 5px;
}

.update-bottom {
    text-align: left;
    font-family: verdana, arial, helvetica, sans-serif;
    font-size: 8pt;
    font-weight: bold;
    background: #E7FBDE;
    border-color: #73CB73;
    border-style: solid;
339
    border-width: 0 0 1px 0;
340 341 342 343 344 345 346 347 348 349 350
    padding: 5px;
}

.update-bottom-left {
    text-align: left;
    font-family: verdana, arial, helvetica, sans-serif;
    font-size: 8pt;
    font-weight: bold;
    background: #E7FBDE;
    border-color: #73CB73;
    border-style: solid;
351
    border-width: 0 0 1px 1px;
352 353 354 355 356 357 358 359 360 361 362
    padding: 5px;
}

.update-bottom-right {
    text-align: left;
    font-family: verdana, arial, helvetica, sans-serif;
    font-size: 8pt;
    font-weight: bold;
    background: #E7FBDE;
    border-color: #73CB73;
    border-style: solid;
363
    border-width: 0 1px 1px 0;
364 365
    padding: 5px;
}
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

.update-top {
    text-align: left;
    font-family: verdana, arial, helvetica, sans-serif;
    font-size: 9pt;
    background: #E7FBDE;
    border-color: #73CB73;
    border-style: solid;
    border-width: 1px 0px 0px 0px;
    padding: 5px;
}

.update-right {
    text-align: left;
    font-family: verdana, arial, helvetica, sans-serif;
    font-size: 8pt;
    font-weight: bold;
    background: #E7FBDE;
    border-color: #73CB73;
    border-style: solid;
    border-width: 1px 1px 0px 0px;
    padding: 5px;
}

.line-bottom-border {
    text-align: left;
    font-family: verdana, arial, helvetica, sans-serif;
    font-size: 9pt;
    border-color: #e3e3e3;
    border-style: solid;
    border-width: 0px 0px 1px 0px;
    padding: 5px;
}
399 400 401 402 403 404 405 406 407 408 409 410 411
</style>


<script type="text/javascript">
    function download(url, hashCode) {
        document.getElementById(hashCode + "-row").style.display = 'none';
        document.getElementById(hashCode + "-update").style.display = '';
        downloader.downloadPlugin(downloadComplete, url);
    }

    function downloadComplete(update) {
        document.getElementById(update.hashCode + "-row").style.display = 'none';
        document.getElementById(update.hashCode + "-update").style.display = '';
412
        document.getElementById(update.hashCode + "-image").innerHTML = '<img src="images/success-16x16.gif" border="0" alt=""/>';
Derek DeMoro's avatar
Derek DeMoro committed
413
        document.getElementById(update.hashCode + "-text").innerHTML = '<fmt:message key="plugin.admin.update.complete" />';
414 415 416 417 418
    }
</script>
</head>

<body>
419 420 421

<% if ("true".equals(request.getParameter("deletesuccess"))) { %>

422 423
<div class="success">
   <fmt:message key="plugin.admin.deleted_success"/>
424 425
</div>
<br>
426

427 428
<% }
else if ("false".equals(request.getParameter("deletesuccess"))) { %>
429

430 431
<div class="error">
    <fmt:message key="plugin.admin.deleted_failure"/>
432 433
</div>
<br>
434 435 436

<% } %>

437
<% if ("true".equals(request.getParameter("reloadsuccess"))) { %>
438

439
<div class="success">
Derek DeMoro's avatar
Derek DeMoro committed
440
   <fmt:message key="plugin.admin.reload_success"/>
441 442
</div>
<br>
443 444 445

<% } %>

446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462
<% if ("true".equals(request.getParameter("uploadsuccess"))) { %>

<div class="success">
   <fmt:message key="plugin.admin.uploaded_success"/>
</div>
<br>

<% }
else if ("false".equals(request.getParameter("uploadsuccess"))) { %>

<div class="error">
    <fmt:message key="plugin.admin.uploaded_failure"/>
</div>
<br>

<% } %>

463
<p>
464
    <fmt:message key="plugin.admin.info"/>
465
</p>
466

467 468
<p>

469
<div class="light-gray-border" style="padding:10px;">
470
<table cellpadding="0" cellspacing="0" border="0" width="100%">
471
 <tr style="background:#eee;">
472 473 474 475 476 477 478 479 480

    <td nowrap colspan="3" class="table-header-left"><fmt:message key="plugin.admin.name"/></td>
    <td nowrap class="table-header"><fmt:message key="plugin.admin.description"/></td>
    <td nowrap class="table-header"><fmt:message key="plugin.admin.version"/></td>
    <td nowrap class="table-header"><fmt:message key="plugin.admin.author"/></td>
    <td nowrap class="table-header"><fmt:message key="plugin.admin.restart"/></td>
    <td nowrap class="table-header-right"><fmt:message key="global.delete"/></td>
</tr>

481
<tbody>
482

483

484
<%
485
    // If only the admin plugin is installed, show "none".
486
    if (plugins.size() == 1) {
487
%>
488
<tr>
489
    <td align="center" colspan="8" style="padding:5px;"><fmt:message key="plugin.admin.no_plugin"/></td>
490
</tr>
491 492 493
<%
    }

Matt Tucker's avatar
Matt Tucker committed
494
    int count = 0;
495
    for (Plugin plugin : plugins) {
496
        String dirName = pluginManager.getPluginDirectory(plugin).getName();
497
        // Skip the admin plugin.
498
        if (!"admin".equals(dirName)) {
Matt Tucker's avatar
Matt Tucker committed
499
            count++;
500 501 502 503
            String pluginName = pluginManager.getName(plugin);
            String pluginDescription = pluginManager.getDescription(plugin);
            String pluginAuthor = pluginManager.getAuthor(plugin);
            String pluginVersion = pluginManager.getVersion(plugin);
504
            File pluginDir = pluginManager.getPluginDirectory(plugin);
505 506 507 508
            File icon = new File(pluginDir, "logo_small.png");
            if (!icon.exists()) {
                icon = new File(pluginDir, "logo_small.gif");
            }
509 510
            // Check if there is an update for this plugin
            Update update = updateManager.getPluginUpdate(pluginName, pluginVersion);
511 512
%>

513 514 515
<tr valign="top">
    <td width="1%" class="<%= update != null ? "update-top-left" : "line-bottom-border"%>">
        <% if (icon.exists()) { %>
516
        <img src="geticon?plugin=<%= URLEncoder.encode(pluginDir.getName(), "utf-8") %>&showIcon=true&decorator=none" width="16" height="16" alt="Plugin">
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
        <% }
        else { %>
        <img src="images/plugin-16x16.gif" width="16" height="16" alt="Plugin">
        <% } %>
    </td>
    <td width="20%" nowrap valign="top" class="<%= update != null ? "update-top" : "line-bottom-border"%>">
        <%= (pluginName != null ? pluginName : dirName) %> &nbsp;
        <%

            boolean readmeExists = new File(pluginDir, "readme.html").exists();
            boolean changelogExists = new File(pluginDir, "changelog.html").exists();
        %>


    </td>
    <td nowrap valign="top" class="<%= update != null ? "update-top" : "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"
540
                    ><img src="images/doc-changelog-16x16.gif" width="16" height="16" border="0" alt="changelog"></a>
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
            <% }
            else { %> &nbsp; <% } %></p>
    </td>
    <td width="60%" valign="top" class="<%= update != null ? "update-top" : "line-bottom-border"%>">
        <%= pluginDescription != null ? pluginDescription : "" %>
    </td>
    <td width="5%" align="center" valign="top" class="<%= update != null ? "update-top" : "line-bottom-border"%>">
        <p><%= pluginVersion != null ? pluginVersion : "" %></p>

    </td>
    <td width="15%" nowrap valign="top" class="<%= update != null ? "update-top" : "line-bottom-border"%>">
        <%= pluginAuthor != null ? pluginAuthor : "" %>  &nbsp;
    </td>
    <td width="1%" align="center" valign="top" class="<%= update != null ? "update-top" : "line-bottom-border"%>">
        <a href="plugin-admin.jsp?reloadplugin=<%= dirName %>"
           title="<fmt:message key="plugin.admin.click_reload" />"
                ><img src="images/refresh-16x16.gif" width="16" height="16" border="0" alt="<fmt:message key="global.refresh" />"></a>
    </td>
    <td width="1%" align="center" valign="top" class="<%= update != null ? "update-right" : "line-bottom-border"%>">
        <a href="#" onclick="if (confirm('<fmt:message key="plugin.admin.confirm" />')) { location.replace('plugin-admin.jsp?deleteplugin=<%= dirName %>'); } "
           title="<fmt:message key="global.click_delete" />"
                ><img src="images/delete-16x16.gif" width="16" height="16" border="0" alt="<fmt:message key="global.delete" />"></a>
    </td>
</tr>

<% if (update != null) { %>

<!-- Has Updates, show show -->
<%
    String updateURL = update.getURL();
    if (updateURL.endsWith(".jar") || updateURL.endsWith(".zip") || updateURL.endsWith(".war")) {
        // Change it so that the server downloads and installs the new version of the plugin
        updateURL = "plugin-admin.jsp?download=true&url=" + updateURL;
    }
%>
<tr id="<%= update.hashCode() %>-row">
    <td class="update-bottom-left">&nbsp;</td>
    <td class="update-bottom" nowrap>
Derek DeMoro's avatar
Derek DeMoro committed
579 580 581 582 583
        <span class="small-label">
            <fmt:message key="plugin.admin.version.available">
                <fmt:param value="<%= update.getLatestVersion()%>" />
            </fmt:message>
            </span>
584 585 586
    </td>
    <td nowrap class="update-bottom">
        <% if (update.getChangelog() != null) { %>
Derek DeMoro's avatar
Derek DeMoro committed
587
        <span class="text">(<a href="<%= update.getChangelog()%>"><fmt:message key="plugin.admin.changelog" /></a>)</span>
588 589 590 591 592 593 594 595 596
        <% }
        else { %>
        &nbsp;
        <% } %>
    </td>
    <td class="update-bottom">
        <table>
            <tr>
                <td><a href="javascript:download('<%= update.getURL()%>', '<%=update.hashCode()%>')"><img src="images/icon_update-16x16.gif" width="16" height="16" border="0" alt="changelog"></a></td>
Derek DeMoro's avatar
Derek DeMoro committed
597
                <td><a href="javascript:download('<%= update.getURL()%>', '<%=update.hashCode()%>')"><span class="small-label"><fmt:message key="plugin.admin.update" /></span></a></td>
598 599 600 601 602 603 604 605 606 607 608
            </tr>
        </table>
    </td>
    <td class="update-bottom" colspan="3">&nbsp;</td>
    <td class="update-bottom-right" colspan="3">&nbsp;</td>
</tr>

    <tr id="<%= update.hashCode()%>-update" style="display:none;">
        <td colspan="8" align="center" class="update">
            <table>
                <tr>
609
                    <td id="<%= update.hashCode()%>-image"><img src="images/working-16x16.gif" border="0" alt=""/></td>
Derek DeMoro's avatar
Derek DeMoro committed
610
                    <td id="<%= update.hashCode()%>-text" class="table-font"><fmt:message key="plugin.admin.updating" /></td>
611 612 613 614 615 616 617 618 619 620 621
                </tr>
            </table>
        </td>
    </tr>


<% } %>
<tr><td></td></tr>

<!-- End of update section -->
<%
622
        }
623 624 625 626 627 628
    }
%>
</tbody>
</table>
</div>

629 630 631 632 633 634 635 636 637 638 639 640 641
<% if (uploadEnabled) { %>
<br /><br />

<div>
    <h3><fmt:message key="plugin.admin.upload_plugin" /></h3>
    <p><fmt:message key="plugin.admin.upload_plugin.info" /></p>
    <form action="plugin-admin.jsp?uploadplugin" enctype="multipart/form-data" method="post">
        <input type="file" name="uploadfile" />
        <input type="submit" value="<fmt:message key="plugin.admin.upload_plugin" />" />
    </form>
</div>
<% } %>

642
</body>
643
</html>