From ef252f5a191c4c1f7f1abf5f750e8a5aad6a5ba3 Mon Sep 17 00:00:00 2001 From: Adrian Malacoda Date: Sun, 13 Dec 2020 22:06:59 -0600 Subject: [PATCH 1/3] ok, NOW add WebDavServer... --- .../piecannon/impl/WebDavServer.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 lib/src/main/java/net/monarchpass/piecannon/impl/WebDavServer.java diff --git a/lib/src/main/java/net/monarchpass/piecannon/impl/WebDavServer.java b/lib/src/main/java/net/monarchpass/piecannon/impl/WebDavServer.java new file mode 100644 index 0000000..d43dbcd --- /dev/null +++ b/lib/src/main/java/net/monarchpass/piecannon/impl/WebDavServer.java @@ -0,0 +1,37 @@ +package net.monarchpass.piecannon.impl; + +import java.io.IOException; +import java.net.URI; + +import com.google.common.io.ByteSource; + +import jodd.http.HttpRequest; +import lombok.Data; +import net.monarchpass.piecannon.Server; + +@Data +public class WebDavServer implements Server { + private final String label; + private final URI uri; + + private final String username; + private final String password; + + @Override + public URI upload (String name, ByteSource source) { + try { + final URI target = URI.create(uri.toString() + "/" + name.replace(" ", "%20")); + final HttpRequest request = HttpRequest.put(target.toString()) + .body(source.read(), ""); + + if (username != null && password != null) { + request.basicAuthentication(username, password); + } + + request.send(); + return target; + } catch (final IOException exception) { + throw new RuntimeException(exception); + } + } +} From b894978f92125f683b778f5abb786da27dde4183 Mon Sep 17 00:00:00 2001 From: Adrian Malacoda Date: Sun, 13 Dec 2020 22:17:01 -0600 Subject: [PATCH 2/3] readme: expand on currently supported server types --- README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index db521fb..d12a799 100644 --- a/README.md +++ b/README.md @@ -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. From be5b64789ae6648d5172e42f6c16d180a44b387a Mon Sep 17 00:00:00 2001 From: Adrian Malacoda Date: Sun, 13 Dec 2020 22:17:42 -0600 Subject: [PATCH 3/3] whitespace --- .../main/java/net/monarchpass/piecannon/util/ServerFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/net/monarchpass/piecannon/util/ServerFactory.java b/lib/src/main/java/net/monarchpass/piecannon/util/ServerFactory.java index bee6931..2ab525c 100644 --- a/lib/src/main/java/net/monarchpass/piecannon/util/ServerFactory.java +++ b/lib/src/main/java/net/monarchpass/piecannon/util/ServerFactory.java @@ -20,7 +20,7 @@ public class ServerFactory implements Function { .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")) {