summaryrefslogtreecommitdiffstats
path: root/server/api/registration.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/api/registration.js')
-rw-r--r--server/api/registration.js141
1 files changed, 68 insertions, 73 deletions
diff --git a/server/api/registration.js b/server/api/registration.js
index 2a26c4f..3eb36e0 100644
--- a/server/api/registration.js
+++ b/server/api/registration.js
@@ -114,7 +114,7 @@ noAuthRouter.postAsync('/add', async (req, res) => {
const uuid = req.body.uuid
const ip = req.body.ip
var name = req.body.name
- const parentId = req.body.id
+ const parentId = parseInt(req.body.id)
const purpose = req.body.purpose
let parentIds = []
@@ -139,24 +139,15 @@ noAuthRouter.postAsync('/add', async (req, res) => {
}
// Add the client to the backends.
- var c = { title: name, uuid: uuid, network: { mac: mac, ip: ip } }
+ var c = { id: newClient.id, title: name, uuid: uuid, network: { mac: mac, ip: ip } }
if (parentIds.length > 0) c.parents = parentIds
- // if (parentId) c.parentId = parentId
if (purpose) c.purpose = purpose
const result = await backendHelper.addClient(c)
if (feedback) res.send(result)
-
- for (let response of result) {
- // If the object was created we need to make the objectid / external id mapping.
- if (response.success) {
- const backend = await db.backend.findOne({ where: { id: response.backendId }, include: ['mappedClients'] })
- backend.addMappedClients(newClient, { through: { externalId: response.id, externalType: response.type } })
- }
- }
- if (!feedback) res.send(`#!ipxe\nchain https://` + url + `/api/configloader/\${uuid}`)
+ else res.send(`#!ipxe\nchain https://` + url + `/api/configloader/\${uuid}`)
})
-noAuthRouter.post('/:uuid/update', (req, res) => {
+noAuthRouter.postAsync('/:uuid/update', async (req, res) => {
const uuid = req.params.uuid
const name = req.body.name
const parentId = req.body.id
@@ -174,85 +165,89 @@ noAuthRouter.post('/:uuid/update', (req, res) => {
const cpuCores = req.body.cpu_cores
// RAM
- var ramSize = req.body.ram_size.split('\n')
- var ramManufacturer = req.body.ram_manufacturer.split('\n')
- var ramFormfactor = req.body.ram_formfactor.split('\n')
- var ramType = req.body.ram_type.split('\n')
- var ramIsEcc = req.body.ram_isecc.replace('Error Correction Type: ', '')
- var ramModules = []
- // Build ram array
- for (var ram in ramSize) {
- if (ramSize[ram].replace('Size: ', '') !== 'No Module Installed') {
- const size = ramSize[ram].replace('Size: ', '').split(' ')
- var title = ramFormfactor[ram].replace('Form Factor: ', '')
- if (ramIsEcc === 'Single-bit ECC') title += '-ECC'
-
- var ramModule = {
- capacity: size[0],
- unit: size[1],
- manufacturer: ramManufacturer[ram].replace('Manufacturer: ', ''),
- title: title,
- type: ramType[ram].replace('Type: ', '')
+ if (req.body.ram_size) {
+ const ramSize = req.body.ram_size.split('\n')
+ const ramManufacturer = req.body.ram_manufacturer.split('\n')
+ const ramFormfactor = req.body.ram_formfactor.split('\n')
+ const ramType = req.body.ram_type.split('\n')
+ const ramIsEcc = req.body.ram_isecc.replace('Error Correction Type: ', '')
+ var ramModules = []
+
+ // Build ram array
+ for (let ram in ramSize) {
+ if (ramSize[ram].replace('Size: ', '') !== 'No Module Installed') {
+ const size = ramSize[ram].replace('Size: ', '').split(' ')
+ let title = ramFormfactor[ram].replace('Form Factor: ', '')
+ if (ramIsEcc === 'Single-bit ECC') title += '-ECC'
+
+ const ramModule = {
+ capacity: size[0],
+ unit: size[1],
+ manufacturer: ramManufacturer[ram].replace('Manufacturer: ', ''),
+ title: title,
+ type: ramType[ram].replace('Type: ', '')
+ }
+ ramModules.push(ramModule)
}
- ramModules.push(ramModule)
}
}
// SSD / HDD
- var drivesRaw = req.body.drives.split('%OBJECT_SPLITTER%')
- var drives = []
- for (var driveRaw in drivesRaw) {
- if (drivesRaw[driveRaw].length > 0) {
- var dRaw = drivesRaw[driveRaw].split('%ATTRIBUTE_SPLITTER%')
- var drive = {
- model: dRaw[0].trim().replace('Device Model: ', ''),
- serial: dRaw[1].trim().replace('Serial Number: ', ''),
- capacity: dRaw[2].trim().split(' ')[0],
- unit: dRaw[2].trim().split(' ')[1],
- type: dRaw[3].trim().replace('Rotation Rate: ', ''),
- formfactor: dRaw[4].trim().replace('Form Factor: ', ''),
- connection: dRaw[5].trim().replace('SATA Version is: ', '')
+ if (req.body.drives) {
+ const drivesRaw = req.body.drives.split('%OBJECT_SPLITTER%')
+ var drives = []
+ for (let driveRaw in drivesRaw) {
+ if (drivesRaw[driveRaw].length > 0) {
+ const dRaw = drivesRaw[driveRaw].split('%ATTRIBUTE_SPLITTER%')
+ const drive = {
+ model: dRaw[0].trim().replace('Device Model: ', ''),
+ serial: dRaw[1].trim().replace('Serial Number: ', ''),
+ capacity: dRaw[2].trim().split(' ')[0],
+ unit: dRaw[2].trim().split(' ')[1],
+ type: dRaw[3].trim().replace('Rotation Rate: ', ''),
+ formfactor: dRaw[4].trim().replace('Form Factor: ', ''),
+ connection: dRaw[5].trim().replace('SATA Version is: ', '')
+ }
+ drives.push(drive)
}
- drives.push(drive)
}
}
- db.client.findOne({ where: { uuid: uuid } }).then(client => {
- client.update({ name: name })
- var c = { uuid: uuid, id: client.id }
- if (name) c.title = name
- if (parentId) c.parentId = parentId
+ const client = await db.client.findOne({ where: { uuid: uuid } })
+ if (!client) return res.status(404).send({ error: 'CLIENT_NOT_FOUND', message: 'There is no client matching the provided uuid.' })
- // System data. Sometime just string with whitespaces only.
- c.system = {}
- if (/\S/.test(sysManufacturer)) c.system.manufacturer = sysManufacturer
- else c.system.manufacturer = 'Not set'
+ client.update({ name: name })
+ var c = { uuid: uuid, id: client.id }
+ if (name) c.title = name
+ if (parentId) c.parentId = parentId
- if (/\S/.test(sysModel)) c.system.model = sysModel
- else c.system.model = 'Not set'
+ // System data. Sometime just string with whitespaces only.
+ c.system = {}
+ if (/\S/.test(sysManufacturer)) c.system.manufacturer = sysManufacturer
+ else c.system.manufacturer = 'Not set'
- if (/\S/.test(sysSerial)) c.system.serialnumber = sysSerial
- else c.system.serialnumber = 'Not set'
+ if (/\S/.test(sysModel)) c.system.model = sysModel
+ else c.system.model = 'Not set'
- // TODO: MULTI GPU's ?!
- c.cpu = { model: cpuModel, manufacturer: cpuManufacturer, type: cpuType, frequency: cpuFrequency, cores: cpuCores }
- c.ram = ramModules
- c.drives = drives
+ if (/\S/.test(sysSerial)) c.system.serialnumber = sysSerial
+ else c.system.serialnumber = 'Not set'
- backendHelper.updateClient(c).then(result => {
- res.send(result)
- })
- })
+ // TODO: MULTI GPU's ?!
+ c.cpu = { model: cpuModel, manufacturer: cpuManufacturer, type: cpuType, frequency: cpuFrequency, cores: cpuCores }
+ if (ramModules) c.ram = ramModules
+ if (drives) c.drives = drives
+
+ const result = await backendHelper.updateClient(c)
+ res.send(result)
})
/*
* Mehtod for uploading the tpm key and stuff.
*/
-noAuthRouter.put('/:uuid/files', (req, res) => {
- db.client.findOne({ where: { uuid: req.params.uuid } }).then(client => {
- backendHelper.uploadFiles(client.id, req.files)
- res.send()
- })
+noAuthRouter.putAsync('/:uuid/files', async (req, res) => {
+ const client = await db.client.findOne({ where: { uuid: req.params.uuid } })
+ const result = await backendHelper.uploadFiles(client.id, req.files)
+ res.send(result)
})
/*