From a9e7898e1cbcd35939ec623fc283cd69297738b6 Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Tue, 16 Apr 2019 22:12:21 +0200 Subject: [registration] Fix dhcp mapping when adding a client & better overview ipxe menu --- server/api/registration.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'server/api/registration.js') diff --git a/server/api/registration.js b/server/api/registration.js index f588ea1..4d2bda1 100644 --- a/server/api/registration.js +++ b/server/api/registration.js @@ -112,7 +112,6 @@ noAuthRouter.post('/group', (req, res) => { noAuthRouter.postAsync('/clients', async (req, res) => { let client = req.body.client if (typeof client === 'string') client = JSON.parse(client) - let ipxe = req.body.ipxe if (typeof ipxe === 'string' && ipxe === 'true') ipxe = true let automatic = req.body.automatic @@ -161,8 +160,9 @@ 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)) if (confirmation) return res.send(buildOverviewIpxeMenu(client)) + const setIp = await dhcp.instance.setIp(dhcp.backend.credentials, network.dhcp, network.mac, client.name) - dhcp.ref = setIp.ref + dhcp.ref = setIp.id // Check for errors. if (setIp.error) { // Setting the client ip failed @@ -187,7 +187,7 @@ noAuthRouter.postAsync('/clients', async (req, res) => { else if (!ipxe && ipCheck.leased && !ipCheck.error) return res.send({ client: client, ipList: ipCheck.nextIps }) // Set the hostname as clientname if it exists and is not a leased ip. - if (!ipCheck.leased) { + if (!ipCheck.leased && ipCheck.name !== '') { if (ipCheck.name) client.name = ipCheck.name if (ipCheck.id) dhcp.ref = ipCheck.id } @@ -471,18 +471,30 @@ function buildOverviewIpxeMenu (client) { const basUrl = 'https://' + url const c = JSON.stringify(client) let script = '#!ipxe\r\n' - script += ':start' + script += ':start\r\n' script += 'menu Overview Register Client\r\n' script += 'item --gap Name: ' + client.name + '\r\n' + delete client.name + if (client.networks[0].dhcp) { + script += 'item --gap New IP: ' + client.networks[0].dhcp + '\r\n' + delete client.networks[0].dhcp + } + + script += 'item --gap\r\n' + script += 'item --gap Current IP: ' + client.networks[0].ip + '\r\n' + script += 'item --gap MAC: ' + client.networks[0].mac + '\r\n' script += 'item --gap UUID: ' + client.uuid + '\r\n' - for (let index in client.networks) { + for (let index = 1; index < client.networks.length; index++) { + // Only handle the networks with index >= 1 const network = client.networks[index] script += 'item --gap\r\n' - script += 'item --gap IP: ' + network.ip + '\r\n' + script += 'item --gap Current IP: ' + network.ip + '\r\n' + if (network.dhcp) script += 'item --gap New IP: ' + network.dhcp + '\r\n' script += 'item --gap MAC: ' + network.mac + '\r\n' if (network.dhcp) delete network.dhcp } + script += 'item --gap\r\n' script += 'item default\r\n' script += 'item --key y confirm Confirm [y]es\r\n' -- cgit v1.2.3-55-g7522