Commit 8ed00ec5 authored by Guus der Kinderen's avatar Guus der Kinderen Committed by daryl herzmann

New HTTP File Upload plugin (#978)

parent 61a256d4
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>HTTP File Upload Plugin Changelog</title>
<style type="text/css">
BODY {
font-size : 100%;
}
BODY, TD, TH {
font-family : tahoma, verdana, arial, helvetica, sans-serif;
font-size : 0.8em;
}
H2 {
font-size : 10pt;
font-weight : bold;
padding-left : 1em;
}
A:hover {
text-decoration : none;
}
H1 {
font-family : tahoma, arial, helvetica, sans-serif;
font-size : 1.4em;
font-weight: bold;
border-bottom : 1px #ccc solid;
padding-bottom : 2px;
}
TT {
font-family : courier new;
font-weight : bold;
color : #060;
}
PRE {
font-family : courier new;
font-size : 100%;
}
</style>
</head>
<body>
<h1>HTTP File Upload Plugin Changelog</h1>
<p><b>1.0.0</b> -- December 14, 2017</p>
<ul>
<li>Initial release.</li>
</ul>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>servlet</servlet-name>
<servlet-class>org.igniterealtime.openfire.plugins.httpfileupload.CORSServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>servlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Openfire HTTP File Upload</title>
</head>
<body>
<h1>Openfire HTTP File Upload</h1>
<p>
This static page is part of the <a href="https://www.igniterealtime.org">Openfire</a> implementation of
<a href="https://xmpp.org/extensions/xep-0363.html">XEP-0363: HTTP File Upload</a>.
</p>
<p>
There's not much to see here with a browser. This service is intended to be used by XMPP clients!
</p>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<plugin>
<class>org.igniterealtime.openfire.plugins.httpfileupload.HttpFileUploadPlugin</class>
<name>HTTP File Upload</name>
<description>Allows clients to share files, as described in the XEP-0363 'HTTP File Upload' specification.</description>
<author>Guus der Kinderen</author>
<version>1.0.0</version>
<date>12/14/2017</date>
</plugin>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>plugins</artifactId>
<groupId>org.igniterealtime.openfire</groupId>
<version>4.2.0</version>
</parent>
<groupId>org.igniterealtime.openfire.plugins</groupId>
<artifactId>httpfileupload</artifactId>
<name>HTTP File Upload Plugin</name>
<description>Allows clients to share files, as described in the XEP-0363 'HTTP File Upload' specification.</description>
<version>1.0.0</version>
<build>
<sourceDirectory>src/java</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>nl.goodbytes.xmpp.xep</groupId>
<artifactId>httpfileuploadcomponent</artifactId>
<version>1.1.2</version>
</dependency>
</dependencies>
</project>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>HTTP File Upload Plugin Readme</title>
<style type="text/css">
BODY {
font-size : 100%;
}
BODY, TD, TH {
font-family : tahoma, verdana, arial, helvetica, sans-serif;
font-size : 0.8em;
}
H3 {
font-size : 10pt;
font-style: italic;
color: #004444;
}
H2 {
font-size : 10pt;
font-weight : bold;
}
A:hover {
text-decoration : none;
}
H1 {
font-family : tahoma, arial, helvetica, sans-serif;
font-size : 1.4em;
font-weight: bold;
border-bottom : 1px #ccc solid;
padding-bottom : 2px;
}
TT {
font-family : courier new;
font-weight : bold;
color : #060;
}
PRE {
font-family : courier new;
font-size : 100%;
}
#datatable TH {
color : #fff;
background-color : #2A448C;
text-align : left;
}
#datatable TD {
background-color : #FAF6EF;
}
#datatable .name {
background-color : #DCE2F5;
}
</style>
</head>
<body>
<h1>HTTP File Upload Plugin Readme
</h1>
<h2>Overview</h2>
<p>
The HTTP File Upload plugin adds functionality to Openfire that allows compliant clients to exchange files.
</p>
<h2>Installation</h2>
<p>
Copy httpfileupload.jar into the plugins directory of your Openfire installation. The plugin will then be
automatically deployed. To upgrade to a new version, copy the new httpfileupload.jar file over the existing file.
</p>
<h2>Using the Plugin</h2>
<p>
After intallation, the functionality provided by the plugin is automatically available to clients. While exchanging
files, the plugin by default stores the files that are being transferred in a temporary directory that is removed
when Openfire is shut down. The content of this directory is purged when its total size is larger than the remaining
disc space.
</p>
<h2>Attribution</h2>
<p>
Icons made by <a href="https://www.flaticon.com/authors/smashicons" title="Smashicons">Smashicons</a> from
<a href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a> is licensed by
<a href="http://creativecommons.org/licenses/by/3.0/" title="Creative Commons BY 3.0" target="_blank">CC 3.0 BY</a>
</p>
</body>
</html>
package org.igniterealtime.openfire.plugins.httpfileupload;
import nl.goodbytes.xmpp.xep0363.Servlet;
import org.jivesoftware.openfire.http.HttpBindManager;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* Created by guus on 19-11-17.
*/
public class CORSServlet extends Servlet
{
@Override
protected void service( HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
final HttpBindManager boshManager = HttpBindManager.getInstance();
// add CORS headers for all HTTP responses (errors, etc.)
if (boshManager.isCORSEnabled())
{
if (boshManager.isAllOriginsAllowed()) {
// Set the Access-Control-Allow-Origin header to * to allow all Origin to do the CORS
response.setHeader( "Access-Control-Allow-Origin", HttpBindManager.HTTP_BIND_CORS_ALLOW_ORIGIN_DEFAULT);
} else {
// Get the Origin header from the request and check if it is in the allowed Origin Map.
// If it is allowed write it back to the Access-Control-Allow-Origin header of the respond.
final String origin = request.getHeader("Origin");
if (boshManager.isThisOriginAllowed(origin)) {
response.setHeader("Access-Control-Allow-Origin", origin);
}
}
response.setHeader("Access-Control-Allow-Methods", HttpBindManager.HTTP_BIND_CORS_ALLOW_METHODS_DEFAULT);
response.setHeader("Access-Control-Allow-Headers", HttpBindManager.HTTP_BIND_CORS_ALLOW_HEADERS_DEFAULT);
response.setHeader("Access-Control-Max-Age", HttpBindManager.HTTP_BIND_CORS_MAX_AGE_DEFAULT);
}
super.service(request, response);
}
}
package org.igniterealtime.openfire.plugins.httpfileupload;
import nl.goodbytes.xmpp.xep0363.Component;
import org.apache.tomcat.InstanceManager;
import org.apache.tomcat.SimpleInstanceManager;
import org.eclipse.jetty.apache.jsp.JettyJasperInitializer;
import org.eclipse.jetty.plus.annotation.ContainerInitializer;
import org.eclipse.jetty.webapp.WebAppContext;
import org.jivesoftware.admin.AuthCheckFilter;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.component.InternalComponentManager;
import org.jivesoftware.openfire.container.Plugin;
import org.jivesoftware.openfire.container.PluginManager;
import org.jivesoftware.openfire.http.HttpBindManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmpp.component.ComponentException;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
/**
* Created by guus on 18-11-17.
*/
public class HttpFileUploadPlugin implements Plugin
{
private static final Logger Log = LoggerFactory.getLogger( HttpFileUploadPlugin.class );
private Component component;
private WebAppContext context;
private final String[] publicResources = new String[]
{
"httpfileupload/*",
"httpFileUpload/*"
};
@Override
public void initializePlugin( PluginManager manager, File pluginDirectory )
{
try
{
final URL endpoint = new URL( "https", XMPPServer.getInstance().getServerInfo().getHostname(), HttpBindManager.getInstance().getHttpBindSecurePort(), "/httpfileupload");
component = new Component( XMPPServer.getInstance().getServerInfo().getXMPPDomain(), endpoint );
// Add the Webchat sources to the same context as the one that's providing the BOSH interface.
context = new WebAppContext( null, pluginDirectory.getPath() + File.separator + "classes", "/httpfileupload" );
context.setClassLoader( this.getClass().getClassLoader() );
// Ensure the JSP engine is initialized correctly (in order to be able to cope with Tomcat/Jasper precompiled JSPs).
final List<ContainerInitializer> initializers = new ArrayList<>();
initializers.add( new ContainerInitializer( new JettyJasperInitializer(), null ) );
context.setAttribute("org.eclipse.jetty.containerInitializers", initializers);
context.setAttribute( InstanceManager.class.getName(), new SimpleInstanceManager());
HttpBindManager.getInstance().addJettyHandler( context );
InternalComponentManager.getInstance().addComponent( "httpfileupload", component );
for ( final String publicResource : publicResources )
{
AuthCheckFilter.addExclude( publicResource );
}
}
catch ( MalformedURLException e )
{
Log.error( "Unable to initialize endpoint URL!", e );
}
catch ( ComponentException e )
{
Log.error( "Unable to register component!", e );
}
}
@Override
public void destroyPlugin()
{
for ( final String publicResource : publicResources )
{
AuthCheckFilter.removeExclude( publicResource );
}
if ( context != null )
{
HttpBindManager.getInstance().removeJettyHandler( context );
context.destroy();
context = null;
}
if ( component != null )
{
InternalComponentManager.getInstance().removeComponent( "httpfileupload" );
}
}
}
......@@ -108,6 +108,7 @@
<module>fastpath</module>
<module>gojara</module>
<module>hazelcast</module>
<module>httpFileUpload</module>
<module>inverse</module>
<!-- jnsapi not in Maven Central-->
<!--<module>jingleNodes</module>-->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment