summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJannik Schönartz2018-08-29 13:28:53 +0200
committerJannik Schönartz2018-08-29 13:28:53 +0200
commitaf9482a0c6ebef83226829fb2a126d5ca9424ffd (patch)
treed235ea088cb7e02c8c74b143b973cd780feabbb2 /server
parent[external-backends] Use search table instead of datatables (diff)
downloadbas-af9482a0c6ebef83226829fb2a126d5ca9424ffd.tar.gz
bas-af9482a0c6ebef83226829fb2a126d5ca9424ffd.tar.xz
bas-af9482a0c6ebef83226829fb2a126d5ca9424ffd.zip
[external-backends] Add getClient methods for all backends
Delete dummy and another backends. Extend template-dummy for testing stuff. Add getClient method for dhcp and idoit backends. Fixed appendicon for selections.
Diffstat (limited to 'server')
-rw-r--r--server/lib/external-backends/backends/another-backend.js15
-rw-r--r--server/lib/external-backends/backends/dummy-backend.js15
-rw-r--r--server/lib/external-backends/backends/idoit-backend.js67
-rw-r--r--server/lib/external-backends/backends/infoblox-backend.js29
-rw-r--r--server/lib/external-backends/backends/template-backend.js34
-rw-r--r--server/lib/external-backends/index.js13
6 files changed, 134 insertions, 39 deletions
diff --git a/server/lib/external-backends/backends/another-backend.js b/server/lib/external-backends/backends/another-backend.js
deleted file mode 100644
index 0d60259..0000000
--- a/server/lib/external-backends/backends/another-backend.js
+++ /dev/null
@@ -1,15 +0,0 @@
-/* global __appdir */
-const path = require('path')
-const ExternalBackends = require(path.join(__appdir, 'lib', 'external-backends'))
-
-class AnotherBackend extends ExternalBackends {
- getCredentials () {
- return [{ type: 'text', id: 1, name: 'text 1' }, { type: 'text', id: 2, name: 'text 2' }, { type: 'password', id: 3, name: 'password 1', show: false }, { type: 'password', id: 4, name: 'password 2', show: true }, { type: 'password', id: 5, name: 'password 3', show: false }]
- }
-
- getSyncTypes () {
- return ['THERE', 'ARE', 'NO', 'SYNC', 'TYPES']
- }
-}
-
-module.exports = AnotherBackend
diff --git a/server/lib/external-backends/backends/dummy-backend.js b/server/lib/external-backends/backends/dummy-backend.js
deleted file mode 100644
index c157e0a..0000000
--- a/server/lib/external-backends/backends/dummy-backend.js
+++ /dev/null
@@ -1,15 +0,0 @@
-/* global __appdir */
-const path = require('path')
-const ExternalBackends = require(path.join(__appdir, 'lib', 'external-backends'))
-
-class DummyBackend extends ExternalBackends {
- getCredentials () {
- return [{ type: 'switch', id: 1, name: 'switch 1', value: false }, { type: 'switch', id: 2, name: 'switch 2', value: false }, { type: 'switch', id: 3, name: 'switch 3', value: true }, { type: 'select', id: 4, name: 'selection 1', items: ['wasd', 'asdf', 'qwertz'] }, { type: 'select', id: 5, name: 'selection 2', items: ['1', '2', '3'] }]
- }
-
- async checkConnection (backend) {
- return { success: false, error: 'This is a test where success was intentionally set to false!' }
- }
-}
-
-module.exports = DummyBackend
diff --git a/server/lib/external-backends/backends/idoit-backend.js b/server/lib/external-backends/backends/idoit-backend.js
index 6bfe001..7db2bf2 100644
--- a/server/lib/external-backends/backends/idoit-backend.js
+++ b/server/lib/external-backends/backends/idoit-backend.js
@@ -33,7 +33,7 @@ class IdoitBackend extends ExternalBackends {
*
* return: { success: <boolean>, status: '<STATUS_CODE_IF_ERROR>', error: '<ERROR_MESSAGE>' }
*/
- async checkConnection (credentials) {
+ checkConnection (credentials) {
var c = this.mapCredentials(credentials)
return this.getSession(c)
}
@@ -71,6 +71,71 @@ class IdoitBackend extends ExternalBackends {
return ['None', 'Two-Way', 'Upload Only', 'Upload Then Delete', 'Upload Mirror', 'Download Only', 'Download Then Delete', 'Download Mirror']
}
+ /*
+ * Gets all objects and searches for the ip. Because idoit cannot search for ip or mac.
+ *
+ */
+ async getClient (credentials, client) {
+ var c = this.mapCredentials(credentials)
+ var login = await this.getSession(c)
+ var sid = login.data.result['session-id']
+
+ // Headers
+ var headers = {
+ 'X-RPC-Auth-Session': sid
+ }
+
+ // Params
+ var params = {
+ 'id': 1450,
+ 'apikey': c.apikey,
+ 'language': 'en'
+ }
+
+ // Get common object data
+ var result = {}
+ result.common = await this.axiosRequest(c.url, 'cmdb.object.read', params, headers)
+ result.common = result.common.data.result
+
+ // Get objecttypes
+ delete params.id
+ // params.type = result.common.objecttype
+ // result.categories = await this.axiosRequest(c.url, 'cmdb.object_type_categories', params, headers)
+ // result.categories = result.categories.data.result
+
+ // result.categories = result.categories.data.result
+ /*
+ var cat = []
+ var self = this
+ result.categories.catg.forEach(async c => {
+ delete params.type
+ params.objID = 1450
+ params.category = c.const
+ console.log(params)
+ //var tmp = await self.axiosRequest(c.url, 'cmdb.category.read', params, headers).catch(error => {console.log(error)})
+ //tmp = tmp.data.result
+
+ //cat.push(tmp)
+ })
+ result.cat = cat
+ */
+
+ // Get all ip addresses
+ // delete params.type
+ params.objID = 1450
+ params.category = 'C__CATG__IP'
+ var tmp = await this.axiosRequest(c.url, 'cmdb.category.read', params, headers)
+ tmp = tmp.data.result
+
+ tmp.forEach(element => {
+ if (element.primary_hostaddress) {
+ result.ip = element.primary_hostaddress.ref_title
+ }
+ })
+
+ return result
+ }
+
async getObjects (credentials) {
var c = this.mapCredentials(credentials)
var login = await this.getSession(c)
diff --git a/server/lib/external-backends/backends/infoblox-backend.js b/server/lib/external-backends/backends/infoblox-backend.js
index f980b8b..9d070ac 100644
--- a/server/lib/external-backends/backends/infoblox-backend.js
+++ b/server/lib/external-backends/backends/infoblox-backend.js
@@ -25,7 +25,7 @@ class InfobloxBackend extends ExternalBackends {
*
* return: { success: <boolean>, status: '<STATUS_CODE_IF_ERROR>', error: '<ERROR_MESSAGE>' }
*/
- async checkConnection (credentials) {
+ checkConnection (credentials) {
var c = this.mapCredentials(credentials)
var ipam = new Infoblox({
@@ -34,13 +34,36 @@ class InfobloxBackend extends ExternalBackends {
})
return ipam.login(c.username, c.password).then(response => {
if (response) {
- console.log('wefkin')
return { success: true }
} else {
- return { success: false, error: 'TEST' }
+ return { success: false, error: 'Login failed' }
}
})
}
+
+ /*
+ * Gets the client via IP, because only fixed pcs can be found via mac. But we also want so support leased pc's?
+ *
+ */
+ async getClient (credentials, client) {
+ 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) {
+ return ipam.getHost('10.21.9.228').then(response => {
+ return JSON.parse(response)
+ })
+ } else {
+ return { success: false, error: 'Login failed' }
+ }
+ })
+ }
+
// ############################################################################
// ####################### helper/optional functions #########################
// Helper function, to map the array of credential objects into a single js object.
diff --git a/server/lib/external-backends/backends/template-backend.js b/server/lib/external-backends/backends/template-backend.js
index 8bee5e1..f554e69 100644
--- a/server/lib/external-backends/backends/template-backend.js
+++ b/server/lib/external-backends/backends/template-backend.js
@@ -4,12 +4,38 @@ const ExternalBackends = require(path.join(__appdir, 'lib', 'external-backends')
class TemplateBackend extends ExternalBackends {
getCredentials () {
- return [{ type: 'text', id: 1, name: 'text test', icon: 'bug_report' }, { type: 'password', id: 2, name: 'password test', show: true }, { type: 'password', id: 3, name: 'password test nr2', show: false }, { type: 'switch', id: 4, name: 'bool test', value: false }, { type: 'select', id: 5, name: 'selection test', items: ['wasd', 'asdf', 'qwertz'] }]
+ return [{ type: 'text', id: 1, name: 'Text, icon', icon: 'bug_report' },
+ { type: 'text', id: 13, name: 'Text, no icon' },
+ { type: 'password', id: 2, name: 'Password, hide', icon: 'lock', show: false },
+ { type: 'password', id: 3, name: 'Password, show', icon: 'lock', show: true },
+ { type: 'switch', id: 4, name: 'Switch, no childs, set false', icon: 'label', value: false },
+ { type: 'switch', id: 5, name: 'Switch, no childs, set true', icon: 'label', value: true },
+ { type: 'switch',
+ id: 6,
+ name: 'Switch, childs, set false',
+ icon: 'label',
+ value: false,
+ elements: [
+ { type: 'text', id: 7, name: 'text test', icon: 'bug_report' },
+ { type: 'password', id: 8, name: 'password test', icon: 'lock', show: false }] },
+ { type: 'switch',
+ id: 9,
+ name: 'Switch, childs, set true',
+ icon: 'label',
+ value: true,
+ elements: [
+ { type: 'text', id: 10, name: 'text test', icon: 'bug_report' },
+ { type: 'password', id: 11, name: 'password test', icon: 'lock', show: false }] },
+ { type: 'select', id: 12, name: 'selection, icon', icon: 'label', items: ['wasd', 'asdf', 'qwertz'] },
+ { type: 'select', id: 14, name: 'selection, no icon', items: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25] }]
}
- async checkConnection (backend) {
- var result = await x()
- return result
+ checkConnection (backend) {
+ return x()
+ }
+
+ getSyncTypes () {
+ return ['THERE', 'ARE', 'NO', 'SYNC', 'TYPES']
}
}
diff --git a/server/lib/external-backends/index.js b/server/lib/external-backends/index.js
index c882522..40e462d 100644
--- a/server/lib/external-backends/index.js
+++ b/server/lib/external-backends/index.js
@@ -45,7 +45,8 @@ class ExternalBackends {
return backend
}
- /* Returns an empty array [] if the backends doesn't have the function implemented.
+ /*
+ * Returns an empty array [] if the backends doesn't have the function implemented.
*
* return: ['<SYNC_TYPE>', ...]
*/
@@ -54,6 +55,16 @@ class ExternalBackends {
}
/*
+ * Get the client from the backend and returns their informationen.
+ * credentials: <BACKEND_CREDENTIALS>
+ * client: Information about the client (ip, mac, uuid)
+ *
+ * return:
+ */
+ async getClient (credentials, client) {
+ return { status: 'NOT_IMPLEMENTED_EXCEPTION', error: 'The provided backend does not have a getClient method' }
+ }
+ /*
* credendtials: <BACKEND_CREDENTIALS>
*
* Returns a list of all objects in the backend.