mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
piss off
Signed-off-by: Robinson Gallego <robinson.leal7@gmail.com>
This commit is contained in:
parent
635316dcd2
commit
bcb466a95c
@ -15,7 +15,6 @@ import me.totalfreedom.totalfreedommod.httpd.module.HTTPDModule;
|
||||
import me.totalfreedom.totalfreedommod.httpd.module.Module_activitylog;
|
||||
import me.totalfreedom.totalfreedommod.httpd.module.Module_admins;
|
||||
import me.totalfreedom.totalfreedommod.httpd.module.Module_bans;
|
||||
import me.totalfreedom.totalfreedommod.httpd.module.Module_dump;
|
||||
import me.totalfreedom.totalfreedommod.httpd.module.Module_file;
|
||||
import me.totalfreedom.totalfreedommod.httpd.module.Module_help;
|
||||
import me.totalfreedom.totalfreedommod.httpd.module.Module_list;
|
||||
@ -62,7 +61,6 @@ public class HTTPDaemon extends FreedomService
|
||||
module("activitylog", Module_activitylog.class, true);
|
||||
module("admins", Module_admins.class, true);
|
||||
module("bans", Module_bans.class, true);
|
||||
module("dump", Module_dump.class, true);
|
||||
module("file", Module_file.class, true);
|
||||
module("help", Module_help.class, false);
|
||||
module("list", Module_list.class, false);
|
||||
|
@ -1,115 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod.httpd.module;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon;
|
||||
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import static me.totalfreedom.totalfreedommod.httpd.HTMLGenerationTools.list;
|
||||
import static me.totalfreedom.totalfreedommod.httpd.HTMLGenerationTools.paragraph;
|
||||
|
||||
public class Module_dump extends HTTPDModule
|
||||
{
|
||||
|
||||
private File echoFile = null;
|
||||
private final String body;
|
||||
|
||||
public Module_dump(TotalFreedomMod plugin, NanoHTTPD.HTTPSession session)
|
||||
{
|
||||
super(plugin, session);
|
||||
|
||||
//Body needs to be computed before getResponse, so we know if a text response or a file echo is needed.
|
||||
this.body = body();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NanoHTTPD.Response getResponse()
|
||||
{
|
||||
String echo = params.get("echo");
|
||||
boolean doEcho = echo != null && ((echo = echo.toLowerCase().trim()).equalsIgnoreCase("true") || echo.equalsIgnoreCase("1"));
|
||||
|
||||
if (doEcho && this.echoFile != null && this.echoFile.exists())
|
||||
{
|
||||
return HTTPDaemon.serveFileBasic(this.echoFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
return super.getResponse();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBody()
|
||||
{
|
||||
return body;
|
||||
}
|
||||
|
||||
private String body()
|
||||
{
|
||||
StringBuilder responseBody = new StringBuilder();
|
||||
|
||||
String remoteAddress = socket.getInetAddress().getHostAddress();
|
||||
|
||||
String[] args = StringUtils.split(uri, "/");
|
||||
|
||||
Map<String, String> files = getFiles();
|
||||
|
||||
responseBody
|
||||
.append(paragraph("URI: " + uri))
|
||||
.append(paragraph("args (Length: " + args.length + "): " + StringUtils.join(args, ",")))
|
||||
.append(paragraph("Method: " + method.toString()))
|
||||
.append(paragraph("Remote Address: " + remoteAddress))
|
||||
.append(paragraph("Headers:"))
|
||||
.append(list(headers))
|
||||
.append(paragraph("Params:"))
|
||||
.append(list(params))
|
||||
.append(paragraph("Files:"))
|
||||
.append(list(files));
|
||||
|
||||
Iterator<Map.Entry<String, String>> it = files.entrySet().iterator();
|
||||
while (it.hasNext())
|
||||
{
|
||||
Map.Entry<String, String> entry = it.next();
|
||||
String formName = entry.getKey();
|
||||
String tempFileName = entry.getValue();
|
||||
String origFileName = params.get(formName);
|
||||
|
||||
File tempFile = new File(tempFileName);
|
||||
if (tempFile.exists())
|
||||
{
|
||||
this.echoFile = tempFile;
|
||||
|
||||
if (origFileName.contains("../"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
String targetFileName = "./public_html/uploads/" + origFileName;
|
||||
|
||||
File targetFile = new File(targetFileName);
|
||||
|
||||
try
|
||||
{
|
||||
FileUtils.copyFile(tempFile, targetFile);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return responseBody.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle()
|
||||
{
|
||||
return "TotalFreedomMod :: Request Debug Dumper";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user