Пример #1
0
        protected override IResponse CreateResponse(UnicornControlPanelRequestPipelineArgs args)
        {
            const string SyncInProgress = "Sync in progress";

            if (Status == SyncStatus.NotStarted)
            {
                var configurations = ResolveConfigurations();
                System.Threading.Tasks.Task.Run(() => ProcessAsync(Progress, Logger, configurations))
                .ContinueWith(t =>
                {
                    if (t.Exception != null)
                    {
                        Status = SyncStatus.Finished;
                        Progress.ReportException(t.Exception);
                    }
                });
                return(new PlainTextResponse(SyncInProgress));
            }

            if (Status == SyncStatus.Started)
            {
                return(new PlainTextResponse(SyncInProgress));
            }

            string message = Logger.LogData.ToString();

            //resetting sync data
            Reset();
            // in any case, need to send 200 OK here and parse response then in script
            return(new PlainTextResponse(message));
        }
		public virtual void ProcessRequest(HttpContext context)
		{
			context.Server.ScriptTimeout = 86400;

			var verb = context.Request.QueryString["verb"];

			var authProvider = UnicornConfigurationManager.AuthenticationProvider;
			SecurityState securityState;
			if (authProvider != null)
			{
				securityState = UnicornConfigurationManager.AuthenticationProvider.ValidateRequest(new HttpRequestWrapper(HttpContext.Current.Request));
			}
			else securityState = new SecurityState(false, false);

			// this securitydisabler allows the control panel to execute unfettered when debug compilation is enabled but you are not signed into Sitecore
			using (new SecurityDisabler())
			{
				var pipelineArgs = new UnicornControlPanelRequestPipelineArgs(verb, new HttpContextWrapper(context), securityState);

				CorePipeline.Run("unicornControlPanelRequest", pipelineArgs, true);

				if (pipelineArgs.Response == null)
				{
					pipelineArgs.Response = new PlainTextResponse("Not Found", HttpStatusCode.NotFound);
				}

				if (securityState.IsAllowed)
				{
					context.Response.AddHeader("X-Unicorn-Version", UnicornVersion.Current);
				}
				
				pipelineArgs.Response.Execute(new HttpResponseWrapper(context.Response));
			}
		}
Пример #3
0
		protected override IResponse CreateResponse(UnicornControlPanelRequestPipelineArgs args)
		{
			var config = args.Context.Request.QueryString["configuration"];
			var targetConfigurations = ControlPanelUtility.ResolveConfigurationsFromQueryParameter(config);
			var result = targetConfigurations.Select(GetHealthStatus);

			return new PlainTextResponse(string.Join(Environment.NewLine, result));
		}
		/// <summary>
		/// Verbs note: passing an empty string to _verbHandled makes you the default page when no verb is passed
		/// Passing null as _verbHandled makes you the catch-all page for every request not handled by previous pipeline handlers
		/// </summary>
		protected virtual bool HandlesVerb(UnicornControlPanelRequestPipelineArgs args)
		{
			if (_requireAuthentication && !args.SecurityState.IsAllowed) return false;

			if (_verbHandled == null) return true;

			return _verbHandled.Equals(args.Verb ?? string.Empty, StringComparison.OrdinalIgnoreCase);
		}
