mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2025-06-29 19:46:42 +00:00
index httpd module
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user