From f6966ee8ced5c7b41bd1a1324868c1b3fd612027 Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Tue, 13 Jul 2021 14:45:40 +0000 Subject: [server/idoit/registration] Change contact from name / lastname to username & cut netmask from ip --- server/api/registration.js | 9 ++++++--- server/lib/external-backends/backends/idoit-backend.js | 17 +++++------------ 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/server/api/registration.js b/server/api/registration.js index 1b5a6d1..5d161b7 100644 --- a/server/api/registration.js +++ b/server/api/registration.js @@ -683,12 +683,15 @@ async function parseHardwareInformation (data) { /* Get network information as fallback for ip */ if (client.networks.length <= 0) { for (let key in data.net) { + // IP v4 and v6 comes with the netmask, so the last 3 chars need to be cut + const ipv4 = data.net[key]['ipv4'] + const ipv6 = data.net[key]['ipv6'] let network = { 'name': key, 'mac': data.net[key]['mac'], - 'ip': data.net[key]['ipv4'], - 'ipv6': data.net[key]['ipv6'], - 'hostname': '' + ...(ipv4 && { 'ip': ipv4.substring(0, ipv4.length - 3) }), + ...(ipv6 && { 'ipv6': ipv6.substring(0, ipv6.length - 3) }), + 'hostname': undefined } client.networks.push(network) } diff --git a/server/lib/external-backends/backends/idoit-backend.js b/server/lib/external-backends/backends/idoit-backend.js index 2b5462c..c538a31 100644 --- a/server/lib/external-backends/backends/idoit-backend.js +++ b/server/lib/external-backends/backends/idoit-backend.js @@ -343,6 +343,7 @@ class IdoitBackend extends ExternalBackends { 'cmdb.objects.read', { 'apikey': c.apikey, + 'categories': ['C__CATS__PERSON'], 'filter': { 'type': 'C__OBJTYPE__PERSON' } @@ -360,19 +361,11 @@ class IdoitBackend extends ExternalBackends { const persons = boundObjects.filter(response => response.id.startsWith('READ_C__OBJTYPE__PERSON'))[0].result let counter = 0 - // Helper method for replaceing ä -> ae, ü -> ue, ö -> oe - const replaceUmlauts = input => { - return input.toLowerCase().replace(/\u00e4/g, 'ae').replace(/\u00fc/g, 'ue').replace(/\u00f6/g, 'oe') - } - - for (let contact of client.contacts) { - const firstname = replaceUmlauts(contact.firstname) - const lastname = replaceUmlauts(contact.lastname) - + for (let username of client.contacts) { const contactPerson = persons.filter(person => { - if (!replaceUmlauts(person.title).includes(firstname)) return false - else if (!replaceUmlauts(person.title).includes(lastname)) return false - return true + // Check for the username + if (person.categories.C__CATS__PERSON[0].title === username) return true + return false }) let contactId -- cgit v1.2.3-55-g7522