add ssh support

This commit is contained in:
Lemon 2019-01-18 18:08:20 +05:00
parent 746ccdfd44
commit 7c6c407f78
4 changed files with 104 additions and 0 deletions

View File

@ -168,6 +168,12 @@
<version>6.2</version> <version>6.2</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>com.github.TFPatches</groupId>
<artifactId>BukkitSSH</artifactId>
<version>master-SNAPSHOT</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -16,6 +16,7 @@ import me.totalfreedom.totalfreedommod.blocking.PVPBlocker;
import me.totalfreedom.totalfreedommod.blocking.PotionBlocker; import me.totalfreedom.totalfreedommod.blocking.PotionBlocker;
import me.totalfreedom.totalfreedommod.blocking.SignBlocker; import me.totalfreedom.totalfreedommod.blocking.SignBlocker;
import me.totalfreedom.totalfreedommod.blocking.command.CommandBlocker; import me.totalfreedom.totalfreedommod.blocking.command.CommandBlocker;
import me.totalfreedom.totalfreedommod.bridge.BukkitSSHBridge;
import me.totalfreedom.totalfreedommod.bridge.BukkitTelnetBridge; import me.totalfreedom.totalfreedommod.bridge.BukkitTelnetBridge;
import me.totalfreedom.totalfreedommod.bridge.CoreProtectBridge; import me.totalfreedom.totalfreedommod.bridge.CoreProtectBridge;
import me.totalfreedom.totalfreedommod.bridge.EssentialsBridge; import me.totalfreedom.totalfreedommod.bridge.EssentialsBridge;
@ -126,6 +127,7 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
// Bridges // Bridges
public ServiceManager<TotalFreedomMod> bridges; public ServiceManager<TotalFreedomMod> bridges;
public BukkitTelnetBridge btb; public BukkitTelnetBridge btb;
public BukkitSSHBridge bsb;
public EssentialsBridge esb; public EssentialsBridge esb;
public LibsDisguisesBridge ldb; public LibsDisguisesBridge ldb;
public CoreProtectBridge cpb; public CoreProtectBridge cpb;
@ -243,6 +245,7 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
// Start bridges // Start bridges
bridges = new ServiceManager<>(plugin); bridges = new ServiceManager<>(plugin);
btb = bridges.registerService(BukkitTelnetBridge.class); btb = bridges.registerService(BukkitTelnetBridge.class);
bsb = bridges.registerService(BukkitSSHBridge.class);
cpb = bridges.registerService(CoreProtectBridge.class); cpb = bridges.registerService(CoreProtectBridge.class);
esb = bridges.registerService(EssentialsBridge.class); esb = bridges.registerService(EssentialsBridge.class);
ldb = bridges.registerService(LibsDisguisesBridge.class); ldb = bridges.registerService(LibsDisguisesBridge.class);

View File

@ -15,6 +15,7 @@ import net.pravian.aero.base.Validatable;
import net.pravian.aero.util.Ips; import net.pravian.aero.util.Ips;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.Validate;
import org.bukkit.ChatColor;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View File

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