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 checkVSpherePowerCLIStatus() { var status = QuickConnectUtils.IsVSpherePowerCLIInstalled(); this.labelVSpherePowerCLIStatusMessage.Text = this.labelVSpherePowerCLIStatusMessage.Text.Replace("{status}", status ? "installed" : "not installed" ); if (status) { this.pictureBoxVSpherePowerCLIStatusIcon.Image = global::QuickConnectPlugin.Properties.Resources.success; } }
public override bool Initialize(IPluginHost pluginHost) { Debug.Assert(pluginHost != null); if (pluginHost == null) { return(false); } this.pluginHost = pluginHost; this.Settings = QuickConnectPluginSettings.Load(pluginHost, new PluginCustomConfigPropertyNameFormatter(PluginName)); this.fieldsMapper = new SettingsFieldMapper(this.Settings); pluginMenuItemOptions = new ToolStripMenuItem("Options..."); pluginMenuItemOptions.Click += new EventHandler( pluginMenuItemOptionsOnClickEventHandler = delegate(object obj, EventArgs ev) { List <String> fields = null; // Check if database is open. if (this.pluginHost.Database != null && this.pluginHost.Database.IsOpen) { fields = this.pluginHost.Database.GetAllFields(true).ToList(); fields.Sort(); } try { KeysHelper.UnregisterKeePassHotKeys(); using (FormOptions form = new FormOptions(Title, this.Settings, fields)) { form.ShowDialog(pluginHost.MainWindow); } } finally { KeysHelper.RegisterKeePassHotKeys(); } } ); pluginMenuItemBatchPasswordChanger = new ToolStripMenuItem("Batch Password Changer..."); pluginMenuItemBatchPasswordChanger.Click += new EventHandler( pluginMenuItemBatchPasswordChangerOnClickEventHandler = delegate(object obj, EventArgs ev) { IPasswordChangerTreeNode pwTreeNode = null; // Check if database is open. if (this.pluginHost.Database != null && this.pluginHost.Database.IsOpen) { pwTreeNode = PasswordChangerTreeNode.Build(pluginHost.Database, fieldsMapper); } else { pwTreeNode = new EmptyTreeNode("No database available."); } var pwChangerFactory = new DictionaryPasswordChangerExFactory(); if (QuickConnectUtils.IsVSpherePowerCLIInstalled()) { pwChangerFactory.Factories.Add(HostType.ESXi, new PasswordChangerExFactory(new ESXiPasswordChangerFactory())); } if (!String.IsNullOrEmpty(this.Settings.PsPasswdPath) && File.Exists(this.Settings.PsPasswdPath) && PsPasswdWrapper.IsPsPasswdUtility(this.Settings.PsPasswdPath) && PsPasswdWrapper.IsSupportedVersion(this.Settings.PsPasswdPath)) { pwChangerFactory.Factories.Add(HostType.Windows, new PasswordChangerExFactory(new WindowsPasswordChangerFactory( new PsPasswdWrapper(this.Settings.PsPasswdPath))) ); } pwChangerFactory.Factories.Add(HostType.Linux, new LinuxPasswordChangerExFactory(new LinuxPasswordChangerFactory())); var pwChangerServiceFactory = new PasswordChangerServiceFactory( new PasswordDatabase(this.pluginHost.Database), pwChangerFactory, new SystemClock() ); using (var form = new FormBatchPasswordChanger(pwTreeNode, pwChangerServiceFactory)) { form.ShowDialog(pluginHost.MainWindow); if (form.Changed) { refreshUI(); } } } ); pluginMenuItemAbout = new ToolStripMenuItem("About"); pluginMenuItemAbout.Click += new EventHandler( pluginMenuItemAboutOnClickEventHandler = delegate(object obj, EventArgs ev) { using (FormAbout form = new FormAbout()) { form.Text = form.Text.Replace("{title}", Title); form.ShowDialog(pluginHost.MainWindow); } } ); pluginMenuItem = new ToolStripMenuItem(String.Format("{0}", Title)); pluginMenuItem.DropDownItems.Add(pluginMenuItemBatchPasswordChanger); pluginMenuItem.DropDownItems.Add(pluginMenuItemOptions); pluginMenuItem.DropDownItems.Add(pluginMenuItemAbout); this.pluginHost.MainWindow.ToolsMenu.DropDownItems.Add(pluginMenuItem); // Add handlers. ContextMenuStrip entryContextMenu = pluginHost.MainWindow.EntryContextMenu; entryContextMenu.Opened += new EventHandler(entryContextMenu_Opened); entryContextMenu.Closed += new ToolStripDropDownClosedEventHandler(entryContextMenu_Closed); var control = FormsUtils.FindControlRecursive(pluginHost.MainWindow, KeePassListViewControl); var listViewControl = control as CustomListViewEx; if (listViewControl != null) { listViewControl.KeyUp += new KeyEventHandler(listViewControl_KeyUp); } return(true); }
private DisposableList <ToolStripItem> createMenuItems(IHostPwEntry 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 }; if (Settings.EnableShortcutKeys == true && Settings.RemoteDesktopShortcutKey != Keys.None) { menuItem.ShortcutKeys = Settings.RemoteDesktopShortcutKey; menuItem.ShowShortcutKeys = true; } 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)) { string puttyPath = null; var menuItem = new ToolStripMenuItem() { Text = OpenPuttyMenuItemText, Image = (System.Drawing.Image)QuickConnectPlugin.Properties.Resources.konsole, Enabled = QuickConnectUtils.CanOpenPutty(Settings, hostPwEntry, out puttyPath) }; if (Settings.EnableShortcutKeys == true && Settings.PuttyShortcutKey != Keys.None) { menuItem.ShortcutKeys = Settings.PuttyShortcutKey; menuItem.ShowShortcutKeys = true; } menuItem.Click += new EventHandler( delegate(object obj, EventArgs ev) { try { var sessionFinder = new RegistryPuttySessionFinder(new WindowsRegistryService()); IArgumentsFormatter argsFormatter = new PuttyArgumentsFormatter(puttyPath, sessionFinder, !this.Settings.DisableCLIPasswordForPutty); ProcessUtils.StartDetached(argsFormatter.Format(hostPwEntry)); } catch (Exception ex) { log(ex); }; } ); menuItems.Add(menuItem); } ; if (hostPwEntry.ConnectionMethods.Contains(ConnectionMethodType.WinSCP)) { string winScpPath = null; var menuItem = new ToolStripMenuItem() { Text = OpenWinScpMenuItemText, Image = (System.Drawing.Image)QuickConnectPlugin.Properties.Resources.winscp, Enabled = QuickConnectUtils.CanOpenWinScp(Settings, hostPwEntry, out winScpPath) }; if (Settings.EnableShortcutKeys == true && Settings.WinScpShortcutKey != Keys.None) { menuItem.ShortcutKeys = Settings.WinScpShortcutKey; menuItem.ShowShortcutKeys = true; } menuItem.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(menuItem); } ; return(menuItems); }
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"); } } }
internal static bool CanOpenWinScp(IQuickConnectPluginSettings settings, IHostPwEntry hostPwEntry, out string winScpPath) { winScpPath = !String.IsNullOrEmpty(settings.WinScpPath) ? settings.WinScpPath : QuickConnectUtils.GetWinScpPath(); return(hostPwEntry.HasIPAddress && !String.IsNullOrEmpty(winScpPath)); }
internal static bool CanOpenPutty(IQuickConnectPluginSettings settings, IHostPwEntry hostPwEntry, out string puttyPath) { puttyPath = !String.IsNullOrEmpty(settings.PuttyPath) ? settings.PuttyPath : QuickConnectUtils.GetPuttyPath(); return(hostPwEntry.HasIPAddress && !String.IsNullOrEmpty(puttyPath)); }