protected void Page_Load(object sender, EventArgs e)
        {
            _currentId = Request.GetItemAs<int>("id");
            prop_domain.Text = ui.Text("assignDomain", "domain", UmbracoUser);
            prop_lang.Text = ui.Text("general", "language", UmbracoUser);
            pane_addnew.Text = ui.Text("assignDomain", "addNew", UmbracoUser);
            pane_edit.Text = ui.Text("assignDomain", "orEdit", UmbracoUser);

            if (Request.GetItemAsString("editDomain").Trim() != "")
            {
                _editDomain = Request.GetItemAs<int>("editDomain");
            }

            if (Request.GetItemAsString("delDomain").Trim() != "")
            {
                var d = new Domain(Request.GetItemAs<int>("delDomain"));
                FeedBackMessage.type = uicontrols.Feedback.feedbacktype.success;
                FeedBackMessage.Text = ui.Text("assignDomain", "domainDeleted", d.Name, UmbracoUser);
                d.Delete();
                UpdateDomainList();
            }

            if (!IsPostBack)
            {
                // Add caption to button
                ok.Text = ui.Text("assignDomain", "addNew", UmbracoUser);

                var selectedLanguage = -1;

                // Maybe add editing info - not the best way this is made ;-)
                if (_editDomain > 0)
                {
                    var d = new Domain(_editDomain);
                    selectedLanguage = d.Language.id;
                    DomainName.Text = d.Name.StartsWith("*") ? "*" : d.Name;
                    ok.Text = ui.Text("general", "update", UmbracoUser);
                }

                // Add caption to language validator
                LanguageValidator.ErrorMessage = ui.Text("defaultdialogs", "requiredField", UmbracoUser) + "<br/>";
                DomainValidator.ErrorMessage = ui.Text("defaultdialogs", "requiredField", UmbracoUser);

                DomainValidator2.ErrorMessage = ui.Text("assignDomain", "invalidDomain", UmbracoUser);
                //DomainValidator2.ValidationExpression = @"^(?i:http[s]?://)?([-\w]+(\.[-\w]+)*)(:\d+)?(/[-\w]*)?$";
                DomainValidator2.ValidationExpression = @"^(\*|((?i:http[s]?://)?([-\w]+(\.[-\w]+)*)(:\d+)?(/[-\w]*)?))$";

                Languages.Items.Add(new ListItem(ui.Text("general", "choose", UmbracoUser), ""));
                foreach (var l in Language.GetAllAsList())
                {
                    var li = new ListItem();
                    li.Text = l.FriendlyName;
                    li.Value = l.id.ToString(CultureInfo.InvariantCulture);
                    if (selectedLanguage == l.id)
                        li.Selected = true;
                    Languages.Items.Add(li);
                }
            }

            UpdateDomainList();
        }
Beispiel #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            currentID = int.Parse(helper.Request("id"));
            prop_domain.Text = umbraco.ui.Text("assignDomain", "domain", this.getUser());
            prop_lang.Text = umbraco.ui.Text("general", "language", this.getUser());
            pane_addnew.Text = umbraco.ui.Text("assignDomain", "addNew", this.getUser());
            pane_edit.Text = umbraco.ui.Text("assignDomain", "orEdit", this.getUser());
            
            // Put user code to initialize the page here
            if (helper.Request("editDomain").Trim() != "")
            {
                editDomain = int.Parse(helper.Request("editDomain"));
            }

            if (helper.Request("delDomain").Trim() != "")
            {
                Domain d = new Domain(int.Parse(helper.Request("delDomain")));
                FeedBackMessage.type = umbraco.uicontrols.Feedback.feedbacktype.success;
                FeedBackMessage.Text = ui.Text("assignDomain", "domainDeleted", d.Name, base.getUser());
                d.Delete();
                updateDomainList();
            }

            if (!IsPostBack)
            {
                // Add caption to button
                ok.Text = ui.Text("assignDomain", "addNew", base.getUser());
              

                int selectedLanguage = -1;

                // Maybe add editing info - not the best way this is made ;-)
                if (editDomain > 0)
                {
                    Domain d = new Domain(editDomain);
                    selectedLanguage = d.Language.id;
                    DomainName.Text = d.Name;
                    ok.Text = ui.Text("general", "update", base.getUser());
                }

                // Add caption to language validator
                LanguageValidator.ErrorMessage = ui.Text("defaultdialogs", "requiredField", base.getUser()) + "<br/>";
                DomainValidator.ErrorMessage = ui.Text("defaultdialogs", "requiredField", base.getUser());

                Languages.Items.Add(new ListItem(ui.Text("general", "choose", base.getUser()), ""));
                foreach (Language l in Language.getAll)
                {
                    ListItem li = new ListItem();
                    li.Text = l.FriendlyName;
                    li.Value = l.id.ToString();
                    if (selectedLanguage == l.id)
                        li.Selected = true;
                    Languages.Items.Add(li);
                }
            }

            updateDomainList();
        }
