コード例 #1
0
        /// <summary>
        /// Start SFTP Manager
        /// </summary>
        private void StartSFTPManager(Tuple <string, string, string> _credentials)
        {
            string PrivateKey = null;
            string hostname   = _credentials.Item1;
            string login      = _credentials.Item2;
            string password   = _credentials.Item3;
            string pk_pwd     = null;

            if (File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                                         "PuTTYStorm", "privatekeys.xml")))
            {
                SavedPrivatekeysInfo privatekeys = saved_data.get_PrivateKeys();
                string[]             groups      = IsPasswordLess.GetGroupsForPwdLessHostname(containers_list, _credentials.Item1);

                // Check if group or su-group is part of private keys configuration setup
                if ((IsPasswordLess.IsGroupBetweenPrivateKeys(privatekeys, groups[0])) ||
                    (IsPasswordLess.IsGroupBetweenPrivateKeys(privatekeys, groups[1])))
                {
                    // Fetch private key and password for group
                    PrivateKey = IsPasswordLess.GetOpenSSHPrivateKeyForGroup(privatekeys, groups[0]);
                    pk_pwd     = IsPasswordLess.GetOpenSSHPrivateKeyPassPhrase(privatekeys, groups[0]);

                    // If private key and password is still null, then sub-group is part of its setup - fetch it!
                    if (PrivateKey == null && pk_pwd == null)
                    {
                        Console.WriteLine("## Sub-group is part of pwdess login!");
                        PrivateKey = IsPasswordLess.GetOpenSSHPrivateKeyForGroup(privatekeys, groups[1]);
                        pk_pwd     = IsPasswordLess.GetOpenSSHPrivateKeyPassPhrase(privatekeys, groups[1]);
                    }

                    // If private key doesn't exists or is still null then something is wrong! Stop processing and return!
                    if (!File.Exists(PrivateKey))
                    {
                        if (PrivateKey == null || PrivateKey == "")
                        {
                            PrivateKey = "of OpenSSH type or its group";
                        }
                        MessageBox.Show("You are going to use SFTP Manager passwordless login, " + Environment.NewLine +
                                        "however private key " + PrivateKey + " doesn't exists!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);

                        return;
                    }

                    password = null;
                }
            }

            SFTPManager sftpManagerForm = new SFTPManager(hostname, login, password, PrivateKey, pk_pwd);

            sftpManagerForm.Name = "SFTPManager";
            sftpManagerForm.Text = GlobalVar.VERSION + " - SFTP Manager";
            sftpManagerForm.Show();
        }
コード例 #2
0
        /// <summary>
        /// See: private void RunCodeButton_Click(object sender, EventArgs e)
        /// </summary>
        public void ExecuteDelegate(Tuple <string, string, string> _credentials, ExecuteFunction f)
        {
            string PrivateKey = null;
            string hostname   = _credentials.Item1;
            string login      = _credentials.Item2;
            string password   = _credentials.Item3;
            string pk_pwd     = null;

            if (File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                                         "PuTTYStorm", "privatekeys.xml")))
            {
                string[] groups = IsPasswordLess.GetGroupsForPwdLessHostname(containers_list, _credentials.Item1);

                // Check if group or su-group is part of private keys configuration setup
                if ((IsPasswordLess.IsGroupBetweenPrivateKeys(privatekeys, groups[0])) ||
                    (IsPasswordLess.IsGroupBetweenPrivateKeys(privatekeys, groups[1])))
                {
                    // Fetch private key and password for group
                    PrivateKey = IsPasswordLess.GetOpenSSHPrivateKeyForGroup(privatekeys, groups[0]);
                    pk_pwd     = IsPasswordLess.GetOpenSSHPrivateKeyPassPhrase(privatekeys, groups[0]);

                    // If private key and password is still null, then sub-group is part of its setup - fetch it!
                    if (PrivateKey == null && pk_pwd == null)
                    {
                        Console.WriteLine("## Sub-group is part of pwdess login!");
                        PrivateKey = IsPasswordLess.GetOpenSSHPrivateKeyForGroup(privatekeys, groups[1]);
                        pk_pwd     = IsPasswordLess.GetOpenSSHPrivateKeyPassPhrase(privatekeys, groups[1]);
                    }

                    // If private key doesn't exists or is still null then something is wrong! Stop processing and return!
                    if (!File.Exists(PrivateKey))
                    {
                        if (PrivateKey == null || PrivateKey == "")
                        {
                            PrivateKey = "of OpenSSH type or its group";
                        }
                        MessageBox.Show("You are going to use Kotarak passwordless login, " + Environment.NewLine +
                                        "however private key " + PrivateKey + " doesn't exists!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);

                        return;
                    }

                    password = null;
                }
            }

            // Priority Login
            if (ForceAccountCheckBox.Checked)
            {
                string    force_username;
                string    force_password;
                Control[] force_username_texbox = this.Controls.Find("LoginTextBox", true);
                Control[] force_password_texbox = this.Controls.Find("PasswordTextBox", true);

                force_username = force_username_texbox[0].Text;
                force_password = force_password_texbox[0].Text;

                login    = force_username;
                password = force_password;

                PrivateKey = null;
            }

            f(dataGridView1, ReadValueFromControl(scintilla1), hostname, login, password, PrivateKey, pk_pwd);
        }