Compare commits

...

8 Commits

5 changed files with 34 additions and 4 deletions

View File

@@ -28,4 +28,16 @@ TODO
## 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.
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.

View File

@@ -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/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/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/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"/>
@@ -10,7 +12,10 @@
<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/net/kothar/xdg-java/0.1.1/xdg-java-0.1.1.jar" enabled="true" runInBatchMode="false"/>
<<<<<<< HEAD
<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"/>
=======
>>>>>>> master
<factorypathentry kind="VARJAR" id="M2_REPO/org/projectlombok/lombok/1.18.16/lombok-1.18.16.jar" enabled="true" runInBatchMode="false"/>
</factorypath>

View File

@@ -61,8 +61,16 @@ public class App {
public static void testServers (final List<Server> servers) {
log.log(Level.INFO, "Testing all defined 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[] {
server.getClass().getSimpleName(), server.getLabel(), PieCannon.testServer(server)
server.getClass().getSimpleName(), server.getLabel(), result
});
}
}

View File

@@ -6,6 +6,7 @@ import java.net.URI;
import com.google.common.io.ByteSource;
import jodd.http.HttpRequest;
import jodd.http.HttpResponse;
import lombok.Data;
import net.monarchpass.piecannon.Server;
@@ -28,7 +29,11 @@ public class WebDavServer implements Server {
request.basicAuthentication(username, password);
}
request.send();
final HttpResponse response = request.send();
if (response.statusCode() >= 400) {
throw new RuntimeException(response.statusCode() + ": " + response.statusPhrase());
}
return target;
} catch (final IOException exception) {
throw new RuntimeException(exception);

View File

@@ -25,7 +25,7 @@ public class ServerFactory implements Function<JsonObject, Server> {
.orElse("webdav");
if (type.equals("webdav")) {
return makeWebDavServer(object);
return makeWebDavServer(object);
} else if (type.equalsIgnoreCase("gofile")) {
return new GoFileServer(Optional.ofNullable(object.getAsJsonPrimitive("label")).map(JsonPrimitive::getAsString).orElse("GoFile"));
} else if (type.equalsIgnoreCase("ftp")) {