/// <summary>
        /// Returns the JavaScript object representing the static server variables javascript object
        /// </summary>
        /// <returns></returns>
        public JavaScriptResult ServerVariables()
        {
            //now we need to build up the variables
            var d = new Dictionary <string, object>();

            d.Add("umbracoPath", Url.Content("~/Umbraco")); //TODO: obviously we should be using the umbraco config
            d.Add("contentEditorApiBaseUrl", Url.GetUmbracoApiService <ContentEditorApiController>("PostSaveContent").TrimEnd("PostSaveContent"));

            return(JavaScript(ServerVariablesParser.Parse(d)));
        }
示例#2
0
        public JavaScriptResult ServerVariables()
        {
            var serverVars = new BackOfficeServerVariables(Url, _runtimeState, _features, GlobalSettings);

            //cache the result if debugging is disabled
            var result = HttpContext.IsDebuggingEnabled
                ? ServerVariablesParser.Parse(serverVars.GetServerVariables())
                : AppCaches.RuntimeCache.GetCacheItem <string>(
                typeof(BackOfficeController) + "ServerVariables",
                () => ServerVariablesParser.Parse(serverVars.GetServerVariables()),
                new TimeSpan(0, 10, 0));

            return(JavaScript(result));
        }
        public JavaScriptResult ServerVariables()
        {
            var serverVars = new BackOfficeServerVariables(Url, ApplicationContext, UmbracoConfig.For.UmbracoSettings());

            //cache the result if debugging is disabled
            var result = HttpContext.IsDebuggingEnabled
                ? ServerVariablesParser.Parse(serverVars.GetServerVariables())
                : ApplicationContext.ApplicationCache.RuntimeCache.GetCacheItem <string>(
                typeof(BackOfficeController) + "ServerVariables",
                () => ServerVariablesParser.Parse(serverVars.GetServerVariables()),
                new TimeSpan(0, 10, 0));

            return(JavaScript(result));
        }
