public Tunnel(Session session, int sourcePort, string destination, int destinationPort, TunnelType type) { this.session = session; this.sourcePort = sourcePort; this.destination = destination; this.destinationPort = destinationPort; this.type = type; }
public PuttyLink(Session session) { this.session = session; this.process = new Process(); this.process.StartInfo.FileName = PuttyTunnelManagerSettings.Instance().PlinkLocation; this.process.StartInfo.CreateNoWindow = true; this.process.StartInfo.UseShellExecute = false; this.guardian = new Thread(Guardian); this.guardian.IsBackground = true; this.guardian.Priority = ThreadPriority.Lowest; this.active = false; }
public static Session Load(string keyName) { string puttyKeyPath = PuttySettings.PUTTY_REGISTRY_KEYPATH_SESSIONS + @"\" + keyName; RegistryKey puttySessionKey = Registry.CurrentUser.OpenSubKey(puttyKeyPath); Session session = new Session( Uri.UnescapeDataString(keyName), puttySessionKey.GetValue(PUTTY_REGISTRY_KEY_SESSION_HOSTNAME, "").ToString(), Int32.Parse(puttySessionKey.GetValue(PUTTY_REGISTRY_KEY_SESSION_PORTNUMBER, "22").ToString()) ); session.Username = puttySessionKey.GetValue(PUTTY_REGISTRY_KEY_SESSION_USERNAME, "").ToString(); session.Compression = puttySessionKey.GetValue(PUTTY_REGISTRY_KEY_SESSION_COMPRESSION, 0).Equals(1); session.LocalPortsAcceptAll = puttySessionKey.GetValue(PUTTY_REGISTRY_KEY_SESSION_LOCALPORTACCEPTALL, 0).Equals(1); string ptmKeyPath = PuttyTunnelManagerSettings.PTM_REGISTRY_KEYPATH_SESSIONS + @"\" + keyName; RegistryKey ptmSessionKey = Registry.CurrentUser.OpenSubKey(ptmKeyPath); // Load Tunnel Manager specific settings. if (ptmSessionKey != null) { session.UsePtmForTunnels = ptmSessionKey.GetValue(PTM_REGISTRY_KEY_SESSION_USEPTMFORTUNNELS, 0).Equals(1); } string[] portForwardingList; if (session.UsePtmForTunnels && ptmSessionKey != null) { portForwardingList = ptmSessionKey.GetValue(PTM_REGISTRY_KEY_SESSION_PORTFORWARDINGS, "").ToString().Split(','); ptmSessionKey.Close(); } else portForwardingList = puttySessionKey.GetValue(PUTTY_REGISTRY_KEY_SESSION_PORTFORWARDINGS, "").ToString().Split(','); puttySessionKey.Close(); foreach (string portForwarding in portForwardingList) { if (portForwarding.Length > 0) { Tunnel t = Tunnel.Load(session, portForwarding); session.Tunnels.Add(t); } } return session; }
public static Tunnel Load(Session session, string data) { string[] parts = data.Substring(1).Split('=', ':'); int sourcePort = Int32.Parse(parts[0]); string destination = ""; int destinationPort = 0; if (parts.Length > 1) { destination = parts[1]; destinationPort = Int32.Parse(parts[2]); } TunnelType type; switch (data.Substring(0, 1)) { default: case "L": type = TunnelType.LOCAL; break; case "R": type = TunnelType.REMOTE; break; case "D": type = TunnelType.DYNAMIC; break; } return new Tunnel(session, sourcePort, destination, destinationPort, type); }
public static Tunnel Load(Session session, string data) { string [] srcdest = data.Substring(1).Split('='); string [] src = srcdest[0].Split(':'); int sourcePort = Int32.Parse(src[src.Length - 1]); string destination = ""; int destinationPort = 0; // Empty data may look like "D100=" instead of just "D100" if (src.Length > 1) { string [] dst = srcdest[1].Split(':'); if (dst.Length > 1) { destination = dst[0]; destinationPort = Int32.Parse(dst[1]); } } TunnelType type; switch (data.Substring(0, 1)) { default: case "L": type = TunnelType.LOCAL; break; case "R": type = TunnelType.REMOTE; break; case "D": type = TunnelType.DYNAMIC; break; } return new Tunnel(session, src.Length == 2 ? src[0] : "", sourcePort, destination, destinationPort, type); }
public static Tunnel Load(Session session, string data) { int sourcePort = 0; string destination = ""; int destinationPort = 0; TunnelType type = TunnelType.LOCAL; var match = Regex.Match(data, "(?<ipprotocol>[46])?(?<tunnelType>[LRD])(?<sourcePort>[0-9]*)=(?<destination>[^:]*):(?<destinationPort>[0-9]*)|(?<ipprotocol>[46])?(?<tunnelType>[LRD])(?<sourcePort>[0-9]*)"); if (match.Success) { if (match.Groups["ipprotocol"].Success) { // implement ip protocol handling } if(match.Groups["tunnelType"].Success) { switch (match.Groups["tunnelType"].Value) { default: case "L": type = TunnelType.LOCAL; break; case "R": type = TunnelType.REMOTE; break; case "D": type = TunnelType.DYNAMIC; break; } } if(match.Groups["sourcePort"].Success) { sourcePort = Int32.Parse(match.Groups["sourcePort"].Value); } if (match.Groups["destination"].Success) { destination = match.Groups["destination"].Value; } if(match.Groups["destinationPort"].Success) { destinationPort = Int32.Parse(match.Groups["destinationPort"].Value); } } return new Tunnel(session, sourcePort, destination, destinationPort, type); }