author | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2013-08-30 15:56:53 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2013-08-30 21:23:42 (UTC) |
commit | 20bea94ab6b91c85b171dcf86baba0a64169d508 (patch) (unidiff) | |
tree | 6e38e91498dcdb861620eba1e237d1026fe79cc5 /frontend/delta/js/Clipperz/PM/BookmarkletProcessor.js | |
parent | bde3c7b98523112ade9c5bbf7390c4ecb494cd2e (diff) | |
download | clipperz-20bea94ab6b91c85b171dcf86baba0a64169d508.zip clipperz-20bea94ab6b91c85b171dcf86baba0a64169d508.tar.gz clipperz-20bea94ab6b91c85b171dcf86baba0a64169d508.tar.bz2 |
First release of /delta version
Diffstat (limited to 'frontend/delta/js/Clipperz/PM/BookmarkletProcessor.js') (more/less context) (show whitespace changes)
-rw-r--r-- | frontend/delta/js/Clipperz/PM/BookmarkletProcessor.js | 191 |
1 files changed, 191 insertions, 0 deletions
diff --git a/frontend/delta/js/Clipperz/PM/BookmarkletProcessor.js b/frontend/delta/js/Clipperz/PM/BookmarkletProcessor.js new file mode 100644 index 0000000..4818b76 --- a/dev/null +++ b/frontend/delta/js/Clipperz/PM/BookmarkletProcessor.js | |||
@@ -0,0 +1,191 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2013 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz, the online password manager. | ||
6 | For further information about its features and functionalities please | ||
7 | refer to http://www.clipperz.com. | ||
8 | |||
9 | * Clipperz is free software: you can redistribute it and/or modify it | ||
10 | under the terms of the GNU Affero General Public License as published | ||
11 | by the Free Software Foundation, either version 3 of the License, or | ||
12 | (at your option) any later version. | ||
13 | |||
14 | * Clipperz is distributed in the hope that it will be useful, but | ||
15 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
17 | See the GNU Affero General Public License for more details. | ||
18 | |||
19 | * You should have received a copy of the GNU Affero General Public | ||
20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. | ||
21 | |||
22 | */ | ||
23 | |||
24 | /* | ||
25 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | ||
26 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } | ||
27 | |||
28 | Clipperz.PM.BookmarkletProcessor = function(aConfiguration) { | ||
29 | this._configuration = aConfiguration; | ||
30 | |||
31 | this._editableFields = null; | ||
32 | this._favicon = null; | ||
33 | |||
34 | return this; | ||
35 | } | ||
36 | |||
37 | Clipperz.PM.BookmarkletProcessor.prototype = MochiKit.Base.update(null, { | ||
38 | |||
39 | 'toString': function() { | ||
40 | return "Clipperz.PM.BookmarkletProcessor"; | ||
41 | }, | ||
42 | |||
43 | //------------------------------------------------------------------------- | ||
44 | |||
45 | 'configuration': function() { | ||
46 | return this._configuration; | ||
47 | }, | ||
48 | |||
49 | //------------------------------------------------------------------------- | ||
50 | |||
51 | 'pageTitle': function() { | ||
52 | return this.configuration().page.title; | ||
53 | }, | ||
54 | |||
55 | //------------------------------------------------------------------------- | ||
56 | |||
57 | 'fields': function() { | ||
58 | return this.configuration().form.inputs; | ||
59 | }, | ||
60 | |||
61 | //------------------------------------------------------------------------- | ||
62 | |||
63 | 'editableFields': function() { | ||
64 | if (this._editableFields == null) { | ||
65 | this._editableFields = MochiKit.Base.filter(function(aField) { | ||
66 | var result; | ||
67 | var type; | ||
68 | |||
69 | type = aField['type'].toLowerCase(); | ||
70 | result = ((type != 'hidden') && (type != 'submit') && (type != 'checkbox') && (type != 'radio') && (type != 'select')); | ||
71 | |||
72 | return result; | ||
73 | }, this.fields()) | ||
74 | } | ||
75 | |||
76 | return this._editableFields; | ||
77 | }, | ||
78 | |||
79 | //------------------------------------------------------------------------- | ||
80 | |||
81 | 'hostname': function() { | ||
82 | if (this._hostname == null) { | ||
83 | var actionUrl; | ||
84 | |||
85 | actionUrl = this.configuration()['form']['attributes']['action']; | ||
86 | this._hostname = actionUrl.replace(/ ^ h t t p s ? : \ / \ / ( [ ^ \ / ] * ) \ / . * /, '$1'); | ||
87 | } | ||
88 | |||
89 | return this._hostname; | ||
90 | }, | ||
91 | |||
92 | 'favicon': function() { | ||
93 | if (this._favicon == null) { | ||
94 | this._favicon = "http://" + this.hostname() + "/favicon.ico"; | ||
95 | } | ||
96 | |||
97 | return this._favicon; | ||
98 | }, | ||
99 | |||
100 | //------------------------------------------------------------------------- | ||
101 | __syntaxFix__: "syntax fix" | ||
102 | }); | ||
103 | |||
104 | //############################################################################# | ||
105 | / * | ||
106 | Clipperz.PM.BookmarkletProcessor.createRecordFromBookmarkletConfiguration = function(anUser, aConfiguration) { | ||
107 | var processor; | ||
108 | var record; | ||
109 | var recordVersion; | ||
110 | var directLogin; | ||
111 | var bindings; | ||
112 | var i,c; | ||
113 | |||
114 | processor = new Clipperz.PM.BookmarkletProcessor(aConfiguration); | ||
115 | |||
116 | record = new Clipperz.PM.DataModel.Record({ | ||
117 | 'label':processor.pageTitle(), | ||
118 | 'notes':"", | ||
119 | 'user': anUser | ||
120 | }); | ||
121 | recordVersion = new Clipperz.PM.DataModel.Record.Version(record, {}) | ||
122 | record.setCurrentVersion(recordVersion); | ||
123 | |||
124 | bindings = {}; | ||
125 | |||
126 | c = processor.editableFields().length; | ||
127 | for (i=0; i<c; i++) { | ||
128 | var formField; | ||
129 | var recordField; | ||
130 | |||
131 | formField = processor.editableFields()[i]; | ||
132 | recordField = new Clipperz.PM.DataModel.RecordField({ | ||
133 | 'label':formField['name'], | ||
134 | 'value':formField['value'], | ||
135 | 'type': Clipperz.PM.Strings.inputTypeToRecordFieldType[formField['type']], | ||
136 | 'hidden': false, | ||
137 | 'recordVersion':recordVersion | ||
138 | }); | ||
139 | recordVersion.addField(recordField); | ||
140 | |||
141 | bindings[formField['name']] = recordField.key(); | ||
142 | } | ||
143 | |||
144 | directLogin = new Clipperz.PM.DataModel.DirectLogin({ | ||
145 | 'record': record, | ||
146 | 'label': processor.pageTitle(), | ||
147 | 'favicon': processor.favicon(), | ||
148 | 'formData': processor.configuration()['form'], | ||
149 | 'bindingData':bindings, | ||
150 | 'bookmarkletVersion':'0.2' | ||
151 | }); | ||
152 | record.addDirectLogin(directLogin); | ||
153 | |||
154 | anUser.addRecord(record); | ||
155 | |||
156 | return record; | ||
157 | }; | ||
158 | * / | ||
159 | //----------------------------------------------------------------------------- | ||
160 | |||
161 | Clipperz.PM.BookmarkletProcessor.sanitizeBookmarkletConfiguration = function(aConfiguration) { | ||
162 | var result; | ||
163 | |||
164 | //throw "XSS Bookmarklet attempt"; | ||
165 | |||
166 | result = aConfiguration; | ||
167 | |||
168 | return result; | ||
169 | }; | ||
170 | |||
171 | //----------------------------------------------------------------------------- | ||
172 | |||
173 | Clipperz.PM.BookmarkletProcessor.checkBookmarkletConfiguration = function(aConfiguration) { | ||
174 | var result; | ||
175 | |||
176 | try { | ||
177 | result = Clipperz.Base.evalJSON(aConfiguration); | ||
178 | result = Clipperz.PM.BookmarkletProcessor.sanitizeBookmarkletConfiguration(result); | ||
179 | |||
180 | if (result['version'] != '0.2.3') { | ||
181 | throw "WrongBookmarkletVersion"; | ||
182 | } | ||
183 | } catch (exception) { | ||
184 | throw exception; | ||
185 | } | ||
186 | |||
187 | return result; | ||
188 | }; | ||
189 | |||
190 | //----------------------------------------------------------------------------- | ||
191 | */ \ No newline at end of file | ||