summaryrefslogtreecommitdiffstats
path: root/server/api/registrations.js
diff options
context:
space:
mode:
authorJannik Schönartz2018-08-29 21:11:47 +0200
committerJannik Schönartz2018-08-29 21:11:47 +0200
commita95d3a92646b447acdfd3cd13d2c028c41c2e132 (patch)
tree1cdd3a04fdb6c9b0aeaba2b95428691a867b31a6 /server/api/registrations.js
parent[registration] Add spaces and parent path to the manual registration (diff)
downloadbas-a95d3a92646b447acdfd3cd13d2c028c41c2e132.tar.gz
bas-a95d3a92646b447acdfd3cd13d2c028c41c2e132.tar.xz
bas-a95d3a92646b447acdfd3cd13d2c028c41c2e132.zip
[registration] Add parent tree view in the manual registration
Add parents as not clickable boot entry. Indent childs to get a tree view. Fix switch bug in the external-backends module. Add utf-8 to ascii escaping because ipxe can't use utf-8
Diffstat (limited to 'server/api/registrations.js')
-rw-r--r--server/api/registrations.js96
1 files changed, 71 insertions, 25 deletions
diff --git a/server/api/registrations.js b/server/api/registrations.js
index 2253be6..3368d0f 100644
--- a/server/api/registrations.js
+++ b/server/api/registrations.js
@@ -35,9 +35,7 @@ module.exports.router = router
noAuthRouter.post('/group', (req, res) => {
const id = req.body.id
var parents = []
- console.log(req.body.parents)
if (req.body.parents) parents = JSON.parse(req.body.parents)
- console.log(parents)
if (id === '0') {
db.group.findAll({ where: { '$parents.id$': null }, include: ['parents'] }).then(groups => {
if (groups) {
@@ -90,56 +88,104 @@ module.exports.noAuthRouter = noAuthRouter
* Used by the manual registration.
*/
function buildIpxeMenu (id, name, groups, parents) {
- console.log(parents)
var script = '#!ipxe\r\n'
// script = script.concat(`console --picture \${img} --x 800 --y 600 || shell\r\n`)
// Add parent to keep track of the path we clicked through.
- parents.push({ id: id, name: name })
- script = script.concat(`set space:hex 20:20\r\n`)
- script = script.concat(`set space \${space:string}\r\n`)
- script = script.concat(`set parents `, JSON.stringify(parents), '\r\n\r\n')
+
+ var parentId = 0
+ var oldParents = parents.slice(0)
+ if (parents.length > 0) {
+ parentId = oldParents[oldParents.length - 1].id
+ oldParents.length = oldParents.length - 1
+ }
+ parents.push({ id: id, name: toAscii(name) })
+ script += `set space:hex 20:20\r\n`
+ script += `set space \${space:string}\r\n`
+ script += `set parents ` + JSON.stringify(parents) + '\r\n\r\n'
// Menu
var menuscript = ''
- script = script.concat(':start\r\n')
- script = script.concat('menu Choose the group you want the client to be saved in\r\n')
+ script += ':start\r\n'
+ script += 'menu Choose the group you want the client to be saved in\r\n'
// Parent menu entries.
var spacer = ''
parents.forEach(parent => {
- script = script.concat('item --gap ', spacer, '[', parent.id, '] ', parent.name, '\r\n')
- spacer = spacer.concat(`\${space}`)
+ script += 'item --gap ' + spacer + '[' + parent.id + '] ' + parent.name + '\r\n'
+ spacer += `\${space}`
})
+ // Back button
+ script += 'item --key b back ' + spacer + '..\r\n'
+ menuscript += ':back\r\nparams\r\nparam id ' + parentId + '\r\nparam parents ' + JSON.stringify(oldParents) + '\r\n'
+ menuscript += 'chain --replace https://bas.stfu-kthx.net:8888/api/registrations/group##params\r\n\r\n'
+
// Group menu entries. First 1-9 are pressable via key?
var counter = '1'
groups.forEach(group => {
- // script = script.concat('echo', ' [', subgroup.id, '] ', subgroup.name, '\r\n')
- script = script.concat('item --key ', counter, ' ', counter, ' ', spacer, '[', group.id, '] ', group.name, '\r\n')
- menuscript = menuscript.concat(':', counter, '\r\n', 'params\r\nparam id ', group.id, `\r\nparam parents \${parents}`)
- menuscript = menuscript.concat('\r\nchain https://bas.stfu-kthx.net:8888/api/registrations/group##params\r\n\r\n')
+ script += 'item --key ' + counter + ' ' + counter + ' ' + spacer + '[' + group.id + '] ' + toAscii(group.name) + '\r\n'
+ menuscript += ':' + counter + '\r\n' + 'params\r\nparam id ' + group.id + `\r\nparam parents \${parents}\r\n`
+ menuscript += 'chain --replace https://bas.stfu-kthx.net:8888/api/registrations/group##params\r\n\r\n'
counter++
})
+ // Menu seperator
+ script += 'item --gap\r\n'
+
// Add client menu
- script = script.concat('item select Add client to ', name, '\r\n')
- menuscript = menuscript.concat(`:select\r\necho Enter client name\r\nread clientname\r\nparams\r\nparam name \${clientname}\r\n`)
- menuscript = menuscript.concat('param id ', id, `\r\nparam mac \${net0/mac}\r\nparam uuid \${uuid}\r\nparam ip \${net0/ip}\r\n`)
- menuscript = menuscript.concat('chain https://bas.stfu-kthx.net:8888/api/registrations/add##params\r\n\r\n')
+ script += 'item select Add client to ' + toAscii(name) + '\r\n'
+ menuscript += `:select\r\necho Enter client name\r\nread clientname\r\nparams\r\nparam name \${clientname}\r\n`
+ menuscript += 'param id ' + id + `\r\nparam mac \${net0/mac}\r\nparam uuid \${uuid}\r\nparam ip \${net0/ip}\r\n`
+ menuscript += 'chain --replace https://bas.stfu-kthx.net:8888/api/registrations/add##params\r\n\r\n'
// Goto start menu
if (id !== '0') {
- script = script.concat('item reset Go to start\r\n')
- menuscript = menuscript.concat(':reset\r\nparams\r\nparam id ', 0, '\r\nchain https://bas.stfu-kthx.net:8888/api/registrations/group##params\r\n\r\n')
+ script += 'item reset Go to start\r\n'
+ menuscript += ':reset\r\nparams\r\nparam id ' + 0 + '\r\nchain --replace https://bas.stfu-kthx.net:8888/api/registrations/group##params\r\n\r\n'
}
// Exit menu
- script = script.concat('item exit Exit manual registration\r\n')
- menuscript = menuscript.concat(':exit\r\nexit 1\r\n\r\n')
+ script += 'item exit Exit manual registration\r\n'
+ menuscript += ':exit\r\nexit 1\r\n\r\n'
// Concat script + menuscript and return it.
- script = script.concat(`choose target && goto \${target}\r\n\r\n`)
- script = script.concat(menuscript)
+ script += `choose target && goto \${target}\r\n\r\n`
+ script += menuscript
return script
}
+
+function toAscii (string) {
+ string = string.replace('ü', 'ue')
+ string = string.replace('ö', 'oe')
+ string = string.replace('ä', 'ae')
+ return ascii(string)
+}
+
+/* eslint-disable */
+var escapable = /[\\"\x00-\x1f\x7f-\uffff]/g
+/* eslint-enable */
+var meta = { // table of character substitutions
+ '\b': '\\b',
+ '\t': '\\t',
+ '\n': '\\n',
+ '\f': '\\f',
+ '\r': '\\r',
+ '"': '\\"',
+ '\\': '\\\\'
+}
+
+function ascii (string) {
+// If the string contains no control characters, no quote characters, and no
+// backslash characters, then we can safely slap some quotes around it.
+// Otherwise we must also replace the offending characters with safe escape
+// sequences.
+
+ escapable.lastIndex = 0
+ return escapable.test(string)
+ ? string.replace(escapable, function (a) {
+ var c = meta[a]
+ return typeof c === 'string' ? c
+ : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4)
+ }) : string
+}