From 9cccb2f86c5ecf4041772d28fbc78ddbd619885f Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 18 Jul 2022 18:24:09 -0700 Subject: Remove trailing spaces --- templates/full/commandResult.vm | 2 +- templates/full/deviceFuelDrop.vm | 2 +- templates/full/deviceInactive.vm | 2 +- templates/full/deviceMoving.vm | 2 +- templates/full/deviceOffline.vm | 2 +- templates/full/deviceOnline.vm | 2 +- templates/full/deviceOverspeed.vm | 2 +- templates/full/deviceStopped.vm | 2 +- templates/full/deviceUnknown.vm | 2 +- templates/full/driverChanged.vm | 2 +- templates/full/geofenceEnter.vm | 2 +- templates/full/geofenceExit.vm | 2 +- templates/full/ignitionOff.vm | 2 +- templates/full/ignitionOn.vm | 2 +- templates/full/maintenance.vm | 2 +- templates/full/test.vm | 2 +- templates/full/textMessage.vm | 4 ++-- 17 files changed, 18 insertions(+), 18 deletions(-) (limited to 'templates/full') diff --git a/templates/full/commandResult.vm b/templates/full/commandResult.vm index c5ceffab0..443e1a399 100644 --- a/templates/full/commandResult.vm +++ b/templates/full/commandResult.vm @@ -7,4 +7,4 @@ Result: $position.getString("result")
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
Link: $webUrl?eventId=$event.id - + diff --git a/templates/full/deviceFuelDrop.vm b/templates/full/deviceFuelDrop.vm index a50e8ca38..bf7a16b97 100644 --- a/templates/full/deviceFuelDrop.vm +++ b/templates/full/deviceFuelDrop.vm @@ -6,4 +6,4 @@ Device: $device.name
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
Point: #{if}($position.address)$position.address#{else}$position.latitude°, $position.longitude°#{end}
- + diff --git a/templates/full/deviceInactive.vm b/templates/full/deviceInactive.vm index 51aead653..626db1dc4 100644 --- a/templates/full/deviceInactive.vm +++ b/templates/full/deviceInactive.vm @@ -9,4 +9,4 @@ Inactive
Last Update: $dateTool.format("YYYY-MM-dd HH:mm:ss", $lastUpdate, $locale, $timezone)
Link: $webUrl?eventId=$event.id - + diff --git a/templates/full/deviceMoving.vm b/templates/full/deviceMoving.vm index 37f3c2a93..b22b90428 100644 --- a/templates/full/deviceMoving.vm +++ b/templates/full/deviceMoving.vm @@ -7,4 +7,4 @@ Moving
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
Point: #{if}($position.address)$position.address#{else}$position.latitude°, $position.longitude°#{end}
- + diff --git a/templates/full/deviceOffline.vm b/templates/full/deviceOffline.vm index c832ee553..332bfe3d9 100644 --- a/templates/full/deviceOffline.vm +++ b/templates/full/deviceOffline.vm @@ -7,4 +7,4 @@ Offline
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
Link: $webUrl?eventId=$event.id - + diff --git a/templates/full/deviceOnline.vm b/templates/full/deviceOnline.vm index fd17edef0..3ca3cfa9b 100644 --- a/templates/full/deviceOnline.vm +++ b/templates/full/deviceOnline.vm @@ -7,4 +7,4 @@ Online
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
Link: $webUrl?eventId=$event.id - + diff --git a/templates/full/deviceOverspeed.vm b/templates/full/deviceOverspeed.vm index f796881a0..f303b734c 100644 --- a/templates/full/deviceOverspeed.vm +++ b/templates/full/deviceOverspeed.vm @@ -16,4 +16,4 @@ Exceeds the speed: $speedString#{if}($geofence) in $geofence.name#{else}#{end} Point: #{if}($position.address)$position.address#{else}$position.latitude°, $position.longitude°#{end}
- + diff --git a/templates/full/deviceStopped.vm b/templates/full/deviceStopped.vm index 9e1e47d12..9f8a30707 100644 --- a/templates/full/deviceStopped.vm +++ b/templates/full/deviceStopped.vm @@ -7,4 +7,4 @@ Stopped
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
Point: #{if}($position.address)$position.address#{else}$position.latitude°, $position.longitude°#{end}
- + diff --git a/templates/full/deviceUnknown.vm b/templates/full/deviceUnknown.vm index 34b3a7795..0e6e9b4b4 100644 --- a/templates/full/deviceUnknown.vm +++ b/templates/full/deviceUnknown.vm @@ -7,4 +7,4 @@ Status is unknown
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
Link: $webUrl?eventId=$event.id - + diff --git a/templates/full/driverChanged.vm b/templates/full/driverChanged.vm index e370d3eea..65e2768b5 100644 --- a/templates/full/driverChanged.vm +++ b/templates/full/driverChanged.vm @@ -7,4 +7,4 @@ Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezo Point: #{if}($position.address)$position.address#{else}$position.latitude°, $position.longitude°#{end}
Driver: #{if}($driver)$driver.name#{else}$event.getString("driverUniqueId")#{end} - + diff --git a/templates/full/geofenceEnter.vm b/templates/full/geofenceEnter.vm index 9e00cb388..2d9cd3613 100644 --- a/templates/full/geofenceEnter.vm +++ b/templates/full/geofenceEnter.vm @@ -7,4 +7,4 @@ Has entered geofence: $geofence.name
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
Point: #{if}($position.address)$position.address#{else}$position.latitude°, $position.longitude°#{end}
- + diff --git a/templates/full/geofenceExit.vm b/templates/full/geofenceExit.vm index c3a300f37..ae1eb5520 100644 --- a/templates/full/geofenceExit.vm +++ b/templates/full/geofenceExit.vm @@ -7,4 +7,4 @@ Has exited geofence: $geofence.name
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
Point: #{if}($position.address)$position.address#{else}$position.latitude°, $position.longitude°#{end}
- + diff --git a/templates/full/ignitionOff.vm b/templates/full/ignitionOff.vm index 8a546ed29..0ec50918b 100644 --- a/templates/full/ignitionOff.vm +++ b/templates/full/ignitionOff.vm @@ -7,4 +7,4 @@ Ignition OFF
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
Point: #{if}($position.address)$position.address#{else}$position.latitude°, $position.longitude°#{end}
- + diff --git a/templates/full/ignitionOn.vm b/templates/full/ignitionOn.vm index 9ae9a63e7..7e0d6532d 100644 --- a/templates/full/ignitionOn.vm +++ b/templates/full/ignitionOn.vm @@ -7,4 +7,4 @@ Ignition ON
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
Point: #{if}($position.address)$position.address#{else}$position.latitude°, $position.longitude°#{end}
- + diff --git a/templates/full/maintenance.vm b/templates/full/maintenance.vm index 612a675f8..798de637d 100644 --- a/templates/full/maintenance.vm +++ b/templates/full/maintenance.vm @@ -7,4 +7,4 @@ Maintenance is required: $maintenance.name
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
Point: #{if}($position.address)$position.address#{else}$position.latitude°, $position.longitude°#{end}
- + diff --git a/templates/full/test.vm b/templates/full/test.vm index 93cbdc549..41e2f3ebd 100644 --- a/templates/full/test.vm +++ b/templates/full/test.vm @@ -4,4 +4,4 @@ Test message - + diff --git a/templates/full/textMessage.vm b/templates/full/textMessage.vm index a20dddbe0..7222b4d91 100644 --- a/templates/full/textMessage.vm +++ b/templates/full/textMessage.vm @@ -3,7 +3,7 @@ Device: $device.name
-Message: $event.getString("message")
+Message: $event.getString("message")
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
- + -- cgit v1.2.3 From a61e08cb47b8294bf639ebdc0916ead031e92827 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 18 Jul 2022 18:25:49 -0700 Subject: Add media events (fix #3863) --- src/main/java/org/traccar/BasePipelineFactory.java | 2 + .../traccar/handler/events/BaseEventHandler.java | 2 +- .../traccar/handler/events/MediaEventHandler.java | 47 ++++++++++++++++++++++ src/main/java/org/traccar/model/Event.java | 3 +- templates/full/media.vm | 11 +++++ templates/short/media.vm | 2 + 6 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 src/main/java/org/traccar/handler/events/MediaEventHandler.java create mode 100644 templates/full/media.vm create mode 100644 templates/short/media.vm (limited to 'templates/full') diff --git a/src/main/java/org/traccar/BasePipelineFactory.java b/src/main/java/org/traccar/BasePipelineFactory.java index 915c3f7ea..fb48f81d1 100644 --- a/src/main/java/org/traccar/BasePipelineFactory.java +++ b/src/main/java/org/traccar/BasePipelineFactory.java @@ -49,6 +49,7 @@ import org.traccar.handler.events.FuelDropEventHandler; import org.traccar.handler.events.GeofenceEventHandler; import org.traccar.handler.events.IgnitionEventHandler; import org.traccar.handler.events.MaintenanceEventHandler; +import org.traccar.handler.events.MediaEventHandler; import org.traccar.handler.events.MotionEventHandler; import org.traccar.handler.events.OverspeedEventHandler; @@ -141,6 +142,7 @@ public abstract class BasePipelineFactory extends ChannelInitializer { ComputedAttributesHandler.class, WebDataHandler.class, DefaultDataHandler.class, + MediaEventHandler.class, CommandResultEventHandler.class, OverspeedEventHandler.class, BehaviorEventHandler.class, diff --git a/src/main/java/org/traccar/handler/events/BaseEventHandler.java b/src/main/java/org/traccar/handler/events/BaseEventHandler.java index f7199f6dc..271aaa35d 100644 --- a/src/main/java/org/traccar/handler/events/BaseEventHandler.java +++ b/src/main/java/org/traccar/handler/events/BaseEventHandler.java @@ -36,7 +36,7 @@ public abstract class BaseEventHandler extends BaseDataHandler { @Override protected Position handlePosition(Position position) { Map events = analyzePosition(position); - if (events != null) { + if (events != null && !events.isEmpty()) { notificationManager.updateEvents(events); } return position; diff --git a/src/main/java/org/traccar/handler/events/MediaEventHandler.java b/src/main/java/org/traccar/handler/events/MediaEventHandler.java new file mode 100644 index 000000000..5b9013fad --- /dev/null +++ b/src/main/java/org/traccar/handler/events/MediaEventHandler.java @@ -0,0 +1,47 @@ +/* + * Copyright 2022 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.handler.events; + +import io.netty.channel.ChannelHandler; +import org.traccar.model.Event; +import org.traccar.model.Position; + +import javax.inject.Inject; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +@ChannelHandler.Sharable +public class MediaEventHandler extends BaseEventHandler { + + @Inject + public MediaEventHandler() { + } + + @Override + protected Map analyzePosition(Position position) { + return Stream.of(Position.KEY_IMAGE, Position.KEY_VIDEO, Position.KEY_AUDIO) + .filter(position::hasAttribute) + .map(type -> { + Event event = new Event(Event.TYPE_MEDIA, position); + event.set("media", type); + event.set("file", position.getString(type)); + return event; + }) + .collect(Collectors.toMap(event -> event, event -> position)); + } + +} diff --git a/src/main/java/org/traccar/model/Event.java b/src/main/java/org/traccar/model/Event.java index 6e3953fda..f00a0e5f1 100644 --- a/src/main/java/org/traccar/model/Event.java +++ b/src/main/java/org/traccar/model/Event.java @@ -62,10 +62,9 @@ public class Event extends Message { public static final String TYPE_IGNITION_OFF = "ignitionOff"; public static final String TYPE_MAINTENANCE = "maintenance"; - public static final String TYPE_TEXT_MESSAGE = "textMessage"; - public static final String TYPE_DRIVER_CHANGED = "driverChanged"; + public static final String TYPE_MEDIA = "media"; private Date eventTime; diff --git a/templates/full/media.vm b/templates/full/media.vm new file mode 100644 index 000000000..6651deffc --- /dev/null +++ b/templates/full/media.vm @@ -0,0 +1,11 @@ +#set($subject = "$device.name: media file received") + + + +Device: $device.name
+Type: $event.getString("media")
+File: $event.getString("file")
+Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
+Link: $webUrl?eventId=$event.id + + diff --git a/templates/short/media.vm b/templates/short/media.vm new file mode 100644 index 000000000..783636f3f --- /dev/null +++ b/templates/short/media.vm @@ -0,0 +1,2 @@ +#set($subject = "$device.name: media file received") +$device.name $event.getString("media") received: $event.getString("file") at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) -- cgit v1.2.3 From 9c9af1e02ab7fea6465bf83b9b10d13197184e3d Mon Sep 17 00:00:00 2001 From: Luiz Kill Date: Thu, 21 Jul 2022 12:01:54 -0300 Subject: Fixes passwordReset.vm template Adds the reset-password endpoint to the reset link. --- templates/full/passwordReset.vm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'templates/full') diff --git a/templates/full/passwordReset.vm b/templates/full/passwordReset.vm index fe692ba1d..45c88f5b3 100644 --- a/templates/full/passwordReset.vm +++ b/templates/full/passwordReset.vm @@ -3,6 +3,6 @@ To reset password please click on the following link:
-$webUrl?passwordReset=$token
+$webUrl?passwordReset=$token
-- cgit v1.2.3 From 708f04be5d9a25bd9d217127680a61f307cb8ef2 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 21 Jul 2022 18:45:13 -0700 Subject: Fix password reset link text --- templates/full/passwordReset.vm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'templates/full') diff --git a/templates/full/passwordReset.vm b/templates/full/passwordReset.vm index 45c88f5b3..38da10aa3 100644 --- a/templates/full/passwordReset.vm +++ b/templates/full/passwordReset.vm @@ -3,6 +3,6 @@ To reset password please click on the following link:
-$webUrl?passwordReset=$token
+$webUrl/modern/reset-password?passwordReset=$token
-- cgit v1.2.3 From ccaa4d13d81901d7001d32795c36b9be53d4c244 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 31 Jul 2022 07:27:15 -0700 Subject: Other modern cleanup --- templates/full/passwordReset.vm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'templates/full') diff --git a/templates/full/passwordReset.vm b/templates/full/passwordReset.vm index 38da10aa3..d380790dc 100644 --- a/templates/full/passwordReset.vm +++ b/templates/full/passwordReset.vm @@ -3,6 +3,6 @@ To reset password please click on the following link:
-$webUrl/modern/reset-password?passwordReset=$token
+$webUrl/reset-password?passwordReset=$token
-- cgit v1.2.3 From bb7bdcfc3389b6822b7680837386e3650962f30a Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 2 Aug 2022 21:01:06 -0700 Subject: Notifications unsubscribe option --- .../java/org/traccar/api/resource/PasswordResource.java | 2 +- src/main/java/org/traccar/api/signature/TokenManager.java | 4 ++++ .../org/traccar/notification/TextTemplateFormatter.java | 13 ++++++++++++- templates/full/alarm.vm | 4 +++- templates/full/commandResult.vm | 4 +++- templates/full/deviceFuelDrop.vm | 2 ++ templates/full/deviceInactive.vm | 4 +++- templates/full/deviceMoving.vm | 2 ++ templates/full/deviceOffline.vm | 4 +++- templates/full/deviceOnline.vm | 4 +++- templates/full/deviceOverspeed.vm | 2 ++ templates/full/deviceStopped.vm | 2 ++ templates/full/deviceUnknown.vm | 4 +++- templates/full/driverChanged.vm | 4 +++- templates/full/geofenceEnter.vm | 2 ++ templates/full/geofenceExit.vm | 2 ++ templates/full/ignitionOff.vm | 2 ++ templates/full/ignitionOn.vm | 2 ++ templates/full/maintenance.vm | 2 ++ templates/full/media.vm | 4 +++- templates/full/textMessage.vm | 2 ++ 21 files changed, 61 insertions(+), 10 deletions(-) (limited to 'templates/full') diff --git a/src/main/java/org/traccar/api/resource/PasswordResource.java b/src/main/java/org/traccar/api/resource/PasswordResource.java index 1fb08b02a..625ff4cb1 100644 --- a/src/main/java/org/traccar/api/resource/PasswordResource.java +++ b/src/main/java/org/traccar/api/resource/PasswordResource.java @@ -62,7 +62,7 @@ public class PasswordResource extends BaseResource { new Columns.All(), new Condition.Equals("email", "email", email))); if (user != null) { var velocityContext = textTemplateFormatter.prepareContext(permissionsService.getServer(), user); - velocityContext.put("token", tokenManager.generateToken(user.getId(), null)); + velocityContext.put("token", tokenManager.generateToken(user.getId())); var fullMessage = textTemplateFormatter.formatMessage(velocityContext, "passwordReset", "full"); mailManager.sendMessage(user, fullMessage.getSubject(), fullMessage.getBody()); } diff --git a/src/main/java/org/traccar/api/signature/TokenManager.java b/src/main/java/org/traccar/api/signature/TokenManager.java index a51234a95..a352ecc10 100644 --- a/src/main/java/org/traccar/api/signature/TokenManager.java +++ b/src/main/java/org/traccar/api/signature/TokenManager.java @@ -46,6 +46,10 @@ public class TokenManager { this.cryptoManager = cryptoManager; } + public String generateToken(long userId) throws IOException, GeneralSecurityException, StorageException { + return generateToken(userId, null); + } + public String generateToken( long userId, Date expiration) throws IOException, GeneralSecurityException, StorageException { Data data = new Data(); diff --git a/src/main/java/org/traccar/notification/TextTemplateFormatter.java b/src/main/java/org/traccar/notification/TextTemplateFormatter.java index bca18f53c..be894af96 100644 --- a/src/main/java/org/traccar/notification/TextTemplateFormatter.java +++ b/src/main/java/org/traccar/notification/TextTemplateFormatter.java @@ -23,14 +23,18 @@ import org.apache.velocity.tools.generic.DateTool; import org.apache.velocity.tools.generic.NumberTool; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.traccar.api.signature.TokenManager; import org.traccar.helper.model.UserUtil; import org.traccar.model.Server; import org.traccar.model.User; +import org.traccar.storage.StorageException; import javax.inject.Inject; +import java.io.IOException; import java.io.StringWriter; import java.nio.charset.StandardCharsets; import java.nio.file.Paths; +import java.security.GeneralSecurityException; import java.util.Locale; public class TextTemplateFormatter { @@ -38,10 +42,12 @@ public class TextTemplateFormatter { private static final Logger LOGGER = LoggerFactory.getLogger(TextTemplateFormatter.class); private final VelocityEngine velocityEngine; + private final TokenManager tokenManager; @Inject - public TextTemplateFormatter(VelocityEngine velocityEngine) { + public TextTemplateFormatter(VelocityEngine velocityEngine, TokenManager tokenManager) { this.velocityEngine = velocityEngine; + this.tokenManager = tokenManager; } public VelocityContext prepareContext(Server server, User user) { @@ -51,6 +57,11 @@ public class TextTemplateFormatter { if (user != null) { velocityContext.put("user", user); velocityContext.put("timezone", UserUtil.getTimezone(server, user)); + try { + velocityContext.put("token", tokenManager.generateToken(user.getId())); + } catch (IOException | GeneralSecurityException | StorageException e) { + LOGGER.warn("Token generation failed", e); + } } velocityContext.put("webUrl", velocityEngine.getProperty("web.url")); diff --git a/templates/full/alarm.vm b/templates/full/alarm.vm index 8eac3930a..5d367dc3a 100644 --- a/templates/full/alarm.vm +++ b/templates/full/alarm.vm @@ -6,5 +6,7 @@ Device: $device.name
Alarm: $position.getString("alarm")
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
Point: #{if}($position.address)$position.address#{else}$position.latitude°, $position.longitude°#{end}
+
+Unsubscribe - + diff --git a/templates/full/commandResult.vm b/templates/full/commandResult.vm index 443e1a399..c3b62edf5 100644 --- a/templates/full/commandResult.vm +++ b/templates/full/commandResult.vm @@ -5,6 +5,8 @@ Device: $device.name
Result: $position.getString("result")
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
-Link: $webUrl?eventId=$event.id +Link: $webUrl?eventId=$event.id
+
+Unsubscribe diff --git a/templates/full/deviceFuelDrop.vm b/templates/full/deviceFuelDrop.vm index bf7a16b97..3fb9aa63c 100644 --- a/templates/full/deviceFuelDrop.vm +++ b/templates/full/deviceFuelDrop.vm @@ -5,5 +5,7 @@ Device: $device.name
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
Point: #{if}($position.address)$position.address#{else}$position.latitude°, $position.longitude°#{end}
+
+Unsubscribe diff --git a/templates/full/deviceInactive.vm b/templates/full/deviceInactive.vm index 626db1dc4..01fa319b5 100644 --- a/templates/full/deviceInactive.vm +++ b/templates/full/deviceInactive.vm @@ -7,6 +7,8 @@ Device: $device.name
Inactive
Last Update: $dateTool.format("YYYY-MM-dd HH:mm:ss", $lastUpdate, $locale, $timezone)
-Link: $webUrl?eventId=$event.id +Link: $webUrl?eventId=$event.id
+
+Unsubscribe diff --git a/templates/full/deviceMoving.vm b/templates/full/deviceMoving.vm index b22b90428..e3941b324 100644 --- a/templates/full/deviceMoving.vm +++ b/templates/full/deviceMoving.vm @@ -6,5 +6,7 @@ Device: $device.name
Moving
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
Point: #{if}($position.address)$position.address#{else}$position.latitude°, $position.longitude°#{end}
+
+Unsubscribe diff --git a/templates/full/deviceOffline.vm b/templates/full/deviceOffline.vm index 332bfe3d9..8f2c515b2 100644 --- a/templates/full/deviceOffline.vm +++ b/templates/full/deviceOffline.vm @@ -5,6 +5,8 @@ Device: $device.name
Offline
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
-Link: $webUrl?eventId=$event.id +Link: $webUrl?eventId=$event.id
+
+Unsubscribe diff --git a/templates/full/deviceOnline.vm b/templates/full/deviceOnline.vm index 3ca3cfa9b..81a4ccbc8 100644 --- a/templates/full/deviceOnline.vm +++ b/templates/full/deviceOnline.vm @@ -5,6 +5,8 @@ Device: $device.name
Online
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
-Link: $webUrl?eventId=$event.id +Link: $webUrl?eventId=$event.id
+
+Unsubscribe diff --git a/templates/full/deviceOverspeed.vm b/templates/full/deviceOverspeed.vm index f303b734c..5f38b3f88 100644 --- a/templates/full/deviceOverspeed.vm +++ b/templates/full/deviceOverspeed.vm @@ -15,5 +15,7 @@ Device: $device.name
Exceeds the speed: $speedString#{if}($geofence) in $geofence.name#{else}#{end}
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
Point: #{if}($position.address)$position.address#{else}$position.latitude°, $position.longitude°#{end}
+
+Unsubscribe diff --git a/templates/full/deviceStopped.vm b/templates/full/deviceStopped.vm index 9f8a30707..e3246b277 100644 --- a/templates/full/deviceStopped.vm +++ b/templates/full/deviceStopped.vm @@ -6,5 +6,7 @@ Device: $device.name
Stopped
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
Point: #{if}($position.address)$position.address#{else}$position.latitude°, $position.longitude°#{end}
+
+Unsubscribe diff --git a/templates/full/deviceUnknown.vm b/templates/full/deviceUnknown.vm index 0e6e9b4b4..e012845e6 100644 --- a/templates/full/deviceUnknown.vm +++ b/templates/full/deviceUnknown.vm @@ -5,6 +5,8 @@ Device: $device.name
Status is unknown
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
-Link: $webUrl?eventId=$event.id +Link: $webUrl?eventId=$event.id
+
+Unsubscribe diff --git a/templates/full/driverChanged.vm b/templates/full/driverChanged.vm index 65e2768b5..f9b6d0ae2 100644 --- a/templates/full/driverChanged.vm +++ b/templates/full/driverChanged.vm @@ -5,6 +5,8 @@ Device: $device.name
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
Point: #{if}($position.address)$position.address#{else}$position.latitude°, $position.longitude°#{end}
-Driver: #{if}($driver)$driver.name#{else}$event.getString("driverUniqueId")#{end} +Driver: #{if}($driver)$driver.name#{else}$event.getString("driverUniqueId")#{end}
+
+Unsubscribe diff --git a/templates/full/geofenceEnter.vm b/templates/full/geofenceEnter.vm index 2d9cd3613..5ae14a8d3 100644 --- a/templates/full/geofenceEnter.vm +++ b/templates/full/geofenceEnter.vm @@ -6,5 +6,7 @@ Device: $device.name
Has entered geofence: $geofence.name
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
Point: #{if}($position.address)$position.address#{else}$position.latitude°, $position.longitude°#{end}
+
+Unsubscribe diff --git a/templates/full/geofenceExit.vm b/templates/full/geofenceExit.vm index ae1eb5520..08887a93a 100644 --- a/templates/full/geofenceExit.vm +++ b/templates/full/geofenceExit.vm @@ -6,5 +6,7 @@ Device: $device.name
Has exited geofence: $geofence.name
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
Point: #{if}($position.address)$position.address#{else}$position.latitude°, $position.longitude°#{end}
+
+Unsubscribe diff --git a/templates/full/ignitionOff.vm b/templates/full/ignitionOff.vm index 0ec50918b..a43e4aabb 100644 --- a/templates/full/ignitionOff.vm +++ b/templates/full/ignitionOff.vm @@ -6,5 +6,7 @@ Device: $device.name
Ignition OFF
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
Point: #{if}($position.address)$position.address#{else}$position.latitude°, $position.longitude°#{end}
+
+Unsubscribe diff --git a/templates/full/ignitionOn.vm b/templates/full/ignitionOn.vm index 7e0d6532d..1ba9ef030 100644 --- a/templates/full/ignitionOn.vm +++ b/templates/full/ignitionOn.vm @@ -6,5 +6,7 @@ Device: $device.name
Ignition ON
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
Point: #{if}($position.address)$position.address#{else}$position.latitude°, $position.longitude°#{end}
+
+Unsubscribe diff --git a/templates/full/maintenance.vm b/templates/full/maintenance.vm index 798de637d..39ccb21bc 100644 --- a/templates/full/maintenance.vm +++ b/templates/full/maintenance.vm @@ -6,5 +6,7 @@ Device: $device.name
Maintenance is required: $maintenance.name
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
Point: #{if}($position.address)$position.address#{else}$position.latitude°, $position.longitude°#{end}
+
+Unsubscribe diff --git a/templates/full/media.vm b/templates/full/media.vm index 6651deffc..1c94265fb 100644 --- a/templates/full/media.vm +++ b/templates/full/media.vm @@ -6,6 +6,8 @@ Device: $device.name
Type: $event.getString("media")
File: $event.getString("file")
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
-Link: $webUrl?eventId=$event.id +Link: $webUrl?eventId=$event.id
+
+Unsubscribe diff --git a/templates/full/textMessage.vm b/templates/full/textMessage.vm index 7222b4d91..fb20275e3 100644 --- a/templates/full/textMessage.vm +++ b/templates/full/textMessage.vm @@ -5,5 +5,7 @@ Device: $device.name
Message: $event.getString("message")
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
+
+Unsubscribe -- cgit v1.2.3 From 074cc52c3d645ac974a1489aa4e197d471093403 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 3 Aug 2022 19:06:12 -0700 Subject: Implement refuel events --- src/main/java/org/traccar/config/Keys.java | 9 +++++++ .../traccar/handler/events/FuelEventHandler.java | 28 +++++++++++++--------- src/main/java/org/traccar/model/Event.java | 1 + templates/full/deviceFuelIncrease.vm | 11 +++++++++ templates/short/deviceFuelIncrease.vm | 2 ++ 5 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 templates/full/deviceFuelIncrease.vm create mode 100644 templates/short/deviceFuelIncrease.vm (limited to 'templates/full') diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java index e97e104a1..a3b39581d 100644 --- a/src/main/java/org/traccar/config/Keys.java +++ b/src/main/java/org/traccar/config/Keys.java @@ -309,6 +309,15 @@ public final class Keys { List.of(KeyType.SERVER, KeyType.DEVICE), 0.0); + /** + * Fuel increase threshold value. When fuel level increases from one position to another for more the value, an + * event is generated. + */ + public static final ConfigKey EVENT_FUEL_INCREASE_THRESHOLD = new DoubleConfigKey( + "fuelIncreaseThreshold", + List.of(KeyType.SERVER, KeyType.DEVICE), + 0.0); + /** * Speed limit value in knots. */ diff --git a/src/main/java/org/traccar/handler/events/FuelEventHandler.java b/src/main/java/org/traccar/handler/events/FuelEventHandler.java index 9ec819a5f..d5d4ab9be 100644 --- a/src/main/java/org/traccar/handler/events/FuelEventHandler.java +++ b/src/main/java/org/traccar/handler/events/FuelEventHandler.java @@ -25,7 +25,6 @@ import org.traccar.model.Position; import org.traccar.session.cache.CacheManager; import javax.inject.Inject; -import java.util.Collections; import java.util.Map; @ChannelHandler.Sharable @@ -49,18 +48,25 @@ public class FuelEventHandler extends BaseEventHandler { return null; } - double fuelDropThreshold = AttributeUtil.lookup( - cacheManager, Keys.EVENT_FUEL_DROP_THRESHOLD, position.getDeviceId()); - if (fuelDropThreshold > 0) { + if (position.hasAttribute(Position.KEY_FUEL_LEVEL)) { Position lastPosition = cacheManager.getPosition(position.getDeviceId()); - if (position.hasAttribute(Position.KEY_FUEL_LEVEL) - && lastPosition != null && lastPosition.hasAttribute(Position.KEY_FUEL_LEVEL)) { + if (lastPosition != null && lastPosition.hasAttribute(Position.KEY_FUEL_LEVEL)) { + double before = lastPosition.getDouble(Position.KEY_FUEL_LEVEL); + double after = position.getDouble(Position.KEY_FUEL_LEVEL); + double change = after - before; - double drop = lastPosition.getDouble(Position.KEY_FUEL_LEVEL) - - position.getDouble(Position.KEY_FUEL_LEVEL); - if (drop >= fuelDropThreshold) { - Event event = new Event(Event.TYPE_DEVICE_FUEL_DROP, position); - return Collections.singletonMap(event, position); + if (change > 0) { + double threshold = AttributeUtil.lookup( + cacheManager, Keys.EVENT_FUEL_INCREASE_THRESHOLD, position.getDeviceId()); + if (change >= threshold) { + return Map.of(new Event(Event.TYPE_DEVICE_FUEL_INCREASE, position), position); + } + } else if (change < 0) { + double threshold = AttributeUtil.lookup( + cacheManager, Keys.EVENT_FUEL_DROP_THRESHOLD, position.getDeviceId()); + if (Math.abs(change) >= threshold) { + return Map.of(new Event(Event.TYPE_DEVICE_FUEL_DROP, position), position); + } } } } diff --git a/src/main/java/org/traccar/model/Event.java b/src/main/java/org/traccar/model/Event.java index f00a0e5f1..0e851d748 100644 --- a/src/main/java/org/traccar/model/Event.java +++ b/src/main/java/org/traccar/model/Event.java @@ -52,6 +52,7 @@ public class Event extends Message { public static final String TYPE_DEVICE_OVERSPEED = "deviceOverspeed"; public static final String TYPE_DEVICE_FUEL_DROP = "deviceFuelDrop"; + public static final String TYPE_DEVICE_FUEL_INCREASE = "deviceFuelIncrease"; public static final String TYPE_GEOFENCE_ENTER = "geofenceEnter"; public static final String TYPE_GEOFENCE_EXIT = "geofenceExit"; diff --git a/templates/full/deviceFuelIncrease.vm b/templates/full/deviceFuelIncrease.vm new file mode 100644 index 000000000..9d4474e1a --- /dev/null +++ b/templates/full/deviceFuelIncrease.vm @@ -0,0 +1,11 @@ +#set($subject = "$device.name: fuel increase") + + + +Device: $device.name
+Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
+Point: #{if}($position.address)$position.address#{else}$position.latitude°, $position.longitude°#{end}
+
+Unsubscribe + + diff --git a/templates/short/deviceFuelIncrease.vm b/templates/short/deviceFuelIncrease.vm new file mode 100644 index 000000000..6a11418b1 --- /dev/null +++ b/templates/short/deviceFuelIncrease.vm @@ -0,0 +1,2 @@ +#set($subject = "$device.name: fuel increase") +$device.name fuel increase at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) -- cgit v1.2.3 From f1cebbcc72359367fc172eb9836339fb33398eb4 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 6 Aug 2022 21:09:33 -0700 Subject: Fix alarm template --- templates/full/alarm.vm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'templates/full') diff --git a/templates/full/alarm.vm b/templates/full/alarm.vm index 5d367dc3a..9fae1f13b 100644 --- a/templates/full/alarm.vm +++ b/templates/full/alarm.vm @@ -3,7 +3,7 @@ Device: $device.name
-Alarm: $position.getString("alarm")
+Alarm: $position.getString("alarm")
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
Point: #{if}($position.address)$position.address#{else}$position.latitude°, $position.longitude°#{end}

-- cgit v1.2.3 From d898163368bdaaee17a2982ec219e997fd0c9b1f Mon Sep 17 00:00:00 2001 From: gustavofarias Date: Sat, 15 Apr 2023 16:33:54 -0300 Subject: Translate camel case names of alarms into proper readable names. --- templates/full/alarm.vm | 80 +++++++++++++++++++++++++++++++++++++++++++++++- templates/short/alarm.vm | 80 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 158 insertions(+), 2 deletions(-) (limited to 'templates/full') diff --git a/templates/full/alarm.vm b/templates/full/alarm.vm index 9fae1f13b..fb596ecde 100644 --- a/templates/full/alarm.vm +++ b/templates/full/alarm.vm @@ -1,9 +1,87 @@ #set($subject = "$device.name: alarm!") +#set($alarmName = $position.getString("alarm")) +#if( $alarmName == "general") + #set($alarmName = "General") +#elseif($alarmName == "sos") + #set($alarmName = "SOS") +#elseif($alarmName == "vibration") + #set($alarmName = "Vibration") +#elseif($alarmName == "movement") + #set($alarmName = "Movement") +#elseif($alarmName == "lowspeed") + #set($alarmName = "Low Speed") +#elseif($alarmName == "overspeed") + #set($alarmName = "Overspeed") +#elseif($alarmName == "fallDown") + #set($alarmName = "Fall Down") +#elseif($alarmName == "lowPower") + #set($alarmName = "Low Power") +#elseif($alarmName == "lowBattery") + #set($alarmName = "Low Battery") +#elseif($alarmName == "fault") + #set($alarmName = "Fault") +#elseif($alarmName == "powerOff") + #set($alarmName = "Power Off") +#elseif($alarmName == "powerOn") + #set($alarmName = "Power On") +#elseif($alarmName == "door") + #set($alarmName = "Door") +#elseif($alarmName == "lock") + #set($alarmName = "Lock") +#elseif($alarmName == "unlock") + #set($alarmName = "Unlock") +#elseif($alarmName == "geofence") + #set($alarmName = "Geofence") +#elseif($alarmName == "geofenceEnter") + #set($alarmName = "Geofence Enter") +#elseif($alarmName == "geofenceExit") + #set($alarmName = "Geofence Exit") +#elseif($alarmName == "gpsAntennaCut") + #set($alarmName = "GPS Antenna Cut") +#elseif($alarmName == "accident") + #set($alarmName = "Accident") +#elseif($alarmName == "tow") + #set($alarmName = "Tow") +#elseif($alarmName == "idle") + #set($alarmName = "Idle") +#elseif($alarmName == "highRpm") + #set($alarmName = "High RPM") +#elseif($alarmName == "hardAcceleration") + #set($alarmName = "Hard Acceleration") +#elseif($alarmName == "hardBraking") + #set($alarmName = "Hard Braking") +#elseif($alarmName == "hardCornering") + #set($alarmName = "Hard Cornering") +#elseif($alarmName == "laneChange") + #set($alarmName = "Lane Change") +#elseif($alarmName == "fatigueDriving") + #set($alarmName = "Fatigue Driving") +#elseif($alarmName == "powerCut") + #set($alarmName = "Power Cut") +#elseif($alarmName == "powerRestored") + #set($alarmName = "Power Restored") +#elseif($alarmName == "jamming") + #set($alarmName = "Jamming") +#elseif($alarmName == "temperature") + #set($alarmName = "Temperature") +#elseif($alarmName == "parking") + #set($alarmName = "Parking") +#elseif($alarmName == "bonnet") + #set($alarmName = "Bonnet") +#elseif($alarmName == "footBrake") + #set($alarmName = "Foot Brake") +#elseif($alarmName == "fuelLeak") + #set($alarmName = "Fuel Leak") +#elseif($alarmName == "tampering") + #set($alarmName = "Tampering") +#elseif($alarmName == "removing") + #set($alarmName = "Removing") +#end Device: $device.name
-Alarm: $position.getString("alarm")
+Alarm: $alarmName
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
Point: #{if}($position.address)$position.address#{else}$position.latitude°, $position.longitude°#{end}

diff --git a/templates/short/alarm.vm b/templates/short/alarm.vm index 15970dab8..effcb8f15 100644 --- a/templates/short/alarm.vm +++ b/templates/short/alarm.vm @@ -1,2 +1,80 @@ #set($subject = "$device.name: alarm!") -$device.name alarm: $position.getString("alarm") at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) +#set($alarmName = $position.getString("alarm")) +#if( $alarmName == "general") + #set($alarmName = "General") +#elseif($alarmName == "sos") + #set($alarmName = "SOS") +#elseif($alarmName == "vibration") + #set($alarmName = "Vibration") +#elseif($alarmName == "movement") + #set($alarmName = "Movement") +#elseif($alarmName == "lowspeed") + #set($alarmName = "Low Speed") +#elseif($alarmName == "overspeed") + #set($alarmName = "Overspeed") +#elseif($alarmName == "fallDown") + #set($alarmName = "Fall Down") +#elseif($alarmName == "lowPower") + #set($alarmName = "Low Power") +#elseif($alarmName == "lowBattery") + #set($alarmName = "Low Battery") +#elseif($alarmName == "fault") + #set($alarmName = "Fault") +#elseif($alarmName == "powerOff") + #set($alarmName = "Power Off") +#elseif($alarmName == "powerOn") + #set($alarmName = "Power On") +#elseif($alarmName == "door") + #set($alarmName = "Door") +#elseif($alarmName == "lock") + #set($alarmName = "Lock") +#elseif($alarmName == "unlock") + #set($alarmName = "Unlock") +#elseif($alarmName == "geofence") + #set($alarmName = "Geofence") +#elseif($alarmName == "geofenceEnter") + #set($alarmName = "Geofence Enter") +#elseif($alarmName == "geofenceExit") + #set($alarmName = "Geofence Exit") +#elseif($alarmName == "gpsAntennaCut") + #set($alarmName = "GPS Antenna Cut") +#elseif($alarmName == "accident") + #set($alarmName = "Accident") +#elseif($alarmName == "tow") + #set($alarmName = "Tow") +#elseif($alarmName == "idle") + #set($alarmName = "Idle") +#elseif($alarmName == "highRpm") + #set($alarmName = "High RPM") +#elseif($alarmName == "hardAcceleration") + #set($alarmName = "Hard Acceleration") +#elseif($alarmName == "hardBraking") + #set($alarmName = "Hard Braking") +#elseif($alarmName == "hardCornering") + #set($alarmName = "Hard Cornering") +#elseif($alarmName == "laneChange") + #set($alarmName = "Lane Change") +#elseif($alarmName == "fatigueDriving") + #set($alarmName = "Fatigue Driving") +#elseif($alarmName == "powerCut") + #set($alarmName = "Power Cut") +#elseif($alarmName == "powerRestored") + #set($alarmName = "Power Restored") +#elseif($alarmName == "jamming") + #set($alarmName = "Jamming") +#elseif($alarmName == "temperature") + #set($alarmName = "Temperature") +#elseif($alarmName == "parking") + #set($alarmName = "Parking") +#elseif($alarmName == "bonnet") + #set($alarmName = "Bonnet") +#elseif($alarmName == "footBrake") + #set($alarmName = "Foot Brake") +#elseif($alarmName == "fuelLeak") + #set($alarmName = "Fuel Leak") +#elseif($alarmName == "tampering") + #set($alarmName = "Tampering") +#elseif($alarmName == "removing") + #set($alarmName = "Removing") +#end +$device.name alarm: $alarmName at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) -- cgit v1.2.3 From dee954b9f28c129215e9fa600e6860e2d4adb673 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 25 May 2023 06:48:50 -0700 Subject: Remove status event links --- templates/full/deviceOffline.vm | 1 - templates/full/deviceOnline.vm | 1 - templates/full/deviceUnknown.vm | 1 - 3 files changed, 3 deletions(-) (limited to 'templates/full') diff --git a/templates/full/deviceOffline.vm b/templates/full/deviceOffline.vm index 8f2c515b2..6d2122624 100644 --- a/templates/full/deviceOffline.vm +++ b/templates/full/deviceOffline.vm @@ -5,7 +5,6 @@ Device: $device.name
Offline
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
-Link: $webUrl?eventId=$event.id

Unsubscribe diff --git a/templates/full/deviceOnline.vm b/templates/full/deviceOnline.vm index 81a4ccbc8..02260c4fb 100644 --- a/templates/full/deviceOnline.vm +++ b/templates/full/deviceOnline.vm @@ -5,7 +5,6 @@ Device: $device.name
Online
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
-Link: $webUrl?eventId=$event.id

Unsubscribe diff --git a/templates/full/deviceUnknown.vm b/templates/full/deviceUnknown.vm index e012845e6..e99981069 100644 --- a/templates/full/deviceUnknown.vm +++ b/templates/full/deviceUnknown.vm @@ -5,7 +5,6 @@ Device: $device.name
Status is unknown
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)
-Link: $webUrl?eventId=$event.id

Unsubscribe -- cgit v1.2.3