Commit 5f76e76d authored by richmidwinter's avatar richmidwinter Committed by akrherz

OF-1021: Admin Console Arbitrary File Upload (#866)

parent a43f90bb
...@@ -42,6 +42,8 @@ import java.nio.file.attribute.BasicFileAttributes; ...@@ -42,6 +42,8 @@ import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileTime; import java.nio.file.attribute.FileTime;
import java.util.*; import java.util.*;
import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.CopyOnWriteArraySet;
import java.util.jar.JarFile;
import java.util.zip.ZipException;
/** /**
* Loads and manages plugins. The <tt>plugins</tt> directory is monitored for any * Loads and manages plugins. The <tt>plugins</tt> directory is monitored for any
...@@ -155,17 +157,20 @@ public class PluginManager ...@@ -155,17 +157,20 @@ public class PluginManager
try try
{ {
// If pluginFilename is a path instead of a simple file name, we only want the file name // If pluginFilename is a path instead of a simple file name, we only want the file name
int index = pluginFilename.lastIndexOf( File.separator ); pluginFilename = Paths.get(pluginFilename).getFileName().toString();
if ( index != -1 )
{
pluginFilename = pluginFilename.substring( index + 1 );
}
// Absolute path to the plugin file // Absolute path to the plugin file
Path absolutePath = pluginDirectory.resolve( pluginFilename ); Path absolutePath = pluginDirectory.resolve( pluginFilename );
Path partFile = pluginDirectory.resolve( pluginFilename + ".part" ); Path partFile = pluginDirectory.resolve( pluginFilename + ".part" );
// Save input stream contents to a temp file // Save input stream contents to a temp file
Files.copy( in, partFile, StandardCopyOption.REPLACE_EXISTING ); Files.copy( in, partFile, StandardCopyOption.REPLACE_EXISTING );
// Check if zip file, else ZipException caught below.
try (JarFile file = new JarFile(partFile.toFile())) {
} catch (ZipException e) {
Files.deleteIfExists(partFile);
throw e;
};
// Rename temp file to .jar // Rename temp file to .jar
Files.move( partFile, absolutePath, StandardCopyOption.REPLACE_EXISTING ); Files.move( partFile, absolutePath, StandardCopyOption.REPLACE_EXISTING );
// Ask the plugin monitor to update the plugin immediately. // Ask the plugin monitor to update the plugin immediately.
......
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