summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJannik Schönartz2019-04-14 05:41:48 +0200
committerJannik Schönartz2019-04-14 05:41:48 +0200
commit9c7488e58053294bbc69fb12addd083d7c7ffbfa (patch)
treece682390e649cfd31f58c44968c3d21af22fe27f /server
parent[webapp/groups] fix tabslider incorrect length when tab name changes (diff)
downloadbas-9c7488e58053294bbc69fb12addd083d7c7ffbfa.tar.gz
bas-9c7488e58053294bbc69fb12addd083d7c7ffbfa.tar.xz
bas-9c7488e58053294bbc69fb12addd083d7c7ffbfa.zip
[server/registration] Set hostname as client name for clients with a fixed ip
Diffstat (limited to 'server')
-rw-r--r--server/api/registration.js8
-rw-r--r--server/lib/external-backends/backends/infoblox-backend.js9
2 files changed, 12 insertions, 5 deletions
diff --git a/server/api/registration.js b/server/api/registration.js
index 4ab7cbc..ff0652b 100644
--- a/server/api/registration.js
+++ b/server/api/registration.js
@@ -178,9 +178,13 @@ noAuthRouter.postAsync('/clients', async (req, res) => {
if (ipSelection) {
// If not check if the client has a leased ipv4 address.
const ipCheck = await dhcp.instance.checkIp(dhcp.backend.credentials, network.ip)
+
// Build ipxe and return
- if (ipxe && ipCheck && !ipCheck.error) return res.send(buildSelectIpIpxeMenu(client, ipCheck, setIpError))
- else if (!ipxe && ipCheck && !ipCheck.error) return res.send({ client: client, ipList: ipCheck })
+ if (ipxe && ipCheck.leased && !ipCheck.error) return res.send(buildSelectIpIpxeMenu(client, ipCheck.nextIps, setIpError))
+ 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 && ipCheck.name) client.name = ipCheck.name
}
}
}
diff --git a/server/lib/external-backends/backends/infoblox-backend.js b/server/lib/external-backends/backends/infoblox-backend.js
index 2671491..e9a8fee 100644
--- a/server/lib/external-backends/backends/infoblox-backend.js
+++ b/server/lib/external-backends/backends/infoblox-backend.js
@@ -73,7 +73,7 @@ class InfobloxBackend extends ExternalBackends {
apiVersion: c.version
})
const login = await ipam.login(c.username, c.password)
- if (!login) return false
+ if (!login) return { leased: false }
// Get the host and check the leased state
let host = JSON.parse(await ipam.getHost(ipv4))[0]
@@ -81,9 +81,12 @@ class InfobloxBackend extends ExternalBackends {
// If leased return the next 20 free ips of the subnet.
const dhcpNetwork = JSON.parse(await ipam.getNetworkFromIp(ipv4))
const nextIps = await ipam.getNext(dhcpNetwork[0]._ref, 20)
- return nextIps
+ return { leased: true, nextIps: nextIps }
}
- return false
+
+ let response = { leased: false }
+ if (host.names.length >= 1) response.name = host.names[0].split('.')[0]
+ return response
}
async setIp (credentials, ipv4, mac, name, setNextIp = false) {