diff --git a/js/app/controllers/import.js b/js/app/controllers/import.js index d30d829b..697287dc 100644 --- a/js/app/controllers/import.js +++ b/js/app/controllers/import.js @@ -11,23 +11,26 @@ angular.module('passmanApp') .controller('ImportCtrl', ['$scope', '$window', function ($scope, $window) { //@TODo read the available importers from $window.PassmanImporter $scope.available_importers = [ - { - name: 'KeePass CSV', - value: 'keepassCsv' - }, - { - name: 'LastPass CSV', - value: 'lastpassCsv' - }, - { - name: 'Passman CSV', - value: 'passmanCsv' - }, - { - name: 'Passman JSON', - value: 'passmanJson' - } + ]; + + + $scope.$watch(function(){ + return $window.PassmanImporter; + }, function (importers) { + for(var key in importers){ + var importer = importers[key]; + if(importer.hasOwnProperty('info')){ + $scope.available_importers.push(importer.info); + } + } + }, true); + + $scope.setImporter = function (importer) { + importer = JSON.parse(importer); + $scope.selectedImporter = importer; + }; + var file_data; $scope.fileLoaded = function (file) { file_data = file.data.split(','); @@ -41,9 +44,9 @@ angular.module('passmanApp') }; - $scope.startImport = function(importerType){ + $scope.startImport = function(){ if(file_data){ - var parsed_data = $window.PassmanImporter[importerType].readFile(file_data); + var parsed_data = $window.PassmanImporter[$scope.selectedImporter.id].readFile(file_data); console.log('Data parsed!', parsed_data); } } diff --git a/js/importers/import-main.js b/js/importers/import-main.js index 56100a4e..a8e62d5d 100644 --- a/js/importers/import-main.js +++ b/js/importers/import-main.js @@ -71,14 +71,20 @@ PassmanImporter.newCredential = function () { return credential; }; -PassmanImporter.readCsv = function( csv ){ +PassmanImporter.readCsv = function( csv, hasHeadings ){ + hasHeadings = (hasHeadings === undefined) ? true : hasHeadings; var lines = []; var rows = csv.split('\n'); - var headings = this.parseRow_(rows[0]); - - for (var i = 1, row; row = rows[i]; i++) { - row = this.toObject_(headings, this.parseRow_(row)); - lines.push(row); + if(hasHeadings) { + var headings = this.parseRow_(rows[0]); + for (var i = 1, row; row = rows[i]; i++) { + row = this.toObject_(headings, this.parseRow_(row)); + lines.push(row); + } + } else { + for (var i = 1, row; row = rows[i]; i++) { + lines.push(this.parseRow_(row)); + } } return lines; }; \ No newline at end of file diff --git a/js/importers/importer-dashlanecsv.js b/js/importers/importer-dashlanecsv.js new file mode 100644 index 00000000..2ff9e8a5 --- /dev/null +++ b/js/importers/importer-dashlanecsv.js @@ -0,0 +1,37 @@ +// Importers should always start with this +if (!window['PassmanImporter']) { + var PassmanImporter = {} +} +// Define the importer +PassmanImporter.dashLaneCsv = { + info: { + name: 'Dashlane 4 csv', + id: 'dashLaneCsv', + description: 'Create an csv export. Go to File -> export -> Unsecured archive (readable) in CSV format' + } +}; + +PassmanImporter.dashLaneCsv.readFile = function (file_data) { + var rows = file_data.split('\n'); + var credential_list = []; + for (var i = 1, row; row = rows[i]; i++) { + row = rows[i]; + var row_data = row.split('","'); + if (row_data[0].charAt(0) == '"') { + row_data[0] = row_data[0].substring(1); + } + + if (row_data[row_data.length-1].toString().charAt(row_data[row_data.length - 1].length - 1) == '"') { + row_data[row_data.length - 1] = row_data[row_data.length -1].substring(0, row_data[row_data.length - 1].length - 1); + } + + var _credential = PassmanImporter.newCredential(); + _credential.label = row_data[0]; + _credential.username = row_data[2]; + _credential.password = row_data[row_data.length - 2]; + _credential.url = row_data[0]; + _credential.description = row_data[row_data.length - 1]; + credential_list.push(_credential); + } + return credential_list; +}; \ No newline at end of file diff --git a/js/templates.js b/js/templates.js index aa8b34f3..c1f46d67 100644 --- a/js/templates.js +++ b/js/templates.js @@ -57,7 +57,7 @@ angular.module('views/partials/forms/settings/general_settings.html', []).run([' angular.module('views/partials/forms/settings/import.html', []).run(['$templateCache', function($templateCache) { 'use strict'; $templateCache.put('views/partials/forms/settings/import.html', - '