summaryrefslogtreecommitdiffstats
path: root/server/lib
diff options
context:
space:
mode:
authorJannik Schönartz2019-12-01 16:03:55 +0100
committerJannik Schönartz2019-12-01 16:03:55 +0100
commitdc25bd7de72aa574767876341e5792733c2ee0e0 (patch)
tree4086f19a6df107773a3990c422fe1160f8959147 /server/lib
parent[configloader] bugfixes in the beta configloader: (diff)
downloadbas-dc25bd7de72aa574767876341e5792733c2ee0e0.tar.gz
bas-dc25bd7de72aa574767876341e5792733c2ee0e0.tar.xz
bas-dc25bd7de72aa574767876341e5792733c2ee0e0.zip
[server/log] Add logging to all modules
Logging with snapshots: Client: create / edit / delete / added to group / removed from group Group: create / edit / delete / added to group / removed from group Logging without snapshot: Wake-on-lan: wakup Ipxe-Builder: build / clear / cancel / script save IP-Ranges: create / edit / delete Logging: with info in description: User: create / edit / delete / grant role / revoke role Event: create / edit / delete Permission-Manager-Role: create / edit / delete Registration-Hook: create / delete / edit / change order Ipxe Configuration: create / delete / edit Backend: create / edit / delete
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/log.js13
-rw-r--r--server/lib/wolhelper.js16
2 files changed, 25 insertions, 4 deletions
diff --git a/server/lib/log.js b/server/lib/log.js
index fede874..782c34f 100644
--- a/server/lib/log.js
+++ b/server/lib/log.js
@@ -2,7 +2,7 @@
const path = require('path')
var db = require(path.join(__appdir, 'lib', 'sequelize'))
-async function log ({ category, description, groupId, clientId, userId }) {
+async function log ({ category, description, clientId, userId, groupId, group, client, user }) {
const entry = db.log.build({
category,
description,
@@ -11,9 +11,14 @@ async function log ({ category, description, groupId, clientId, userId }) {
clientId,
userId
})
- if (groupId) entry.groupSnapshot = JSON.stringify(await db.group.findOne({ where: { id: groupId } }))
- if (clientId) entry.clientSnapshot = JSON.stringify(await db.client.findOne({ where: { id: clientId } }))
- if (userId) entry.userSnapshot = JSON.stringify(await db.user.findOne({ where: { id: userId } }))
+
+ if (group) entry.groupSnapshot = JSON.stringify(group)
+ else if (groupId) entry.groupSnapshot = JSON.stringify(await db.group.findOne({ where: { id: groupId } }))
+ if (client) entry.clientSnapshot = JSON.stringify(client)
+ else if (clientId) entry.clientSnapshot = JSON.stringify(await db.client.findOne({ where: { id: clientId } }))
+ if (user) entry.userSnapshot = JSON.stringify(user)
+ else if (userId) entry.userSnapshot = JSON.stringify(await db.user.findOne({ where: { id: userId } }))
+
await entry.save()
return entry
}
diff --git a/server/lib/wolhelper.js b/server/lib/wolhelper.js
index 97c0958..c840e44 100644
--- a/server/lib/wolhelper.js
+++ b/server/lib/wolhelper.js
@@ -1,3 +1,6 @@
+/* global __appdir */
+var path = require('path')
+const log = require(path.join(__appdir, 'lib', 'log'))
const wol = require('node-wol')
function wakeUp (clients) {
@@ -8,6 +11,19 @@ function wakeUp (clients) {
if (client.mac !== null && client.ip !== null) {
console.log('Waking up: ' + client.name + ' (' + client.mac + ')')
wol.wake(client.mac, { address: client.ip.slice(0, client.ip.lastIndexOf('.') + 1) + '255' }, err => { if (err) console.log(err) })
+ log({
+ category: 'WAKE_ON_LAN',
+ description: 'Wake on Lan signal sent to client.',
+ client,
+ clientId: client.id
+ })
+ } else {
+ log({
+ category: 'ERROR_WAKE_ON_LAN',
+ description: 'Client is missing ip or mac address.',
+ client,
+ clientId: client.id
+ })
}
i++
if (i < clients.length) loop()