From ebf55390eb0587e71fde0fbd294ff6cedba5b60d Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 11 Nov 2016 19:21:12 -0500 Subject: [PATCH] Added password dragon xml importer #1 --- src/Web/wwwroot/app/services/importService.js | 122 ++++++++++++++++++ .../wwwroot/app/tools/views/toolsImport.html | 1 + 2 files changed, 123 insertions(+) diff --git a/src/Web/wwwroot/app/services/importService.js b/src/Web/wwwroot/app/services/importService.js index f5ce481c72..7af8285695 100644 --- a/src/Web/wwwroot/app/services/importService.js +++ b/src/Web/wwwroot/app/services/importService.js @@ -44,6 +44,9 @@ case 'keepercsv': importKeeperCsv(file, success, error); break; + case 'passworddragonxml': + importPasswordDragonXml(file, success, error); + break; default: error(); break; @@ -860,5 +863,124 @@ }); } + function importPasswordDragonXml(file, success, error) { + var folders = [], + sites = [], + folderRelationships = [], + foldersIndex = [], + j = 0; + + var reader = new FileReader(); + reader.readAsText(file, 'utf-8'); + reader.onload = function (evt) { + var xmlDoc = $.parseXML(evt.target.result), + xml = $(xmlDoc); + + var pwManager = xml.find('PasswordManager'); + if (pwManager.length) { + var records = pwManager.find('> record'); + if (records.length) { + for (var i = 0; i < records.length; i++) { + var record = $(records[i]); + + var accountNameNode = record.find('> Account-Name'), + accountName = accountNameNode.length ? $(accountNameNode) : null, + userIdNode = record.find('> User-Id'), + userId = userIdNode.length ? $(userIdNode) : null, + passwordNode = record.find('> Password'), + password = passwordNode.length ? $(passwordNode) : null, + urlNode = record.find('> URL'), + url = urlNode.length ? $(urlNode) : null, + notesNode = record.find('> Notes'), + notes = notesNode.length ? $(notesNode) : null, + categoryNode = record.find('> Category'), + category = categoryNode.length ? $(categoryNode) : null, + categoryText = category ? category.text() : null; + + var folderIndex = folders.length, + siteIndex = sites.length, + hasFolder = categoryText && categoryText !== '' && categoryText !== 'Unfiled', + addFolder = hasFolder; + + if (hasFolder) { + for (j = 0; j < folders.length; j++) { + if (folders[j].name === categoryText) { + addFolder = false; + folderIndex = j; + break; + } + } + } + + var site = { + favorite: false, + uri: url && url.text() !== '' ? trimUri(url.text()) : null, + username: userId && userId.text() !== '' ? userId.text() : null, + password: password && password.text() !== '' ? password.text() : null, + notes: notes && notes.text() !== '' ? notes.text() : null, + name: accountName && accountName.text() !== '' ? accountName.text() : '--', + }; + + var attributesSelector = ''; + for (j = 1; j <= 10; j++) { + attributesSelector += '> Attribute-' + j; + if (j < 10) { + attributesSelector += ', '; + } + } + + var attributes = record.find(attributesSelector); + if (attributes.length) { + // we have some attributes. add them to notes. + for (j = 0; j < attributes.length; j++) { + var attr = $(attributes[j]), + attrName = attr.prop('tagName'), + attrValue = attr.text(); + + if (!attrValue || attrValue === '' || attrValue === 'null') { + continue; + } + + if (site.notes === null) { + site.notes = ''; + } + else { + site.notes += '\n'; + } + + site.notes += (attrName + ': ' + attrValue); + } + } + + sites.push(site); + + if (addFolder) { + folders.push({ + name: categoryText + }); + } + + if (hasFolder) { + var relationship = { + key: siteIndex, + value: folderIndex + }; + folderRelationships.push(relationship); + } + } + } + + success(folders, sites, folderRelationships); + } + else { + error(); + } + }; + + reader.onerror = function (evt) { + error(); + }; + } + return _service; }); diff --git a/src/Web/wwwroot/app/tools/views/toolsImport.html b/src/Web/wwwroot/app/tools/views/toolsImport.html index 7be0c4837f..93e161960a 100644 --- a/src/Web/wwwroot/app/tools/views/toolsImport.html +++ b/src/Web/wwwroot/app/tools/views/toolsImport.html @@ -18,6 +18,7 @@ +