diff options
author | bernamaxim <bernamaxim@gmail.com> | 2023-03-13 11:53:43 +0700 |
---|---|---|
committer | bernamaxim <bernamaxim@gmail.com> | 2023-03-13 11:53:43 +0700 |
commit | 016c107821a6df94a6f71659f9f067334fbc75fd (patch) | |
tree | b9406942e68558a01601ccd8d088fbd5b7ce80b0 | |
parent | 08612944b879861c37b34688e0e9ef2d4a8c11a2 (diff) | |
download | trackermap-server-016c107821a6df94a6f71659f9f067334fbc75fd.tar.gz trackermap-server-016c107821a6df94a6f71659f9f067334fbc75fd.tar.bz2 trackermap-server-016c107821a6df94a6f71659f9f067334fbc75fd.zip |
RegisterUnknown filter with regex #5023 update PR #5044
-rw-r--r-- | setup/default.xml | 2 | ||||
-rw-r--r-- | src/main/java/org/traccar/config/Keys.java | 7 | ||||
-rw-r--r-- | src/main/java/org/traccar/session/ConnectionManager.java | 4 |
3 files changed, 12 insertions, 1 deletions
diff --git a/setup/default.xml b/setup/default.xml index 75acf25a1..f7f1af15b 100644 --- a/setup/default.xml +++ b/setup/default.xml @@ -39,6 +39,8 @@ <entry key='commands.queueing'>true</entry> <entry key='database.ignoreUnknown'>true</entry> + <entry key='database.registerUnknown.regex'>\w{3,15}</entry> + <entry key='database.changelog'>./schema/changelog-master.xml</entry> <entry key='gps103.port'>5001</entry> diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java index 1b4b3a5b4..7896f0dc4 100644 --- a/src/main/java/org/traccar/config/Keys.java +++ b/src/main/java/org/traccar/config/Keys.java @@ -495,6 +495,13 @@ public final class Keys { List.of(KeyType.CONFIG)); /** + * Automatically register unknown devices with regex filter. + */ + public static final ConfigKey<String> DATABASE_REGISTER_UNKNOWN_REGEX = new StringConfigKey( + "database.registerUnknown.regex", + List.of(KeyType.CONFIG)); + + /** * Store empty messages as positions. For example, heartbeats. */ public static final ConfigKey<Boolean> DATABASE_SAVE_EMPTY = new BooleanConfigKey( diff --git a/src/main/java/org/traccar/session/ConnectionManager.java b/src/main/java/org/traccar/session/ConnectionManager.java index 37a42d827..e6f5d00cf 100644 --- a/src/main/java/org/traccar/session/ConnectionManager.java +++ b/src/main/java/org/traccar/session/ConnectionManager.java @@ -123,7 +123,9 @@ public class ConnectionManager implements BroadcastInterface { Device device = deviceLookupService.lookup(uniqueIds); if (device == null && config.getBoolean(Keys.DATABASE_REGISTER_UNKNOWN)) { - device = addUnknownDevice(uniqueIds[0]); + if (uniqueIds[0].matches(config.getString(Keys.DATABASE_REGISTER_UNKNOWN_REGEX))) { + device = addUnknownDevice(uniqueIds[0]); + } } if (device != null) { |