|
1
|
|
|
// Importers should always start with this |
|
2
|
|
|
var PassmanImporter = PassmanImporter || {}; |
|
|
|
|
|
|
3
|
|
|
(function(window, $, PassmanImporter) { |
|
4
|
|
|
'use strict'; |
|
5
|
|
|
PassmanImporter.passmanJson = { |
|
6
|
|
|
info: { |
|
7
|
|
|
name: 'Passman JSON', |
|
8
|
|
|
id: 'passmanJson', |
|
9
|
|
|
description: 'Export the item in passman as passman json, with all fields enabled' |
|
10
|
|
|
} |
|
11
|
|
|
}; |
|
12
|
|
|
|
|
13
|
|
|
PassmanImporter.passmanJson.readFile = function (file_data) { |
|
14
|
|
|
return new C_Promise(function(){ |
|
|
|
|
|
|
15
|
|
|
var parsed_json = PassmanImporter.readJson(file_data); |
|
16
|
|
|
var credential_list = []; |
|
17
|
|
|
for (var i = 0; i < parsed_json.length; i++) { |
|
18
|
|
|
var item = parsed_json[i]; |
|
19
|
|
|
var _credential = PassmanImporter.newCredential(); |
|
20
|
|
|
_credential.label = item.label; |
|
21
|
|
|
_credential.username = item.account; |
|
22
|
|
|
_credential.password = item.password; |
|
23
|
|
|
_credential.email = item.email; |
|
24
|
|
|
_credential.url = item.url; |
|
25
|
|
|
_credential.tags = item.tags; |
|
26
|
|
|
_credential.description = item.description; |
|
27
|
|
|
//Check for custom fields |
|
28
|
|
|
if (item.hasOwnProperty('customFields')) { |
|
29
|
|
|
//Check for otp |
|
30
|
|
|
if (item.customFields.length > 0) { |
|
31
|
|
|
for (var cf = 0; cf < item.customFields.length; cf++) { |
|
32
|
|
|
_credential.custom_fields.push( |
|
33
|
|
|
{ |
|
34
|
|
|
'label': item.customFields[cf].label, |
|
35
|
|
|
'value': item.customFields[cf].value, |
|
36
|
|
|
'secret': (item.customFields[cf].clicktoshow == '1') |
|
37
|
|
|
} |
|
38
|
|
|
) |
|
|
|
|
|
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
if (item.hasOwnProperty('otpsecret')) { |
|
43
|
|
|
if (item.otpsecret) { |
|
44
|
|
|
_credential.otp = { |
|
45
|
|
|
'issuer': item.otpsecret.issuer, |
|
46
|
|
|
'label': item.otpsecret.label, |
|
47
|
|
|
'qr_uri': { |
|
48
|
|
|
'image': item.otpsecret.qrCode, |
|
49
|
|
|
'qrData': '' |
|
50
|
|
|
}, |
|
51
|
|
|
'secret': item.otpsecret.secret, |
|
52
|
|
|
'type': item.otpsecret.type |
|
53
|
|
|
} |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
if(_credential.label){ |
|
57
|
|
|
credential_list.push(_credential); |
|
58
|
|
|
} |
|
59
|
|
|
var progress = { |
|
60
|
|
|
percent: i/parsed_json.length*100, |
|
61
|
|
|
loaded: i, |
|
62
|
|
|
total: parsed_json.length |
|
63
|
|
|
}; |
|
64
|
|
|
|
|
65
|
|
|
this.call_progress(progress); |
|
66
|
|
|
} |
|
67
|
|
|
this.call_then(credential_list); |
|
68
|
|
|
}); |
|
69
|
|
|
}; |
|
70
|
|
|
})(window, $, PassmanImporter); |
|
71
|
|
|
|