mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-30 02:05:41 +00:00
Merge branch 'development' of https://github.com/TFPatches/TotalFreedomMod into development
This commit is contained in:
commit
f3a655d40d
@ -45,6 +45,7 @@ public enum ConfigEntry
|
||||
MOB_LIMITER_DISABLE_SLIME(Boolean.class, "moblimiter.disable.slime"),
|
||||
//
|
||||
HTTPD_ENABLED(Boolean.class, "httpd.enabled"),
|
||||
HTTPD_HOST(String.class, "httpd.host"),
|
||||
HTTPD_PORT(Integer.class, "httpd.port"),
|
||||
HTTPD_PUBLIC_FOLDER(String.class, "httpd.public_folder"),
|
||||
//
|
||||
|
@ -7,11 +7,6 @@ import static org.apache.commons.lang3.StringEscapeUtils.escapeHtml4;
|
||||
|
||||
public class HTMLGenerationTools
|
||||
{
|
||||
|
||||
private HTMLGenerationTools()
|
||||
{
|
||||
}
|
||||
|
||||
public static String paragraph(String data)
|
||||
{
|
||||
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>\r\n{$SCRIPT}\r\n</script>\r\n";
|
||||
//
|
||||
private String body = null;
|
||||
private String title = null;
|
||||
private String style = null;
|
||||
private String script = null;
|
||||
|
||||
public HTTPDPageBuilder()
|
||||
{
|
||||
}
|
||||
private String body;
|
||||
private String title;
|
||||
private String style;
|
||||
private String script;
|
||||
|
||||
public HTTPDPageBuilder(String body, String title, String style, String 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_help;
|
||||
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_logfile;
|
||||
import me.totalfreedom.totalfreedommod.httpd.module.Module_logs;
|
||||
@ -47,7 +48,6 @@ public class HTTPDaemon extends FreedomService
|
||||
}
|
||||
|
||||
port = ConfigEntry.HTTPD_PORT.getInteger();
|
||||
;
|
||||
httpd = new HTTPD(port);
|
||||
|
||||
// Modules
|
||||
@ -63,6 +63,7 @@ public class HTTPDaemon extends FreedomService
|
||||
module("players", Module_players.class, false);
|
||||
module("punishments", Module_punishments.class, true);
|
||||
module("schematic", Module_schematic.class, true);
|
||||
module("index", Module_index.class, false);
|
||||
|
||||
try
|
||||
{
|
||||
@ -103,7 +104,6 @@ public class HTTPDaemon extends FreedomService
|
||||
|
||||
private class HTTPD extends NanoHTTPD
|
||||
{
|
||||
|
||||
private HTTPD(int port)
|
||||
{
|
||||
super(port);
|
||||
@ -177,8 +177,6 @@ public class HTTPDaemon extends FreedomService
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
|
||||
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.List;
|
||||
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.HTTPDaemon;
|
||||
@ -57,7 +58,6 @@ public class Module_logfile extends HTTPDModule
|
||||
{
|
||||
FLog.warning("The logfile module failed to find the logs folder.");
|
||||
return HTMLGenerationTools.paragraph("Can't find the logs folder.");
|
||||
|
||||
}
|
||||
|
||||
final StringBuilder out = new StringBuilder();
|
||||
@ -128,21 +128,28 @@ public class Module_logfile extends HTTPDModule
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
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);
|
||||
if (!targetFile.exists())
|
||||
{
|
||||
@ -230,5 +237,4 @@ public class Module_logfile extends HTTPDModule
|
||||
return INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -14,6 +14,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
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.HTTPDaemon;
|
||||
@ -114,12 +115,10 @@ public class Module_schematic extends HTTPDModule
|
||||
}
|
||||
});
|
||||
|
||||
out
|
||||
.append(HTMLGenerationTools.heading("Schematics:", 1))
|
||||
out.append(HTMLGenerationTools.heading("Schematics:", 1))
|
||||
.append("<ul>")
|
||||
.append(StringUtils.join(schematicsFormatted, "\r\n"))
|
||||
.append("</ul>");
|
||||
|
||||
break;
|
||||
}
|
||||
case DOWNLOAD:
|
||||
@ -165,11 +164,23 @@ public class Module_schematic extends HTTPDModule
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
@ -216,7 +227,6 @@ public class Module_schematic extends HTTPDModule
|
||||
throw new SchematicTransferException("Schematic already exists on the server.");
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
FileUtils.copyFile(tempFile, targetFile);
|
||||
@ -344,5 +354,4 @@ public class Module_schematic extends HTTPDModule
|
||||
return INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -195,7 +195,7 @@ forceip:
|
||||
|
||||
# TotalFreedom Social Media Links, casing will be preserved
|
||||
social_links:
|
||||
Forum: 'https://totalfreedom.boards.net/'
|
||||
Forum: 'https://forum.totalfreedom.me'
|
||||
Website: 'https://totalfreedom.me/'
|
||||
Discord: 'https://discordapp.com/invite/XXjmAmV/'
|
||||
|
||||
@ -401,7 +401,7 @@ announcer:
|
||||
prefix: '&5[&eTotalFreedom&5] &b'
|
||||
|
||||
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!'
|
||||
- 'Somebody breaking the rules? Report it! /report <user> <reason>'
|
||||
- 'Griefing is not allowed!'
|
||||
@ -429,7 +429,7 @@ staffinfo:
|
||||
- ' &2- Be helpful within the server'
|
||||
- ' &6- Report those breaking the rules'
|
||||
- ' &2- And apply on our forums at the link:'
|
||||
- ' &9www.totalfreedom.boards.net'
|
||||
- ' &9https://forum.totalfreedom.me/'
|
||||
|
||||
# What to display in the vote command.
|
||||
votinginfo:
|
||||
@ -503,6 +503,7 @@ service_checker_url: http://status.mojang.com/check
|
||||
# HTTPD server
|
||||
httpd:
|
||||
enabled: true
|
||||
host: play.totalfreedom.me
|
||||
port: 28966
|
||||
public_folder: ./public_html
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user