Skip to content

Commit

Permalink
Merge branch 'traccar:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
rora-fly authored Feb 21, 2024
2 parents aa1b994 + 8cf3fcd commit e25fb02
Show file tree
Hide file tree
Showing 71 changed files with 1,471 additions and 233 deletions.
36 changes: 18 additions & 18 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ compileJava.options.encoding = "UTF-8"
jar.destinationDirectory = file("$projectDir/target")

checkstyle {
toolVersion = "10.12.0"
toolVersion = "10.12.5"
configFile = "gradle/checkstyle.xml" as File
checkstyleTest.enabled = false
}
Expand All @@ -27,11 +27,11 @@ enforce {

ext {
guiceVersion = "7.0.0"
jettyVersion = "11.0.18"
jerseyVersion = "3.1.3"
jacksonVersion = "2.15.2" // same version as jersey-media-json-jackson dependency
protobufVersion = "3.24.0"
jxlsVersion = "2.13.0"
jettyVersion = "11.0.19"
jerseyVersion = "3.1.5"
jacksonVersion = "2.15.3" // same version as jersey-media-json-jackson dependency
protobufVersion = "3.25.2"
jxlsVersion = "2.14.0"
junitVersion = "5.10.1"
}

Expand All @@ -45,12 +45,12 @@ dependencies {
implementation "commons-codec:commons-codec:1.16.0"
implementation "com.h2database:h2:2.2.224"
implementation "com.mysql:mysql-connector-j:8.2.0"
implementation "org.mariadb.jdbc:mariadb-java-client:3.3.0"
implementation "org.postgresql:postgresql:42.6.0"
implementation "org.mariadb.jdbc:mariadb-java-client:3.3.2"
implementation "org.postgresql:postgresql:42.7.1"
implementation "com.microsoft.sqlserver:mssql-jdbc:12.4.2.jre11"
implementation "com.zaxxer:HikariCP:5.1.0"
implementation "io.netty:netty-all:4.1.101.Final"
implementation "org.slf4j:slf4j-jdk14:2.0.9"
implementation "io.netty:netty-all:4.1.104.Final"
implementation "org.slf4j:slf4j-jdk14:2.0.11"
implementation "com.google.inject:guice:$guiceVersion"
implementation "com.google.inject.extensions:guice-servlet:$guiceVersion"
implementation "org.owasp.encoder:encoder:1.2.3"
Expand All @@ -66,7 +66,7 @@ dependencies {
implementation "org.glassfish.jersey.containers:jersey-container-servlet:$jerseyVersion"
implementation "org.glassfish.jersey.media:jersey-media-json-jackson:$jerseyVersion"
implementation "org.glassfish.jersey.inject:jersey-hk2:$jerseyVersion"
implementation "org.glassfish.hk2:guice-bridge:3.0.4" // same version as jersey-hk2
implementation "org.glassfish.hk2:guice-bridge:3.0.5" // same version as jersey-hk2
implementation "com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:$jacksonVersion"
implementation "com.fasterxml.jackson.datatype:jackson-datatype-jakarta-jsonp:$jacksonVersion"
implementation "org.liquibase:liquibase-core:4.23.2" // upgrade has issues
Expand All @@ -79,20 +79,20 @@ dependencies {
implementation "org.mnode.ical4j:ical4j:3.2.14"
implementation "org.locationtech.spatial4j:spatial4j:0.8"
implementation "org.locationtech.jts:jts-core:1.19.0"
implementation "net.java.dev.jna:jna-platform:5.13.0"
implementation "net.java.dev.jna:jna-platform:5.14.0"
implementation "com.github.jnr:jnr-posix:3.1.18"
implementation "com.google.protobuf:protobuf-java:$protobufVersion"
implementation "com.amazonaws:aws-java-sdk-sns:1.12.592"
implementation "org.apache.kafka:kafka-clients:3.6.0"
implementation "com.amazonaws:aws-java-sdk-sns:1.12.636"
implementation "org.apache.kafka:kafka-clients:3.6.1"
implementation "com.hivemq:hivemq-mqtt-client:1.3.3"
implementation "redis.clients:jedis:5.0.2"
implementation "redis.clients:jedis:5.1.0"
implementation "com.google.firebase:firebase-admin:9.2.0"
implementation "com.nimbusds:oauth2-oidc-sdk:11.6"
implementation "com.nimbusds:oauth2-oidc-sdk:11.9.1"
implementation "com.rabbitmq:amqp-client:5.20.0"
implementation "com.warrenstrange:googleauth:1.5.0"
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
testImplementation "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
testImplementation "org.mockito:mockito-core:5.7.0"
testImplementation "org.mockito:mockito-core:5.8.0"
}

test {
Expand All @@ -109,7 +109,7 @@ jar {
manifest {
attributes(
"Main-Class": "org.traccar.Main",
"Implementation-Version": "5.10",
"Implementation-Version": "5.12",
"Class-Path": configurations.runtimeClasspath.files.collect { "lib/$it.name" }.join(" "))
}
}
2 changes: 2 additions & 0 deletions setup/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<entry key='web.path'>./modern</entry>
<entry key='web.sanitize'>false</entry>
<entry key='web.persistSession'>false</entry>
<entry key='web.showUnknownDevices'>true</entry>

<entry key='geocoder.enable'>true</entry>
<entry key='geocoder.type'>locationiq</entry>
Expand Down Expand Up @@ -295,5 +296,6 @@
<entry key='ramac.port'>5251</entry>
<entry key='positrex.port'>5252</entry>
<entry key='dragino.port'>5253</entry>
<entry key='fleetguide.port'>5254</entry>

</properties>
2 changes: 1 addition & 1 deletion setup/traccar.iss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[Setup]
AppName=Traccar
AppVersion=5.10
AppVersion=5.12
DefaultDirName={pf}\Traccar
OutputBaseFilename=traccar-setup
ArchitecturesInstallIn64BitMode=x64
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/traccar/BaseProtocolDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder {
private MediaManager mediaManager;
private CommandsManager commandsManager;

private String modelOverride;

public BaseProtocolDecoder(Protocol protocol) {
this.protocol = protocol;
}
Expand Down Expand Up @@ -141,6 +143,14 @@ public DeviceSession getDeviceSession(Channel channel, SocketAddress remoteAddre
}
}

public void setModelOverride(String modelOverride) {
this.modelOverride = modelOverride;
}

public String getDeviceModel(DeviceSession deviceSession) {
return modelOverride != null ? modelOverride : deviceSession.getModel();
}

public void getLastLocation(Position position, Date deviceTime) {
if (position.getDeviceId() != 0) {
position.setOutdated(true);
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/traccar/BaseProtocolEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public abstract class BaseProtocolEncoder extends ChannelOutboundHandlerAdapter

private CacheManager cacheManager;

private String modelOverride;

public BaseProtocolEncoder(Protocol protocol) {
this.protocol = protocol;
}
Expand Down Expand Up @@ -68,6 +70,15 @@ protected void initDevicePassword(Command command, String defaultPassword) {
}
}

public void setModelOverride(String modelOverride) {
this.modelOverride = modelOverride;
}

public String getDeviceModel(long deviceId) {
String model = getCacheManager().getObject(Device.class, deviceId).getModel();
return modelOverride != null ? modelOverride : model;
}

@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {

Expand Down
32 changes: 12 additions & 20 deletions src/main/java/org/traccar/Main.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012 - 2022 Anton Tananaev (anton@traccar.org)
* Copyright 2012 - 2024 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.
Expand All @@ -20,10 +20,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.traccar.broadcast.BroadcastService;
import org.traccar.helper.model.DeviceUtil;
import org.traccar.schedule.ScheduleManager;
import org.traccar.storage.DatabaseModule;
import org.traccar.storage.Storage;
import org.traccar.web.WebModule;
import org.traccar.web.WebServer;

Expand All @@ -33,10 +31,9 @@
import java.lang.management.OperatingSystemMXBean;
import java.lang.management.RuntimeMXBean;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public final class Main {

Expand Down Expand Up @@ -70,8 +67,7 @@ public static void logSystemInfo() {
+ " heap: " + memoryBean.getHeapMemoryUsage().getMax() / (1024 * 1024) + "mb"
+ " non-heap: " + memoryBean.getNonHeapMemoryUsage().getMax() / (1024 * 1024) + "mb");

LOGGER.info("Character encoding: "
+ System.getProperty("file.encoding") + " charset: " + Charset.defaultCharset());
LOGGER.info("Character encoding: " + Charset.defaultCharset().displayName());

} catch (Exception error) {
LOGGER.warn("Failed to get system info");
Expand Down Expand Up @@ -122,18 +118,14 @@ public static void run(String configFile) {
LOGGER.info("Version: " + Main.class.getPackage().getImplementationVersion());
LOGGER.info("Starting server...");

if (injector.getInstance(BroadcastService.class).singleInstance()) {
DeviceUtil.resetStatus(injector.getInstance(Storage.class));
}

var services = Stream.of(
ServerManager.class, WebServer.class, ScheduleManager.class, BroadcastService.class)
.map(injector::getInstance)
.filter(Objects::nonNull)
.collect(Collectors.toList());

for (var service : services) {
service.start();
var services = new ArrayList<LifecycleObject>();
for (var clazz : List.of(
ScheduleManager.class, ServerManager.class, WebServer.class, BroadcastService.class)) {
var service = injector.getInstance(clazz);
if (service != null) {
service.start();
services.add(service);
}
}

Thread.setDefaultUncaughtExceptionHandler((t, e) -> LOGGER.error("Thread exception", e));
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/traccar/WindowsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private void reportStatus(int status, int win32ExitCode, int waitHint) {

public abstract void run();

private class ServiceMain implements SERVICE_MAIN_FUNCTION {
private final class ServiceMain implements SERVICE_MAIN_FUNCTION {

public void callback(int dwArgc, Pointer lpszArgv) {
ServiceControl serviceControl = new ServiceControl();
Expand Down Expand Up @@ -203,7 +203,7 @@ public void callback(int dwArgc, Pointer lpszArgv) {

}

private class ServiceControl implements HandlerEx {
private final class ServiceControl implements HandlerEx {

public int callback(int dwControl, int dwEventType, Pointer lpEventData, Pointer lpContext) {
switch (dwControl) {
Expand Down
40 changes: 31 additions & 9 deletions src/main/java/org/traccar/api/resource/DeviceResource.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015 - 2022 Anton Tananaev (anton@traccar.org)
* Copyright 2015 - 2024 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.
Expand All @@ -19,6 +19,8 @@
import org.traccar.api.BaseObjectResource;
import org.traccar.api.signature.TokenManager;
import org.traccar.broadcast.BroadcastService;
import org.traccar.config.Config;
import org.traccar.config.Keys;
import org.traccar.database.MediaManager;
import org.traccar.helper.LogAction;
import org.traccar.model.Device;
Expand Down Expand Up @@ -60,6 +62,9 @@
@Consumes(MediaType.APPLICATION_JSON)
public class DeviceResource extends BaseObjectResource<Device> {

@Inject
private Config config;

@Inject
private CacheManager cacheManager;

Expand Down Expand Up @@ -199,23 +204,40 @@ public String shareDevice(
@FormParam("expiration") Date expiration) throws StorageException, GeneralSecurityException, IOException {

User user = permissionsService.getUser(getUserId());
if (permissionsService.getServer().getBoolean(Keys.DEVICE_SHARE_DISABLE.getKey())) {
throw new SecurityException("Sharing is disabled");
}
if (user.getTemporary()) {
throw new SecurityException("Temporary user");
}
if (user.getExpirationTime() != null && user.getExpirationTime().before(expiration)) {
expiration = user.getExpirationTime();
}

Device device = storage.getObject(Device.class, new Request(
new Columns.All(),
new Condition.And(
new Condition.Equals("id", deviceId),
new Condition.Permission(User.class, user.getId(), Device.class))));

User share = new User();
share.setName(device.getName());
share.setEmail(user.getEmail() + ":" + device.getUniqueId());
share.setExpirationTime(expiration);
share.setTemporary(true);
share.setReadonly(true);
String shareEmail = user.getEmail() + ":" + device.getUniqueId();
User share = storage.getObject(User.class, new Request(
new Columns.All(), new Condition.Equals("email", shareEmail)));

if (share == null) {
share = new User();
share.setName(device.getName());
share.setEmail(shareEmail);
share.setExpirationTime(expiration);
share.setTemporary(true);
share.setReadonly(true);
share.setLimitCommands(user.getLimitCommands() || !config.getBoolean(Keys.WEB_SHARE_DEVICE_COMMANDS));
share.setDisableReports(user.getDisableReports() || !config.getBoolean(Keys.WEB_SHARE_DEVICE_REPORTS));

share.setId(storage.addObject(share, new Request(new Columns.Exclude("id"))));
share.setId(storage.addObject(share, new Request(new Columns.Exclude("id"))));

storage.addPermission(new Permission(User.class, share.getId(), Device.class, deviceId));
storage.addPermission(new Permission(User.class, share.getId(), Device.class, deviceId));
}

return tokenManager.generateToken(share.getId(), expiration);
}
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/org/traccar/api/resource/ServerResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ public Server get() throws StorageException {
} else {
server.setNewServer(UserUtil.isEmpty(storage));
}
if (user != null && user.getAdministrator()) {
server.setStorageSpace(Log.getStorageSpace());
}
return server;
}

Expand Down
Loading

0 comments on commit e25fb02

Please sign in to comment.