msecure csv importer

This commit is contained in:
Kyle Spearrin 2016-12-29 02:33:37 -05:00
parent 6bf6cc365b
commit 8649c3b2b1
2 changed files with 90 additions and 0 deletions

View File

@ -59,6 +59,9 @@
case 'stickypasswordxml':
importStickyPasswordXml(file, success, error);
break;
case 'msecurecsv':
importmSecureCsv(file, success, error);
break;
default:
error();
break;
@ -1382,5 +1385,91 @@
};
}
function importmSecureCsv(file, success, error) {
Papa.parse(file, {
encoding: 'UTF-8',
complete: function (results) {
parseCsvErrors(results);
var folders = [],
sites = [],
folderRelationships = [];
angular.forEach(results.data, function (value, key) {
if (value.length >= 3) {
var folderIndex = folders.length,
siteIndex = sites.length,
hasFolder = value[0] && value[0] !== '' && value[0] !== 'Unassigned',
addFolder = hasFolder,
i = 0;
if (hasFolder) {
for (i = 0; i < folders.length; i++) {
if (folders[i].name === value[0]) {
addFolder = false;
folderIndex = i;
break;
}
}
}
var site = {
favorite: false,
uri: null,
username: null,
password: null,
notes: '',
name: value[2] && value[2] !== '' ? value[2] : null
};
if (value[1] === 'Web Logins') {
site.uri = value[4] && value[4] !== '' ? trimUri(value[4]) : null;
site.username = value[5] && value[5] !== '' ? value[5] : null;
site.password = value[6] && value[6] !== '' ? value[6] : null;
site.notes = value[3] && value[3] !== '' ? value[3] : null;
}
else if (value.length > 3) {
for (var j = 3; j < value.length; j++) {
if (value[j] && value[j] !== '') {
if (site.notes !== '') {
site.notes = site.notes + '\n';
}
site.notes = site.notes + value[j];
}
}
}
if (value[1] && value[1] !== '' && value[1] !== 'Web Logins') {
site.name = value[1] + ': ' + site.name;
}
if (site.notes === '') {
site.notes = null;
}
sites.push(site);
if (addFolder) {
folders.push({
name: value[0]
});
}
if (hasFolder) {
var relationship = {
key: siteIndex,
value: folderIndex
};
folderRelationships.push(relationship);
}
}
});
success(folders, sites, folderRelationships);
}
});
}
return _service;
});

View File

@ -23,6 +23,7 @@
<option value="enpasscsv">Enpass (csv)</option>
<option value="pwsafexml">Password Safe (xml)</option>
<option value="stickypasswordxml">Sticky Password (xml)</option>
<option value="msecurecsv">mSecure (csv)</option>
</select>
</div>
<div class="form-group">