From 96d8ea7322d1a588dd2d4cfac73d5c049ebe3faf Mon Sep 17 00:00:00 2001 From: Edward Valley Date: Wed, 17 Jul 2019 11:58:45 -0400 Subject: Make device password group configurable --- src/main/java/org/traccar/BaseProtocolEncoder.java | 2 +- src/main/java/org/traccar/database/DeviceManager.java | 11 +++++++++-- src/main/java/org/traccar/database/IdentityManager.java | 2 +- src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) (limited to 'src/main/java/org') diff --git a/src/main/java/org/traccar/BaseProtocolEncoder.java b/src/main/java/org/traccar/BaseProtocolEncoder.java index 69d1fe6f5..b6df07b98 100644 --- a/src/main/java/org/traccar/BaseProtocolEncoder.java +++ b/src/main/java/org/traccar/BaseProtocolEncoder.java @@ -46,7 +46,7 @@ public abstract class BaseProtocolEncoder extends ChannelOutboundHandlerAdapter protected void initDevicePassword(Command command, String defaultPassword) { if (!command.getAttributes().containsKey(Command.KEY_DEVICE_PASSWORD)) { String password = Context.getIdentityManager() - .getDevicePassword(command.getDeviceId(), defaultPassword); + .getDevicePassword(command.getDeviceId(), getProtocolName(), defaultPassword); command.set(Command.KEY_DEVICE_PASSWORD, password); } } diff --git a/src/main/java/org/traccar/database/DeviceManager.java b/src/main/java/org/traccar/database/DeviceManager.java index d5b1c8c0d..51f35b3db 100644 --- a/src/main/java/org/traccar/database/DeviceManager.java +++ b/src/main/java/org/traccar/database/DeviceManager.java @@ -116,13 +116,20 @@ public class DeviceManager extends BaseObjectManager implements Identity } @Override - public String getDevicePassword(long id, String defaultPassword) { + public String getDevicePassword(long id, String protocol, String defaultPassword) { - String password = getById(id).getString(Command.KEY_DEVICE_PASSWORD); + String password = lookupAttributeString(id, Command.KEY_DEVICE_PASSWORD, null, false); if (password != null) { return password; } + if (protocol != null) { + password = Context.getConfig().getString(protocol + "." + Command.KEY_DEVICE_PASSWORD); + if (password != null) { + return password; + } + } + return defaultPassword; } diff --git a/src/main/java/org/traccar/database/IdentityManager.java b/src/main/java/org/traccar/database/IdentityManager.java index b30537f4f..af6a6ce71 100644 --- a/src/main/java/org/traccar/database/IdentityManager.java +++ b/src/main/java/org/traccar/database/IdentityManager.java @@ -26,7 +26,7 @@ public interface IdentityManager { Device getByUniqueId(String uniqueId) throws Exception; - String getDevicePassword(long id, String defaultPassword); + String getDevicePassword(long id, String protocol, String defaultPassword); Position getLastPosition(long deviceId); diff --git a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java index 2185b707e..06a379862 100644 --- a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java @@ -254,7 +254,7 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { sendAcknowledge(status, event, checksum, channel, remoteAddress); String devicePassword = Context.getIdentityManager() - .getDevicePassword(deviceSession.getDeviceId(), DEFAULT_DEVICE_PASSWORD); + .getDevicePassword(deviceSession.getDeviceId(), getProtocolName(), DEFAULT_DEVICE_PASSWORD); sendEventResponse(event, devicePassword, channel, remoteAddress); } -- cgit v1.2.3 From 94fdc382f4cf46e804472f094401d20421d1e1b3 Mon Sep 17 00:00:00 2001 From: Edward Valley Date: Thu, 18 Jul 2019 13:19:33 -0400 Subject: Changes after merge PR #4357 --- src/main/java/org/traccar/database/DeviceManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java/org') diff --git a/src/main/java/org/traccar/database/DeviceManager.java b/src/main/java/org/traccar/database/DeviceManager.java index 51f35b3db..fa95adeb2 100644 --- a/src/main/java/org/traccar/database/DeviceManager.java +++ b/src/main/java/org/traccar/database/DeviceManager.java @@ -118,7 +118,7 @@ public class DeviceManager extends BaseObjectManager implements Identity @Override public String getDevicePassword(long id, String protocol, String defaultPassword) { - String password = lookupAttributeString(id, Command.KEY_DEVICE_PASSWORD, null, false); + String password = lookupAttributeString(id, Command.KEY_DEVICE_PASSWORD, null, false, false); if (password != null) { return password; } -- cgit v1.2.3 From ad32779b17fd4e480479b3f5702ef62443b8a387 Mon Sep 17 00:00:00 2001 From: Edward Valley Date: Thu, 18 Jul 2019 15:12:44 -0400 Subject: Update some encoders with hardcoded protocol names and passwords --- src/main/java/org/traccar/protocol/Gt06ProtocolEncoder.java | 12 ++++++++---- src/main/java/org/traccar/protocol/H02ProtocolEncoder.java | 2 +- .../java/org/traccar/protocol/HuabaoProtocolEncoder.java | 2 +- .../java/org/traccar/protocol/MeitrackProtocolEncoder.java | 2 +- src/main/java/org/traccar/protocol/Tk103ProtocolEncoder.java | 2 +- 5 files changed, 12 insertions(+), 8 deletions(-) (limited to 'src/main/java/org') diff --git a/src/main/java/org/traccar/protocol/Gt06ProtocolEncoder.java b/src/main/java/org/traccar/protocol/Gt06ProtocolEncoder.java index bbc5e02d8..a3ceb4f30 100644 --- a/src/main/java/org/traccar/protocol/Gt06ProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/Gt06ProtocolEncoder.java @@ -34,7 +34,7 @@ public class Gt06ProtocolEncoder extends BaseProtocolEncoder { private ByteBuf encodeContent(long deviceId, String content) { boolean language = Context.getIdentityManager() - .lookupAttributeBoolean(deviceId, "gt06.language", false, false, true); + .lookupAttributeBoolean(deviceId, getProtocolName() + ".language", false, false, true); ByteBuf buf = Unpooled.buffer(); @@ -67,13 +67,17 @@ public class Gt06ProtocolEncoder extends BaseProtocolEncoder { protected Object encodeCommand(Command command) { boolean alternative = Context.getIdentityManager().lookupAttributeBoolean( - command.getDeviceId(), "gt06.alternative", false, false, true); + command.getDeviceId(), getProtocolName() + ".alternative", false, false, true); + + initDevicePassword(command, "123456"); switch (command.getType()) { case Command.TYPE_ENGINE_STOP: - return encodeContent(command.getDeviceId(), alternative ? "DYD,123456#" : "Relay,1#"); + return encodeContent(command.getDeviceId(), + alternative ? "DYD," + Command.KEY_DEVICE_PASSWORD + "#" : "Relay,1#"); case Command.TYPE_ENGINE_RESUME: - return encodeContent(command.getDeviceId(), alternative ? "HFYD,123456#" : "Relay,0#"); + return encodeContent(command.getDeviceId(), + alternative ? "HFYD," + Command.KEY_DEVICE_PASSWORD + "#" : "Relay,0#"); case Command.TYPE_CUSTOM: return encodeContent(command.getDeviceId(), command.getString(Command.KEY_DATA)); default: diff --git a/src/main/java/org/traccar/protocol/H02ProtocolEncoder.java b/src/main/java/org/traccar/protocol/H02ProtocolEncoder.java index 024899abb..7a765332c 100644 --- a/src/main/java/org/traccar/protocol/H02ProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/H02ProtocolEncoder.java @@ -60,7 +60,7 @@ public class H02ProtocolEncoder extends StringProtocolEncoder { case Command.TYPE_POSITION_PERIODIC: String frequency = command.getAttributes().get(Command.KEY_FREQUENCY).toString(); if (Context.getIdentityManager().lookupAttributeBoolean( - command.getDeviceId(), "h02.alternative", false, false, true)) { + command.getDeviceId(), getProtocolName() + ".alternative", false, false, true)) { return formatCommand(time, uniqueId, "D1", frequency); } else { return formatCommand(time, uniqueId, "S71", "22", frequency); diff --git a/src/main/java/org/traccar/protocol/HuabaoProtocolEncoder.java b/src/main/java/org/traccar/protocol/HuabaoProtocolEncoder.java index c493b49fe..40d07230d 100644 --- a/src/main/java/org/traccar/protocol/HuabaoProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/HuabaoProtocolEncoder.java @@ -36,7 +36,7 @@ public class HuabaoProtocolEncoder extends BaseProtocolEncoder { protected Object encodeCommand(Command command) { boolean alternative = Context.getIdentityManager().lookupAttributeBoolean( - command.getDeviceId(), "huabao.alternative", false, false, true); + command.getDeviceId(), getProtocolName() + ".alternative", false, false, true); ByteBuf id = Unpooled.wrappedBuffer( DataConverter.parseHex(getUniqueId(command.getDeviceId()))); diff --git a/src/main/java/org/traccar/protocol/MeitrackProtocolEncoder.java b/src/main/java/org/traccar/protocol/MeitrackProtocolEncoder.java index 4db404ecf..354e81434 100644 --- a/src/main/java/org/traccar/protocol/MeitrackProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/MeitrackProtocolEncoder.java @@ -43,7 +43,7 @@ public class MeitrackProtocolEncoder extends StringProtocolEncoder { Map attributes = command.getAttributes(); boolean alternative = Context.getIdentityManager().lookupAttributeBoolean( - command.getDeviceId(), "meitrack.alternative", false, false, true); + command.getDeviceId(), getProtocolName() + ".alternative", false, false, true); switch (command.getType()) { case Command.TYPE_POSITION_SINGLE: diff --git a/src/main/java/org/traccar/protocol/Tk103ProtocolEncoder.java b/src/main/java/org/traccar/protocol/Tk103ProtocolEncoder.java index f21c5a3ae..a8aa84105 100644 --- a/src/main/java/org/traccar/protocol/Tk103ProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/Tk103ProtocolEncoder.java @@ -43,7 +43,7 @@ public class Tk103ProtocolEncoder extends StringProtocolEncoder { protected Object encodeCommand(Command command) { boolean alternative = forceAlternative || Context.getIdentityManager().lookupAttributeBoolean( - command.getDeviceId(), "tk103.alternative", false, false, true); + command.getDeviceId(), getProtocolName() + ".alternative", false, false, true); initDevicePassword(command, "123456"); -- cgit v1.2.3 From aef97ed2e75db35b8ababd573eccb0864da7c9e1 Mon Sep 17 00:00:00 2001 From: Edward Valley Date: Thu, 18 Jul 2019 15:51:51 -0400 Subject: Fix minor mistake about device password --- src/main/java/org/traccar/protocol/Gt06ProtocolEncoder.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/main/java/org') diff --git a/src/main/java/org/traccar/protocol/Gt06ProtocolEncoder.java b/src/main/java/org/traccar/protocol/Gt06ProtocolEncoder.java index a3ceb4f30..d375730bf 100644 --- a/src/main/java/org/traccar/protocol/Gt06ProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/Gt06ProtocolEncoder.java @@ -1,3 +1,4 @@ + /* * Copyright 2015 - 2019 Anton Tananaev (anton@traccar.org) * @@ -69,15 +70,16 @@ public class Gt06ProtocolEncoder extends BaseProtocolEncoder { boolean alternative = Context.getIdentityManager().lookupAttributeBoolean( command.getDeviceId(), getProtocolName() + ".alternative", false, false, true); - initDevicePassword(command, "123456"); + String password = Context.getIdentityManager() + .getDevicePassword(command.getDeviceId(), getProtocolName(), "123456"); switch (command.getType()) { case Command.TYPE_ENGINE_STOP: return encodeContent(command.getDeviceId(), - alternative ? "DYD," + Command.KEY_DEVICE_PASSWORD + "#" : "Relay,1#"); + alternative ? "DYD," + password + "#" : "Relay,1#"); case Command.TYPE_ENGINE_RESUME: return encodeContent(command.getDeviceId(), - alternative ? "HFYD," + Command.KEY_DEVICE_PASSWORD + "#" : "Relay,0#"); + alternative ? "HFYD," + password + "#" : "Relay,0#"); case Command.TYPE_CUSTOM: return encodeContent(command.getDeviceId(), command.getString(Command.KEY_DATA)); default: -- cgit v1.2.3 From 9cdd5f45605ee6b0322301885641587e260174c5 Mon Sep 17 00:00:00 2001 From: Edward Valley Date: Thu, 18 Jul 2019 16:01:00 -0400 Subject: Fix minor typo --- src/main/java/org/traccar/protocol/Gt06ProtocolEncoder.java | 1 - 1 file changed, 1 deletion(-) (limited to 'src/main/java/org') diff --git a/src/main/java/org/traccar/protocol/Gt06ProtocolEncoder.java b/src/main/java/org/traccar/protocol/Gt06ProtocolEncoder.java index d375730bf..9115ba10f 100644 --- a/src/main/java/org/traccar/protocol/Gt06ProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/Gt06ProtocolEncoder.java @@ -1,4 +1,3 @@ - /* * Copyright 2015 - 2019 Anton Tananaev (anton@traccar.org) * -- cgit v1.2.3