1
|
|
|
/** |
2
|
|
|
* Nextcloud - passman |
3
|
|
|
* |
4
|
|
|
* @copyright Copyright (c) 2016, Sander Brand ([email protected]) |
5
|
|
|
* @copyright Copyright (c) 2016, Marcos Zuriaga Miguel ([email protected]) |
6
|
|
|
* @license GNU AGPL version 3 or any later version |
7
|
|
|
* |
8
|
|
|
* This program is free software: you can redistribute it and/or modify |
9
|
|
|
* it under the terms of the GNU Affero General Public License as |
10
|
|
|
* published by the Free Software Foundation, either version 3 of the |
11
|
|
|
* License, or (at your option) any later version. |
12
|
|
|
* |
13
|
|
|
* This program is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
* GNU Affero General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU Affero General Public License |
19
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
20
|
|
|
* |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
// Importers should always start with this |
24
|
|
|
/** global: PassmanImporter */ |
25
|
|
|
var PassmanImporter = PassmanImporter || {}; |
|
|
|
|
26
|
|
|
(function(window, $, PassmanImporter) { |
27
|
|
|
'use strict'; |
28
|
|
|
// Define the importer |
29
|
|
|
PassmanImporter.EnPassTXT = { |
30
|
|
|
info: { |
31
|
|
|
name: 'EnPass text file', |
32
|
|
|
id: 'EnPassTXT', |
33
|
|
|
description: 'Access your Enpass Database. Select "File" > "Export" > "As Text"' |
34
|
|
|
} |
35
|
|
|
}; |
36
|
|
|
|
37
|
|
|
function parseEnpass(fileData){ |
38
|
|
|
var lastProperty, matches,loginBlocks; |
39
|
|
|
loginBlocks = fileData.replaceAll("Title :","<~passman~>\nTitle :").split('<~passman~>\n').clean(""); |
40
|
|
|
var regex = /(.*) : (.*)/; |
41
|
|
|
var results = []; |
42
|
|
|
for(var l = 0; l < loginBlocks.length; l++){ |
43
|
|
|
var loginBlock = loginBlocks[l]; |
44
|
|
|
var lrow = loginBlock.split('\n'); |
45
|
|
|
var result = {}; |
46
|
|
|
for(var r = 0; r < lrow.length; r++){ |
47
|
|
|
var row = lrow[r]; |
48
|
|
|
matches = regex.exec(row); |
49
|
|
|
if(matches){ |
50
|
|
|
var property = matches[1]; |
51
|
|
|
result[property] = matches[2]; |
52
|
|
|
} else { |
53
|
|
|
if(lastProperty){ |
54
|
|
|
result[lastProperty] += "\n" + row; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
lastProperty = property; |
|
|
|
|
58
|
|
|
} |
59
|
|
|
results.push(result) |
|
|
|
|
60
|
|
|
} |
61
|
|
|
return results |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
PassmanImporter.EnPassTXT.readFile = function (file_data) { |
65
|
|
|
var mapper = { |
66
|
|
|
'Title': 'label', |
67
|
|
|
'Username': 'username', |
68
|
|
|
'Password': 'password', |
69
|
|
|
'Email': 'email', |
70
|
|
|
'Url': 'url', |
71
|
|
|
'Note': 'description' |
72
|
|
|
}; |
73
|
|
|
|
74
|
|
|
var secret_fields = ['cvc', 'pin', 'security answer']; |
75
|
|
|
|
76
|
|
|
return new C_Promise(function(){ |
|
|
|
|
77
|
|
|
var credential_list = []; |
78
|
|
|
var credentials = parseEnpass(file_data); |
79
|
|
|
for (var i = 0; i < credentials.length; i++) { |
80
|
|
|
var enpass_credential = credentials[i]; |
81
|
|
|
var new_credential = PassmanImporter.newCredential(); |
82
|
|
|
for(var key in enpass_credential){ |
83
|
|
|
if(!enpass_credential.hasOwnProperty(key)){ |
84
|
|
|
continue; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
if(mapper.hasOwnProperty(key)){ |
88
|
|
|
var prop = mapper[key]; |
89
|
|
|
new_credential[prop] = enpass_credential[key]; |
90
|
|
|
} else { |
91
|
|
|
var isSecret = (secret_fields.indexOf(key.toLowerCase()) !== -1) ? 1 : 0; |
92
|
|
|
new_credential.custom_fields.push({ |
93
|
|
|
'label': key, |
94
|
|
|
'value': enpass_credential[key], |
95
|
|
|
'secret': isSecret |
96
|
|
|
}) |
|
|
|
|
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
if(enpass_credential.hasOwnProperty('TOTP')){ |
101
|
|
|
new_credential.otp.secret = enpass_credential['TOTP']; |
|
|
|
|
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
var progress = { |
105
|
|
|
percent: i/credentials.length*100, |
106
|
|
|
loaded: i, |
107
|
|
|
total: credentials.length |
108
|
|
|
}; |
109
|
|
|
|
110
|
|
|
credential_list.push(new_credential); |
111
|
|
|
this.call_progress(progress); |
112
|
|
|
} |
113
|
|
|
this.call_then(credential_list); |
114
|
|
|
}); |
115
|
|
|
}; |
116
|
|
|
})(window, $, PassmanImporter); |