mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-12-25 01:57:53 +01:00
Initial file filter code
This commit is contained in:
parent
2b1d0aa955
commit
806e8c056a
@ -60,6 +60,7 @@ import org.dynmap.utils.BlockStep;
|
||||
import org.dynmap.utils.ImageIOManager;
|
||||
import org.dynmap.web.BanIPFilter;
|
||||
import org.dynmap.web.CustomHeaderFilter;
|
||||
import org.dynmap.web.FileNameFilter;
|
||||
import org.dynmap.web.FilterHandler;
|
||||
import org.dynmap.web.HandlerRouter;
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
@ -973,6 +974,8 @@ public class DynmapCore implements DynmapCommonAPI {
|
||||
if (checkbannedips) {
|
||||
filters.add(new BanIPFilter(this));
|
||||
}
|
||||
filters.add(new FileNameFilter(this));
|
||||
|
||||
// filters.add(new LoginFilter(this));
|
||||
|
||||
/* Load customized response headers, if any */
|
||||
|
34
DynmapCore/src/main/java/org/dynmap/web/FileNameFilter.java
Normal file
34
DynmapCore/src/main/java/org/dynmap/web/FileNameFilter.java
Normal file
@ -0,0 +1,34 @@
|
||||
package org.dynmap.web;
|
||||
|
||||
import org.dynmap.DynmapCore;
|
||||
import org.dynmap.Log;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class FileNameFilter implements Filter {
|
||||
|
||||
public FileNameFilter(DynmapCore core) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException { }
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
||||
String path = ((HttpServletRequest)request).getRequestURL().toString();
|
||||
HttpServletResponse resp = (HttpServletResponse)response;
|
||||
// Filter unneeded file requests
|
||||
if (path.toLowerCase().endsWith(".php")) {
|
||||
resp.sendError(404);
|
||||
} else {
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() { }
|
||||
}
|
Loading…
Reference in New Issue
Block a user