summaryrefslogtreecommitdiffstats
path: root/server/api/registrations.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/api/registrations.js')
-rw-r--r--server/api/registrations.js72
1 files changed, 54 insertions, 18 deletions
diff --git a/server/api/registrations.js b/server/api/registrations.js
index 74e7d84..4eaff6d 100644
--- a/server/api/registrations.js
+++ b/server/api/registrations.js
@@ -4,7 +4,7 @@ var express = require('express')
var router = express.Router()
var noAuthRouter = express.Router()
var db = require(path.join(__appdir, 'lib', 'sequelize'))
-// const ExternalBackends = require(path.join(__appdir, 'lib', 'external-backends'))
+const ExternalBackends = require(path.join(__appdir, 'lib', 'external-backends'))
const backendHelper = require(path.join(__appdir, 'lib', 'external-backends', 'backendhelper'))
// GET requests.
@@ -13,9 +13,10 @@ const backendHelper = require(path.join(__appdir, 'lib', 'external-backends', 'b
* TODO: CURRENTLY TEST FUNCTION
*/
noAuthRouter.get('/', (req, res) => {
- backendHelper.deleteClients().then(r => {
- res.send(r)
- })
+ //backendHelper.deleteClients().then(r => {
+ // res.send(r)
+ //})
+
/*
db.backend.findOne({ where: { id: 1 } }).then(result => {
const b = new ExternalBackends()
@@ -24,6 +25,13 @@ noAuthRouter.get('/', (req, res) => {
res.status(200).send(result)
})
}) */
+ db.backend.findOne({ where: { id: 3 } }).then(result => {
+ const b = new ExternalBackends()
+ const instance = b.getInstance(result.type)
+ instance.uploadTpm(result.credentials, 99696, 'I-123-d12', null).then(result => {
+ res.status(200).send(result)
+ })
+ })
})
/*
@@ -123,6 +131,7 @@ noAuthRouter.post('/group', (req, res) => {
* Adds the client to the database and set parents if a parent was selected. Calls addClient for all external-backends.
*/
noAuthRouter.post('/add', (req, res) => {
+ const feedback = req.body.feedback
const mac = req.body.mac
const uuid = req.body.uuid
const ip = req.body.ip
@@ -134,45 +143,72 @@ noAuthRouter.post('/add', (req, res) => {
var groupids = []
if (parentId) groupids = [parentId]
getNextHookScript(groupids).then(resId => {
- db.client.create({ name: name, ip: ip, mac: mac, uuid: uuid, registrationState: resId }).then(newClient => {
+ db.client.create({ name: name, description: 'Client', ip: ip, mac: mac, uuid: uuid, registrationState: resId }).then(newClient => {
if (parentId) {
newClient.addGroup(parentId)
}
// Add the client to the backends.
- const c = { network: { mac: mac, ip: ip } }
+ const c = { uuid: uuid, network: { mac: mac, ip: ip } }
if (parentId) c.parentId = parentId
if (name) c.title = name
else c.title = 'Client_' + uuid
backendHelper.addClient(c).then(result => {
+ if (feedback) res.send(result)
result.forEach(response => {
// If the object was created we need to make the objectid / external id mapping.
- if (response.success && response.create) {
+ if (response.success) {
db.backend.findOne({ where: { id: response.backendId }, include: ['mappedClients'] }).then(backend => {
backend.addMappedClients(newClient, { through: { externalId: response.id, externalType: response.type } })
})
}
})
})
- res.send(`#!ipxe\nchain https://bas.intra.uni-freiburg.de/api/configloader/\${uuid}`)
+ if (!feedback) res.send(`#!ipxe\nchain https://bas.intra.uni-freiburg.de/api/configloader/\${uuid}`)
})
})
}
})
})
+noAuthRouter.post('/update', (req, res) => {
+ const uuid = req.body.uuid
+ const name = req.body.name
+ const parentId = req.body.id
+ const sys_manufacturer = req.body.sys_manufacturer
+ const sys_model = req.body.sys_model
+ const sys_serial = req.body.sys_serial
+ const cpu_model = req.body.cpu_model
+ const cpu_manufacturer = req.body.cpu_manufacturer
+ const cpu_type = req.body.cpu_type
+ const cpu_frequency = req.body.cpu_frequency
+ const cpu_cores = req.body.cpu_cores
+ const ram_model = req.body.ram_model
+ const ram_manufacturer = req.body.ram_manufacturer
+ const ram_capacity = req.body.ram_capacity
+ const ram_unit = req.body.ram_unit
+
+ db.client.findOne({ where: { uuid: uuid } }).then(client => {
+ client.update({ name: name })
+ const c = { uuid: uuid, id: client.id }
+ if (name) c.title = name
+ if (parentId) c.parentId = parentId
+ if (sys_manufacturer && sys_model && sys_serial) c.system = { model: sys_model, manufacturer: sys_manufacturer, serialnumber: sys_serial}
+ if (cpu_model && cpu_manufacturer && cpu_type && cpu_frequency && cpu_cores) c.cpu = { model: cpu_model, manufacturer: cpu_manufacturer, type: cpu_type, frequency: cpu_frequency, cores: cpu_cores }
+ if (ram_model && ram_manufacturer && ram_capacity && ram_unit) c.ram = [{ model: ram_model, manufacturer: ram_manufacturer, capacity: ram_capacity, unit: ram_unit }]
+
+ backendHelper.updateClient(c).then(result => {
+ res.send(result)
+ })
+ })
+})
+
/*
- * Adds additional information for the backends of the client in the firstregistration.
+ * Mehtod for uploading the tpm key and stuff.
*/
-noAuthRouter.post('/addInfo', (req, res) => {
- const id = req.body.id
- const systemModel = req.body.sysmodel
- const systemManufacturer = req.body.sysmanu
- const systemSerial = req.body.sysserial
-
- // Add the client to the backends.
- backendHelper.addClient({ id: id, system: { model: systemModel, manufacturer: systemManufacturer, serialnumber: systemSerial } })
- res.send({ status: 'success' })
+noAuthRouter.put('/:uuid/tpm', (req, res) => {
+ console.log(req.files)
+ res.send()
})
/*