summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--server/api/configloader.js7
-rw-r--r--server/api/registration.js2
-rw-r--r--server/ipxe/default.ipxe31
-rw-r--r--server/lib/confighelper.js41
4 files changed, 36 insertions, 45 deletions
diff --git a/server/api/configloader.js b/server/api/configloader.js
index f6c4597..ba395d0 100644
--- a/server/api/configloader.js
+++ b/server/api/configloader.js
@@ -8,8 +8,6 @@ const config = require(path.join(__appdir, 'config', 'config'))
const url = config.https.host + ':' + config.https.port
const configHelper = require(path.join(__appdir, 'lib', 'confighelper'))
-
-
noAuthRouter.getAsync(['/test/group/:id', '/test/group/'], async (req, res) => {
const list = req.query.list !== undefined && req.query.list !== 'false'
const config = await configHelper.getGroupConfig(req.params.id, list)
@@ -22,7 +20,6 @@ noAuthRouter.getAsync(['/test/group/:id', '/test/group/'], async (req, res) => {
}
})
-
noAuthRouter.getAsync(['/test/:uuid', '/test/'], async (req, res) => {
const list = req.query.list !== undefined && req.query.list !== 'false'
const config = await configHelper.getConfig(req.params.uuid, list)
@@ -34,7 +31,6 @@ noAuthRouter.getAsync(['/test/:uuid', '/test/'], async (req, res) => {
}
})
-
// if client in db -> load script (default if none is found), else load registration script
noAuthRouter.getAsync('/:uuid', async (req, res) => {
const uuid = req.params.uuid
@@ -128,7 +124,8 @@ noAuthRouter.getAsync('/:uuid', async (req, res) => {
if (client.configId !== null) return res.send(await createIpxeScript(client.configId))
}
// No config found, use default config
- await sendFilePromise(res, path.join(__appdir, 'ipxe', 'default.ipxe'))
+ // await sendFilePromise(res, path.join(__appdir, 'ipxe', 'default.ipxe'))
+ res.send(await configHelper.getDefaultConfig(client))
})
// load config by given id
diff --git a/server/api/registration.js b/server/api/registration.js
index 9064846..156ec21 100644
--- a/server/api/registration.js
+++ b/server/api/registration.js
@@ -232,7 +232,7 @@ noAuthRouter.postAsync('/clients', async (req, res) => {
// Add the client to the backends.
const result = backendHelper.addClient(client)
if (ipxe) return res.send(`#!ipxe\nsleep 5\nchain https://` + url + `/api/configloader/\${uuid}`)
- else return res.send(result)
+ else return res.send(await result)
})
noAuthRouter.postAsync('/clients/:uuid', async (req, res) => {
diff --git a/server/ipxe/default.ipxe b/server/ipxe/default.ipxe
deleted file mode 100644
index 8ed6c1f..0000000
--- a/server/ipxe/default.ipxe
+++ /dev/null
@@ -1,31 +0,0 @@
-#!ipxe
-
-:start
-menu Default Script:
-item bwlehrpool bwLehrpool
-item bwlehrpool_efi bwLehrpool_efi
-item bwlehrpool_tpm bwLehrpool_tpm
-item --key r registration Registration
-item --key s sh [Shell]
-choose --default automatic --timeout 25000 target && goto ${target}
-
-:bwlehrpool
-#chain --replace http://132.230.4.2/tftp/ipxelinux.0
-chain --replace http://132.230.4.2/boot/ipxe
-
-:bwlehrpool_efi
-#chain --replace http://132.230.8.192/tftp/snponly.efi || shell
-chain --replace http://132.230.8.197/tftp/snponly.efi || shell
-
-:bwlehrpool_tpm
-kernel http://132.230.4.6/tbk/kernel-neu.sb.efi
-boot
-
-:registration
-set crosscert http://ca.ipxe.org/auto/
-chain --replace https://bas.intra.uni-freiburg.de/api/ipxe/load/registration ||
-goto start
-
-:sh
-shell ||
-goto start
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 }