Beispiel #1
0
        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[] parts = data.Substring(1).Split('=', ':');

            int    sourcePort      = parsePuTTYPort(parts[0]);
            string destination     = "";
            int    destinationPort = 0;

            if ((parts.Length > 1) && (parts[1].Trim().Length > 0)) // So what if the PortForwardings line is something like 'D8080='
            {
                destination = parts[1];

                destinationPort = parsePuTTYPort(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));
        }
Beispiel #3
0
        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 AddTunnelForm(TunnelType tunnelType)
        {
            InitializeComponent();

            this.tunnelType      = tunnelType;
            this.sourcePort      = -1;
            this.destinationPort = -1;

            switch (tunnelType)
            {
            case TunnelType.LOCAL:
                this.Text = "Add local port";
                this.labelSourcePort.Text      = "Local port:";
                this.labelDestination.Text     = "Remote host:";
                this.labelDestinationPort.Text = "Remote port:";
                break;

            case TunnelType.REMOTE:
                this.Text = "Add remote port";
                this.labelSourcePort.Text      = "Remote port:";
                this.labelDestination.Text     = "Local host:";
                this.labelDestinationPort.Text = "Local port:";
                break;

            case TunnelType.DYNAMIC:
                this.Text = "Add dynamic port";
                this.labelSourcePort.Text = "Local port:";

                this.labelDestination.Hide();
                this.destinationTextBox.Hide();
                this.labelDestinationPort.Hide();
                this.destinationPortTextBox.Hide();
                break;
            }
        }
        public AddTunnelForm(TunnelType tunnelType)
        {
            InitializeComponent();

            this.tunnelType = tunnelType;
            this.sourcePort = -1;
            this.destinationPort = -1;

            switch (tunnelType)
            {
                case TunnelType.LOCAL:
                    this.Text = "Add local port";
                    this.labelSourcePort.Text = "Local port:";
                    this.labelDestination.Text = "Remote host:";
                    this.labelDestinationPort.Text = "Remote port:";
                    break;

                case TunnelType.DYNAMIC:
                    this.Text = "Add dynamic port";
                    this.labelSourcePort.Text = "Local port:";

                    this.labelDestination.Hide();
                    this.destinationTextBox.Hide();
                    this.labelDestinationPort.Hide();
                    this.destinationPortTextBox.Hide();
                    break;
            }
        }
Beispiel #6
0
 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;
 }
Beispiel #7
0
        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;
        }
Beispiel #8
0
 protected override void Awake()
 {
     if (singleton)
     {
         Debug.LogError("Multiple of this type");
     }
     singleton       = this;
     resourceTypeIn  = new ResourceTypes[] { ResourceTypes.People };
     resourceTypeOut = new ResourceTypes[] { ResourceTypes.People };
     name            = "Tunnel";
     base.Awake();
     resourceInTypeMaxes[(int)ResourceTypes.People]            = 10;
     resourceTypeMaxesIncreasePerLevel[(int)resourceTypeIn[0]] = 10;
 }
		public TunnelTypeAttribute(byte tag, TunnelType tunnelType) : base(RadiusAttributeType.TUNNEL_TYPE)
		{
			Tag = tag;
			TunnelType = tunnelType;
			Data = BitConverter.GetBytes((uint)tunnelType);
			
			Length = TUNNEL_TYPE_LENGTH;
			RawData = new byte[Length];

			RawData[0] = (byte)Type;
			RawData[1] = Length;
			RawData[2] = ((tag & 0xFF) == 0) ? (byte)0x00 : tag;

			Array.Copy(Utils.IntTo3Byte((int)tunnelType), 0, RawData, TUNNEL_TYPE_VALUE_INDEX, TUNNEL_TYPE_VALUE_LENGTH);
		}
        public TunnelTypeAttribute(byte tag, TunnelType tunnelType) : base(RadiusAttributeType.TUNNEL_TYPE)
        {
            Tag        = tag;
            TunnelType = tunnelType;
            Data       = BitConverter.GetBytes((uint)tunnelType);

            Length  = TUNNEL_TYPE_LENGTH;
            RawData = new byte[Length];

            RawData[0] = (byte)Type;
            RawData[1] = Length;
            RawData[2] = ((tag & 0xFF) == 0) ? (byte)0x00 : tag;

            Array.Copy(Utils.IntTo3Byte((int)tunnelType), 0, RawData, TUNNEL_TYPE_VALUE_INDEX, TUNNEL_TYPE_VALUE_LENGTH);
        }
