X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ffcp%2FFcpInterface.java;h=e66bb8d8293b354eead3f3180a5306e33429211e;hb=c2233cceb10f4403a7dd63dfc42fe8d1e4bdb07f;hp=3d76d42c34375df4c2579f5b9d2106a2eaf6e83e;hpb=d13fa7cfe7e5e3770b8ff06fc307a622fa28a5aa;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java b/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java index 3d76d42..e66bb8d 100644 --- a/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java +++ b/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java @@ -24,7 +24,6 @@ import java.util.logging.Level; import java.util.logging.Logger; import net.pterodactylus.sone.core.Core; -import net.pterodactylus.sone.freenet.fcp.Command; import net.pterodactylus.sone.freenet.fcp.Command.AccessType; import net.pterodactylus.sone.freenet.fcp.Command.ErrorResponse; import net.pterodactylus.sone.freenet.fcp.Command.Response; @@ -50,8 +49,11 @@ public class FcpInterface { /** Whether the FCP interface is currently active. */ private volatile boolean active; + /** Whether to allow write access from full access hosts only. */ + private volatile boolean allowWriteFromFullAccessOnly; + /** All available FCP commands. */ - private final Map commands = Collections.synchronizedMap(new HashMap()); + private final Map commands = Collections.synchronizedMap(new HashMap()); /** * Creates a new FCP interface. @@ -60,8 +62,9 @@ public class FcpInterface { * The core */ public FcpInterface(Core core) { - commands.put("Version", new VersionCommand()); + commands.put("Version", new VersionCommand(core)); commands.put("GetLocalSones", new GetLocalSonesCommand(core)); + commands.put("GetSones", new GetSonesCommand(core)); commands.put("GetPost", new GetPostCommand(core)); commands.put("GetPosts", new GetPostsCommand(core)); commands.put("GetPostFeed", new GetPostFeedCommand(core)); @@ -69,6 +72,8 @@ public class FcpInterface { commands.put("LikeReply", new LikeReplyCommand(core)); commands.put("CreatePost", new CreatePostCommand(core)); commands.put("CreateReply", new CreateReplyCommand(core)); + commands.put("DeletePost", new DeletePostCommand(core)); + commands.put("DeleteReply", new DeleteReplyCommand(core)); } // @@ -87,6 +92,17 @@ public class FcpInterface { this.active = active; } + /** + * Sets whether write access is only allowed from full access hosts. + * + * @param allowWriteFromFullAccessOnly + * {@code true} to allow write access only from full access + * hosts, {@code false} to always allow write access + */ + public void setAllowWriteFromFullAccessOnly(boolean allowWriteFromFullAccessOnly) { + this.allowWriteFromFullAccessOnly = allowWriteFromFullAccessOnly; + } + // // ACTIONS // @@ -114,7 +130,15 @@ public class FcpInterface { } return; } - Command command = commands.get(parameters.get("Message")); + AbstractSoneCommand command = commands.get(parameters.get("Message")); + if (allowWriteFromFullAccessOnly && command.requiresWriteAccess() && (accessType == FredPluginFCP.ACCESS_FCP_RESTRICTED)) { + try { + sendReply(pluginReplySender, null, new ErrorResponse(401, "No Write Access")); + } catch (PluginNotFoundException pnfe1) { + logger.log(Level.FINE, "Could not set error to plugin.", pnfe1); + } + return; + } try { if (command == null) { sendReply(pluginReplySender, null, new ErrorResponse("Unrecognized Message: " + parameters.get("Message")));