コード例 #1
0
        /// <summary>
        /// Reset alls settings instead of VpnProtocolType and Username
        /// </summary>
        public void Reset()
        {
            UnfreezeSettings(isRestoreFreezedState: false);

            VpnType vpnType  = VpnProtocolType;
            string  userName = Username;
            bool    isFirstIntroductionDone   = IsFirstIntroductionDone;
            bool    macIsShowIconInSystemDock = MacIsShowIconInSystemDock;
            bool    isLoggingOn = IsLoggingEnabled;

            // Reset values to defaults
            try
            {
                __IsLoading = true;
                __SettingsProvider.Reset(this);
            }
            finally
            {
                __IsLoading = false;
            }

            // Some values should not be changed after reset:
            VpnProtocolType           = vpnType;
            Username                  = userName;
            IsFirstIntroductionDone   = isFirstIntroductionDone;
            MacIsShowIconInSystemDock = macIsShowIconInSystemDock;
            IsLoggingEnabled          = isLoggingOn;

            Save();

            OnCredentialsChanged(this);
        }
コード例 #2
0
        public void RemoveFastestServer(string serverId, VpnType vpnType, IEnumerable <string> allServers)
        {
            if (string.IsNullOrEmpty(serverId))
            {
                return;
            }

            // When customer changes a list of servers, it is not allowed to add additional servers / location to the list.Any new server deployed should be unchecked.
            // (this can be implemented by storing the list of servers for which the “fastest connection” is enabled.)
            // Use case example:
            //  Customer removed “Vienna, AT” from the list of fastest servers
            //      We deployed new location in “New Delhi, India”
            //      This new server should be also not included in the “Fastest servers”
            if (__FastestServersInUse.ContainsKey(vpnType) && !__FastestServersInUse[vpnType].Any())
            {
                __FastestServersInUse.Remove(vpnType);
            }
            if (!__FastestServersInUse.ContainsKey(vpnType))
            {
                __FastestServersInUse.Add(vpnType, new HashSet <string>(allServers.Select(x => x.Trim().ToLower())));
            }

            __FastestServersInUse[vpnType].Remove(serverId.Trim().ToLower());

            OnFilterChangedFastestServer(this, new EventArgs());
        }
コード例 #3
0
        public bool IsFastestServerInUse(string serverId, VpnType vpnType)
        {
            if (string.IsNullOrEmpty(serverId))
            {
                return(false);
            }

            // if configuration not defined - allow all servers
            if (!__FastestServersInUse.ContainsKey(vpnType) ||
                !__FastestServersInUse[vpnType].Any())
            {
                return(true);
            }

            return(__FastestServersInUse[vpnType].Contains(serverId.Trim().ToLower()));
        }
