summaryrefslogtreecommitdiffstats
path: root/server/api
diff options
context:
space:
mode:
authorChristian Hofmaier2019-03-25 18:01:48 +0100
committerChristian Hofmaier2019-03-25 18:01:48 +0100
commitd325ee44ae8323445627b93387d567a9e2b02d91 (patch)
treef801b636015caa17a9a13e0dcc43864e9e59ba7b /server/api
parent[external-backends/idoit] Add server rack segmentation & add multiple ip support (diff)
downloadbas-d325ee44ae8323445627b93387d567a9e2b02d91.tar.gz
bas-d325ee44ae8323445627b93387d567a9e2b02d91.tar.xz
bas-d325ee44ae8323445627b93387d567a9e2b02d91.zip
[configloader] fix sendFile async bug
Diffstat (limited to 'server/api')
-rw-r--r--server/api/configloader.js37
1 files changed, 30 insertions, 7 deletions
diff --git a/server/api/configloader.js b/server/api/configloader.js
index 63c0d84..90d9e88 100644
--- a/server/api/configloader.js
+++ b/server/api/configloader.js
@@ -17,7 +17,7 @@ noAuthRouter.getAsync('/:uuid', async (req, res) => {
// client is in registration state, load scripts
var hook = await db.registrationhook.findOne({ where: { id: client.registrationState } })
if (hook.type === 'IPXE') res.send(hook.script)
- else if (hook.type === 'BASH') res.sendFile(path.join(__appdir, 'ipxe', 'minilinux.ipxe'))
+ else if (hook.type === 'BASH') await sendFilePromise(res, path.join(__appdir, 'ipxe', 'minilinux.ipxe'))
return
}
@@ -26,11 +26,24 @@ noAuthRouter.getAsync('/:uuid', async (req, res) => {
var importantEvents = []
var groupIds = []
var result
+ var now = new Date()
for (let i = 0; i < client.events.length; i++) {
- if (client.events[i].important) importantEvents.push(client.events[i])
- if (client.events[i].client_x_event.blacklist) blacklist.push(client.events[i].id)
- else events.push(client.events[i])
+ let intime = true
+ let times = client.events[i].times
+
+ if (times.repetitive) {
+ let intervalBool = true
+ if (times.monthMap[now.getMonth()] && times.dayMap[((now.getDay() + 6) % 7)] && intervalBool) intime = true
+ } else {
+ if (times.start <= now.getTime() <= times.end) intime = true
+ }
+
+ if (intime) {
+ if (client.events[i].client_x_event.blacklist) blacklist.push(client.events[i].id)
+ else if (client.events[i].important) importantEvents.push(client.events[i])
+ else events.push(client.events[i])
+ } else continue
}
importantEvents = importantEvents.filter(e => !blacklist.includes(e.id))
@@ -115,10 +128,10 @@ noAuthRouter.getAsync('/:uuid', async (req, res) => {
}
}
// No config found, use default config
- res.sendFile(path.join(__appdir, 'ipxe', 'default.ipxe'))
+ await sendFilePromise(res, path.join(__appdir, 'ipxe', 'default.ipxe'))
} else {
// client not known, start registration
- res.sendFile(path.join(__appdir, 'ipxe', 'registration.ipxe'))
+ await sendFilePromise(res, path.join(__appdir, 'ipxe', 'registration.ipxe'))
}
})
@@ -149,8 +162,9 @@ async function fetchParentConfigs (groupIds, blacklist) {
parentIds.push(groups[i].parents[j].id)
}
for (let j = 0; j < groups[i].events.length; j++) {
- if (groups[i].events[j].important) importantEvents.push(groups[i].events[j])
+ // Execute these 3 Lines only if event is happening right now
if (groups[i].events[j].group_x_event.blacklist) newBlacklist.push(groups[i].events[j].id)
+ else if (groups[i].events[j].important) importantEvents.push(groups[i].events[j])
else events.push(groups[i].events[j])
}
}
@@ -250,4 +264,13 @@ function createDynamicMenu (ids) {
})
}
+function sendFilePromise (res, file) {
+ return new Promise((resolve, reject) => {
+ res.sendFile(file, {}, err => {
+ if (err) console.log(err)
+ resolve()
+ })
+ })
+}
+
module.exports.noAuthRouter = noAuthRouter