Beispiel #1
0
        public override PuttySessionInfo GetSession(string sessionName)
        {
            var registrySessionName = GetRegistrySessionName(sessionName);

            if (!string.IsNullOrEmpty(registrySessionName))
            {
                return(ModifyRegistrySessionInfo(PuttySessionsRegistryProvider.GetSession(registrySessionName)));
            }

            var sessionsFolderPath = GetSessionsFolderPath();

            if (!Directory.Exists(sessionsFolderPath))
            {
                return(null);
            }

            var sessionFile = Path.Combine(sessionsFolderPath, sessionName);

            if (!File.Exists(sessionFile))
            {
                return(null);
            }

            sessionName = System.Web.HttpUtility.UrlDecode(sessionName.Replace("+", "%2B"));

            var sessionFileReader = new SessionFileReader(sessionFile);
            var sessionInfo       = new PuttySessionInfo
            {
                PuttySession = sessionName,
                Name         = sessionName,
                Hostname     = sessionFileReader.GetValue("HostName"),
                Username     = sessionFileReader.GetValue("UserName")
            };
            var protocol = sessionFileReader.GetValue("Protocol") ?? "ssh";

            switch (protocol.ToLowerInvariant())
            {
            case "raw":
                sessionInfo.Protocol = ProtocolType.RAW;
                break;

            case "rlogin":
                sessionInfo.Protocol = ProtocolType.Rlogin;
                break;

            case "serial":
                return(null);

            case "ssh":
                object sshVersionObject = sessionFileReader.GetValue("SshProt");
                if (sshVersionObject != null)
                {
                    var sshVersion = Convert.ToInt32(sshVersionObject);
                    sessionInfo.Protocol = sshVersion >= 2 ? ProtocolType.SSH2 : ProtocolType.SSH1;
                }
                else
                {
                    sessionInfo.Protocol = ProtocolType.SSH2;
                }
                break;

            case "telnet":
                sessionInfo.Protocol = ProtocolType.Telnet;
                break;

            default:
                return(null);
            }
            sessionInfo.Port = Convert.ToInt32(sessionFileReader.GetValue("PortNumber"));

            return(sessionInfo);
        }
		public override PuttySessionInfo GetSession(string sessionName)
		{
            var registrySessionName = GetRegistrySessionName(sessionName);
			if (!string.IsNullOrEmpty(registrySessionName))
			{
				return ModifyRegistrySessionInfo(PuttySessionsRegistryProvider.GetSession(registrySessionName));
			}

            var sessionsFolderPath = GetSessionsFolderPath();
			if (!Directory.Exists(sessionsFolderPath))
			{
				return null;
			}

            var sessionFile = Path.Combine(sessionsFolderPath, sessionName);
			if (!File.Exists(sessionFile))
			{
				return null;
			}
				
			sessionName = System.Web.HttpUtility.UrlDecode(sessionName.Replace("+", "%2B"));

            var sessionFileReader = new SessionFileReader(sessionFile);
		    var sessionInfo = new PuttySessionInfo
		    {
		        PuttySession = sessionName,
		        Name = sessionName,
		        Hostname = sessionFileReader.GetValue("HostName"),
		        Username = sessionFileReader.GetValue("UserName")
		    };
		    var protocol = sessionFileReader.GetValue("Protocol") ?? "ssh";
		    switch (protocol.ToLowerInvariant())
			{
				case "raw":
					sessionInfo.Protocol = ProtocolType.RAW;
					break;
				case "rlogin":
					sessionInfo.Protocol = ProtocolType.Rlogin;
					break;
				case "serial":
					return null;
				case "ssh":
					object sshVersionObject = sessionFileReader.GetValue("SshProt");
					if (sshVersionObject != null)
					{
					    var sshVersion = Convert.ToInt32(sshVersionObject);
					    sessionInfo.Protocol = sshVersion >= 2 ? ProtocolType.SSH2 : ProtocolType.SSH1;
					}
					else
					{
						sessionInfo.Protocol = ProtocolType.SSH2;
					}
					break;
				case "telnet":
					sessionInfo.Protocol = ProtocolType.Telnet;
					break;
				default:
					return null;
			}
			sessionInfo.Port = Convert.ToInt32(sessionFileReader.GetValue("PortNumber"));
			
			return sessionInfo;
		}