plugin-admin.jsp 17.3 KB
Newer Older
1 2 3 4 5 6 7
<%--
  - Copyright (C) 2005 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
<%@ page import="org.jivesoftware.util.ParamUtils,
9 10 11
                 org.jivesoftware.util.WebManager,
                 org.jivesoftware.wildfire.XMPPServer,
                 org.jivesoftware.wildfire.container.Plugin,
12
                 org.jivesoftware.wildfire.container.PluginManager,
13 14 15 16 17 18 19 20 21 22 23 24
                 org.jivesoftware.wildfire.update.Update"
        %>
<%@ page import="org.jivesoftware.wildfire.update.UpdateManager" %>
<%@ page import="java.io.BufferedReader" %>
<%@ page import="java.io.File" %>
<%@ page import="java.io.FileReader" %>
<%@ page import="java.io.IOException" %>
<%@ 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" %>
25 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" %>

<%
30 31 32 33 34
    WebManager webManager = new WebManager();
%>
<%
    String deletePlugin = ParamUtils.getParameter(request, "deleteplugin");
    String reloadPlugin = ParamUtils.getParameter(request, "reloadplugin");
35 36
    boolean showReadme = ParamUtils.getBooleanParameter(request, "showReadme", false);
    boolean showChangelog = ParamUtils.getBooleanParameter(request, "showChangelog", false);
37
    boolean showIcon = ParamUtils.getBooleanParameter(request, "showIcon", false);
38 39
    boolean downloadRequested = request.getParameter("download") != null;
    String url = request.getParameter("url");
40

41
    final PluginManager pluginManager = webManager.getXMPPServer().getPluginManager();
42 43 44

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

45 46
    UpdateManager updateManager = XMPPServer.getInstance().getUpdateManager();

47 48 49 50 51 52 53
    if (plugins != null) {
        Collections.sort(plugins, new Comparator<Plugin>() {
            public int compare(Plugin p1, Plugin p2) {
                return pluginManager.getName(p1).compareTo(pluginManager.getName(p2));
            }
        });
    }
54

55 56 57 58 59
    if (downloadRequested) {
        // Download and install new version of plugin
        updateManager.downloadPlugin(url);
    }

60 61
    if (deletePlugin != null) {
        File pluginDir = pluginManager.getPluginDirectory(pluginManager.getPlugin(deletePlugin));
62
        File pluginJar = new File(pluginDir.getParent(), pluginDir.getName() + ".jar");
63 64 65 66 67
        // Also try the .war extension.
        if (!pluginJar.exists()) {
            pluginJar = new File(pluginDir.getParent(), pluginDir.getName() + ".war");
        }
        pluginJar.delete();
68
        pluginManager.unloadPlugin(pluginDir.getName());
69
        response.sendRedirect("plugin-admin.jsp?deletesuccess=true");
70
        return;
71 72 73 74
    }

    if (reloadPlugin != null) {
        for (Plugin plugin : plugins) {
75
            File pluginDir = pluginManager.getPluginDirectory(plugin);
76 77 78
            if (reloadPlugin.equals(pluginDir.getName())) {
                pluginManager.unloadPlugin(reloadPlugin);
                response.sendRedirect("plugin-admin.jsp?reloadsuccess=true");
79
                return;
80 81 82
            }
        }
    }
83 84
%>

85
<% if (showReadme) {
86 87 88 89 90 91 92 93 94 95
    String pluginName = ParamUtils.getParameter(request, "plugin");
    Plugin plugin = pluginManager.getPlugin(pluginName);
    if (plugin != null) {
        File readme = new File(pluginManager.getPluginDirectory(plugin), "readme.html");
        if (readme.exists()) {
            BufferedReader in = null;
            try {
                in = new BufferedReader(new FileReader(readme));
                String line;
                while ((line = in.readLine()) != null) {
96
%>
97
<%= line %>
98
<%
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
                    }
                }
                catch (IOException ioe) {
                    ioe.printStackTrace();
                }
                finally {
                    if (in != null) {
                        try {
                            in.close();
                        }
                        catch (Exception e) {
                        }
                    }
                }
            }
        }
        return;
    }
