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

View File

@ -1,47 +0,0 @@
forge_support: false
connection_throttle_limit: 3
timeout: 30000
online_mode: true
log_commands: false
listeners:
- query_port: 25577
motd: '&1Another Bungee server'
tab_list: GLOBAL_PING
query_enabled: false
proxy_protocol: false
forced_hosts:
pvp.md-5.net: pvp
ping_passthrough: false
priorities:
- lobby
bind_local_address: true
host: 0.0.0.0:25577
max_players: 1
tab_size: 60
force_default_server: false
connection_throttle: 4000
groups:
md_5:
- admin
log_pings: true
ip_forward: false
prevent_proxy_connections: false
network_compression_threshold: 256
disabled_commands:
- disabledcommandhere
stats: 8d157bd9-a8be-441b-8dec-fd61c19393e5
permissions:
default:
- bungeecord.command.server
- bungeecord.command.list
admin:
- bungeecord.command.alert
- bungeecord.command.end
- bungeecord.command.ip
- bungeecord.command.reload
servers:
lobby:
motd: '&1Just another BungeeCord - Forced Host'
address: localhost:25565
restricted: false
player_limit: -1

View File

@ -1 +0,0 @@
{}

View File

@ -1,8 +0,0 @@
version: 2
modules:
- jenkins://cmd_alert
- jenkins://cmd_find
- jenkins://cmd_list
- jenkins://cmd_send
- jenkins://cmd_server
- jenkins://reconnect_yaml

View File

@ -1 +0,0 @@
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDlOkUWRz4aOH8E0oX2Cx7WIqFdIK17n0aeLopLemE9xXPQnPQYKpxCXimU242GAF3c6UldRMWesrXqdyjaPOCe63NAgBpsc7v+nfDOZSYmN1OoBDTs/gDSIA/KlAK+c5W8kEQ108d0us5lmPT+KEKx8jo614jwSaKNRjPLY9G7pXcJ2u1q55wNW/6T/z//zzulo3Bvo6rFnj8hg85cFnOO/ZyiZbI72RO/ElAlP8Q+tpwRTP/JE5BR50sdf6jVuowsMw4BdTMi+U+ggRPbfOTowLoQybV8y/GM8F6+PCAi7ItZYgEYJvw3jjCl5F88hyrm5ayBo17tGKrrQ827HB0T zachery@Zachery

Binary file not shown.

View File

@ -1,8 +0,0 @@
§l§4 _____ _____ _ _ _____§r
§l§6 / ____/ ____| | | | __ \§r
§l§2| (___| (___ | |__| | | | |§r
§l§3 \___ \\___ \| __ | | | |§r
§l§9 ____) |___) | | | | |__| |§r
§l§5|_____/_____/|_| |_|_____/§r
===============================================

View File

@ -1 +0,0 @@
test: This configuration file works!

File diff suppressed because it is too large Load Diff

View File

View File

@ -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);

View File

@ -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)

View File

@ -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();
}

View File

@ -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();
}
}
}

View File

@ -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()

View File

@ -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