/* Copyright 2008-2011 Clipperz Srl This file is part of Clipperz Community Edition. Clipperz Community Edition is an online password manager. For further information about its features and functionalities please refer to http://www.clipperz.com. * Clipperz Community Edition is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * Clipperz Community Edition is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. * You should have received a copy of the GNU Affero General Public License along with Clipperz Community Edition. If not, see . */ if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } if (typeof(Clipperz.PM.Components) == 'undefined') { Clipperz.PM.Components = {}; } if (typeof(Clipperz.PM.Components.OTP) == 'undefined') { Clipperz.PM.Components.OTP = {}; } //############################################################################# Clipperz.PM.Components.OTP.MainComponent = function(anElement, args) { args = args || {}; //MochiKit.Logging.logDebug("new OTP.MainComponent"); Clipperz.PM.Components.OTP.MainComponent.superclass.constructor.call(this, anElement, args); this._user = args.user; this._shouldRender = true; this._deleteButton = null; this._printButton = null; Clipperz.NotificationCenter.register(null, 'tabSelected', this, 'tabSelectedHandler'); // Clipperz.NotificationCenter.register(null, 'oneTimePasswordAdded', this, 'render'); return this; } //============================================================================= YAHOO.extendX(Clipperz.PM.Components.OTP.MainComponent, Clipperz.PM.Components.BaseComponent, { 'toString': function() { return "Clipperz.PM.Components.OTP.MainComponent component"; }, //------------------------------------------------------------------------- 'render': function() { //MochiKit.Logging.logDebug("### OTP.MainComponent.render"); Clipperz.NotificationCenter.unregister(this); MochiKit.Signal.disconnectAllTo(this); if (Clipperz.PM.Proxy.defaultProxy.isReadOnly()) { this.element().update(""); this.domHelper().append(this.element(), {tag:'div', cls:'oneTimePasswordReadOnlyMessage', htmlString:Clipperz.PM.Strings['oneTimePasswordReadOnlyMessage']}); } else { var deferredResult; deferredResult = new MochiKit.Async.Deferred(); //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("OTP.MainComponent.render - 1: " + res); return res;}); deferredResult.addCallback(MochiKit.Base.bind(function() { this.element().update(""); Clipperz.YUI.DomHelper.append(this.element(), {tag:'div', htmlString:Clipperz.PM.Strings['oneTimePasswordLoadingMessage']}); }, this)); //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("OTP.MainComponent.render - 2: " + res); return res;}); deferredResult.addCallback(MochiKit.Base.method(this.user(), 'loadOneTimePasswords')); //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("OTP.MainComponent.render - 3: " + res); return res;}); //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("OTP.MainComponent.render - 3.1: " + Clipperz.Base.serializeJSON(res.serializedData())); return res;}); deferredResult.addCallback(MochiKit.Base.bind(function(aResult) { var tbodyElement; var oneTimePasswordReferenceKeys; var imageExtension; var isThereAnyActiveOneTimePassword; isThereAnyActiveOneTimePassword = false; this.element().update(""); Clipperz.YUI.DomHelper.append(this.element(), {tag:'div', id:'oneTimePasswordList', children:[ {tag:'div', id:'oneTimePasswords_header', children:[ {tag:'table', width:'100%', children:[ {tag:'tbody', children:[ {tag:'tr', children:[ {tag:'td', width:'10%', children:[ {tag:'div', id:this.getId('createNewOneTimePasswordButton')} ]}, {tag:'td', width:'40%', children:[ {tag:'div', id:this.getId('deleteSelectedOneTimePasswordButton')} ]}, {tag:'td', width:'50%', align:'right', children:[ {tag:'div', id:this.getId('printOneTimePasswordButton')} ]} ]} ]} ]}, {tag:'div', children:[ {tag:'ul', children:[ {tag:'li', children:[ {tag:'span', htmlString:Clipperz.PM.Strings['oneTimePasswordSelectionLink_selectLabel']} ]}, {tag:'li', children:[ {tag:'a', href:'#', id:this.getId('selectAllOneTimePasswords_link'), htmlString:Clipperz.PM.Strings['oneTimePasswordSelectionLink_all']} ]}, {tag:'li', children:[ {tag:'a', href:'#', id:this.getId('selectNoneOneTimePasswords_link'), htmlString:Clipperz.PM.Strings['oneTimePasswordSelectionLink_none']} ]}, {tag:'li', children:[ {tag:'a', href:'#', id:this.getId('selectUsedOneTimePasswords_link'), htmlString:Clipperz.PM.Strings['oneTimePasswordSelectionLink_used']} ]}, {tag:'li', children:[ {tag:'a', href:'#', id:this.getId('selectUnusedOneTimePasswords_link'), htmlString:Clipperz.PM.Strings['oneTimePasswordSelectionLink_unused']} ]} ]} ]} ]}, {tag:'form', id:this.getId('oneTimePasswords_form'), children:[ {tag:'table', cls:'oneTimePassword', cellspacing:'0', cellpadding:'2', children:[ {tag:'tbody', id:this.getId('oneTimePasswords_tbody'), children:[ ]} ]} ]} ]}); imageExtension = (Clipperz_IEisBroken == true) ? 'gif': 'png'; tbodyElement = this.getElement('oneTimePasswords_tbody'); oneTimePasswordReferenceKeys = MochiKit.Base.keys(this.user().oneTimePasswordManager().oneTimePasswords()).reverse(); c = oneTimePasswordReferenceKeys.length; if (c>0) { for (i=0; i>> printAllData"); newWindow = window.open("", ""); newWindow.document.write( "" + "
" + " Clipperz One Time Password" + "" + "" + "" + "" + "
" + "" + "" + "" ); activeOneTimePasswords = MochiKit.Base.filter(function(aOneTimePassword) {return (aOneTimePassword.isExpired() == false)}, MochiKit.Base.values(this.user().oneTimePasswordManager().oneTimePasswords()).reverse()); MochiKit.Iter.forEach(activeOneTimePasswords, MochiKit.Base.partial(function(aWindow, aOneTimePassword) { MochiKit.DOM.withWindow(aWindow, MochiKit.Base.partial(function(aOneTimePassword) { var newBlock; newBlock = MochiKit.DOM.DIV({'class': 'oneTimePassword_print'}, MochiKit.DOM.H2(null, aOneTimePassword.password()) ); MochiKit.DOM.appendChildNodes(MochiKit.DOM.currentDocument().body, newBlock); }, aOneTimePassword)); }, newWindow)); }, //------------------------------------------------------------------------- 'generateRandomBase32OTPValue': function(aButton) { var randomValue; var result; randomValue = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(160/8); result = randomValue.toBase32String(); result = result.replace(/.{4}\B/g, '$&' + ' '); result = result.replace(/(.{4} ){2}/g, '$&' + '- '); return result; }, //------------------------------------------------------------------------- 'createNewOneTimePassword': function() { var newOneTimePassword; var password; password = this.generateRandomBase32OTPValue(); newOneTimePassword = new Clipperz.PM.DataModel.OneTimePassword({ user:this.user(), password:password }); this.user().oneTimePasswordManager().addOneTimePassword(newOneTimePassword); Clipperz.PM.Components.MessageBox.showProgressPanel(MochiKit.Base.method(newOneTimePassword, 'saveChanges'), null, this.getDom('createNewOneTimePasswordButton')); }, //------------------------------------------------------------------------- 'oneTimePasswordCheckboxes': function() { return MochiKit.DOM.getElementsByTagAndClassName('input', 'otpCheckbox', this.getId('oneTimePasswords_tbody')); }, 'checkedOneTimePasswordCheckboxes': function() { return MochiKit.Base.filter(function(aCheckbox) {return (aCheckbox.checked == true)}, this.oneTimePasswordCheckboxes()); }, //------------------------------------------------------------------------- 'selectAllOneTimePasswords': function(anEvent) { var checkboxes; var i,c; anEvent.stop(); checkboxes = this.oneTimePasswordCheckboxes(); c = checkboxes.length; for (i=0; i 0) { this.deleteButton().enable(); } else { this.deleteButton().disable(); } }, //------------------------------------------------------------------------- 'printButton': function() { return this._printButton; }, 'setPrintButton': function(aValue) { this._printButton = aValue; }, //------------------------------------------------------------------------- __syntaxFix__: "syntax fix" });