mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
HTTPD updates
This commit is contained in:
parent
eccf940b81
commit
81002cbe97
@ -61,7 +61,6 @@ public class HTTPDaemon extends FreedomService
|
|||||||
module("activitylog", Module_activitylog.class, true);
|
module("activitylog", Module_activitylog.class, true);
|
||||||
module("admins", Module_admins.class, true);
|
module("admins", Module_admins.class, true);
|
||||||
module("bans", Module_bans.class, true);
|
module("bans", Module_bans.class, true);
|
||||||
module("file", Module_file.class, true);
|
|
||||||
module("help", Module_help.class, false);
|
module("help", Module_help.class, false);
|
||||||
module("list", Module_list.class, false);
|
module("list", Module_list.class, false);
|
||||||
module("logfile", Module_logfile.class, true);
|
module("logfile", Module_logfile.class, true);
|
||||||
|
@ -3,6 +3,7 @@ package me.totalfreedom.totalfreedommod.httpd.module;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||||
import me.totalfreedom.totalfreedommod.admin.ActivityLog;
|
import me.totalfreedom.totalfreedommod.admin.ActivityLog;
|
||||||
|
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||||
import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon;
|
import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon;
|
||||||
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
|
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
|
||||||
|
|
||||||
@ -17,6 +18,13 @@ public class Module_activitylog extends HTTPDModule
|
|||||||
@Override
|
@Override
|
||||||
public NanoHTTPD.Response getResponse()
|
public NanoHTTPD.Response getResponse()
|
||||||
{
|
{
|
||||||
|
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 activity log. Your IP, " + remoteAddress + ", is not registered to an admin on the server.");
|
||||||
|
}
|
||||||
File activityLogFile = new File(plugin.getDataFolder(), ActivityLog.FILENAME);
|
File activityLogFile = new File(plugin.getDataFolder(), ActivityLog.FILENAME);
|
||||||
if (activityLogFile.exists())
|
if (activityLogFile.exists())
|
||||||
{
|
{
|
||||||
@ -28,4 +36,10 @@ public class Module_activitylog extends HTTPDModule
|
|||||||
"Error 404: Not Found - The requested resource was not found on this server.");
|
"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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ public class Module_admins extends HTTPDModule
|
|||||||
if (!isAuthorized(remoteAddress))
|
if (!isAuthorized(remoteAddress))
|
||||||
{
|
{
|
||||||
return new NanoHTTPD.Response(NanoHTTPD.Response.Status.NOT_FOUND, NanoHTTPD.MIME_PLAINTEXT,
|
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.");
|
"You may not view the admin list. Your IP, " + remoteAddress + ", is not registered to an admin on the server.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -25,7 +25,7 @@ public class Module_bans extends HTTPDModule
|
|||||||
if (!isAuthorized(remoteAddress))
|
if (!isAuthorized(remoteAddress))
|
||||||
{
|
{
|
||||||
return new NanoHTTPD.Response(NanoHTTPD.Response.Status.NOT_FOUND, NanoHTTPD.MIME_PLAINTEXT,
|
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.");
|
"You may not view the ban list, Your IP. " + remoteAddress + ", is not registered to an admin on the server.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -2,9 +2,15 @@ package me.totalfreedom.totalfreedommod.httpd.module;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||||
|
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||||
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
|
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.json.simple.JSONArray;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
public class Module_list extends HTTPDModule
|
public class Module_list extends HTTPDModule
|
||||||
{
|
{
|
||||||
@ -15,7 +21,83 @@ public class Module_list extends HTTPDModule
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getBody()
|
public NanoHTTPD.Response getResponse()
|
||||||
|
{
|
||||||
|
if (params.get("json") != null && params.get("json").equals("true"))
|
||||||
|
{
|
||||||
|
final JSONObject responseObject = new JSONObject();
|
||||||
|
|
||||||
|
final JSONArray operators = new JSONArray();
|
||||||
|
final JSONArray imposters = new JSONArray();
|
||||||
|
final JSONArray masterbuilders = new JSONArray();
|
||||||
|
final JSONArray superadmins = new JSONArray();
|
||||||
|
final JSONArray telnetadmins = new JSONArray();
|
||||||
|
final JSONArray senioradmins = new JSONArray();
|
||||||
|
final JSONArray developers = new JSONArray();
|
||||||
|
final JSONArray executives = new JSONArray();
|
||||||
|
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers())
|
||||||
|
{
|
||||||
|
|
||||||
|
if (isImposter(player))
|
||||||
|
{
|
||||||
|
imposters.add(player.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (plugin.mbl.isMasterBuilder(player))
|
||||||
|
{
|
||||||
|
masterbuilders.add(player.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (FUtil.DEVELOPERS.contains(player.getName()))
|
||||||
|
{
|
||||||
|
developers.add(player.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ConfigEntry.SERVER_EXECUTIVES.getList().contains(player.getName()) && !FUtil.DEVELOPERS.contains(player.getName()))
|
||||||
|
{
|
||||||
|
executives.add(player.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!plugin.al.isAdmin(player) && !hasSpecialTitle(player))
|
||||||
|
{
|
||||||
|
FLog.info(player.getName() + " is an op");
|
||||||
|
operators.add(player.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hasSpecialTitle(player) && plugin.al.isAdmin(player))
|
||||||
|
{
|
||||||
|
Admin admin = plugin.al.getAdmin(player);
|
||||||
|
switch (admin.getRank())
|
||||||
|
{
|
||||||
|
case SUPER_ADMIN:
|
||||||
|
superadmins.add(player.getName());
|
||||||
|
break;
|
||||||
|
case TELNET_ADMIN:
|
||||||
|
telnetadmins.add(player.getName());
|
||||||
|
break;
|
||||||
|
case SENIOR_ADMIN:
|
||||||
|
senioradmins.add(player.getName());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
responseObject.put("operators", operators);
|
||||||
|
responseObject.put("imposters", imposters);
|
||||||
|
responseObject.put("masterbuilders", masterbuilders);
|
||||||
|
responseObject.put("superadmins", superadmins);
|
||||||
|
responseObject.put("telnetadmins", telnetadmins);
|
||||||
|
responseObject.put("senioradmins", senioradmins);
|
||||||
|
responseObject.put("developers", developers);
|
||||||
|
responseObject.put("executives", executives);
|
||||||
|
|
||||||
|
final NanoHTTPD.Response response = new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, NanoHTTPD.MIME_JSON, responseObject.toString());
|
||||||
|
response.addHeader("Access-Control-Allow-Origin", "*");
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
final StringBuilder body = new StringBuilder();
|
final StringBuilder body = new StringBuilder();
|
||||||
|
|
||||||
@ -33,12 +115,33 @@ public class Module_list extends HTTPDModule
|
|||||||
|
|
||||||
body.append("</ul>\r\n");
|
body.append("</ul>\r\n");
|
||||||
|
|
||||||
return body.toString();
|
final NanoHTTPD.Response response = new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, NanoHTTPD.MIME_HTML, body.toString());
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isImposter(Player player)
|
||||||
|
{
|
||||||
|
if (plugin.al.isAdminImpostor(player) || plugin.pv.isPlayerImpostor(player) || plugin.mbl.isMasterBuilderImpostor(player))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasSpecialTitle(Player player)
|
||||||
|
{
|
||||||
|
if (FUtil.DEVELOPERS.contains(player.getName()) || ConfigEntry.SERVER_EXECUTIVES.getList().contains(player.getName()) || ConfigEntry.SERVER_OWNERS.getList().contains(player.getName()))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTitle()
|
public String getTitle()
|
||||||
{
|
{
|
||||||
return "Total Freedom - Online Users";
|
return "Total Freedom - Online Players";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package me.totalfreedom.totalfreedommod.httpd.module;
|
|||||||
|
|
||||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||||
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
|
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
|
||||||
import me.totalfreedom.totalfreedommod.masterbuilder.MasterBuilder;
|
import me.totalfreedom.totalfreedommod.masterbuilder.MasterBuilder;
|
||||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
@ -31,6 +32,7 @@ public class Module_players extends HTTPDModule
|
|||||||
final JSONArray telnetadmins = new JSONArray();
|
final JSONArray telnetadmins = new JSONArray();
|
||||||
final JSONArray senioradmins = new JSONArray();
|
final JSONArray senioradmins = new JSONArray();
|
||||||
final JSONArray developers = new JSONArray();
|
final JSONArray developers = new JSONArray();
|
||||||
|
final JSONArray executives = new JSONArray();
|
||||||
|
|
||||||
// All online players
|
// All online players
|
||||||
for (Player player : Bukkit.getOnlinePlayers())
|
for (Player player : Bukkit.getOnlinePlayers())
|
||||||
@ -70,12 +72,16 @@ public class Module_players extends HTTPDModule
|
|||||||
// Developers
|
// Developers
|
||||||
developers.addAll(FUtil.DEVELOPERS);
|
developers.addAll(FUtil.DEVELOPERS);
|
||||||
|
|
||||||
|
// Executives
|
||||||
|
executives.addAll(ConfigEntry.SERVER_EXECUTIVES.getList());
|
||||||
|
|
||||||
responseObject.put("players", players);
|
responseObject.put("players", players);
|
||||||
responseObject.put("masterbuilders", masterbuilders);
|
responseObject.put("masterbuilders", masterbuilders);
|
||||||
responseObject.put("superadmins", superadmins);
|
responseObject.put("superadmins", superadmins);
|
||||||
responseObject.put("telnetadmins", telnetadmins);
|
responseObject.put("telnetadmins", telnetadmins);
|
||||||
responseObject.put("senioradmins", senioradmins);
|
responseObject.put("senioradmins", senioradmins);
|
||||||
responseObject.put("developers", developers);
|
responseObject.put("developers", developers);
|
||||||
|
responseObject.put("executives", developers);
|
||||||
|
|
||||||
final NanoHTTPD.Response response = new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, NanoHTTPD.MIME_JSON, responseObject.toString());
|
final NanoHTTPD.Response response = new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, NanoHTTPD.MIME_JSON, responseObject.toString());
|
||||||
response.addHeader("Access-Control-Allow-Origin", "*");
|
response.addHeader("Access-Control-Allow-Origin", "*");
|
||||||
|
Loading…
Reference in New Issue
Block a user