From 3d793f502e1d48eb9c1dd60005ccf6c8682d73ca Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 7 Apr 2024 14:55:48 -0700 Subject: Add Open Location Code geocoder --- src/main/java/org/traccar/MainModule.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/main/java/org/traccar/MainModule.java') diff --git a/src/main/java/org/traccar/MainModule.java b/src/main/java/org/traccar/MainModule.java index 791d61c61..d1d3d4663 100644 --- a/src/main/java/org/traccar/MainModule.java +++ b/src/main/java/org/traccar/MainModule.java @@ -66,7 +66,7 @@ import org.traccar.geocoder.MapmyIndiaGeocoder; import org.traccar.geocoder.NominatimGeocoder; import org.traccar.geocoder.OpenCageGeocoder; import org.traccar.geocoder.PositionStackGeocoder; -import org.traccar.geocoder.TestGeocoder; +import org.traccar.geocoder.PlusCodesGeocoder; import org.traccar.geocoder.TomTomGeocoder; import org.traccar.geolocation.GeolocationProvider; import org.traccar.geolocation.GoogleGeolocationProvider; @@ -211,8 +211,8 @@ public class MainModule extends AbstractModule { int cacheSize = config.getInteger(Keys.GEOCODER_CACHE_SIZE); Geocoder geocoder; switch (type) { - case "test": - geocoder = new TestGeocoder(); + case "pluscodes": + geocoder = new PlusCodesGeocoder(); break; case "nominatim": geocoder = new NominatimGeocoder(client, url, key, language, cacheSize, addressFormat); -- cgit v1.2.3 From ef67a4c1577b2fbabb04c4de9b08b6d778c78952 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 17 Apr 2024 07:47:01 -0700 Subject: Move some defaults to the code --- setup/default.xml | 33 ------------ src/main/java/org/traccar/MainModule.java | 4 +- src/main/java/org/traccar/config/Keys.java | 59 ++++++++++++++-------- .../org/traccar/database/StatisticsManager.java | 2 +- .../java/org/traccar/storage/DatabaseModule.java | 5 +- 5 files changed, 43 insertions(+), 60 deletions(-) (limited to 'src/main/java/org/traccar/MainModule.java') diff --git a/setup/default.xml b/setup/default.xml index 7422bdf05..02c0650c3 100644 --- a/setup/default.xml +++ b/setup/default.xml @@ -10,39 +10,6 @@ --> - 8082 - ./web - ./override - false - false - true - - true - locationiq - pk.689d849289c8c63708068b2ff1f63b2d - true - true - - info - ./logs/tracker-server.log - true - - true - 86400 - - true - - ./media - - web,mail,command - - https://www.traccar.org/analytics/ - - true - - true - ./schema/changelog-master.xml - 5001 5002 5003 diff --git a/src/main/java/org/traccar/MainModule.java b/src/main/java/org/traccar/MainModule.java index d1d3d4663..89d3d2fe0 100644 --- a/src/main/java/org/traccar/MainModule.java +++ b/src/main/java/org/traccar/MainModule.java @@ -191,7 +191,7 @@ public class MainModule extends AbstractModule { @Provides public static WebServer provideWebServer(Injector injector, Config config) { - if (config.hasKey(Keys.WEB_PORT)) { + if (config.getInteger(Keys.WEB_PORT) > 0) { return new WebServer(injector, config); } return null; @@ -201,7 +201,7 @@ public class MainModule extends AbstractModule { @Provides public static Geocoder provideGeocoder(Config config, Client client, StatisticsManager statisticsManager) { if (config.getBoolean(Keys.GEOCODER_ENABLE)) { - String type = config.getString(Keys.GEOCODER_TYPE, "google"); + String type = config.getString(Keys.GEOCODER_TYPE); String url = config.getString(Keys.GEOCODER_URL); String key = config.getString(Keys.GEOCODER_KEY); String language = config.getString(Keys.GEOCODER_LANGUAGE); diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java index db3c5c9ed..0d34c75dc 100644 --- a/src/main/java/org/traccar/config/Keys.java +++ b/src/main/java/org/traccar/config/Keys.java @@ -320,7 +320,8 @@ public final class Keys { */ public static final ConfigKey SERVER_STATISTICS = new StringConfigKey( "server.statistics", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + "https://www.traccar.org/analytics/"); /** * Fuel drop threshold value. When fuel level drops from one position to another for more the value, an event is @@ -397,7 +398,8 @@ public final class Keys { */ public static final ConfigKey EVENT_IGNORE_DUPLICATE_ALERTS = new BooleanConfigKey( "event.ignoreDuplicateAlerts", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + true); /** * If set to true, invalid positions will be considered for motion logic. @@ -472,7 +474,8 @@ public final class Keys { */ public static final ConfigKey DATABASE_CHANGELOG = new StringConfigKey( "database.changelog", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + "./schema/changelog-master.xml"); /** * Database connection pool size. Default value is defined by the HikariCP library. @@ -736,7 +739,8 @@ public final class Keys { */ public static final ConfigKey MEDIA_PATH = new StringConfigKey( "media.path", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + "./media"); /** * Optional parameter to specify network interface for web interface to bind to. By default server will bind to all @@ -747,12 +751,13 @@ public final class Keys { List.of(KeyType.CONFIG)); /** - * Web interface TCP port number. By default Traccar uses port 8082. To avoid specifying port in the browser you + * Web interface TCP port number. By default, Traccar uses port 8082. To avoid specifying port in the browser you * can set it to 80 (default HTTP port). */ public static final ConfigKey WEB_PORT = new IntegerConfigKey( "web.port", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + 8082); /** * Maximum API requests per second. Above this limit requests and delayed and throttled. @@ -782,14 +787,16 @@ public final class Keys { */ public static final ConfigKey WEB_PATH = new StringConfigKey( "web.path", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + "./web"); /** * Path to a folder with overrides. It can be used for branding to keep custom logos in a separate place. */ public static final ConfigKey WEB_OVERRIDE = new StringConfigKey( "web.override", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + "./override"); /** * WebSocket connection timeout in milliseconds. Default timeout is 5 minutes. @@ -1172,7 +1179,8 @@ public final class Keys { */ public static final ConfigKey NOTIFICATOR_TYPES = new StringConfigKey( "notificator.types", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + "web,mail,command"); /** * If the event time is too old, we should not send notifications. This parameter is the threshold value in @@ -1338,7 +1346,8 @@ public final class Keys { */ public static final ConfigKey FILTER_ENABLE = new BooleanConfigKey( "filter.enable", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + true); /** * Filter invalid (valid field is set to false) positions. @@ -1376,7 +1385,8 @@ public final class Keys { */ public static final ConfigKey FILTER_FUTURE = new LongConfigKey( "filter.future", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + 86400L); /** * Filter records with fix time in the past. The value is specified in seconds. Records that have fix time more @@ -1587,15 +1597,16 @@ public final class Keys { */ public static final ConfigKey GEOCODER_ENABLE = new BooleanConfigKey( "geocoder.enable", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + true); /** - * Reverse geocoder type. Check reverse geocoding documentation for more info. By default (if the value is not - * specified) server uses Google API. + * Reverse geocoder type. Check reverse geocoding documentation for more info. */ public static final ConfigKey GEOCODER_TYPE = new StringConfigKey( "geocoder.type", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + "locationiq"); /** * Geocoder server URL. Applicable only to Nominatim and Gisgraphy providers. @@ -1609,7 +1620,8 @@ public final class Keys { */ public static final ConfigKey GEOCODER_KEY = new StringConfigKey( "geocoder.key", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + "pk.689d849289c8c63708068b2ff1f63b2d"); /** * Language parameter for providers that support localization (e.g. Google and Nominatim). @@ -1637,7 +1649,8 @@ public final class Keys { */ public static final ConfigKey GEOCODER_IGNORE_POSITIONS = new BooleanConfigKey( "geocoder.ignorePositions", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + true); /** * Boolean flag to apply reverse geocoding to invalid positions. @@ -1659,7 +1672,8 @@ public final class Keys { */ public static final ConfigKey GEOCODER_ON_REQUEST = new BooleanConfigKey( "geocoder.onRequest", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + true); /** * Boolean flag to enable LBS location resolution. Some devices send cell towers information and WiFi point when GPS @@ -1860,7 +1874,8 @@ public final class Keys { */ public static final ConfigKey LOGGER_FILE = new StringConfigKey( "logger.file", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + "./logs/tracker-server.log"); /** * Logging level. Default value is 'info'. @@ -1868,7 +1883,8 @@ public final class Keys { */ public static final ConfigKey LOGGER_LEVEL = new StringConfigKey( "logger.level", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + "info"); /** * Print full exception traces. Useful for debugging. By default shortened traces are logged. @@ -1883,7 +1899,8 @@ public final class Keys { */ public static final ConfigKey LOGGER_ROTATE = new BooleanConfigKey( "logger.rotate", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + true); /** * Log file rotation interval, the default rotation interval is once a day. diff --git a/src/main/java/org/traccar/database/StatisticsManager.java b/src/main/java/org/traccar/database/StatisticsManager.java index 445e53e7c..8711289a0 100644 --- a/src/main/java/org/traccar/database/StatisticsManager.java +++ b/src/main/java/org/traccar/database/StatisticsManager.java @@ -121,7 +121,7 @@ public class StatisticsManager { } String url = config.getString(Keys.SERVER_STATISTICS); - if (url != null) { + if (url != null && !url.isEmpty()) { String time = DateUtil.formatDate(statistics.getCaptureTime()); Form form = new Form(); diff --git a/src/main/java/org/traccar/storage/DatabaseModule.java b/src/main/java/org/traccar/storage/DatabaseModule.java index 9d9e5bd5e..9898a2fca 100644 --- a/src/main/java/org/traccar/storage/DatabaseModule.java +++ b/src/main/java/org/traccar/storage/DatabaseModule.java @@ -78,7 +78,8 @@ public class DatabaseModule extends AbstractModule { DataSource dataSource = new HikariDataSource(hikariConfig); - if (config.hasKey(Keys.DATABASE_CHANGELOG)) { + String changelog = config.getString(Keys.DATABASE_CHANGELOG); + if (changelog != null && !changelog.isEmpty()) { ResourceAccessor resourceAccessor = new DirectoryResourceAccessor(new File(".")); @@ -89,8 +90,6 @@ public class DatabaseModule extends AbstractModule { config.getString(Keys.DATABASE_DRIVER), null, null, null, resourceAccessor); - String changelog = config.getString(Keys.DATABASE_CHANGELOG); - try (Liquibase liquibase = new Liquibase(changelog, resourceAccessor, database)) { liquibase.clearCheckSums(); liquibase.update(new Contexts()); -- cgit v1.2.3 From d83502ac2885c64a9d65a17e1573dedc9b0680d4 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 1 Jun 2024 13:44:30 -0700 Subject: Remove sanitization option --- build.gradle | 1 - src/main/java/org/traccar/MainModule.java | 6 +-- src/main/java/org/traccar/config/Keys.java | 8 ---- .../java/org/traccar/helper/SanitizerModule.java | 45 ---------------------- 4 files changed, 1 insertion(+), 59 deletions(-) delete mode 100644 src/main/java/org/traccar/helper/SanitizerModule.java (limited to 'src/main/java/org/traccar/MainModule.java') diff --git a/build.gradle b/build.gradle index 77fe9ec36..c24e25843 100644 --- a/build.gradle +++ b/build.gradle @@ -53,7 +53,6 @@ dependencies { implementation "org.slf4j:slf4j-jdk14:2.0.12" implementation "com.google.inject:guice:$guiceVersion" implementation "com.google.inject.extensions:guice-servlet:$guiceVersion" - implementation "org.owasp.encoder:encoder:1.2.3" implementation "org.glassfish:jakarta.json:2.0.1" implementation "com.sun.mail:jakarta.mail:2.0.1" implementation "org.eclipse.jetty:jetty-server:$jettyVersion" diff --git a/src/main/java/org/traccar/MainModule.java b/src/main/java/org/traccar/MainModule.java index 89d3d2fe0..66238ab44 100644 --- a/src/main/java/org/traccar/MainModule.java +++ b/src/main/java/org/traccar/MainModule.java @@ -79,7 +79,6 @@ import org.traccar.handler.GeolocationHandler; import org.traccar.handler.SpeedLimitHandler; import org.traccar.handler.TimeHandler; import org.traccar.helper.ObjectMapperContextResolver; -import org.traccar.helper.SanitizerModule; import org.traccar.helper.WebHelper; import org.traccar.mail.LogMailManager; import org.traccar.mail.MailManager; @@ -132,11 +131,8 @@ public class MainModule extends AbstractModule { @Singleton @Provides - public static ObjectMapper provideObjectMapper(Config config) { + public static ObjectMapper provideObjectMapper() { ObjectMapper objectMapper = new ObjectMapper(); - if (config.getBoolean(Keys.WEB_SANITIZE)) { - objectMapper.registerModule(new SanitizerModule()); - } objectMapper.registerModule(new JSONPModule()); objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); return objectMapper; diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java index 5d9a43c01..91d5dac5d 100644 --- a/src/main/java/org/traccar/config/Keys.java +++ b/src/main/java/org/traccar/config/Keys.java @@ -774,14 +774,6 @@ public final class Keys { List.of(KeyType.CONFIG), 600); - /** - * Sanitize all strings returned via API. This is needed to fix XSS issues in the old web interface. New React-based - * interface doesn't require this. - */ - public static final ConfigKey WEB_SANITIZE = new BooleanConfigKey( - "web.sanitize", - List.of(KeyType.CONFIG)); - /** * Path to the web app folder. */ diff --git a/src/main/java/org/traccar/helper/SanitizerModule.java b/src/main/java/org/traccar/helper/SanitizerModule.java deleted file mode 100644 index af9ac5c2b..000000000 --- a/src/main/java/org/traccar/helper/SanitizerModule.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2018 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.traccar.helper; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.module.SimpleModule; -import com.fasterxml.jackson.databind.ser.std.StdSerializer; -import org.owasp.encoder.Encode; - -import java.io.IOException; - -public class SanitizerModule extends SimpleModule { - - public static class SanitizerSerializer extends StdSerializer { - - protected SanitizerSerializer() { - super(String.class); - } - - @Override - public void serialize(String value, JsonGenerator gen, SerializerProvider provider) throws IOException { - gen.writeString(Encode.forHtml(value)); - } - - } - - public SanitizerModule() { - addSerializer(new SanitizerSerializer()); - } - -} -- cgit v1.2.3