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 bool isPsPasswdPathValid() { if (this.textBoxPsPasswdPath.Text.Length == 0) { this.pictureBoxPsPasswdPathWarningIcon.Visible = false; this.labelPsPasswdPathWarningMessage.Visible = false; this.textBoxPsPasswdPath.BackColor = default(Color); return(true); } else { this.pictureBoxPsPasswdPathWarningIcon.Visible = true; this.labelPsPasswdPathWarningMessage.Visible = true; if (File.Exists(this.textBoxPsPasswdPath.Text)) { if (!PsPasswdWrapper.IsPsPasswdUtility(this.textBoxPsPasswdPath.Text)) { this.labelPsPasswdPathWarningMessage.Text = String.Format("Specified file is not valid."); return(false); } else if (!PsPasswdWrapper.IsSupportedVersion(this.textBoxPsPasswdPath.Text)) { this.labelPsPasswdPathWarningMessage.Text = String.Format("Only version {0} is supported.", PsPasswdWrapper.SupportedVersion); return(false); } else { this.pictureBoxPsPasswdPathWarningIcon.Visible = false; this.labelPsPasswdPathWarningMessage.Visible = false; return(true); } } else { this.pictureBoxPsPasswdPathWarningIcon.Image = global::QuickConnectPlugin.Properties.Resources.important; this.labelPsPasswdPathWarningMessage.Text = "Specified path does not exists."; return(false); } } }
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); }
public void ChangePassword(String ipAddress, String username, String password) { var psPasswdWrapper = new PsPasswdWrapper(@"C:\Program Files (x86)\SysinternalsSuite\pspasswd_122.exe"); Assert.DoesNotThrow(() => psPasswdWrapper.ChangePassword(ipAddress, username, password, username, password)); }
public void IsPsPasswdUtility(String psPasswdPath, bool expectedResult) { Assert.AreEqual(expectedResult, PsPasswdWrapper.IsPsPasswdUtility(psPasswdPath)); }
public void IsSupportedVersion(String psPasswdPath, bool expectedResult) { Assert.AreEqual(expectedResult, PsPasswdWrapper.IsSupportedVersion(psPasswdPath)); }