summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--server/api/registration.js42
-rw-r--r--server/lib/external-backends/backends/infoblox-backend.js19
-rw-r--r--server/lib/external-backends/index.js3
3 files changed, 55 insertions, 9 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
}
diff --git a/server/lib/external-backends/backends/infoblox-backend.js b/server/lib/external-backends/backends/infoblox-backend.js
index 6c80392..0571841 100644
--- a/server/lib/external-backends/backends/infoblox-backend.js
+++ b/server/lib/external-backends/backends/infoblox-backend.js
@@ -64,6 +64,20 @@ class InfobloxBackend extends ExternalBackends {
})
}
+ async checkDomain (credentials) {
+ const c = this.mapCredentials(credentials)
+
+ const ipam = new Infoblox({
+ ip: c.url,
+ apiVersion: c.version
+ })
+ const login = await ipam.login(c.username, c.password)
+ if (!login) return { error: 'LOGIN_FAILED' }
+
+ const domainList = await ipam.getDomain()
+ return domainList
+ }
+
async checkIp (credentials, ipv4) {
const c = this.mapCredentials(credentials)
@@ -96,7 +110,7 @@ class InfobloxBackend extends ExternalBackends {
return response
}
- async setIp (credentials, ipv4, mac, name, setNextIp = false) {
+ async setIp (credentials, ipv4, domain, mac, name, setNextIp = false) {
const c = this.mapCredentials(credentials)
const ipam = new Infoblox({
@@ -116,7 +130,8 @@ class InfobloxBackend extends ExternalBackends {
return { error: 'ERROR_INFOBLOX', msg: 'No network found. Missing permissions?' }
}
}
- const domain = (await ipam.getDomain())[0]
+ // If the domain is not set, take the first available one.
+ if (!domain) domain = (await ipam.getDomain())[0]
// Set fixed ip if the name is not set (Automatic registration)
let path = ''
diff --git a/server/lib/external-backends/index.js b/server/lib/external-backends/index.js
index 9716b36..f16a1e1 100644
--- a/server/lib/external-backends/index.js
+++ b/server/lib/external-backends/index.js
@@ -166,6 +166,9 @@ class ExternalBackends {
async getFile (credentials, externalId, filename) {
return { error: 'NOT_IMPLEMENTED_EXCEPTION', message: 'The provided backend does not have an getFile method' }
}
+ async checkDomain (credentials) {
+ return { error: 'NOT_IMPLEMENTED_EXCEPTION', message: 'The provided backend does not have a checkDomain method' }
+ }
async checkIp (credentials, ipv4) {
return { error: 'NOT_IMPLEMENTED_EXCEPTION', message: 'The provided backend does not have a checkIp method' }
}