示例#4
0
        public void Parse()
        {
            var d = new Dictionary <string, object>();

            d.Add("test1", "Test 1");
            d.Add("test2", "Test 2");
            d.Add("test3", "Test 3");
            d.Add("test4", "Test 4");
            d.Add("test5", "Test 5");

            var output = ServerVariablesParser.Parse(d);

            Assert.IsTrue(output.Contains(@"Umbraco.Sys.ServerVariables = {
  ""test1"": ""Test 1"",
  ""test2"": ""Test 2"",
  ""test3"": ""Test 3"",
  ""test4"": ""Test 4"",
  ""test5"": ""Test 5""
} ;"));
        }
        public JavaScriptResult ServerVariables()
        {
            Func <string> getResult = () =>
            {
                var defaultVals = new Dictionary <string, object>
                {
                    {
                        "umbracoUrls", new Dictionary <string, object>
                        {
                            //TODO: Add 'umbracoApiControllerBaseUrl' which people can use in JS
                            // to prepend their URL. We could then also use this in our own resources instead of
                            // having each url defined here explicitly - we can do that in v8! for now
                            // for umbraco services we'll stick to explicitly defining the endpoints.

                            { "externalLoginsUrl", Url.Action("ExternalLogin", "BackOffice") },
                            { "externalLinkLoginsUrl", Url.Action("LinkLogin", "BackOffice") },
                            { "legacyTreeJs", Url.Action("LegacyTreeJs", "BackOffice") },
                            { "manifestAssetList", Url.Action("GetManifestAssetList", "BackOffice") },
                            { "gridConfig", Url.Action("GetGridConfig", "BackOffice") },
                            { "serverVarsJs", Url.Action("Application", "BackOffice") },
                            //API URLs
                            {
                                "packagesRestApiBaseUrl", UmbracoConfig.For.UmbracoSettings().PackageRepositories.GetDefault().RestApiUrl
                            },
                            {
                                "redirectUrlManagementApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl <RedirectUrlManagementController>(
                                    controller => controller.GetEnableState())
                            },
                            {
                                "embedApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl <RteEmbedController>(
                                    controller => controller.GetEmbed("", 0, 0))
                            },
                            {
                                "userApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl <UserController>(
                                    controller => controller.PostDisableUser(0))
                            },
                            {
                                "contentApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl <ContentController>(
                                    controller => controller.PostSave(null))
                            },
                            {
                                "mediaApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl <MediaController>(
                                    controller => controller.GetRootMedia())
                            },
                            {
                                "imagesApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl <ImagesController>(
                                    controller => controller.GetBigThumbnail(0))
                            },
                            {
                                "sectionApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl <SectionController>(
                                    controller => controller.GetSections())
                            },
                            {
                                "treeApplicationApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl <ApplicationTreeController>(
                                    controller => controller.GetApplicationTrees(null, null, null, true))
                            },
                            {
                                "contentTypeApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl <ContentTypeController>(
                                    controller => controller.GetAllowedChildren(0))
                            },
                            {
                                "mediaTypeApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl <MediaTypeController>(
                                    controller => controller.GetAllowedChildren(0))
                            },
                            {
                                "macroApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl <MacroController>(
                                    controller => controller.GetMacroParameters(0))
                            },
                            {
                                "authenticationApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl <AuthenticationController>(
                                    controller => controller.PostLogin(null))
                            },
                            {
                                "currentUserApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl <CurrentUserController>(
                                    controller => controller.GetMembershipProviderConfig())
                            },
                            {
                                "legacyApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl <LegacyController>(
                                    controller => controller.DeleteLegacyItem(null, null, null))
                            },
                            {
                                "entityApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl <EntityController>(
                                    controller => controller.GetById(0, UmbracoEntityTypes.Media))
                            },
                            {
                                "dataTypeApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl <DataTypeController>(
                                    controller => controller.GetById(0))
                            },
                            {
                                "dashboardApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl <DashboardController>(
                                    controller => controller.GetDashboard(null))
                            },
                            {
                                "logApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl <LogController>(
                                    controller => controller.GetEntityLog(0))
                            },
                            {
                                "gravatarApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl <GravatarController>(
                                    controller => controller.GetCurrentUserGravatarUrl())
                            },
                            {
                                "memberApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl <MemberController>(
                                    controller => controller.GetByKey(Guid.Empty))
                            },
                            {
                                "packageInstallApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl <PackageInstallController>(
                                    controller => controller.Fetch(string.Empty))
                            },
                            {
                                "relationApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl <RelationController>(
                                    controller => controller.GetById(0))
                            },
                            {
                                "rteApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl <RichTextPreValueController>(
                                    controller => controller.GetConfiguration())
                            },
                            {
                                "stylesheetApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl <StylesheetController>(
                                    controller => controller.GetAll())
                            },
                            {
                                "memberTypeApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl <MemberTypeController>(
                                    controller => controller.GetAllTypes())
                            },
                            {
                                "updateCheckApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl <UpdateCheckController>(
                                    controller => controller.GetCheck())
                            },
                            {
                                "tagApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl <TagsController>(
                                    controller => controller.GetAllTags(null))
                            },
                            {
                                "templateApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl <TemplateController>(
                                    controller => controller.GetById(0))
                            },
                            {
                                "memberTreeBaseUrl", Url.GetUmbracoApiServiceBaseUrl <MemberTreeController>(
                                    controller => controller.GetNodes("-1", null))
                            },
                            {
                                "mediaTreeBaseUrl", Url.GetUmbracoApiServiceBaseUrl <MediaTreeController>(
                                    controller => controller.GetNodes("-1", null))
                            },
                            {
                                "contentTreeBaseUrl", Url.GetUmbracoApiServiceBaseUrl <ContentTreeController>(
                                    controller => controller.GetNodes("-1", null))
                            },
                            {
                                "tagsDataBaseUrl", Url.GetUmbracoApiServiceBaseUrl <TagsDataController>(
                                    controller => controller.GetTags(""))
                            },
                            {
                                "examineMgmtBaseUrl", Url.GetUmbracoApiServiceBaseUrl <ExamineManagementApiController>(
                                    controller => controller.GetIndexerDetails())
                            },
                            {
                                "xmlDataIntegrityBaseUrl", Url.GetUmbracoApiServiceBaseUrl <XmlDataIntegrityController>(
                                    controller => controller.CheckContentXmlTable())
                            },
                            {
                                "healthCheckBaseUrl", Url.GetUmbracoApiServiceBaseUrl <HealthCheckController>(
                                    controller => controller.GetAllHealthChecks())
                            },
                            {
                                "templateQueryApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl <TemplateQueryController>(
                                    controller => controller.PostTemplateQuery(null))
                            },
                            {
                                "codeFileApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl <CodeFileController>(
                                    controller => controller.GetByPath("", ""))
                            }
                        }
                    },
                    {
                        "umbracoSettings", new Dictionary <string, object>
                        {
                            { "umbracoPath", GlobalSettings.Path },
                            { "mediaPath", IOHelper.ResolveUrl(SystemDirectories.Media).TrimEnd('/') },
                            { "appPluginsPath", IOHelper.ResolveUrl(SystemDirectories.AppPlugins).TrimEnd('/') },
                            {
                                "imageFileTypes",
                                string.Join(",", UmbracoConfig.For.UmbracoSettings().Content.ImageFileTypes)
                            },
                            {
                                "disallowedUploadFiles",
                                string.Join(",", UmbracoConfig.For.UmbracoSettings().Content.DisallowedUploadFiles)
                            },
                            {
                                "allowedUploadFiles",
                                string.Join(",", UmbracoConfig.For.UmbracoSettings().Content.AllowedUploadFiles)
                            },
                            {
                                "maxFileSize",
                                GetMaxRequestLength()
                            },
                            { "keepUserLoggedIn", UmbracoConfig.For.UmbracoSettings().Security.KeepUserLoggedIn },
                            { "cssPath", IOHelper.ResolveUrl(SystemDirectories.Css).TrimEnd('/') },
                            { "allowPasswordReset", UmbracoConfig.For.UmbracoSettings().Security.AllowPasswordReset },
                            { "loginBackgroundImage", UmbracoConfig.For.UmbracoSettings().Content.LoginBackgroundImage },
                        }
                    },
                    {
                        "umbracoPlugins", new Dictionary <string, object>
                        {
                            { "trees", GetTreePluginsMetaData() }
                        }
                    },
                    {
                        "isDebuggingEnabled", HttpContext.IsDebuggingEnabled
                    },
                    {
                        "application", GetApplicationState()
                    },
                    {
                        "externalLogins", new Dictionary <string, object>
                        {
                            {
                                "providers", HttpContext.GetOwinContext().Authentication.GetExternalAuthenticationTypes()
                                .Where(p => p.Properties.ContainsKey("UmbracoBackOffice"))
                                .Select(p => new
                                {
                                    authType = p.AuthenticationType, caption = p.Caption,
                                    //TODO: Need to see if this exposes any sensitive data!
                                    properties = p.Properties
                                })
                                .ToArray()
                            }
                        }
                    }
                };

                //Parse the variables to a string
                return(ServerVariablesParser.Parse(defaultVals));
            };

            //cache the result if debugging is disabled
            var result = HttpContext.IsDebuggingEnabled
                ? getResult()
                : ApplicationContext.ApplicationCache.RuntimeCache.GetCacheItem <string>(
                typeof(BackOfficeController) + "ServerVariables",
                () => getResult(),
                new TimeSpan(0, 10, 0));

            return(JavaScript(result));
        }