author | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2011-10-02 23:56:18 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2011-10-02 23:56:18 (UTC) |
commit | ef68436ac04da078ffdcacd7e1f785473a303d45 (patch) (unidiff) | |
tree | c403752d66a2c4775f00affd4fa8431b29c5b68c /frontend/beta/js/Clipperz/PM/BookmarkletProcessor.js | |
parent | 597ecfbc0249d83e1b856cbd558340c01237a360 (diff) | |
download | clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.zip clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.gz clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.bz2 |
First version of the newly restructured repository
Diffstat (limited to 'frontend/beta/js/Clipperz/PM/BookmarkletProcessor.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/beta/js/Clipperz/PM/BookmarkletProcessor.js | 288 |
1 files changed, 288 insertions, 0 deletions
diff --git a/frontend/beta/js/Clipperz/PM/BookmarkletProcessor.js b/frontend/beta/js/Clipperz/PM/BookmarkletProcessor.js new file mode 100644 index 0000000..4dfdd8e --- a/dev/null +++ b/frontend/beta/js/Clipperz/PM/BookmarkletProcessor.js | |||
@@ -0,0 +1,288 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2011 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz's Javascript Crypto Library. | ||
6 | Javascript Crypto Library provides web developers with an extensive | ||
7 | and efficient set of cryptographic functions. The library aims to | ||
8 | obtain maximum execution speed while preserving modularity and | ||
9 | reusability. | ||
10 | For further information about its features and functionalities please | ||
11 | refer to http://www.clipperz.com | ||
12 | |||
13 | * Javascript Crypto Library is free software: you can redistribute | ||
14 | it and/or modify it under the terms of the GNU Affero General Public | ||
15 | License as published by the Free Software Foundation, either version | ||
16 | 3 of the License, or (at your option) any later version. | ||
17 | |||
18 | * Javascript Crypto Library is distributed in the hope that it will | ||
19 | be useful, but WITHOUT ANY WARRANTY; without even the implied | ||
20 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
21 | See the GNU Affero General Public License for more details. | ||
22 | |||
23 | * You should have received a copy of the GNU Affero General Public | ||
24 | License along with Javascript Crypto Library. If not, see | ||
25 | <http://www.gnu.org/licenses/>. | ||
26 | |||
27 | */ | ||
28 | |||
29 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | ||
30 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } | ||
31 | //if (typeof(Clipperz.PM.BookmarkletProcessor) == 'undefined') { Clipperz.PM.BookmarkletProcessor = {}; } | ||
32 | //if (typeof(Clipperz.PM.BookmarkletProcessor.versions) == 'undefined') { Clipperz.PM.BookmarkletProcessor.versions = {}; } | ||
33 | |||
34 | /* | ||
35 | Clipperz.PM.BookmarkletProcessor.versions['abstract'] = function(anUser, aConfiguration) { | ||
36 | this._user = anUser; | ||
37 | this._configuration = aConfiguration; | ||
38 | |||
39 | this._recordTitle = null; | ||
40 | this._record = null; | ||
41 | this._editableFields = null; | ||
42 | |||
43 | return this; | ||
44 | } | ||
45 | |||
46 | |||
47 | Clipperz.PM.BookmarkletProcessor.versions['abstract'].prototype = MochiKit.Base.update(null, { | ||
48 | |||
49 | 'toString': function() { | ||
50 | return "BookmarkletProcessor - " + this.user(); | ||
51 | }, | ||
52 | |||
53 | //------------------------------------------------------------------------- | ||
54 | |||
55 | 'user': function() { | ||
56 | return this._user; | ||
57 | }, | ||
58 | |||
59 | //------------------------------------------------------------------------- | ||
60 | |||
61 | 'configuration': function() { | ||
62 | return this._configuration; | ||
63 | }, | ||
64 | |||
65 | //------------------------------------------------------------------------- | ||
66 | |||
67 | 'record': function() { | ||
68 | throw Clipperz.Base.exception.AbstractMethod; | ||
69 | }, | ||
70 | |||
71 | //------------------------------------------------------------------------- | ||
72 | __syntaxFix__: "syntax fix" | ||
73 | }); | ||
74 | */ | ||
75 | |||
76 | Clipperz.PM.BookmarkletProcessor = function(anUser, aConfiguration) { | ||
77 | this._user = anUser; | ||
78 | this._configuration = aConfiguration; | ||
79 | |||
80 | this._recordTitle = null; | ||
81 | this._record = null; | ||
82 | this._editableFields = null; | ||
83 | this._favicon = null; | ||
84 | |||
85 | return this; | ||
86 | } | ||
87 | |||
88 | Clipperz.PM.BookmarkletProcessor.prototype = MochiKit.Base.update(null, { | ||
89 | |||
90 | 'toString': function() { | ||
91 | return "BookmarkletProcessor - " + this.user(); | ||
92 | }, | ||
93 | |||
94 | //------------------------------------------------------------------------- | ||
95 | |||
96 | 'user': function() { | ||
97 | return this._user; | ||
98 | }, | ||
99 | |||
100 | //------------------------------------------------------------------------- | ||
101 | |||
102 | 'configuration': function() { | ||
103 | return this._configuration; | ||
104 | }, | ||
105 | |||
106 | //------------------------------------------------------------------------- | ||
107 | |||
108 | 'recordTitle': function() { | ||
109 | if (this._recordTitle == null) { | ||
110 | this._recordTitle = this.configuration().page.title; | ||
111 | } | ||
112 | |||
113 | return this._recordTitle; | ||
114 | }, | ||
115 | |||
116 | //------------------------------------------------------------------------- | ||
117 | |||
118 | 'fields': function() { | ||
119 | return this.configuration().form.inputs; | ||
120 | }, | ||
121 | |||
122 | //------------------------------------------------------------------------- | ||
123 | |||
124 | 'editableFields': function() { | ||
125 | if (this._editableFields == null) { | ||
126 | this._editableFields = MochiKit.Base.filter(function(aField) { | ||
127 | var result; | ||
128 | var type; | ||
129 | |||
130 | type = aField['type'].toLowerCase(); | ||
131 | result = ((type != 'hidden') && (type != 'submit') && (type != 'checkbox') && (type != 'radio') && (type != 'select')); | ||
132 | |||
133 | return result; | ||
134 | }, this.fields()) | ||
135 | } | ||
136 | |||
137 | return this._editableFields; | ||
138 | }, | ||
139 | |||
140 | //------------------------------------------------------------------------- | ||
141 | |||
142 | 'hostname': function() { | ||
143 | if (this._hostname == null) { | ||
144 | var actionUrl; | ||
145 | |||
146 | actionUrl = this.configuration()['form']['attributes']['action']; | ||
147 | //MochiKit.Logging.logDebug("+++ actionUrl: " + actionUrl); | ||
148 | this._hostname = actionUrl.replace(/^https?:\/\/([^\/]*)\/.*/, '$1'); | ||
149 | } | ||
150 | |||
151 | return this._hostname; | ||
152 | }, | ||
153 | |||
154 | 'favicon': function() { | ||
155 | if (this._favicon == null) { | ||
156 | this._favicon = "http://" + this.hostname() + "/favicon.ico"; | ||
157 | //MochiKit.Logging.logDebug("+++ favicon: " + this._favicon); | ||
158 | } | ||
159 | |||
160 | return this._favicon; | ||
161 | }, | ||
162 | |||
163 | //------------------------------------------------------------------------- | ||
164 | |||
165 | 'record': function() { | ||
166 | if (this._record == null) { | ||
167 | var record; | ||
168 | var recordVersion; | ||
169 | var directLogin; | ||
170 | var bindings; | ||
171 | var i,c; | ||
172 | |||
173 | record = new Clipperz.PM.DataModel.Record({ | ||
174 | label:this.recordTitle(), | ||
175 | notes:"", | ||
176 | user:this.user() | ||
177 | }); | ||
178 | recordVersion = new Clipperz.PM.DataModel.RecordVersion(record, {}) | ||
179 | record.setCurrentVersion(recordVersion); | ||
180 | |||
181 | bindings = {}; | ||
182 | |||
183 | c = this.editableFields().length; | ||
184 | for (i=0; i<c; i++) { | ||
185 | var formField; | ||
186 | var recordField; | ||
187 | |||
188 | //MochiKit.Logging.logDebug(">>> adding a field"); | ||
189 | formField = this.editableFields()[i]; | ||
190 | recordField = new Clipperz.PM.DataModel.RecordField({ | ||
191 | recordVersion:recordVersion, | ||
192 | label:formField['name'], | ||
193 | value:formField['value'], | ||
194 | type:Clipperz.PM.Strings.inputTypeToRecordFieldType[formField['type']], | ||
195 | hidden:false | ||
196 | }); | ||
197 | recordVersion.addField(recordField); | ||
198 | |||
199 | bindings[formField['name']] = recordField.key(); | ||
200 | //MochiKit.Logging.logDebug("<<< adding a field"); | ||
201 | } | ||
202 | |||
203 | directLogin = new Clipperz.PM.DataModel.DirectLogin({ | ||
204 | record:record, | ||
205 | label:this.recordTitle() + Clipperz.PM.Strings['newDirectLoginLabelSuffix'], | ||
206 | // bookmarkletVersion:this.version(), | ||
207 | bookmarkletVersion:'0.2', | ||
208 | favicon:this.favicon(), | ||
209 | formData:this.configuration()['form'], | ||
210 | bindingData:bindings | ||
211 | }); | ||
212 | record.addDirectLogin(directLogin); | ||
213 | |||
214 | this.user().addRecord(record); | ||
215 | |||
216 | this._record = record; | ||
217 | } | ||
218 | |||
219 | return this._record; | ||
220 | }, | ||
221 | |||
222 | //------------------------------------------------------------------------- | ||
223 | __syntaxFix__: "syntax fix" | ||
224 | }); | ||
225 | |||
226 | //############################################################################# | ||
227 | |||
228 | Clipperz.PM.BookmarkletProcessor.createRecordFromBookmarkletConfiguration = function(anUser, aConfiguration) { | ||
229 | var processor; | ||
230 | |||
231 | processor = new Clipperz.PM.BookmarkletProcessor(anUser, aConfiguration); | ||
232 | |||
233 | return processor.record(); | ||
234 | }; | ||
235 | |||
236 | //----------------------------------------------------------------------------- | ||
237 | |||
238 | Clipperz.PM.BookmarkletProcessor.sanitizeBookmarkletConfiguration = function(aConfiguration) { | ||
239 | var result; | ||
240 | |||
241 | //throw "XSS Bookmarklet attempt"; | ||
242 | |||
243 | result = aConfiguration; | ||
244 | |||
245 | return result; | ||
246 | }; | ||
247 | |||
248 | //----------------------------------------------------------------------------- | ||
249 | |||
250 | Clipperz.PM.BookmarkletProcessor.checkBookmarkletConfiguration = function(aConfiguration, aButton, aCallback) { | ||
251 | var result; | ||
252 | |||
253 | try { | ||
254 | result = Clipperz.Base.evalJSON(aConfiguration); | ||
255 | result = Clipperz.PM.BookmarkletProcessor.sanitizeBookmarkletConfiguration(result); | ||
256 | |||
257 | if (result['version'] != '0.2.3') { | ||
258 | throw "WrongBookmarkletVersion"; | ||
259 | } | ||
260 | } catch (exception) { | ||
261 | var title; | ||
262 | var message; | ||
263 | |||
264 | if (exception == "WrongBookmarkletVersion") { | ||
265 | title = Clipperz.PM.Strings['newRecordPanelWrongBookmarkletVersionExceptionTitle']; | ||
266 | message = Clipperz.PM.Strings['newRecordPanelWrongBookmarkletVersionExceptionMessage']; | ||
267 | } else { | ||
268 | title = Clipperz.PM.Strings['newRecordPanelGeneralExceptionTitle']; | ||
269 | message = Clipperz.PM.Strings['newRecordPanelGeneralExceptionMessage']; | ||
270 | } | ||
271 | Clipperz.PM.Components.MessageBox().show({ | ||
272 | title:title, | ||
273 | text:message, | ||
274 | width:240, | ||
275 | fn:aCallback, | ||
276 | closable:false, | ||
277 | showProgressBar:false, | ||
278 | showCloseButton:false, | ||
279 | buttons:{'ok':Clipperz.PM.Strings['newRecordPanelExceptionPanelCloseButtonLabel']} | ||
280 | }, aButton); | ||
281 | |||
282 | throw exception; | ||
283 | } | ||
284 | |||
285 | return result; | ||
286 | }; | ||
287 | |||
288 | //----------------------------------------------------------------------------- | ||