1
|
|
|
// Importers should always start with this |
2
|
|
|
var PassmanImporter = PassmanImporter || {}; |
|
|
|
|
3
|
|
|
(function(window, $, PassmanImporter) { |
4
|
|
|
'use strict'; |
5
|
|
|
// Define the importer |
6
|
|
|
|
7
|
|
|
// Define the importer |
8
|
|
|
PassmanImporter.randomData = { |
9
|
|
|
info: { |
10
|
|
|
name: 'Random data', |
11
|
|
|
id: 'randomData', |
12
|
|
|
description: 'Create\'s 50 random credentials for testing purposes.' |
13
|
|
|
} |
14
|
|
|
}; |
15
|
|
|
|
16
|
|
|
PassmanImporter.randomData.readFile = function () { |
17
|
|
|
return new C_Promise(function () { |
|
|
|
|
18
|
|
|
var tags = |
19
|
|
|
['Social media', |
20
|
|
|
'Hosting', |
21
|
|
|
'Forums', |
22
|
|
|
'Webshops', |
23
|
|
|
'FTP', |
24
|
|
|
'SSH', |
25
|
|
|
'Banking', |
26
|
|
|
'Applications', |
27
|
|
|
'Server stuff', |
28
|
|
|
'mysql', |
29
|
|
|
'Wifi', |
30
|
|
|
'Games', |
31
|
|
|
'Certificate', |
32
|
|
|
'Serials' |
33
|
|
|
]; |
34
|
|
|
var label; |
35
|
|
|
var credential_list = []; |
36
|
|
|
var _this = this; |
37
|
|
|
var generateCredential = function (max, i, callback) { |
38
|
|
|
if (jQuery) { |
39
|
|
|
var url = OC.generateUrl('apps/passman/api/internal/generate_person'); |
40
|
|
|
$.ajax({ |
41
|
|
|
url: url, |
42
|
|
|
dataType: 'json', |
43
|
|
|
success: function (data) { |
44
|
|
|
if(data) { |
45
|
|
|
var _credential = PassmanImporter.newCredential(); |
46
|
|
|
label = (Math.random() >= 0.5) ? data.domain : data.email_d + ' - ' + data.email_u; |
47
|
|
|
_credential.label = label; |
48
|
|
|
_credential.username = data.username; |
49
|
|
|
_credential.password = data.password; |
50
|
|
|
_credential.url = data.url; |
51
|
|
|
|
52
|
|
|
var tag_amount = Math.floor(Math.random() * 5); |
53
|
|
|
var ta = 0; |
54
|
|
|
var _tags = []; |
55
|
|
|
while (ta < tag_amount) { |
56
|
|
|
var item = tags[Math.floor(Math.random() * tags.length)]; |
57
|
|
|
if (_tags.indexOf(item) === -1) { |
58
|
|
|
_tags.push(item); |
59
|
|
|
ta++ |
|
|
|
|
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
_credential.tags = _tags.map(function (item) { |
63
|
|
|
if (item) { |
|
|
|
|
64
|
|
|
return {text: item} |
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
}).filter(function (item) { |
68
|
|
|
return (item); |
69
|
|
|
}); |
70
|
|
|
credential_list.push(_credential); |
71
|
|
|
|
72
|
|
|
if (i < max) { |
73
|
|
|
var progress = { |
74
|
|
|
percent: i / max * 100, |
75
|
|
|
loaded: i, |
76
|
|
|
total: max |
77
|
|
|
}; |
78
|
|
|
_this.call_progress(progress); |
79
|
|
|
generateCredential(max, i + 1, callback) |
|
|
|
|
80
|
|
|
} else { |
81
|
|
|
callback(credential_list) |
|
|
|
|
82
|
|
|
} |
83
|
|
|
} else { |
84
|
|
|
generateCredential(max, i , callback) |
|
|
|
|
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
}); |
88
|
|
|
} |
89
|
|
|
}; |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
generateCredential(50, 1, function (credential_list) { |
93
|
|
|
_this.call_then(credential_list); |
94
|
|
|
}); |
95
|
|
|
}); |
96
|
|
|
}; |
97
|
|
|
})(window, $, PassmanImporter); |