/// <summary> /// This method will grab the list of zones from cloudflare. It will then check to make sure that the zone has some corresponding hostnames in umbraco. /// If it does, we will save the domain names & the zones. /// </summary> /// <returns>A key value pair where the Key is the zones, and the value is the domains</returns> private KeyValuePair <IEnumerable <Zone>, IEnumerable <string> > GetAllowedZonesAndDomains() { List <Zone> allowedZones = new List <Zone>(); List <string> allowedDomains = new List <string>(); //Get the list of domains from cloudflare. IEnumerable <Zone> allZones = _cloudflareManager.ListZones(); IEnumerable <string> domainsInUmbraco = ApplicationContext.Current.Services.DomainService.GetAll(false).Select(x => new UriBuilder(x.DomainName).Uri.DnsSafeHost); foreach (Zone zone in allZones) { foreach (string domain in domainsInUmbraco) { if (domain.Contains(zone.Name)) //if the domain url contains the zone url, then we know its the domain or a sub domain. { if (!allowedZones.Contains(zone)) { //The allowed zones doesn't contain this zone yet, add it. allowedZones.Add(zone); } if (!allowedDomains.Contains(domain)) { //The allowed domains doens't contain this domain yet, add it. allowedDomains.Add(domain); } } } } return(new KeyValuePair <IEnumerable <Zone>, IEnumerable <string> >(allowedZones, allowedDomains)); }