summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/Clipperz/PM/BookmarkletProcessor.js
Unidiff
Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/BookmarkletProcessor.js') (more/less context) (show whitespace changes)
-rw-r--r--frontend/gamma/js/Clipperz/PM/BookmarkletProcessor.js196
1 files changed, 196 insertions, 0 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/BookmarkletProcessor.js b/frontend/gamma/js/Clipperz/PM/BookmarkletProcessor.js
new file mode 100644
index 0000000..789d6b8
--- a/dev/null
+++ b/frontend/gamma/js/Clipperz/PM/BookmarkletProcessor.js
@@ -0,0 +1,196 @@
1/*
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer 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/*
30if (typeof(Clipperz) == 'undefined') { Clipperz = {}; }
31if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; }
32
33Clipperz.PM.BookmarkletProcessor = function(aConfiguration) {
34 this._configuration = aConfiguration;
35
36 this._editableFields = null;
37 this._favicon = null;
38
39 return this;
40}
41
42Clipperz.PM.BookmarkletProcessor.prototype = MochiKit.Base.update(null, {
43
44 'toString': function() {
45 return "Clipperz.PM.BookmarkletProcessor";
46 },
47
48 //-------------------------------------------------------------------------
49
50 'configuration': function() {
51 return this._configuration;
52 },
53
54 //-------------------------------------------------------------------------
55
56 'pageTitle': function() {
57 return this.configuration().page.title;
58 },
59
60 //-------------------------------------------------------------------------
61
62 'fields': function() {
63 return this.configuration().form.inputs;
64 },
65
66 //-------------------------------------------------------------------------
67
68 'editableFields': function() {
69 if (this._editableFields == null) {
70 this._editableFields = MochiKit.Base.filter(function(aField) {
71 var result;
72 var type;
73
74 type = aField['type'].toLowerCase();
75 result = ((type != 'hidden') && (type != 'submit') && (type != 'checkbox') && (type != 'radio') && (type != 'select'));
76
77 return result;
78 }, this.fields())
79 }
80
81 return this._editableFields;
82 },
83
84 //-------------------------------------------------------------------------
85
86 'hostname': function() {
87 if (this._hostname == null) {
88 var actionUrl;
89
90 actionUrl = this.configuration()['form']['attributes']['action'];
91 this._hostname = actionUrl.replace(/ ^ h t t p s ? : \ / \ / ( [ ^ \ / ] * ) \ / . * /, '$1');
92 }
93
94 return this._hostname;
95 },
96
97 'favicon': function() {
98 if (this._favicon == null) {
99 this._favicon = "http://" + this.hostname() + "/favicon.ico";
100 }
101
102 return this._favicon;
103 },
104
105 //-------------------------------------------------------------------------
106 __syntaxFix__: "syntax fix"
107});
108
109//#############################################################################
110/ *
111Clipperz.PM.BookmarkletProcessor.createRecordFromBookmarkletConfiguration = function(anUser, aConfiguration) {
112 var processor;
113 var record;
114 var recordVersion;
115 var directLogin;
116 var bindings;
117 var i,c;
118
119 processor = new Clipperz.PM.BookmarkletProcessor(aConfiguration);
120
121 record = new Clipperz.PM.DataModel.Record({
122 'label':processor.pageTitle(),
123 'notes':"",
124 'user': anUser
125 });
126 recordVersion = new Clipperz.PM.DataModel.Record.Version(record, {})
127 record.setCurrentVersion(recordVersion);
128
129 bindings = {};
130
131 c = processor.editableFields().length;
132 for (i=0; i<c; i++) {
133 var formField;
134 var recordField;
135
136 formField = processor.editableFields()[i];
137 recordField = new Clipperz.PM.DataModel.RecordField({
138 'label':formField['name'],
139 'value':formField['value'],
140 'type': Clipperz.PM.Strings.inputTypeToRecordFieldType[formField['type']],
141 'hidden': false,
142 'recordVersion':recordVersion
143 });
144 recordVersion.addField(recordField);
145
146 bindings[formField['name']] = recordField.key();
147 }
148
149 directLogin = new Clipperz.PM.DataModel.DirectLogin({
150 'record': record,
151 'label': processor.pageTitle(),
152 'favicon': processor.favicon(),
153 'formData': processor.configuration()['form'],
154 'bindingData':bindings,
155 'bookmarkletVersion':'0.2'
156 });
157 record.addDirectLogin(directLogin);
158
159 anUser.addRecord(record);
160
161 return record;
162};
163* /
164//-----------------------------------------------------------------------------
165
166Clipperz.PM.BookmarkletProcessor.sanitizeBookmarkletConfiguration = function(aConfiguration) {
167 var result;
168
169 //throw "XSS Bookmarklet attempt";
170
171 result = aConfiguration;
172
173 return result;
174};
175
176//-----------------------------------------------------------------------------
177
178Clipperz.PM.BookmarkletProcessor.checkBookmarkletConfiguration = function(aConfiguration) {
179 var result;
180
181 try {
182 result = Clipperz.Base.evalJSON(aConfiguration);
183 result = Clipperz.PM.BookmarkletProcessor.sanitizeBookmarkletConfiguration(result);
184
185 if (result['version'] != '0.2.3') {
186 throw "WrongBookmarkletVersion";
187 }
188 } catch (exception) {
189 throw exception;
190 }
191
192 return result;
193};
194
195//-----------------------------------------------------------------------------
196*/ \ No newline at end of file