public void FormatWithTelnetConnection() { InMemoryHostPwEntry pwEntry = new InMemoryHostPwEntry() { Username = "******", Password = "******", IPAddress = "127.0.0.1" }; pwEntry.ConnectionMethods.Add(ConnectionMethodType.PuttyTelnet); FakePuttySessionFinder sessionFinder = new FakePuttySessionFinder(); PuttyArgumentsFormatter argumentsFormatter = new PuttyArgumentsFormatter("putty.exe", sessionFinder, true); Assert.AreEqual("\"putty.exe\" -telnet [email protected]", argumentsFormatter.Format(pwEntry)); }
public void FormatWithSSHConnectionAndSessionNotFound() { InMemoryHostPwEntry pwEntry = new InMemoryHostPwEntry() { Username = "******", Password = "******", IPAddress = "127.0.0.1", AdditionalOptions = "session:MySession1" }; pwEntry.ConnectionMethods.Add(ConnectionMethodType.PuttySSH); FakePuttySessionFinder sessionFinder = new FakePuttySessionFinder(); PuttyArgumentsFormatter argumentsFormatter = new PuttyArgumentsFormatter("putty.exe", sessionFinder, true); Assert.AreEqual("\"putty.exe\" -ssh [email protected] -pw \"12345678\"", argumentsFormatter.Format(pwEntry)); }
public void FormatWithNoPassword() { InMemoryHostPwEntry pwEntry = new InMemoryHostPwEntry() { Username = "******", Password = "******", IPAddress = "127.0.0.1:2222" }; pwEntry.ConnectionMethods.Add(ConnectionMethodType.PuttySSH); var mock = new Mock <IPuttySessionFinder>(); mock.Setup(m => m.Find(It.IsAny <String>())).Returns(new Collection <String>()); PuttyArgumentsFormatter argumentsFormatter = new PuttyArgumentsFormatter("putty.exe", mock.Object, false); Assert.AreEqual("\"putty.exe\" -P 2222 -ssh [email protected]", argumentsFormatter.Format(pwEntry)); }
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"); } } }
public void FormatWithCommandContainingPort(bool appendPassword) { InMemoryHostPwEntry pwEntry = new InMemoryHostPwEntry() { Username = "******", Password = "******", IPAddress = "127.0.0.1", AdditionalOptions = "ssh;command:-L 5555:127.0.0.1:5432 -pw \"123456\"" }; pwEntry.ConnectionMethods.Add(ConnectionMethodType.PuttySSH); var mock = new Mock <IPuttySessionFinder>(); mock.Setup(m => m.Find(It.IsAny <String>())).Returns(new Collection <String>()); PuttyArgumentsFormatter argumentsFormatter = new PuttyArgumentsFormatter("putty.exe", mock.Object, appendPassword); Assert.AreEqual("\"putty.exe\" -ssh [email protected] -L 5555:127.0.0.1:5432 -pw \"123456\"", argumentsFormatter.Format(pwEntry)); }
public void FormatWithPortFromHostAddressTakePrecedence() { InMemoryHostPwEntry pwEntry = new InMemoryHostPwEntry() { Username = "******", Password = "******", IPAddress = "127.0.0.1:2222", AdditionalOptions = "session:MySession1;port:50000" }; pwEntry.ConnectionMethods.Add(ConnectionMethodType.PuttySSH); var mock = new Mock <IPuttySessionFinder>(); mock.Setup(m => m.Find(It.IsAny <String>())).Returns(new Collection <String>() { "MySession" }); PuttyArgumentsFormatter argumentsFormatter = new PuttyArgumentsFormatter("putty.exe", mock.Object, true); Assert.AreEqual("\"putty.exe\" -load \"MySession\" -P 2222 -ssh [email protected] -pw \"12345678\"", argumentsFormatter.Format(pwEntry)); }
public void FormatWithKeyFile() { InMemoryHostPwEntry pwEntry = new InMemoryHostPwEntry() { Username = "******", Password = "******", IPAddress = "127.0.0.1", AdditionalOptions = "key:\"C:\\Key Files\\PrivateKey.ppk\"" }; pwEntry.ConnectionMethods.Add(ConnectionMethodType.PuttySSH); var mock = new Mock <IPuttySessionFinder>(); mock.Setup(m => m.Find(It.IsAny <String>())).Returns(new Collection <String>()); PuttyArgumentsFormatter argumentsFormatter = new PuttyArgumentsFormatter("putty.exe", mock.Object, true); Assert.AreEqual("\"putty.exe\" -i \"C:\\Key Files\\PrivateKey.ppk\" -ssh [email protected] -pw \"12345678\"", argumentsFormatter.Format(pwEntry)); }
public void FormatWithSSHConnectionAndOverrideDefaultPort() { InMemoryHostPwEntry pwEntry = new InMemoryHostPwEntry() { Username = "******", Password = "******", IPAddress = "127.0.0.1", AdditionalOptions = "session:MySession1;port:50000" }; pwEntry.ConnectionMethods.Add(ConnectionMethodType.PuttySSH); FakePuttySessionFinder sessionFinder = new FakePuttySessionFinder(); sessionFinder.Sessions.Add("MySession"); PuttyArgumentsFormatter argumentsFormatter = new PuttyArgumentsFormatter("putty.exe", sessionFinder); Assert.AreEqual("\"putty.exe\" -load \"MySession\" -P 50000 -ssh [email protected] -pw \"12345678\"", argumentsFormatter.Format(pwEntry)); }