mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2025-06-11 13:33:54 +00:00
Bug fixes and improvements (#16)
* Bug fixes and improvements * Re-add Marco's name * Actually make the logfile page load.
This commit is contained in:
@ -13,10 +13,13 @@ import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.HTTPSession;
|
||||
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.Response;
|
||||
import me.totalfreedom.totalfreedommod.httpd.module.HTTPDModule;
|
||||
import me.totalfreedom.totalfreedommod.httpd.module.Module_admins;
|
||||
import me.totalfreedom.totalfreedommod.httpd.module.Module_bans;
|
||||
import me.totalfreedom.totalfreedommod.httpd.module.Module_dump;
|
||||
import me.totalfreedom.totalfreedommod.httpd.module.Module_file;
|
||||
import me.totalfreedom.totalfreedommod.httpd.module.Module_help;
|
||||
import me.totalfreedom.totalfreedommod.httpd.module.Module_list;
|
||||
import me.totalfreedom.totalfreedommod.httpd.module.Module_logfile;
|
||||
import me.totalfreedom.totalfreedommod.httpd.module.Module_logs;
|
||||
import me.totalfreedom.totalfreedommod.httpd.module.Module_permbans;
|
||||
import me.totalfreedom.totalfreedommod.httpd.module.Module_players;
|
||||
@ -24,6 +27,7 @@ import me.totalfreedom.totalfreedommod.httpd.module.Module_schematic;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
|
||||
public class HTTPDaemon extends FreedomService
|
||||
{
|
||||
@ -53,10 +57,13 @@ public class HTTPDaemon extends FreedomService
|
||||
|
||||
// Modules
|
||||
modules.clear();
|
||||
module("admins", Module_admins.class, true);
|
||||
module("bans", Module_bans.class, true);
|
||||
module("dump", Module_dump.class, true);
|
||||
module("file", Module_file.class, true);
|
||||
module("help", Module_help.class, false);
|
||||
module("list", Module_list.class, false);
|
||||
module("logfile", Module_logfile.class, true);
|
||||
module("logs", Module_logs.class, true);
|
||||
module("permbans", Module_permbans.class, true);
|
||||
module("players", Module_players.class, false);
|
||||
@ -160,6 +167,12 @@ public class HTTPDaemon extends FreedomService
|
||||
{
|
||||
mimetype = MIME_DEFAULT_BINARY;
|
||||
}
|
||||
|
||||
// Some browsers like firefox download the file for text/yaml mime types
|
||||
if (FilenameUtils.getExtension(file.getName()).equals("yml"))
|
||||
{
|
||||
mimetype = NanoHTTPD.MIME_PLAINTEXT;
|
||||
}
|
||||
|
||||
response = new Response(Response.Status.OK, mimetype, new FileInputStream(file));
|
||||
response.addHeader("Content-Length", "" + file.length());
|
||||
|
@ -0,0 +1,47 @@
|
||||
package me.totalfreedom.totalfreedommod.httpd.module;
|
||||
|
||||
import java.io.File;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon;
|
||||
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
|
||||
|
||||
public class Module_admins extends HTTPDModule
|
||||
{
|
||||
|
||||
public Module_admins(TotalFreedomMod plugin, NanoHTTPD.HTTPSession session)
|
||||
{
|
||||
super(plugin, session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NanoHTTPD.Response getResponse()
|
||||
{
|
||||
File adminFile = new File(plugin.getDataFolder(), Admin.CONFIG_FILENAME);
|
||||
if (adminFile.exists())
|
||||
{
|
||||
final String remoteAddress = socket.getInetAddress().getHostAddress();
|
||||
if (!isAuthorized(remoteAddress))
|
||||
{
|
||||
return new NanoHTTPD.Response(NanoHTTPD.Response.Status.NOT_FOUND, NanoHTTPD.MIME_PLAINTEXT,
|
||||
"You may not view the admin list, Your IP, " + remoteAddress + ", is not registered to an admin on the server.");
|
||||
}
|
||||
else
|
||||
{
|
||||
return HTTPDaemon.serveFileBasic(new File(plugin.getDataFolder(), Admin.CONFIG_FILENAME));
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return new NanoHTTPD.Response(NanoHTTPD.Response.Status.NOT_FOUND, NanoHTTPD.MIME_PLAINTEXT,
|
||||
"Error 404: Not Found - The requested resource was not found on this server.");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isAuthorized(String remoteAddress)
|
||||
{
|
||||
Admin entry = plugin.al.getEntryByIp(remoteAddress);
|
||||
return entry != null && entry.isActive();
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package me.totalfreedom.totalfreedommod.httpd.module;
|
||||
|
||||
import java.io.File;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.banning.BanManager;
|
||||
import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon;
|
||||
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
|
||||
|
||||
public class Module_bans extends HTTPDModule
|
||||
{
|
||||
|
||||
public Module_bans(TotalFreedomMod plugin, NanoHTTPD.HTTPSession session)
|
||||
{
|
||||
super(plugin, session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NanoHTTPD.Response getResponse()
|
||||
{
|
||||
File banFile = new File(plugin.getDataFolder(), BanManager.CONFIG_FILENAME);
|
||||
if (banFile.exists())
|
||||
{
|
||||
final String remoteAddress = socket.getInetAddress().getHostAddress();
|
||||
if (!isAuthorized(remoteAddress))
|
||||
{
|
||||
return new NanoHTTPD.Response(NanoHTTPD.Response.Status.NOT_FOUND, NanoHTTPD.MIME_PLAINTEXT,
|
||||
"You may not view the ban list, Your IP, " + remoteAddress + ", is not registered to an admin on the server.");
|
||||
}
|
||||
else
|
||||
{
|
||||
return HTTPDaemon.serveFileBasic(new File(plugin.getDataFolder(), BanManager.CONFIG_FILENAME));
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return new NanoHTTPD.Response(NanoHTTPD.Response.Status.NOT_FOUND, NanoHTTPD.MIME_PLAINTEXT,
|
||||
"Error 404: Not Found - The requested resource was not found on this server.");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isAuthorized(String remoteAddress)
|
||||
{
|
||||
Admin entry = plugin.al.getEntryByIp(remoteAddress);
|
||||
return entry != null && entry.isActive();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user