summaryrefslogtreecommitdiff
path: root/frontend/beta/js/Clipperz/KeePassExportProcessor.js
Unidiff
Diffstat (limited to 'frontend/beta/js/Clipperz/KeePassExportProcessor.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/beta/js/Clipperz/KeePassExportProcessor.js22
1 files changed, 10 insertions, 12 deletions
diff --git a/frontend/beta/js/Clipperz/KeePassExportProcessor.js b/frontend/beta/js/Clipperz/KeePassExportProcessor.js
index 74d36ca..7a32f3f 100644
--- a/frontend/beta/js/Clipperz/KeePassExportProcessor.js
+++ b/frontend/beta/js/Clipperz/KeePassExportProcessor.js
@@ -1,214 +1,212 @@
1/* 1/*
2 2
3Copyright 2008-2011 Clipperz Srl 3Copyright 2008-2013 Clipperz Srl
4 4
5This file is part of Clipperz Community Edition. 5This file is part of Clipperz, the online password manager.
6Clipperz Community Edition is an online password manager.
7For further information about its features and functionalities please 6For further information about its features and functionalities please
8refer to http://www.clipperz.com. 7refer to http://www.clipperz.com.
9 8
10* Clipperz Community Edition is free software: you can redistribute 9* Clipperz is free software: you can redistribute it and/or modify it
11 it and/or modify it under the terms of the GNU Affero General Public 10 under the terms of the GNU Affero General Public License as published
12 License as published by the Free Software Foundation, either version 11 by the Free Software Foundation, either version 3 of the License, or
13 3 of the License, or (at your option) any later version. 12 (at your option) any later version.
14 13
15* Clipperz Community Edition is distributed in the hope that it will 14* Clipperz is distributed in the hope that it will be useful, but
16 be useful, but WITHOUT ANY WARRANTY; without even the implied 15 WITHOUT ANY WARRANTY; without even the implied warranty of
17 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU Affero General Public License for more details. 17 See the GNU Affero General Public License for more details.
19 18
20* You should have received a copy of the GNU Affero General Public 19* You should have received a copy of the GNU Affero General Public
21 License along with Clipperz Community Edition. If not, see 20 License along with Clipperz. If not, see http://www.gnu.org/licenses/.
22 <http://www.gnu.org/licenses/>.
23 21
24*/ 22*/
25 23
26if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } 24if (typeof(Clipperz) == 'undefined') { Clipperz = {}; }
27 25
28 26
29Clipperz.KeePassExportProcessor = function(args) { 27Clipperz.KeePassExportProcessor = function(args) {
30 args = args || {}; 28 args = args || {};
31 29
32 return this; 30 return this;
33} 31}
34 32
35//============================================================================= 33//=============================================================================
36 34
37Clipperz.KeePassExportProcessor.prototype = MochiKit.Base.update(null, { 35Clipperz.KeePassExportProcessor.prototype = MochiKit.Base.update(null, {
38 36
39 //------------------------------------------------------------------------- 37 //-------------------------------------------------------------------------
40/* 38/*
41 'parse': function(aValue) { 39 'parse': function(aValue) {
42 var result; 40 var result;
43 41
44//MochiKit.Logging.logDebug(">>> KeePassExportProcessor.parse"); 42//MochiKit.Logging.logDebug(">>> KeePassExportProcessor.parse");
45 result = []; 43 result = [];
46//MochiKit.Logging.logDebug("--- KeePassExportProcessor.parse - result: " + Clipperz.Base.serializeJSON(result)); 44//MochiKit.Logging.logDebug("--- KeePassExportProcessor.parse - result: " + Clipperz.Base.serializeJSON(result));
47//MochiKit.Logging.logDebug("<<< KeePassExportProcessor.parse"); 45//MochiKit.Logging.logDebug("<<< KeePassExportProcessor.parse");
48 46
49 return result; 47 return result;
50 }, 48 },
51*/ 49*/
52 //------------------------------------------------------------------------- 50 //-------------------------------------------------------------------------
53 51
54 'deferredParse_core': function(aContext) { 52 'deferredParse_core': function(aContext) {
55 var deferredResult; 53 var deferredResult;
56 54
57 //MochiKit.Logging.logDebug(">>> KeePassExportProcessor.deferredParse_core"); 55 //MochiKit.Logging.logDebug(">>> KeePassExportProcessor.deferredParse_core");
58 //MochiKit.Logging.logDebug("--- KeePassExportProcessor.deferredParse_core - (1) aContext.line: " + aContext.line.replace(/\n/g, "\\n").substring(0,50)); 56 //MochiKit.Logging.logDebug("--- KeePassExportProcessor.deferredParse_core - (1) aContext.line: " + aContext.line.replace(/\n/g, "\\n").substring(0,50));
59 //MochiKit.Logging.logDebug("--- KeePassExportProcessor.deferredParse_core - aContext: " + Clipperz.Base.serializeJSON(aContext).substring(0,50)); 57 //MochiKit.Logging.logDebug("--- KeePassExportProcessor.deferredParse_core - aContext: " + Clipperz.Base.serializeJSON(aContext).substring(0,50));
60 //MochiKit.Logging.logDebug("--- KeePassExportProcessor.deferredParse_core - (2) aContext.line: " + aContext.line.replace(/\n/g, "\\n").substring(0,50)); 58 //MochiKit.Logging.logDebug("--- KeePassExportProcessor.deferredParse_core - (2) aContext.line: " + aContext.line.replace(/\n/g, "\\n").substring(0,50));
61//console.log("deferredParse_core - aContext", aContext); 59//console.log("deferredParse_core - aContext", aContext);
62 //MochiKit.Logging.logDebug("--- KeePassExportProcessor.deferredParse_core - (3) aContext.line: " + aContext.line.replace(/\n/g, "\\n").substring(0,50)); 60 //MochiKit.Logging.logDebug("--- KeePassExportProcessor.deferredParse_core - (3) aContext.line: " + aContext.line.replace(/\n/g, "\\n").substring(0,50));
63 if (aContext.line == "") { 61 if (aContext.line == "") {
64 deferredResult = MochiKit.Async.succeed(aContext.result); 62 deferredResult = MochiKit.Async.succeed(aContext.result);
65 } else { 63 } else {
66 var record; 64 var record;
67 65
68 record = this.parseRecord(aContext); 66 record = this.parseRecord(aContext);
69 if (record != null) { 67 if (record != null) {
70 aContext.result.push(record); 68 aContext.result.push(record);
71 } 69 }
72 70
73 //MochiKit.Logging.logDebug("--> KeePassExportProcessor.deferredParse_core - aContext.line: " + aContext.line.replace(/\n/g, "\\n").substring(0,50)); 71 //MochiKit.Logging.logDebug("--> KeePassExportProcessor.deferredParse_core - aContext.line: " + aContext.line.replace(/\n/g, "\\n").substring(0,50));
74 aContext.line = aContext.line.replace(/^\n*/g, "").replace(/\n$/g, ""); 72 aContext.line = aContext.line.replace(/^\n*/g, "").replace(/\n$/g, "");
75 //MochiKit.Logging.logDebug("<-- KeePassExportProcessor.deferredParse_core - aContext.line: " + aContext.line.replace(/\n/g, "\\n").substring(0,50)); 73 //MochiKit.Logging.logDebug("<-- KeePassExportProcessor.deferredParse_core - aContext.line: " + aContext.line.replace(/\n/g, "\\n").substring(0,50));
76 74
77 deferredResult = new MochiKit.Async.Deferred(); 75 deferredResult = new MochiKit.Async.Deferred();
78//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassExportProcessor.deferredParse_core - 1.1 " + res); return res;}); 76//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassExportProcessor.deferredParse_core - 1.1 " + res); return res;});
79 deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'importProcessorProgressUpdate', {status:'processing', size:aContext.size, progress:(aContext.size - aContext.line.length)}); 77 deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'importProcessorProgressUpdate', {status:'processing', size:aContext.size, progress:(aContext.size - aContext.line.length)});
80//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassExportProcessor.deferredParse_core - 1.2 " + res); return res;}); 78//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassExportProcessor.deferredParse_core - 1.2 " + res); return res;});
81 deferredResult.addCallback(MochiKit.Async.wait, 0.2); 79 deferredResult.addCallback(MochiKit.Async.wait, 0.2);
82//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassExportProcessor.deferredParse_core - 1.3 " + res); return res;}); 80//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassExportProcessor.deferredParse_core - 1.3 " + res); return res;});
83//deferredResult.addBoth(function(res) {console.log("KeePassExportProcessor.deferredParse_core - 1.3 ", res); return res;}); 81//deferredResult.addBoth(function(res) {console.log("KeePassExportProcessor.deferredParse_core - 1.3 ", res); return res;});
84 deferredResult.addCallback(MochiKit.Base.method(this, 'deferredParse_core')) 82 deferredResult.addCallback(MochiKit.Base.method(this, 'deferredParse_core'))
85//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassExportProcessor.deferredParse_core - 1.4 " + res); return res;}); 83//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassExportProcessor.deferredParse_core - 1.4 " + res); return res;});
86 deferredResult.callback(aContext); 84 deferredResult.callback(aContext);
87 } 85 }
88 //MochiKit.Logging.logDebug("<<< KeePassExportProcessor.deferredParse_core"); 86 //MochiKit.Logging.logDebug("<<< KeePassExportProcessor.deferredParse_core");
89 87
90 return deferredResult; 88 return deferredResult;
91 }, 89 },
92 90
93 //......................................................................... 91 //.........................................................................
94 92
95 'deferredParse': function(aValue) { 93 'deferredParse': function(aValue) {
96 var deferredResult; 94 var deferredResult;
97 var lines; 95 var lines;
98 var context; 96 var context;
99 97
100//MochiKit.Logging.logDebug(">>> KeePassExportProcessor.deferredParse"); 98//MochiKit.Logging.logDebug(">>> KeePassExportProcessor.deferredParse");
101//MochiKit.Logging.logDebug("--- KeePassExportProcessor.deferredParse - aValue: " + aValue.length); 99//MochiKit.Logging.logDebug("--- KeePassExportProcessor.deferredParse - aValue: " + aValue.length);
102 lines = aValue.replace(/\r?\n/g, "\n"); 100 lines = aValue.replace(/\r?\n/g, "\n");
103//MochiKit.Logging.logDebug("--- KeePassExportProcessor.deferredParse - lines: " + lines.length); 101//MochiKit.Logging.logDebug("--- KeePassExportProcessor.deferredParse - lines: " + lines.length);
104 context = { 102 context = {
105 line: lines, 103 line: lines,
106 size: lines.length, 104 size: lines.length,
107 result: [] 105 result: []
108 } 106 }
109//MochiKit.Logging.logDebug("--- KeePassExportProcessor.deferredParse - context: " + Clipperz.Base.serializeJSON(context).substring(0,50)); 107//MochiKit.Logging.logDebug("--- KeePassExportProcessor.deferredParse - context: " + Clipperz.Base.serializeJSON(context).substring(0,50));
110//console.log("--- KeePassExportProcessor.deferredParse - context: ", context); 108//console.log("--- KeePassExportProcessor.deferredParse - context: ", context);
111 109
112 deferredResult = new MochiKit.Async.Deferred(); 110 deferredResult = new MochiKit.Async.Deferred();
113//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassExportProcessor.deferredParse - 1 " + res); return res;}); 111//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassExportProcessor.deferredParse - 1 " + res); return res;});
114//deferredResult.addBoth(function(res) {console.log("KeePassExportProcessor.deferredParse - 1 ", res); return res;}); 112//deferredResult.addBoth(function(res) {console.log("KeePassExportProcessor.deferredParse - 1 ", res); return res;});
115 deferredResult.addCallback(MochiKit.Base.method(this, 'deferredParse_core')); 113 deferredResult.addCallback(MochiKit.Base.method(this, 'deferredParse_core'));
116//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassExportProcessor.deferredParse - 2 " + res); return res;}); 114//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassExportProcessor.deferredParse - 2 " + res); return res;});
117 deferredResult.callback(context); 115 deferredResult.callback(context);
118//MochiKit.Logging.logDebug("<<< KeePassExportProcessor.deferredParse"); 116//MochiKit.Logging.logDebug("<<< KeePassExportProcessor.deferredParse");
119 117
120 return deferredResult; 118 return deferredResult;
121 }, 119 },
122 120
123 //------------------------------------------------------------------------- 121 //-------------------------------------------------------------------------
124 122
125 'parseRecord': function(aContext) { 123 'parseRecord': function(aContext) {
126 var result; 124 var result;
127 var recordLabelRegexp; 125 var recordLabelRegexp;
128 varfieldLabelRegexp; 126 varfieldLabelRegexp;
129 var fieldValueRegexp; 127 var fieldValueRegexp;
130 var fullLineRegexp; 128 var fullLineRegexp;
131/* 129/*
132[Record name] 130[Record name]
133Group Tree: 131Group Tree:
134UserName: 132UserName:
135URL: 133URL:
136Password: 134Password:
137Notes: test 135Notes: test
138UUID: 525f62430079bae48b79ed2961924b05 136UUID: 525f62430079bae48b79ed2961924b05
139Icon: 0 137Icon: 0
140Creation Time: 2007-06-26 17:56:03 138Creation Time: 2007-06-26 17:56:03
141Last Access: 2007-10-25 16:23:51 139Last Access: 2007-10-25 16:23:51
142Last Modification: 2007-10-25 16:23:51 140Last Modification: 2007-10-25 16:23:51
143Expires: 2999-12-28 23:59:59 141Expires: 2999-12-28 23:59:59
144 142
145 [Record name] ==> Title 143 [Record name] ==> Title
146 Group: General ==> Group 144 Group: General ==> Group
147 Group Tree: ==> Group Tree 145 Group Tree: ==> Group Tree
148 UserName: ==> UserName 146 UserName: ==> UserName
149 URL: ==>URL 147 URL: ==>URL
150 Password: ==>Password 148 Password: ==>Password
151 Notes: test ==>Notes 149 Notes: test ==>Notes
152 UUID: 525f62430079bae48b79ed2961924b05 ==>UUID 150 UUID: 525f62430079bae48b79ed2961924b05 ==>UUID
153 Icon: 0 ==>Icon 151 Icon: 0 ==>Icon
154 Creation Time: 2007-06-26 17:56:03 ==>Creation Time 152 Creation Time: 2007-06-26 17:56:03 ==>Creation Time
155 Last Access: 2007-10-25 16:23:51 ==>Last Access 153 Last Access: 2007-10-25 16:23:51 ==>Last Access
156 Last Modification: 2007-10-25 16:23:51 ==>Last Modification 154 Last Modification: 2007-10-25 16:23:51 ==>Last Modification
157 Expires: 2999-12-28 23:59:59 ==> Expires 155 Expires: 2999-12-28 23:59:59 ==> Expires
158 Attachment Description: ==> Attachment Description 156 Attachment Description: ==> Attachment Description
159 Attachment: ==> Attachment 157 Attachment: ==> Attachment
160*/ 158*/
161 recordLabelRegexp = new RegExp("^\\[(.*)\\]\\n"); 159 recordLabelRegexp = new RegExp("^\\[(.*)\\]\\n");
162 // recordLabelRegexp = new RegExp("^\\[(.*)\\]$", "m"); 160 // recordLabelRegexp = new RegExp("^\\[(.*)\\]$", "m");
163 fieldLabelRegexp = new RegExp("^(Group|Group Tree|UserName|URL|Password|Notes|UUID|Icon|Creation Time|Last Access|Last Modification|Expires|Attachment Description|Attachment|Valid until): "); 161 fieldLabelRegexp = new RegExp("^(Group|Group Tree|UserName|URL|Password|Notes|UUID|Icon|Creation Time|Last Access|Last Modification|Expires|Attachment Description|Attachment|Valid until): ");
164 fieldValueRegexp = new RegExp("(.*)(\\n|$)"); 162 fieldValueRegexp = new RegExp("(.*)(\\n|$)");
165 fullLineRegexp = new RegExp("^(.*\\n)"); 163 fullLineRegexp = new RegExp("^(.*\\n)");
166 164
167 165
168 if (recordLabelRegexp.test(aContext.line) == true) { 166 if (recordLabelRegexp.test(aContext.line) == true) {
169 var line; 167 var line;
170 168
171//MochiKit.Logging.logDebug("1.0"); 169//MochiKit.Logging.logDebug("1.0");
172 line = aContext.line; 170 line = aContext.line;
173//MochiKit.Logging.logDebug("0 - line: " + line.replace(/\n/g, "\\n").substring(0,50)); 171//MochiKit.Logging.logDebug("0 - line: " + line.replace(/\n/g, "\\n").substring(0,50));
174 172
175 result = {}; 173 result = {};
176 result['Title'] = line.match(recordLabelRegexp)[1]; 174 result['Title'] = line.match(recordLabelRegexp)[1];
177//MochiKit.Logging.logDebug("1 - title: " + result['Title']); 175//MochiKit.Logging.logDebug("1 - title: " + result['Title']);
178 line = line.replace(/^.*\n/, ""); 176 line = line.replace(/^.*\n/, "");
179//MochiKit.Logging.logDebug("2 - line: " + line.replace(/\n/g, "\\n").substring(0,50)); 177//MochiKit.Logging.logDebug("2 - line: " + line.replace(/\n/g, "\\n").substring(0,50));
180//MochiKit.Logging.logDebug("======================================="); 178//MochiKit.Logging.logDebug("=======================================");
181 while (fieldLabelRegexp.test(line) == true) { 179 while (fieldLabelRegexp.test(line) == true) {
182 var fieldName; 180 var fieldName;
183 var fieldValue; 181 var fieldValue;
184 182
185 fieldName = RegExp.$1; 183 fieldName = RegExp.$1;
186//MochiKit.Logging.logDebug("3 - fieldName: " + fieldName); 184//MochiKit.Logging.logDebug("3 - fieldName: " + fieldName);
187 line = RegExp.rightContext; 185 line = RegExp.rightContext;
188//MochiKit.Logging.logDebug("4 - line: " + line.replace(/\n/g, "\\n").substring(0,50)); 186//MochiKit.Logging.logDebug("4 - line: " + line.replace(/\n/g, "\\n").substring(0,50));
189 187
190 fieldValue = line.match(fieldValueRegexp)[1]; 188 fieldValue = line.match(fieldValueRegexp)[1];
191//MochiKit.Logging.logDebug("5 - fieldValue: " + fieldValue); 189//MochiKit.Logging.logDebug("5 - fieldValue: " + fieldValue);
192 line = RegExp.rightContext; 190 line = RegExp.rightContext;
193//MochiKit.Logging.logDebug("6 - line: " + line.replace(/\n/g, "\\n").substring(0,50)); 191//MochiKit.Logging.logDebug("6 - line: " + line.replace(/\n/g, "\\n").substring(0,50));
194 192
195 if (fieldName == 'Notes') { 193 if (fieldName == 'Notes') {
196 var isMultiline; 194 var isMultiline;
197 195
198 isMultiline = false; 196 isMultiline = false;
199 197
200//MochiKit.Logging.logDebug("7 - fieldLabelRegexp.test(line): " + fieldLabelRegexp.test(line) + " - recordLabelRegexp.test(line): " + recordLabelRegexp.test(line)); 198//MochiKit.Logging.logDebug("7 - fieldLabelRegexp.test(line): " + fieldLabelRegexp.test(line) + " - recordLabelRegexp.test(line): " + recordLabelRegexp.test(line));
201 if ((line != "") && (fieldLabelRegexp.test(line) == false) && (recordLabelRegexp.test(line) == false)) { 199 if ((line != "") && (fieldLabelRegexp.test(line) == false) && (recordLabelRegexp.test(line) == false)) {
202 fieldValue += '\n'; 200 fieldValue += '\n';
203 } 201 }
204 202
205 while ((line != "") && (fieldLabelRegexp.test(line) == false) && (recordLabelRegexp.test(line) == false)) { 203 while ((line != "") && (fieldLabelRegexp.test(line) == false) && (recordLabelRegexp.test(line) == false)) {
206 var newLineValue; 204 var newLineValue;
207 205
208 newLineValue = line.match(fullLineRegexp)[1]; 206 newLineValue = line.match(fullLineRegexp)[1];
209 if (newLineValue != "\n") { 207 if (newLineValue != "\n") {
210 isMultiline = true; 208 isMultiline = true;
211 } 209 }
212 fieldValue += newLineValue; 210 fieldValue += newLineValue;
213//MochiKit.Logging.logDebug("8 - fieldValue: " + fieldValue); 211//MochiKit.Logging.logDebug("8 - fieldValue: " + fieldValue);
214 line = RegExp.rightContext; 212 line = RegExp.rightContext;