Diffstat (limited to 'frontend/beta/js/Clipperz/Base.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/beta/js/Clipperz/Base.js | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/frontend/beta/js/Clipperz/Base.js b/frontend/beta/js/Clipperz/Base.js index 1c0504b..cf40314 100644 --- a/frontend/beta/js/Clipperz/Base.js +++ b/frontend/beta/js/Clipperz/Base.js | |||
@@ -1,214 +1,212 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2013 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz Community Edition. | 5 | This file is part of Clipperz, the online password manager. |
6 | Clipperz Community Edition is an online password manager. | ||
7 | For further information about its features and functionalities please | 6 | For further information about its features and functionalities please |
8 | refer to http://www.clipperz.com. | 7 | refer 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 | ||
26 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 24 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
27 | if (typeof(Clipperz.Base) == 'undefined') { Clipperz.Base = {}; } | 25 | if (typeof(Clipperz.Base) == 'undefined') { Clipperz.Base = {}; } |
28 | 26 | ||
29 | Clipperz.Base.VERSION = "0.1"; | 27 | Clipperz.Base.VERSION = "0.1"; |
30 | Clipperz.Base.NAME = "Clipperz.Base"; | 28 | Clipperz.Base.NAME = "Clipperz.Base"; |
31 | 29 | ||
32 | MochiKit.Base.update(Clipperz.Base, { | 30 | MochiKit.Base.update(Clipperz.Base, { |
33 | 31 | ||
34 | //------------------------------------------------------------------------- | 32 | //------------------------------------------------------------------------- |
35 | 33 | ||
36 | '__repr__': function () { | 34 | '__repr__': function () { |
37 | return "[" + this.NAME + " " + this.VERSION + "]"; | 35 | return "[" + this.NAME + " " + this.VERSION + "]"; |
38 | }, | 36 | }, |
39 | 37 | ||
40 | //------------------------------------------------------------------------- | 38 | //------------------------------------------------------------------------- |
41 | 39 | ||
42 | 'toString': function () { | 40 | 'toString': function () { |
43 | return this.__repr__(); | 41 | return this.__repr__(); |
44 | }, | 42 | }, |
45 | 43 | ||
46 | //------------------------------------------------------------------------- | 44 | //------------------------------------------------------------------------- |
47 | 45 | ||
48 | 'trim': function (aValue) { | 46 | 'trim': function (aValue) { |
49 | return aValue.replace(/^\s+|\s+$/g, ""); | 47 | return aValue.replace(/^\s+|\s+$/g, ""); |
50 | }, | 48 | }, |
51 | 49 | ||
52 | //------------------------------------------------------------------------- | 50 | //------------------------------------------------------------------------- |
53 | 51 | ||
54 | 'stringToByteArray': function (aValue) { | 52 | 'stringToByteArray': function (aValue) { |
55 | varresult; | 53 | varresult; |
56 | var i, c; | 54 | var i, c; |
57 | 55 | ||
58 | result = []; | 56 | result = []; |
59 | 57 | ||
60 | c = aValue.length; | 58 | c = aValue.length; |
61 | for (i=0; i<c; i++) { | 59 | for (i=0; i<c; i++) { |
62 | result[i] = aValue.charCodeAt(i); | 60 | result[i] = aValue.charCodeAt(i); |
63 | } | 61 | } |
64 | 62 | ||
65 | return result; | 63 | return result; |
66 | }, | 64 | }, |
67 | 65 | ||
68 | //......................................................................... | 66 | //......................................................................... |
69 | 67 | ||
70 | 'byteArrayToString': function (anArrayOfBytes) { | 68 | 'byteArrayToString': function (anArrayOfBytes) { |
71 | varresult; | 69 | varresult; |
72 | var i, c; | 70 | var i, c; |
73 | 71 | ||
74 | result = ""; | 72 | result = ""; |
75 | 73 | ||
76 | c = anArrayOfBytes.length; | 74 | c = anArrayOfBytes.length; |
77 | for (i=0; i<c; i++) { | 75 | for (i=0; i<c; i++) { |
78 | result += String.fromCharCode(anArrayOfBytes[i]); | 76 | result += String.fromCharCode(anArrayOfBytes[i]); |
79 | } | 77 | } |
80 | 78 | ||
81 | return result; | 79 | return result; |
82 | }, | 80 | }, |
83 | 81 | ||
84 | //------------------------------------------------------------------------- | 82 | //------------------------------------------------------------------------- |
85 | 83 | ||
86 | 'getValueForKeyInFormContent': function (aFormContent, aKey) { | 84 | 'getValueForKeyInFormContent': function (aFormContent, aKey) { |
87 | return aFormContent[1][MochiKit.Base.find(aFormContent[0], aKey)]; | 85 | return aFormContent[1][MochiKit.Base.find(aFormContent[0], aKey)]; |
88 | }, | 86 | }, |
89 | 87 | ||
90 | //------------------------------------------------------------------------- | 88 | //------------------------------------------------------------------------- |
91 | 89 | ||
92 | 'indexOfObjectInArray': function(anObject, anArray) { | 90 | 'indexOfObjectInArray': function(anObject, anArray) { |
93 | varresult; | 91 | varresult; |
94 | vari, c; | 92 | vari, c; |
95 | 93 | ||
96 | result = -1; | 94 | result = -1; |
97 | 95 | ||
98 | c = anArray.length; | 96 | c = anArray.length; |
99 | for (i=0; ((i<c) && (result < 0)); i++) { | 97 | for (i=0; ((i<c) && (result < 0)); i++) { |
100 | if (anArray[i] === anObject) { | 98 | if (anArray[i] === anObject) { |
101 | result = i; | 99 | result = i; |
102 | } | 100 | } |
103 | } | 101 | } |
104 | 102 | ||
105 | return result; | 103 | return result; |
106 | }, | 104 | }, |
107 | 105 | ||
108 | 'removeObjectAtIndexFromArray': function(anIndex, anArray) { | 106 | 'removeObjectAtIndexFromArray': function(anIndex, anArray) { |
109 | anArray.splice(anIndex, 1); | 107 | anArray.splice(anIndex, 1); |
110 | }, | 108 | }, |
111 | 109 | ||
112 | 'removeObjectFromArray': function(anObject, anArray) { | 110 | 'removeObjectFromArray': function(anObject, anArray) { |
113 | varobjectIndex; | 111 | varobjectIndex; |
114 | 112 | ||
115 | objectIndex = Clipperz.Base.indexOfObjectInArray(anObject, anArray); | 113 | objectIndex = Clipperz.Base.indexOfObjectInArray(anObject, anArray); |
116 | if (objectIndex > -1) { | 114 | if (objectIndex > -1) { |
117 | Clipperz.Base.removeObjectAtIndexFromArray(objectIndex, anArray); | 115 | Clipperz.Base.removeObjectAtIndexFromArray(objectIndex, anArray); |
118 | } else { | 116 | } else { |
119 | // jslog.error("Trying to remove an object not present in the array"); | 117 | // jslog.error("Trying to remove an object not present in the array"); |
120 | //TODO: raise an exception | 118 | //TODO: raise an exception |
121 | } | 119 | } |
122 | }, | 120 | }, |
123 | 121 | ||
124 | 'removeFromArray': function(anArray, anObject) { | 122 | 'removeFromArray': function(anArray, anObject) { |
125 | return Clipperz.Base.removeObjectFromArray(anObject, anArray); | 123 | return Clipperz.Base.removeObjectFromArray(anObject, anArray); |
126 | }, | 124 | }, |
127 | 125 | ||
128 | //------------------------------------------------------------------------- | 126 | //------------------------------------------------------------------------- |
129 | 127 | ||
130 | 'splitStringAtFixedTokenSize': function(aString, aTokenSize) { | 128 | 'splitStringAtFixedTokenSize': function(aString, aTokenSize) { |
131 | var result; | 129 | var result; |
132 | varstringToProcess; | 130 | varstringToProcess; |
133 | 131 | ||
134 | stringToProcess = aString; | 132 | stringToProcess = aString; |
135 | result = []; | 133 | result = []; |
136 | if (stringToProcess != null) { | 134 | if (stringToProcess != null) { |
137 | while (stringToProcess.length > aTokenSize) { | 135 | while (stringToProcess.length > aTokenSize) { |
138 | result.push(stringToProcess.substring(0, aTokenSize)); | 136 | result.push(stringToProcess.substring(0, aTokenSize)); |
139 | stringToProcess = stringToProcess.substring(aTokenSize); | 137 | stringToProcess = stringToProcess.substring(aTokenSize); |
140 | } | 138 | } |
141 | 139 | ||
142 | result.push(stringToProcess); | 140 | result.push(stringToProcess); |
143 | } | 141 | } |
144 | 142 | ||
145 | return result; | 143 | return result; |
146 | }, | 144 | }, |
147 | 145 | ||
148 | //------------------------------------------------------------------------- | 146 | //------------------------------------------------------------------------- |
149 | 147 | ||
150 | 'objectType': function(anObject) { | 148 | 'objectType': function(anObject) { |
151 | var result; | 149 | var result; |
152 | 150 | ||
153 | if (anObject == null) { | 151 | if (anObject == null) { |
154 | result = null; | 152 | result = null; |
155 | } else { | 153 | } else { |
156 | result = typeof(anObject); | 154 | result = typeof(anObject); |
157 | 155 | ||
158 | if (result == "object") { | 156 | if (result == "object") { |
159 | if (anObject instanceof Array) { | 157 | if (anObject instanceof Array) { |
160 | result = 'array' | 158 | result = 'array' |
161 | } else if (anObject.constructor == Boolean) { | 159 | } else if (anObject.constructor == Boolean) { |
162 | result = 'boolean' | 160 | result = 'boolean' |
163 | } else if (anObject instanceof Date) { | 161 | } else if (anObject instanceof Date) { |
164 | result = 'date' | 162 | result = 'date' |
165 | } else if (anObject instanceof Error) { | 163 | } else if (anObject instanceof Error) { |
166 | result = 'error' | 164 | result = 'error' |
167 | } else if (anObject instanceof Function) { | 165 | } else if (anObject instanceof Function) { |
168 | result = 'function' | 166 | result = 'function' |
169 | } else if (anObject.constructor == Number) { | 167 | } else if (anObject.constructor == Number) { |
170 | result = 'number' | 168 | result = 'number' |
171 | } else if (anObject.constructor == String) { | 169 | } else if (anObject.constructor == String) { |
172 | result = 'string' | 170 | result = 'string' |
173 | } else if (anObject instanceof Object) { | 171 | } else if (anObject instanceof Object) { |
174 | result = 'object' | 172 | result = 'object' |
175 | } else { | 173 | } else { |
176 | throw Clipperz.Base.exception.UnknownType; | 174 | throw Clipperz.Base.exception.UnknownType; |
177 | } | 175 | } |
178 | } | 176 | } |
179 | } | 177 | } |
180 | 178 | ||
181 | return result; | 179 | return result; |
182 | }, | 180 | }, |
183 | 181 | ||
184 | //------------------------------------------------------------------------- | 182 | //------------------------------------------------------------------------- |
185 | 183 | ||
186 | 'escapeHTML': function(aValue) { | 184 | 'escapeHTML': function(aValue) { |
187 | var result; | 185 | var result; |
188 | 186 | ||
189 | result = aValue; | 187 | result = aValue; |
190 | result = result.replace(/</g, "<"); | 188 | result = result.replace(/</g, "<"); |
191 | result = result.replace(/>/g, ">"); | 189 | result = result.replace(/>/g, ">"); |
192 | 190 | ||
193 | return result; | 191 | return result; |
194 | }, | 192 | }, |
195 | 193 | ||
196 | //------------------------------------------------------------------------- | 194 | //------------------------------------------------------------------------- |
197 | 195 | ||
198 | 'deepClone': function(anObject) { | 196 | 'deepClone': function(anObject) { |
199 | var result; | 197 | var result; |
200 | 198 | ||
201 | result = Clipperz.Base.evalJSON(Clipperz.Base.serializeJSON(anObject)); | 199 | result = Clipperz.Base.evalJSON(Clipperz.Base.serializeJSON(anObject)); |
202 | 200 | ||
203 | return result; | 201 | return result; |
204 | }, | 202 | }, |
205 | 203 | ||
206 | //------------------------------------------------------------------------- | 204 | //------------------------------------------------------------------------- |
207 | 205 | ||
208 | 'evalJSON': function(aString) { | 206 | 'evalJSON': function(aString) { |
209 | /* | 207 | /* |
210 | var result; | 208 | var result; |
211 | 209 | ||
212 | //check for XSS injection | 210 | //check for XSS injection |
213 | if (/<script>/.test(aString)) { | 211 | if (/<script>/.test(aString)) { |
214 | throw "error"; | 212 | throw "error"; |