117 118
%>
<% if (showChangelog) {
119 120 121 122 123 124 125 126 127 128
    String pluginName = ParamUtils.getParameter(request, "plugin");
    Plugin plugin = pluginManager.getPlugin(pluginName);
    if (plugin != null) {
        File changelog = new File(pluginManager.getPluginDirectory(plugin), "changelog.html");
        if (changelog.exists()) {
            BufferedReader in = null;
            try {
                in = new BufferedReader(new FileReader(changelog));
                String line;
                while ((line = in.readLine()) != null) {
129
%>
130
<%= line %>
131
<%
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
                    }
                }
                catch (IOException ioe) {

                }
                finally {
                    if (in != null) {
                        try {
                            in.close();
                        }
                        catch (Exception e) {
                        }
                    }
                }
            }
        }
        return;
149 150 151
    }
%>

152
<html>
153 154 155 156 157 158 159
<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>
160

161 162
<script type="text/javascript" >
    DWREngine.setErrorHandler(handleError);
163

164 165
    function handleError(error) {
    }
166 167
</script>

168
<style type="text/css">
169

170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196

.textfield {
    font-size: 11px;
    font-family: verdana;
    padding: 3px 2px;
    background: #efefef;
}

.text {
    font-size: 11px;
    font-family: verdana;
}

.small-label {
    font-size: 11px;
    font-weight: bold;
    font-family: verdana;
}

.small-label-link {
    font-size: 11px;
    font-weight: bold;
    font-family: verdana;
    text-decoration: underline;
}

.light-gray-border {
197
    border-color: #ccc;
198 199 200
    border-style: solid;
    border-width: 1px 1px 1px 1px;
    padding: 5px;
201
	-moz-border-radius: 3px;
202 203 204
}

.light-gray-border-bottom {
205
    border-color: #dcdcdc;
206 207 208 209 210 211 212 213 214
    border-style: solid;
    border-width: 0px 0px 1px 0px;
}

.table-header {
    text-align: left;
    font-family: verdana, arial, helvetica, sans-serif;
    font-size: 8pt;
    font-weight: bold;
215
    border-color: #ccc;
216 217 218 219 220 221 222 223 224 225
    border-style: solid;
    border-width: 1px 0px 1px 0px;
    padding: 5px;
}

.table-header-left {
    text-align: left;
    font-family: verdana, arial, helvetica, sans-serif;
    font-size: 8pt;
    font-weight: bold;
226
    border-color: #ccc;
227 228 229 230 231 232 233 234 235 236 237
    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;
238
    border-color: #ccc;
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 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 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 322 323 324 325 326 327 328 329 330 331 332 333
    border-style: solid;
    border-width: 1px 1px 1px 0px;
    padding: 5px;
}

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

.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 {
    font-family: verdana, arial, helvetica, sans-serif;
    font-size: 8pt;
    background: #E7FBDE;
    border-color: #73CB73;
    border-style: solid;
    border-width: 0px 1px 1px 1px;
    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;
    border-width: 0px 0px 1px 0px;
    padding: 5px;
}

.update-top-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;
    border-width: 1px 0px 0px 1px;
    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;
    border-width: 0px 0px 1px 1px;
    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;
    border-width: 0px 1px 1px 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;
334
    border-color: #e3e3e3;
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
    border-style: solid;
    border-width: 0px 0px 1px 0px;
    padding: 5px;
}


</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 = '';
        document.getElementById(update.hashCode + "-image").innerHTML = '<img src="images/success-16x16.gif" border="0"/>';
Derek DeMoro's avatar
Derek DeMoro committed
355
        document.getElementById(update.hashCode + "-text").innerHTML = '<fmt:message key="plugin.admin.update.complete" />';
356 357 358 359 360
    }
</script>
</head>

<body>
361 362 363

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

364 365
<div class="success">
   <fmt:message key="plugin.admin.deleted_success"/>
366 367
</div>
<br>
368

369 370
<% }
else if ("false".equals(request.getParameter("deletesuccess"))) { %>
371

372 373
<div class="error">
    <fmt:message key="plugin.admin.deleted_failure"/>
374 375
</div>
<br>
376 377 378

<% } %>

