From 725d738de64bd7df7ec05786baf6590c15a105b9 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 13 Apr 2024 07:25:54 -0700 Subject: Option to block notifications for users --- src/main/java/org/traccar/config/Keys.java | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/main/java/org/traccar/config/Keys.java') diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java index d346084bd..db3c5c9ed 100644 --- a/src/main/java/org/traccar/config/Keys.java +++ b/src/main/java/org/traccar/config/Keys.java @@ -1260,6 +1260,13 @@ public final class Keys { "notification.expiration.device.reminder", List.of(KeyType.CONFIG)); + /** + * Block notifications for specific users. The value should be a comma-separated list of internal user ids. + */ + public static final ConfigKey NOTIFICATION_BLOCK_USERS = new StringConfigKey( + "notification.block.users", + List.of(KeyType.CONFIG)); + /** * Maximum time period for reports in seconds. Can be useful to prevent users to request unreasonably long reports. * By default, there is no limit. -- 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/config/Keys.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 dc6f5d92527624afb11225e94494e6604aaf8082 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 17 Apr 2024 17:21:26 -0700 Subject: Fix comment --- src/main/java/org/traccar/config/Keys.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/main/java/org/traccar/config/Keys.java') diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java index 0d34c75dc..44037fb2e 100644 --- a/src/main/java/org/traccar/config/Keys.java +++ b/src/main/java/org/traccar/config/Keys.java @@ -23,7 +23,7 @@ public final class Keys { } /** - * Network interface for a the protocol. If not specified, server will bind all interfaces. + * Network interface for the protocol. If not specified, server will bind all interfaces. */ public static final ConfigSuffix PROTOCOL_ADDRESS = new StringConfigSuffix( ".address", @@ -674,7 +674,7 @@ public final class Keys { /** * OpenID Connect Authorization URL. * This can usually be found in the documentation of your identity provider or by using the well-known - * configuration endpoint, e.g. https://auth.example.com//.well-known/openid-configuration + * configuration endpoint, e.g. https://auth.example.com/.well-known/openid-configuration * Required to enable SSO if openid.issuerUrl is not set. */ public static final ConfigKey OPENID_AUTH_URL = new StringConfigKey( -- cgit v1.2.3 From 93c4e0ef2f882c4818b542b7792e9b02975f9da7 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 17 Apr 2024 20:53:14 -0700 Subject: Migrate default ports to code --- debug.xml | 4 - setup/default.xml | 271 -------------------- setup/traccar.xml | 16 +- src/main/java/org/traccar/ServerManager.java | 2 +- src/main/java/org/traccar/config/Keys.java | 2 +- .../java/org/traccar/config/PortConfigSuffix.java | 278 +++++++++++++++++++++ 6 files changed, 281 insertions(+), 292 deletions(-) delete mode 100644 setup/default.xml create mode 100644 src/main/java/org/traccar/config/PortConfigSuffix.java (limited to 'src/main/java/org/traccar/config/Keys.java') diff --git a/debug.xml b/debug.xml index 89b5a5ba3..15fa57324 100644 --- a/debug.xml +++ b/debug.xml @@ -1,11 +1,7 @@ - - - ./setup/default.xml - ./traccar-web/simple true true diff --git a/setup/default.xml b/setup/default.xml deleted file mode 100644 index 02c0650c3..000000000 --- a/setup/default.xml +++ /dev/null @@ -1,271 +0,0 @@ - - - - - - - - - 5001 - 5002 - 5003 - 5004 - 5005 - 5006 - false - 5007 - 5008 - 5009 - 5010 - 5011 - 5012 - 5013 - 5014 - 5015 - 5016 - 5017 - 5018 - 5019 - 5020 - 5021 - 5022 - 5023 - 5024 - 5025 - 5026 - 5027 - 5028 - 5029 - 5030 - 5031 - 5032 - 5033 - 5034 - 5035 - 5036 - 5037 - 5038 - 5039 - 5040 - 5041 - 5042 - 5043 - 5044 - 5045 - 5046 - 5047 - 5048 - 5049 - 5050 - 5051 - 5052 - 5053 - 5054 - 5055 - 5056 - 5057 - 5058 - 5059 - 5060 - 5061 - 5062 - 5063 - 5064 - 5065 - 5066 - 5067 - 5068 - 5069 - 5070 - 5071 - 5072 - 5073 - 5074 - 5075 - 5076 - 5077 - 5078 - 5079 - 5080 - 5081 - 5082 - 5083 - 5084 - 5085 - 5086 - 5087 - 5088 - 5089 - 5090 - 5091 - 5092 - 5093 - 5094 - 5095 - 5096 - 5097 - 5098 - 5099 - 5100 - 5101 - 5102 - 5103 - 5104 - 5105 - 5106 - 5107 - 5108 - 5109 - 5110 - 5111 - 5112 - 5113 - 5114 - 5115 - 5116 - 5117 - 5118 - 5119 - 5120 - 5121 - 5122 - 5123 - 5124 - 5125 - 5126 - 5127 - 5128 - 5129 - 5130 - 5131 - 5132 - 5133 - 5134 - 5135 - 5136 - 5137 - 5138 - 5139 - 5140 - 5141 - 5142 - 5143 - 5144 - 5145 - 5146 - 5147 - 5148 - 5149 - 5150 - 5151 - 5152 - 5153 - 5154 - 5155 - 5156 - 5157 - 5158 - 5159 - 5160 - 5161 - 5162 - 5163 - 5164 - 5165 - 5166 - 5167 - 5168 - 5169 - 5170 - 5171 - 5172 - 5173 - 5174 - 5175 - 5176 - 5177 - 5178 - 5179 - 5180 - 5181 - 5182 - 5183 - 5184 - 5185 - 5186 - 5187 - 5188 - 5189 - 5190 - 5191 - 5192 - 5193 - 5194 - 5195 - 5196 - 5197 - 5198 - 5199 - 5200 - 5201 - 5202 - 5203 - 5204 - 5205 - 5206 - 5207 - 5208 - 5209 - 5210 - 5211 - 5212 - 5213 - 5214 - 5215 - 5216 - 5217 - 5218 - 5219 - 5220 - 5221 - 5222 - 5223 - 5224 - 5225 - 5226 - 5227 - 5228 - 5229 - 5230 - 5231 - 5232 - 5233 - 5234 - 5235 - 5236 - 5237 - 5238 - 5239 - 5240 - 5241 - 5242 - 5243 - 5244 - 5245 - 5246 - 5247 - 5248 - 5249 - 5250 - 5251 - 5252 - 5253 - 5254 - 5255 - 5256 - - diff --git a/setup/traccar.xml b/setup/traccar.xml index aab9ba311..d5bd87e9c 100644 --- a/setup/traccar.xml +++ b/setup/traccar.xml @@ -1,22 +1,8 @@ - - - ./conf/default.xml - - + org.h2.Driver jdbc:h2:./data/database diff --git a/src/main/java/org/traccar/ServerManager.java b/src/main/java/org/traccar/ServerManager.java index 22af66b41..1b0c441cf 100644 --- a/src/main/java/org/traccar/ServerManager.java +++ b/src/main/java/org/traccar/ServerManager.java @@ -54,7 +54,7 @@ public class ServerManager implements LifecycleObject { for (Class protocolClass : ClassScanner.findSubclasses(BaseProtocol.class, "org.traccar.protocol")) { String protocolName = BaseProtocol.nameFromClass(protocolClass); if (enabledProtocols == null || enabledProtocols.contains(protocolName)) { - if (config.hasKey(Keys.PROTOCOL_PORT.withPrefix(protocolName))) { + if (config.getInteger(Keys.PROTOCOL_PORT.withPrefix(protocolName)) > 0) { BaseProtocol protocol = (BaseProtocol) injector.getInstance(protocolClass); connectorList.addAll(protocol.getConnectorList()); protocolList.put(protocol.getName(), protocol); diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java index 44037fb2e..a2aa42e1c 100644 --- a/src/main/java/org/traccar/config/Keys.java +++ b/src/main/java/org/traccar/config/Keys.java @@ -33,7 +33,7 @@ public final class Keys { * Port number for the protocol. Most protocols use TCP on the transport layer. Some protocols use UDP. Some * support both TCP and UDP. */ - public static final ConfigSuffix PROTOCOL_PORT = new IntegerConfigSuffix( + public static final ConfigSuffix PROTOCOL_PORT = new PortConfigSuffix( ".port", List.of(KeyType.CONFIG)); diff --git a/src/main/java/org/traccar/config/PortConfigSuffix.java b/src/main/java/org/traccar/config/PortConfigSuffix.java new file mode 100644 index 000000000..11d6f2dbb --- /dev/null +++ b/src/main/java/org/traccar/config/PortConfigSuffix.java @@ -0,0 +1,278 @@ +package org.traccar.config; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class PortConfigSuffix extends ConfigSuffix { + + private static final Map PORTS = new HashMap<>(); + + static { + PORTS.put("gps103", 5001); + PORTS.put("tk103", 5002); + PORTS.put("gl100", 5003); + PORTS.put("gl200", 5004); + PORTS.put("t55", 5005); + PORTS.put("xexun", 5006); + PORTS.put("totem", 5007); + PORTS.put("enfora", 5008); + PORTS.put("meiligao", 5009); + PORTS.put("trv", 5010); + PORTS.put("suntech", 5011); + PORTS.put("progress", 5012); + PORTS.put("h02", 5013); + PORTS.put("jt600", 5014); + PORTS.put("huabao", 5015); + PORTS.put("v680", 5016); + PORTS.put("pt502", 5017); + PORTS.put("tr20", 5018); + PORTS.put("navis", 5019); + PORTS.put("meitrack", 5020); + PORTS.put("skypatrol", 5021); + PORTS.put("gt02", 5022); + PORTS.put("gt06", 5023); + PORTS.put("megastek", 5024); + PORTS.put("navigil", 5025); + PORTS.put("gpsgate", 5026); + PORTS.put("teltonika", 5027); + PORTS.put("mta6", 5028); + PORTS.put("tzone", 5029); + PORTS.put("tlt2h", 5030); + PORTS.put("taip", 5031); + PORTS.put("wondex", 5032); + PORTS.put("cellocator", 5033); + PORTS.put("galileo", 5034); + PORTS.put("ywt", 5035); + PORTS.put("tk102", 5036); + PORTS.put("intellitrac", 5037); + PORTS.put("gpsmta", 5038); + PORTS.put("wialon", 5039); + PORTS.put("carscop", 5040); + PORTS.put("apel", 5041); + PORTS.put("manpower", 5042); + PORTS.put("globalsat", 5043); + PORTS.put("atrack", 5044); + PORTS.put("pt3000", 5045); + PORTS.put("ruptela", 5046); + PORTS.put("topflytech", 5047); + PORTS.put("laipac", 5048); + PORTS.put("aplicom", 5049); + PORTS.put("gotop", 5050); + PORTS.put("sanav", 5051); + PORTS.put("gator", 5052); + PORTS.put("noran", 5053); + PORTS.put("m2m", 5054); + PORTS.put("osmand", 5055); + PORTS.put("easytrack", 5056); + PORTS.put("gpsmarker", 5057); + PORTS.put("khd", 5058); + PORTS.put("piligrim", 5059); + PORTS.put("stl060", 5060); + PORTS.put("cartrack", 5061); + PORTS.put("minifinder", 5062); + PORTS.put("haicom", 5063); + PORTS.put("eelink", 5064); + PORTS.put("box", 5065); + PORTS.put("freedom", 5066); + PORTS.put("telic", 5067); + PORTS.put("trackbox", 5068); + PORTS.put("visiontek", 5069); + PORTS.put("orion", 5070); + PORTS.put("riti", 5071); + PORTS.put("ulbotech", 5072); + PORTS.put("tramigo", 5073); + PORTS.put("tr900", 5074); + PORTS.put("ardi01", 5075); + PORTS.put("xt013", 5076); + PORTS.put("autofon", 5077); + PORTS.put("gosafe", 5078); + PORTS.put("tt8850", 5079); + PORTS.put("bce", 5080); + PORTS.put("xirgo", 5081); + PORTS.put("calamp", 5082); + PORTS.put("mtx", 5083); + PORTS.put("tytan", 5084); + PORTS.put("avl301", 5085); + PORTS.put("castel", 5086); + PORTS.put("mxt", 5087); + PORTS.put("cityeasy", 5088); + PORTS.put("aquila", 5089); + PORTS.put("flextrack", 5090); + PORTS.put("blackkite", 5091); + PORTS.put("adm", 5092); + PORTS.put("watch", 5093); + PORTS.put("t800x", 5094); + PORTS.put("upro", 5095); + PORTS.put("auro", 5096); + PORTS.put("disha", 5097); + PORTS.put("thinkrace", 5098); + PORTS.put("pathaway", 5099); + PORTS.put("arnavi", 5100); + PORTS.put("nvs", 5101); + PORTS.put("kenji", 5102); + PORTS.put("astra", 5103); + PORTS.put("homtecs", 5104); + PORTS.put("fox", 5105); + PORTS.put("gnx", 5106); + PORTS.put("arknav", 5107); + PORTS.put("supermate", 5108); + PORTS.put("appello", 5109); + PORTS.put("idpl", 5110); + PORTS.put("huasheng", 5111); + PORTS.put("l100", 5112); + PORTS.put("granit", 5113); + PORTS.put("carcell", 5114); + PORTS.put("obddongle", 5115); + PORTS.put("hunterpro", 5116); + PORTS.put("raveon", 5117); + PORTS.put("cradlepoint", 5118); + PORTS.put("arknavx8", 5119); + PORTS.put("autograde", 5120); + PORTS.put("oigo", 5121); + PORTS.put("jpkorjar", 5122); + PORTS.put("cguard", 5123); + PORTS.put("fifotrack", 5124); + PORTS.put("smokey", 5125); + PORTS.put("extremtrac", 5126); + PORTS.put("trakmate", 5127); + PORTS.put("at2000", 5128); + PORTS.put("maestro", 5129); + PORTS.put("ais", 5130); + PORTS.put("gt30", 5131); + PORTS.put("tmg", 5132); + PORTS.put("pretrace", 5133); + PORTS.put("pricol", 5134); + PORTS.put("siwi", 5135); + PORTS.put("starlink", 5136); + PORTS.put("dmt", 5137); + PORTS.put("xt2400", 5138); + PORTS.put("dmthttp", 5139); + PORTS.put("alematics", 5140); + PORTS.put("gps056", 5141); + PORTS.put("flexcomm", 5142); + PORTS.put("vt200", 5143); + PORTS.put("owntracks", 5144); + PORTS.put("vtfms", 5145); + PORTS.put("tlv", 5146); + PORTS.put("esky", 5147); + PORTS.put("genx", 5148); + PORTS.put("flespi", 5149); + PORTS.put("dway", 5150); + PORTS.put("recoda", 5151); + PORTS.put("oko", 5152); + PORTS.put("ivt401", 5153); + PORTS.put("sigfox", 5154); + PORTS.put("t57", 5155); + PORTS.put("spot", 5156); + PORTS.put("m2c", 5157); + PORTS.put("austinnb", 5158); + PORTS.put("opengts", 5159); + PORTS.put("cautela", 5160); + PORTS.put("continental", 5161); + PORTS.put("egts", 5162); + PORTS.put("robotrack", 5163); + PORTS.put("pt60", 5164); + PORTS.put("telemax", 5165); + PORTS.put("sabertek", 5166); + PORTS.put("retranslator", 5167); + PORTS.put("svias", 5168); + PORTS.put("eseal", 5169); + PORTS.put("freematics", 5170); + PORTS.put("avema", 5171); + PORTS.put("autotrack", 5172); + PORTS.put("tek", 5173); + PORTS.put("wristband", 5174); + PORTS.put("lacak", 5175); + PORTS.put("milesmate", 5176); + PORTS.put("anytrek", 5177); + PORTS.put("smartsole", 5178); + PORTS.put("its", 5179); + PORTS.put("xrb28", 5180); + PORTS.put("c2stek", 5181); + PORTS.put("nyitech", 5182); + PORTS.put("neos", 5183); + PORTS.put("satsol", 5184); + PORTS.put("globalstar", 5185); + PORTS.put("sanul", 5186); + PORTS.put("minifinder2", 5187); + PORTS.put("radar", 5188); + PORTS.put("techtlt", 5189); + PORTS.put("starcom", 5190); + PORTS.put("mictrack", 5191); + PORTS.put("plugin", 5192); + PORTS.put("leafspy", 5193); + PORTS.put("naviset", 5194); + PORTS.put("racedynamics", 5195); + PORTS.put("rst", 5196); + PORTS.put("pt215", 5197); + PORTS.put("pacifictrack", 5198); + PORTS.put("topin", 5199); + PORTS.put("outsafe", 5200); + PORTS.put("solarpowered", 5201); + PORTS.put("motor", 5202); + PORTS.put("omnicomm", 5203); + PORTS.put("s168", 5204); + PORTS.put("vnet", 5205); + PORTS.put("blue", 5206); + PORTS.put("pst", 5207); + PORTS.put("dingtek", 5208); + PORTS.put("wli", 5209); + PORTS.put("niot", 5210); + PORTS.put("portman", 5211); + PORTS.put("moovbox", 5212); + PORTS.put("futureway", 5213); + PORTS.put("polte", 5214); + PORTS.put("net", 5215); + PORTS.put("mobilogix", 5216); + PORTS.put("swiftech", 5217); + PORTS.put("iotm", 5218); + PORTS.put("dolphin", 5219); + PORTS.put("ennfu", 5220); + PORTS.put("navtelecom", 5221); + PORTS.put("startek", 5222); + PORTS.put("gs100", 5223); + PORTS.put("mavlink2", 5224); + PORTS.put("uux", 5225); + PORTS.put("r12w", 5226); + PORTS.put("flexiblereport", 5227); + PORTS.put("thinkpower", 5228); + PORTS.put("stb", 5229); + PORTS.put("b2316", 5230); + PORTS.put("hoopo", 5231); + PORTS.put("dualcam", 5232); + PORTS.put("xexun2", 5233); + PORTS.put("techtocruz", 5234); + PORTS.put("flexapi", 5235); + PORTS.put("dsf22", 5236); + PORTS.put("jido", 5237); + PORTS.put("armoli", 5238); + PORTS.put("teratrack", 5239); + PORTS.put("envotech", 5240); + PORTS.put("bstpl", 5241); + PORTS.put("thuraya", 5242); + PORTS.put("ndtpv6", 5243); + PORTS.put("g1rus", 5244); + PORTS.put("rftrack", 5245); + PORTS.put("vlt", 5246); + PORTS.put("transync", 5247); + PORTS.put("t622iridium", 5248); + PORTS.put("pui", 5249); + PORTS.put("nto", 5250); + PORTS.put("ramac", 5251); + PORTS.put("positrex", 5252); + PORTS.put("dragino", 5253); + PORTS.put("fleetguide", 5254); + PORTS.put("valtrack", 5255); + PORTS.put("snapper", 5256); + } + + PortConfigSuffix(String key, List types) { + super(key, types, null); + } + + @Override + public ConfigKey withPrefix(String protocol) { + return new IntegerConfigKey(protocol + keySuffix, types, PORTS.get(protocol)); + } +} -- cgit v1.2.3 From fb7a817440f3734e465c7843024d676c13f82d24 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 20 Apr 2024 07:28:01 -0700 Subject: Fix configuration issues --- src/main/java/org/traccar/config/Keys.java | 2 +- src/main/java/org/traccar/schedule/TaskExpirations.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/main/java/org/traccar/config/Keys.java') diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java index a2aa42e1c..0898e8f0a 100644 --- a/src/main/java/org/traccar/config/Keys.java +++ b/src/main/java/org/traccar/config/Keys.java @@ -601,7 +601,7 @@ public final class Keys { "uid"); /** - * LDAP attribute used as user name. Default value is 'cn'. + * LDAP attribute used as username. Default value is 'cn'. */ public static final ConfigKey LDAP_NAME_ATTRIBUTE = new StringConfigKey( "ldap.nameAttribute", diff --git a/src/main/java/org/traccar/schedule/TaskExpirations.java b/src/main/java/org/traccar/schedule/TaskExpirations.java index 94f855c5f..e16dcd86c 100644 --- a/src/main/java/org/traccar/schedule/TaskExpirations.java +++ b/src/main/java/org/traccar/schedule/TaskExpirations.java @@ -111,7 +111,7 @@ public class TaskExpirations implements ScheduleTask { } if (config.getBoolean(Keys.NOTIFICATION_EXPIRATION_DEVICE)) { - long reminder = config.getLong(Keys.NOTIFICATION_EXPIRATION_USER_REMINDER); + long reminder = config.getLong(Keys.NOTIFICATION_EXPIRATION_DEVICE_REMINDER); var devices = storage.getObjects(Device.class, new Request(new Columns.All())); for (Device device : devices) { if (checkTimeTrigger(device, currentTime, 0)) { -- cgit v1.2.3 From 5d647be37332790aab41731d52e8dcadac9d5eb4 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 4 May 2024 19:56:42 -0700 Subject: Improve daily limit throttling --- src/main/java/org/traccar/config/Keys.java | 9 +++++++- .../java/org/traccar/handler/FilterHandler.java | 24 ++++++++++++++-------- 2 files changed, 23 insertions(+), 10 deletions(-) (limited to 'src/main/java/org/traccar/config/Keys.java') diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java index 0898e8f0a..5d9a43c01 100644 --- a/src/main/java/org/traccar/config/Keys.java +++ b/src/main/java/org/traccar/config/Keys.java @@ -1443,12 +1443,19 @@ public final class Keys { List.of(KeyType.CONFIG)); /** - * Filter position if the daily limit is exceeded for the device. + * Throttle positions if the daily limit is exceeded for the device. */ public static final ConfigKey FILTER_DAILY_LIMIT = new IntegerConfigKey( "filter.dailyLimit", List.of(KeyType.CONFIG)); + /** + * Throttling interval if the limit exceeded. The value is in seconds. + */ + public static final ConfigKey FILTER_DAILY_LIMIT_INTERVAL = new IntegerConfigKey( + "filter.dailyLimitInterval", + List.of(KeyType.CONFIG)); + /** * If false, the server expects all locations to come sequentially (for each device). Filter checks for duplicates, * distance, speed, or time period only against the location that was last received by server. diff --git a/src/main/java/org/traccar/handler/FilterHandler.java b/src/main/java/org/traccar/handler/FilterHandler.java index 796c302fb..3bb7ef426 100644 --- a/src/main/java/org/traccar/handler/FilterHandler.java +++ b/src/main/java/org/traccar/handler/FilterHandler.java @@ -53,6 +53,7 @@ public class FilterHandler extends BasePositionHandler { private final int filterMaxSpeed; private final long filterMinPeriod; private final int filterDailyLimit; + private final long filterDailyLimitInterval; private final boolean filterRelative; private final long skipLimit; private final boolean skipAttributes; @@ -77,6 +78,7 @@ public class FilterHandler extends BasePositionHandler { filterMaxSpeed = config.getInteger(Keys.FILTER_MAX_SPEED); filterMinPeriod = config.getInteger(Keys.FILTER_MIN_PERIOD) * 1000L; filterDailyLimit = config.getInteger(Keys.FILTER_DAILY_LIMIT); + filterDailyLimitInterval = config.getInteger(Keys.FILTER_DAILY_LIMIT_INTERVAL) * 1000L; filterRelative = config.getBoolean(Keys.FILTER_RELATIVE); skipLimit = config.getLong(Keys.FILTER_SKIP_LIMIT) * 1000; skipAttributes = config.getBoolean(Keys.FILTER_SKIP_ATTRIBUTES_ENABLE); @@ -164,9 +166,12 @@ public class FilterHandler extends BasePositionHandler { return false; } - private boolean filterDailyLimit(Position position) { - if (filterDailyLimit != 0) { - return statisticsManager.messageStoredCount(position.getDeviceId()) >= filterDailyLimit; + private boolean filterDailyLimit(Position position, Position last) { + if (filterDailyLimit != 0 + && statisticsManager.messageStoredCount(position.getDeviceId()) >= filterDailyLimit) { + long lastTime = last != null ? last.getFixTime().getTime() : 0; + long interval = position.getFixTime().getTime() - lastTime; + return filterDailyLimitInterval <= 0 || interval < filterDailyLimitInterval; } return false; } @@ -216,20 +221,18 @@ public class FilterHandler extends BasePositionHandler { if (filterApproximate(position)) { filterType.append("Approximate "); } - if (filterDailyLimit(position)) { - filterType.append("DailyLimit "); - } // filter out excessive data long deviceId = position.getDeviceId(); - if (filterDuplicate || filterStatic || filterDistance > 0 || filterMaxSpeed > 0 || filterMinPeriod > 0) { - Position preceding = null; + if (filterDuplicate || filterStatic + || filterDistance > 0 || filterMaxSpeed > 0 || filterMinPeriod > 0 || filterDailyLimit > 0) { + Position preceding; if (filterRelative) { try { Date newFixTime = position.getFixTime(); preceding = getPrecedingPosition(deviceId, newFixTime); } catch (StorageException e) { - LOGGER.warn("Error retrieving preceding position; fallbacking to last received position.", e); + LOGGER.warn("Error retrieving preceding position; fall backing to last received position.", e); preceding = cacheManager.getPosition(deviceId); } } else { @@ -250,6 +253,9 @@ public class FilterHandler extends BasePositionHandler { if (filterMinPeriod(position, preceding)) { filterType.append("MinPeriod "); } + if (filterDailyLimit(position, preceding)) { + filterType.append("DailyLimit "); + } } Device device = cacheManager.getObject(Device.class, deviceId); -- 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/config/Keys.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