private ToolStripMenuItem createChangePasswordMenuItem(HostPwEntry hostPwEntry) { IPasswordChanger pwChanger = null; var hostTypeMapper = new HostTypeMapper(new HostTypeSafeConverter()); var hostType = hostTypeMapper.Get(hostPwEntry); if (hostType == HostType.ESXi && QuickConnectUtils.IsVSpherePowerCLIInstalled()) { pwChanger = new ESXiPasswordChanger(); } else if (hostType == HostType.Windows && !String.IsNullOrEmpty(this.Settings.PsPasswdPath) && File.Exists(this.Settings.PsPasswdPath) && PsPasswdWrapper.IsPsPasswdUtility(this.Settings.PsPasswdPath) && PsPasswdWrapper.IsSupportedVersion(this.Settings.PsPasswdPath) ) { pwChanger = new WindowsPasswordChanger(new PsPasswdWrapper(this.Settings.PsPasswdPath)); } else if (hostType == HostType.Linux) { PuttyOptions puttyOptions = null; bool success = PuttyOptionsParser.TryParse(hostPwEntry.AdditionalOptions, out puttyOptions); // Disable change password menu item if authentication is done using SSH key file. if (!success || (success && !puttyOptions.HasKeyFile())) { int?sshPort = null; if (success) { sshPort = puttyOptions.Port; } pwChanger = new LinuxPasswordChanger() { SshPort = sshPort }; } } var menuItem = new ToolStripMenuItem() { Text = ChangePasswordMenuItemText, Enabled = hostPwEntry.HasIPAddress && pwChanger != null }; menuItem.Click += new EventHandler( delegate(object obj, EventArgs ev) { try { var pwDatabase = new PasswordDatabase(this.pluginHost.Database); var pwChangerService = new PasswordChangerServiceWrapper(pwDatabase, pwChanger); using (var formPasswordChange = new FormPasswordChanger(hostPwEntry, pwChangerService)) { formPasswordChange.ShowDialog(); } } catch (Exception ex) { log(ex); } } ); return(menuItem); }
private void entryContextMenu_Opened(object sender, EventArgs e) { if (!this.Settings.Enabled) { return; } PwEntry[] selectedEntries = this.pluginHost.MainWindow.GetSelectedEntries(); if (selectedEntries != null && selectedEntries.Length == 1) { this.menuItems = new DisposableList <ToolStripItem>(); HostPwEntry hostPwEntry = new HostPwEntry(selectedEntries[0], this.pluginHost.Database, this.fieldsMapper); var changePasswordMenuItem = this.createChangePasswordMenuItem(hostPwEntry); if (hostPwEntry.HasConnectionMethods) { menuItems.AddRange(this.createMenuItems(hostPwEntry)); if (this.Settings.CompatibleMode) { this.menuItems.Insert(0, new ToolStripSeparator()); } else { this.menuItems.Add(new ToolStripSeparator()); } if (this.Settings.AddChangePasswordMenuItem) { if (this.Settings.CompatibleMode) { this.menuItems.Insert(0, changePasswordMenuItem); this.menuItems.Insert(0, new ToolStripSeparator()); } else { this.menuItems.Add(changePasswordMenuItem); this.menuItems.Add(new ToolStripSeparator()); } } if (this.Settings.CompatibleMode) { foreach (var item in this.menuItems) { this.pluginHost.MainWindow.EntryContextMenu.Items.Add(item); } } else { for (int i = this.menuItems.Count - 1; i >= 0; i--) { this.pluginHost.MainWindow.EntryContextMenu.Items.Insert(0, this.menuItems[i]); } } } } }
private void listViewControl_KeyUp(object sender, KeyEventArgs e) { if (Settings.Enabled && Settings.EnableShortcutKeys == true) { Debug.WriteLine("[QuickConnectPlugin] ListViewControl Key Up Event: " + e.KeyData); PwEntry[] selectedEntries = pluginHost.MainWindow.GetSelectedEntries(); HostPwEntry selectedEntry = null; if (selectedEntries != null && selectedEntries.Length == 1) { selectedEntry = new HostPwEntry(selectedEntries[0], pluginHost.Database, fieldsMapper); } ; if (selectedEntry == null) { return; } if (Settings.PuttyShortcutKey != Keys.None && e.KeyData == Settings.RemoteDesktopShortcutKey) { Debug.WriteLine("[QuickConnectPlugin] Open Remote Desktop Using Shortcut Key"); if (selectedEntry.ConnectionMethods.Contains(ConnectionMethodType.RemoteDesktop)) { try { ProcessUtils.Start(CmdKeyRegisterArgumentsFormatter.CmdKeyPath, new CmdKeyRegisterArgumentsFormatter().Format(selectedEntry)); var argsFormatter = new RemoteDesktopArgumentsFormatter() { FullScreen = true }; ProcessUtils.StartDetached(argsFormatter.Format(selectedEntry)); ProcessUtils.StartDetached(new CmdKeyUnregisterArgumentsFormatter() { IncludePath = true }.Format(selectedEntry), RemoveCredentialsDelay); } catch (Exception ex) { log(ex); }; e.Handled = true; } } else if (Settings.PuttyShortcutKey != Keys.None && e.KeyData == Settings.PuttyShortcutKey) { Debug.WriteLine("[QuickConnectPlugin] Open PuTTY Using Shortcut Key"); if (selectedEntry.ConnectionMethods.Contains(ConnectionMethodType.PuttySSH) || selectedEntry.ConnectionMethods.Contains(ConnectionMethodType.PuttyTelnet)) { string puttyPath = null; if (QuickConnectUtils.CanOpenPutty(Settings, selectedEntry, out puttyPath)) { try { var sessionFinder = new RegistryPuttySessionFinder(new WindowsRegistryService()); var argsFormatter = new PuttyArgumentsFormatter(puttyPath, sessionFinder, !Settings.DisableCLIPasswordForPutty); ProcessUtils.StartDetached(argsFormatter.Format(selectedEntry)); } catch (Exception ex) { log(ex); }; } e.Handled = true; } } else if (Settings.WinScpShortcutKey != Keys.None && e.KeyData == Settings.WinScpShortcutKey) { Debug.WriteLine("[QuickConnectPlugin] Open WinSCP Using Shortcut Key"); if (selectedEntry.ConnectionMethods.Contains(ConnectionMethodType.WinSCP)) { string winScpPath = null; if (QuickConnectUtils.CanOpenWinScp(Settings, selectedEntry, out winScpPath)) { try { var argsFormatter = new WinScpArgumentsFormatter(winScpPath); ProcessUtils.StartDetached(argsFormatter.Format(selectedEntry)); } catch (Exception ex) { log(ex); }; } e.Handled = true; } } else { Debug.WriteLine("[QuickConnectPlugin] Keyboard Event Ignored"); } } }
private DisposableList <ToolStripItem> createMenuItems(HostPwEntry hostPwEntry) { var menuItems = new DisposableList <ToolStripItem>(); if (hostPwEntry.ConnectionMethods.Contains(ConnectionMethodType.RemoteDesktop)) { var menuItem = new ToolStripMenuItem() { Text = OpenRemoteDesktopMenuItemText, Image = (System.Drawing.Image)QuickConnectPlugin.Properties.Resources.remote, Enabled = hostPwEntry.HasIPAddress }; menuItem.Click += new EventHandler( delegate(object obj, EventArgs ev) { try { ProcessUtils.Start(CmdKeyRegisterArgumentsFormatter.CmdKeyPath, new CmdKeyRegisterArgumentsFormatter().Format(hostPwEntry)); IArgumentsFormatter argsFormatter = new RemoteDesktopArgumentsFormatter() { FullScreen = true }; ProcessUtils.StartDetached(argsFormatter.Format(hostPwEntry)); ProcessUtils.StartDetached(new CmdKeyUnregisterArgumentsFormatter() { IncludePath = true }.Format(hostPwEntry), RemoveCredentialsDelay); } catch (Exception ex) { log(ex); } } ); menuItems.Add(menuItem); } ; if (hostPwEntry.ConnectionMethods.Contains(ConnectionMethodType.RemoteDesktopConsole)) { var menuItem = new ToolStripMenuItem() { Text = OpenRemoteDesktopConsoleMenuItemText, Image = (System.Drawing.Image)QuickConnectPlugin.Properties.Resources.mycomputer, Enabled = hostPwEntry.HasIPAddress }; menuItem.Click += new EventHandler( delegate(object obj, EventArgs ev) { try { ProcessUtils.Start(CmdKeyRegisterArgumentsFormatter.CmdKeyPath, new CmdKeyRegisterArgumentsFormatter() .Format(hostPwEntry)); IArgumentsFormatter argsFormatter = new RemoteDesktopArgumentsFormatter() { FullScreen = true, UseConsole = true, IsOlderVersion = RDCIsOlderVersion }; ProcessUtils.StartDetached(argsFormatter.Format(hostPwEntry)); ProcessUtils.StartDetached(new CmdKeyUnregisterArgumentsFormatter() { IncludePath = true }.Format(hostPwEntry), RemoveCredentialsDelay); } catch (Exception ex) { log(ex); } } ); menuItems.Add(menuItem); } ; if (hostPwEntry.ConnectionMethods.Contains(ConnectionMethodType.vSphereClient)) { var vSphereClientPath = QuickConnectUtils.GetVSphereClientPath(); var menuItem = new ToolStripMenuItem() { Text = OpenVSphereClientMenuItemText, Image = (System.Drawing.Image)QuickConnectPlugin.Properties.Resources.vmware, Enabled = hostPwEntry.HasIPAddress && !String.IsNullOrEmpty(vSphereClientPath) }; menuItem.Click += new EventHandler( delegate(object obj, EventArgs ev) { try { IArgumentsFormatter argsFormatter = new VSphereClientArgumentsFormatter(vSphereClientPath); ProcessUtils.StartDetached(argsFormatter.Format(hostPwEntry)); } catch (Exception ex) { log(ex); } } ); menuItems.Add(menuItem); } if (hostPwEntry.ConnectionMethods.Contains(ConnectionMethodType.PuttySSH) || hostPwEntry.ConnectionMethods.Contains(ConnectionMethodType.PuttyTelnet)) { var sshClientPath = !String.IsNullOrEmpty(this.Settings.SSHClientPath) ? this.Settings.SSHClientPath : QuickConnectUtils.GetPuttyPath(); var menuItem = new ToolStripMenuItem() { Text = OpenSSHConsoleMenuItemText, Image = (System.Drawing.Image)QuickConnectPlugin.Properties.Resources.konsole, Enabled = hostPwEntry.HasIPAddress && !String.IsNullOrEmpty(sshClientPath) }; menuItem.Click += new EventHandler( delegate(object obj, EventArgs ev) { try { var sessionFinder = new RegistryPuttySessionFinder(new WindowsRegistryService()); IArgumentsFormatter argsFormatter = new PuttyArgumentsFormatter(sshClientPath, sessionFinder); ProcessUtils.StartDetached(argsFormatter.Format(hostPwEntry)); } catch (Exception ex) { log(ex); }; } ); menuItems.Add(menuItem); } ; if (hostPwEntry.ConnectionMethods.Contains(ConnectionMethodType.WinSCP)) { var winScpPath = !String.IsNullOrEmpty(this.Settings.WinScpPath) ? this.Settings.WinScpPath : QuickConnectUtils.GetWinScpPath(); var winScpConsoleMenuItem = new ToolStripMenuItem() { Text = OpenWinScpMenuItemText, Image = (System.Drawing.Image)QuickConnectPlugin.Properties.Resources.winscp, Enabled = hostPwEntry.HasIPAddress && !String.IsNullOrEmpty(winScpPath) }; winScpConsoleMenuItem.Click += new EventHandler( delegate(object obj, EventArgs ev) { try { IArgumentsFormatter argsFormatter = new WinScpArgumentsFormatter(winScpPath); ProcessUtils.StartDetached(argsFormatter.Format(hostPwEntry)); } catch (Exception ex) { log(ex); }; } ); menuItems.Add(winScpConsoleMenuItem); } ; return(menuItems); }