summaryrefslogtreecommitdiff
path: root/frontend/beta/js/Clipperz/PM/Components/Panels/ToolsPanel.js
Unidiff
Diffstat (limited to 'frontend/beta/js/Clipperz/PM/Components/Panels/ToolsPanel.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/beta/js/Clipperz/PM/Components/Panels/ToolsPanel.js305
1 files changed, 305 insertions, 0 deletions
diff --git a/frontend/beta/js/Clipperz/PM/Components/Panels/ToolsPanel.js b/frontend/beta/js/Clipperz/PM/Components/Panels/ToolsPanel.js
new file mode 100644
index 0000000..abd2621
--- a/dev/null
+++ b/frontend/beta/js/Clipperz/PM/Components/Panels/ToolsPanel.js
@@ -0,0 +1,305 @@
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
29if (typeof(Clipperz) == 'undefined') { Clipperz = {}; }
30if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; }
31if (typeof(Clipperz.PM.Components) == 'undefined') { Clipperz.PM.Components = {}; }
32if (typeof(Clipperz.PM.Components.Panels) == 'undefined') { Clipperz.PM.Components.Panels = {}; }
33
34//#############################################################################
35
36Clipperz.PM.Components.Panels.ToolsPanel = function(anElement, args) {
37 args = args || {};
38
39 Clipperz.PM.Components.Panels.ToolsPanel.superclass.constructor.call(this, anElement, args);
40
41 this._generateButtonElement = null;
42 this._needsRenderingUponTabSwitch = false;
43
44 this.render();
45
46 return this;
47}
48
49//=============================================================================
50
51YAHOO.extendX(Clipperz.PM.Components.Panels.ToolsPanel, Clipperz.PM.Components.Panels.BasePanel, {
52
53 'toString': function() {
54 return "Clipperz.PM.Components.Panels.ToolsPanel component";
55 },
56
57 //-------------------------------------------------------------------------
58
59 'render': function() {
60 var bookmarkletUrl;
61
62//MochiKit.Logging.logDebug(">>> ToolsPanel.render");
63 Clipperz.NotificationCenter.unregister(this);
64 MochiKit.Signal.disconnectAllTo(this);
65
66 if (Clipperz_IEisBroken == true) {
67 bookmarkletUrl = bookmarklet_ie;
68 } else {
69 bookmarkletUrl = bookmarklet;
70 }
71
72 this.element().update("");
73 Clipperz.YUI.DomHelper.append(this.element().dom, {tag:'table', border:'0', cellspacing:'0', cellpadding:'0', children:[
74 {tag:'tbody', children:[
75 {tag:'tr', children:[
76 {tag:'td', valign:'top', width:'200', children:[
77 {tag:'ul', id:"dataSubMenu", cls:'subMenu', children:[
78 {tag:'li', id:this.getId('passwordGenerator'), htmlString:Clipperz.PM.Strings['passwordGeneratorTabLabel']},
79 {tag:'li', id:this.getId('bookmarklet'), htmlString:Clipperz.PM.Strings['bookmarkletTabLabel']},
80 {tag:'li', id:this.getId('compact'), htmlString:Clipperz.PM.Strings['compactTabLabel']},
81 {tag:'li', id:this.getId('httpAuth'), htmlString:Clipperz.PM.Strings['httpAuthTabLabel']}
82 ]}
83 ]},
84 {tag:'td', valign:'top', children:[
85 {tag:'ul', cls:'clipperzTabPanels', children:[
86 {tag:'li', id:this.getId('passwordGeneratorPanel'), children:[
87 {tag:'div', cls:'clipperzSubPanel', children:[
88 {tag:'h5', htmlString:Clipperz.PM.Strings['passwordGeneratorTabTitle']},
89 {tag:'div', cls:'panelDescription', htmlString:Clipperz.PM.Strings['paswordGeneratorTabDescription']},
90
91 //---------------------------------------------------
92 {tag:'div', children:[
93 {tag:'form', id:this.getId('passwordGeneratorForm'), cls:'passwordGenerator', children:[
94 {tag:'input', type:'text', cls:'clipperz_passwordGenerator_password', id:this.getId('passwordField')},
95 {tag:'table', children:[
96 {tag:'tbody', children:[
97 {tag:'tr', children:[
98 {tag:'td', width:'20%', children:[
99 {tag:'input', type:'checkbox', name:'lowercase', id:this.getId('lowercase'), checked:true},
100 {tag:'span', htmlString:Clipperz.PM.Strings['passwordGeneratorLowercaseLabel']}
101 ]},
102 {tag:'td', width:'20%', children:[
103 {tag:'input', type:'checkbox', name:'uppercase', id:this.getId('uppercase'), checked:true},
104 {tag:'span', htmlString:Clipperz.PM.Strings['passwordGeneratorUppercaseLabel']}
105 ]},
106 {tag:'td', width:'20%', children:[
107 {tag:'input', type:'checkbox', name:'numbers', id:this.getId('numbers'), checked:true},
108 {tag:'span', htmlString:Clipperz.PM.Strings['passwordGeneratorNumberLabel']}
109 ]},
110 {tag:'td', width:'20%', children:[
111 {tag:'input', type:'checkbox', name:'symbols', id:this.getId('symbols'), checked:true},
112 {tag:'span', htmlString:Clipperz.PM.Strings['passwordGeneratorSymbolLabel']}
113 ]},
114 {tag:'td', width:'20%', children:[
115 {tag:'span', cls:'passwordGeneratorLength', children:[
116 {tag:'span', htmlString:Clipperz.PM.Strings['passwordGeneratorLengthLabel']},
117 {tag:'span', id:this.getId('passwordLength'), cls:'passwordGeneratorLengthValue', html:'0'}
118 ]}
119 ]}
120 ]}
121 ]}
122 ]}
123 ]},
124 {tag:'div', id:this.getId('generateRandomPassword')}
125 ]}
126 //---------------------------------------------------
127
128 ]}
129 ]},
130 {tag:'li', id:this.getId('bookmarkletPanel'), children:[
131 {tag:'div', cls:'clipperzSubPanel', children:[
132 {tag:'h5', htmlString:Clipperz.PM.Strings['bookmarkletTabTitle']},
133 {tag:'div', cls:'panelDescription', htmlString:Clipperz.PM.Strings['bookmarkletTabDescription']},
134 {tag:'a', href:bookmarkletUrl, cls:'bookmarkletLink', htmlString:Clipperz.PM.Strings['bookmarkletTabBookmarkletTitle']},
135 {tag:'div', cls:'panelDescription', htmlString:Clipperz.PM.Strings['bookmarkletTabInstructions']}
136 ]}
137 ]},
138 {tag:'li', id:this.getId('compactPanel'), children:[
139 {tag:'div', cls:'clipperzSubPanel', children:[
140 {tag:'h5', htmlString:Clipperz.PM.Strings['compactTabTitle']},
141 {tag:'div', cls:'panelDescription', htmlString:Clipperz.PM.Strings['compactTabDescription']}
142 ]}
143 ]},
144 {tag:'li', id:this.getId('httpAuthPanel'), children:[
145 {tag:'div', cls:'clipperzSubPanel', children:[
146 {tag:'h5', htmlString:Clipperz.PM.Strings['httpAuthTabTitle']},
147 {tag:'div', cls:'panelDescription', htmlString:Clipperz.PM.Strings['httpAuthTabDescription']},
148 {tag:'div', cls:'bookmarkletConfiguration', children:[Clipperz.PM.Strings['httpAuthBookmarkletConfiguration']]}
149 ]}
150 ]}
151 ]}
152 ]}
153 ]}
154 ]}
155 ]});
156
157 new Clipperz.PM.Components.PasswordEntropyDisplay(this.getElement('passwordField'));
158
159 MochiKit.Signal.connect(this.getId('lowercase'), 'onclick', this, 'updatePasswordValue');
160 MochiKit.Signal.connect(this.getId('uppercase'), 'onclick', this, 'updatePasswordValue');
161 MochiKit.Signal.connect(this.getId('numbers'), 'onclick', this, 'updatePasswordValue');
162 MochiKit.Signal.connect(this.getId('symbols'), 'onclick', this, 'updatePasswordValue');
163
164 MochiKit.Signal.connect(this.getDom('passwordField'), 'onkeyup', this, 'updatePasswordLengthLabel');
165 MochiKit.Signal.connect(this.getDom('passwordField'), 'onchange', this, 'updatePasswordLengthLabel');
166 MochiKit.Signal.connect(this.getDom('passwordField'), 'onblur', this, 'updatePasswordLengthLabel');
167
168 this.setGenerateButtonElement(new YAHOO.ext.Button(this.getDom('generateRandomPassword'), {text:Clipperz.PM.Strings['passwordGeneratorTabButtonLabel'], handler:this.updatePasswordValue, scope:this}));
169
170 this.setNeedsRenderingUponTabSwitch(false);
171 this.tabPanelController().setUp();
172 Clipperz.NotificationCenter.register(null, 'tabSelected', this, 'tabSelectedHandler');
173 Clipperz.NotificationCenter.register(null, 'switchLanguage', this, 'switchLanguageHandler');
174//MochiKit.Logging.logDebug("<<< ToolsPanel.render");
175 },
176
177 //-------------------------------------------------------------------------
178
179 'needsRenderingUponTabSwitch': function() {
180 return this._needsRenderingUponTabSwitch;
181 },
182
183 'setNeedsRenderingUponTabSwitch': function(aValue) {
184 this._needsRenderingUponTabSwitch = aValue;
185 },
186
187 'tabSelectedHandler': function(anEvent) {
188 if (this.needsRenderingUponTabSwitch()) {
189 this.render();
190 }
191
192 if (anEvent.parameters() == this.getId('httpAuth')) {
193 var textarea;
194
195 textarea = document.getElementById("httpAuthDefaultConfiguration");
196 textarea.focus();
197 textarea.select();
198 }
199 },
200
201 //-------------------------------------------------------------------------
202
203 'tabPanelController': function() {
204 if (this._tabPanelController == null) {
205 var tabPanelControllerConfig;
206
207 tabPanelControllerConfig = {}
208 tabPanelControllerConfig[this.getId('passwordGenerator')] = this.getId('passwordGeneratorPanel');
209 tabPanelControllerConfig[this.getId('bookmarklet')] = this.getId('bookmarkletPanel');
210 tabPanelControllerConfig[this.getId('compact')] = this.getId('compactPanel');
211 tabPanelControllerConfig[this.getId('httpAuth')] = this.getId('httpAuthPanel');
212 this._tabPanelController = new Clipperz.PM.Components.TabPanel.TabPanelController({ config:tabPanelControllerConfig, selectedTab:this.getId('passwordGenerator') });
213 }
214
215 return this._tabPanelController;
216 },
217
218 //-------------------------------------------------------------------------
219
220 'generateButtonElement': function() {
221 return this._generateButtonElement;
222 },
223
224 'setGenerateButtonElement': function(aValue) {
225 this._generateButtonElement = aValue;
226 },
227
228 //-------------------------------------------------------------------------
229
230 'updatePasswordValue': function(anEvent) {
231 varrandomBytes;
232 varrandomValue;
233 var charset;
234 var charsetBitSize;
235 var stringValue;
236 varblockIndex;
237
238//MochiKit.Logging.logDebug(">>> updatePasswordValue");
239 randomBytes = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(50);
240 stringValue = "";
241 blockIndex = 0;
242
243 charset = "";
244 if (this.getDom('lowercase').checked) {
245 charset += Clipperz.PM.Strings['passwordGeneratorLowercaseCharset'];
246 }
247 if (this.getDom('uppercase').checked) {
248 charset += Clipperz.PM.Strings['passwordGeneratorUppercaseCharset'];
249 }
250 if (this.getDom('numbers').checked) {
251 charset += Clipperz.PM.Strings['passwordGeneratorNumberCharset'];
252 }
253 if (this.getDom('symbols').checked) {
254 charset += Clipperz.PM.Strings['passwordGeneratorSymbolCharset'];
255 }
256
257 charsetBitSize = 0;
258 while (Math.pow(2, charsetBitSize) < charset.length) {
259 charsetBitSize ++;
260 }
261
262 if (charsetBitSize > 0) {
263 while (Clipperz.PM.Crypto.passwordEntropy(stringValue) < 128) {
264 if (((blockIndex + 1)*charsetBitSize) > (randomBytes.length() * 8)) {
265 randomBytes = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(50);
266 blockIndex = 0;
267 }
268 randomValue = randomBytes.bitBlockAtIndexWithSize(blockIndex*charsetBitSize, charsetBitSize);
269 if (randomValue < charset.length) {
270 stringValue += charset.charAt(randomValue);
271 }
272
273 blockIndex ++;
274 }
275 } else {
276 stringValue = "";
277 }
278
279 this.getElement('passwordField').dom.focus()
280 this.getElement('passwordField').dom.value = stringValue;
281
282
283 if (anEvent.src) {
284 anEvent.src().focus();
285 } else {
286 this.generateButtonElement().el.focus();
287 }
288
289 this.setNeedsRenderingUponTabSwitch(true);
290
291 return false;
292//MochiKit.Logging.logDebug("<<< updatePasswordValue");
293 },
294
295 //-----------------------------------------------------
296
297 'updatePasswordLengthLabel': function() {
298 this.getElement('passwordLength').update(this.getDom('passwordField').value.length);
299 },
300
301 //-------------------------------------------------------------------------
302 __syntaxFix__: "syntax fix"
303
304});
305