Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc76da9ac1 | ||
|
|
7330b1eead | ||
|
|
8f6319d979 | ||
|
|
272e7cf8dc | ||
|
|
69d31175d4 | ||
|
|
16f5c063ce | ||
|
|
2f1e03d7a2 | ||
|
|
32f65a506e | ||
|
|
703c69b055 | ||
|
|
15faff3dd4 | ||
|
|
dc8e49f643 | ||
|
|
2380c42089 | ||
|
|
02b700b07f | ||
|
|
87cb4d8929 | ||
|
|
ac6a552e95 | ||
|
|
0951c6f971 | ||
|
|
5a9a5245b9 | ||
|
|
396351771c | ||
|
|
f034cef465 | ||
|
|
956f0cc3ef | ||
|
|
027605e743 | ||
|
|
be9c53bf6f |
4
.travis.yml
Normal file
4
.travis.yml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
sudo: false
|
||||||
|
language: java
|
||||||
|
jdk:
|
||||||
|
- oraclejdk8
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
Bukkit-SSHD
|
Bukkit-SSHD
|
||||||
===========
|
===========
|
||||||
|
|
||||||
|
[](https://travis-ci.org/rmichela/Bukkit-SSHD)
|
||||||
|
|
||||||
An SSHD daemon embedded in a Bukkit plugin.
|
An SSHD daemon embedded in a Bukkit plugin.
|
||||||
|
|||||||
105
pom.xml
105
pom.xml
@@ -6,14 +6,14 @@
|
|||||||
|
|
||||||
<groupId>com.ryanmichela</groupId>
|
<groupId>com.ryanmichela</groupId>
|
||||||
<artifactId>SSHD</artifactId>
|
<artifactId>SSHD</artifactId>
|
||||||
<version>1.1</version>
|
<version>1.3.4.1</version>
|
||||||
<url>http://dev.bukkit.org/server-mods/sshd/</url>
|
<url>http://dev.bukkit.org/server-mods/sshd/</url>
|
||||||
|
|
||||||
<!-- Repositories -->
|
<!-- Repositories -->
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>bukkit-repo</id>
|
<id>spigot-repo</id>
|
||||||
<url>http://repo.bukkit.org/content/groups/public/</url>
|
<url>https://hub.spigotmc.org/nexus/content/groups/public</url>
|
||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
@@ -29,58 +29,107 @@
|
|||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bukkit</groupId>
|
<groupId>org.bukkit</groupId>
|
||||||
<artifactId>craftbukkit</artifactId>
|
<artifactId>bukkit</artifactId>
|
||||||
<version>1.7.9-R0.2</version>
|
<version>1.12.2-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
|
||||||
<type>jar</type>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.sshd</groupId>
|
<groupId>org.apache.sshd</groupId>
|
||||||
<artifactId>sshd-core</artifactId>
|
<artifactId>sshd-core</artifactId>
|
||||||
<version>0.9.0</version>
|
<version>1.6.0</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.mina</groupId>
|
||||||
|
<artifactId>mina-core</artifactId>
|
||||||
|
<version>2.0.16</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
<version>1.7.25</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-jdk14</artifactId>
|
||||||
|
<version>1.7.25</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>jline</groupId>
|
||||||
|
<artifactId>jline</artifactId>
|
||||||
|
<version>2.12.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-core</artifactId>
|
||||||
|
<version>2.0</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-api</artifactId>
|
||||||
|
<version>2.1</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-codec</groupId>
|
||||||
|
<artifactId>commons-codec</artifactId>
|
||||||
|
<version>1.10</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
<!-- Build -->
|
<!-- Build -->
|
||||||
<build>
|
<build>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<targetPath>.</targetPath>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
<directory>${basedir}/src/main/resources</directory>
|
||||||
|
<includes>
|
||||||
|
<include>plugin.yml</include>
|
||||||
|
<include>config.yml</include>
|
||||||
|
</includes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
|
||||||
<plugins>
|
<plugins>
|
||||||
<!-- Shade plugin -->
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<version>3.1.0</version>
|
||||||
<version>1.5</version>
|
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>package</phase>
|
<phase>package</phase>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>shade</goal>
|
<goal>single</goal>
|
||||||
</goals>
|
</goals>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
<configuration>
|
<configuration>
|
||||||
<filters>
|
<finalName>${project.name}-${project.version}</finalName>
|
||||||
<filter>
|
<appendAssemblyId>false</appendAssemblyId>
|
||||||
<artifact>*:*</artifact>
|
<descriptorRefs>
|
||||||
<excludes>
|
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||||
<exclude>META-INF/*.SF</exclude>
|
</descriptorRefs>
|
||||||
<exclude>META-INF/*.DSA</exclude>
|
|
||||||
<exclude>META-INF/*.RSA</exclude>
|
|
||||||
</excludes>
|
|
||||||
</filter>
|
|
||||||
</filters>
|
|
||||||
<minimizeJar>true</minimizeJar>
|
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<!-- Compile plugin -->
|
<!-- Compile plugin -->
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.0</version>
|
<version>3.5.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>1.6</source>
|
<source>1.8</source>
|
||||||
<target>1.6</target>
|
<target>1.8</target>
|
||||||
<showDeprecation>true</showDeprecation>
|
<showDeprecation>true</showDeprecation>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.ryanmichela.sshd;
|
package com.ryanmichela.sshd;
|
||||||
|
|
||||||
import org.apache.sshd.server.PasswordAuthenticator;
|
import org.apache.sshd.server.auth.password.PasswordAuthenticator;
|
||||||
import org.apache.sshd.server.session.ServerSession;
|
import org.apache.sshd.server.session.ServerSession;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -10,6 +10,7 @@ import java.util.Map;
|
|||||||
* Copyright 2013 Ryan Michela
|
* Copyright 2013 Ryan Michela
|
||||||
*/
|
*/
|
||||||
public class ConfigPasswordAuthenticator implements PasswordAuthenticator {
|
public class ConfigPasswordAuthenticator implements PasswordAuthenticator {
|
||||||
|
|
||||||
private Map<String, Integer> failCounts = new HashMap<String, Integer>();
|
private Map<String, Integer> failCounts = new HashMap<String, Integer>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -4,15 +4,16 @@ package com.ryanmichela.sshd;
|
|||||||
* Copyright 2013 Ryan Michela
|
* Copyright 2013 Ryan Michela
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import jline.console.completer.Completer;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandMap;
|
import org.bukkit.command.CommandMap;
|
||||||
import org.bukkit.craftbukkit.libs.jline.console.completer.Completer;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class ConsoleCommandCompleter implements Completer {
|
public class ConsoleCommandCompleter implements Completer {
|
||||||
|
|
||||||
public int complete(final String buffer, final int cursor, final List<CharSequence> candidates) {
|
public int complete(final String buffer, final int cursor, final List<CharSequence> candidates) {
|
||||||
Waitable<List<String>> waitable = new Waitable<List<String>>() {
|
Waitable<List<String>> waitable = new Waitable<List<String>>() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -14,12 +14,14 @@ import java.io.OutputStream;
|
|||||||
* Copyright 2013 Ryan Michela
|
* Copyright 2013 Ryan Michela
|
||||||
*/
|
*/
|
||||||
public class ConsoleCommandFactory implements CommandFactory {
|
public class ConsoleCommandFactory implements CommandFactory {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Command createCommand(String command) {
|
public Command createCommand(String command) {
|
||||||
return new ConsoleCommand(command);
|
return new ConsoleCommand(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ConsoleCommand implements Command {
|
public class ConsoleCommand implements Command {
|
||||||
|
|
||||||
private String command;
|
private String command;
|
||||||
|
|
||||||
private InputStream in;
|
private InputStream in;
|
||||||
@@ -50,7 +52,8 @@ public class ConsoleCommandFactory implements CommandFactory {
|
|||||||
@Override
|
@Override
|
||||||
public void start(Environment environment) throws IOException {
|
public void start(Environment environment) throws IOException {
|
||||||
try {
|
try {
|
||||||
SshdPlugin.instance.getLogger().info("[U: " + environment.getEnv().get(Environment.ENV_USER) + "] " + command);
|
SshdPlugin.instance.getLogger()
|
||||||
|
.info("[U: " + environment.getEnv().get(Environment.ENV_USER) + "] " + command);
|
||||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
|
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
SshdPlugin.instance.getLogger().severe("Error processing command from SSH -" + e.getMessage());
|
SshdPlugin.instance.getLogger().severe("Error processing command from SSH -" + e.getMessage());
|
||||||
|
|||||||
@@ -4,9 +4,14 @@ package com.ryanmichela.sshd;
|
|||||||
* Copyright 2013 Ryan Michela
|
* Copyright 2013 Ryan Michela
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.fusesource.jansi.Ansi;
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.EnumMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.logging.Formatter;
|
import java.util.logging.Formatter;
|
||||||
import java.util.logging.LogRecord;
|
import java.util.logging.LogRecord;
|
||||||
|
|
||||||
@@ -19,10 +24,16 @@ public class ConsoleLogFormatter extends Formatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String format(LogRecord logrecord) {
|
public String format(LogRecord logrecord) {
|
||||||
|
try {
|
||||||
|
Class.forName("org.bukkit.craftbukkit.command.ColouredConsoleSender");
|
||||||
|
} catch (ClassNotFoundException ignored) {
|
||||||
|
// MEANS WE'RE ON PAPER/TACO/OTHER SHIT
|
||||||
|
colorize(logrecord);
|
||||||
|
}
|
||||||
StringBuilder stringbuilder = new StringBuilder();
|
StringBuilder stringbuilder = new StringBuilder();
|
||||||
|
|
||||||
stringbuilder.append(" [");
|
stringbuilder.append(" [");
|
||||||
stringbuilder.append(this.dateFormat.format(Long.valueOf(logrecord.getMillis()))).append(" ");
|
stringbuilder.append(this.dateFormat.format(logrecord.getMillis())).append(" ");
|
||||||
|
|
||||||
stringbuilder.append(logrecord.getLevel().getName()).append("]: ");
|
stringbuilder.append(logrecord.getLevel().getName()).append("]: ");
|
||||||
stringbuilder.append(this.formatMessage(logrecord));
|
stringbuilder.append(this.formatMessage(logrecord));
|
||||||
@@ -38,5 +49,53 @@ public class ConsoleLogFormatter extends Formatter {
|
|||||||
|
|
||||||
return stringbuilder.toString();
|
return stringbuilder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void colorize(LogRecord logrecord) {
|
||||||
|
// ORIGINAL CODE FROM org.bukkit.craftbukkit.command.ColouredConsoleSender
|
||||||
|
final Map<ChatColor, String> replacements = new EnumMap<>(ChatColor.class);
|
||||||
|
|
||||||
|
replacements
|
||||||
|
.put(ChatColor.BLACK, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLACK).boldOff().toString());
|
||||||
|
replacements
|
||||||
|
.put(ChatColor.DARK_BLUE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLUE).boldOff().toString());
|
||||||
|
replacements.put(ChatColor.DARK_GREEN,
|
||||||
|
Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.GREEN).boldOff().toString());
|
||||||
|
replacements
|
||||||
|
.put(ChatColor.DARK_AQUA, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.CYAN).boldOff().toString());
|
||||||
|
replacements
|
||||||
|
.put(ChatColor.DARK_RED, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.RED).boldOff().toString());
|
||||||
|
replacements.put(ChatColor.DARK_PURPLE,
|
||||||
|
Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.MAGENTA).boldOff().toString());
|
||||||
|
replacements
|
||||||
|
.put(ChatColor.GOLD, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.YELLOW).boldOff().toString());
|
||||||
|
replacements.put(ChatColor.GRAY, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.WHITE).boldOff().toString());
|
||||||
|
replacements
|
||||||
|
.put(ChatColor.DARK_GRAY, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLACK).bold().toString());
|
||||||
|
replacements.put(ChatColor.BLUE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLUE).bold().toString());
|
||||||
|
replacements.put(ChatColor.GREEN, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.GREEN).bold().toString());
|
||||||
|
replacements.put(ChatColor.AQUA, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.CYAN).bold().toString());
|
||||||
|
replacements.put(ChatColor.RED, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.RED).bold().toString());
|
||||||
|
replacements.put(ChatColor.LIGHT_PURPLE,
|
||||||
|
Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.MAGENTA).bold().toString());
|
||||||
|
replacements.put(ChatColor.YELLOW, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.YELLOW).bold().toString());
|
||||||
|
replacements.put(ChatColor.WHITE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.WHITE).bold().toString());
|
||||||
|
replacements.put(ChatColor.MAGIC, Ansi.ansi().a(Ansi.Attribute.BLINK_SLOW).toString());
|
||||||
|
replacements.put(ChatColor.BOLD, Ansi.ansi().a(Ansi.Attribute.UNDERLINE_DOUBLE).toString());
|
||||||
|
replacements.put(ChatColor.STRIKETHROUGH, Ansi.ansi().a(Ansi.Attribute.STRIKETHROUGH_ON).toString());
|
||||||
|
replacements.put(ChatColor.UNDERLINE, Ansi.ansi().a(Ansi.Attribute.UNDERLINE).toString());
|
||||||
|
replacements.put(ChatColor.ITALIC, Ansi.ansi().a(Ansi.Attribute.ITALIC).toString());
|
||||||
|
replacements.put(ChatColor.RESET, Ansi.ansi().a(Ansi.Attribute.RESET).toString());
|
||||||
|
|
||||||
|
String result = logrecord.getMessage();
|
||||||
|
for (ChatColor color : ChatColor.values()) {
|
||||||
|
if (replacements.containsKey(color)) {
|
||||||
|
result = result.replaceAll("(?i)" + color.toString(), replacements.get(color));
|
||||||
|
} else {
|
||||||
|
result = result.replaceAll("(?i)" + color.toString(), "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result += Ansi.ansi().reset().toString();
|
||||||
|
logrecord.setMessage(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.ryanmichela.sshd;
|
package com.ryanmichela.sshd;
|
||||||
|
|
||||||
|
import com.ryanmichela.sshd.implementations.SSHDCommandSender;
|
||||||
|
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;
|
||||||
import org.apache.sshd.common.Factory;
|
import org.apache.sshd.common.Factory;
|
||||||
@@ -7,15 +9,21 @@ import org.apache.sshd.server.Command;
|
|||||||
import org.apache.sshd.server.Environment;
|
import org.apache.sshd.server.Environment;
|
||||||
import org.apache.sshd.server.ExitCallback;
|
import org.apache.sshd.server.ExitCallback;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader;
|
|
||||||
|
|
||||||
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() {
|
||||||
|
return this.create();
|
||||||
|
}
|
||||||
|
|
||||||
public Command create() {
|
public Command create() {
|
||||||
return new ConsoleShell();
|
return new ConsoleShell();
|
||||||
}
|
}
|
||||||
@@ -30,7 +38,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;
|
||||||
@@ -65,7 +73,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);
|
||||||
@@ -89,38 +96,45 @@ public class ConsoleShellFactory implements Factory<Command> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
String command;
|
|
||||||
try {
|
try {
|
||||||
printPreamble(consoleReader);
|
if (!SshdPlugin.instance.getConfig().getString("mode").equals("RPC"))
|
||||||
while(true) {
|
printPreamble(consoleReader);
|
||||||
command = consoleReader.readLine("\r>", null);
|
while (true) {
|
||||||
if (command != null) {
|
String command = consoleReader.readLine("\r>", null);
|
||||||
if (command.equals("exit")) {
|
if (command == null) continue;
|
||||||
break;
|
if (command.equals("exit") || command.equals("quit")) break;
|
||||||
|
Bukkit.getScheduler().runTask(SshdPlugin.instance, () -> {
|
||||||
|
if (SshdPlugin.instance.getConfig().getString("mode").equals("RPC") &&
|
||||||
|
command.startsWith("rpc")) {
|
||||||
|
//NO ECHO NO PREAMBLE AND SHIT
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
SshdPlugin.instance.getLogger().info("<" + environment.getEnv().get(Environment.ENV_USER) + "> " + 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printPreamble(ConsoleReader consoleReader) throws IOException{
|
private void printPreamble(ConsoleReader consoleReader) throws IOException {
|
||||||
consoleReader.println(" _____ _____ _ _ _____");
|
consoleReader.println(" _____ _____ _ _ _____" + "\r");
|
||||||
consoleReader.println(" / ____/ ____| | | | __ \\");
|
consoleReader.println(" / ____/ ____| | | | __ \\" + "\r");
|
||||||
consoleReader.println("| (___| (___ | |__| | | | |");
|
consoleReader.println("| (___| (___ | |__| | | | |" + "\r");
|
||||||
consoleReader.println(" \\___ \\\\___ \\| __ | | | |");
|
consoleReader.println(" \\___ \\\\___ \\| __ | | | |" + "\r");
|
||||||
consoleReader.println(" ____) |___) | | | | |__| |");
|
consoleReader.println(" ____) |___) | | | | |__| |" + "\r");
|
||||||
consoleReader.println("|_____/_____/|_| |_|_____/");
|
consoleReader.println("|_____/_____/|_| |_|_____/" + "\r");
|
||||||
consoleReader.println("Connected to: " + Bukkit.getServer().getName());
|
consoleReader.println("Connected to: " + Bukkit.getServer().getName() + "\r");
|
||||||
consoleReader.println("- " + Bukkit.getServer().getMotd());
|
consoleReader.println("- " + Bukkit.getServer().getMotd() + "\r");
|
||||||
consoleReader.println();
|
consoleReader.println("\r");
|
||||||
consoleReader.println("Type 'exit' to exit the shell.");
|
consoleReader.println("Type 'exit' to exit the shell." + "\r");
|
||||||
consoleReader.println("===============================================");
|
consoleReader.println("===============================================" + "\r");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.ryanmichela.sshd;
|
package com.ryanmichela.sshd;
|
||||||
|
|
||||||
|
import org.apache.sshd.common.SshException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
@@ -7,7 +9,9 @@ import java.io.OutputStream;
|
|||||||
* Copyright 2013 Ryan Michela
|
* Copyright 2013 Ryan Michela
|
||||||
*/
|
*/
|
||||||
public class FlushyOutputStream extends OutputStream {
|
public class FlushyOutputStream extends OutputStream {
|
||||||
|
|
||||||
private OutputStream base;
|
private OutputStream base;
|
||||||
|
private boolean isClosed = false;
|
||||||
|
|
||||||
public FlushyOutputStream(OutputStream base) {
|
public FlushyOutputStream(OutputStream base) {
|
||||||
this.base = base;
|
this.base = base;
|
||||||
@@ -15,19 +19,31 @@ public class FlushyOutputStream extends OutputStream {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(int b) throws IOException {
|
public void write(int b) throws IOException {
|
||||||
|
if (isClosed) return;
|
||||||
base.write(b);
|
base.write(b);
|
||||||
base.flush();
|
base.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(byte[] b) throws IOException {
|
public void write(byte[] b) throws IOException {
|
||||||
|
if (isClosed) return;
|
||||||
base.write(b);
|
base.write(b);
|
||||||
base.flush();
|
base.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(byte[] b, int off, int len) throws IOException {
|
public void write(byte[] b, int off, int len) throws IOException {
|
||||||
base.write(b, off, len);
|
if (isClosed) return;
|
||||||
base.flush();
|
try {
|
||||||
|
base.write(b, off, len);
|
||||||
|
base.flush();
|
||||||
|
} catch (SshException e) {
|
||||||
|
if (!e.getMessage().contains("channel already closed")) throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
isClosed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.ryanmichela.sshd;
|
package com.ryanmichela.sshd;
|
||||||
|
|
||||||
|
import jline.console.ConsoleReader;
|
||||||
import org.apache.sshd.common.SshException;
|
import org.apache.sshd.common.SshException;
|
||||||
import org.bukkit.craftbukkit.libs.jline.console.ConsoleReader;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
@@ -11,6 +11,7 @@ import java.util.logging.*;
|
|||||||
* Copyright 2013 Ryan Michela
|
* Copyright 2013 Ryan Michela
|
||||||
*/
|
*/
|
||||||
public class FlushyStreamHandler extends StreamHandler {
|
public class FlushyStreamHandler extends StreamHandler {
|
||||||
|
|
||||||
private ConsoleReader reader;
|
private ConsoleReader reader;
|
||||||
|
|
||||||
public FlushyStreamHandler(OutputStream out, Formatter formatter, ConsoleReader reader) {
|
public FlushyStreamHandler(OutputStream out, Formatter formatter, ConsoleReader reader) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.ryanmichela.sshd;
|
package com.ryanmichela.sshd;
|
||||||
|
|
||||||
import org.apache.mina.util.Base64;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
|
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
@@ -13,6 +13,7 @@ import java.security.spec.RSAPublicKeySpec;
|
|||||||
* Copyright 2013 Ryan Michela
|
* Copyright 2013 Ryan Michela
|
||||||
*/
|
*/
|
||||||
public class PemDecoder extends java.io.BufferedReader {
|
public class PemDecoder extends java.io.BufferedReader {
|
||||||
|
|
||||||
private static final String BEGIN = "^-+\\s*BEGIN.+";
|
private static final String BEGIN = "^-+\\s*BEGIN.+";
|
||||||
private static final String END = "^-+\\s*END.+";
|
private static final String END = "^-+\\s*END.+";
|
||||||
private static final String COMMENT = "Comment:";
|
private static final String COMMENT = "Comment:";
|
||||||
@@ -22,14 +23,14 @@ public class PemDecoder extends java.io.BufferedReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public PublicKey getPemBytes() throws Exception {
|
public PublicKey getPemBytes() throws Exception {
|
||||||
StringBuffer b64 = new StringBuffer();
|
StringBuilder b64 = new StringBuilder();
|
||||||
|
|
||||||
String line = readLine();
|
String line = readLine();
|
||||||
if (!line.matches(BEGIN)) {
|
if (!line.matches(BEGIN)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(line = readLine(); line != null; line = readLine()) {
|
for (line = readLine(); line != null; line = readLine()) {
|
||||||
if (!line.matches(END) && !line.startsWith(COMMENT)) {
|
if (!line.matches(END) && !line.startsWith(COMMENT)) {
|
||||||
b64.append(line.trim());
|
b64.append(line.trim());
|
||||||
}
|
}
|
||||||
@@ -84,7 +85,7 @@ public class PemDecoder extends java.io.BufferedReader {
|
|||||||
|
|
||||||
private int decodeInt() {
|
private int decodeInt() {
|
||||||
return ((bytes[pos++] & 0xFF) << 24) | ((bytes[pos++] & 0xFF) << 16)
|
return ((bytes[pos++] & 0xFF) << 24) | ((bytes[pos++] & 0xFF) << 16)
|
||||||
| ((bytes[pos++] & 0xFF) << 8) | (bytes[pos++] & 0xFF);
|
| ((bytes[pos++] & 0xFF) << 8) | (bytes[pos++] & 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
private BigInteger decodeBigInt() {
|
private BigInteger decodeBigInt() {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.ryanmichela.sshd;
|
package com.ryanmichela.sshd;
|
||||||
|
|
||||||
import org.apache.commons.lang.ArrayUtils;
|
import org.apache.commons.lang.ArrayUtils;
|
||||||
import org.apache.sshd.server.PublickeyAuthenticator;
|
import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;
|
||||||
import org.apache.sshd.server.session.ServerSession;
|
import org.apache.sshd.server.session.ServerSession;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -12,6 +12,7 @@ import java.security.PublicKey;
|
|||||||
* Copyright 2013 Ryan Michela
|
* Copyright 2013 Ryan Michela
|
||||||
*/
|
*/
|
||||||
public class PublicKeyAuthenticator implements PublickeyAuthenticator {
|
public class PublicKeyAuthenticator implements PublickeyAuthenticator {
|
||||||
|
|
||||||
private File authorizedKeysDir;
|
private File authorizedKeysDir;
|
||||||
|
|
||||||
public PublicKeyAuthenticator(File authorizedKeysDir) {
|
public PublicKeyAuthenticator(File authorizedKeysDir) {
|
||||||
@@ -39,10 +40,13 @@ public class PublicKeyAuthenticator implements PublickeyAuthenticator {
|
|||||||
SshdPlugin.instance.getLogger().severe("Failed to parse PEM file. " + keyFile.getAbsolutePath());
|
SshdPlugin.instance.getLogger().severe("Failed to parse PEM file. " + keyFile.getAbsolutePath());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
SshdPlugin.instance.getLogger().severe("Failed to process public key " + keyFile.getAbsolutePath() + ". " + e.getMessage());
|
SshdPlugin.instance.getLogger()
|
||||||
|
.severe("Failed to process public key " + keyFile.getAbsolutePath() + ". " + e.getMessage());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
SshdPlugin.instance.getLogger().warning("Could not locate public key for " + username + ". Make sure the user's key is named the same as their user name without a file extension.");
|
SshdPlugin.instance.getLogger().warning("Could not locate public key for " + username +
|
||||||
|
". Make sure the user's key is named the same as their user name " +
|
||||||
|
"without a file extension.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import java.lang.reflect.Modifier;
|
|||||||
* Copyright 2013 Ryan Michela
|
* Copyright 2013 Ryan Michela
|
||||||
*/
|
*/
|
||||||
public class ReflectionUtil {
|
public class ReflectionUtil {
|
||||||
|
|
||||||
public static void setProtectedValue(Object o, String field, Object newValue) {
|
public static void setProtectedValue(Object o, String field, Object newValue) {
|
||||||
setProtectedValue(o.getClass(), o, field, newValue);
|
setProtectedValue(o.getClass(), o, field, newValue);
|
||||||
}
|
}
|
||||||
@@ -28,9 +29,7 @@ public class ReflectionUtil {
|
|||||||
modifiersField.setInt(f, f.getModifiers() & ~Modifier.FINAL);
|
modifiersField.setInt(f, f.getModifiers() & ~Modifier.FINAL);
|
||||||
|
|
||||||
f.set(o, newValue);
|
f.set(o, newValue);
|
||||||
} catch (NoSuchFieldException ex) {
|
} catch (NoSuchFieldException | IllegalAccessException ex) {
|
||||||
System.out.println("*** " + c.getName() + ":" + ex);
|
|
||||||
} catch (IllegalAccessException ex) {
|
|
||||||
System.out.println("*** " + c.getName() + ":" + ex);
|
System.out.println("*** " + c.getName() + ":" + ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -38,9 +37,9 @@ public class ReflectionUtil {
|
|||||||
public static <T> T getProtectedValue(Object obj, String fieldName) {
|
public static <T> T getProtectedValue(Object obj, String fieldName) {
|
||||||
try {
|
try {
|
||||||
Class c = obj.getClass();
|
Class c = obj.getClass();
|
||||||
while(c != Object.class) {
|
while (c != Object.class) {
|
||||||
Field[] fields = c.getDeclaredFields();
|
Field[] fields = c.getDeclaredFields();
|
||||||
for(Field f : fields) {
|
for (Field f : fields) {
|
||||||
if (f.getName() == fieldName) {
|
if (f.getName() == fieldName) {
|
||||||
f.setAccessible(true);
|
f.setAccessible(true);
|
||||||
return (T) f.get(obj);
|
return (T) f.get(obj);
|
||||||
@@ -78,7 +77,7 @@ public class ReflectionUtil {
|
|||||||
public static Object invokeProtectedMethod(Class c, Object o, String method, Object... args) {
|
public static Object invokeProtectedMethod(Class c, Object o, String method, Object... args) {
|
||||||
try {
|
try {
|
||||||
Class[] pTypes = new Class[args.length];
|
Class[] pTypes = new Class[args.length];
|
||||||
for(int i = 0; i < args.length; i++) {
|
for (int i = 0; i < args.length; i++) {
|
||||||
if (args[i] instanceof Integer) {
|
if (args[i] instanceof Integer) {
|
||||||
pTypes[i] = int.class;
|
pTypes[i] = int.class;
|
||||||
} else {
|
} else {
|
||||||
@@ -89,8 +88,7 @@ public class ReflectionUtil {
|
|||||||
Method m = c.getDeclaredMethod(method, pTypes);
|
Method m = c.getDeclaredMethod(method, pTypes);
|
||||||
m.setAccessible(true);
|
m.setAccessible(true);
|
||||||
return m.invoke(o, args);
|
return m.invoke(o, args);
|
||||||
}
|
} catch (Exception ex) {
|
||||||
catch (Exception ex) {
|
|
||||||
System.out.println("*** " + c.getName() + "." + method + "(): " + ex);
|
System.out.println("*** " + c.getName() + "." + method + "(): " + ex);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.ryanmichela.sshd;
|
package com.ryanmichela.sshd;
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.libs.jline.TerminalSupport;
|
import jline.TerminalSupport;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copyright 2013 Ryan Michela
|
* Copyright 2013 Ryan Michela
|
||||||
|
|||||||
@@ -1,17 +1,22 @@
|
|||||||
package com.ryanmichela.sshd;
|
package com.ryanmichela.sshd;
|
||||||
|
|
||||||
import org.apache.sshd.SshServer;
|
import org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory;
|
||||||
|
import org.apache.sshd.server.SshServer;
|
||||||
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
|
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
|
||||||
|
import org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.FileSystems;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copyright 2013 Ryan Michela
|
* Copyright 2013 Ryan Michela
|
||||||
*/
|
*/
|
||||||
public class SshdPlugin extends JavaPlugin {
|
public class SshdPlugin extends JavaPlugin {
|
||||||
|
|
||||||
private SshServer sshd;
|
private SshServer sshd;
|
||||||
public static SshdPlugin instance;
|
public static SshdPlugin instance;
|
||||||
|
|
||||||
@@ -35,19 +40,31 @@ public class SshdPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
sshd = SshServer.setUpDefaultServer();
|
sshd = SshServer.setUpDefaultServer();
|
||||||
sshd.setPort(getConfig().getInt("port", 22));
|
sshd.setPort(getConfig().getInt("port", 22));
|
||||||
|
String host = getConfig().getString("listenAddress", "all");
|
||||||
|
sshd.setHost(host.equals("all") ? null : host);
|
||||||
|
|
||||||
File hostKey = new File(getDataFolder(), "hostkey");
|
File hostKey = new File(getDataFolder(), "hostkey");
|
||||||
File authorizedKeys = new File(getDataFolder(), "authorized_keys");
|
File authorizedKeys = new File(getDataFolder(), "authorized_keys");
|
||||||
|
|
||||||
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(hostKey.getPath()));
|
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(hostKey));
|
||||||
sshd.setShellFactory(new ConsoleShellFactory());
|
sshd.setShellFactory(new ConsoleShellFactory());
|
||||||
sshd.setPasswordAuthenticator(new ConfigPasswordAuthenticator());
|
sshd.setPasswordAuthenticator(new ConfigPasswordAuthenticator());
|
||||||
sshd.setPublickeyAuthenticator(new PublicKeyAuthenticator(authorizedKeys));
|
sshd.setPublickeyAuthenticator(new PublicKeyAuthenticator(authorizedKeys));
|
||||||
|
|
||||||
|
if (getConfig().getBoolean("enableSFTP")) {
|
||||||
|
sshd.setSubsystemFactories(Collections.singletonList(new SftpSubsystemFactory()));
|
||||||
|
sshd.setFileSystemFactory(new VirtualFileSystemFactory(
|
||||||
|
FileSystems.getDefault().getPath(
|
||||||
|
getDataFolder().getAbsolutePath()
|
||||||
|
).getParent().getParent()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
sshd.setCommandFactory(new ConsoleCommandFactory());
|
sshd.setCommandFactory(new ConsoleCommandFactory());
|
||||||
try {
|
try {
|
||||||
sshd.start();
|
sshd.start();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
getLogger().severe("Failed to start SSH server! " + e.getMessage());
|
getLogger().log(Level.SEVERE, "Failed to start SSH server! ", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import java.util.logging.StreamHandler;
|
|||||||
* Copyright 2014 Ryan Michela
|
* Copyright 2014 Ryan Michela
|
||||||
*/
|
*/
|
||||||
public class StreamHandlerAppender implements Appender {
|
public class StreamHandlerAppender implements Appender {
|
||||||
|
|
||||||
private StreamHandler streamHandler;
|
private StreamHandler streamHandler;
|
||||||
private UUID uuid;
|
private UUID uuid;
|
||||||
|
|
||||||
@@ -25,15 +26,18 @@ public class StreamHandlerAppender implements Appender {
|
|||||||
@Override
|
@Override
|
||||||
public void append(LogEvent logEvent) {
|
public void append(LogEvent logEvent) {
|
||||||
java.util.logging.Level level;
|
java.util.logging.Level level;
|
||||||
switch (logEvent.getLevel())
|
|
||||||
{
|
|
||||||
case DEBUG: level = java.util.logging.Level.FINE; break;
|
|
||||||
case INFO: level = java.util.logging.Level.INFO; break;
|
|
||||||
case WARN: level = java.util.logging.Level.WARNING; break;
|
|
||||||
case ERROR: level = java.util.logging.Level.SEVERE; break;
|
|
||||||
default: level = java.util.logging.Level.INFO; break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (logEvent.getLevel().equals(org.apache.logging.log4j.Level.DEBUG)) {
|
||||||
|
level = java.util.logging.Level.FINE;
|
||||||
|
} else if (logEvent.getLevel().equals(org.apache.logging.log4j.Level.INFO)) {
|
||||||
|
level = java.util.logging.Level.INFO;
|
||||||
|
} else if (logEvent.getLevel().equals(org.apache.logging.log4j.Level.WARN)) {
|
||||||
|
level = java.util.logging.Level.WARNING;
|
||||||
|
} else if (logEvent.getLevel().equals(org.apache.logging.log4j.Level.ERROR)) {
|
||||||
|
level = java.util.logging.Level.SEVERE;
|
||||||
|
} else {
|
||||||
|
level = java.util.logging.Level.INFO;
|
||||||
|
}
|
||||||
String message = logEvent.getMessage().getFormattedMessage();
|
String message = logEvent.getMessage().getFormattedMessage();
|
||||||
|
|
||||||
|
|
||||||
@@ -80,4 +84,9 @@ public class StreamHandlerAppender implements Appender {
|
|||||||
public boolean isStarted() {
|
public boolean isStarted() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isStopped() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,11 +6,13 @@ import java.util.concurrent.ExecutionException;
|
|||||||
* Copyright 2013 Ryan Michela
|
* Copyright 2013 Ryan Michela
|
||||||
*/
|
*/
|
||||||
public abstract class Waitable<T> implements Runnable {
|
public abstract class Waitable<T> implements Runnable {
|
||||||
|
|
||||||
private enum Status {
|
private enum Status {
|
||||||
WAITING,
|
WAITING,
|
||||||
RUNNING,
|
RUNNING,
|
||||||
FINISHED,
|
FINISHED,
|
||||||
}
|
}
|
||||||
|
|
||||||
Throwable t = null;
|
Throwable t = null;
|
||||||
T value = null;
|
T value = null;
|
||||||
Status status = Status.WAITING;
|
Status status = Status.WAITING;
|
||||||
|
|||||||
@@ -0,0 +1,130 @@
|
|||||||
|
package com.ryanmichela.sshd.implementations;
|
||||||
|
|
||||||
|
import com.ryanmichela.sshd.ConsoleShellFactory;
|
||||||
|
import com.ryanmichela.sshd.SshdPlugin;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
|
import org.bukkit.conversations.Conversation;
|
||||||
|
import org.bukkit.conversations.ConversationAbandonedEvent;
|
||||||
|
import org.bukkit.conversations.ManuallyAbandonedConversationCanceller;
|
||||||
|
import org.bukkit.permissions.PermissibleBase;
|
||||||
|
import org.bukkit.permissions.Permission;
|
||||||
|
import org.bukkit.permissions.PermissionAttachment;
|
||||||
|
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class SSHDCommandSender implements ConsoleCommandSender, CommandSender {
|
||||||
|
|
||||||
|
private final PermissibleBase perm = new PermissibleBase(this);
|
||||||
|
private final SSHDConversationTracker conversationTracker = new SSHDConversationTracker();
|
||||||
|
|
||||||
|
public void sendMessage(String message) {
|
||||||
|
this.sendRawMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendRawMessage(String message) {
|
||||||
|
if(ConsoleShellFactory.ConsoleShell.consoleReader == null) return;
|
||||||
|
try {
|
||||||
|
ConsoleShellFactory.ConsoleShell.consoleReader.println(ChatColor.stripColor(message));
|
||||||
|
} 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPermissionSet(String name) {
|
||||||
|
return this.perm.isPermissionSet(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPermissionSet(Permission perm) {
|
||||||
|
return this.perm.isPermissionSet(perm);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasPermission(String name) {
|
||||||
|
return this.perm.hasPermission(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasPermission(Permission perm) {
|
||||||
|
return this.perm.hasPermission(perm);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value) {
|
||||||
|
return this.perm.addAttachment(plugin, name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PermissionAttachment addAttachment(Plugin plugin) {
|
||||||
|
return this.perm.addAttachment(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks) {
|
||||||
|
return this.perm.addAttachment(plugin, name, value, ticks);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PermissionAttachment addAttachment(Plugin plugin, int ticks) {
|
||||||
|
return this.perm.addAttachment(plugin, ticks);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeAttachment(PermissionAttachment attachment) {
|
||||||
|
this.perm.removeAttachment(attachment);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void recalculatePermissions() {
|
||||||
|
this.perm.recalculatePermissions();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<PermissionAttachmentInfo> getEffectivePermissions() {
|
||||||
|
return this.perm.getEffectivePermissions();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPlayer() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Server getServer() {
|
||||||
|
return Bukkit.getServer();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
package com.ryanmichela.sshd.implementations;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.conversations.Conversation;
|
||||||
|
import org.bukkit.conversations.ConversationAbandonedEvent;
|
||||||
|
import org.bukkit.conversations.ManuallyAbandonedConversationCanceller;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class SSHDConversationTracker {
|
||||||
|
private LinkedList<Conversation> conversationQueue = new LinkedList<>();
|
||||||
|
|
||||||
|
synchronized boolean beginConversation(Conversation conversation) {
|
||||||
|
if (!this.conversationQueue.contains(conversation)) {
|
||||||
|
this.conversationQueue.addLast(conversation);
|
||||||
|
if (this.conversationQueue.getFirst() == conversation) {
|
||||||
|
conversation.begin();
|
||||||
|
conversation.outputNextPrompt();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized void abandonConversation(Conversation conversation, ConversationAbandonedEvent details) {
|
||||||
|
if (!this.conversationQueue.isEmpty()) {
|
||||||
|
if (this.conversationQueue.getFirst() == conversation) {
|
||||||
|
conversation.abandon(details);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.conversationQueue.contains(conversation)) {
|
||||||
|
this.conversationQueue.remove(conversation);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.conversationQueue.isEmpty()) {
|
||||||
|
this.conversationQueue.getFirst().outputNextPrompt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void abandonAllConversations() {
|
||||||
|
LinkedList<Conversation> oldQueue = this.conversationQueue;
|
||||||
|
this.conversationQueue = new LinkedList<>();
|
||||||
|
|
||||||
|
for (Conversation conversation : oldQueue) {
|
||||||
|
try {
|
||||||
|
conversation.abandon(new ConversationAbandonedEvent(conversation, new ManuallyAbandonedConversationCanceller()));
|
||||||
|
} catch (Throwable var5) {
|
||||||
|
Bukkit.getLogger().log(Level.SEVERE, "Unexpected exception while abandoning a conversation", var5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized void acceptConversationInput(String input) {
|
||||||
|
if (this.isConversing()) {
|
||||||
|
Conversation conversation = this.conversationQueue.getFirst();
|
||||||
|
|
||||||
|
try {
|
||||||
|
conversation.acceptInput(input);
|
||||||
|
} catch (Throwable var4) {
|
||||||
|
conversation.getContext().getPlugin().getLogger().log(Level.WARNING, String.format("Plugin %s generated an exception whilst handling conversation input", conversation.getContext().getPlugin().getDescription().getFullName()), var4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized boolean isConversing() {
|
||||||
|
return !this.conversationQueue.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized boolean isConversingModaly() {
|
||||||
|
return this.isConversing() && this.conversationQueue.getFirst().isModal();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,10 +22,7 @@ public class PluginSlf4jFactory implements ILoggerFactory {
|
|||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
private boolean isEnabled(Level level) {
|
private boolean isEnabled(Level level) {
|
||||||
if (SshdPlugin.instance != null) {
|
return SshdPlugin.instance != null && SshdPlugin.instance.getLogger().isLoggable(level);
|
||||||
return SshdPlugin.instance.getLogger().isLoggable(level);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void log(Level level, String s, Object[] objects) {
|
private void log(Level level, String s, Object[] objects) {
|
||||||
|
|||||||
@@ -1,6 +1,16 @@
|
|||||||
# This is the port the SSH server will listen on.
|
# The IP addresses(s) the SSH server will listen on. Use a comma separated list for multiple addresses.
|
||||||
|
# Leave as "all" for all addresses.
|
||||||
|
listenAddress: all
|
||||||
|
# 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
|
||||||
|
|
||||||
|
# Enable built-in SFTP server or not. You'll be able to connect and upload/download files via SFTP protocol.
|
||||||
|
# Might be useful for testing purposes as well , i. e. docker containers.
|
||||||
|
enableSFTP: true
|
||||||
|
|
||||||
# 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
|
||||||
@@ -9,4 +19,4 @@ port: 22
|
|||||||
# For less secure username and password based authentication, complete the sections below.
|
# For less secure username and password based authentication, complete the sections below.
|
||||||
credentials:
|
credentials:
|
||||||
# user1: password1
|
# user1: password1
|
||||||
# user2: password2
|
# user2: password2
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
name: SSHD
|
name: SSHD
|
||||||
version: "1.1"
|
version: ${project.version}
|
||||||
author: Ryan Michela
|
author: Ryan Michela, Haarolean, toxuin
|
||||||
main: com.ryanmichela.sshd.SshdPlugin
|
main: com.ryanmichela.sshd.SshdPlugin
|
||||||
Reference in New Issue
Block a user