Пример #5
0
        protected virtual IEnumerable<IControlPanelControl> CreateBodyControls(UnicornControlPanelRequestPipelineArgs args)
        {
            var configurations = GetConfigurations(args);

            var hasSerializedItems = configurations.All(ControlPanelUtility.HasAnySerializedItems);
            var hasAllRootParentPaths = configurations.All(ControlPanelUtility.AllRootParentPathsExist);
            var allowMultiSelect = hasSerializedItems && hasAllRootParentPaths && configurations.Length > 1;
            // note that we don't just check dependencies property here to catch implicit dependencies
            var anyConfigurationsWithDependencies = configurations.Any(config => config.Resolve<ConfigurationDependencyResolver>().Dependents.Any());

            var isAuthorized = args.SecurityState.IsAllowed;

            if (!hasSerializedItems)
            {
                yield return new GlobalWarnings(hasAllRootParentPaths, anyConfigurationsWithDependencies);
            }

            if (isAuthorized)
            {
                if (configurations.Length == 0)
                {
                    yield return new NoConfigurations();
                    yield break;
                }

                if (allowMultiSelect)
                {
                    yield return new BatchProcessingControls();
                }

                yield return new Literal(@"
                        <article>
                            <h2{0} Configurations</h2>".FormatWith(allowMultiSelect ? @" class=""fakebox fakebox-all""><span></span>" : ">"));

                if (allowMultiSelect) yield return new Literal(@"
                            <p class=""help"">Check 'Configurations' above to select all configurations, or individually select as many as you like below.</p>");

                yield return new Literal(@"
                            <table>
                                <tbody>");

                foreach (var configuration in configurations)
                {
                    yield return new ConfigurationInfo(configuration) { MultipleConfigurationsExist = allowMultiSelect };
                }

                yield return new Literal(@"
                                </tbody>
                            </table>
                        </article>");

                yield return new QuickReference();
            }
            else
            {
                yield return new AccessDenied();
            }
        }
Пример #6
0
        protected override IResponse CreateResponse(UnicornControlPanelRequestPipelineArgs args)
        {
            if (args.SecurityState.IsAutomatedTool)
            {
                return(new PlainTextResponse("Automated tool authentication failed.", HttpStatusCode.Unauthorized));
            }

            return(new ControlPanelPageResponse(args.SecurityState, new AccessDenied()));
        }
Пример #7
0
		protected override IResponse CreateResponse(UnicornControlPanelRequestPipelineArgs args)
		{
			if (args.SecurityState.IsAutomatedTool)
			{
				return new PlainTextResponse("Automated tool authentication failed.", HttpStatusCode.Unauthorized);
			}

			return new ControlPanelPageResponse(args.SecurityState, new AccessDenied());
		}
		public virtual void Process(UnicornControlPanelRequestPipelineArgs args)
		{
			bool handled = HandlesVerb(args);

			if (!handled) return;

			args.Response = CreateResponse(args);

			if(_abortPipelineIfHandled) args.AbortPipeline();
		}
        /// <summary>
        /// Verbs note: passing an empty string to _verbHandled makes you the default page when no verb is passed
        /// Passing null as _verbHandled makes you the catch-all page for every request not handled by previous pipeline handlers
        /// </summary>
        protected virtual bool HandlesVerb(UnicornControlPanelRequestPipelineArgs args)
        {
            if (_requireAuthentication && !args.SecurityState.IsAllowed)
            {
                return(false);
            }

            if (_verbHandled == null)
            {
                return(true);
            }

            return(_verbHandled.Equals(args.Verb ?? string.Empty, StringComparison.OrdinalIgnoreCase));
        }
        public virtual void Process(UnicornControlPanelRequestPipelineArgs args)
        {
            bool handled = HandlesVerb(args);

            if (!handled)
            {
                return;
            }

            args.Response = CreateResponse(args);

            if (_abortPipelineIfHandled)
            {
                args.AbortPipeline();
            }
        }
        public virtual void Process(UnicornControlPanelRequestPipelineArgs args)
        {
            bool handled = HandlesVerb(args);

            if (!handled)
            {
                if (_verbHandled.Equals(args.Verb ?? string.Empty, StringComparison.OrdinalIgnoreCase) && !args.SecurityState.IsAllowed && args.SecurityState.IsAutomatedTool)
                {
                    args.Response = new PlainTextResponse("Unable to authorize request, ensure that your shared secrets match.", System.Net.HttpStatusCode.Forbidden);
                    args.AbortPipeline();
                }
                return;
            }

            args.Response = CreateResponse(args);

            if (_abortPipelineIfHandled)
            {
                args.AbortPipeline();
            }
        }
Пример #12
0
		protected override IResponse CreateResponse(UnicornControlPanelRequestPipelineArgs args)
		{
			return new StreamingEncodedLogResponse(Process);
		}
Пример #13
0
 protected override IResponse CreateResponse(UnicornControlPanelRequestPipelineArgs args)
 {
     return(new WebConsoleResponse("Reserialize Unicorn", args.SecurityState.IsAutomatedTool, new HeadingService(), progress => Process(progress, new WebConsoleLogger(progress))));
 }
Пример #14
0
		protected override bool HandlesVerb(UnicornControlPanelRequestPipelineArgs args)
		{
			return !args.SecurityState.IsAllowed;
		}
Пример #15
0
		protected virtual IConfiguration[] GetConfigurations(UnicornControlPanelRequestPipelineArgs args)
		{
			return new InterconfigurationDependencyResolver().OrderByDependencies(UnicornConfigurationManager.Configurations);
		}
 protected abstract IResponse CreateResponse(UnicornControlPanelRequestPipelineArgs args);
Пример #17
0
 protected override IResponse CreateResponse(UnicornControlPanelRequestPipelineArgs args)
 {
     return(new PlainTextResponse(UnicornConfigurationManager.AuthenticationProvider.GetChallengeToken()));
 }
Пример #18
0
 protected override bool HandlesVerb(UnicornControlPanelRequestPipelineArgs args)
 {
     return(!args.SecurityState.IsAllowed);
 }
		protected abstract IResponse CreateResponse(UnicornControlPanelRequestPipelineArgs args);
Пример #20
0
		protected override IResponse CreateResponse(UnicornControlPanelRequestPipelineArgs args)
		{
			return new PlainTextResponse(string.Join(",", UnicornConfigurationManager.Configurations.Select(config => config.Name)));
		}
Пример #21
0
		protected override IResponse CreateResponse(UnicornControlPanelRequestPipelineArgs args)
		{
			return new PlainTextResponse(UnicornVersion.Current);
		}
Пример #22
0
		protected override IResponse CreateResponse(UnicornControlPanelRequestPipelineArgs args)
		{
			return new WebConsoleResponse("Reserialize Unicorn", args.SecurityState.IsAutomatedTool, new HeadingService(), progress => Process(progress, new WebConsoleLogger(progress)));
		}
Пример #23
0
		protected override IResponse CreateResponse(UnicornControlPanelRequestPipelineArgs args)
		{
			return new ControlPanelPageResponse(args.SecurityState, CreateBodyControls(args).ToArray());
		}
Пример #24
0
 protected override IResponse CreateResponse(UnicornControlPanelRequestPipelineArgs args)
 {
     return new WebConsoleResponse("Sync Unicorn", args.SecurityState.IsAutomatedTool, new HeadingService(), progress => Process(progress, new WebConsoleLogger(progress, args.Context.Request.QueryString["log"])));
 }
Пример #25
0
 protected override IResponse CreateResponse(UnicornControlPanelRequestPipelineArgs args)
 {
     return(new ControlPanelPageResponse(args.SecurityState, CreateBodyControls(args).ToArray()));
 }
Пример #26
0
        protected virtual IEnumerable <IControlPanelControl> CreateBodyControls(UnicornControlPanelRequestPipelineArgs args)
        {
            var configurations = GetConfigurations(args);

            var hasSerializedItems    = configurations.All(ControlPanelUtility.HasAnySerializedItems);
            var hasAllRootParentPaths = configurations.All(ControlPanelUtility.AllRootParentPathsExist);
            var allowMultiSelect      = hasSerializedItems && hasAllRootParentPaths && configurations.Length > 1;
            var allowReserializeAll   = hasAllRootParentPaths && configurations.Sum(c => ControlPanelUtility.GetInvalidRootPaths(c).Length) == 0;

            // note that we don't just check dependencies property here to catch implicit dependencies
            var anyConfigurationsWithDependencies = configurations.Any(config => config.Resolve <ConfigurationDependencyResolver>().Dependents.Any());

            var isAuthorized = args.SecurityState.IsAllowed;

            if (!hasSerializedItems)
            {
                yield return(new GlobalWarnings(hasAllRootParentPaths, anyConfigurationsWithDependencies));
            }

            if (isAuthorized)
            {
                if (configurations.Length == 0)
                {
                    yield return(new NoConfigurations());

                    yield break;
                }

                if (allowMultiSelect)
                {
                    yield return(new BatchProcessingControls(allowReserializeAll));
                }

                yield return(new Literal(@"
						<article>
							<h2{0} Configurations</h2>"                            .FormatWith(allowMultiSelect ? @" class=""fakebox fakebox-all""><span></span>" : ">")));

                if (allowMultiSelect)
                {
                    yield return(new Literal(@"<p class=""help"">Check 'Configurations' above to select all configurations, or individually select as many as you like below.</p>"));

                    if (!allowReserializeAll)
                    {
                        yield return(new Literal(@"<p class=""help"">'Reserialize All' has been disabled because one or more configurations rely on root paths that do not exist in Sitecore currently.<br />'Reserialize' has also been removed from the configurations involved.</p>"));
                    }
                }
                else
                {
                    yield return(new Literal(@"<p class=""help"">Some configurations prevent the 'sync all' checkbox because they include predicates that rely on (currently) invalid root paths. You likely need to sync one or more base configurations.<p>"));
                }



                yield return(new Literal(@"
							<table>
								<tbody>"                                ));

                foreach (var configuration in configurations)
                {
                    yield return(new ConfigurationInfo(configuration)
                    {
                        MultipleConfigurationsExist = allowMultiSelect
                    });
                }

                yield return(new Literal(@"
								</tbody>
							</table>
						</article>"                        ));

                yield return(new QuickReference());
            }
            else
            {
                yield return(new AccessDenied());
            }
        }
Пример #27
0
        protected virtual IEnumerable <IControlPanelControl> CreateBodyControls(UnicornControlPanelRequestPipelineArgs args)
        {
            var configurations = GetConfigurations(args);

            var hasSerializedItems    = configurations.All(ControlPanelUtility.HasAnySerializedItems);
            var hasAllRootParentPaths = configurations.All(ControlPanelUtility.AllRootParentPathsExist);
            var allowMultiSelect      = hasSerializedItems && hasAllRootParentPaths && configurations.Length > 1;
            // note that we don't just check dependencies property here to catch implicit dependencies
            var anyConfigurationsWithDependencies = configurations.Any(config => config.Resolve <ConfigurationDependencyResolver>().Dependents.Any());

            var isAuthorized = args.SecurityState.IsAllowed;

            if (!hasSerializedItems)
            {
                yield return(new GlobalWarnings(hasAllRootParentPaths, anyConfigurationsWithDependencies));
            }

            if (isAuthorized)
            {
                if (configurations.Length == 0)
                {
                    yield return(new NoConfigurations());

                    yield break;
                }

                if (allowMultiSelect)
                {
                    yield return(new BatchProcessingControls());
                }

                yield return(new Literal(@"
						<article>
							<h2{0} Configurations</h2>"                            .FormatWith(allowMultiSelect ? @" class=""fakebox fakebox-all""><span></span>" : ">")));

                if (allowMultiSelect)
                {
                    yield return(new Literal(@"
							<p class=""help"">Check 'Configurations' above to select all configurations, or individually select as many as you like below.</p>"                            ));
                }



                yield return(new Literal(@"
							<table>
								<tbody>"                                ));

                foreach (var configuration in configurations)
                {
                    yield return(new ConfigurationInfo(configuration)
                    {
                        MultipleConfigurationsExist = allowMultiSelect
                    });
                }

                yield return(new Literal(@"
								</tbody>
							</table>
						</article>"                        ));

                yield return(new QuickReference());
            }
            else
            {
                yield return(new AccessDenied());
            }
        }
Пример #28
0
 protected virtual IConfiguration[] GetConfigurations(UnicornControlPanelRequestPipelineArgs args)
 {
     return(new InterconfigurationDependencyResolver().OrderByDependencies(UnicornConfigurationManager.Configurations));
 }
Пример #29
0
 protected override IResponse CreateResponse(UnicornControlPanelRequestPipelineArgs args)
 {
     return(new WebConsoleResponse("Sync Unicorn", args.SecurityState.IsAutomatedTool, new HeadingService(), progress => Process(progress, new WebConsoleLogger(progress, args.Context.Request.QueryString["log"]))));
 }
Пример #30
0
		protected override IResponse CreateResponse(UnicornControlPanelRequestPipelineArgs args)
		{
			return new PlainTextResponse(UnicornConfigurationManager.AuthenticationProvider.GetChallengeToken());
		}