379
<% if ("true".equals(request.getParameter("reloadsuccess"))) { %>
380

381
<div class="success">
Derek DeMoro's avatar
Derek DeMoro committed
382
   <fmt:message key="plugin.admin.reload_success"/>
383 384
</div>
<br>
385 386 387 388

<% } %>

<p>
389
    <fmt:message key="plugin.admin.info"/>
390
</p>
391

392 393
<p>

394
<div class="light-gray-border" style="padding:10px;">
395
<table cellpadding="0" cellspacing="0" border="0" width="100%">
396
 <tr style="background:#f3f7fa;">
397 398 399 400 401 402 403 404 405

    <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>

406
<tbody>
407

408

409
<%
410
    // If only the admin plugin is installed, show "none".
411
    if (plugins.size() == 1) {
412
%>
413
<tr>
414
    <td align="center" colspan="8" style="padding:5px;"><fmt:message key="plugin.admin.no_plugin"/></td>
415
</tr>
416 417 418
<%
    }

Matt Tucker's avatar
Matt Tucker committed
419
    int count = 0;
420
    for (Plugin plugin : plugins) {
421
        String dirName = pluginManager.getPluginDirectory(plugin).getName();
422
        // Skip the admin plugin.
423
        if (!"admin".equals(dirName)) {
Matt Tucker's avatar
Matt Tucker committed
424
            count++;
425 426 427 428
            String pluginName = pluginManager.getName(plugin);
            String pluginDescription = pluginManager.getDescription(plugin);
            String pluginAuthor = pluginManager.getAuthor(plugin);
            String pluginVersion = pluginManager.getVersion(plugin);
429
            File pluginDir = pluginManager.getPluginDirectory(plugin);
430 431 432 433
            File icon = new File(pluginDir, "logo_small.png");
            if (!icon.exists()) {
                icon = new File(pluginDir, "logo_small.gif");
            }
434 435
            // Check if there is an update for this plugin
            Update update = updateManager.getPluginUpdate(pluginName, pluginVersion);
436 437
%>

438 439 440
<tr valign="top">
    <td width="1%" class="<%= update != null ? "update-top-left" : "line-bottom-border"%>">
        <% if (icon.exists()) { %>
441
        <img src="geticon?plugin=<%= URLEncoder.encode(pluginDir.getName(), "utf-8") %>&showIcon=true&decorator=none" width="16" height="16" alt="Plugin">
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
        <% }
        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"
465
                    ><img src="images/doc-changelog-16x16.gif" width="16" height="16" border="0" alt="changelog"></a>
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503
            <% }
            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
504 505 506 507 508
        <span class="small-label">
            <fmt:message key="plugin.admin.version.available">
                <fmt:param value="<%= update.getLatestVersion()%>" />
            </fmt:message>
            </span>
509 510 511
    </td>
    <td nowrap class="update-bottom">
        <% if (update.getChangelog() != null) { %>
Derek DeMoro's avatar
Derek DeMoro committed
512
        <span class="text">(<a href="<%= update.getChangelog()%>"><fmt:message key="plugin.admin.changelog" /></a>)</span>
513 514 515 516 517 518 519 520 521
        <% }
        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
522
                <td><a href="javascript:download('<%= update.getURL()%>', '<%=update.hashCode()%>')"><span class="small-label"><fmt:message key="plugin.admin.update" /></span></a></td>
523 524 525 526 527 528 529 530 531 532 533 534
            </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>
                    <td id="<%= update.hashCode()%>-image"><img src="images/working-16x16.gif" border="0"/></td>
Derek DeMoro's avatar
Derek DeMoro committed
535
                    <td id="<%= update.hashCode()%>-text" class="table-font"><fmt:message key="plugin.admin.updating" /></td>
536 537 538 539 540 541 542 543 544 545 546
                </tr>
            </table>
        </td>
    </tr>


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

<!-- End of update section -->
<%
547
        }
548 549 550 551 552 553
    }
%>
</tbody>
</table>
</div>

554
</body>
555
</html>