From 016c107821a6df94a6f71659f9f067334fbc75fd Mon Sep 17 00:00:00 2001 From: bernamaxim Date: Mon, 13 Mar 2023 11:53:43 +0700 Subject: RegisterUnknown filter with regex #5023 update PR #5044 --- src/main/java/org/traccar/config/Keys.java | 7 +++++++ src/main/java/org/traccar/session/ConnectionManager.java | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'src/main/java/org') 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 @@ -494,6 +494,13 @@ public final class Keys { "database.registerUnknown.defaultGroupId", List.of(KeyType.CONFIG)); + /** + * Automatically register unknown devices with regex filter. + */ + public static final ConfigKey DATABASE_REGISTER_UNKNOWN_REGEX = new StringConfigKey( + "database.registerUnknown.regex", + List.of(KeyType.CONFIG)); + /** * Store empty messages as positions. For example, heartbeats. */ 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) { -- cgit v1.2.3 From 0ed96dc475883bf2d56e6308089d6891ca521b18 Mon Sep 17 00:00:00 2001 From: Bernard Date: Mon, 13 Mar 2023 22:36:21 +0700 Subject: Update Keys.java --- src/main/java/org/traccar/config/Keys.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java/org') diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java index 7896f0dc4..3c7346833 100644 --- a/src/main/java/org/traccar/config/Keys.java +++ b/src/main/java/org/traccar/config/Keys.java @@ -499,7 +499,7 @@ public final class Keys { */ public static final ConfigKey DATABASE_REGISTER_UNKNOWN_REGEX = new StringConfigKey( "database.registerUnknown.regex", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), "\w{3,15}"); /** * Store empty messages as positions. For example, heartbeats. -- cgit v1.2.3 From fc0b4234d1d0d668769819b40c476a51beab0c1d Mon Sep 17 00:00:00 2001 From: Bernard Date: Mon, 13 Mar 2023 23:26:53 +0700 Subject: Update Keys.java --- src/main/java/org/traccar/config/Keys.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java/org') diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java index 3c7346833..491c724aa 100644 --- a/src/main/java/org/traccar/config/Keys.java +++ b/src/main/java/org/traccar/config/Keys.java @@ -499,7 +499,7 @@ public final class Keys { */ public static final ConfigKey DATABASE_REGISTER_UNKNOWN_REGEX = new StringConfigKey( "database.registerUnknown.regex", - List.of(KeyType.CONFIG), "\w{3,15}"); + List.of(KeyType.CONFIG), "\\w{3,15}"); /** * Store empty messages as positions. For example, heartbeats. -- cgit v1.2.3