Beispiel #1
0
 public Host(HostInfo info, Config config, PuttyProfile profile)
 {
     Info = info;
     _config = config;
     _profile = profile;
     _puttyLink = new PuttyLink(Info, config, profile);
 }
 public static void CreatePuttyInstance(HostInfo puttyInfo)
 {
     var psi = new ProcessStartInfo
                 {
                     FileName = _puttyFullPath,
                     Arguments = PuttyArguments(puttyInfo)
                 };
     var proc = Process.Start(psi);
     proc.WaitForInputIdle();
     var hwnd = proc.MainWindowHandle;
     WinApi.ShowWindowAsync(hwnd, WinApi.SW_HIDE);
 }
 public static void RemovePrivateKey(HostInfo host)
 {
     List<PrivateKey> values;
     if (_keysCache.TryGetValue(host, out values))
     {
         foreach (var key in values)
         {
             key.Dispose();
         }
         _keysCache.Remove(host);
     }
 }
Beispiel #4
0
        public bool DeepDependsOn(HostInfo host)
        {
            if (host == null) throw new ArgumentNullException("host");

            for (HostInfo dependency = DependsOn; dependency != null; dependency = dependency.DependsOn)
            {
                if (dependency == host)
                {
                    return true;
                }
            }
            return false;
        }
