aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar')
-rw-r--r--src/main/java/org/traccar/api/resource/ServerResource.java6
-rw-r--r--src/main/java/org/traccar/helper/Log.java18
-rw-r--r--src/main/java/org/traccar/model/Server.java12
3 files changed, 36 insertions, 0 deletions
diff --git a/src/main/java/org/traccar/api/resource/ServerResource.java b/src/main/java/org/traccar/api/resource/ServerResource.java
index b66f5a931..2ef99c578 100644
--- a/src/main/java/org/traccar/api/resource/ServerResource.java
+++ b/src/main/java/org/traccar/api/resource/ServerResource.java
@@ -18,8 +18,10 @@ package org.traccar.api.resource;
import org.traccar.api.BaseResource;
import org.traccar.database.MailManager;
import org.traccar.geocoder.Geocoder;
+import org.traccar.helper.Log;
import org.traccar.helper.LogAction;
import org.traccar.model.Server;
+import org.traccar.model.User;
import org.traccar.storage.Storage;
import org.traccar.storage.StorageException;
import org.traccar.storage.query.Columns;
@@ -60,6 +62,10 @@ public class ServerResource extends BaseResource {
public Server get() throws StorageException {
Server server = storage.getObject(Server.class, new Request(new Columns.All()));
server.setEmailEnabled(mailManager.getEmailEnabled());
+ User user = permissionsService.getUser(getUserId());
+ if (user != null && user.getAdministrator()) {
+ server.setStorageSpace(Log.getStorageSpace());
+ }
return server;
}
diff --git a/src/main/java/org/traccar/helper/Log.java b/src/main/java/org/traccar/helper/Log.java
index 8c67f9ddc..e1b201f9f 100644
--- a/src/main/java/org/traccar/helper/Log.java
+++ b/src/main/java/org/traccar/helper/Log.java
@@ -28,6 +28,10 @@ import java.io.StringWriter;
import java.io.Writer;
import java.net.URL;
import java.nio.charset.StandardCharsets;
+import java.nio.file.FileStore;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.ConsoleHandler;
@@ -269,4 +273,18 @@ public final class Log {
return s.toString();
}
+ public static long[] getStorageSpace() {
+ long usable = 0;
+ long total = 0;
+ for (Path root : FileSystems.getDefault().getRootDirectories()) {
+ try {
+ FileStore store = Files.getFileStore(root);
+ usable += store.getUsableSpace();
+ total += store.getTotalSpace();
+ } catch (IOException ignored) {
+ }
+ }
+ return new long[]{usable, total};
+ }
+
}
diff --git a/src/main/java/org/traccar/model/Server.java b/src/main/java/org/traccar/model/Server.java
index ee7f7069a..648be2991 100644
--- a/src/main/java/org/traccar/model/Server.java
+++ b/src/main/java/org/traccar/model/Server.java
@@ -214,4 +214,16 @@ public class Server extends ExtendedModel implements UserRestrictions {
return emailEnabled;
}
+ private long[] storageSpace;
+
+ @QueryIgnore
+ public long[] getStorageSpace() {
+ return storageSpace;
+ }
+
+ @QueryIgnore
+ public void setStorageSpace(long[] storageSpace) {
+ this.storageSpace = storageSpace;
+ }
+
}