diff --git a/server/src/lib/wifiDevices.js b/server/src/lib/wifiDevices.js
index 0d5a0f1..dc08335 100644
--- a/server/src/lib/wifiDevices.js
+++ b/server/src/lib/wifiDevices.js
@@ -5,12 +5,14 @@ import * as ciscoController from './ciscoController'
import prisma from '../prisma'
import { pubsub, USER_PRESENCE_UPDATED, ACCESS_POINTS_UPDATED } from '../pubsub'
-import { logError, logSuccess } from './logger'
+import { logError, logInfo, logLow, logSuccess } from './logger'
import { performance } from 'perf_hooks'
const RECENT_THRESHOLD_IN_MINUTES = 2
+const OLD_DEVICES_THRESHOLD_IN_DAYS = 90
+
const TIMEOUT_IN_MILLISECONDS = process.env.TASK_TIMEOUT || 120000
let working = false
@@ -225,4 +227,30 @@ function updateDevicesInfo() {
})
}
-export { updateDevicesInfo }
+// Delete devices that are offline for more than OLD_DEVICES_THRESHOLD_IN_DAYS days
+async function deleteOldDevices() {
+ const oldDevicesThresholdInMilliseconds = OLD_DEVICES_THRESHOLD_IN_DAYS * 24 * 60 * 60 * 1000
+
+ const oldDevices = await prisma.wifiDevice.deleteMany({
+ where: {
+ lastSeen: {
+ lt: new Date(Date.now() - oldDevicesThresholdInMilliseconds)
+ },
+ status: 'OFFLINE'
+ }
+ })
+
+ if (oldDevices.count > 0)
+ logInfo({
+ tags: ['wifiDevices', 'deleteOldDevices'],
+ message: `${oldDevices.count} dispositivos Wi-Fi não vistos há mais de ${OLD_DEVICES_THRESHOLD_IN_DAYS} dias foram excluídos.`,
+ data: { oldDevices }
+ })
+ else
+ logInfo({
+ tags: ['wifiDevices', 'deleteOldDevices'],
+ message: `Nenhum dispositivo Wi-Fi não visto há mais de ${OLD_DEVICES_THRESHOLD_IN_DAYS} dias foi encontrado.`
+ })
+}
+
+export { updateDevicesInfo, deleteOldDevices }
diff --git a/server/src/resolvers/Query/wifiDevices.js b/server/src/resolvers/Query/wifiDevices.js
index a413484..bea42a5 100644
--- a/server/src/resolvers/Query/wifiDevices.js
+++ b/server/src/resolvers/Query/wifiDevices.js
@@ -7,6 +7,8 @@ export async function wifiDevices(parent, { take = 50, skip = 0, search, sortBy,
if (!onlineOnly) onlineOnly = undefined
+ console.log(sortBy, sortDesc);
+
const where = {
OR: [
{ hostname: { contains: search, mode } },
@@ -29,8 +31,8 @@ export async function wifiDevices(parent, { take = 50, skip = 0, search, sortBy,
data: prisma.wifiDevice.findMany({
where,
orderBy: [
- { status: 'asc' },
- { [sortBy || 'hostname']: sortDesc ? 'desc' : 'asc' }],
+ { [sortBy || 'hostname']: sortDesc ? 'desc' : 'asc' },
+ ],
include: { user: true, accessPoint: true },
take,
skip
diff --git a/web/src/components/DataTables/AccessPointClientsDataTable.vue b/web/src/components/DataTables/AccessPointClientsDataTable.vue
index c70f5d9..9a05315 100644
--- a/web/src/components/DataTables/AccessPointClientsDataTable.vue
+++ b/web/src/components/DataTables/AccessPointClientsDataTable.vue
@@ -13,12 +13,12 @@
-
- {{ mac }}
-
-
-
- {{ ip }}
+
+ {{ ip }}
+
+
+ {{ mac }}
+
@@ -73,8 +73,7 @@ export default {
data: () => ({
headers: [
{ text: 'Hostname', value: 'hostname' },
- { text: 'MAC', value: 'mac' },
- { text: 'IP', value: 'ip' },
+ { text: 'IP / MAC', value: 'ip' },
{ text: 'ESSID', value: 'essid' },
{ text: 'Uptime', value: 'uptime' },
{ text: 'Usuário', value: 'combinedUser' },
@@ -102,4 +101,8 @@ export default {
}
-
+
diff --git a/web/src/components/DataTables/UserWifiDevicesDataTable.vue b/web/src/components/DataTables/UserWifiDevicesDataTable.vue
index 0f6736a..d18320f 100644
--- a/web/src/components/DataTables/UserWifiDevicesDataTable.vue
+++ b/web/src/components/DataTables/UserWifiDevicesDataTable.vue
@@ -19,12 +19,14 @@
Offline
-
- {{ ip }}
-
-
- {{ mac }}
+
+ {{ ip }}
+
+
+ {{ mac }}
+
+
{{ essid }}
@@ -53,9 +55,6 @@
>
{{ item.apName }}
-
- ({{ item.accessPoint.local }})
-
@@ -85,8 +84,7 @@ export default {
search: '',
headers: [
{ text: 'Hostname', value: 'hostname' },
- { text: 'IP', value: 'ip' },
- { text: 'MAC', value: 'mac' },
+ { text: 'IP / MAC', value: 'ip' },
{ text: 'Status', value: 'status' },
{ text: 'ESSID', value: 'essid' },
{ text: 'Sinal', value: 'signalStrength' },
@@ -109,7 +107,7 @@ export default {
}
-