summaryrefslogtreecommitdiffstats
path: root/server/api
diff options
context:
space:
mode:
authorJannik Schönartz2019-10-16 21:26:20 +0200
committerJannik Schönartz2019-10-16 21:26:20 +0200
commit4fb5c2e10add325aa0167f20a3dee45d777eac16 (patch)
treee917f75681772cf19bf97d293b886b71d0d5e841 /server/api
parent[webapp/clients] Add the choice to select backends when deleting clients (diff)
downloadbas-4fb5c2e10add325aa0167f20a3dee45d777eac16.tar.gz
bas-4fb5c2e10add325aa0167f20a3dee45d777eac16.tar.xz
bas-4fb5c2e10add325aa0167f20a3dee45d777eac16.zip
[server/registration] Automatic registration now sets the hostname (dhcp) as the name for the client
Diffstat (limited to 'server/api')
-rw-r--r--server/api/registration.js33
1 files changed, 24 insertions, 9 deletions
diff --git a/server/api/registration.js b/server/api/registration.js
index 190bfeb..548e82d 100644
--- a/server/api/registration.js
+++ b/server/api/registration.js
@@ -146,15 +146,26 @@ noAuthRouter.postAsync('/clients', async (req, res) => {
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
- client.networks[0].ip = setIp.ip
- } else {
- log({ category: 'ERROR_DHCP', description: `[${dhcp.backend.id}] Error setting ip ${network.ip} for mac ${network.mac}\nError: ${setIp.msg}` })
+ if (!client.name) {
+ // Check the ip state in the dhcp
+ const ipCheck = await dhcp.instance.checkIp(dhcp.backend.credentials, network.ip)
+
+ // If it's not leased, set the hostname as clientname
+ if (!ipCheck.leased && ipCheck.name !== '') {
+ if (ipCheck.name) client.name = ipCheck.name
+ if (ipCheck.id) dhcp.ref = ipCheck.id
+ } else {
+ 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
+ client.networks[0].ip = setIp.ip
+ } else {
+ log({ category: 'ERROR_DHCP', description: `[${dhcp.backend.id}] Error setting ip ${network.ip} for mac ${network.mac}\nError: ${setIp.msg}` })
+ }
+ }
}
} else if (network.dhcp) {
// If networks.dhcp is set the user already choose the ip and we have to set it now.
@@ -194,6 +205,10 @@ noAuthRouter.postAsync('/clients', async (req, res) => {
if (ipCheck.id) dhcp.ref = ipCheck.id
}
}
+ } else {
+ if (automatic) {
+ client.name = client.type + '_' + client.uuid
+ }
}
}