mirror of
https://github.com/TotalFreedomMC/BukkitTelnet.git
synced 2024-09-20 17:16:28 +00:00
Updated to new config system.
Major rewrite, removed password auth (single password)... very
This commit is contained in:
parent
33f7d9c7b6
commit
b2cfb10f84
|
@ -26,11 +26,10 @@ dist.jar=${dist.dir}/MCTelnet.jar
|
||||||
dist.javadoc.dir=${dist.dir}/javadoc
|
dist.javadoc.dir=${dist.dir}/javadoc
|
||||||
endorsed.classpath=
|
endorsed.classpath=
|
||||||
excludes=
|
excludes=
|
||||||
file.reference.craftbukkit-0.0.1-SNAPSHOT.jar=C:\\github\\craftbukkit-0.0.1-SNAPSHOT.jar
|
|
||||||
includes=**
|
includes=**
|
||||||
jar.compress=false
|
jar.compress=false
|
||||||
javac.classpath=\
|
javac.classpath=\
|
||||||
${file.reference.craftbukkit-0.0.1-SNAPSHOT.jar}
|
${libs.Bukkit.classpath}
|
||||||
# Space-separated list of extra javac options
|
# Space-separated list of extra javac options
|
||||||
javac.compilerargs=
|
javac.compilerargs=
|
||||||
javac.deprecation=false
|
javac.deprecation=false
|
||||||
|
|
|
@ -1,251 +1,206 @@
|
||||||
package com.bekvon.bukkit.mctelnet;
|
package com.bekvon.bukkit.mctelnet;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
|
||||||
import org.bukkit.craftbukkit.CraftServer;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.security.MessageDigest;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map.Entry;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.util.config.ConfigurationNode;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
public class MCTelnet extends JavaPlugin
|
public class MCTelnet extends JavaPlugin
|
||||||
{
|
{
|
||||||
private ServerSocket listenerSocket;
|
private static final String CONFIG_FILE = "config.yml";
|
||||||
private ArrayList<TelnetListener> clientHolder;
|
|
||||||
private Thread listenerThread;
|
private static final Logger log = Logger.getLogger("Minecraft");
|
||||||
private boolean run = false;
|
|
||||||
int port = 8765;
|
private ServerSocket listenerSocket = null;
|
||||||
InetAddress listenAddress;
|
private ArrayList<TelnetListener> clientHolder;
|
||||||
|
private Thread listenerThread = null;
|
||||||
|
private boolean is_running = false;
|
||||||
|
private int port = 8765;
|
||||||
|
private InetAddress listenAddress = null;
|
||||||
|
|
||||||
|
protected String password = null;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
log.log(Level.INFO, "[" + getDescription().getName() + "]: Enabled - Version " + this.getDescription().getVersion() + " by bekvon, revamped by Madgeek1450.");
|
||||||
|
log.log(Level.INFO, "[" + getDescription().getName() + "]: Starting server.");
|
||||||
|
|
||||||
|
TelnetUtil.createDefaultConfiguration(CONFIG_FILE, this, getFile());
|
||||||
|
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(getDataFolder(), CONFIG_FILE));
|
||||||
|
|
||||||
|
password = config.getString("password", null);
|
||||||
|
if (password == null)
|
||||||
|
{
|
||||||
|
log.log(Level.SEVERE, "[" + getDescription().getName() + "]: Password is not defined in config file! Can't start server!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
public MCTelnet()
|
port = config.getInt("port", port);
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onDisable()
|
String address = config.getString("address", null);
|
||||||
{
|
if (address != null)
|
||||||
run = false;
|
{
|
||||||
if (listenerSocket != null)
|
try
|
||||||
{
|
{
|
||||||
try
|
listenAddress = null;
|
||||||
{
|
listenAddress = InetAddress.getByName(address);
|
||||||
synchronized (listenerSocket)
|
}
|
||||||
{
|
catch (UnknownHostException ex)
|
||||||
if (listenerSocket != null)
|
{
|
||||||
{
|
log.log(Level.SEVERE, "[" + getDescription().getName() + "]: Unknown host: " + address);
|
||||||
listenerSocket.close();
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
catch (IOException ex)
|
{
|
||||||
{
|
address = "*";
|
||||||
Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Thread.sleep(1000);
|
|
||||||
}
|
|
||||||
catch (InterruptedException ex)
|
|
||||||
{
|
|
||||||
Logger.getLogger(MCTelnet.class.getName()).log(Level.SEVERE, null, ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onEnable()
|
try
|
||||||
{
|
{
|
||||||
try
|
if (listenAddress != null)
|
||||||
{
|
{
|
||||||
Logger.getLogger("Minecraft").log(Level.INFO, "[MCTelnet] - Starting Up! Version: " + this.getDescription().getVersion() + " by bekvon");
|
listenerSocket = new java.net.ServerSocket(port, 10, listenAddress);
|
||||||
run = true;
|
}
|
||||||
this.getConfiguration().load();
|
else
|
||||||
testConfig();
|
{
|
||||||
if (this.getConfiguration().getBoolean("encryptPasswords", false))
|
listenerSocket = new java.net.ServerSocket(port);
|
||||||
{
|
}
|
||||||
encryptPasswords();
|
|
||||||
}
|
String host_ip = listenerSocket.getInetAddress().getHostAddress();
|
||||||
port = this.getConfiguration().getInt("telnetPort", port);
|
if (host_ip.equals("0.0.0.0"))
|
||||||
try
|
{
|
||||||
{
|
host_ip = "*";
|
||||||
String address = this.getConfiguration().getString("listenAddress", null);
|
}
|
||||||
if (address != null)
|
|
||||||
{
|
|
||||||
listenAddress = InetAddress.getByName(address);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
System.out.println("[MCTelnet] Exception when trying to binding to custom address:" + ex.getMessage());
|
|
||||||
}
|
|
||||||
if (listenAddress != null)
|
|
||||||
{
|
|
||||||
listenerSocket = new java.net.ServerSocket(port, 10, listenAddress);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
listenerSocket = new java.net.ServerSocket(port, 10);
|
|
||||||
}
|
|
||||||
clientHolder = new ArrayList<TelnetListener>();
|
|
||||||
listenerThread = new Thread(new Runnable()
|
|
||||||
{
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
acceptConnections();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
listenerThread.start();
|
|
||||||
Field cfield = CraftServer.class.getDeclaredField("console");
|
|
||||||
cfield.setAccessible(true);
|
|
||||||
Logger.getLogger("Minecraft").log(Level.INFO, "[MCTelnet] - Listening on: " + listenerSocket.getInetAddress().getHostAddress() + ":" + port);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Logger.getLogger("Minecraft").log(Level.SEVERE, "[MCTelnet] - Unable to Enable! Error: " + ex.getMessage());
|
|
||||||
this.setEnabled(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void encryptPasswords()
|
log.log(Level.INFO, "[" + getDescription().getName() + "]: Server started on " + host_ip + ":" + port);
|
||||||
{
|
}
|
||||||
Map<String, ConfigurationNode> users = this.getConfiguration().getNodes("users");
|
catch (IOException ex)
|
||||||
if (users != null)
|
{
|
||||||
{
|
log.log(Level.SEVERE, "[" + getDescription().getName() + "]: Cant bind to " + address + ":" + port);
|
||||||
Iterator<Entry<String, ConfigurationNode>> thisIt = users.entrySet().iterator();
|
}
|
||||||
if (thisIt != null)
|
|
||||||
{
|
|
||||||
while (thisIt.hasNext())
|
|
||||||
{
|
|
||||||
Entry<String, ConfigurationNode> thisEntry = thisIt.next();
|
|
||||||
if (thisEntry != null)
|
|
||||||
{
|
|
||||||
ConfigurationNode thisNode = thisEntry.getValue();
|
|
||||||
if (thisNode != null && !thisNode.getBoolean("passEncrypted", false))
|
|
||||||
{
|
|
||||||
this.getConfiguration().setProperty("users." + thisEntry.getKey() + ".password", hashPassword(thisNode.getString("password")));
|
|
||||||
this.getConfiguration().setProperty("users." + thisEntry.getKey() + ".passEncrypted", true);
|
|
||||||
this.getConfiguration().save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String hashPassword(String password)
|
clientHolder = new ArrayList<TelnetListener>();
|
||||||
{
|
|
||||||
String hashword = null;
|
is_running = true;
|
||||||
try
|
|
||||||
{
|
|
||||||
MessageDigest md5 = MessageDigest.getInstance("MD5");
|
|
||||||
md5.update(password.getBytes());
|
|
||||||
BigInteger hash = new BigInteger(1, md5.digest());
|
|
||||||
hashword = hash.toString(16);
|
|
||||||
}
|
|
||||||
catch (NoSuchAlgorithmException nsae)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
return hashword;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void acceptConnections()
|
listenerThread = new Thread(new Runnable()
|
||||||
{
|
{
|
||||||
while (run)
|
public void run()
|
||||||
{
|
{
|
||||||
try
|
acceptConnections();
|
||||||
{
|
}
|
||||||
Socket client = listenerSocket.accept();
|
});
|
||||||
if (client != null)
|
listenerThread.start();
|
||||||
{
|
}
|
||||||
clientHolder.add(new TelnetListener(client, this));
|
catch (Throwable ex)
|
||||||
System.out.print("[MCTelnet] - Client connected: " + client.getInetAddress().toString());
|
{
|
||||||
}
|
log.log(Level.SEVERE, "[" + getDescription().getName() + "]: Error starting plugin!", ex);
|
||||||
for (int i = 0; i < clientHolder.size(); i++)
|
}
|
||||||
{
|
}
|
||||||
TelnetListener thisListener = clientHolder.get(i);
|
|
||||||
if (thisListener.isAlive() == false)
|
@Override
|
||||||
{
|
public void onDisable()
|
||||||
clientHolder.remove(i);
|
{
|
||||||
}
|
is_running = false;
|
||||||
}
|
|
||||||
}
|
log.log(Level.INFO, "[" + getDescription().getName() + "]: Stopping server.");
|
||||||
catch (IOException ex)
|
|
||||||
{
|
try
|
||||||
run = false;
|
{
|
||||||
}
|
Thread.sleep(250);
|
||||||
}
|
}
|
||||||
Logger.getLogger("Minecraft").log(Level.INFO, "[MCTelnet] - Shutting Down!");
|
catch (Throwable ex)
|
||||||
for (int i = 0; i < clientHolder.size(); i++)
|
{
|
||||||
{
|
}
|
||||||
TelnetListener temp = clientHolder.get(i);
|
|
||||||
temp.killClient();
|
if (clientHolder != null)
|
||||||
}
|
{
|
||||||
listenerSocket = null;
|
try
|
||||||
clientHolder.clear();
|
{
|
||||||
clientHolder = null;
|
for (TelnetListener listener : clientHolder)
|
||||||
this.setEnabled(false);
|
{
|
||||||
}
|
listener.killClient();
|
||||||
|
}
|
||||||
|
clientHolder.clear();
|
||||||
|
clientHolder = null;
|
||||||
|
}
|
||||||
|
catch (Throwable ex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void testConfig()
|
if (listenerSocket != null)
|
||||||
{
|
{
|
||||||
String testConfig = this.getConfiguration().getString("telnetPort", null);
|
try
|
||||||
if (testConfig == null || testConfig.equals(""))
|
{
|
||||||
{
|
synchronized (listenerSocket)
|
||||||
this.getConfiguration().setProperty("telnetPort", 8765);
|
{
|
||||||
this.getConfiguration().save();
|
if (listenerSocket != null)
|
||||||
}
|
{
|
||||||
testConfig = this.getConfiguration().getString("listenAddress", null);
|
listenerSocket.close();
|
||||||
if (testConfig == null || testConfig.equals(""))
|
}
|
||||||
{
|
}
|
||||||
this.getConfiguration().setProperty("listenAddress", "0.0.0.0");
|
listenerSocket = null;
|
||||||
this.getConfiguration().save();
|
}
|
||||||
}
|
catch (Throwable ex)
|
||||||
testConfig = this.getConfiguration().getString("encryptPasswords", null);
|
{
|
||||||
if (testConfig == null || testConfig.equals(""))
|
}
|
||||||
{
|
}
|
||||||
this.getConfiguration().setProperty("encryptPasswords", true);
|
|
||||||
this.getConfiguration().save();
|
try
|
||||||
}
|
{
|
||||||
|
Thread.sleep(250);
|
||||||
|
}
|
||||||
|
catch (Throwable ex)
|
||||||
|
{
|
||||||
|
log.log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void acceptConnections()
|
||||||
|
{
|
||||||
|
while (is_running)
|
||||||
|
{
|
||||||
|
Socket client = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
client = listenerSocket.accept();
|
||||||
|
if (client != null)
|
||||||
|
{
|
||||||
|
clientHolder.add(new TelnetListener(client, this));
|
||||||
|
|
||||||
}
|
log.info("[" + getDescription().getName() + "]: Client connected: " + client.getInetAddress().getHostAddress());
|
||||||
|
|
||||||
@Override
|
Iterator<TelnetListener> listeners = clientHolder.iterator();
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
|
while (listeners.hasNext())
|
||||||
{
|
{
|
||||||
if (this.isEnabled())
|
TelnetListener listener = listeners.next();
|
||||||
{
|
if (!listener.isAlive())
|
||||||
if (cmd.getName().equals("telnetreload"))
|
{
|
||||||
{
|
listeners.remove();
|
||||||
if (sender instanceof ConsoleCommandSender)
|
}
|
||||||
{
|
}
|
||||||
this.getConfiguration().load();
|
}
|
||||||
testConfig();
|
}
|
||||||
if (this.getConfiguration().getBoolean("encryptPasswords", false))
|
catch (IOException ex)
|
||||||
{
|
{
|
||||||
encryptPasswords();
|
is_running = false;
|
||||||
}
|
}
|
||||||
sender.sendMessage("[MCTelnet] - Reloaded Config...");
|
}
|
||||||
for (int i = 0; i < clientHolder.size(); i++)
|
|
||||||
{
|
this.setEnabled(false);
|
||||||
TelnetListener thisListener = clientHolder.get(i);
|
}
|
||||||
thisListener.sendMessage("[MCTelnet] - Telnet Restarting...");
|
|
||||||
thisListener.killClient();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return super.onCommand(sender, cmd, commandLabel, args);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ import java.util.logging.Handler;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.LogRecord;
|
import java.util.logging.LogRecord;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
@ -19,371 +18,349 @@ import org.bukkit.permissions.Permission;
|
||||||
import org.bukkit.permissions.PermissionAttachment;
|
import org.bukkit.permissions.PermissionAttachment;
|
||||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.util.config.ConfigurationNode;
|
|
||||||
|
|
||||||
public class TelnetListener extends Handler implements CommandSender
|
public class TelnetListener extends Handler implements CommandSender
|
||||||
{
|
{
|
||||||
private boolean run;
|
private static final Logger log = Logger.getLogger("Minecraft");
|
||||||
private boolean isAuth;
|
private boolean is_running = false;
|
||||||
private String authUser;
|
private boolean is_authenticated = false;
|
||||||
private Thread listenThread;
|
private boolean already_stopped = false;
|
||||||
Socket clientSocket;
|
private String telnet_username = null;
|
||||||
MinecraftServer mcserv;
|
private Thread listenThread;
|
||||||
BufferedReader instream;
|
private Socket clientSocket;
|
||||||
BufferedWriter outstream;
|
private BufferedReader instream;
|
||||||
MCTelnet parent;
|
private BufferedWriter outstream;
|
||||||
String ip;
|
private MCTelnet plugin;
|
||||||
String passRegex = "[^a-zA-Z0-9\\-\\.\\_]";
|
private String client_ip;
|
||||||
String commandRegex = "[^\\x20-\\x7E§]";
|
private static final String COMMAND_REGEX = "[^\\x20-\\x7E]";
|
||||||
|
private static final String LOGIN_REGEX = "[^a-zA-Z0-9\\-\\.\\_]";
|
||||||
|
|
||||||
|
public TelnetListener(Socket socket, MCTelnet plugin)
|
||||||
|
{
|
||||||
|
this.is_running = true;
|
||||||
|
this.clientSocket = socket;
|
||||||
|
this.plugin = plugin;
|
||||||
|
if (clientSocket.getInetAddress() != null)
|
||||||
|
{
|
||||||
|
this.client_ip = clientSocket.getInetAddress().getHostAddress();
|
||||||
|
}
|
||||||
|
|
||||||
|
startListener();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startListener()
|
||||||
|
{
|
||||||
|
listenThread = new Thread(new Runnable()
|
||||||
|
{
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
listenThread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
instream = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
|
||||||
|
outstream = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream()));
|
||||||
|
}
|
||||||
|
catch (Throwable ex)
|
||||||
|
{
|
||||||
|
is_running = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//sendTelnetCommand(WILL, LINEMODE);
|
||||||
|
//sendTelnetCommand(DO, LINEMODE);
|
||||||
|
//sendTelnetCommand(WONT, ECHO);
|
||||||
|
//sendTelnetCommand(DO, ECHO);
|
||||||
|
|
||||||
|
writeOut("[MCTelnet] - Session Started!\r\n");
|
||||||
|
|
||||||
|
authenticateLoop();
|
||||||
|
commandLoop();
|
||||||
|
shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void authenticateLoop()
|
||||||
|
{
|
||||||
|
int tries = 0;
|
||||||
|
|
||||||
|
while (is_running && clientSocket.isConnected() && !is_authenticated)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//Get Username:
|
||||||
|
writeOut("Username: ");
|
||||||
|
String username = instream.readLine().replaceAll(LOGIN_REGEX, "").trim();
|
||||||
|
|
||||||
|
//sendTelnetCommand(WILL, ECHO);
|
||||||
|
//sendTelnetCommand(DONT, ECHO);
|
||||||
|
|
||||||
public TelnetListener(Socket inSock, MCTelnet iparent)
|
//Get Password:
|
||||||
{
|
writeOut("Password: ");
|
||||||
run = true;
|
String password = instream.readLine().replaceAll(LOGIN_REGEX, "").trim();
|
||||||
clientSocket = inSock;
|
writeOut("\r\n");
|
||||||
parent = iparent;
|
|
||||||
passRegex = parent.getConfiguration().getString("passwordRegex", passRegex);
|
//sendTelnetCommand(WONT, ECHO);
|
||||||
//commandRegex = parent.getConfiguration().getString("commandRegex", commandRegex);
|
//sendTelnetCommand(DO, ECHO);
|
||||||
ip = clientSocket.getInetAddress().toString();
|
|
||||||
listenThread = new Thread(new Runnable()
|
if (password.equals(plugin.password))
|
||||||
{
|
{
|
||||||
public void run()
|
telnet_username = username;
|
||||||
{
|
is_authenticated = true;
|
||||||
mainLoop();
|
}
|
||||||
}
|
|
||||||
});
|
if (is_authenticated)
|
||||||
listenThread.start();
|
{
|
||||||
}
|
writeOut("Logged In as " + getName() + ".\r\n:");
|
||||||
|
return;
|
||||||
private void mainLoop()
|
}
|
||||||
{
|
else
|
||||||
try
|
{
|
||||||
{
|
try
|
||||||
instream = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
|
{
|
||||||
outstream = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream()));
|
Thread.sleep(2000);
|
||||||
//sendTelnetCommand(251,3);
|
}
|
||||||
//sendTelnetCommand(253,3);
|
catch (InterruptedException ex)
|
||||||
sendTelnetCommand(251, 34);
|
{
|
||||||
sendTelnetCommand(253, 34);
|
}
|
||||||
sendTelnetCommand(252, 1);
|
writeOut("Invalid Username or Password.\r\n\r\n");
|
||||||
sendTelnetCommand(253, 1);
|
}
|
||||||
outstream.write("[MCTelnet] - Session Started!\r\n");
|
|
||||||
outstream.flush();
|
if (++tries >= 3)
|
||||||
}
|
{
|
||||||
catch (IOException ex)
|
writeOut("Too many failed login attempts.\r\n");
|
||||||
{
|
return;
|
||||||
Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex);
|
}
|
||||||
run = false;
|
}
|
||||||
}
|
catch (Throwable ex)
|
||||||
if (!clientSocket.getInetAddress().isLoopbackAddress() || !parent.getConfiguration().getBoolean("allowAuthlessLocalhost", false))
|
{
|
||||||
{
|
is_running = false;
|
||||||
authenticateLoop();
|
telnet_username = null;
|
||||||
}
|
is_authenticated = false;
|
||||||
else
|
}
|
||||||
{
|
}
|
||||||
isAuth = true;
|
}
|
||||||
authUser = parent.getConfiguration().getString("rootUser");
|
|
||||||
}
|
private void commandLoop()
|
||||||
commandLoop();
|
{
|
||||||
shutdown();
|
if (!is_running || !is_authenticated)
|
||||||
}
|
{
|
||||||
|
return;
|
||||||
private void authenticateLoop()
|
}
|
||||||
{
|
|
||||||
int retrys = 0;
|
Logger.getLogger("Minecraft").addHandler(this);
|
||||||
while (run && clientSocket.isConnected() && isAuth == false)
|
|
||||||
{
|
while (is_running && clientSocket.isConnected() && is_authenticated)
|
||||||
try
|
{
|
||||||
{
|
String command = null;
|
||||||
outstream.write("Username:");
|
try
|
||||||
outstream.flush();
|
{
|
||||||
String username = instream.readLine().replaceAll(passRegex, "");
|
command = instream.readLine();
|
||||||
sendTelnetCommand(251, 1);
|
}
|
||||||
sendTelnetCommand(254, 1);
|
catch (IOException ex)
|
||||||
outstream.write("Password:");
|
{
|
||||||
outstream.flush();
|
}
|
||||||
String pw = instream.readLine().replaceAll(passRegex, "");
|
|
||||||
outstream.write("\r\n");
|
if (command != null)
|
||||||
sendTelnetCommand(252, 1);
|
{
|
||||||
sendTelnetCommand(253, 1);
|
if (!command.isEmpty())
|
||||||
ConfigurationNode parentnode = parent.getConfiguration().getNode("users");
|
{
|
||||||
if (parentnode != null)
|
command = command.replaceAll(COMMAND_REGEX, "").trim();
|
||||||
{
|
plugin.getServer().dispatchCommand(this, command);
|
||||||
ConfigurationNode usernode = parentnode.getNode(username);
|
log.log(Level.INFO, "[" + plugin.getDescription().getName() + "]: " + getName() + " issued command: " + command);
|
||||||
if (usernode != null)
|
}
|
||||||
{
|
else
|
||||||
String userpw = usernode.getString("password");
|
{
|
||||||
if (usernode.getBoolean("passEncrypted", false))
|
writeOut(":");
|
||||||
{
|
}
|
||||||
pw = MCTelnet.hashPassword(pw);
|
}
|
||||||
}
|
}
|
||||||
if (pw.equals(userpw))
|
}
|
||||||
{
|
|
||||||
authUser = username;
|
private void shutdown()
|
||||||
isAuth = true;
|
{
|
||||||
}
|
if (already_stopped)
|
||||||
}
|
{
|
||||||
}
|
return;
|
||||||
if (isAuth)
|
}
|
||||||
{
|
already_stopped = true;
|
||||||
outstream.write("Logged In as " + authUser + "!\r\n:");
|
|
||||||
outstream.flush();
|
is_running = false;
|
||||||
}
|
|
||||||
else
|
log.log(Level.INFO, "[" + plugin.getDescription().getName() + "]: Closing connection: " + client_ip);
|
||||||
{
|
Logger.getLogger("Minecraft").removeHandler(this);
|
||||||
Thread.sleep(2000);
|
|
||||||
outstream.write("Invalid Username or Password!\r\n\r\n");
|
if (!clientSocket.isClosed())
|
||||||
outstream.flush();
|
{
|
||||||
}
|
writeOut("[" + plugin.getDescription().getName() + "]: Closing connection.");
|
||||||
retrys++;
|
try
|
||||||
if (retrys == 3 && isAuth == false)
|
{
|
||||||
{
|
clientSocket.close();
|
||||||
try
|
}
|
||||||
{
|
catch (IOException ex)
|
||||||
outstream.write("Too many failed login attempts!");
|
{
|
||||||
outstream.flush();
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
}
|
||||||
{
|
|
||||||
}
|
// public static final int WILL = 251; //Sender wants to do something.
|
||||||
return;
|
// public static final int WONT = 252; //Sender doesn't want to do something.
|
||||||
}
|
// public static final int DO = 253; //Sender wants the other end to do something.
|
||||||
}
|
// public static final int DONT = 254; //Sender wants the other not to do something.
|
||||||
catch (Exception ex)
|
//
|
||||||
{
|
// public static final int ECHO = 1;
|
||||||
run = false;
|
// public static final int LINEMODE = 34;
|
||||||
authUser = null;
|
//
|
||||||
isAuth = false;
|
// private void sendTelnetCommand(int command, int option)
|
||||||
}
|
// {
|
||||||
}
|
// writeOut(("" + ((char) 255) + ((char) command) + ((char) option)));
|
||||||
}
|
// }
|
||||||
|
|
||||||
private void commandLoop()
|
private void writeOut(String message)
|
||||||
{
|
{
|
||||||
try
|
if (outstream != null)
|
||||||
{
|
{
|
||||||
if (isAuth)
|
if (clientSocket.isConnected())
|
||||||
{
|
{
|
||||||
String[] validCommands = new String[0];
|
try
|
||||||
|
{
|
||||||
Logger.getLogger("Minecraft").addHandler(this);
|
outstream.write(message);
|
||||||
|
outstream.flush();
|
||||||
while (run && clientSocket.isConnected() && isAuth)
|
}
|
||||||
{
|
catch (IOException ex)
|
||||||
String command = "";
|
{
|
||||||
command = instream.readLine().replaceAll(commandRegex, "").trim();
|
is_running = false;
|
||||||
if (command.equals("exit"))
|
}
|
||||||
{
|
}
|
||||||
run = false;
|
}
|
||||||
clientSocket.close();
|
}
|
||||||
return;
|
|
||||||
}
|
public boolean isAlive()
|
||||||
if (!clientSocket.isClosed())
|
{
|
||||||
{
|
return is_running;
|
||||||
parent.getServer().dispatchCommand(this, command);
|
}
|
||||||
System.out.println("[MCTelnet] " + authUser + " issued command: " + command);
|
|
||||||
}
|
public void killClient()
|
||||||
}
|
{
|
||||||
}
|
shutdown();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
@Override
|
||||||
}
|
public void publish(LogRecord record)
|
||||||
}
|
{
|
||||||
|
writeOut(ChatColor.stripColor(record.getMessage()) + "\r\n:");
|
||||||
public boolean isAlive()
|
}
|
||||||
{
|
|
||||||
return run;
|
@Override
|
||||||
}
|
public void flush()
|
||||||
|
{
|
||||||
public void killClient()
|
if (clientSocket.isConnected())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
run = false;
|
outstream.flush();
|
||||||
outstream.write("[MCTelnet] - Closing Connection!");
|
}
|
||||||
clientSocket.close();
|
catch (IOException ex)
|
||||||
}
|
{
|
||||||
catch (IOException ex)
|
}
|
||||||
{
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
private void shutdown()
|
public void close() throws SecurityException
|
||||||
{
|
{
|
||||||
try
|
shutdown();
|
||||||
{
|
}
|
||||||
run = false;
|
|
||||||
Logger.getLogger("Minecraft").removeHandler(this);
|
public void sendMessage(String string)
|
||||||
Logger.getLogger("Minecraft").log(Level.INFO, "[MCTelnet] Closing connection: " + ip);
|
{
|
||||||
if (!clientSocket.isClosed())
|
writeOut(ChatColor.stripColor(string) + "\r\n:");
|
||||||
{
|
}
|
||||||
outstream.write("[MCTelnet] - Closing Connection!");
|
|
||||||
clientSocket.close();
|
public Server getServer()
|
||||||
}
|
{
|
||||||
mcserv = null;
|
return plugin.getServer();
|
||||||
parent = null;
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
public String getName()
|
||||||
{
|
{
|
||||||
Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex);
|
if (telnet_username != null)
|
||||||
run = false;
|
{
|
||||||
}
|
return telnet_username;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
@Override
|
{
|
||||||
public void publish(LogRecord record)
|
return plugin.getDescription().getName();
|
||||||
{
|
}
|
||||||
try
|
}
|
||||||
{
|
|
||||||
if (!clientSocket.isClosed())
|
public boolean isPermissionSet(String string)
|
||||||
{
|
{
|
||||||
outstream.write(ChatColor.stripColor(record.getMessage()) + "\r\n:");
|
return true;
|
||||||
outstream.flush();
|
}
|
||||||
}
|
|
||||||
}
|
public boolean isPermissionSet(Permission prmsn)
|
||||||
catch (IOException ex)
|
{
|
||||||
{
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public boolean hasPermission(String string)
|
||||||
@Override
|
{
|
||||||
public void flush()
|
return true;
|
||||||
{
|
}
|
||||||
if (clientSocket.isConnected())
|
|
||||||
{
|
public boolean hasPermission(Permission prmsn)
|
||||||
try
|
{
|
||||||
{
|
return true;
|
||||||
outstream.flush();
|
}
|
||||||
}
|
|
||||||
catch (IOException ex)
|
public PermissionAttachment addAttachment(Plugin plugin, String string, boolean bln)
|
||||||
{
|
{
|
||||||
}
|
return null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public PermissionAttachment addAttachment(Plugin plugin)
|
||||||
public void sendMessage(String string)
|
{
|
||||||
{
|
return null;
|
||||||
if (clientSocket.isConnected())
|
}
|
||||||
{
|
|
||||||
try
|
public PermissionAttachment addAttachment(Plugin plugin, String string, boolean bln, int i)
|
||||||
{
|
{
|
||||||
string = ChatColor.stripColor(string);
|
return null;
|
||||||
outstream.write(string + "\r\n:");
|
}
|
||||||
outstream.flush();
|
|
||||||
}
|
public PermissionAttachment addAttachment(Plugin plugin, int i)
|
||||||
catch (IOException ex)
|
{
|
||||||
{
|
return null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
public void removeAttachment(PermissionAttachment pa)
|
||||||
|
{
|
||||||
public boolean isOp()
|
return;
|
||||||
{
|
}
|
||||||
if (authUser.equalsIgnoreCase("console"))
|
|
||||||
{
|
public void recalculatePermissions()
|
||||||
return true;
|
{
|
||||||
}
|
return;
|
||||||
if (parent.getConfiguration().getBoolean("allowOPsAll", false))
|
}
|
||||||
{
|
|
||||||
return parent.getServer().getPlayer(authUser).isOp();
|
public Set<PermissionAttachmentInfo> getEffectivePermissions()
|
||||||
}
|
{
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPlayer()
|
public boolean isOp()
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Server getServer()
|
public void setOp(boolean bln)
|
||||||
{
|
{
|
||||||
return parent.getServer();
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() throws SecurityException
|
|
||||||
{
|
|
||||||
shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sendTelnetCommand(int command, int option)
|
|
||||||
{
|
|
||||||
if (clientSocket.isConnected())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
String tcmd = ("" + ((char) 255) + ((char) command) + ((char) option));
|
|
||||||
outstream.write(tcmd);
|
|
||||||
outstream.flush();
|
|
||||||
}
|
|
||||||
catch (IOException ex)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName()
|
|
||||||
{
|
|
||||||
return authUser;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isPermissionSet(String string)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isPermissionSet(Permission prmsn)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasPermission(String string)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasPermission(Permission prmsn)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PermissionAttachment addAttachment(Plugin plugin, String string, boolean bln)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PermissionAttachment addAttachment(Plugin plugin)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PermissionAttachment addAttachment(Plugin plugin, String string, boolean bln, int i)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PermissionAttachment addAttachment(Plugin plugin, int i)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeAttachment(PermissionAttachment pa)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void recalculatePermissions()
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<PermissionAttachmentInfo> getEffectivePermissions()
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOp(boolean bln)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
93
src/com/bekvon/bukkit/mctelnet/TelnetUtil.java
Normal file
93
src/com/bekvon/bukkit/mctelnet/TelnetUtil.java
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
package com.bekvon.bukkit.mctelnet;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.jar.JarFile;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
|
||||||
|
public class TelnetUtil
|
||||||
|
{
|
||||||
|
private static final Logger log = Logger.getLogger("Minecraft");
|
||||||
|
|
||||||
|
private TelnetUtil()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void createDefaultConfiguration(String name, MCTelnet tfm, File plugin_file)
|
||||||
|
{
|
||||||
|
File actual = new File(tfm.getDataFolder(), name);
|
||||||
|
if (!actual.exists())
|
||||||
|
{
|
||||||
|
log.info("[" + tfm.getDescription().getName() + "]: Installing default configuration file template: " + actual.getPath());
|
||||||
|
InputStream input = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
JarFile file = new JarFile(plugin_file);
|
||||||
|
ZipEntry copy = file.getEntry(name);
|
||||||
|
if (copy == null)
|
||||||
|
{
|
||||||
|
log.severe("[" + tfm.getDescription().getName() + "]: Unable to read default configuration: " + actual.getPath());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
input = file.getInputStream(copy);
|
||||||
|
}
|
||||||
|
catch (IOException ioex)
|
||||||
|
{
|
||||||
|
log.severe("[" + tfm.getDescription().getName() + "]: Unable to read default configuration: " + actual.getPath());
|
||||||
|
}
|
||||||
|
if (input != null)
|
||||||
|
{
|
||||||
|
FileOutputStream output = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
tfm.getDataFolder().mkdirs();
|
||||||
|
output = new FileOutputStream(actual);
|
||||||
|
byte[] buf = new byte[8192];
|
||||||
|
int length = 0;
|
||||||
|
while ((length = input.read(buf)) > 0)
|
||||||
|
{
|
||||||
|
output.write(buf, 0, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("[" + tfm.getDescription().getName() + "]: Default configuration file written: " + actual.getPath());
|
||||||
|
}
|
||||||
|
catch (IOException ioex)
|
||||||
|
{
|
||||||
|
log.log(Level.SEVERE, "[" + tfm.getDescription().getName() + "]: Unable to write default configuration: " + actual.getPath(), ioex);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (input != null)
|
||||||
|
{
|
||||||
|
input.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException ioex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (output != null)
|
||||||
|
{
|
||||||
|
output.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException ioex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
8
src/config.yml
Normal file
8
src/config.yml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# Port to bind to:
|
||||||
|
port: 8765
|
||||||
|
|
||||||
|
# Address to listen on, leave blank for all:
|
||||||
|
address:
|
||||||
|
|
||||||
|
# Main connection password, must be defined:
|
||||||
|
password:
|
|
@ -1,8 +1,5 @@
|
||||||
name: MCTelnet
|
name: MCTelnet
|
||||||
main: com.bekvon.bukkit.mctelnet.MCTelnet
|
main: com.bekvon.bukkit.mctelnet.MCTelnet
|
||||||
version: 1.2.7
|
version: 1.3
|
||||||
description: Telnet console access plugin.
|
description: Telnet console access plugin.
|
||||||
author: bekvon
|
author: bekvon
|
||||||
commands:
|
|
||||||
telnetreload:
|
|
||||||
description: Reloads MCTelnets config file...
|
|
Loading…
Reference in a new issue