summaryrefslogtreecommitdiffstats
path: root/server/api
diff options
context:
space:
mode:
authorJannik Schönartz2019-04-14 04:46:53 +0200
committerJannik Schönartz2019-04-14 04:46:53 +0200
commitf0808189575e7024d0ad100dfb71b18810ec79de (patch)
tree723346534123ff462c4d5d1bbdf5f25546adc6b5 /server/api
parenteslint fixes (diff)
downloadbas-f0808189575e7024d0ad100dfb71b18810ec79de.tar.gz
bas-f0808189575e7024d0ad100dfb71b18810ec79de.tar.xz
bas-f0808189575e7024d0ad100dfb71b18810ec79de.zip
[server/external-backends] Add delete method for the infoblox backend & add infoblox client mappings method
Diffstat (limited to 'server/api')
-rw-r--r--server/api/backends.js21
-rw-r--r--server/api/registration.js10
2 files changed, 29 insertions, 2 deletions
diff --git a/server/api/backends.js b/server/api/backends.js
index e92999a..f3de01f 100644
--- a/server/api/backends.js
+++ b/server/api/backends.js
@@ -301,6 +301,27 @@ router.get('/:id/import', (req, res) => {
})
})
+/*
+ * Adds the client mapping from the backend to the client with the same mac address.
+ */
+router.getAsync('/:id/mapping', async (req, res) => {
+ const id = req.params.id
+ const backend = await db.backend.findOne({ where: { id: id } })
+
+ if (backend) {
+ const b = new ExternalBackends()
+ const instance = b.getInstance(backend.type)
+ const objects = await instance.getObjects(backend.credentials)
+
+ for (let index in objects) {
+ const object = objects[index]
+ const client = await db.client.findOne({ where: { mac: object.mac } })
+ await backend.addMappedClients(client, { through: { externalId: object.id } })
+ }
+ return res.status(200).send()
+ } else return res.status(500).send()
+})
+
// No auth router for now but those client based methods should better be in the clients api.
// TODO: Move to clients?
// TODO: receive files should be authenticated!
diff --git a/server/api/registration.js b/server/api/registration.js
index 5638747..4ab7cbc 100644
--- a/server/api/registration.js
+++ b/server/api/registration.js
@@ -135,17 +135,19 @@ noAuthRouter.postAsync('/clients', async (req, res) => {
// If there is no ip, we don't need DHCP checks.
// Only the first ip address is checked! client.networks[0]
+ let dhcp = false
if (client.networks.length >= 1) {
const network = client.networks[0]
// Get the dhcp backend. Only one dhcp backend can exist else -> conflict.
- const dhcp = await backendHelper.getDhcp()
+ dhcp = await backendHelper.getDhcp()
let ipSelection = false
- let setIpError = undefined
+ let setIpError
if (dhcp) {
if (automatic) {
// Set the name of the client if it's not set
if (!client.name) client.name = client.type + '_' + client.uuid
const setIp = await dhcp.instance.setIp(dhcp.backend.credentials, network.ip, network.mac, undefined, true)
+ dhcp.ref = setIp.ref
// Check for errors.
if (!setIp.error) {
// Client ip set successfully
@@ -157,6 +159,7 @@ noAuthRouter.postAsync('/clients', async (req, res) => {
// If networks.dhcp is set the user already choose the ip and we have to set it now.
if (!client.name) return res.send(buildNameClientIpxeMenu(client))
const setIp = await dhcp.instance.setIp(dhcp.backend.credentials, network.dhcp, network.mac, client.name)
+ dhcp.ref = setIp.ref
// Check for errors.
if (setIp.error) {
// Setting the client ip failed
@@ -190,6 +193,9 @@ noAuthRouter.postAsync('/clients', async (req, res) => {
const newClient = await db.client.create(createClient)
client.id = newClient.id
+ // Add dhcp backend mapping
+ if (dhcp) dhcp.backend.addMappedClients(newClient, { through: { externalId: dhcp.ref } })
+
// Add groups to the client.
if (client.parents.length === 0) client.parents = await ipHelper.getGroups(client.networks[0].ip)
client.parents.forEach(pid => { newClient.addGroup(pid) })