mirror of
https://github.com/nextcloud/passman.git
synced 2025-11-07 19:46:02 +08:00
Add Dashlane 4 csv importer
This commit is contained in:
parent
31a85bf673
commit
b916ce4290
6 changed files with 78 additions and 30 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
37
js/importers/importer-dashlanecsv.js
Normal file
37
js/importers/importer-dashlanecsv.js
Normal file
|
|
@ -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;
|
||||
};
|
||||
|
|
@ -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',
|
||||
'<div ng-controller="ImportCtrl"><div class="row"><div class="col-xs-12" ng-init="importerType"><label>Import type<select ng-model="importerType"><option ng-repeat="importer in available_importers" value="{{importer.value}}">{{importer.name}}</option></select></label><input ng-if="importerType" type="file" file-select success="fileLoaded" error="fileLoadError" progress="fileSelectProgress"><br><button class="button" ng-click="startImport(importerType)" ng-if="importerType">Import</button></div></div></div>');
|
||||
'<div ng-controller="ImportCtrl"><div class="row"><div class="col-xs-12"><label>Import type<select ng-init="importerType" ng-model="importerType" ng-change="setImporter(importerType)"><option ng-repeat="importer in available_importers" value="{{importer}}">{{importer.name}}</option></select></label><div><b>{{selectedImporter.description}}</b></div><input ng-if="selectedImporter" type="file" file-select success="fileLoaded" error="fileLoadError" progress="fileSelectProgress"><br><button class="button" ng-click="startImport()" ng-if="selectedImporter">Import</button></div></div></div>');
|
||||
}]);
|
||||
|
||||
angular.module('views/partials/forms/settings/tool.html', []).run(['$templateCache', function($templateCache) {
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ script('passman', 'app/directives/ngenter');
|
|||
script('passman', 'importers/import-main');
|
||||
script('passman', 'importers/importer-keepasscsv');
|
||||
script('passman', 'importers/importer-lastpasscsv');
|
||||
script('passman', 'importers/importer-dashlanecsv');
|
||||
|
||||
/*
|
||||
* Styles
|
||||
|
|
|
|||
|
|
@ -1,14 +1,15 @@
|
|||
<div ng-controller="ImportCtrl">
|
||||
<div class="row">
|
||||
<div class="col-xs-12" ng-init="importerType">
|
||||
<div class="col-xs-12" >
|
||||
<label>Import type
|
||||
<select ng-model="importerType">
|
||||
<option ng-repeat="importer in available_importers" value="{{importer.value}}">
|
||||
<select ng-init="importerType" ng-model="importerType" ng-change="setImporter(importerType)">
|
||||
<option ng-repeat="importer in available_importers" value="{{importer}}">
|
||||
{{importer.name}}
|
||||
</option>
|
||||
</select></label>
|
||||
<input ng-if="importerType" type="file" file-select success="fileLoaded" error="fileLoadError" progress="fileSelectProgress"><br />
|
||||
<button class="button" ng-click="startImport(importerType)" ng-if="importerType">Import</button>
|
||||
<div><b>{{selectedImporter.description}}</b></div>
|
||||
<input ng-if="selectedImporter" type="file" file-select success="fileLoaded" error="fileLoadError" progress="fileSelectProgress"><br />
|
||||
<button class="button" ng-click="startImport()" ng-if="selectedImporter">Import</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
Loading…
Add table
Reference in a new issue