diff options
author | developerKurt <mustafakurt.business@gmail.com> | 2020-01-02 08:01:03 +0300 |
---|---|---|
committer | developerKurt <mustafakurt.business@gmail.com> | 2020-01-02 08:01:03 +0300 |
commit | 1c43e31b622eba08b14079c03f9ad1861b4a0868 (patch) | |
tree | d2847bfd8694a1177ed18146b018dde742bd10b2 | |
parent | 8b7257b4e952bdcfd4411c572a73adaf350d0d58 (diff) | |
parent | c31417c85f80854e33267ac23fb5636885954e83 (diff) | |
download | trackermap-server-1c43e31b622eba08b14079c03f9ad1861b4a0868.tar.gz trackermap-server-1c43e31b622eba08b14079c03f9ad1861b4a0868.tar.bz2 trackermap-server-1c43e31b622eba08b14079c03f9ad1861b4a0868.zip |
As requested in issue #4393, added logging IP address functionality when login attempts fail.
-rw-r--r-- | setup/default.xml | 1 | ||||
-rw-r--r-- | src/main/java/org/traccar/protocol/PstFrameDecoder.java | 51 | ||||
-rw-r--r-- | src/main/java/org/traccar/protocol/PstProtocol.java | 40 | ||||
-rw-r--r-- | src/main/java/org/traccar/protocol/PstProtocolDecoder.java | 111 | ||||
-rw-r--r-- | src/test/java/org/traccar/protocol/PstFrameDecoderTest.java | 19 | ||||
-rw-r--r-- | src/test/java/org/traccar/protocol/PstProtocolDecoderTest.java | 21 |
6 files changed, 243 insertions, 0 deletions
diff --git a/setup/default.xml b/setup/default.xml index 06920925f..1d82ad926 100644 --- a/setup/default.xml +++ b/setup/default.xml @@ -283,5 +283,6 @@ <entry key='s168.port'>5204</entry> <entry key='vnet.port'>5205</entry> <entry key='blue.port'>5206</entry> + <entry key='pst.port'>5207</entry> </properties> diff --git a/src/main/java/org/traccar/protocol/PstFrameDecoder.java b/src/main/java/org/traccar/protocol/PstFrameDecoder.java new file mode 100644 index 000000000..dbafd1476 --- /dev/null +++ b/src/main/java/org/traccar/protocol/PstFrameDecoder.java @@ -0,0 +1,51 @@ +/* + * Copyright 2019 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.protocol; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.Channel; +import io.netty.channel.ChannelHandlerContext; +import org.traccar.BaseFrameDecoder; + +public class PstFrameDecoder extends BaseFrameDecoder { + + @Override + protected Object decode( + ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception { + + while (buf.isReadable() && buf.getByte(buf.readerIndex()) == 0x28) { + buf.skipBytes(1); + } + + int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0x29); + if (endIndex > 0) { + ByteBuf result = Unpooled.buffer(endIndex - buf.readerIndex()); + while (buf.readerIndex() < endIndex) { + int b = buf.readUnsignedByte(); + if (b == 0x27) { + b = buf.readUnsignedByte() ^ 0x40; + } + result.writeByte(b); + } + buf.skipBytes(1); + return result; + } + + return null; + } + +} diff --git a/src/main/java/org/traccar/protocol/PstProtocol.java b/src/main/java/org/traccar/protocol/PstProtocol.java new file mode 100644 index 000000000..0ed9affd8 --- /dev/null +++ b/src/main/java/org/traccar/protocol/PstProtocol.java @@ -0,0 +1,40 @@ +/* + * Copyright 2019 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.protocol; + +import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; +import org.traccar.TrackerServer; + +public class PstProtocol extends BaseProtocol { + + public PstProtocol() { + addServer(new TrackerServer(true, getName()) { + @Override + protected void addProtocolHandlers(PipelineBuilder pipeline) { + pipeline.addLast(new PstProtocolDecoder(PstProtocol.this)); + } + }); + addServer(new TrackerServer(false, getName()) { + @Override + protected void addProtocolHandlers(PipelineBuilder pipeline) { + pipeline.addLast(new PstFrameDecoder()); + pipeline.addLast(new PstProtocolDecoder(PstProtocol.this)); + } + }); + } + +} diff --git a/src/main/java/org/traccar/protocol/PstProtocolDecoder.java b/src/main/java/org/traccar/protocol/PstProtocolDecoder.java new file mode 100644 index 000000000..40caa9727 --- /dev/null +++ b/src/main/java/org/traccar/protocol/PstProtocolDecoder.java @@ -0,0 +1,111 @@ +/* + * Copyright 2019 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.protocol; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.Channel; +import org.traccar.BaseProtocolDecoder; +import org.traccar.DeviceSession; +import org.traccar.Protocol; +import org.traccar.helper.BitUtil; +import org.traccar.helper.DateBuilder; +import org.traccar.model.Position; + +import java.net.SocketAddress; +import java.util.Date; + +public class PstProtocolDecoder extends BaseProtocolDecoder { + + public PstProtocolDecoder(Protocol protocol) { + super(protocol); + } + + public static final int MSG_STATUS = 0x05; + + private Date readDate(ByteBuf buf) { + long value = buf.readUnsignedInt(); + return new DateBuilder() + .setYear((int) BitUtil.between(value, 26, 32)) + .setMonth((int) BitUtil.between(value, 22, 26)) + .setDay((int) BitUtil.between(value, 17, 22)) + .setMonth((int) BitUtil.between(value, 12, 17)) + .setMonth((int) BitUtil.between(value, 6, 12)) + .setMonth((int) BitUtil.between(value, 0, 6)).getDate(); + } + + private double readCoordinate(ByteBuf buf) { + long value = buf.readUnsignedInt(); + return (BitUtil.from(value, 16) + BitUtil.to(value, 16) * 0.00001) / 60; + } + + @Override + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + + ByteBuf buf = (ByteBuf) msg; + + String id = String.valueOf(buf.readUnsignedInt()); + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id); + if (deviceSession == null) { + return null; + } + + buf.readUnsignedByte(); // version + buf.readUnsignedInt(); // index + + int type = buf.readUnsignedByte(); + + if (type == MSG_STATUS) { + + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + position.setDeviceTime(readDate(buf)); + + buf.readUnsignedByte(); + + int count = buf.readUnsignedByte(); + for (int i = 0; i < count; i++) { + + int tag = buf.readUnsignedByte(); + int length = buf.readUnsignedByte(); + + switch (tag) { + case 0x0D: + position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte() * 5); + break; + case 0x10: + position.setFixTime(readDate(buf)); + position.setLatitude(readCoordinate(buf)); + position.setLongitude(readCoordinate(buf)); + position.setSpeed(buf.readUnsignedByte()); + position.setCourse(buf.readUnsignedByte() * 2); + position.setAltitude(buf.readShort()); + buf.readUnsignedInt(); // gps condition + break; + default: + buf.skipBytes(length); + break; + } + } + + return position; + } + + return null; + } + +} diff --git a/src/test/java/org/traccar/protocol/PstFrameDecoderTest.java b/src/test/java/org/traccar/protocol/PstFrameDecoderTest.java new file mode 100644 index 000000000..790c2c1d9 --- /dev/null +++ b/src/test/java/org/traccar/protocol/PstFrameDecoderTest.java @@ -0,0 +1,19 @@ +package org.traccar.protocol; + +import org.junit.Test; +import org.traccar.ProtocolTest; + +public class PstFrameDecoderTest extends ProtocolTest { + + @Test + public void testDecode() throws Exception { + + PstFrameDecoder decoder = new PstFrameDecoder(); + + verifyFrame( + binary("2fafac5a050f0000e0022fafac5a01891e882bbfdd06dd577c9865620a0efe524c419f940b6710f5ba0c86e5868ffc97c77eaaf166a31dba63f9894e98a91b9486c94e79ce537359737a5e9385431a590eb20b5115a2b7939e4e66ae"), + decoder.decode(null, null, binary("282fafac5a050f0000e0022fafac5a01891e882bbfdd06dd577c9865620a0efe524c419f940b6710f5ba0c86e5868ffc97c77eaaf166a31dba63f9894e98a91b9486c94e79ce537359737a5e9385431a590eb20b5115a2b7939e4e66ae29"))); + + } + +} diff --git a/src/test/java/org/traccar/protocol/PstProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/PstProtocolDecoderTest.java new file mode 100644 index 000000000..9c3d2108e --- /dev/null +++ b/src/test/java/org/traccar/protocol/PstProtocolDecoderTest.java @@ -0,0 +1,21 @@ +package org.traccar.protocol; + +import org.junit.Test; +import org.traccar.ProtocolTest; + +public class PstProtocolDecoderTest extends ProtocolTest { + + @Test + public void testDecode() throws Exception { + + PstProtocolDecoder decoder = new PstProtocolDecoder(null); + + verifyNull(decoder, binary( + "2faf9b5605e40000e0022faf9b560196cb2f003f0c72ab56129ae0847ac98801cd1ed8")); + + verifyNull(decoder, binary( + "2fafac5a050f0000e0022fafac5a01891e882bbfdd06dd577c9865620a0efe524c419f940b6710f5ba0c86e5868ffc97c77eaaf166a31dba63f9894e98a91b9486c94e79ce537359737a5e9385431a590eb20b5115a2b7939e4e66ae")); + + } + +} |