summaryrefslogtreecommitdiffstats
path: root/server/api
diff options
context:
space:
mode:
authorJannik Schönartz2020-04-17 21:36:33 +0200
committerJannik Schönartz2020-04-17 21:36:33 +0200
commit234aa456078c589e1d575810dad1873bd7458f36 (patch)
treec8e0227dba5b92544d09ba175702c397263ce8d4 /server/api
parent[webapp/Backends] Add docu overlay styles, used for the screenshots (diff)
downloadbas-234aa456078c589e1d575810dad1873bd7458f36.tar.gz
bas-234aa456078c589e1d575810dad1873bd7458f36.tar.xz
bas-234aa456078c589e1d575810dad1873bd7458f36.zip
[server/registration] Add domain selection to the semi-automatic registration
Diffstat (limited to 'server/api')
-rw-r--r--server/api/registration.js42
1 files changed, 35 insertions, 7 deletions
diff --git a/server/api/registration.js b/server/api/registration.js
index 6688b29..4c79551 100644
--- a/server/api/registration.js
+++ b/server/api/registration.js
@@ -209,7 +209,7 @@ noAuthRouter.postAsync('/clients', async (req, res) => {
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)
+ const setIp = await dhcp.instance.setIp(dhcp.backend.credentials, network.ip, undefined, network.mac, undefined, true)
// Check for errors.
if (!setIp.error) {
dhcp.ref = setIp.ref
@@ -225,10 +225,16 @@ noAuthRouter.postAsync('/clients', async (req, res) => {
}
} else if (network.dhcp) {
// If networks.dhcp is set the user already choose the ip and we have to set it now.
+ if (!network.dhcp.domain) {
+ // Check if there are multiple domains.
+ const domainList = await dhcp.instance.checkDomain(dhcp.backend.credentials)
+ if (domainList.length > 1) return res.send(buildSelectDomainIpxeMenu(client, domainList))
+ else network.dhcp.domain = domainList[0]
+ }
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)
+ const setIp = await dhcp.instance.setIp(dhcp.backend.credentials, network.dhcp.ip, network.dhcp.domain, network.mac, client.name)
dhcp.ref = setIp.id
// Check for errors.
if (setIp.error) {
@@ -244,7 +250,7 @@ noAuthRouter.postAsync('/clients', async (req, res) => {
setIpError = setIp.msg
} else {
// Client ip set successfully
- client.networks[0].ip = network.dhcp
+ client.networks[0].ip = network.dhcp.ip
client.networks[0].hostname = client.name
client.networks[0].domain = setIp.domain
}
@@ -266,7 +272,7 @@ noAuthRouter.postAsync('/clients', async (req, res) => {
if (ipCheck.id) dhcp.ref = ipCheck.id
}
}
- } else {
+ } else { // End of DHCP Stuff
if (automatic) {
client.name = client.type + '_' + client.uuid
}
@@ -532,7 +538,7 @@ function buildSelectIpIpxeMenu (client, ipList, error = undefined) {
script += 'menu Select the ip for this client: \r\n'
for (let index in ipList) {
const ip = ipList[index]
- client.networks[0].dhcp = ip
+ client.networks[0].dhcp = { ip: ip }
script += 'item ' + ip + ' ' + ip + '\r\n'
menuscript += ':' + ip + '\r\n' + 'params\r\nparam client ' + JSON.stringify(client) + '\r\n'
menuscript += 'param ipxe true\r\n'
@@ -543,6 +549,26 @@ function buildSelectIpIpxeMenu (client, ipList, error = undefined) {
return script
}
+function buildSelectDomainIpxeMenu (client, domainList) {
+ const basUrl = 'https://' + url
+ let script = '#!ipxe\r\n'
+
+ let menuscript = ''
+ script += ':start\r\n'
+ script += 'menu Select the domain for this client: \r\n'
+ for (let index in domainList) {
+ const domain = domainList[index]
+ client.networks[0].dhcp.domain = domain
+ script += 'item ' + domain + ' ' + domain + '\r\n'
+ menuscript += ':' + domain + '\r\n' + 'params\r\nparam client ' + JSON.stringify(client) + '\r\n'
+ menuscript += 'param ipxe true\r\n'
+ menuscript += 'chain --replace ' + basUrl + '/api/registration/clients##params\r\n\r\n'
+ }
+ script += `choose target && goto \${target}\r\n\r\n`
+ script += menuscript
+ return script
+}
+
function buildNameClientIpxeMenu (client) {
const basUrl = 'https://' + url
let script = '#!ipxe\r\n'
@@ -565,7 +591,8 @@ function buildOverviewIpxeMenu (client) {
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'
+ if (client.networks[0].dhcp.ip) script += 'item --gap New IP: ' + client.networks[0].dhcp.ip + '\r\n'
+ if (client.networks[0].dhcp.domain) script += 'item --gap Domain: ' + client.networks[0].dhcp.domain + '\r\n'
delete client.networks[0].dhcp
}
@@ -579,7 +606,8 @@ function buildOverviewIpxeMenu (client) {
const network = client.networks[index]
script += 'item --gap\r\n'
script += 'item --gap Current IP: ' + network.ip + '\r\n'
- if (network.dhcp) script += 'item --gap New IP: ' + network.dhcp + '\r\n'
+ if (network.dhcp && network.dhcp.ip) script += 'item --gap New IP: ' + network.dhcp.ip + '\r\n'
+ if (network.dhcp && network.dhcp.domain) script += 'item --gap Domain: ' + network.dhcp.domain + '\r\n'
script += 'item --gap MAC: ' + network.mac + '\r\n'
if (network.dhcp) delete network.dhcp
}