summaryrefslogtreecommitdiffstats
path: root/server/api/registration.js
diff options
context:
space:
mode:
authorJannik Schönartz2019-04-16 22:12:21 +0200
committerJannik Schönartz2019-04-16 22:12:21 +0200
commita9e7898e1cbcd35939ec623fc283cd69297738b6 (patch)
tree7b480e5ea3534d786ca9cfc109ed9407fb7f3b15 /server/api/registration.js
parent[ipxe] Wallpaper and minilinux: tftp -> https (diff)
downloadbas-a9e7898e1cbcd35939ec623fc283cd69297738b6.tar.gz
bas-a9e7898e1cbcd35939ec623fc283cd69297738b6.tar.xz
bas-a9e7898e1cbcd35939ec623fc283cd69297738b6.zip
[registration] Fix dhcp mapping when adding a client & better overview ipxe menu
Diffstat (limited to 'server/api/registration.js')
-rw-r--r--server/api/registration.js24
1 files changed, 18 insertions, 6 deletions
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'