summaryrefslogtreecommitdiffstats
path: root/server/lib/confighelper.js
diff options
context:
space:
mode:
authorJannik Schönartz2019-10-28 18:21:30 +0100
committerJannik Schönartz2019-10-28 18:21:30 +0100
commit9f057b6941fa77d8021ec99230689941c77193b3 (patch)
treee0c7c628d1c28a5cfae38e50df0cff7882e11af2 /server/lib/confighelper.js
parent[groups] Add first implementation of the new config path ui (diff)
downloadbas-9f057b6941fa77d8021ec99230689941c77193b3.tar.gz
bas-9f057b6941fa77d8021ec99230689941c77193b3.tar.xz
bas-9f057b6941fa77d8021ec99230689941c77193b3.zip
[server/configloader] Add a better (dynamic) default config, delete the old default config & eslint fix
Diffstat (limited to 'server/lib/confighelper.js')
-rw-r--r--server/lib/confighelper.js41
1 files changed, 33 insertions, 8 deletions
diff --git a/server/lib/confighelper.js b/server/lib/confighelper.js
index 0e152a8..5843725 100644
--- a/server/lib/confighelper.js
+++ b/server/lib/confighelper.js
@@ -6,7 +6,6 @@ const eventHelper = require(path.join(__appdir, 'lib', 'eventhelper'))
const config = require(path.join(__appdir, 'config', 'config'))
const url = config.https.host + ':' + config.https.port
-
async function getConfig (uuid, list) {
const client = await db.client.findOne({ where: { uuid: uuid } })
let configPath = []
@@ -60,7 +59,6 @@ async function getConfig (uuid, list) {
return configPath
}
-
async function getGroupConfig (groupId, list) {
const group = await db.group.findOne({ where: { id: groupId } })
if (!group) return
@@ -88,7 +86,6 @@ async function getGroupConfig (groupId, list) {
return configPath
}
-
async function _checkParentConfigs (ids, importantList, eventList, configList, breakOnImportant, blackList = []) {
let events = []
let configs = []
@@ -112,8 +109,8 @@ async function _checkParentConfigs (ids, importantList, eventList, configList, b
let eventTimes = JSON.parse(event.times)
if (!eventHelper.isActive(eventTimes)) return
- if ((event.groups && event.groups.some(group => group.group_x_event.blacklist))
- || (event.clients && event.clients.length && event.clients[0].client_x_event.blacklist)) {
+ if ((event.groups && event.groups.some(group => group.group_x_event.blacklist)) ||
+ (event.clients && event.clients.length && event.clients[0].client_x_event.blacklist)) {
return blackList.push(event.id)
}
@@ -154,7 +151,6 @@ async function _checkParentConfigs (ids, importantList, eventList, configList, b
if (parents.length) await _checkParentConfigs(parents.map(x => x.id), importantList, eventList, configList, breakOnImportant, blackList)
}
-
// create the config script from database
async function _prepareConfig (configInfo, noScript) {
let id = configInfo.id
@@ -205,7 +201,6 @@ async function _prepareConfig (configInfo, noScript) {
return result
}
-
// create dynamic menu to load the different given configs for a client
async function _createDynamicMenu (configInfos, noScript) {
const ids = []
@@ -254,5 +249,35 @@ async function _createDynamicMenu (configInfos, noScript) {
return result
}
+// Creates a default overview config, when there is no default config in the frontend.
+async function getDefaultConfig (client) {
+ let script = '#!ipxe\r\n\r\n'
+ script += ':start\r\n'
+ script += 'menu ' + 'Client is successfully registrated' + '\r\n'
+ script += 'item --gap BAS-ID: ' + client.id + '\r\n'
+ script += 'item --gap Name: ' + client.name + '\r\n'
+ script += 'item --gap\r\n'
+ script += 'item --gap IP: ' + client.ip + '\r\n'
+ script += 'item --gap MAC: ' + client.mac + '\r\n'
+ script += 'item --gap UUID: ' + client.uuid + '\r\n'
+ script += 'item --gap\r\n'
+ script += 'item --gap\r\n'
+ script += 'item --gap ' + 'No config is set for the client or any of its parents!' + '\r\n'
+ script += 'item --gap ' + 'Please assign a config to the client or a parent first! (e.g. in the frontend)' + '\r\n'
+ script += 'item --gap\r\n'
+ script += 'item ' + 'poweroff Power Off' + '\r\n'
+ script += 'item ' + 'reboot Reboot' + '\r\n'
+ script += `choose --default poweroff --timeout 25000 target && goto \${target}\r\n\r\n`
+
+ script += '\r\n'
+ script += ':poweroff\r\n'
+ script += 'poweroff\r\n'
+ script += '\r\n'
+ script += ':reboot\r\n'
+ script += 'reboot\r\n'
+ script += '\r\n'
+
+ return script
+}
-module.exports = { getConfig, getGroupConfig } \ No newline at end of file
+module.exports = { getConfig, getGroupConfig, getDefaultConfig }