Added RPC mode without preamble and annoying stuff.
This commit is contained in:
parent
02b700b07f
commit
2380c42089
@ -1,5 +1,6 @@
|
|||||||
package com.ryanmichela.sshd;
|
package com.ryanmichela.sshd;
|
||||||
|
|
||||||
|
import com.ryanmichela.sshd.implementations.SSHDCommandSender;
|
||||||
import jline.console.ConsoleReader;
|
import jline.console.ConsoleReader;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.core.Logger;
|
import org.apache.logging.log4j.core.Logger;
|
||||||
@ -12,9 +13,13 @@ import org.bukkit.Bukkit;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.util.logging.Level;
|
||||||
import java.util.logging.StreamHandler;
|
import java.util.logging.StreamHandler;
|
||||||
|
|
||||||
public class ConsoleShellFactory implements Factory<Command> {
|
public class ConsoleShellFactory implements Factory<Command> {
|
||||||
|
|
||||||
|
static SSHDCommandSender sshdCommandSender = new SSHDCommandSender();
|
||||||
|
|
||||||
public Command get() {
|
public Command get() {
|
||||||
return this.create();
|
return this.create();
|
||||||
}
|
}
|
||||||
@ -24,7 +29,6 @@ public class ConsoleShellFactory implements Factory<Command> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class ConsoleShell implements Command, Runnable {
|
public static class ConsoleShell implements Command, Runnable {
|
||||||
|
|
||||||
private InputStream in;
|
private InputStream in;
|
||||||
private OutputStream out;
|
private OutputStream out;
|
||||||
private OutputStream err;
|
private OutputStream err;
|
||||||
@ -33,7 +37,7 @@ public class ConsoleShellFactory implements Factory<Command> {
|
|||||||
private Thread thread;
|
private Thread thread;
|
||||||
|
|
||||||
StreamHandlerAppender streamHandlerAppender;
|
StreamHandlerAppender streamHandlerAppender;
|
||||||
ConsoleReader consoleReader;
|
public static ConsoleReader consoleReader;
|
||||||
|
|
||||||
public InputStream getIn() {
|
public InputStream getIn() {
|
||||||
return in;
|
return in;
|
||||||
@ -68,7 +72,6 @@ public class ConsoleShellFactory implements Factory<Command> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void start(Environment env) throws IOException {
|
public void start(Environment env) throws IOException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
consoleReader = new ConsoleReader(in, new FlushyOutputStream(out), new SshTerminal());
|
consoleReader = new ConsoleReader(in, new FlushyOutputStream(out), new SshTerminal());
|
||||||
consoleReader.setExpandEvents(true);
|
consoleReader.setExpandEvents(true);
|
||||||
@ -93,21 +96,25 @@ public class ConsoleShellFactory implements Factory<Command> {
|
|||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
printPreamble(consoleReader);
|
if (!SshdPlugin.instance.getConfig().getString("mode").equals("RPC"))
|
||||||
|
printPreamble(consoleReader);
|
||||||
while (true) {
|
while (true) {
|
||||||
String command = consoleReader.readLine("\r>", null);
|
String command = consoleReader.readLine("\r>", null);
|
||||||
if (command != null) {
|
if (command == null) continue;
|
||||||
if (command.equals("exit")) {
|
if (command.equals("exit")) break;
|
||||||
break;
|
Bukkit.getScheduler().runTask(SshdPlugin.instance, () -> {
|
||||||
}
|
if (SshdPlugin.instance.getConfig().getString("mode").equals("RPC") && command.startsWith("rpc")) {
|
||||||
SshdPlugin.instance.getLogger().info("<" + environment.getEnv().get(Environment.ENV_USER) + "> " + command);
|
//NO ECHO NO PREAMBLE AND SHIT
|
||||||
Bukkit.getScheduler().runTask(SshdPlugin.instance, () -> {
|
String cmd = command.substring("rpc".length() + 1, command.length());
|
||||||
|
Bukkit.dispatchCommand(sshdCommandSender, cmd);
|
||||||
|
} else {
|
||||||
|
SshdPlugin.instance.getLogger().info("<" + environment.getEnv().get(Environment.ENV_USER) + "> " + command);
|
||||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
|
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
SshdPlugin.instance.getLogger().severe("Error processing command from SSH");
|
SshdPlugin.instance.getLogger().log(Level.SEVERE, "Error processing command from SSH", e);
|
||||||
} finally {
|
} finally {
|
||||||
callback.onExit(0);
|
callback.onExit(0);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,69 @@
|
|||||||
|
package com.ryanmichela.sshd.implementations;
|
||||||
|
|
||||||
|
import com.ryanmichela.sshd.ConsoleShellFactory;
|
||||||
|
import com.ryanmichela.sshd.SshdPlugin;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
|
import org.bukkit.conversations.Conversation;
|
||||||
|
import org.bukkit.conversations.ConversationAbandonedEvent;
|
||||||
|
import org.bukkit.conversations.ManuallyAbandonedConversationCanceller;
|
||||||
|
import org.bukkit.craftbukkit.v1_12_R1.command.ServerCommandSender;
|
||||||
|
import org.bukkit.craftbukkit.v1_12_R1.conversations.ConversationTracker;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class SSHDCommandSender extends ServerCommandSender implements ConsoleCommandSender {
|
||||||
|
|
||||||
|
private final ConversationTracker conversationTracker = new ConversationTracker();
|
||||||
|
|
||||||
|
public void sendMessage(String message) {
|
||||||
|
this.sendRawMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendRawMessage(String message) {
|
||||||
|
try {
|
||||||
|
ConsoleShellFactory.ConsoleShell.consoleReader.println(ChatColor.stripColor(message) + "\r");
|
||||||
|
} catch (IOException e) {
|
||||||
|
SshdPlugin.instance.getLogger().log(Level.SEVERE, "Error sending message to SSHDCommandSender", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendMessage(String[] messages) {
|
||||||
|
Arrays.asList(messages).forEach(this::sendMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return "SSHD CONSOLE";
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isOp() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOp(boolean value) {
|
||||||
|
throw new UnsupportedOperationException("Cannot change operator status of server console");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean beginConversation(Conversation conversation) {
|
||||||
|
return this.conversationTracker.beginConversation(conversation);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void abandonConversation(Conversation conversation) {
|
||||||
|
this.conversationTracker.abandonConversation(conversation, new ConversationAbandonedEvent(conversation, new ManuallyAbandonedConversationCanceller()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void abandonConversation(Conversation conversation, ConversationAbandonedEvent details) {
|
||||||
|
this.conversationTracker.abandonConversation(conversation, details);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void acceptConversationInput(String input) {
|
||||||
|
this.conversationTracker.acceptConversationInput(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isConversing() {
|
||||||
|
return this.conversationTracker.isConversing();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -4,6 +4,9 @@ listenAddress: all
|
|||||||
# The port the SSH server will listen on.
|
# The port the SSH server will listen on.
|
||||||
port: 22
|
port: 22
|
||||||
|
|
||||||
|
# Operational mode. Don't touch if you don't know what you're doing. Can be either DEFAULT or RPC
|
||||||
|
mode: DEFAULT
|
||||||
|
|
||||||
# By default, only public key authentication is enabled. This is the most secure mode.
|
# By default, only public key authentication is enabled. This is the most secure mode.
|
||||||
# To authorize a user to log in with public key authentication, install their public
|
# To authorize a user to log in with public key authentication, install their public
|
||||||
# PEM certificate in the authorized_users directory. Name the key file with user's user
|
# PEM certificate in the authorized_users directory. Name the key file with user's user
|
||||||
|
Loading…
Reference in New Issue
Block a user