コード例 #4
0
        /// <summary>
        /// Reset alls settings instead of VpnProtocolType and Username
        /// </summary>
        public void Reset()
        {
            UnfreezeSettings(isRestoreFreezedState: false);

            VpnType vpnType = VpnProtocolType;

            bool isFirstIntroductionDone   = IsFirstIntroductionDone;
            bool macIsShowIconInSystemDock = MacIsShowIconInSystemDock;
            bool isLoggingOn = IsLoggingEnabled;

            // Reset values to defaults
            __SettingsProvider.Reset(this);

            // Some values should not be changed after reset:
            VpnProtocolType           = vpnType;
            IsFirstIntroductionDone   = isFirstIntroductionDone;
            MacIsShowIconInSystemDock = macIsShowIconInSystemDock;
            IsLoggingEnabled          = isLoggingOn;

            Save();
        }
        internal static VirtualNetworkGatewayData DeserializeVirtualNetworkGatewayData(JsonElement element)
        {
            Optional <ExtendedLocation> extendedLocation  = default;
            Optional <string>           etag              = default;
            Optional <string>           name              = default;
            Optional <string>           type              = default;
            Optional <string>           location          = default;
            Optional <IDictionary <string, string> > tags = default;
            ResourceIdentifier id = default;
            Optional <IList <VirtualNetworkGatewayIPConfiguration> > ipConfigurations = default;
            Optional <VirtualNetworkGatewayType> gatewayType = default;
            Optional <VpnType> vpnType = default;
            Optional <VpnGatewayGeneration> vpnGatewayGeneration = default;
            Optional <bool>        enableBgp = default;
            Optional <bool>        enablePrivateIpAddress = default;
            Optional <bool>        activeActive           = default;
            Optional <SubResource> gatewayDefaultSite     = default;
            Optional <VirtualNetworkGatewaySku> sku       = default;
            Optional <VpnClientConfiguration>   vpnClientConfiguration = default;
            Optional <BgpSettings>       bgpSettings         = default;
            Optional <AddressSpace>      customRoutes        = default;
            Optional <string>            resourceGuid        = default;
            Optional <ProvisioningState> provisioningState   = default;
            Optional <bool>   enableDnsForwarding            = default;
            Optional <string> inboundDnsForwardingEndpoint   = default;
            Optional <string> vNetExtendedLocationResourceId = default;
            Optional <IList <VirtualNetworkGatewayNatRuleData> > natRules = default;
            Optional <bool> enableBgpRouteTranslationForNat = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("extendedLocation"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    extendedLocation = ExtendedLocation.DeserializeExtendedLocation(property.Value);
                    continue;
                }
                if (property.NameEquals("etag"))
                {
                    etag = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("type"))
                {
                    type = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("location"))
                {
                    location = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("tags"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    Dictionary <string, string> dictionary = new Dictionary <string, string>();
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        dictionary.Add(property0.Name, property0.Value.GetString());
                    }
                    tags = dictionary;
                    continue;
                }
                if (property.NameEquals("id"))
                {
                    id = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("properties"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        if (property0.NameEquals("ipConfigurations"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List <VirtualNetworkGatewayIPConfiguration> array = new List <VirtualNetworkGatewayIPConfiguration>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(VirtualNetworkGatewayIPConfiguration.DeserializeVirtualNetworkGatewayIPConfiguration(item));
                            }
                            ipConfigurations = array;
                            continue;
                        }
                        if (property0.NameEquals("gatewayType"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            gatewayType = new VirtualNetworkGatewayType(property0.Value.GetString());
                            continue;
                        }
                        if (property0.NameEquals("vpnType"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            vpnType = new VpnType(property0.Value.GetString());
                            continue;
                        }
                        if (property0.NameEquals("vpnGatewayGeneration"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            vpnGatewayGeneration = new VpnGatewayGeneration(property0.Value.GetString());
                            continue;
                        }
                        if (property0.NameEquals("enableBgp"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            enableBgp = property0.Value.GetBoolean();
                            continue;
                        }
                        if (property0.NameEquals("enablePrivateIpAddress"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            enablePrivateIpAddress = property0.Value.GetBoolean();
                            continue;
                        }
                        if (property0.NameEquals("activeActive"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            activeActive = property0.Value.GetBoolean();
                            continue;
                        }
                        if (property0.NameEquals("gatewayDefaultSite"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            gatewayDefaultSite = SubResource.DeserializeSubResource(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("sku"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            sku = VirtualNetworkGatewaySku.DeserializeVirtualNetworkGatewaySku(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("vpnClientConfiguration"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            vpnClientConfiguration = VpnClientConfiguration.DeserializeVpnClientConfiguration(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("bgpSettings"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            bgpSettings = BgpSettings.DeserializeBgpSettings(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("customRoutes"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            customRoutes = AddressSpace.DeserializeAddressSpace(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("resourceGuid"))
                        {
                            resourceGuid = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("provisioningState"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            provisioningState = new ProvisioningState(property0.Value.GetString());
                            continue;
                        }
                        if (property0.NameEquals("enableDnsForwarding"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            enableDnsForwarding = property0.Value.GetBoolean();
                            continue;
                        }
                        if (property0.NameEquals("inboundDnsForwardingEndpoint"))
                        {
                            inboundDnsForwardingEndpoint = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("vNetExtendedLocationResourceId"))
                        {
                            vNetExtendedLocationResourceId = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("natRules"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List <VirtualNetworkGatewayNatRuleData> array = new List <VirtualNetworkGatewayNatRuleData>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(VirtualNetworkGatewayNatRuleData.DeserializeVirtualNetworkGatewayNatRuleData(item));
                            }
                            natRules = array;
                            continue;
                        }
                        if (property0.NameEquals("enableBgpRouteTranslationForNat"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            enableBgpRouteTranslationForNat = property0.Value.GetBoolean();
                            continue;
                        }
                    }
                    continue;
                }
            }
            return(new VirtualNetworkGatewayData(id, name.Value, type.Value, location.Value, Optional.ToDictionary(tags), extendedLocation.Value, etag.Value, Optional.ToList(ipConfigurations), Optional.ToNullable(gatewayType), Optional.ToNullable(vpnType), Optional.ToNullable(vpnGatewayGeneration), Optional.ToNullable(enableBgp), Optional.ToNullable(enablePrivateIpAddress), Optional.ToNullable(activeActive), gatewayDefaultSite.Value, sku.Value, vpnClientConfiguration.Value, bgpSettings.Value, customRoutes.Value, resourceGuid.Value, Optional.ToNullable(provisioningState), Optional.ToNullable(enableDnsForwarding), inboundDnsForwardingEndpoint.Value, vNetExtendedLocationResourceId.Value, Optional.ToList(natRules), Optional.ToNullable(enableBgpRouteTranslationForNat)));
        }
コード例 #6
0
        /// <summary>
        /// IPs which must be excluded from connection to server
        /// (serverID -> List of IPs)
        /// </summary>
        //[JsonProperty]
        //private Dictionary<string, HashSet<string>> __ExcludedServerIp = new Dictionary<string, HashSet<string>>();

        /// <summary>
        /// Remove references to unused(removed) servers or IPs from configuration (if necesary)
        /// </summary>
        public bool NormalizeData(IEnumerable <VpnServerInfoBase> allServers, VpnType vpnType)
        {
            if (allServers == null || !allServers.Any())
            {
                return(false);
            }

            if (!__FastestServersInUse.Any()
                //&& !__ExcludedServerIp.Any()
                )
            {
                return(false);
            }

            try
            {
                bool isChanged = false;

                // list of all posible server-IDs
                HashSet <string> allServersId = new HashSet <string>(allServers.Select(s => s.GatewayId.Trim().ToLower()));

                // if fastest servers defined
                if (__FastestServersInUse.ContainsKey(vpnType) &&
                    __FastestServersInUse[vpnType].Any()
                    )
                {
                    List <string> serversToRemove = new List <string>();
                    foreach (string svrId in __FastestServersInUse[vpnType])
                    {
                        if (!allServersId.Contains(svrId))
                        {
                            serversToRemove.Add(svrId);
                        }
                    }

                    isChanged = serversToRemove.Any() || isChanged;
                    foreach (string svr in serversToRemove)
                    {
                        __FastestServersInUse[vpnType].Remove(svr);
                    }
                }

                /*
                 * // if servers to exclude defined
                 * if (__ExcludedServerIp.Any())
                 * {
                 *  // list of all possible server IP-s
                 *  HashSet<string> allIPs = new HashSet<string>(allPossibleServers.SelectMany(s => s.GetHostsIpAddresses().Select(ip => ip.Trim().ToLower())));
                 *
                 *  List<string> serversToRemove = new List<string>();
                 *  foreach (KeyValuePair<string, HashSet<string>> svr in __ExcludedServerIp)
                 *  {
                 *      if (!allServersId.Contains(svr.Key))
                 *          serversToRemove.Add(svr.Key);
                 *      else
                 *      {
                 *          List<string> ipToRemove = new List<string>();
                 *          foreach (string ip in svr.Value)
                 *          {
                 *              if (!allIPs.Contains(ip))
                 *                  ipToRemove.Add(ip);
                 *          }
                 *
                 *          isChanged = ipToRemove.Any() || isChanged;
                 *          foreach (string ip in ipToRemove)
                 *              svr.Value.Remove(ip);
                 *      }
                 *  }
                 *
                 *  isChanged = serversToRemove.Any() || isChanged;
                 *  foreach (string svr in serversToRemove)
                 *      __ExcludedServerIp.Remove(svr);
                 * }*/

                return(isChanged);
            }
            catch (Exception ex)
            {
                __FastestServersInUse.Clear();
                //__ExcludedServerIp.Clear();
                Logging.Info($"EXCEPTION. Failed to normalize ServersFilterConfig: {ex}");
            }
            return(true);
        }
コード例 #7
0
 public void GenerateDiagnosticLogs(VpnType vpnProtocolType)
 {
     SendRequest(new IVPNGenerateDiagnosticsRequest {
         VpnProtocolType = vpnProtocolType
     });
 }