|
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
|
|
|
* @copyright Copyright (c) 2017, Bingen Eguzkitza ([email protected]) |
|
7
|
|
|
* @license GNU AGPL version 3 or any later version |
|
8
|
|
|
* |
|
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
12
|
|
|
* License, or (at your option) any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU Affero General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
// TODO: Allow for new lines and commas in values |
|
25
|
|
|
|
|
26
|
|
|
// Importers should always start with this |
|
27
|
|
|
/** global: PassmanImporter */ |
|
28
|
|
|
var PassmanImporter = PassmanImporter || {}; |
|
29
|
|
|
(function(window, $, PassmanImporter) { |
|
30
|
|
|
'use strict'; |
|
31
|
|
|
// Define the importer |
|
32
|
|
|
PassmanImporter.padlock = { |
|
33
|
|
|
info: { |
|
34
|
|
|
name: 'Padlock', |
|
35
|
|
|
id: 'padlock', |
|
36
|
|
|
exportSteps: ['Create a csv export. Go to Menu -> Settings -> Export Data and copy text into a .csv file'] |
|
37
|
|
|
} |
|
38
|
|
|
}; |
|
39
|
|
|
|
|
40
|
|
|
PassmanImporter.padlock.readFile = function (file_data) { |
|
41
|
|
|
/** global: C_Promise */ |
|
42
|
|
|
return new C_Promise(function(){ |
|
43
|
|
|
var rows = file_data.split('\n'); |
|
44
|
|
|
var credential_list = []; |
|
45
|
|
|
var titles = rows[0].split(','); |
|
46
|
|
|
for (var i = 1; i < rows.length; i++) { |
|
47
|
|
|
var row = rows[i]; |
|
48
|
|
|
var row_data = row.split(','); |
|
49
|
|
|
if (row_data[0].charAt(0) === '"') { |
|
50
|
|
|
row_data[0] = row_data[0].substring(1); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
if (row_data[row_data.length-1].toString().charAt(row_data[row_data.length - 1].length - 1) === '"') { |
|
54
|
|
|
row_data[row_data.length - 1] = row_data[row_data.length -1].substring(0, row_data[row_data.length - 1].length - 1); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
var _credential = PassmanImporter.newCredential(); |
|
58
|
|
|
_credential.label = row_data[0]; |
|
59
|
|
|
_credential.username = row_data[2]; |
|
60
|
|
|
_credential.password = row_data[3]; |
|
61
|
|
|
var k = 0; |
|
62
|
|
|
for (var j = 4; j < titles.length; j++) { |
|
63
|
|
|
if (!row_data[j]) |
|
64
|
|
|
continue; |
|
|
|
|
|
|
65
|
|
|
if (titles[j].toLowerCase() == 'url') { |
|
66
|
|
|
_credential.url = row_data[j]; |
|
67
|
|
|
continue; |
|
68
|
|
|
} |
|
69
|
|
|
if (titles[j].toLowerCase() == 'e-mail' |
|
70
|
|
|
|| titles[j].toLowerCase() == 'email') { |
|
|
|
|
|
|
71
|
|
|
_credential.email = row_data[j]; |
|
72
|
|
|
continue; |
|
73
|
|
|
} |
|
74
|
|
|
if (titles[j].toLowerCase() == 'description') { |
|
75
|
|
|
_credential.description = row_data[j]; |
|
76
|
|
|
continue; |
|
77
|
|
|
} |
|
78
|
|
|
_credential.custom_fields[k] = { |
|
79
|
|
|
'label' : titles[j], |
|
80
|
|
|
'value' : row_data[j], |
|
81
|
|
|
'secret' : true, |
|
82
|
|
|
'field_type' : 'text' |
|
83
|
|
|
}; |
|
84
|
|
|
k++; |
|
85
|
|
|
} |
|
86
|
|
|
if(_credential.label){ |
|
87
|
|
|
credential_list.push(_credential); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
var progress = { |
|
91
|
|
|
percent: i/rows.length*100, |
|
92
|
|
|
loaded: i, |
|
93
|
|
|
total: rows.length |
|
94
|
|
|
}; |
|
95
|
|
|
this.call_progress(progress); |
|
96
|
|
|
} |
|
97
|
|
|
this.call_then(credential_list); |
|
98
|
|
|
}); |
|
99
|
|
|
}; |
|
100
|
|
|
})(window, $, PassmanImporter); |
|
101
|
|
|
|
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.
Consider:
If you or someone else later decides to put another statement in, only the first statement will be executed.
In this case the statement
b = 42will always be executed, while the logging statement will be executed conditionally.ensures that the proper code will be executed conditionally no matter how many statements are added or removed.