From 7c6c407f78db0210c80b1a4b192bc2b7ee46d3be Mon Sep 17 00:00:00 2001 From: Lemon Date: Fri, 18 Jan 2019 18:08:20 +0500 Subject: [PATCH] add ssh support --- pom.xml | 6 ++ .../totalfreedommod/TotalFreedomMod.java | 3 + .../totalfreedommod/admin/Admin.java | 1 + .../bridge/BukkitSSHBridge.java | 94 +++++++++++++++++++ 4 files changed, 104 insertions(+) create mode 100644 src/main/java/me/totalfreedom/totalfreedommod/bridge/BukkitSSHBridge.java diff --git a/pom.xml b/pom.xml index 8764960d..eb147032 100644 --- a/pom.xml +++ b/pom.xml @@ -168,6 +168,12 @@ 6.2 provided + + + com.github.TFPatches + BukkitSSH + master-SNAPSHOT + diff --git a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java index ff28c11f..f49fcdbe 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java @@ -16,6 +16,7 @@ import me.totalfreedom.totalfreedommod.blocking.PVPBlocker; import me.totalfreedom.totalfreedommod.blocking.PotionBlocker; import me.totalfreedom.totalfreedommod.blocking.SignBlocker; import me.totalfreedom.totalfreedommod.blocking.command.CommandBlocker; +import me.totalfreedom.totalfreedommod.bridge.BukkitSSHBridge; import me.totalfreedom.totalfreedommod.bridge.BukkitTelnetBridge; import me.totalfreedom.totalfreedommod.bridge.CoreProtectBridge; import me.totalfreedom.totalfreedommod.bridge.EssentialsBridge; @@ -126,6 +127,7 @@ public class TotalFreedomMod extends AeroPlugin // Bridges public ServiceManager bridges; public BukkitTelnetBridge btb; + public BukkitSSHBridge bsb; public EssentialsBridge esb; public LibsDisguisesBridge ldb; public CoreProtectBridge cpb; @@ -243,6 +245,7 @@ public class TotalFreedomMod extends AeroPlugin // Start bridges bridges = new ServiceManager<>(plugin); btb = bridges.registerService(BukkitTelnetBridge.class); + bsb = bridges.registerService(BukkitSSHBridge.class); cpb = bridges.registerService(CoreProtectBridge.class); esb = bridges.registerService(EssentialsBridge.class); ldb = bridges.registerService(LibsDisguisesBridge.class); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java b/src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java index 3468ada5..c8f12d75 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java @@ -15,6 +15,7 @@ import net.pravian.aero.base.Validatable; import net.pravian.aero.util.Ips; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.Validate; +import org.bukkit.ChatColor; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; diff --git a/src/main/java/me/totalfreedom/totalfreedommod/bridge/BukkitSSHBridge.java b/src/main/java/me/totalfreedom/totalfreedommod/bridge/BukkitSSHBridge.java new file mode 100644 index 00000000..ec0a1a50 --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/bridge/BukkitSSHBridge.java @@ -0,0 +1,94 @@ +package me.totalfreedom.totalfreedommod.bridge; + +import com.ryanmichela.bukkitssh.BukkitSSH; +import com.ryanmichela.bukkitssh.SshTerminal; +import me.totalfreedom.bukkitssh.SSHCommandEvent; +import me.totalfreedom.bukkitssh.SSHPreLoginEvent; +import java.util.ArrayList; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import me.totalfreedom.totalfreedommod.FreedomService; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import me.totalfreedom.totalfreedommod.admin.Admin; +import me.totalfreedom.totalfreedommod.rank.Rank; +import me.totalfreedom.totalfreedommod.util.FLog; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.plugin.Plugin; + +public class BukkitSSHBridge extends FreedomService +{ + + private BukkitSSH BukkitSSHPlugin = null; + + public BukkitSSHBridge(TotalFreedomMod plugin) + { + super(plugin); + } + + @Override + protected void onStart() + { + } + + @Override + protected void onStop() + { + } + + @EventHandler(priority = EventPriority.NORMAL) + public void onTelnetPreLogin(SSHPreLoginEvent event) + { + + final String ip = event.getIp(); + if (ip == null || ip.isEmpty()) + { + return; + } + + final Admin admin = plugin.al.getEntryByIpFuzzy(ip); + + if (admin == null || !admin.isActive() || !admin.getRank().hasConsoleVariant()) + { + return; + } + + event.setBypassPassword(true); + event.setName(admin.getName()); + } + + @EventHandler(priority = EventPriority.NORMAL) + public void onTelnetCommand(SSHCommandEvent event) + { + if (plugin.cb.isCommandBlocked(event.getCommand(), event.getSender())) + { + event.setCancelled(true); + } + } + public BukkitSSH getBukkitSSHPlugin() + { + if (BukkitSSHPlugin == null) + { + try + { + final Plugin BukkitSSH = server.getPluginManager().getPlugin("BukkitSSH"); + if (BukkitSSH != null) + { + if (BukkitSSH instanceof BukkitSSH) + { + BukkitSSHPlugin = (BukkitSSH)BukkitSSH; + } + } + } + catch (Exception ex) + { + FLog.severe(ex); + } + } + + return BukkitSSHPlugin; + } +}