コード例 #1
0
ファイル: VpnManager.cs プロジェクト: Hunv/beRemote
        public bool ConnectVpn(int vpnId)
        {
            if (_ListVpn.ContainsKey(vpnId))
            {
                //Connection already established
                if (_ListVpn[vpnId].IsConnected)
                {
                    _ListVpn[vpnId].ConnectionCounter++; //One more connection uses this VPN
                    return(true);
                }

                if (_ListVpn[vpnId].Connect() == false)
                {
                    return(false);
                }

                _ListVpn[vpnId].ConnectionCounter++; //One more connection uses this VPN
                return(true);
            }

            VpnBase vpnConnection = GetUserVpnConnection(vpnId);

            //Add VPN-Connection to list
            if (vpnConnection != null)
            {
                _ListVpn.Add(vpnConnection.Id, vpnConnection);
                _ListVpn[vpnId].ConnectionCounter = 1;

                bool establishSuccess = vpnConnection.Connect();

                if (establishSuccess == false)
                {
                    _ListVpn.Remove(vpnConnection.Id);
                }

                return(establishSuccess);
            }

            return(false);
        }
コード例 #2
0
ファイル: VpnManager.cs プロジェクト: Hunv/beRemote
        /// <summary>
        /// Gets all VPNs of a User
        /// </summary>
        /// <returns></returns>
        private List <VpnBase> GetUserVpnConnections()
        {
            var dT             = StorageCore.Core.GetUserVpnConnections();
            var vpnConnections = new List <VpnBase>();

            for (var i = 0; i < dT.Rows.Count; i++)
            {
                switch (Convert.ToInt32(dT.Rows[i]["type"]))
                {
                default:     //Invalid
                    continue;

                case 0:     //Undefined
                    var bVpn = new VpnBase();
                    bVpn.Id   = Convert.ToInt32(dT.Rows[i]["id"]);
                    bVpn.Name = StorageCore.Core.EnfuseString(dT.Rows[i]["name"].ToString());
                    bVpn.Type = VpnType.Undefined;

                    vpnConnections.Add(bVpn);
                    continue;

                case 1:     //Cisco VPN
                    var cVpn = new CiscoVpn();
                    cVpn.ClientPath = StorageCore.Core.EnfuseString(dT.Rows[i]["parameter2"].ToString());
                    cVpn.ConfigName = StorageCore.Core.EnfuseString(dT.Rows[i]["parameter1"].ToString());

                    if (dT.Rows[i]["parameter3"] != null && dT.Rows[i]["parameter3"].ToString().Length > 0)
                    {
                        cVpn.ShowAuthenticationWindow = Convert.ToBoolean(dT.Rows[i]["parameter3"]);
                    }
                    if (dT.Rows[i]["parameter4"] != null && dT.Rows[i]["parameter4"].ToString() != "")
                    {
                        cVpn.CredentialId = Convert.ToInt32(dT.Rows[i]["parameter4"]);
                    }
                    cVpn.Name = StorageCore.Core.EnfuseString(dT.Rows[i]["name"].ToString());
                    cVpn.Id   = Convert.ToInt32(dT.Rows[i]["id"]);
                    cVpn.Type = VpnType.CiscoVpn;

                    vpnConnections.Add(cVpn);
                    break;

                case 2:     //OpenVPN
                    var oVpn = new OpenVpn();
                    oVpn.ConfigPath = StorageCore.Core.EnfuseString(dT.Rows[i]["parameter1"].ToString());
                    oVpn.ConfigName = StorageCore.Core.EnfuseString(dT.Rows[i]["parameter2"].ToString());
                    oVpn.Name       = StorageCore.Core.EnfuseString(dT.Rows[i]["name"].ToString());
                    oVpn.Id         = Convert.ToInt32(dT.Rows[i]["id"]);
                    oVpn.Type       = VpnType.OpenVpn;

                    vpnConnections.Add(oVpn);
                    break;

                case 3:     //Windows
                    var wVpn = new WindowsVPN();
                    wVpn.ConfigName = StorageCore.Core.EnfuseString(dT.Rows[i]["parameter1"].ToString());
                    if (dT.Rows[i]["parameter3"] != null && dT.Rows[i]["parameter3"].ToString().Length > 0)
                    {
                        wVpn.Parameter3 = Convert.ToBoolean(dT.Rows[i]["parameter3"]).ToString();
                    }
                    if (dT.Rows[i]["parameter4"] != null && dT.Rows[i]["parameter4"].ToString() != "")
                    {
                        wVpn.CredentialId = Convert.ToInt32(dT.Rows[i]["parameter4"]);
                    }
                    wVpn.Name = StorageCore.Core.EnfuseString(dT.Rows[i]["name"].ToString());
                    wVpn.Id   = Convert.ToInt32(dT.Rows[i]["id"]);
                    wVpn.Type = VpnType.WindowsVpn;

                    vpnConnections.Add(wVpn);
                    break;

                case 4:     //Shrewsoft VPN
                    var sVpn = new ShrewSoftVPN();
                    sVpn.ConfigPath = StorageCore.Core.EnfuseString(dT.Rows[i]["parameter1"].ToString());
                    sVpn.ConfigName = StorageCore.Core.EnfuseString(dT.Rows[i]["parameter2"].ToString());
                    if (dT.Rows[i]["parameter3"] != null && dT.Rows[i]["parameter3"].ToString().Length > 0)
                    {
                        sVpn.ShowCredentialDialog = Convert.ToBoolean(dT.Rows[i]["parameter3"]);
                    }
                    if (dT.Rows[i]["parameter4"] != null && dT.Rows[i]["parameter4"].ToString() != "")
                    {
                        sVpn.CredentialId = Convert.ToInt32(dT.Rows[i]["parameter4"]);
                    }
                    sVpn.Name = StorageCore.Core.EnfuseString(dT.Rows[i]["name"].ToString());
                    sVpn.Id   = Convert.ToInt32(dT.Rows[i]["id"]);
                    sVpn.Type = VpnType.ShrewSoftVpn;

                    vpnConnections.Add(sVpn);
                    break;
                }
            }

            return(vpnConnections);
        }