1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-29 12:55:21 +01:00

import for safeincloud xml

This commit is contained in:
Kyle Spearrin 2016-10-14 23:50:39 -04:00
parent 7b88d30aa8
commit 30d19b4ee1
2 changed files with 101 additions and 1 deletions

View File

@ -15,6 +15,9 @@
case 'safeincloudcsv':
importSafeInCloudCsv(file, success, error);
break;
case 'safeincloudxml':
importSafeInCloudXml(file, success, error);
break;
case 'keypassxml':
importKeyPassXml(file, success, error);
break;
@ -209,6 +212,102 @@
});
}
function importSafeInCloudXml(file, success, error) {
var folders = [],
sites = [],
siteRelationships = [],
foldersIndex = [];
var i = 0,
j = 0;
var reader = new FileReader();
reader.readAsText(file, 'utf-8');
reader.onload = function (evt) {
var xmlDoc = $.parseXML(evt.target.result),
xml = $(xmlDoc);
var db = xml.find('database');
if (db.length) {
var labels = db.find('> label');
if (labels.length) {
for (i = 0; i < labels.length; i++) {
var label = $(labels[i]);
foldersIndex[label.attr('id')] = folders.length;
folders.push({
name: label.attr('name')
});
}
}
var cards = db.find('> card');
if (cards.length) {
for (i = 0; i < cards.length; i++) {
var card = $(cards[i]);
if (card.attr('template') === 'true') {
continue;
}
var site = {
favorite: false,
uri: null,
username: null,
password: null,
notes: null,
name: card.attr('title'),
};
var fields = card.find('> field');
for (j = 0; j < fields.length; j++) {
var field = $(fields[j]);
var text = field.text();
var type = field.attr('type');
if (text && text !== '') {
if (type === 'login') {
site.username = text;
}
else if (type === 'password') {
site.password = text;
}
else if (type === 'notes') {
site.notes = text;
}
else if (type === 'website') {
site.uri = text;
}
}
}
sites.push(site);
labels = card.find('> label_id');
if (labels.length) {
var labelId = $(labels[0]).text();
var folderIndex = foldersIndex[labelId];
if (labelId !== null && labelId !== '' && folderIndex !== null) {
siteRelationships.push({
key: sites.length - 1,
value: folderIndex
});
}
}
}
}
success(folders, sites, siteRelationships);
}
else {
error();
}
};
reader.onerror = function (evt) {
error();
};
}
function importPadlockCsv(file, success, error) {
Papa.parse(file, {
complete: function (results) {

View File

@ -9,7 +9,8 @@
<select id="source" name="source" class="form-control" ng-model="model.source">
<option value="local">bitwarden (csv)</option>
<option value="lastpass">LastPass (csv)</option>
<option value="safeincloudcsv">SafeInCloud (csv)</option>
<option value="safeincloudxml">SafeInCloud (xml)</option>
<option value="safeincloud">SafeInCloud (csv)</option>
<option value="keypassxml">KeyPass (xml)</option>
<option value="padlockcsv">Padlock (csv)</option>
<option value="1password1pif">1Password (1pif)</option>