aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar')
-rw-r--r--src/main/java/org/traccar/config/Keys.java7
-rw-r--r--src/main/java/org/traccar/web/ModernDefaultServlet.java26
-rw-r--r--src/main/java/org/traccar/web/WebServer.java4
3 files changed, 35 insertions, 2 deletions
diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java
index 162a3fe13..4ebdd49f1 100644
--- a/src/main/java/org/traccar/config/Keys.java
+++ b/src/main/java/org/traccar/config/Keys.java
@@ -754,6 +754,13 @@ public final class Keys {
List.of(KeyType.CONFIG));
/**
+ * Path to a folder with overrides. It can be used for branding to keep custom logos in a separate place.
+ */
+ public static final ConfigKey<String> WEB_OVERRIDE = new StringConfigKey(
+ "web.override",
+ List.of(KeyType.CONFIG));
+
+ /**
* WebSocket connection timeout in milliseconds. Default timeout is 10 minutes.
*/
public static final ConfigKey<Long> WEB_TIMEOUT = new LongConfigKey(
diff --git a/src/main/java/org/traccar/web/ModernDefaultServlet.java b/src/main/java/org/traccar/web/ModernDefaultServlet.java
index bae089d6c..7911c0e7f 100644
--- a/src/main/java/org/traccar/web/ModernDefaultServlet.java
+++ b/src/main/java/org/traccar/web/ModernDefaultServlet.java
@@ -17,11 +17,37 @@ package org.traccar.web;
import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.util.resource.Resource;
+import org.traccar.config.Config;
+import org.traccar.config.Keys;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.IOException;
public class ModernDefaultServlet extends DefaultServlet {
+ private Resource overrideResource;
+
+ @Inject
+ public ModernDefaultServlet(Config config) {
+ String override = config.getString(Keys.WEB_OVERRIDE);
+ if (override != null) {
+ overrideResource = Resource.newResource(new File(override));
+ }
+ }
+
@Override
public Resource getResource(String pathInContext) {
+ if (overrideResource != null) {
+ try {
+ Resource override = overrideResource.addPath(pathInContext);
+ if (override.exists()) {
+ return override;
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
return super.getResource(pathInContext.indexOf('.') < 0 ? "/" : pathInContext);
}
diff --git a/src/main/java/org/traccar/web/WebServer.java b/src/main/java/org/traccar/web/WebServer.java
index ce1220157..b5d2f2771 100644
--- a/src/main/java/org/traccar/web/WebServer.java
+++ b/src/main/java/org/traccar/web/WebServer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2022 Anton Tananaev (anton@traccar.org)
+ * Copyright 2012 - 2023 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -141,7 +141,7 @@ public class WebServer implements LifecycleObject {
}
private void initWebApp(ServletContextHandler servletHandler) {
- ServletHolder servletHolder = new ServletHolder(ModernDefaultServlet.class);
+ ServletHolder servletHolder = new ServletHolder(new ModernDefaultServlet(config));
servletHolder.setInitParameter("resourceBase", new File(config.getString(Keys.WEB_PATH)).getAbsolutePath());
servletHolder.setInitParameter("dirAllowed", "false");
if (config.getBoolean(Keys.WEB_DEBUG)) {