summaryrefslogtreecommitdiffstats
path: root/server/lib
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/external-backends/backends/idoit-backend.js2
-rw-r--r--server/lib/external-backends/backends/infoblox-backend.js95
-rw-r--r--server/lib/shell.js10
3 files changed, 102 insertions, 5 deletions
diff --git a/server/lib/external-backends/backends/idoit-backend.js b/server/lib/external-backends/backends/idoit-backend.js
index 5d94e41..6bfe001 100644
--- a/server/lib/external-backends/backends/idoit-backend.js
+++ b/server/lib/external-backends/backends/idoit-backend.js
@@ -249,7 +249,7 @@ class IdoitBackend extends ExternalBackends {
console.log(response.data.error)
return { success: false, error: response.data.error.message, msg: response.data.error.data.error }
} else {
- return { success: false, msg: 'UNNOWN ERROR' }
+ return { success: false, error: 'UNNOWN_ERROR' }
}
}
}
diff --git a/server/lib/external-backends/backends/infoblox-backend.js b/server/lib/external-backends/backends/infoblox-backend.js
new file mode 100644
index 0000000..f980b8b
--- /dev/null
+++ b/server/lib/external-backends/backends/infoblox-backend.js
@@ -0,0 +1,95 @@
+/* global __appdir */
+const path = require('path')
+const ExternalBackends = require(path.join(__appdir, 'lib', 'external-backends'))
+const Infoblox = require('infoblox')
+
+class InfobloxBackend extends ExternalBackends {
+ // ############################################################################
+ // ######################## needed functions #################################
+
+ /*
+ * Returns the credential structure / fields, defined in the backends.
+ */
+ getCredentials () {
+ return [
+ { type: 'text', id: 1, name: 'API url', icon: 'link' },
+ { type: 'text', id: 2, name: 'API version', icon: 'info' },
+ { type: 'text', id: 3, name: 'Username', icon: 'person_outline' },
+ { type: 'password', id: 4, name: 'Password', icon: 'vpn_key', show: false }
+ ]
+ }
+
+ /*
+ * Checks the connection of a given backend.
+ * infoblox: If we can login the connection to the server and also the login is successfull.
+ *
+ * return: { success: <boolean>, status: '<STATUS_CODE_IF_ERROR>', error: '<ERROR_MESSAGE>' }
+ */
+ async checkConnection (credentials) {
+ var c = this.mapCredentials(credentials)
+
+ var ipam = new Infoblox({
+ ip: c.url,
+ apiVersion: c.version
+ })
+ return ipam.login(c.username, c.password).then(response => {
+ if (response) {
+ console.log('wefkin')
+ return { success: true }
+ } else {
+ return { success: false, error: 'TEST' }
+ }
+ })
+ }
+ // ############################################################################
+ // ####################### helper/optional functions #########################
+ // Helper function, to map the array of credential objects into a single js object.
+ mapCredentials (credentials) {
+ const c = JSON.parse(credentials)
+ var mapped = {
+ url: c.find(x => x.id === 1).value,
+ version: c.find(x => x.id === 2).value,
+ username: c.find(x => x.id === 3).value,
+ password: c.find(x => x.id === 4).value
+ }
+
+ return mapped
+ }
+
+ // #### TEST FUNCTIONS ###
+ test (credentials) {
+ var c = this.mapCredentials(credentials)
+
+ var ipam = new Infoblox({
+ ip: c.url,
+ apiVersion: c.version
+ })
+
+ var promise = new Promise((resolve, reject) => {
+ ipam.login(c.username, c.password).then(response => {
+ if (response) {
+ // ipam.create('record:host?_return_fields%2B=na13me,ipv4addrs&_return_as_object=1', {'name': 'wapiTest.lp.privat', 'ipv4addrs': [{'ipv4addr': '10.21.9.141', 'mac': 'aa:bb:cc:11:22:21'}]}).then(function (response) {
+ // return response
+ // })
+ // Get the network from the ip.
+ // ipam.getHost('10.21.9.78').then(function (response) {
+ ipam.getNetworkFromIp('10.21.9.78').then(response => {
+ // ipam.getIpsFromSubnet('10.21.9.0/24').then(function (response) {
+ // ipam.list('record:host').then(function (response) {
+ // ipam.getDomain().then(function (response) {
+ response = JSON.parse(response)
+ // ipam.getNext(response[0]._ref, 1).then(r => {
+ resolve(response)
+ // })
+ // res.send(JSON.parse(response))
+ })
+ } else {
+ return { success: false, error: 'TEST' }
+ }
+ })
+ })
+ return promise
+ }
+}
+
+module.exports = InfobloxBackend
diff --git a/server/lib/shell.js b/server/lib/shell.js
index e0782f1..37de779 100644
--- a/server/lib/shell.js
+++ b/server/lib/shell.js
@@ -20,13 +20,15 @@ module.exports = {
shell.rm(path.join(__appdir, 'ipxe', 'ipxe', 'src', 'config', 'console.h'))
shell.cp(path.join(__appdir, 'ipxe', 'console.h'), path.join(__appdir, 'ipxe', 'ipxe', 'src', 'config'))
// var make = 'make EMBED=' + path.join(__appdir, 'ipxe', 'main.ipxe');
- var make = 'make EMBED=' + path.join(__appdir, 'ipxe', 'main.ipxe') + ' TRUST=' + path.join(__appdir, 'bin', 'fullchain.pem')
+ var make = 'make EMBED=' + path.join(__appdir, 'ipxe', 'main.ipxe') + ' TRUST=' + path.join(__appdir, 'bin', 'fullchain.pem') + ' bin/undionly.kpxe'
// shell.env.PATH = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin';
shell.env.DEBUG = ''
shell.exec(make, function (code, stdout, stderr) {
- shell.rm(path.join(__appdir, 'tftp', 'ipxe.0'))
- shell.cp('bin/ipxe.pxe', path.join(__appdir, 'tftp'))
- shell.mv(path.join(__appdir, 'tftp', 'ipxe.pxe'), path.join(__appdir, 'tftp', 'ipxe.0'))
+ // shell.rm(path.join(__appdir, 'tftp', 'ipxe.0'))
+ shell.rm(path.join(__appdir, 'ipxe', 'ipxe.0'))
+ // shell.cp('bin/undionly.kpxe', path.join(__appdir, 'tftp'))
+ shell.cp('bin/undionly.kpxe', path.join(__appdir, 'ipxe'))
+ shell.mv(path.join(__appdir, 'ipxe', 'undionly.kpxe'), path.join(__appdir, 'ipxe', 'ipxe.0'))
// shell.rm('-rf', 'ipxe');
return res.status(200).send({ status: 'success' })
})