passman/js/importers/importer-randomdata.js

82 lines
1.9 KiB
JavaScript
Raw Normal View History

// Importers should always start with this
if (!window['PassmanImporter']) {
var PassmanImporter = {}
}
// Define the importer
PassmanImporter.randomData = {
info: {
name: 'Random data',
id: 'randomData',
description: 'Create\'s 10 random credentials for testing purposes.'
}
};
2016-09-27 00:17:42 +08:00
PassmanImporter.randomData.readFile = function (file_data, callback) {
return new C_Promise(function () {
2016-09-26 23:42:41 +08:00
var tags =
['Social media',
'Hosting',
'Forums',
'Webshops',
'FTP',
'SSH',
'Banking',
'Applications',
'Server stuff',
'mysql',
'Wifi',
'Games',
'Certificate',
'Serials'
];
2016-09-26 23:42:41 +08:00
var label;
var credential_list = [];
var _this = this;
var generateCredential = function (max, i, callback) {
2016-09-27 00:17:42 +08:00
if (jQuery) {
2016-09-26 23:42:41 +08:00
var url = OC.generateUrl('apps/passman/api/internal/generate_person');
$.ajax({
url: url,
dataType: 'json',
2016-09-27 00:17:42 +08:00
success: function (data) {
2016-09-26 23:42:41 +08:00
var _credential = PassmanImporter.newCredential();
2016-09-27 00:17:42 +08:00
label = (Math.random() >= 0.5) ? data.domain : data.email_d + ' - ' + data.email_u;
2016-09-26 23:42:41 +08:00
_credential.label = label;
_credential.username = data.username;
_credential.password = data.password;
_credential.url = data.url;
2016-09-27 00:17:42 +08:00
var tag_amount = Math.floor(Math.random() * 5);
for (var ta = 0; ta < tag_amount; ta++) {
var item = tags[Math.floor(Math.random() * tags.length)];
2016-09-26 23:42:41 +08:00
var tag = {
text: item
};
2016-09-27 00:17:42 +08:00
if (_credential.tags.indexOf(tag) === -1) {
2016-09-26 23:42:41 +08:00
_credential.tags.push(tag);
}
}
credential_list.push(_credential);
2016-09-27 00:17:42 +08:00
if (i <= max) {
var values = {
percent: i / max * 100,
loaded: i,
total: max
};
_this.call_progress(values);
2016-09-26 23:42:41 +08:00
generateCredential(max, i + 1, callback)
} else {
callback(credential_list)
}
}
2016-09-26 23:42:41 +08:00
});
}
};
2016-09-27 00:17:42 +08:00
generateCredential(10, 1, function (credential_list) {
2016-09-26 23:42:41 +08:00
_this.call_then(credential_list);
});
});
};