Beispiel #3
0
        // todo: this functionality might be a double of the Store url functionality
        public string GenerateDomainUrlForContent(int id = 0)
        {
            try
            {
                if (id == 0)
                {
                    id = Node.GetCurrent().Id;
                }
            }
            catch (Exception)
            {
                // intentional empty catch
            }

            string baseUrl = string.Empty;

            string http = "http://";

            if (HttpContext.Current.Request.IsSecureConnection)
            {
                http = "https://";
            }

            if (false)             //id != 0)
            {
                if (library.GetCurrentDomains(id) != null && library.GetCurrentDomains(id).Any())
                {
                    umbraco.cms.businesslogic.web.Domain firstOrDefaultDomain = library.GetCurrentDomains(id).FirstOrDefault();

                    if (firstOrDefaultDomain != null && string.IsNullOrEmpty(firstOrDefaultDomain.Name))
                    {
                        baseUrl = string.Format("{0}{1}", http, firstOrDefaultDomain.Name);

                        baseUrl = baseUrl.Substring(0, baseUrl.LastIndexOf("/", StringComparison.Ordinal));
                    }
                }
            }
            else
            {
                string currentDomain = HttpContext.Current.Request.Url.Authority;
                baseUrl = string.Format("{0}{1}", http, currentDomain);
            }

            if (baseUrl == string.Empty || baseUrl == "http:/" || baseUrl == "https:/" || baseUrl == "http://" || baseUrl == "https://")
            {
                baseUrl = string.Format("{0}{1}", http, HttpContext.Current.Request.Url.Authority);
            }

            Log.Instance.LogDebug("baseUrl to return" + baseUrl);

            return(baseUrl);
        }
Beispiel #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DomainAndUri"/> class with a Domain and a uri scheme.
 /// </summary>
 /// <param name="domain">The domain.</param>
 /// <param name="scheme">The uri scheme.</param>
 public DomainAndUri(Domain domain, string scheme)
 {
     Domain = domain;
     try
     {
         Uri = new Uri(UriUtility.TrimPathEndSlash(UriUtility.StartWithScheme(domain.Name, scheme)));
     }
     catch (UriFormatException)
     {
         var name = domain.Name.ToCSharpString();
         throw new ArgumentException(string.Format("Failed to parse invalid domain: node id={0}, hostname=\"{1}\"."
             + " Hostname should be a valid uri.", domain.RootNodeId, name), "domain");
     }
 }
Beispiel #5
0
		private static Domain SanitizeForBackwardCompatibility(Domain d)
		{
			// this is a _really_ nasty one that should be removed in 6.x
			// some people were using hostnames such as "/en" which happened to work pre-4.10
			// but make _no_ sense at all... and 4.10 throws on them, so here we just try
			// to find a way so 4.11 does not throw.
			// but, really.
			// no.
			var context = System.Web.HttpContext.Current;
			if (context != null && d.Name.StartsWith("/"))
			{
				// turn /en into http://whatever.com/en so it becomes a parseable uri
				var authority = context.Request.Url.GetLeftPart(UriPartial.Authority);
				d.Name = authority + d.Name;
			}
			return d;
		}
