diff --git a/js/importers/import-main.js b/js/importers/import-main.js index 42dcafa6..56100a4e 100644 --- a/js/importers/import-main.js +++ b/js/importers/import-main.js @@ -6,16 +6,22 @@ if(!window['PassmanImporter']){ PassmanImporter.parseRow_ = function(row, isHeading) { // Strip leading quote. row = row.trim(); + var isQuoted = false; if (row.charAt(0) == '"') { row = row.substring(1); + isQuoted = true; } if (row.charAt(row.length - 2) == '"') { row = row.substring(0, row.length - 2); + isQuoted = true; } // Strip trailing quote. There seems to be a character between the last quote // and the line ending, hence 2 instead of 1. - - row = row.split('","'); + if(isQuoted == true) { + row = row.split('","'); + } else { + row = row.split(','); + } return row; }; @@ -69,6 +75,7 @@ PassmanImporter.readCsv = function( csv ){ 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); diff --git a/js/importers/importer-lastpasscsv.js b/js/importers/importer-lastpasscsv.js new file mode 100644 index 00000000..047ba061 --- /dev/null +++ b/js/importers/importer-lastpasscsv.js @@ -0,0 +1,29 @@ +// Importers should always start with this +if (!window['PassmanImporter']) { + var PassmanImporter = {} +} +// Define the importer +PassmanImporter.lastpassCsv = { + info: { + name: 'LastPass csv', + id: 'lastpassCsv', + description: 'Create an csv export. Go to More options -> Advanced -> Export -> Last Pass CSV File' + } +}; + +PassmanImporter.lastpassCsv.readFile = function (file_data) { + var parsed_csv = PassmanImporter.readCsv(file_data); + var credential_list = []; + for (var i = 0; i < parsed_csv.length; i++) { + var row = parsed_csv[i]; + var _credential = PassmanImporter.newCredential(); + _credential.label = row.name; + _credential.username = row.username; + _credential.password = row.password; + _credential.url = row.url; + _credential.tags = [{text: row.grouping}]; + _credential.description = row.extra; + credential_list.push(_credential); + } + return credential_list; +}; \ No newline at end of file diff --git a/templates/main.php b/templates/main.php index 7d5eff7c..bc9d45cf 100644 --- a/templates/main.php +++ b/templates/main.php @@ -60,6 +60,7 @@ script('passman', 'app/directives/credentialfield'); script('passman', 'app/directives/ngenter'); script('passman', 'importers/import-main'); script('passman', 'importers/importer-keepasscsv'); +script('passman', 'importers/importer-lastpasscsv'); /* * Styles