示例#1
0
        /// <summary>
        /// Load a list of remote hosts from the registry into the list box
        /// </summary>
        private void RefreshRemoteHosts()
        {
            listHosts.Items.Clear();
            try
            {
                string[] keys;
                using (var reg = Registry.CurrentUser.OpenSubKey(PuTTY_Regkey, false))
                {
                    keys = reg.GetValueNames();
                }

                foreach (string key in keys)
                {
                    ClassUrl.Url url = ClassUrl.Parse(key);
                    // Decipher the registry host format using our URL parse functions,
                    // the fields align in the following way:
                    // Ex. rsa2@22:github.com
                    if (url.Ok)
                    {
                        listHosts.Items.Add(url.Path + "  Port: " + url.Host + "  Type: " + url.User);
                    }
                    else
                    {
                        listHosts.Items.Add(key);
                    }
                }
                listHosts.Tag = keys;   // Store list of keys in the listBox tag
            }
            catch { }
        }
示例#2
0
        /// <summary>
        /// Return current values from the input fields
        /// </summary>
        /// <returns>Structure with values</returns>
        public ClassRemotes.Remote Get()
        {
            ClassRemotes.Remote repo = new ClassRemotes.Remote();
            repo.Name     = textName.Text.Trim();
            repo.PushCmd  = textPushCmd.Text.Trim();
            repo.Password = textPassword.Text.Trim();

            // For SSH, make sure the URL string follows the strict format
            if (_fetchUrl.Type == ClassUrl.UrlType.Ssh)
            {
                repo.UrlFetch = ClassUrl.ToCanonical(textUrlFetch.Text.Trim());
            }
            else
            {
                repo.UrlFetch = textUrlFetch.Text.Trim();
            }

            if (_pushUrl.Type == ClassUrl.UrlType.Ssh)
            {
                repo.UrlPush = ClassUrl.ToCanonical(textUrlPush.Text.Trim());
            }
            else
            {
                repo.UrlPush = textUrlPush.Text.Trim();
            }

            return(repo);
        }
示例#3
0
        /// <summary>
        /// Test connection to the selected host
        /// </summary>
        private void BtTestHostClick(object sender, EventArgs e)
        {
            string[] keys = listHosts.Tag as string[];
            string   key  = keys[listHosts.SelectedIndex];

            ClassUrl.Url url = ClassUrl.Parse(key);
            App.Putty.RunPLink(String.Format("-agent git@{0} -P {1}", url.Path, url.Host));
        }
示例#4
0
        /// <summary>
        /// Text in the input box has changed. Validate it and if it's a valid HTTPS URL, enable the "Add" button
        /// </summary>
        private void TextBoxHostTextChanged(object sender, EventArgs e)
        {
            // First, a simple test that allows users to paste a clone command
            textBoxHost.Text = textBoxHost.Text.Replace("git clone ", "");

            ClassUrl.Url host = ClassUrl.Parse(textBoxHost.Text);
            btAddHost.Enabled = host.Type == ClassUrl.UrlType.Https;
        }
示例#5
0
        /// <summary>
        /// Validate entries and return true if they are reasonably valid
        /// </summary>
        public bool IsValid()
        {
            _fetchUrl = ClassUrl.Parse(textUrlFetch.Text.Trim());
            _pushUrl  = ClassUrl.Parse(textUrlPush.Text.Trim());

            // Consider valid entry if the name is ok and some combination of urls
            return(textName.Text.Trim().Length > 0 && _fetchUrl.Type != ClassUrl.UrlType.Unknown);
        }
示例#6
0
        /// <summary>
        /// Initializes SSH connection by running the PLINK using the specified
        /// connection parameters. This function blocks until the PLINK returns.
        /// </summary>
        public void ImportRemoteSshKey(ClassUrl.Url url)
        {
            // Build the arguments to the PLINK process: port number, user and the host
            // Use the default SSH values if the url did not provide them
            string args = " -P " + (url.Port > 0 ? url.Port.ToString() : "22") +
                          " -l " + (string.IsNullOrEmpty(url.User) ? "anonymous" : url.User) +
                          " " + url.Host;

            // plink does everything through its stderr stream
            ExecResult result = Exec.Run(pathPlink, args);
            App.PrintLogMessage(result.stderr, MessageType.Error);
        }
示例#7
0
 /// <summary>
 /// Disable or enable Add Host button based on the validity of the host address
 /// </summary>
 private void TextBoxHostTextChanged(object sender, EventArgs e)
 {
     remoteUrl         = ClassUrl.Parse(textBoxHost.Text);
     btAddHost.Enabled = textBoxHost.Text.Length > 0 && remoteUrl.Type == ClassUrl.UrlType.Ssh;
 }
示例#8
0
 /// <summary>
 /// User clicked on the Add host button, prompt for user name and password and then add it
 /// </summary>
 private void BtAddHostClick(object sender, EventArgs e)
 {
     // We assume the URL in the text box is a well formatted HTTPS string since Add button would not be enabled otherwise
     ClassUrl.Url host = ClassUrl.Parse(textBoxHost.Text.Trim());
     AddEdit(host.Host); // Use only the host part of the address
 }
示例#9
0
 /// <summary>
 /// Checks the given web target link and returns true if it is reasonably valid URL
 /// </summary>
 private bool isValidUrl(string target)
 {
     ClassUrl.Url url = ClassUrl.Parse(target.Trim());
     return(url.Ok);
 }