Beispiel #6
0
		private static bool IsWildcardDomain(Domain d)
		{
			// supporting null or whitespace for backward compatibility, 
			// although we should not allow ppl to create them anymore
			return string.IsNullOrWhiteSpace(d.Name) || d.Name.StartsWith("*");
		}
 /// <summary>
 /// Gets the domains that match a specified uri, into a group of domains.
 /// </summary>
 /// <param name="domains">The group of domains.</param>
 /// <param name="current">The uri, or null.</param>
 /// <returns>The domains and their normalized uris, that match the specified uri.</returns>
 internal static IEnumerable<DomainAndUri> DomainsForUri(Domain[] domains, Uri current)
 {
     var scheme = current == null ? Uri.UriSchemeHttp : current.Scheme;
     return domains
         .Where(d => !d.IsWildcard)
         .Select(SanitizeForBackwardCompatibility)
         .Select(d => new DomainAndUri(d, scheme))
         .OrderByDescending(d => d.Uri.ToString());
 }
Beispiel #8
0
		/// <summary>
		/// Gets a value indicating whether there is another domain defined down in the path to a node under the current domain's root node.
		/// </summary>
		/// <param name="current">The current domain.</param>
		/// <param name="path">The path to a node under the current domain's root node.</param>
		/// <returns>A value indicating if there is another domain defined down in the path.</returns>
		public static bool ExistsDomainInPath(Domain current, string path)
		{
			var domains = Domain.GetDomains();
			var stopNodeId = current == null ? -1 : current.RootNodeId;

			return path.Split(',')
				.Reverse()
				.Select(id => int.Parse(id))
				.TakeWhile(id => id != stopNodeId)
				.Any(id => domains.Any(d => d.RootNodeId == id && !IsWildcardDomain(d)));
		}
 static void DomainNew(Domain sender, NewEventArgs e)
 {
     DistributedCache.Instance.RefreshDomainCache(sender);
 }
 static void DomainAfterSave(Domain sender, SaveEventArgs e)
 {
     DistributedCache.Instance.RefreshDomainCache(sender);
 } 
 void Domain_AfterDelete(Domain sender, umbraco.cms.businesslogic.DeleteEventArgs e)
 {
     UmbracoHelper.ClearDomains();
 }
 public static void RemoveDomainCache(this DistributedCache dc, Domain domain)
 {
     if (domain != null)
     {
         dc.Remove(new Guid(DistributedCache.DomainCacheRefresherId), domain.Id);
     }
 }
 void Domain_New(Domain sender, NewEventArgs e)
 {
     UmbracoHelper.ClearDomains();
 }
Beispiel #14
0
 /// <summary>
 /// Sanitize a Domain.
 /// </summary>
 /// <param name="domain">The Domain to sanitize.</param>
 /// <returns>The sanitized domain.</returns>
 /// <remarks>This is a _really_ nasty one that should be removed at some point. Some people were
 /// using hostnames such as "/en" which happened to work pre-4.10 but really make no sense at
 /// all... and 4.10 throws on them, so here we just try to find a way so 4.11 does not throw.
 /// But really... no.</remarks>
 private static Domain SanitizeForBackwardCompatibility(Domain domain)
 {
     var context = System.Web.HttpContext.Current;
     if (context != null && domain.Name.StartsWith("/"))
     {
         // turn "/en" into "http://whatever.com/en" so it becomes a parseable uri
         var authority = context.Request.Url.GetLeftPart(UriPartial.Authority);
         domain.Name = authority + domain.Name;
     }
     return domain;
 }
Beispiel #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DomainAndUri"/> class with a Domain and a uri scheme.
 /// </summary>
 /// <param name="domain">The domain.</param>
 /// <param name="scheme">The uri scheme.</param>
 public DomainAndUri(Domain domain, string scheme)
 {
     Domain = domain;
     Uri = new Uri(UriUtility.TrimPathEndSlash(UriUtility.StartWithScheme(domain.Name, scheme)));
 }
Beispiel #16
0
 /// <summary>
 /// Gets a value indicating whether there is another domain defined down in the path to a node under the current domain's root node.
 /// </summary>
 /// <param name="domains">The domains.</param>
 /// <param name="path">The path to a node under the current domain's root node eg '-1,1234,5678'.</param>
 /// <param name="rootNodeId">The current domain root node identifier, or null.</param>
 /// <returns>A value indicating if there is another domain defined down in the path.</returns>
 /// <remarks>Looks _under_ rootNodeId but not _at_ rootNodeId.</remarks>
 internal static bool ExistsDomainInPath(Domain[] domains, string path, int? rootNodeId)
 {
     return FindDomainInPath(domains, path, rootNodeId) != null;
 }
