mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-12-20 23:57:36 +01:00
commit
fbe431d9ac
@ -2,8 +2,9 @@ description = "DynmapCore"
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile project(path: ':DynmapCoreAPI', configuration: 'shadow')
|
compile project(path: ':DynmapCoreAPI', configuration: 'shadow')
|
||||||
compile 'org.eclipse.jetty:jetty-server:8.1.21.v20160908'
|
compile 'javax.servlet:javax.servlet-api:3.1'
|
||||||
compile 'org.eclipse.jetty:jetty-servlet:8.1.21.v20160908'
|
compile 'org.eclipse.jetty:jetty-server:9.4.24.v20191120'
|
||||||
|
compile 'org.eclipse.jetty:jetty-servlet:9.4.24.v20191120'
|
||||||
compile 'com.googlecode.json-simple:json-simple:1.1.1'
|
compile 'com.googlecode.json-simple:json-simple:1.1.1'
|
||||||
compile 'org.yaml:snakeyaml:1.23'
|
compile 'org.yaml:snakeyaml:1.23'
|
||||||
compile 'com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:20180219.1'
|
compile 'com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:20180219.1'
|
||||||
@ -36,6 +37,7 @@ shadowJar {
|
|||||||
include(dependency('com.googlecode.json-simple:json-simple:'))
|
include(dependency('com.googlecode.json-simple:json-simple:'))
|
||||||
include(dependency('org.yaml:snakeyaml:'))
|
include(dependency('org.yaml:snakeyaml:'))
|
||||||
include(dependency('com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:'))
|
include(dependency('com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:'))
|
||||||
|
include(dependency('javax.servlet::'))
|
||||||
include(dependency('org.eclipse.jetty::'))
|
include(dependency('org.eclipse.jetty::'))
|
||||||
include(dependency('org.eclipse.jetty.orbit:javax.servlet:'))
|
include(dependency('org.eclipse.jetty.orbit:javax.servlet:'))
|
||||||
include(dependency(':DynmapCoreAPI'))
|
include(dependency(':DynmapCoreAPI'))
|
||||||
|
@ -11,6 +11,7 @@ import java.io.InputStreamReader;
|
|||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
@ -65,10 +66,12 @@ import org.dynmap.web.CustomHeaderFilter;
|
|||||||
import org.dynmap.web.FilterHandler;
|
import org.dynmap.web.FilterHandler;
|
||||||
import org.dynmap.web.HandlerRouter;
|
import org.dynmap.web.HandlerRouter;
|
||||||
import org.eclipse.jetty.server.Connector;
|
import org.eclipse.jetty.server.Connector;
|
||||||
|
import org.eclipse.jetty.server.NetworkTrafficServerConnector;
|
||||||
import org.eclipse.jetty.server.Server;
|
import org.eclipse.jetty.server.Server;
|
||||||
|
import org.eclipse.jetty.server.handler.AllowSymLinkAliasChecker;
|
||||||
|
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||||
import org.eclipse.jetty.server.handler.HandlerList;
|
import org.eclipse.jetty.server.handler.HandlerList;
|
||||||
import org.eclipse.jetty.server.nio.SelectChannelConnector;
|
import org.eclipse.jetty.server.session.DefaultSessionIdManager;
|
||||||
import org.eclipse.jetty.server.session.HashSessionIdManager;
|
|
||||||
import org.eclipse.jetty.server.session.SessionHandler;
|
import org.eclipse.jetty.server.session.SessionHandler;
|
||||||
import org.eclipse.jetty.servlet.ServletHolder;
|
import org.eclipse.jetty.servlet.ServletHolder;
|
||||||
import org.eclipse.jetty.util.resource.FileResource;
|
import org.eclipse.jetty.util.resource.FileResource;
|
||||||
@ -768,21 +771,17 @@ public class DynmapCore implements DynmapCommonAPI {
|
|||||||
webhostname = configuration.getString("webserver-bindaddress", ip);
|
webhostname = configuration.getString("webserver-bindaddress", ip);
|
||||||
webport = configuration.getInteger("webserver-port", 8123);
|
webport = configuration.getInteger("webserver-port", 8123);
|
||||||
|
|
||||||
webServer = new Server();
|
|
||||||
webServer.setSessionIdManager(new HashSessionIdManager());
|
|
||||||
|
|
||||||
int maxconnections = configuration.getInteger("max-sessions", 30);
|
int maxconnections = configuration.getInteger("max-sessions", 30);
|
||||||
if(maxconnections < 2) maxconnections = 2;
|
if(maxconnections < 2) maxconnections = 2;
|
||||||
LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(maxconnections);
|
LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(maxconnections);
|
||||||
ExecutorThreadPool pool = new ExecutorThreadPool(2, maxconnections, 60, TimeUnit.SECONDS, queue);
|
ExecutorThreadPool pool = new ExecutorThreadPool(maxconnections, 2, queue);
|
||||||
webServer.setThreadPool(pool);
|
|
||||||
|
|
||||||
SelectChannelConnector connector=new SelectChannelConnector();
|
webServer = new Server(pool);
|
||||||
connector.setMaxIdleTime(5000);
|
webServer.setSessionIdManager(new DefaultSessionIdManager(webServer));
|
||||||
connector.setAcceptors(1);
|
|
||||||
|
NetworkTrafficServerConnector connector = new NetworkTrafficServerConnector(webServer);
|
||||||
|
connector.setIdleTimeout(5000);
|
||||||
connector.setAcceptQueueSize(50);
|
connector.setAcceptQueueSize(50);
|
||||||
connector.setLowResourcesMaxIdleTime(1000);
|
|
||||||
connector.setLowResourcesConnections(maxconnections/2);
|
|
||||||
if(webhostname.equals("0.0.0.0") == false)
|
if(webhostname.equals("0.0.0.0") == false)
|
||||||
connector.setHost(webhostname);
|
connector.setHost(webhostname);
|
||||||
connector.setPort(webport);
|
connector.setPort(webport);
|
||||||
@ -790,15 +789,37 @@ public class DynmapCore implements DynmapCommonAPI {
|
|||||||
|
|
||||||
webServer.setStopAtShutdown(true);
|
webServer.setStopAtShutdown(true);
|
||||||
//webServer.setGracefulShutdown(1000);
|
//webServer.setGracefulShutdown(1000);
|
||||||
|
|
||||||
final boolean allow_symlinks = configuration.getBoolean("allow-symlinks", false);
|
final boolean allow_symlinks = configuration.getBoolean("allow-symlinks", false);
|
||||||
router = new HandlerRouter() {{
|
router = new HandlerRouter() {{
|
||||||
this.addHandler("/", new FileResourceHandler() {{
|
FileResourceHandler fileResourceHandler = new FileResourceHandler() {{
|
||||||
this.setAliases(allow_symlinks);
|
|
||||||
this.setWelcomeFiles(new String[] { "index.html" });
|
this.setWelcomeFiles(new String[] { "index.html" });
|
||||||
|
this.setRedirectWelcome(false);
|
||||||
this.setDirectoriesListed(true);
|
this.setDirectoriesListed(true);
|
||||||
this.setBaseResource(createFileResource(getFile(getWebPath()).getAbsolutePath()));
|
this.setBaseResource(createFileResource(getFile(getWebPath()).getAbsolutePath()));
|
||||||
}});
|
}};
|
||||||
|
try {
|
||||||
|
fileResourceHandler.doStart();
|
||||||
|
}catch (Exception ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
Log.severe("Failed to start resource handler: "+ex.getMessage());
|
||||||
|
}
|
||||||
|
ContextHandler fileResourceContext = new ContextHandler();
|
||||||
|
fileResourceContext.setHandler(fileResourceHandler);
|
||||||
|
fileResourceContext.clearAliasChecks();
|
||||||
|
if (allow_symlinks){
|
||||||
|
fileResourceContext.addAliasCheck(new ContextHandler.ApproveAliases());
|
||||||
|
fileResourceContext.addAliasCheck(new ContextHandler.ApproveNonExistentDirectoryAliases());
|
||||||
|
fileResourceContext.addAliasCheck(new AllowSymLinkAliasChecker());
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Class<?> handlerClass = fileResourceHandler.getClass().getSuperclass().getSuperclass();
|
||||||
|
Field field = handlerClass.getDeclaredField("_context");
|
||||||
|
field.setAccessible(true);
|
||||||
|
field.set(fileResourceHandler,fileResourceContext);
|
||||||
|
}catch (Exception e){
|
||||||
|
Log.severe("Failed to initialize resource handler: "+e.getMessage());
|
||||||
|
}
|
||||||
|
this.addHandler("/", fileResourceHandler);
|
||||||
this.addHandler("/tiles/*", new MapStorageResourceHandler() {{
|
this.addHandler("/tiles/*", new MapStorageResourceHandler() {{
|
||||||
this.setCore(DynmapCore.this);
|
this.setCore(DynmapCore.this);
|
||||||
}});
|
}});
|
||||||
|
@ -49,12 +49,7 @@ public class FileResourceHandler extends ResourceHandler {
|
|||||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
||||||
Resource resource;
|
Resource resource;
|
||||||
String normalizedTarget = getNormalizedPath(target);
|
String normalizedTarget = getNormalizedPath(target);
|
||||||
|
|
||||||
try {
|
|
||||||
resource = getResource(normalizedTarget);
|
resource = getResource(normalizedTarget);
|
||||||
} catch(MalformedURLException ex) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (resource == null) {
|
if (resource == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -63,7 +58,7 @@ public class FileResourceHandler extends ResourceHandler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(!target.equals(normalizedTarget)){
|
if(!target.equals(normalizedTarget)){
|
||||||
baseRequest.setRequestURI(normalizedTarget);
|
baseRequest.setURIPathQuery(normalizedTarget);
|
||||||
baseRequest.setPathInfo(normalizedTarget);
|
baseRequest.setPathInfo(normalizedTarget);
|
||||||
try{
|
try{
|
||||||
Class<?> requestClass = request.getClass();
|
Class<?> requestClass = request.getClass();
|
||||||
|
@ -35,6 +35,10 @@ public class JettyNullLogger implements Logger {
|
|||||||
public void debug(String s, Object... objects) {
|
public void debug(String s, Object... objects) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void debug(String s, long l) {
|
||||||
|
}
|
||||||
|
|
||||||
public void debug(Throwable throwable) {
|
public void debug(Throwable throwable) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.dynmap.web;
|
package org.dynmap.web;
|
||||||
|
|
||||||
|
import org.dynmap.Log;
|
||||||
import org.eclipse.jetty.server.Handler;
|
import org.eclipse.jetty.server.Handler;
|
||||||
import org.eclipse.jetty.server.Request;
|
import org.eclipse.jetty.server.Request;
|
||||||
import org.eclipse.jetty.server.handler.AbstractHandler;
|
import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||||
@ -22,7 +23,14 @@ public class FilterHandler extends AbstractHandler {
|
|||||||
public FilterHandler(Handler handler, Iterable<Filter> filters) {
|
public FilterHandler(Handler handler, Iterable<Filter> filters) {
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
for(Filter f : filters) {
|
for(Filter f : filters) {
|
||||||
this.filters.add(new FilterHolder(f));
|
try {
|
||||||
|
FilterHolder holder = new FilterHolder(f);
|
||||||
|
holder.start();
|
||||||
|
holder.initialize();
|
||||||
|
this.filters.add(holder);
|
||||||
|
}catch (Exception e){
|
||||||
|
Log.severe("Failed to initialize filter holder: "+e.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ public class HandlerRouter extends AbstractHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
||||||
String pathInfo = request.getPathInfo();
|
String pathInfo = request.getPathInfo();
|
||||||
PathMap.Entry e = pathMap.getMatch(pathInfo);
|
PathMap.MappedEntry e = pathMap.getMatch(pathInfo);
|
||||||
String mappedPath = e.getMapped();
|
String mappedPath = e.getMapped();
|
||||||
|
|
||||||
String childPathInfo = pathInfo;
|
String childPathInfo = pathInfo;
|
||||||
|
Loading…
Reference in New Issue
Block a user