mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
commit
cdb28afba6
@ -45,6 +45,7 @@ public enum ConfigEntry
|
|||||||
MOB_LIMITER_DISABLE_SLIME(Boolean.class, "moblimiter.disable.slime"),
|
MOB_LIMITER_DISABLE_SLIME(Boolean.class, "moblimiter.disable.slime"),
|
||||||
//
|
//
|
||||||
HTTPD_ENABLED(Boolean.class, "httpd.enabled"),
|
HTTPD_ENABLED(Boolean.class, "httpd.enabled"),
|
||||||
|
HTTPD_HOST(String.class, "httpd.host"),
|
||||||
HTTPD_PORT(Integer.class, "httpd.port"),
|
HTTPD_PORT(Integer.class, "httpd.port"),
|
||||||
HTTPD_PUBLIC_FOLDER(String.class, "httpd.public_folder"),
|
HTTPD_PUBLIC_FOLDER(String.class, "httpd.public_folder"),
|
||||||
//
|
//
|
||||||
@ -172,7 +173,7 @@ public enum ConfigEntry
|
|||||||
FAMOUS_PLAYERS(List.class, "famous_players"),
|
FAMOUS_PLAYERS(List.class, "famous_players"),
|
||||||
STAFF_ONLY_MODE(Boolean.class, "staff_only_mode"),
|
STAFF_ONLY_MODE(Boolean.class, "staff_only_mode"),
|
||||||
STAFF_INFO(List.class, "staffinfo"),
|
STAFF_INFO(List.class, "staffinfo"),
|
||||||
VOTING_INFO(List.class, "votinginfo"),
|
VOTING_INFO(List.class, "votinginfo"),
|
||||||
MASTER_BUILDER_INFO(List.class, "masterbuilderinfo"),
|
MASTER_BUILDER_INFO(List.class, "masterbuilderinfo"),
|
||||||
AUTO_ENTITY_WIPE(Boolean.class, "auto_wipe"),
|
AUTO_ENTITY_WIPE(Boolean.class, "auto_wipe"),
|
||||||
TOGGLE_CHAT(Boolean.class, "toggle_chat"),
|
TOGGLE_CHAT(Boolean.class, "toggle_chat"),
|
||||||
|
@ -7,11 +7,6 @@ import static org.apache.commons.lang3.StringEscapeUtils.escapeHtml4;
|
|||||||
|
|
||||||
public class HTMLGenerationTools
|
public class HTMLGenerationTools
|
||||||
{
|
{
|
||||||
|
|
||||||
private HTMLGenerationTools()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String paragraph(String data)
|
public static String paragraph(String data)
|
||||||
{
|
{
|
||||||
return "<p>" + escapeHtml4(data) + "</p>\r\n";
|
return "<p>" + escapeHtml4(data) + "</p>\r\n";
|
||||||
|
@ -20,14 +20,10 @@ public class HTTPDPageBuilder
|
|||||||
+ "<script src=\"//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js\"></script>\r\n"
|
+ "<script src=\"//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js\"></script>\r\n"
|
||||||
+ "<script>\r\n{$SCRIPT}\r\n</script>\r\n";
|
+ "<script>\r\n{$SCRIPT}\r\n</script>\r\n";
|
||||||
//
|
//
|
||||||
private String body = null;
|
private String body;
|
||||||
private String title = null;
|
private String title;
|
||||||
private String style = null;
|
private String style;
|
||||||
private String script = null;
|
private String script;
|
||||||
|
|
||||||
public HTTPDPageBuilder()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public HTTPDPageBuilder(String body, String title, String style, String script)
|
public HTTPDPageBuilder(String body, String title, String style, String script)
|
||||||
{
|
{
|
||||||
@ -71,4 +67,4 @@ public class HTTPDPageBuilder
|
|||||||
.replace("{$STYLE}", this.style == null ? "" : STYLE.replace("{$STYLE}", this.style))
|
.replace("{$STYLE}", this.style == null ? "" : STYLE.replace("{$STYLE}", this.style))
|
||||||
.replace("{$SCRIPT}", this.script == null ? "" : SCRIPT.replace("{$SCRIPT}", this.script));
|
.replace("{$SCRIPT}", this.script == null ? "" : SCRIPT.replace("{$SCRIPT}", this.script));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -16,6 +16,7 @@ import me.totalfreedom.totalfreedommod.httpd.module.Module_bans;
|
|||||||
import me.totalfreedom.totalfreedommod.httpd.module.Module_file;
|
import me.totalfreedom.totalfreedommod.httpd.module.Module_file;
|
||||||
import me.totalfreedom.totalfreedommod.httpd.module.Module_help;
|
import me.totalfreedom.totalfreedommod.httpd.module.Module_help;
|
||||||
import me.totalfreedom.totalfreedommod.httpd.module.Module_indefbans;
|
import me.totalfreedom.totalfreedommod.httpd.module.Module_indefbans;
|
||||||
|
import me.totalfreedom.totalfreedommod.httpd.module.Module_index;
|
||||||
import me.totalfreedom.totalfreedommod.httpd.module.Module_list;
|
import me.totalfreedom.totalfreedommod.httpd.module.Module_list;
|
||||||
import me.totalfreedom.totalfreedommod.httpd.module.Module_logfile;
|
import me.totalfreedom.totalfreedommod.httpd.module.Module_logfile;
|
||||||
import me.totalfreedom.totalfreedommod.httpd.module.Module_logs;
|
import me.totalfreedom.totalfreedommod.httpd.module.Module_logs;
|
||||||
@ -47,7 +48,6 @@ public class HTTPDaemon extends FreedomService
|
|||||||
}
|
}
|
||||||
|
|
||||||
port = ConfigEntry.HTTPD_PORT.getInteger();
|
port = ConfigEntry.HTTPD_PORT.getInteger();
|
||||||
;
|
|
||||||
httpd = new HTTPD(port);
|
httpd = new HTTPD(port);
|
||||||
|
|
||||||
// Modules
|
// Modules
|
||||||
@ -63,6 +63,7 @@ public class HTTPDaemon extends FreedomService
|
|||||||
module("players", Module_players.class, false);
|
module("players", Module_players.class, false);
|
||||||
module("punishments", Module_punishments.class, true);
|
module("punishments", Module_punishments.class, true);
|
||||||
module("schematic", Module_schematic.class, true);
|
module("schematic", Module_schematic.class, true);
|
||||||
|
module("index", Module_index.class, false);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -103,7 +104,6 @@ public class HTTPDaemon extends FreedomService
|
|||||||
|
|
||||||
private class HTTPD extends NanoHTTPD
|
private class HTTPD extends NanoHTTPD
|
||||||
{
|
{
|
||||||
|
|
||||||
private HTTPD(int port)
|
private HTTPD(int port)
|
||||||
{
|
{
|
||||||
super(port);
|
super(port);
|
||||||
@ -177,8 +177,6 @@ public class HTTPDaemon extends FreedomService
|
|||||||
FLog.severe(ex);
|
FLog.severe(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
@ -0,0 +1,64 @@
|
|||||||
|
package me.totalfreedom.totalfreedommod.httpd.module;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||||
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
|
import me.totalfreedom.totalfreedommod.httpd.HTMLGenerationTools;
|
||||||
|
import me.totalfreedom.totalfreedommod.httpd.HTTPDPageBuilder;
|
||||||
|
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
|
||||||
|
import org.reflections.Reflections;
|
||||||
|
|
||||||
|
public class Module_index extends HTTPDModule
|
||||||
|
{
|
||||||
|
|
||||||
|
public Module_index(TotalFreedomMod plugin, NanoHTTPD.HTTPSession session)
|
||||||
|
{
|
||||||
|
super(plugin, session);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NanoHTTPD.Response getResponse()
|
||||||
|
{
|
||||||
|
return new HTTPDPageBuilder(body(), title(), null, null).getResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String body()
|
||||||
|
{
|
||||||
|
final StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
sb.append(HTMLGenerationTools.heading("TotalFreedom HTTPd Module List", 1));
|
||||||
|
|
||||||
|
Reflections r = new Reflections("me.totalfreedom.totalfreedommod.httpd.module");
|
||||||
|
|
||||||
|
Set<Class<? extends HTTPDModule>> moduleClasses = r.getSubTypesOf(HTTPDModule.class);
|
||||||
|
|
||||||
|
for (Class c : moduleClasses)
|
||||||
|
{
|
||||||
|
String name = c.getSimpleName().replace("Module_", "");
|
||||||
|
|
||||||
|
if (name.equals("file"))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// <a href="http://localhost:28966/index">index</a>
|
||||||
|
sb.append("<ul><li>");
|
||||||
|
sb.append("<a href=\"http://")
|
||||||
|
.append(ConfigEntry.HTTPD_HOST.getString())
|
||||||
|
.append(":")
|
||||||
|
.append(ConfigEntry.HTTPD_PORT.getInteger())
|
||||||
|
.append("/")
|
||||||
|
.append(name)
|
||||||
|
.append("\">")
|
||||||
|
.append(name)
|
||||||
|
.append("</a>")
|
||||||
|
.append("</li></ul>");
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String title()
|
||||||
|
{
|
||||||
|
return "TotalFreedom :: HTTPd Modules";
|
||||||
|
}
|
||||||
|
}
|
@ -7,6 +7,7 @@ import java.util.Collections;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||||
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
import me.totalfreedom.totalfreedommod.httpd.HTMLGenerationTools;
|
import me.totalfreedom.totalfreedommod.httpd.HTMLGenerationTools;
|
||||||
import me.totalfreedom.totalfreedommod.httpd.HTTPDPageBuilder;
|
import me.totalfreedom.totalfreedommod.httpd.HTTPDPageBuilder;
|
||||||
import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon;
|
import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon;
|
||||||
@ -57,7 +58,6 @@ public class Module_logfile extends HTTPDModule
|
|||||||
{
|
{
|
||||||
FLog.warning("The logfile module failed to find the logs folder.");
|
FLog.warning("The logfile module failed to find the logs folder.");
|
||||||
return HTMLGenerationTools.paragraph("Can't find the logs folder.");
|
return HTMLGenerationTools.paragraph("Can't find the logs folder.");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final StringBuilder out = new StringBuilder();
|
final StringBuilder out = new StringBuilder();
|
||||||
@ -128,21 +128,28 @@ public class Module_logfile extends HTTPDModule
|
|||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
out.append(HTMLGenerationTools.paragraph("Invalid request mode."));
|
out.append(HTMLGenerationTools.heading("Logfile Submodules", 1));
|
||||||
|
out.append("<ul><li>");
|
||||||
|
out.append("<a href=\"http://")
|
||||||
|
.append(ConfigEntry.HTTPD_HOST.getString())
|
||||||
|
.append(":")
|
||||||
|
.append(ConfigEntry.HTTPD_PORT.getInteger())
|
||||||
|
.append("/logfile/list")
|
||||||
|
.append("\">Logfile List</a></li>")
|
||||||
|
.append("<li><a href=\"http://")
|
||||||
|
.append(ConfigEntry.HTTPD_HOST.getString())
|
||||||
|
.append(":")
|
||||||
|
.append(ConfigEntry.HTTPD_PORT.getInteger())
|
||||||
|
.append("/logfile/download")
|
||||||
|
.append("\">Download Specified Logfile</a></li></ul>");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return out.toString();
|
return out.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Response downloadLogFile(String LogFilesName) throws LogFileTransferException
|
private Response downloadLogFile(String LogFilesName) throws LogFileTransferException
|
||||||
{
|
{
|
||||||
if (LogFilesName == null)
|
|
||||||
{
|
|
||||||
throw new LogFileTransferException("Invalid logfile requested: " + LogFilesName);
|
|
||||||
}
|
|
||||||
|
|
||||||
final File targetFile = new File(LOG_FOLDER.getPath(), LogFilesName);
|
final File targetFile = new File(LOG_FOLDER.getPath(), LogFilesName);
|
||||||
if (!targetFile.exists())
|
if (!targetFile.exists())
|
||||||
{
|
{
|
||||||
@ -230,5 +237,4 @@ public class Module_logfile extends HTTPDModule
|
|||||||
return INVALID;
|
return INVALID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
@ -14,6 +14,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||||
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
import me.totalfreedom.totalfreedommod.httpd.HTMLGenerationTools;
|
import me.totalfreedom.totalfreedommod.httpd.HTMLGenerationTools;
|
||||||
import me.totalfreedom.totalfreedommod.httpd.HTTPDPageBuilder;
|
import me.totalfreedom.totalfreedommod.httpd.HTTPDPageBuilder;
|
||||||
import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon;
|
import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon;
|
||||||
@ -114,12 +115,10 @@ public class Module_schematic extends HTTPDModule
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
out
|
out.append(HTMLGenerationTools.heading("Schematics:", 1))
|
||||||
.append(HTMLGenerationTools.heading("Schematics:", 1))
|
|
||||||
.append("<ul>")
|
.append("<ul>")
|
||||||
.append(StringUtils.join(schematicsFormatted, "\r\n"))
|
.append(StringUtils.join(schematicsFormatted, "\r\n"))
|
||||||
.append("</ul>");
|
.append("</ul>");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DOWNLOAD:
|
case DOWNLOAD:
|
||||||
@ -165,11 +164,23 @@ public class Module_schematic extends HTTPDModule
|
|||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
out.append(HTMLGenerationTools.paragraph("Invalid request mode."));
|
out.append(HTMLGenerationTools.heading("Schematic Submodules", 1));
|
||||||
|
out.append("<ul><li>");
|
||||||
|
out.append("<a href=\"http://")
|
||||||
|
.append(ConfigEntry.HTTPD_HOST.getString())
|
||||||
|
.append(":")
|
||||||
|
.append(ConfigEntry.HTTPD_PORT.getInteger())
|
||||||
|
.append("/schematic/list")
|
||||||
|
.append("\">Schematic List</a></li>")
|
||||||
|
.append("<li><a href=\"http://")
|
||||||
|
.append(ConfigEntry.HTTPD_HOST.getString())
|
||||||
|
.append(":")
|
||||||
|
.append(ConfigEntry.HTTPD_PORT.getInteger())
|
||||||
|
.append("/schematic/upload")
|
||||||
|
.append("\">Upload Schematics</a></li></ul>");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return out.toString();
|
return out.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,7 +227,6 @@ public class Module_schematic extends HTTPDModule
|
|||||||
throw new SchematicTransferException("Schematic already exists on the server.");
|
throw new SchematicTransferException("Schematic already exists on the server.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
FileUtils.copyFile(tempFile, targetFile);
|
FileUtils.copyFile(tempFile, targetFile);
|
||||||
@ -344,5 +354,4 @@ public class Module_schematic extends HTTPDModule
|
|||||||
return INVALID;
|
return INVALID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
@ -195,7 +195,7 @@ forceip:
|
|||||||
|
|
||||||
# TotalFreedom Social Media Links, casing will be preserved
|
# TotalFreedom Social Media Links, casing will be preserved
|
||||||
social_links:
|
social_links:
|
||||||
Forum: 'https://totalfreedom.boards.net/'
|
Forum: 'https://forum.totalfreedom.me'
|
||||||
Website: 'https://totalfreedom.me/'
|
Website: 'https://totalfreedom.me/'
|
||||||
Discord: 'https://discordapp.com/invite/XXjmAmV/'
|
Discord: 'https://discordapp.com/invite/XXjmAmV/'
|
||||||
|
|
||||||
@ -401,7 +401,7 @@ announcer:
|
|||||||
prefix: '&5[&eTotalFreedom&5] &b'
|
prefix: '&5[&eTotalFreedom&5] &b'
|
||||||
|
|
||||||
announcements:
|
announcements:
|
||||||
- 'Be sure to visit our forums at &6http://totalfreedom.boards.net/'
|
- 'Be sure to visit our forums at &6https://forum.totalfreedom.me/'
|
||||||
- 'If you are not OP, be sure to ask!'
|
- 'If you are not OP, be sure to ask!'
|
||||||
- 'Somebody breaking the rules? Report it! /report <user> <reason>'
|
- 'Somebody breaking the rules? Report it! /report <user> <reason>'
|
||||||
- 'Griefing is not allowed!'
|
- 'Griefing is not allowed!'
|
||||||
@ -429,7 +429,7 @@ staffinfo:
|
|||||||
- ' &2- Be helpful within the server'
|
- ' &2- Be helpful within the server'
|
||||||
- ' &6- Report those breaking the rules'
|
- ' &6- Report those breaking the rules'
|
||||||
- ' &2- And apply on our forums at the link:'
|
- ' &2- And apply on our forums at the link:'
|
||||||
- ' &9www.totalfreedom.boards.net'
|
- ' &9https://forum.totalfreedom.me/'
|
||||||
|
|
||||||
# What to display in the vote command.
|
# What to display in the vote command.
|
||||||
votinginfo:
|
votinginfo:
|
||||||
@ -503,6 +503,7 @@ service_checker_url: http://status.mojang.com/check
|
|||||||
# HTTPD server
|
# HTTPD server
|
||||||
httpd:
|
httpd:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
host: play.totalfreedom.me
|
||||||
port: 28966
|
port: 28966
|
||||||
public_folder: ./public_html
|
public_folder: ./public_html
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user