Beispiel #17
0
        /// <summary>
        /// Gets the deepest wildcard Domain, if any, from a group of Domains, in a node path.
        /// </summary>
        /// <param name="domains">The domains.</param>
        /// <param name="path">The node path eg '-1,1234,5678'.</param>
        /// <param name="rootNodeId">The current domain root node identifier, or null.</param>
        /// <returns>The deepest wildcard Domain in the path, or null.</returns>
        /// <remarks>Looks _under_ rootNodeId but not _at_ rootNodeId.</remarks>
        internal static Domain FindWildcardDomainInPath(Domain[] domains, string path, int? rootNodeId)
        {
            var stopNodeId = rootNodeId ?? -1;

            return path.Split(',')
                       .Reverse()
                       .Select(int.Parse)
                       .TakeWhile(id => id != stopNodeId)
                       .Select(id => domains.FirstOrDefault(d => d.RootNodeId == id && d.IsWildcard))
                       .FirstOrDefault(domain => domain != null);
        }
 void Domain_AfterSave(Domain sender, SaveEventArgs e)
 {
     UmbracoHelper.ClearDomains();
 }
 void Domain_AfterDelete( Domain sender, DeleteEventArgs e )
 {
     Compatibility.Domain.InvalidateCache();
 }
Beispiel #20
0
		/// <summary>
		/// Gets a value indicating whether there is another domain defined down in the path to a node under the current domain's root node.
		/// </summary>
		/// <param name="current">The current domain.</param>
		/// <param name="path">The path to a node under the current domain's root node.</param>
		/// <returns>A value indicating if there is another domain defined down in the path.</returns>
		public static bool ExistsDomainInPath(Domain current, string path)
		{
			var domains = Domain.GetDomains();

			return path.Split(',')
				.Reverse()
				.Select(id => int.Parse(id))
				.TakeWhile(id => id != current.RootNodeId)
				.Any(id => domains.Any(d => d.RootNodeId == id));
		}
 void Domain_AfterSave( Domain sender, SaveEventArgs e )
 {
     Compatibility.Domain.InvalidateCache();
 }
        protected void SaveDomain(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                if (_editDomain > 0)
                {
                    var d = new Domain(_editDomain);
                    d.Language = new Language(int.Parse(Languages.SelectedValue));
                    d.Name = DomainName.Text.ToLower();
                    FeedBackMessage.type = uicontrols.Feedback.feedbacktype.success;
                    FeedBackMessage.Text = ui.Text("assignDomain", "domainUpdated", DomainName.Text, getUser());
                    d.Save();

                    DomainName.Text = "";
                    Languages.SelectedIndex = 0;
                    UpdateDomainList();

                    //this is probably the worst webform I've ever seen... 
                    Response.Redirect("AssignDomain.aspx?id=" + _currentId.ToString());
                }
                else
                {
					// have to handle wildcard
                    var domainName = DomainName.Text.Trim();
					domainName = domainName == "*" ? ("*" + _currentId.ToString()) : domainName;

                    if (!Domain.Exists(domainName.ToLower()))
                    {
                        Domain.MakeNew(domainName, _currentId, int.Parse(Languages.SelectedValue));
                        FeedBackMessage.Text = ui.Text("assignDomain", "domainCreated", domainName, getUser());
                        FeedBackMessage.type = uicontrols.Feedback.feedbacktype.success;

                        DomainName.Text = "";
                        Languages.SelectedIndex = 0;
                        UpdateDomainList();

                        //this is probably the worst webform I've ever seen... 
                        Response.Redirect("AssignDomain.aspx?id=" + _currentId.ToString());
                    }
                    else
                    {
                        FeedBackMessage.Text = ui.Text("assignDomain", "domainExists", DomainName.Text.Trim(), getUser());
                        FeedBackMessage.type = uicontrols.Feedback.feedbacktype.error;
                    }
                }   
            }
        }
 void Domain_New( Domain sender, NewEventArgs e )
 {
     Compatibility.Domain.InvalidateCache();
 }
 static void DomainAfterDelete(Domain sender, DeleteEventArgs e)
 {
     DistributedCache.Instance.RemoveDomainCache(sender);
 }
 void Domain_AfterDelete(Domain sender, DeleteEventArgs e)
 {
     UmbracoHelper.ClearDomains();
 }
        protected void SaveDomain(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                if (editDomain > 0)
                {
                    Domain d = new Domain(editDomain);
                    d.Language = new Language(int.Parse(Languages.SelectedValue));
                    d.Name = DomainName.Text.ToLower();
                    FeedBackMessage.type = umbraco.uicontrols.Feedback.feedbacktype.success;
                    FeedBackMessage.Text = ui.Text("assignDomain", "domainUpdated", DomainName.Text, base.getUser());
                    d.Save();

                    DomainName.Text = "";
                    Languages.SelectedIndex = 0;
                    updateDomainList();

                    //this is probably the worst webform I've ever seen...
                    Response.Redirect("AssignDomain.aspx?id=" + currentID.ToString());
                }
                else
                {

                    if( !Domain.Exists(DomainName.Text.ToLower())) {
                        Domain.MakeNew(DomainName.Text, currentID, int.Parse(Languages.SelectedValue));
                        FeedBackMessage.Text = ui.Text("assignDomain", "domainCreated", DomainName.Text, base.getUser());
                        FeedBackMessage.type = umbraco.uicontrols.Feedback.feedbacktype.success;

                        DomainName.Text = "";
                        Languages.SelectedIndex = 0;
                        updateDomainList();

                        //this is probably the worst webform I've ever seen...
                        Response.Redirect("AssignDomain.aspx?id=" + currentID.ToString());
                    } else {
                        FeedBackMessage.Text = ui.Text("assignDomain", "domainExists", DomainName.Text, base.getUser());
                        FeedBackMessage.type = umbraco.uicontrols.Feedback.feedbacktype.error;
                    }
                }

            }
        }
