summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJannik Schönartz2019-04-08 05:17:38 +0200
committerJannik Schönartz2019-04-08 05:17:38 +0200
commitba5482abf1aa5c308f9f2d16748014335bc3444f (patch)
treec31fb5e493e699a2c70b3b7563ee38b3fb5dd010 /server
parent[webapp/external-backends] Remove console logs. lul ^^ (diff)
downloadbas-ba5482abf1aa5c308f9f2d16748014335bc3444f.tar.gz
bas-ba5482abf1aa5c308f9f2d16748014335bc3444f.tar.xz
bas-ba5482abf1aa5c308f9f2d16748014335bc3444f.zip
[server/external-backends] Fix dhcp registration stuff
Diffstat (limited to 'server')
-rw-r--r--server/api/registration.js26
-rw-r--r--server/ipxe/registration.ipxe8
-rw-r--r--server/lib/external-backends/backends/infoblox-backend.js40
3 files changed, 51 insertions, 23 deletions
diff --git a/server/api/registration.js b/server/api/registration.js
index dc18bf1..5638747 100644
--- a/server/api/registration.js
+++ b/server/api/registration.js
@@ -139,18 +139,19 @@ noAuthRouter.postAsync('/clients', async (req, res) => {
const network = client.networks[0]
// Get the dhcp backend. Only one dhcp backend can exist else -> conflict.
const dhcp = await backendHelper.getDhcp()
+ let ipSelection = false
+ let setIpError = undefined
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, client.name, true)
-
+ const setIp = await dhcp.instance.setIp(dhcp.backend.credentials, network.ip, network.mac, undefined, true)
// 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}. Error: ${setIp.msg}` })
+ 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.
@@ -159,16 +160,23 @@ noAuthRouter.postAsync('/clients', async (req, res) => {
// Check for errors.
if (setIp.error) {
// Setting the client ip failed
- log({ category: 'ERROR_DHCP', description: `[${dhcp.backend.id}] Error setting ip ${network.ip} for mac ${network.mac}. Error: ${setIp.msg}` })
+ ipSelection = true
+ delete client.networks[0].dhcp
+ delete client.name
+ setIpError = setIp.msg
} else {
// Client ip set successfully
client.networks[0].ip = network.dhcp
}
} else {
+ ipSelection = true
+ }
+
+ 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))
+ 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 })
}
}
@@ -404,17 +412,20 @@ function buildIpxeMenu (id, name, groups, parents) {
return script
}
-function buildSelectIpIpxeMenu (client, ipList) {
+function buildSelectIpIpxeMenu (client, ipList, error = undefined) {
const basUrl = 'https://' + url
let script = '#!ipxe\r\n'
+ if (error) script += 'echo\r\necho ' + error + '\r\necho\r\nprompt Press any key to select a new ip address\r\n'
+
let menuscript = ''
script += ':start\r\n'
- script += 'menu Select the ip for this client:\r\n'
+ script += 'menu Select the ip for this client: \r\n'
for (let index in ipList) {
const ip = ipList[index]
client.networks[0].dhcp = 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'
menuscript += 'chain --replace ' + basUrl + '/api/registration/clients##params\r\n\r\n'
}
script += `choose target && goto \${target}\r\n\r\n`
@@ -428,6 +439,7 @@ function buildNameClientIpxeMenu (client) {
script += '\r\necho Enter client name\r\nread clientname\r\nparams\r\n'
client.name = `\${clientname}`
script += 'param client ' + JSON.stringify(client) + '\r\n'
+ script += 'param ipxe true\r\n'
script += 'chain --replace ' + basUrl + '/api/registration/clients##params\r\n\r\n'
return script
}
diff --git a/server/ipxe/registration.ipxe b/server/ipxe/registration.ipxe
index 621921d..1fe2217 100644
--- a/server/ipxe/registration.ipxe
+++ b/server/ipxe/registration.ipxe
@@ -10,7 +10,7 @@ set crosscert http://ca.ipxe.org/auto/
:start
menu Initializing client registration
item --key a automatic Automatic Registration
-item --key c customname Automatic Registration (Custom Name)
+item --key s semiautomatic Semi-Automatic Registration
item --key m manual Manual Registration
item --key k key Replace Secure Boot Keys
item --key l localboot Localboot
@@ -32,12 +32,10 @@ param automatic true
param client { "type": "CLIENT", "uuid": "${uuid}", "purpose": "Pool PC", "networks": [{ "ip": "${net0/ip}", "mac": "${net0/mac}" }] }
chain https://bas.intra.uni-freiburg.de/api/registration/clients##params
-:customname
-echo Enter client name
-read clientname
+:semiautomatic
params
param ipxe true
-param client { "name": "${clientname}", "type": "CLIENT", "uuid": "${uuid}", "purpose": "Pool PC", "networks": [{ "ip": "${net0/ip}", "mac": "${net0/mac}" }] }
+param client { "type": "CLIENT", "uuid": "${uuid}", "purpose": "Pool PC", "networks": [{ "ip": "${net0/ip}", "mac": "${net0/mac}" }] }
chain https://bas.intra.uni-freiburg.de/api/registration/clients##params
:manual
diff --git a/server/lib/external-backends/backends/infoblox-backend.js b/server/lib/external-backends/backends/infoblox-backend.js
index 27aa0b4..6076217 100644
--- a/server/lib/external-backends/backends/infoblox-backend.js
+++ b/server/lib/external-backends/backends/infoblox-backend.js
@@ -101,21 +101,39 @@ class InfobloxBackend extends ExternalBackends {
const network = JSON.parse(await ipam.getNetworkFromIp(ipv4))
ipv4 = 'func:nextavailableip:' + network[0].network
}
- const domain = await ipam.getDomain()
- const createHost = await ipam.create('record:host?_return_fields%2B=ipv4addrs&_return_as_object=1', {
- 'name': name + '.' + domain,
- 'ipv4addrs': [
- {
- 'ipv4addr': ipv4,
- 'mac': mac
- }
- ]
- })
+ const domain = (await ipam.getDomain())[0]
+
+ // Set fixed ip if the name is not set (Automatic registration)
+ let path = ''
+ let data = {}
+
+ if (!name) {
+ path = 'fixedaddress?_return_fields%2B=ipv4addr&_return_as_object=1'
+ data = {
+ 'ipv4addr': ipv4,
+ 'mac': mac
+ }
+ } else {
+ path = 'record:host?_return_fields%2B=ipv4addrs&_return_as_object=1'
+ data = {
+ 'name': name + '.' + domain,
+ 'ipv4addrs': [
+ {
+ 'ipv4addr': ipv4,
+ 'mac': mac
+ }
+ ]
+ }
+ }
+ const createHost = await ipam.create(path, data)
// Return error if there is one
if (createHost.Error) {
return { error: 'ERROR_INFOBLOX', msg: createHost.text }
- } else return { host: createHost.result.ipv4addrs[0].host, ip: createHost.result.ipv4addrs[0].ipv4addr }
+ } else {
+ if (!name) return { ip: createHost.result.ipv4addr }
+ else return { host: createHost.result.ipv4addrs[0].host, ip: createHost.result.ipv4addrs[0].ipv4addr }
+ }
}
isDhcp () {