From 9f057b6941fa77d8021ec99230689941c77193b3 Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Mon, 28 Oct 2019 17:21:30 +0000 Subject: [server/configloader] Add a better (dynamic) default config, delete the old default config & eslint fix --- server/lib/confighelper.js | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) (limited to 'server/lib/confighelper.js') 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 } -- cgit v1.2.3-55-g7522