Beispiel #27
0
        /// <summary>
        /// Finds the domain that best matches a specified uri, into a group of domains.
        /// </summary>
        /// <param name="domains">The group of domains.</param>
        /// <param name="current">The uri, or null.</param>
        /// <param name="filter">A function to filter the list of domains, if more than one applies, or <c>null</c>.</param>
        /// <returns>The domain and its normalized uri, that best matches the specified uri.</returns>
        /// <remarks>
        /// <para>If more than one domain matches, then the <paramref name="filter"/> function is used to pick
        /// the right one, unless it is <c>null</c>, in which case the method returns <c>null</c>.</para>
        /// <para>The filter, if any, will be called only with a non-empty argument, and _must_ return something.</para>
        /// </remarks>
        internal static DomainAndUri DomainForUri(Domain[] domains, Uri current, Func<DomainAndUri[], DomainAndUri> filter = null)
        {
            // sanitize the list to have proper uris for comparison (scheme, path end with /)
            // we need to end with / because example.com/foo cannot match example.com/foobar
            // we need to order so example.com/foo matches before example.com/
            var scheme = current == null ? Uri.UriSchemeHttp : current.Scheme;
            var domainsAndUris = domains
                .Where(d => !d.IsWildcard)
                .Select(SanitizeForBackwardCompatibility)
                .Select(d => new DomainAndUri(d, scheme))
                .OrderByDescending(d => d.Uri.ToString())
                .ToArray();

            if (!domainsAndUris.Any())
                return null;

            DomainAndUri domainAndUri;
            if (current == null)
            {
                // take the first one by default (what else can we do?)
                domainAndUri = domainsAndUris.First(); // .First() protected by .Any() above
            }
            else
            {
                // look for the first domain that would be the base of the hint
                var hintWithSlash = current.EndPathWithSlash();
                domainAndUri = domainsAndUris
                    .FirstOrDefault(d => d.Uri.EndPathWithSlash().IsBaseOf(hintWithSlash));
                // if none matches, then try to run the filter to pick a domain
                if (domainAndUri == null && filter != null)
                {
                    domainAndUri = filter(domainsAndUris);
                    // if still nothing, pick the first one?
                    // no: move that constraint to the filter, but check
                    if (domainAndUri == null)
                        throw new InvalidOperationException("The filter returned null.");
                }
            }

            return domainAndUri;
        }