grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026/** BEGIN COPYRIGHT BLOCK * This Program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; version 2 of the License. * * This Program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place, Suite 330, Boston, MA 02111-1307 USA. * * Copyright (C) 2005 Red Hat, Inc. * All rights reserved. * END COPYRIGHT BLOCK **/ imports.gi.versions.Gtk = '3.0' const Gtk = imports.gi.Gtk; const Lang = imports.lang; const Gio = imports.gi.Gio; const GObject = imports.gi.GObject; const GLib = imports.gi.GLib; var OP_FORMAT = 0; var OP_ENROLL = 1; var OP_PIN_RESET = 2; const DEF_TOKEN_TYPE = "userKey"; var OpLabels = new Array("Format", "Enroll", "ResetPin" ); const TOKEN_OPERATION = "Token Operation"; function operationDialog(app) { if(!app) return; this.app = app; } operationDialog.prototype = { launchOperation: function(tokenInfo,operation) { if(tokenInfo == null) { this.app_alert("Invalid Token!"); } this.operation = operation; this.tokenInfo = tokenInfo; let opMessage = ""; if(this.operation == OP_FORMAT) { opMessage = "Format Smart Card:"; } else if(this.operation == OP_ENROLL) { opMessage = "Enroll Smart Card:"; } else if(this.operation == OP_PIN_RESET) { opMessage = "Reset Smart Card Pin:"; } else { this.app._alert("operationdDialog: Invalid operation!"); return; } this.dialog = new Gtk.Dialog ({ transient_for: this.app._window, modal: true,deletable: false, title: TOKEN_OPERATION, border_width: 10 }); this.area = this.dialog.get_content_area(); this.grid = new Gtk.Grid ({row_spacing: 20, column_spacing: 20}); //this.throbberImage = new Gtk.Image({file: this.app._currentDir + "/" + "throbber-anim5.gif"}); this.label = new Gtk.Label({label: opMessage}); this.progressBar = new Gtk.ProgressBar ({ valign: Gtk.Align.CENTER }); this.progressBar.set_fraction(0.0); this.progressLabel = new Gtk.Label({label: "Progress:"}); this.actionArea = this.dialog.get_action_area(); this.actionArea.add(this.grid); this.ldapUserLabel = new Gtk.Label({label: "Ldap User:"}); this.ldapUserBox = new Gtk.Entry(); this.grid.attach(this.label,0,0,1,1); this.grid.attach(this.ldapUserLabel, 0, 1, 1,1); this.grid.attach(this.ldapUserBox,1, 1,1,1); this.ldapPasswordLabel = new Gtk.Label({label: "Ldap Password:"}); this.ldapPasswordBox = new Gtk.Entry(); this.ldapPasswordBox.set_visibility(false); this.grid.attach(this.ldapPasswordLabel,2,1,1,1); this.grid.attach(this.ldapPasswordBox,3,1,1,1); if(this.operation != OP_FORMAT ) { this.newpinLabel = new Gtk.Label({label: "New Pin:"}); this.newpinBox = new Gtk.Entry(); this.newpinBox.set_visibility(false); this.confirmPinLabel = new Gtk.Label({label: "Confirm Pin:"}); this.confirmPinBox = new Gtk.Entry(); this.confirmPinBox.set_visibility(false); this.grid.attach(this.newpinLabel, 0,2,1,1); this.grid.attach(this.newpinBox,1,2,1,1); this.grid.attach(this.confirmPinLabel,2,2,1,1); this.grid.attach(this.confirmPinBox,3,2,1,1); } this.oKButton = new Gtk.Button ({label: OpLabels[this.operation]}); this.dismissButton = new Gtk.Button({label: "Cancel" }); //this.grid.attach(this.throbberImage,0,2,1,1); this.grid.attach(this.progressLabel, 0,3,1,1); //this.throbberImage.hide(); this.grid.attach(this.progressBar, 1,3,1,1); this.grid.attach (this.oKButton,2,3,1,1); this.grid.attach (this.dismissButton,3,3,1,1); // Connect the button to the function that handles what it does this.oKButton.connect ("clicked", this.oKHandler.bind(this)); this.dismissButton.connect("clicked", this.cancelHandler.bind(this)); this.dialog.show_all(); this.hideThrobberImage(); this.inProgress = false; }, hideThrobberImage() { //this.throbberImage.hide(); }, showThrobberImage() { //this.throbberImage.show(); }, updateUI(state) { }, checkSanity: function() { if(this.operation == OP_ENROLL || this.operation == OP_PIN_RESET) { let pin = this.newpinBox.get_text(); let confirm = this.confirmPinBox.get_text(); if( pin && confirm) { if(pin != confirm) { this.app._alert("Pins must match!"); return false; } } else { this.app._alert("Must provide token pin!"); return false; } } // Now check the ldap user info let ldapUser = this.ldapUserBox.get_text(); let ldapPin = this.ldapPasswordBox.get_text(); if(!ldapUser || !ldapPin) { this.app._alert("Must provide user name and password!"); return false; } return true; }, cancelHandler() { if(this.inProgress == false) { this.dialog.destroy(); } else { this.app.mgr.cancel_token_operation(this.tokenInfo); } }, oKHandler: function() { if(this.inProgress) { return; } if(!this.checkSanity()) { return; } let res = 0; this.app._setNotifyCallback(this.notify.bind(this)); if(this.operation == OP_FORMAT) { this.inProgress = 1; this.showThrobberImage(); res = this.app.mgr.format_token(this.tokenInfo, DEF_TOKEN_TYPE, this.ldapUserBox.get_text(), "" /* pin */ ,this.ldapPasswordBox.get_text(),"" ); } else if(this.operation == OP_ENROLL) { this.inProgress = true; this.showThrobberImage(); res = this.app.mgr.enroll_token(this.tokenInfo, DEF_TOKEN_TYPE, this.ldapUserBox.get_text(), this.newpinBox.get_text() /* pin */ ,this.ldapPasswordBox.get_text(),"" ); } else if(this.operation == OP_PIN_RESET) { this.inProgress = true; this.showThrobberImage(); res = this.app.mgr.reset_token_pin(this.tokenInfo, DEF_TOKEN_TYPE, this.ldapUserBox.get_text(), this.newpinBox.get_text() /* pin */ ,this.ldapPasswordBox.get_text(),"" ); } else { this.app_alert("Invalid token operation!"); } }, notify: function(aKeyType, aKeyID, aKeyState, aData, strData) { this.onCoolKeyStateChange(aKeyType, aKeyID, aKeyState, aData, strData); //print("notify: aKeyType: " + aKeyType + " aKeyID: " + aKeyID + " aKeyState: " + aKeyState + " aData: " + aData + " strDAta: " + strData); }, onCoolKeyStateChange: function(keyType, keyID, keyState, data,strData) { //this.app._alert("KeyID: " + keyID + "\n" + // "KeyState: " + keyState + "\n" + // "Data: " + data); //this.app._alert("State Change ="+keyState); switch(keyState) { case 1000: // KeyInserted break; case 1001: // KeyRemoved break; case 1002: // EnrollmentStart this.inProgress = true; break; case 1003: // EnrollmentComplete this.onCoolKeyEnrollmentComplete(keyType, keyID); this.inProgress = false; break; case 1004: // EnrollmentError this.inProgress = false; this.onCoolKeyStateError(keyType, keyID, keyState, data); break; case 1008: // PINResetStart this.inProgress = true; break; case 1009: // PINResetComplete this.onCoolKeyPINResetComplete(keyType, keyID); this.inProgress = false; break; case 1010: // PINResetError this.onCoolKeyStateError(keyType, keyID, keyState, data); this.inProgress = false; break; case 1014: // FormatStart this.inProgress = true; break; case 1015: // FormatComplete this.onCoolKeyFormatComplete(keyType, keyID); this.inProgress = false; break; case 1016: // FormatError this.onCoolKeyStateError(keyType, keyID, keyState, data); this.inProgress = false; break; case 1017: // BlinkStatus Update? break; case 1018: break; case 1020: // OperationCancelled this.onCoolKeyStateError(keyType, keyID, keyState, data); this.inProgress = false; break; case 1021: // OperationStatusUpdate this.onCoolKeyStatusUpdate(keyType, keyID, data); break; case 1022: //Need Auth inProgress = false; break; } }, onCoolKeyEnrollmentComplete: function(keyType, keyID) { this.hideThrobberImage(); this.app._alert("Enrollment Succesfully Complete!"); this.app._updateCoolkey( this.tokenInfo); this.dialog.destroy(); }, onCoolKeyStateError: function(keyType, keyID, keyState, data) { this.hideThrobberImage(); this.app._alert(OpLabels[this.operation] + " Error: " + this.app._getErrorMessage(data)); this.app._updateCoolkey( this.tokenInfo ); this.dialog.destroy(); }, onCoolKeyPINResetComplete: function(keyType, keyID) { this.hideThrobberImage(); this.app._alert("Pin Reset Successfully Completed!"); this.dialog.destroy(); }, onCoolKeyFormatComplete: function(keyType, keyID) { this.hideThrobberImage(); this.app._alert("Format Succesfully Completed!"); this.app._updateCoolkey(this.tokenInfo); this.dialog.destroy(); }, onCoolKeyStatusUpdate: function(keyType, keyID, data) { if(data) { let percent = parseFloat(data); this.progressBar.set_fraction( percent / 100); } } }