Compare commits
12 Commits
21a7b6e870
...
master
Author | SHA1 | Date | |
---|---|---|---|
5c3c00e18b | |||
ca3dec0ae1 | |||
fc4d7f1f43 | |||
1fac9b9378 | |||
835e5db92f | |||
816b95afb6 | |||
4e1156d4bc | |||
e4ea50ac66 | |||
33491e3904 | |||
be5b64789a | |||
b894978f92 | |||
ef252f5a19 |
14
README.md
14
README.md
@@ -28,4 +28,16 @@ TODO
|
|||||||
## How to use
|
## How to use
|
||||||
Place a `servers.json` in the Pie Cannon data directory. For GNU/Linux this is `XDG_DATA_HOME` (by default this would be `~/.local/share/piecannon`) (create this directory if it does not exist. For Android this would be the app's "externalFilesDir" (probably something like `Android/data/net.monarchpass.piecannon/files` - the app will tell you when you launch it). See `servers.example.json` for an example of such a file. Whenever you initiate a file upload, Pie Cannon will select one of your defined servers at random and upload the file.
|
Place a `servers.json` in the Pie Cannon data directory. For GNU/Linux this is `XDG_DATA_HOME` (by default this would be `~/.local/share/piecannon`) (create this directory if it does not exist. For Android this would be the app's "externalFilesDir" (probably something like `Android/data/net.monarchpass.piecannon/files` - the app will tell you when you launch it). See `servers.example.json` for an example of such a file. Whenever you initiate a file upload, Pie Cannon will select one of your defined servers at random and upload the file.
|
||||||
|
|
||||||
For FTP/SFTP servers (the only supported types as of now), the `path` is relative to your home directory and should be where `url` points to. i.e. a file uploaded to `path` should be downloadable at `url`. In the future Pie Cannon should be able to get SSH credentials from your agent so you won't need to put a password in this file.
|
#### Server Types
|
||||||
|
The `type` field in the server configuration tells Pie Cannon what type of server to use. The default value is `webdav`.
|
||||||
|
|
||||||
|
##### WebDAV (`webdav`)
|
||||||
|
For WebDAV servers, `url` is where the file is uploaded to and served from. `username` and `password`, if given, are HTTP Basic authentication credentials.
|
||||||
|
|
||||||
|
For setting this up with nginx, see [ngx_http_dav_module](https://nginx.org/en/docs/http/ngx_http_dav_module.html) documentation and also [HTTP Basic Authentication](https://docs.nginx.com/nginx/admin-guide/security-controls/configuring-http-basic-authentication/) guide.
|
||||||
|
|
||||||
|
##### FTP/SFTP (`ftp`/`sftp`)
|
||||||
|
For FTP/SFTP servers, the `path` is relative to your home directory and should be where `url` points to. i.e. a file uploaded to `path` should be downloadable at `url`. In the future Pie Cannon should be able to get SSH credentials from your agent so you won't need to put a password in this file.
|
||||||
|
|
||||||
|
##### GoFile.io (`gofile`)
|
||||||
|
No configuration options are supported for this currently, however in the future there may be support for using a token. Note that it's not possible to get a direct download link for this service without visiting a page first, so Pie Cannon returns the URL for that page instead of a direct download link.
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar" enabled="true" runInBatchMode="false"/>
|
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar" enabled="true" runInBatchMode="false"/>
|
||||||
<factorypathentry kind="VARJAR" id="M2_REPO/org/checkerframework/checker-compat-qual/2.5.5/checker-compat-qual-2.5.5.jar" enabled="true" runInBatchMode="false"/>
|
<factorypathentry kind="VARJAR" id="M2_REPO/org/checkerframework/checker-compat-qual/2.5.5/checker-compat-qual-2.5.5.jar" enabled="true" runInBatchMode="false"/>
|
||||||
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3.jar" enabled="true" runInBatchMode="false"/>
|
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3.jar" enabled="true" runInBatchMode="false"/>
|
||||||
|
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/code/gson/gson/2.8.6/gson-2.8.6.jar" enabled="true" runInBatchMode="false"/>
|
||||||
<factorypathentry kind="VARJAR" id="M2_REPO/com/jcraft/jsch/0.1.55/jsch-0.1.55.jar" enabled="true" runInBatchMode="false"/>
|
<factorypathentry kind="VARJAR" id="M2_REPO/com/jcraft/jsch/0.1.55/jsch-0.1.55.jar" enabled="true" runInBatchMode="false"/>
|
||||||
<factorypathentry kind="VARJAR" id="M2_REPO/org/jodd/jodd-util/6.0.0/jodd-util-6.0.0.jar" enabled="true" runInBatchMode="false"/>
|
<factorypathentry kind="VARJAR" id="M2_REPO/org/jodd/jodd-util/6.0.0/jodd-util-6.0.0.jar" enabled="true" runInBatchMode="false"/>
|
||||||
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/android/android/4.1.1.4/android-4.1.1.4.jar" enabled="true" runInBatchMode="false"/>
|
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/android/android/4.1.1.4/android-4.1.1.4.jar" enabled="true" runInBatchMode="false"/>
|
||||||
|
@@ -2,6 +2,8 @@
|
|||||||
<factorypathentry kind="VARJAR" id="M2_REPO/net/monarchpass/libpiecannon/0.0.1-SNAPSHOT/libpiecannon-0.0.1-SNAPSHOT.jar" enabled="true" runInBatchMode="false"/>
|
<factorypathentry kind="VARJAR" id="M2_REPO/net/monarchpass/libpiecannon/0.0.1-SNAPSHOT/libpiecannon-0.0.1-SNAPSHOT.jar" enabled="true" runInBatchMode="false"/>
|
||||||
<factorypathentry kind="VARJAR" id="M2_REPO/com/github/mwiede/jsch/0.1.60/jsch-0.1.60.jar" enabled="true" runInBatchMode="false"/>
|
<factorypathentry kind="VARJAR" id="M2_REPO/com/github/mwiede/jsch/0.1.60/jsch-0.1.60.jar" enabled="true" runInBatchMode="false"/>
|
||||||
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/code/gson/gson/2.8.6/gson-2.8.6.jar" enabled="true" runInBatchMode="false"/>
|
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/code/gson/gson/2.8.6/gson-2.8.6.jar" enabled="true" runInBatchMode="false"/>
|
||||||
|
<factorypathentry kind="VARJAR" id="M2_REPO/org/jodd/jodd-http/6.0.3/jodd-http-6.0.3.jar" enabled="true" runInBatchMode="false"/>
|
||||||
|
<factorypathentry kind="VARJAR" id="M2_REPO/org/jodd/jodd-util/6.0.0/jodd-util-6.0.0.jar" enabled="true" runInBatchMode="false"/>
|
||||||
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/guava/guava/30.0-jre/guava-30.0-jre.jar" enabled="true" runInBatchMode="false"/>
|
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/guava/guava/30.0-jre/guava-30.0-jre.jar" enabled="true" runInBatchMode="false"/>
|
||||||
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1.jar" enabled="true" runInBatchMode="false"/>
|
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1.jar" enabled="true" runInBatchMode="false"/>
|
||||||
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar" enabled="true" runInBatchMode="false"/>
|
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar" enabled="true" runInBatchMode="false"/>
|
||||||
@@ -10,7 +12,5 @@
|
|||||||
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/errorprone/error_prone_annotations/2.3.4/error_prone_annotations-2.3.4.jar" enabled="true" runInBatchMode="false"/>
|
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/errorprone/error_prone_annotations/2.3.4/error_prone_annotations-2.3.4.jar" enabled="true" runInBatchMode="false"/>
|
||||||
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3.jar" enabled="true" runInBatchMode="false"/>
|
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3.jar" enabled="true" runInBatchMode="false"/>
|
||||||
<factorypathentry kind="VARJAR" id="M2_REPO/net/kothar/xdg-java/0.1.1/xdg-java-0.1.1.jar" enabled="true" runInBatchMode="false"/>
|
<factorypathentry kind="VARJAR" id="M2_REPO/net/kothar/xdg-java/0.1.1/xdg-java-0.1.1.jar" enabled="true" runInBatchMode="false"/>
|
||||||
<factorypathentry kind="VARJAR" id="M2_REPO/com/jcraft/jsch.agentproxy.jsch/0.0.9/jsch.agentproxy.jsch-0.0.9.jar" enabled="true" runInBatchMode="false"/>
|
|
||||||
<factorypathentry kind="VARJAR" id="M2_REPO/com/jcraft/jsch.agentproxy.core/0.0.9/jsch.agentproxy.core-0.0.9.jar" enabled="true" runInBatchMode="false"/>
|
|
||||||
<factorypathentry kind="VARJAR" id="M2_REPO/org/projectlombok/lombok/1.18.16/lombok-1.18.16.jar" enabled="true" runInBatchMode="false"/>
|
<factorypathentry kind="VARJAR" id="M2_REPO/org/projectlombok/lombok/1.18.16/lombok-1.18.16.jar" enabled="true" runInBatchMode="false"/>
|
||||||
</factorypath>
|
</factorypath>
|
||||||
|
12
desktop/Makefile
Normal file
12
desktop/Makefile
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
PREFIX=~/.local
|
||||||
|
DEST=$(PREFIX)/lib/piecannon
|
||||||
|
COMMAND=$(PREFIX)/bin/piecannon
|
||||||
|
|
||||||
|
target:
|
||||||
|
mvn install
|
||||||
|
|
||||||
|
install: target
|
||||||
|
mkdir -p $(DEST)
|
||||||
|
cp target/piecannon-*.jar $(DEST)/piecannon.jar
|
||||||
|
sed "s#@JAR_PATH@#$(DEST)/piecannon.jar#g" piecannon.in > $(COMMAND)
|
||||||
|
chmod +x $(COMMAND)
|
@@ -1,20 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
PC_GROUP="net.monarchpass"
|
|
||||||
PC_ARTIFACT="piecannon-desktop-app"
|
|
||||||
PC_VERSION="0.0.1-SNAPSHOT"
|
|
||||||
PC_CLASS="net.monarchpass.piecannon.App"
|
|
||||||
|
|
||||||
STUB_POM="<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 https://maven.apache.org/xsd/maven-4.0.0.xsd'> <modelVersion>4.0.0</modelVersion> <groupId>$PC_GROUP</groupId> <artifactId>piecannon-launcher</artifactId> <version>$PC_VERSION</version> <dependencies> <dependency><groupId>$PC_GROUP</groupId><artifactId>$PC_ARTIFACT</artifactId><version>\${project.version}</version></dependency></dependencies></project>"
|
|
||||||
STUB_POM_FILE=/tmp/pc.xml
|
|
||||||
echo $STUB_POM > $STUB_POM_FILE
|
|
||||||
|
|
||||||
OUTPUT=$(mvn -f $STUB_POM_FILE -B exec:java -Dexec.mainClass=$PC_CLASS -Dexec.arguments=$1 -Dorg.slf4j.simpleLogger.defaultLogLevel=WARN)
|
|
||||||
EXEC_RESULT=$?
|
|
||||||
echo "$OUTPUT"
|
|
||||||
|
|
||||||
if [ $EXEC_RESULT != 0 ]; then
|
|
||||||
exit $EXEC_RESULT;
|
|
||||||
fi
|
|
||||||
|
|
||||||
RESULT=$(echo "$OUTPUT" | tail -n 1)
|
|
||||||
xdg-open $RESULT
|
|
10
desktop/piecannon.in
Normal file
10
desktop/piecannon.in
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
JAR_PATH=@JAR_PATH@
|
||||||
|
|
||||||
|
if [ "$1" = "--file-selector" ]; then
|
||||||
|
RESULT=$(java -jar "$JAR_PATH" $(yad --file))
|
||||||
|
else
|
||||||
|
RESULT=$(java -jar "$JAR_PATH" "$@")
|
||||||
|
fi
|
||||||
|
|
||||||
|
xdg-open $RESULT
|
@@ -16,44 +16,17 @@
|
|||||||
<groupId>net.monarchpass</groupId>
|
<groupId>net.monarchpass</groupId>
|
||||||
<artifactId>libpiecannon</artifactId>
|
<artifactId>libpiecannon</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>com.github.mwiede</groupId>
|
|
||||||
<artifactId>jsch</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.jcraft</groupId>
|
|
||||||
<artifactId>jsch</artifactId>
|
|
||||||
<version>0.1.55</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.guava</groupId>
|
<groupId>com.google.guava</groupId>
|
||||||
<artifactId>guava</artifactId>
|
<artifactId>guava</artifactId>
|
||||||
<version>30.0-jre</version>
|
<version>30.0-jre</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.kothar</groupId>
|
<groupId>net.kothar</groupId>
|
||||||
<artifactId>xdg-java</artifactId>
|
<artifactId>xdg-java</artifactId>
|
||||||
<version>0.1.1</version>
|
<version>0.1.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.jcraft</groupId>
|
|
||||||
<artifactId>jsch.agentproxy.jsch</artifactId>
|
|
||||||
<version>0.0.9</version>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>com.jcraft</groupId>
|
|
||||||
<artifactId>jsch</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.jcraft</groupId>
|
|
||||||
<artifactId>jsch.agentproxy.connector-factory</artifactId>
|
|
||||||
<version>0.0.9</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
@@ -84,6 +57,31 @@
|
|||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>2.22.2</version>
|
<version>2.22.2</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<addClasspath>true</addClasspath>
|
||||||
|
<mainClass>net.monarchpass.piecannon.App</mainClass>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.4</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
@@ -9,21 +9,11 @@ import org.freedesktop.BaseDirectory;
|
|||||||
import lombok.extern.java.Log;
|
import lombok.extern.java.Log;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import net.monarchpass.piecannon.util.ServerFactory;
|
|
||||||
|
|
||||||
import com.jcraft.jsch.IdentityRepository;
|
|
||||||
import com.jcraft.jsch.agentproxy.Connector;
|
|
||||||
import com.jcraft.jsch.agentproxy.AgentProxyException;
|
|
||||||
import com.jcraft.jsch.agentproxy.RemoteIdentityRepository;
|
|
||||||
import com.jcraft.jsch.agentproxy.ConnectorFactory;
|
|
||||||
|
|
||||||
@Log
|
@Log
|
||||||
public class App {
|
public class App {
|
||||||
public static void main (final String... args) throws Exception {
|
public static void main (final String... args) throws Exception {
|
||||||
final File serversJson = getServersJson();
|
final File serversJson = getServersJson();
|
||||||
final PieCannon cannon = new PieCannon();
|
final PieCannon cannon = new PieCannon();
|
||||||
cannon.getServerFactory().setIdentityRepository(createIdentityRepository());
|
|
||||||
|
|
||||||
final List<Server> servers = cannon.loadServersFrom(serversJson);
|
final List<Server> servers = cannon.loadServersFrom(serversJson);
|
||||||
log.log(Level.INFO, "{0} servers loaded from {1}", new Object[] {
|
log.log(Level.INFO, "{0} servers loaded from {1}", new Object[] {
|
||||||
servers.size(), serversJson
|
servers.size(), serversJson
|
||||||
@@ -61,8 +51,16 @@ public class App {
|
|||||||
public static void testServers (final List<Server> servers) {
|
public static void testServers (final List<Server> servers) {
|
||||||
log.log(Level.INFO, "Testing all defined servers");
|
log.log(Level.INFO, "Testing all defined servers");
|
||||||
for (final Server server : servers) {
|
for (final Server server : servers) {
|
||||||
|
Object result;
|
||||||
|
try {
|
||||||
|
result = PieCannon.testServer(server);
|
||||||
|
}
|
||||||
|
catch (final Exception exception) {
|
||||||
|
result = exception;
|
||||||
|
}
|
||||||
|
|
||||||
log.log(Level.INFO, "{0} {1}: {2}", new Object[] {
|
log.log(Level.INFO, "{0} {1}: {2}", new Object[] {
|
||||||
server.getClass().getSimpleName(), server.getLabel(), PieCannon.testServer(server)
|
server.getClass().getSimpleName(), server.getLabel(), result
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -74,20 +72,4 @@ public class App {
|
|||||||
public static File getDataDirectory () {
|
public static File getDataDirectory () {
|
||||||
return new File(BaseDirectory.get(BaseDirectory.XDG_DATA_HOME), "piecannon");
|
return new File(BaseDirectory.get(BaseDirectory.XDG_DATA_HOME), "piecannon");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IdentityRepository createIdentityRepository () {
|
|
||||||
try {
|
|
||||||
final ConnectorFactory connectorFactory = ConnectorFactory.getDefault();
|
|
||||||
final Connector connector = connectorFactory.createConnector();
|
|
||||||
|
|
||||||
if (connector != null) {
|
|
||||||
return new RemoteIdentityRepository(connector);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (final AgentProxyException exception) {
|
|
||||||
log.log(Level.WARNING, "Failed to create agent identity repository", exception);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -22,12 +22,8 @@ import com.google.gson.JsonParser;
|
|||||||
|
|
||||||
import net.monarchpass.piecannon.util.ServerFactory;
|
import net.monarchpass.piecannon.util.ServerFactory;
|
||||||
|
|
||||||
import lombok.Setter;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
public class PieCannon {
|
public class PieCannon {
|
||||||
public List<Server> servers;
|
public List<Server> servers;
|
||||||
public @Getter @Setter ServerFactory serverFactory = new ServerFactory();
|
|
||||||
|
|
||||||
public List<Server> loadServersFrom (final File serversJson) throws IOException {
|
public List<Server> loadServersFrom (final File serversJson) throws IOException {
|
||||||
try (final InputStream in = new FileInputStream(serversJson)) {
|
try (final InputStream in = new FileInputStream(serversJson)) {
|
||||||
@@ -36,6 +32,7 @@ public class PieCannon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<Server> loadServersFrom (final InputStream in) throws IOException {
|
public List<Server> loadServersFrom (final InputStream in) throws IOException {
|
||||||
|
final ServerFactory factory = new ServerFactory();
|
||||||
final JsonParser parser = new JsonParser();
|
final JsonParser parser = new JsonParser();
|
||||||
final List<Server> loadedServers = new ArrayList<>();
|
final List<Server> loadedServers = new ArrayList<>();
|
||||||
for (final JsonElement element : parser.parse(new InputStreamReader(in)).getAsJsonArray()) {
|
for (final JsonElement element : parser.parse(new InputStreamReader(in)).getAsJsonArray()) {
|
||||||
@@ -43,7 +40,7 @@ public class PieCannon {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
loadedServers.add(serverFactory.apply((JsonObject)element));
|
loadedServers.add(factory.apply((JsonObject)element));
|
||||||
}
|
}
|
||||||
servers = loadedServers;
|
servers = loadedServers;
|
||||||
return loadedServers;
|
return loadedServers;
|
||||||
|
@@ -13,7 +13,6 @@ import com.jcraft.jsch.Channel;
|
|||||||
import com.jcraft.jsch.ChannelSftp;
|
import com.jcraft.jsch.ChannelSftp;
|
||||||
import com.jcraft.jsch.JSchException;
|
import com.jcraft.jsch.JSchException;
|
||||||
import com.jcraft.jsch.SftpException;
|
import com.jcraft.jsch.SftpException;
|
||||||
import com.jcraft.jsch.IdentityRepository;
|
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@@ -26,17 +25,12 @@ public class SftpServer implements Server {
|
|||||||
private final String password;
|
private final String password;
|
||||||
private final String path;
|
private final String path;
|
||||||
private final URI uri;
|
private final URI uri;
|
||||||
private final IdentityRepository identityRepository;
|
|
||||||
|
|
||||||
public URI upload (String name, ByteSource source) {
|
public URI upload (String name, ByteSource source) {
|
||||||
try {
|
try {
|
||||||
final URI target = URI.create(uri.toString() + "/" + name.replace(" ", "%20"));
|
final URI target = URI.create(uri.toString() + "/" + name.replace(" ", "%20"));
|
||||||
|
|
||||||
final JSch jsch = new JSch();
|
final JSch jsch = new JSch();
|
||||||
if (identityRepository != null) {
|
|
||||||
jsch.setIdentityRepository(identityRepository);
|
|
||||||
}
|
|
||||||
|
|
||||||
final Session session = jsch.getSession(username, host, port);
|
final Session session = jsch.getSession(username, host, port);
|
||||||
session.setPassword(password);
|
session.setPassword(password);
|
||||||
session.setConfig("StrictHostKeyChecking", "no");
|
session.setConfig("StrictHostKeyChecking", "no");
|
||||||
|
@@ -6,6 +6,7 @@ import java.net.URI;
|
|||||||
import com.google.common.io.ByteSource;
|
import com.google.common.io.ByteSource;
|
||||||
|
|
||||||
import jodd.http.HttpRequest;
|
import jodd.http.HttpRequest;
|
||||||
|
import jodd.http.HttpResponse;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import net.monarchpass.piecannon.Server;
|
import net.monarchpass.piecannon.Server;
|
||||||
|
|
||||||
@@ -28,7 +29,11 @@ public class WebDavServer implements Server {
|
|||||||
request.basicAuthentication(username, password);
|
request.basicAuthentication(username, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
request.send();
|
final HttpResponse response = request.send();
|
||||||
|
if (response.statusCode() >= 400) {
|
||||||
|
throw new RuntimeException(response.statusCode() + ": " + response.statusPhrase());
|
||||||
|
}
|
||||||
|
|
||||||
return target;
|
return target;
|
||||||
} catch (final IOException exception) {
|
} catch (final IOException exception) {
|
||||||
throw new RuntimeException(exception);
|
throw new RuntimeException(exception);
|
||||||
|
@@ -5,7 +5,6 @@ import java.util.Optional;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.jcraft.jsch.IdentityRepository;
|
|
||||||
import com.google.gson.JsonPrimitive;
|
import com.google.gson.JsonPrimitive;
|
||||||
|
|
||||||
import net.monarchpass.piecannon.Server;
|
import net.monarchpass.piecannon.Server;
|
||||||
@@ -14,18 +13,14 @@ import net.monarchpass.piecannon.impl.GoFileServer;
|
|||||||
import net.monarchpass.piecannon.impl.SftpServer;
|
import net.monarchpass.piecannon.impl.SftpServer;
|
||||||
import net.monarchpass.piecannon.impl.WebDavServer;
|
import net.monarchpass.piecannon.impl.WebDavServer;
|
||||||
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
public class ServerFactory implements Function<JsonObject, Server> {
|
public class ServerFactory implements Function<JsonObject, Server> {
|
||||||
private @Setter IdentityRepository identityRepository;
|
|
||||||
|
|
||||||
public Server apply (final JsonObject object) {
|
public Server apply (final JsonObject object) {
|
||||||
final String type = Optional.ofNullable(object.getAsJsonPrimitive("type"))
|
final String type = Optional.ofNullable(object.getAsJsonPrimitive("type"))
|
||||||
.map(JsonPrimitive::getAsString)
|
.map(JsonPrimitive::getAsString)
|
||||||
.orElse("webdav");
|
.orElse("webdav");
|
||||||
|
|
||||||
if (type.equals("webdav")) {
|
if (type.equals("webdav")) {
|
||||||
return makeWebDavServer(object);
|
return makeWebDavServer(object);
|
||||||
} else if (type.equalsIgnoreCase("gofile")) {
|
} else if (type.equalsIgnoreCase("gofile")) {
|
||||||
return new GoFileServer(Optional.ofNullable(object.getAsJsonPrimitive("label")).map(JsonPrimitive::getAsString).orElse("GoFile"));
|
return new GoFileServer(Optional.ofNullable(object.getAsJsonPrimitive("label")).map(JsonPrimitive::getAsString).orElse("GoFile"));
|
||||||
} else if (type.equalsIgnoreCase("ftp")) {
|
} else if (type.equalsIgnoreCase("ftp")) {
|
||||||
@@ -59,13 +54,13 @@ public class ServerFactory implements Function<JsonObject, Server> {
|
|||||||
final String label = object.has("label") ? object.getAsJsonPrimitive("label").getAsString() : host;
|
final String label = object.has("label") ? object.getAsJsonPrimitive("label").getAsString() : host;
|
||||||
final int port = object.has("port") ? object.getAsJsonPrimitive("port").getAsInt() : 22;
|
final int port = object.has("port") ? object.getAsJsonPrimitive("port").getAsInt() : 22;
|
||||||
final String username = object.getAsJsonPrimitive("username").getAsString();
|
final String username = object.getAsJsonPrimitive("username").getAsString();
|
||||||
final String password = object.has("password") ? object.getAsJsonPrimitive("password").getAsString() : null;
|
final String password = object.getAsJsonPrimitive("password").getAsString();
|
||||||
final String path = object.getAsJsonPrimitive("path").getAsString();
|
final String path = object.getAsJsonPrimitive("path").getAsString();
|
||||||
final String url = object.getAsJsonPrimitive("url").getAsString();
|
final String url = object.getAsJsonPrimitive("url").getAsString();
|
||||||
|
|
||||||
return new SftpServer(
|
return new SftpServer(
|
||||||
label, host, port, username, password,
|
label, host, port, username, password,
|
||||||
path, URI.create(url), identityRepository
|
path, URI.create(url)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -22,7 +22,7 @@ public class SftpTest {
|
|||||||
final Server server = new SftpServer(
|
final Server server = new SftpServer(
|
||||||
"Test Server Instance", testServerHost, 22,
|
"Test Server Instance", testServerHost, 22,
|
||||||
testServerUser, testServerPassword, testServerPath,
|
testServerUser, testServerPassword, testServerPath,
|
||||||
URI.create(testServerURL), null
|
URI.create(testServerURL)
|
||||||
);
|
);
|
||||||
|
|
||||||
assertThat(PieCannon.testServer(server)).isTrue();
|
assertThat(PieCannon.testServer(server)).isTrue();
|
||||||
|
Reference in New Issue
Block a user