Beispiel #5
0
        public bool DeepDependsOn(HostInfo host)
        {
            if (host == null)
            {
                throw new ArgumentNullException("host");
            }

            for (HostInfo dependency = DependsOn; dependency != null; dependency = dependency.DependsOn)
            {
                if (dependency == host)
                {
                    return(true);
                }
            }
            return(false);
        }
        public static string PuttyArguments(HostInfo host, PuttyProfile profile, AuthenticationType authType)
        {
            // example: -ssh -load _stm_preset_ username@domainName -P 22 -pw password -D 5000 -L 44333:username.dyndns.org:44333

            string profileArg = "";
            if (profile != null)
            {
                profileArg = @" -load " + profile.Name;
            }

            var startShellOption = "";
            if (string.IsNullOrWhiteSpace(host.RemoteCommand))
            {
                startShellOption = " -N";
            }

            string args;
            switch (authType)
            {
            case AuthenticationType.None:
                args = String.Format(@"-ssh{0} {1}@{2} -P {3} -v{4}", profileArg, host.Username, host.Hostname,
                                     host.Port, startShellOption);
                Logger.Log.DebugFormat(@"plink.exe {0}", args);
                break;
            case AuthenticationType.Password:
                args = String.Format(@"-ssh{0} {1}@{2} -P {3} -pw {4} -v{5}", profileArg, host.Username, host.Hostname,
                                     host.Port, host.Password, startShellOption);
                Logger.Log.DebugFormat(@"plink.exe -ssh{0} {1}@{2} -P {3} -pw ******** -v -N", profileArg, host.Username,
                                       host.Hostname, host.Port);
                break;
            case AuthenticationType.PrivateKey:
                args = String.Format(@"-ssh{0} {1}@{2} -P {3} -i {4} -v{5}", profileArg, host.Username, host.Hostname,
                                     host.Port, PrivateKeysStorage.CreatePrivateKey(host).Filename, startShellOption);
                Logger.Log.DebugFormat(@"plink.exe {0}", args);
                break;
            default:
                throw new ArgumentOutOfRangeException("authType");
            }
            var sb = new StringBuilder(args);
            foreach (var tunnelArg in host.Tunnels.Select(tunnelArguments))
            {
                sb.Append(tunnelArg);
            }

            args = sb.ToString();
            return args;
        }
 public static PrivateKey CreatePrivateKey(HostInfo host)
 {
     if (host == null)
     {
         throw new ArgumentNullException("host");
     }
     if (host.AuthType != AuthenticationType.PrivateKey)
     {
         throw new FormatException();
     }
     
     var key = new PrivateKey(host.PrivateKeyData);
     List<PrivateKey> values;
     if (_keysCache.TryGetValue(host, out values))
     {
         values.Add(key);
     } else
     {
         _keysCache.Add(host, new List<PrivateKey>() { key });
     }
     return key;
 }
        public static string PuttyArguments(HostInfo host)
        {
            // example: -ssh username@domainName -P 22 -pw password -D 5000 -L 44333:username.dyndns.org:44333

            var args = String.Format(@"-ssh {0}@{1} -P {2} -pw {3}", host.Username, host.Hostname, host.Port, host.Password);
            var sb = new StringBuilder(args);
            foreach (var arg in host.Tunnels.Select(PuttyTunnelArguments))
            {
                sb.AppendFormat(@" {0}", (object) arg);
            }
            args = sb.ToString();
            return args;
        }
        /// <summary>
        /// Парсинг командной строки с вычленением основным параметров соединения
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public static HostInfo FromPuttyArguments(string args)
        {
            const string pattern = @"""[^""]+""\s+-ssh\s+(?<Username>[^@]+)@(?<Hostname>[^\s]+)\s+-P\s+(?<Port>\d+)\s+-pw\s+(?<Password>[^\s]+)";
            var m = Regex.Match(args, pattern);
            if (!m.Success)
                return null;

            var pid = new HostInfo
                          {
                              Username = m.Groups["Username"].Value,
                              Hostname = m.Groups["Hostname"].Value,
                              Port = m.Groups["Port"].Value,
                              Password = m.Groups["Password"].Value
                          };
            return pid;
        }
Beispiel #10
0
 public PuttyLink(HostInfo host, Config config, PuttyProfile profile)
 {
     if (host == null) throw new ArgumentNullException("host");
     if (config == null) throw new ArgumentNullException("config");
     if (profile == null) throw new ArgumentNullException("profile");
     Host = host;
     _config = config;
     _profile = profile;
 }
Beispiel #11
0
        private void reset()
        {
            if (Mode == EMode.AddHost)
            {
                _currentHost = new HostInfo();

                textBoxName.Text = "";
                textBoxHostname.Text = "";
                textBoxPort.Text = "";
                textBoxLogin.Text = "";
                tbxPassword.Text = "";
                tbxRemoteCommand.Text = "";

                comboBoxDependsOn.Items.Clear();
                var hosts = _committedHosts.Where(h => h != _currentHost && !h.DeepDependsOn(_currentHost)).OrderBy(h => h.Name);
                comboBoxDependsOn.Items.AddRange(new[] { Resources.HostDialog_DependsOnNone }.Concat<object>(hosts).ToArray());
                if (StartupDependsOn != null)
                    comboBoxDependsOn.SelectedItem = StartupDependsOn;
                else
                    comboBoxDependsOn.SelectedIndex = 0;

                tunnelsGridView.Rows.Clear();
                buttonRemoveTunnel.Enabled = tunnelsGridView.SelectedRows.Count > 0;

                _hostValidator.Reset();
                resetAddTunnelGroup();
                Text = Resources.HostDialog_AddNewHostTitle;
            }
            else // Edit mode
            {
                hostToForm();
                Text = Resources.HostDialog_EditHostTitle;
            }
        }
 private static string psftpArguments(HostInfo host)
 {
     string args;
     switch (host.AuthType)
     {
     case AuthenticationType.Password:
         args = String.Format(@"{0}@{1} -P {2} -pw {3} -batch", host.Username, host.Hostname, host.Port,
                              host.Password);
         break;
     case AuthenticationType.PrivateKey:
         args = String.Format(@"{0}@{1} -P {2} -i {3} -batch", host.Username, host.Hostname, host.Port,
                              PrivateKeysStorage.CreatePrivateKey(host).Filename);
         break;
     default:
         throw new ArgumentOutOfRangeException("authType");
     }
     return args;
 }
 public static void StartFileZilla(HostInfo host)
 {
     var fileName = Path.Combine(Util.Helper.StartupPath, FileZillaLocation);
     var args = string.Format(@"sftp://{0}:{1}@{2}:{3}", host.Username, host.Password, host.Hostname, host.Port);
     Process.Start(fileName, args);
 }
 public static void StartPsftp(HostInfo host)
 {
     var fileName = Path.Combine(Util.Helper.StartupPath, PsftpLocation);
     var args = psftpArguments(host);
     Process.Start(fileName, args);
 }
 public static void StartPutty(HostInfo host, PuttyProfile profile)
 {
     var fileName = Path.Combine(Util.Helper.StartupPath, PuttyLocation);
     var args = PuttyArguments(host, profile, host.AuthType);
     Process.Start(fileName, args);
 }