Beispiel #11
0
        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));
        }
Beispiel #12
0
        public Tunnel(int x, int y, int height, TunnelType type)
        {
            X      = x;
            Y      = y;
            Height = height;
            Type   = type;
            if (Type == TunnelType.Bottom)
            {
                model = Resources.pipe;
            }
            else
            {
                model = Resources.pipeD;
            }

            pointCounted = false;
        }
Beispiel #13
0
 public static string getCode(this TunnelType type)
 {
     return(type.ToString().Substring(0, 1));
 }
Beispiel #14
0
        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);
        }
Beispiel #15
0
 public Tunnel(TunnelType tunelType, string userUrl, int userId)
 {
     TunelType = tunelType;
     UserUrl   = userUrl;
     UserId    = userId;
 }
Beispiel #16
0
        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);
        }
Beispiel #17
0
        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);
        }
Beispiel #18
0
        /// <summary>
        /// 创建或更新一个VPN连接(指定VPN名称,及IP)
        /// </summary>
        public void CreateOrUpdateVPN(string updateVPNname, string updateVPNip)
        {
            try
            {
                switch (TunnelType.ToLower())
                {
                case "pptp":
                    VpnStrategy = RasVpnStrategy.PptpOnly;
                    break;

                case "l2tp":
                    VpnStrategy = RasVpnStrategy.L2tpOnly;
                    break;

                case "sstp":
                    VpnStrategy = RasVpnStrategy.SstpOnly;
                    break;

                case "ikev2":
                    VpnStrategy = RasVpnStrategy.IkeV2Only;
                    break;

                case "automatic":
                    VpnStrategy = RasVpnStrategy.Default;
                    break;

                default:
                    VpnStrategy = RasVpnStrategy.PptpOnly;
                    break;
                }
                switch (EncryptionLevel.ToLower())
                {
                case "optional":
                    EncryptionType = RasEncryptionType.Optional;
                    break;

                case "noencryption":
                    EncryptionType = RasEncryptionType.None;
                    break;

                case "required":
                    EncryptionType = RasEncryptionType.Require;
                    break;

                case "maximum":
                    EncryptionType = RasEncryptionType.RequireMax;
                    break;

                default:
                    EncryptionType = RasEncryptionType.None;
                    break;
                }
                RasPhoneBook allUsersPhoneBook = new RasPhoneBook();
                allUsersPhoneBook.Open(RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.AllUsers));
                // 如果已经该名称的VPN已经存在,则更新这个VPN服务器地址
                if (allUsersPhoneBook.Entries.Contains(updateVPNname))
                {
                    allUsersPhoneBook.Entries[updateVPNname].PhoneNumber    = updateVPNip;
                    allUsersPhoneBook.Entries[updateVPNname].EncryptionType = EncryptionType;
                    allUsersPhoneBook.Entries[updateVPNname].VpnStrategy    = VpnStrategy;
                    allUsersPhoneBook.Entries[updateVPNname].Options.RemoteDefaultGateway     = SplitTunneling;
                    allUsersPhoneBook.Entries[updateVPNname].Options.IPv6RemoteDefaultGateway = SplitTunneling;
                    switch (AuthenticationMethod.ToLower())
                    {
                    case "pap":
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequirePap                 = true;
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequireEap                 = false;
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequireChap                = false;
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequireMSChap2             = false;
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequireEncryptedPassword   = false;
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequireDataEncryption      = false;
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequireMSEncryptedPassword = false;
                        break;

                    case "eap":
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequireEap                 = true;
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequireChap                = false;
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequirePap                 = false;
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequireMSChap2             = false;
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequireEncryptedPassword   = false;
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequireDataEncryption      = false;
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequireMSEncryptedPassword = false;
                        break;

                    case "chap":
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequireChap                = true;
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequirePap                 = false;
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequireEap                 = false;
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequireMSChap2             = false;
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequireEncryptedPassword   = false;
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequireDataEncryption      = false;
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequireMSEncryptedPassword = false;
                        break;

                    case "mschapv2":
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequireMSChap2             = true;
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequirePap                 = false;
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequireEap                 = false;
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequireChap                = false;
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequireEncryptedPassword   = false;
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequireDataEncryption      = false;
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequireMSEncryptedPassword = false;
                        break;

                    default:
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequirePap                 = true;
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequireEap                 = false;
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequireChap                = false;
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequireMSChap2             = false;
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequireEncryptedPassword   = false;
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequireDataEncryption      = false;
                        allUsersPhoneBook.Entries[updateVPNname].Options.RequireMSEncryptedPassword = false;
                        break;
                    }
                }
                // 创建一个新VPN
                else
                {
                    RasEntry entry = RasEntry.CreateVpnEntry(updateVPNname, updateVPNip, VpnStrategy, RasDevice.GetDevices().First(o => o.DeviceType == RasDeviceType.Vpn));
                    entry.EncryptionType = EncryptionType;
                    entry.Options.RemoteDefaultGateway     = SplitTunneling;
                    entry.Options.IPv6RemoteDefaultGateway = SplitTunneling;
                    switch (AuthenticationMethod.ToLower())
                    {
                    case "pap":
                        entry.Options.RequirePap                 = true;
                        entry.Options.RequireEap                 = false;
                        entry.Options.RequireChap                = false;
                        entry.Options.RequireMSChap2             = false;
                        entry.Options.RequireEncryptedPassword   = false;
                        entry.Options.RequireDataEncryption      = false;
                        entry.Options.RequireMSEncryptedPassword = false;
                        break;

                    case "eap":
                        entry.Options.RequireEap                 = true;
                        entry.Options.RequireChap                = false;
                        entry.Options.RequirePap                 = false;
                        entry.Options.RequireMSChap2             = false;
                        entry.Options.RequireEncryptedPassword   = false;
                        entry.Options.RequireDataEncryption      = false;
                        entry.Options.RequireMSEncryptedPassword = false;
                        break;

                    case "chap":
                        entry.Options.RequireChap                = true;
                        entry.Options.RequirePap                 = false;
                        entry.Options.RequireEap                 = false;
                        entry.Options.RequireMSChap2             = false;
                        entry.Options.RequireEncryptedPassword   = false;
                        entry.Options.RequireDataEncryption      = false;
                        entry.Options.RequireMSEncryptedPassword = false;
                        break;

                    case "mschapv2":
                        entry.Options.RequireMSChap2             = true;
                        entry.Options.RequirePap                 = false;
                        entry.Options.RequireEap                 = false;
                        entry.Options.RequireChap                = false;
                        entry.Options.RequireEncryptedPassword   = false;
                        entry.Options.RequireDataEncryption      = false;
                        entry.Options.RequireMSEncryptedPassword = false;
                        break;

                    default:
                        entry.Options.RequirePap                 = true;
                        entry.Options.RequireEap                 = false;
                        entry.Options.RequireChap                = false;
                        entry.Options.RequireMSChap2             = false;
                        entry.Options.RequireEncryptedPassword   = false;
                        entry.Options.RequireDataEncryption      = false;
                        entry.Options.RequireMSEncryptedPassword = false;
                        break;
                    }
                    allUsersPhoneBook.Entries.Add(entry);
                }
                if (VpnStrategy == RasVpnStrategy.L2tpOnly)
                {
                    allUsersPhoneBook.Entries[updateVPNname].Options.UsePreSharedKey = true;
                    allUsersPhoneBook.Entries[updateVPNname].UpdateCredentials(RasPreSharedKey.Client, L2tpPsk);
                }
                // 不管当前VPN是否连接,服务器地址的更新总能成功,如果正在连接,则需要VPN重启后才能起作用
                allUsersPhoneBook.Entries[updateVPNname].Update();
                allUsersPhoneBook.Dispose();
            }
            catch (Exception ex)
            {
                //LogUtil.Write("CreateOrUpdateVPN Error:" + ex);
            }
        }