SSH on bungee now works.

Had to rewrite the mkpasswd command and how the console was handled
in the SSH session as many areas didn't use CRLF compared to Spigot
which seems to work better. The config had to be done manually for
the plugin since BungeeCord doesn't handle plugin configs as conveniently.

Removed the test server I accidentally added to the git repo.
This commit is contained in:
Zachery
2019-10-09 22:57:57 -05:00
parent 1c6028199b
commit d38c75dd9e
15 changed files with 61 additions and 1322 deletions
@@ -54,8 +54,10 @@ public class ConsoleCommandFactory implements CommandFactory {
}
@Override
public void start(ChannelSession cs, Environment environment) throws IOException {
try {
public void start(ChannelSession cs, Environment environment) throws IOException
{
try
{
SshdPlugin.instance.getLogger()
.info("[U: " + environment.getEnv().get(Environment.ENV_USER) + "] " + command);
@@ -97,7 +97,7 @@ public class ConsoleLogFormatter extends Formatter
stringbuilder.append(stringwriter.toString());
}
return stringbuilder.toString();
return stringbuilder.toString().replace("\n", "\r\n");
}
private void colorize(LogRecord logrecord)
@@ -25,7 +25,7 @@ public class FlushyStreamHandler extends StreamHandler
@Override
public synchronized void publish(LogRecord record)
{
record.setMessage(record.getMessage().replace("\n", "\r\n"));
record.setMessage(record.getMessage().replace("\n", "\n\r"));
super.publish(record);
flush();
}
@@ -5,24 +5,31 @@ import java.util.Arrays;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.ComponentBuilder;
import com.ryanmichela.sshd.Cryptography;
import com.ryanmichela.sshd.SshdPlugin;
public class MkpasswdCommand extends Command
{
public MkpasswdCommand()
{
super("mkpasswd");
}
public void SendSyntax(CommandSender sender, boolean invalid)
{
if (invalid)
sender.sendMessage(new ComponentBuilder("Invalid Syntax").color(ChatColor.RED).create());
sender.sendMessage(new ComponentBuilder("/mkpasswd <help|hash> <password>").color(ChatColor.GREEN).create());
sender.sendMessage(new ComponentBuilder("Supported Hashes: SHA256, PBKDF2, BCRYPT, PLAIN").color(ChatColor.BLUE).create());
}
@Override
public void execute(CommandSender sender, String[] args)
{
ProxiedPlayer player = (ProxiedPlayer) sender;
String algoritm, password;
try
{
// Stupid bukkit, we have to concatenate the arguments together if they're using
@@ -33,37 +40,44 @@ public class MkpasswdCommand extends Command
catch (ArrayIndexOutOfBoundsException e)
{
// ignore it.
sender.sendMessage("Invalid Syntax");
return;
}
// If they're console, allow regardless.
try
// If they're a player, check and make sure they have a permission
// If they're not a player (aka, the console), just return true.
boolean hasperm = (sender instanceof ProxiedPlayer) ? ((ProxiedPlayer)sender).hasPermission("sshd.mkpasswd") : true;
if (hasperm)
{
if (player.hasPermission("sshd.mkpasswd"))
try
{
String hash = "";
// Dumb but whatever. Some people are really dense.
if (algoritm.equalsIgnoreCase("PLAIN"))
sender.sendMessage(password);
else if (algoritm.equalsIgnoreCase("pbkdf2"))
sender.sendMessage(Cryptography.PBKDF2_HashPassword(password));
else if (algoritm.equalsIgnoreCase("bcrypt"))
sender.sendMessage(Cryptography.BCrypt_HashPassword(password));
else if (algoritm.equalsIgnoreCase("sha256"))
sender.sendMessage(Cryptography.SHA256_HashPassword(password));
else
{
sender.sendMessage("Invalid Syntax");
// I mean c'mon...
sender.sendMessage("Bro really? it's literally your unencrypted password...");
return;
}
else if (algoritm.equalsIgnoreCase("pbkdf2"))
hash = Cryptography.PBKDF2_HashPassword(password);
else if (algoritm.equalsIgnoreCase("bcrypt"))
hash = Cryptography.BCrypt_HashPassword(password);
else if (algoritm.equalsIgnoreCase("sha256"))
hash = Cryptography.SHA256_HashPassword(password);
else
{
this.SendSyntax(sender, !algoritm.equalsIgnoreCase("help"));
return;
}
sender.sendMessage(new ComponentBuilder("Your Hash: " + hash).color(ChatColor.BLUE).create());
}
catch (Exception e)
{
// We're console, just print the stack trace.
e.printStackTrace();
}
}
catch (Exception e)
{
// since this is a player, send a failure message
sender.sendMessage("An error occured, please check console.");
e.printStackTrace();
}
}
}
@@ -32,10 +32,9 @@ public final class SshdPlugin extends Plugin
private File file;
public Configuration configuration;
@Override public void onLoad()
{
file = new File(ProxyServer.getInstance().getPluginsFolder()+ "/config.yml");
file = new File(getDataFolder(), "config.yml");
File authorizedKeys = new File(getDataFolder(), "authorized_keys");
if (!authorizedKeys.exists())
@@ -59,13 +58,11 @@ public final class SshdPlugin extends Plugin
{
if (!file.exists())
{
file.createNewFile();
// Copy our config file.
InputStream link = (getClass().getResourceAsStream("/config.yml"));
Files.copy(link, file.getAbsoluteFile().toPath());
}
configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
// more testing
configuration.set("test", "This configuration file works!");
ConfigurationProvider.getProvider(YamlConfiguration.class).save(configuration,file);
}
catch (IOException e)
{
@@ -76,10 +73,6 @@ public final class SshdPlugin extends Plugin
// SSHD will log that it wrote bites to the output stream, which writes
// bytes to the output stream - ad nauseaum.
getLogger().setLevel(Level.INFO);
// config testing
String printout = configuration.getString("test");
getLogger().info(printout);
}
@Override public void onEnable()
@@ -23,25 +23,33 @@ public final class SSHDCommandSender implements CommandSender
@Override
public void sendMessage(String message)
{
if (message.indexOf('\n') != 0)
this.sendRawMessage(message);
else
Arrays.asList(message.split("\n")).forEach(this::sendMessage);
this.sendRawMessage(message + "\r");
}
public void sendRawMessage(String message)
{
if (this.console.ConsoleReader == null)
return;
/*
try
{
this.console.ConsoleReader.println(ConsoleLogFormatter.ColorizeString(message).replace("\n", "\n\r"));
this.console.ConsoleReader.print(this.console.ConsoleReader.RESET_LINE + "");
this.console.ConsoleReader.flush();
try
{
this.console.ConsoleReader.drawLine();
}
catch (Throwable ex)
{
this.console.ConsoleReader.getCursorBuffer().clear();
}
this.console.ConsoleReader.flush();
}
catch (IOException e)
{
SshdPlugin.instance.getLogger().log(Level.SEVERE, "Error sending message to SSHDCommandSender", e);
}*/
}
}
@Override