diff --git a/server/prisma/migrations/20201119134248-add-controller-to-wifi-device/README.md b/server/prisma/migrations/20201119134248-add-controller-to-wifi-device/README.md new file mode 100644 index 0000000..16a5e2f --- /dev/null +++ b/server/prisma/migrations/20201119134248-add-controller-to-wifi-device/README.md @@ -0,0 +1,68 @@ +# Migration `20201119134248-add-controller-to-wifi-device` + +This migration has been generated by Douglas Barone at 11/19/2020, 9:42:48 AM. +You can check out the [state of the schema](./schema.prisma) after the migration. + +## Database Steps + +```sql +ALTER TABLE "WifiDevice" ADD COLUMN "controller" TEXT NOT NULL DEFAULT E'unknown' +``` + +## Changes + +```diff +diff --git schema.prisma schema.prisma +migration 20201110194349-init..20201119134248-add-controller-to-wifi-device +--- datamodel.dml ++++ datamodel.dml +@@ -3,9 +3,9 @@ + } + datasource db { + provider = "postgresql" +- url = "***" ++ url = "***" + } + model ResetToken { + id Int @id @default(autoincrement()) +@@ -71,23 +71,24 @@ + WifiDevice WifiDevice[] @relation("wifidevice_to_user") + } + model WifiDevice { +- id Int @id @default(autoincrement()) +- oui String? +- mac String @unique +- hostname String? +- firstSeen DateTime? +- lastSeen DateTime? +- essid String? +- ip String? +- uptime String? +- apName String? +- status Status? +- createdAt DateTime @default(now()) +- updatedAt DateTime @updatedAt +- userId Int? +- user User? @relation(fields: [userId], references: [id], name: "wifidevice_to_user") ++ id Int @id @default(autoincrement()) ++ mac String @unique ++ controller String @default("unknown") ++ createdAt DateTime @default(now()) ++ updatedAt DateTime @updatedAt ++ oui String? ++ hostname String? ++ firstSeen DateTime? ++ lastSeen DateTime? ++ essid String? ++ ip String? ++ uptime String? ++ apName String? ++ status Status? ++ userId Int? ++ user User? @relation(fields: [userId], references: [id], name: "wifidevice_to_user") + } + enum Status { + ONLINE +``` + + diff --git a/server/prisma/migrations/20201119134248-add-controller-to-wifi-device/schema.prisma b/server/prisma/migrations/20201119134248-add-controller-to-wifi-device/schema.prisma new file mode 100644 index 0000000..eb30da2 --- /dev/null +++ b/server/prisma/migrations/20201119134248-add-controller-to-wifi-device/schema.prisma @@ -0,0 +1,96 @@ +generator client { + provider = "prisma-client-js" +} + +datasource db { + provider = "postgresql" + url = "***" +} + +model ResetToken { + id Int @id @default(autoincrement()) + token String @unique + expiration DateTime + usedAt DateTime? + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + user User @relation(fields: [userId], references: [id], name: "resettoken_to_user") + userId Int + creator User @relation(fields: [creatorId], references: [id], name: "resettoken_to_creator") + creatorId Int +} + +model User { + id Int @id @default(autoincrement()) + lastLogin DateTime? + lastLoginPrior DateTime? + roles Json? + groups Json? + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + accountExpires String? + badPasswordTime String? + badPwdCount String? + cn String? + department String? + description String? + displayName String? + distinguishedName String? + dn String? + extensionAttribute1 String? + extensionAttribute10 String? + extensionAttribute2 String? + extensionAttribute6 String? + extensionAttribute7 String? + givenName String? + homeDirectory String? + homeDrive String? + lastLogoff String? + lastLogon String? + lastLogonTimestamp String? + lockoutTime String? + logonCount String? + mail String? + name String? + objectCategory String? + objectGUID String? + objectSid String? + primaryGroupID String? + pwdLastSet DateTime? + sAMAccountName String @unique + sAMAccountType String? + sn String? + thumbnailPhoto String? + title String? + userAccountControl String? + userPrincipalName String? + whenChanged String? + whenCreated String? + createdTokens ResetToken[] @relation("resettoken_to_user") + tokens ResetToken[] @relation("resettoken_to_creator") + WifiDevice WifiDevice[] @relation("wifidevice_to_user") +} + +model WifiDevice { + id Int @id @default(autoincrement()) + mac String @unique + controller String @default("unknown") + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + oui String? + hostname String? + firstSeen DateTime? + lastSeen DateTime? + essid String? + ip String? + uptime String? + apName String? + status Status? + userId Int? + user User? @relation(fields: [userId], references: [id], name: "wifidevice_to_user") +} + +enum Status { + ONLINE + OFFLINE +} diff --git a/server/prisma/migrations/20201119134248-add-controller-to-wifi-device/steps.json b/server/prisma/migrations/20201119134248-add-controller-to-wifi-device/steps.json new file mode 100644 index 0000000..6bdae71 --- /dev/null +++ b/server/prisma/migrations/20201119134248-add-controller-to-wifi-device/steps.json @@ -0,0 +1,37 @@ +{ + "version": "0.3.14-fixed", + "steps": [ + { + "tag": "CreateField", + "model": "WifiDevice", + "field": "controller", + "type": "String", + "arity": "Required" + }, + { + "tag": "CreateDirective", + "location": { + "path": { + "tag": "Field", + "model": "WifiDevice", + "field": "controller" + }, + "directive": "default" + } + }, + { + "tag": "CreateArgument", + "location": { + "tag": "Directive", + "path": { + "tag": "Field", + "model": "WifiDevice", + "field": "controller" + }, + "directive": "default" + }, + "argument": "", + "value": "\"unknown\"" + } + ] +} \ No newline at end of file diff --git a/server/prisma/migrations/migrate.lock b/server/prisma/migrations/migrate.lock index 4f2bc0f..bf70e8d 100644 --- a/server/prisma/migrations/migrate.lock +++ b/server/prisma/migrations/migrate.lock @@ -1,3 +1,4 @@ # Prisma Migrate lockfile v1 -20201110194349-init \ No newline at end of file +20201110194349-init +20201119134248-add-controller-to-wifi-device \ No newline at end of file diff --git a/server/prisma/schema.prisma b/server/prisma/schema.prisma index 2e02e14..1a62181 100644 --- a/server/prisma/schema.prisma +++ b/server/prisma/schema.prisma @@ -72,21 +72,22 @@ model User { } model WifiDevice { - id Int @id @default(autoincrement()) - oui String? - mac String @unique - hostname String? - firstSeen DateTime? - lastSeen DateTime? - essid String? - ip String? - uptime String? - apName String? - status Status? - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - userId Int? - user User? @relation(fields: [userId], references: [id], name: "wifidevice_to_user") + id Int @id @default(autoincrement()) + mac String @unique + controller String @default("unknown") + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + oui String? + hostname String? + firstSeen DateTime? + lastSeen DateTime? + essid String? + ip String? + uptime String? + apName String? + status Status? + userId Int? + user User? @relation(fields: [userId], references: [id], name: "wifidevice_to_user") } enum Status { diff --git a/server/src/resolvers/Query.js b/server/src/resolvers/Query.js index 0c247ca..2ff6a66 100755 --- a/server/src/resolvers/Query.js +++ b/server/src/resolvers/Query.js @@ -106,11 +106,9 @@ const Query = { }, userPresence: async (_, { search }) => { - if (!search) { - //await updateDBWithOnlineDevices() - updateDBWithOnlineDevices() - search = '' - } + if (!search) search = '' + + updateDBWithOnlineDevices() const usersWithWifiDevices = await prisma.user.findMany({ where: { @@ -123,7 +121,9 @@ const Query = { .filter( user => user.displayName.toLowerCase().includes(search.toLowerCase()) || - user.WifiDevice[0].apName.toLowerCase().includes(search.toLowerCase()) + user.WifiDevice.some(device => + device.apName.toLowerCase().includes(search.toLowerCase()) + ) ) .map(user => ({ user: { diff --git a/server/src/typeDefs.js b/server/src/typeDefs.js index 2aea181..f7bf2b7 100644 --- a/server/src/typeDefs.js +++ b/server/src/typeDefs.js @@ -28,7 +28,7 @@ const typeDefs = gql` identifiedOnly: Boolean = true ): [WifiDevice]! - userPresence(search: String): [UserPresence!] @auth(roles: ["watcher"]) + userPresence(search: String = ""): [UserPresence!] @auth(roles: ["watcher"]) } type Mutation { @@ -140,9 +140,10 @@ const typeDefs = gql` type WifiDevice { user: User - id: String + id: ID! oui: String - mac: String + mac: String! + controller: String! hostname: String firstSeen: String lastSeen: String diff --git a/server/src/utils/ciscoController.js b/server/src/utils/ciscoController.js index 8972cfb..0c0a06e 100644 --- a/server/src/utils/ciscoController.js +++ b/server/src/utils/ciscoController.js @@ -61,7 +61,8 @@ export async function getOnlineWifiDevices() { ip: client.IP, uptime: client.UT.toString(), apName: client.AP, - status: client.ST == 'Online' ? 'ONLINE' : 'OFFLINE' + status: client.ST == 'Online' ? 'ONLINE' : 'OFFLINE', + controller: "Cisco" })) return hydratedOnlineDevices diff --git a/server/src/utils/unifiController.js b/server/src/utils/unifiController.js index 70cc7e2..e959f67 100644 --- a/server/src/utils/unifiController.js +++ b/server/src/utils/unifiController.js @@ -188,15 +188,14 @@ export async function getOnlineWifiDevices() { ip: client.ip, uptime: client.uptime.toString(), apName: accessPoints[0].find(ap => ap.mac === client.ap_mac).name, - status: 'ONLINE' + status: 'ONLINE', + controller: "UniFi" })) - unifiController.logout() + await unifiController.logout() return hydratedOnlineDevices } catch (e) { throw new Error('Error getting devices. ' + e) } } - - diff --git a/server/src/utils/wifiUtils.js b/server/src/utils/wifiUtils.js index 070ee23..56e89d3 100644 --- a/server/src/utils/wifiUtils.js +++ b/server/src/utils/wifiUtils.js @@ -13,41 +13,49 @@ async function updateDBWithOnlineDevices() { const onlineUnifiDevicesPromise = getOnlineUnifiDevices() const onlineCiscoDevicesPromise = getOnlineCiscoDevices() - const [onlineUnifiDevices, onlineCiscoDevices] = await Promise.all([ - onlineUnifiDevicesPromise, - onlineCiscoDevicesPromise - ]) + try { + const [onlineUnifiDevices, onlineCiscoDevices] = await Promise.all([ + onlineUnifiDevicesPromise, + onlineCiscoDevicesPromise + ]) - await prisma.wifiDevice.updateMany({ - data: { - status: 'OFFLINE' - } - }) + await prisma.wifiDevice.updateMany({ + data: { + status: 'OFFLINE' + } + }) - const onlineDevices = [...onlineUnifiDevices, ...onlineCiscoDevices] + const onlineDevices = [...onlineUnifiDevices, ...onlineCiscoDevices] - for (const onlineDevice of onlineDevices) { - const device = { - ...onlineDevice, - user: onlineDevice.user - ? { connect: { sAMAccountName: onlineDevice.user } } - : undefined + for (const onlineDevice of onlineDevices) { + const device = { + ...onlineDevice, + user: onlineDevice.user + ? { connect: { sAMAccountName: onlineDevice.user } } + : undefined + } + + try { + await prisma.wifiDevice.upsert({ + where: { mac: onlineDevice.mac }, + create: device, + update: device + }) + } catch (e) { + if (e.code != 'P2016') console.log('[wifiDevice upsert error]', e) + } } - try { - await prisma.wifiDevice.upsert({ - where: { mac: onlineDevice.mac }, - create: device, - update: device - }) - } catch (e) { - if (e.code != 'P2016') console.log('[wifiDevice upsert error]', e) - } + setTimeout(() => { + updating = false + }, 10000) + + // TODO: pubsub + return onlineDevices.length + } catch (e) { + console.log('Error updating DB: ', e) + return -2 } - - updating = false - // TODO: pubsub - return onlineDevices.length } export { updateDBWithOnlineDevices } diff --git a/web/src/assets/bg.jpeg b/web/src/assets/bg.jpeg deleted file mode 100755 index ea8d72d..0000000 Binary files a/web/src/assets/bg.jpeg and /dev/null differ diff --git a/web/src/assets/bg.jpg b/web/src/assets/bg.jpg deleted file mode 100755 index d6235e1..0000000 Binary files a/web/src/assets/bg.jpg and /dev/null differ diff --git a/web/src/assets/cisco_logo.svg b/web/src/assets/cisco_logo.svg new file mode 100644 index 0000000..b210c52 --- /dev/null +++ b/web/src/assets/cisco_logo.svg @@ -0,0 +1,31 @@ + + + + + + diff --git a/web/src/assets/unifi_logo.svg b/web/src/assets/unifi_logo.svg new file mode 100644 index 0000000..f24e657 --- /dev/null +++ b/web/src/assets/unifi_logo.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/web/src/components/ApIcon.vue b/web/src/components/ApIcon.vue new file mode 100644 index 0000000..835631b --- /dev/null +++ b/web/src/components/ApIcon.vue @@ -0,0 +1,26 @@ + + diff --git a/web/src/components/UserPresenceStatusList.vue b/web/src/components/UserPresenceStatusList.vue index 7f6de62..4e0cc2e 100644 --- a/web/src/components/UserPresenceStatusList.vue +++ b/web/src/components/UserPresenceStatusList.vue @@ -43,6 +43,7 @@ {{ userPresence.wifiDevices[0].apName }} + @@ -96,9 +97,11 @@