From 24575aba88e487669854b193a2c362806d4516be Mon Sep 17 00:00:00 2001 From: speedxx <43330808+speedxx@users.noreply.github.com> Date: Mon, 17 Aug 2020 18:17:45 -0400 Subject: [PATCH] index httpd module --- .../totalfreedommod/config/ConfigEntry.java | 3 +- .../httpd/HTMLGenerationTools.java | 5 -- .../httpd/HTTPDPageBuilder.java | 14 ++-- .../totalfreedommod/httpd/HTTPDaemon.java | 8 +-- .../httpd/module/Module_index.java | 64 +++++++++++++++++++ .../httpd/module/Module_logfile.java | 26 +++++--- .../httpd/module/Module_schematic.java | 25 +++++--- src/main/resources/config.yml | 7 +- 8 files changed, 111 insertions(+), 41 deletions(-) create mode 100644 src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_index.java diff --git a/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java b/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java index 6c6657b7..de9b8acb 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java @@ -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"), // @@ -172,7 +173,7 @@ public enum ConfigEntry FAMOUS_PLAYERS(List.class, "famous_players"), STAFF_ONLY_MODE(Boolean.class, "staff_only_mode"), STAFF_INFO(List.class, "staffinfo"), - VOTING_INFO(List.class, "votinginfo"), + VOTING_INFO(List.class, "votinginfo"), MASTER_BUILDER_INFO(List.class, "masterbuilderinfo"), AUTO_ENTITY_WIPE(Boolean.class, "auto_wipe"), TOGGLE_CHAT(Boolean.class, "toggle_chat"), diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTMLGenerationTools.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTMLGenerationTools.java index 4570f14d..23bc066c 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTMLGenerationTools.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTMLGenerationTools.java @@ -7,11 +7,6 @@ import static org.apache.commons.lang3.StringEscapeUtils.escapeHtml4; public class HTMLGenerationTools { - - private HTMLGenerationTools() - { - } - public static String paragraph(String data) { return "

" + escapeHtml4(data) + "

\r\n"; diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDPageBuilder.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDPageBuilder.java index 5a9b5d54..b4027a0d 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDPageBuilder.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDPageBuilder.java @@ -20,14 +20,10 @@ public class HTTPDPageBuilder + "\r\n" + "\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) { @@ -71,4 +67,4 @@ public class HTTPDPageBuilder .replace("{$STYLE}", this.style == null ? "" : STYLE.replace("{$STYLE}", this.style)) .replace("{$SCRIPT}", this.script == null ? "" : SCRIPT.replace("{$SCRIPT}", this.script)); } -} +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDaemon.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDaemon.java index cd334bfd..a18d0375 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDaemon.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDaemon.java @@ -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; } - -} +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_index.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_index.java new file mode 100644 index 00000000..8b3fb66b --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_index.java @@ -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> moduleClasses = r.getSubTypesOf(HTTPDModule.class); + + for (Class c : moduleClasses) + { + String name = c.getSimpleName().replace("Module_", ""); + + if (name.equals("file")) + { + continue; + } + + // index + sb.append(""); + } + return sb.toString(); + } + + public String title() + { + return "TotalFreedom :: HTTPd Modules"; + } +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_logfile.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_logfile.java index 2765f401..8767cf64 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_logfile.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_logfile.java @@ -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(""); 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; } } - -} +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_schematic.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_schematic.java index a983bef9..3c64d5bf 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_schematic.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_schematic.java @@ -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(""); - 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(""); 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; } } - -} +} \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 0b5ec05f..0e33a3a1 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -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 ' - '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