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);
        }
예제 #2
0
        public void ChangePassword(String ipAddress, String username, String password)
        {
            var esxiPasswordChanger = new ESXiPasswordChanger();

            Assert.DoesNotThrow(() => esxiPasswordChanger.ChangePassword(ipAddress, username, password, password));
        }