예제 #1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var ioConnectionInfo = new IOConnectionInfo()
            {
                Path = databasePath
            };

            var key = new CompositeKey();

            key.AddUserKey(new KcpPassword(databasePassword));

            var pwDatabase = new PwDatabase();

            pwDatabase.Open(ioConnectionInfo, key, null);

            var fieldMapper = new InMemoryFieldMapper()
            {
                HostAddress      = "IP Address",
                ConnectionMethod = "OS"
            };

            IPasswordChangerTreeNode treeNode = PasswordChangerTreeNode.Build(pwDatabase, fieldMapper);

            var pwChangerServiceFactory = new PasswordChangerServiceFactory(
                new PasswordDatabase(pwDatabase),
                new FakePasswordChangerExFactoryThatThrowsException()
                );

            var formBatchPasswordChanger = new FormBatchPasswordChanger(treeNode, pwChangerServiceFactory);

            Application.Run(formBatchPasswordChanger);
        }
        private void treeViewAfterSelect(object sender, TreeViewEventArgs e)
        {
            Debug.WriteLine("treeViewAfterSelect");
            IPasswordChangerTreeNode treeNode = e.Node as IPasswordChangerTreeNode;

            if (treeNode != null)
            {
                bool showPassword = this.showPasswordIsChecked();
                this.listView.Items.Clear();
                foreach (var pwEntry in treeNode.GetEntries(this.toolStripMenuItemShowEntriesOfSubgroups.Checked))
                {
                    PwEntryListViewItem item = new PwEntryListViewItem(pwEntry, showPassword);
                    this.listView.Items.Add(item);
                }
            }
        }
예제 #3
0
        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 FormBatchPasswordChanger(
            IPasswordChangerTreeNode pwChangerTreeNode,
            IPasswordChangerServiceFactory pwChangerServiceFactory
            )
        {
            InitializeComponent();

            this.pwChangerServiceFactory = pwChangerServiceFactory;

            // Smooth resize.
            if (this.FormBorderStyle == System.Windows.Forms.FormBorderStyle.Sizable)
            {
                this.treeView.Dock = DockStyle.Fill;
                this.listView.Dock = DockStyle.Fill;
                this.splitContainer.IsSplitterFixed = false;
            }
            else
            {
                this.splitContainer.IsSplitterFixed = true;
            }

            this.buttonStartChangePasswords.Enabled = false;
            this.checkBoxOverrideHostType.Checked   = false;
            this.comboBoxHostType.Enabled           = false;
            this.toolStripMenuItemSaveLogAs.Enabled = false;
            this.toolStripMenuItemClearLog.Enabled  = false;

            foreach (var hostType in this.pwChangerServiceFactory.GetSupported())
            {
                this.comboBoxHostType.Items.Add(hostType);
            }
            this.checkBoxOverrideHostType.Enabled = this.comboBoxHostType.Items.Count > 0;

            this.listView.FullRowSelect = true;

            this.treeView.Nodes.Add(pwChangerTreeNode.Root);
            this.treeView.Nodes[0].Expand();
            this.treeView.AfterSelect += new TreeViewEventHandler(treeViewAfterSelect);

            this.listViewContextMenuStrip = new ContextMenuStrip();
            listViewContextMenuStrip.Items.Add("Select all");
            listViewContextMenuStrip.Items.Add("Deselect all");
            listViewContextMenuStrip.Items[0].Click += new EventHandler(selectAllClick);
            listViewContextMenuStrip.Items[1].Click += new EventHandler(deselectAllClick);
            this.listView.ContextMenuStrip           = listViewContextMenuStrip;

            this.toolStripMenuItemSaveLogAs.Click += new EventHandler(saveLogAsClick);
            this.toolStripMenuItemClearLog.Click  += new EventHandler(clearLogClick);

            this.maskedTextBoxNewPassword.TextChanged       += new EventHandler(checkPasswords);
            this.maskedTextBoxRepeatNewPassword.TextChanged += new EventHandler(checkPasswords);
            this.checkBoxOverrideHostType.Click             += new EventHandler(overrideHostTypeClick);
            this.buttonStartChangePasswords.Click           += new EventHandler(startChangePasswordsClick);
            this.textBox.TextChanged += new EventHandler(textBoxTextChanged);

            this.listView.ItemChecked += new ItemCheckedEventHandler(checkControls);
            this.maskedTextBoxNewPassword.TextChanged       += new EventHandler(checkControls);
            this.maskedTextBoxRepeatNewPassword.TextChanged += new EventHandler(checkControls);
            this.checkBoxOverrideHostType.CheckStateChanged += new EventHandler(checkControls);
            this.comboBoxHostType.SelectedIndexChanged      += new EventHandler(checkControls);

            this.FormClosing += new FormClosingEventHandler(formClosing);
            this.KeyDown     += new KeyEventHandler(form_KeyPress);
        }