Exemplo n.º 1
0
        private string TokeniseLinks(string content, int portalId)
        {
            // Replace any relative portal root reference by a token "{{PortalRoot}}"
            var portal     = PortalController.Instance.GetPortal(portalId);
            var portalRoot = UrlUtils.Combine(Globals.ApplicationPath, portal.HomeDirectory);

            if (!portalRoot.StartsWith("/"))
            {
                portalRoot = "/" + portalRoot;
            }

            if (!portalRoot.EndsWith("/"))
            {
                portalRoot = portalRoot + "/";
            }

            // Portal Root regular expression
            var regex = @"(?<url>
                        (?<host>
                        (?<protocol>[A-Za-z]{3,9}:(?:\/\/)?)
                        (?<domain>(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+))?
                        (?<portalRoot>" + portalRoot + "))";

            var matchEvaluator = new MatchEvaluator(this.ReplaceWithRootToken);
            var exp            = RegexUtils.GetCachedRegex(regex, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);

            return(exp.Replace(content, matchEvaluator));
        }
Exemplo n.º 2
0
        void OnEndRequest(object sender, EventArgs args)
        {
            HttpApplication app     = (HttpApplication)sender;
            HttpContext     context = app.Context;

            if (context.Response.StatusCode != 401 || context.Request.QueryString ["ReturnUrl"] != null)
            {
                return;
            }

#if NET_4_5
            if (context.Response.StatusCode == 401 && context.Response.SuppressFormsAuthenticationRedirect)
            {
                return;
            }
#endif

            string loginPage;
            InitConfig(context);
#if NET_2_0
            loginPage = _config.Forms.LoginUrl;
#else
            loginPage = _config.LoginUrl;
#endif
            if (_config == null || _config.Mode != AuthenticationMode.Forms)
            {
                return;
            }

            StringBuilder login = new StringBuilder();
            login.Append(UrlUtils.Combine(context.Request.ApplicationPath, loginPage));
            login.AppendFormat("?ReturnUrl={0}", HttpUtility.UrlEncode(context.Request.RawUrl));
            context.Response.Redirect(login.ToString(), false);
        }
Exemplo n.º 3
0
        public static string ToAbsoluteUrl(string link, string baseUrl, string serverUrl /*, bool isSecure*/)
        {
            if (link.StartsWith("//"))
            {
                bool isSecure = serverUrl != null &&
                                serverUrl.StartsWith("https://", StringComparison.OrdinalIgnoreCase);

                return("http{0}://{1}".FormatWith(isSecure ? "s" : "", link));
            }

            if (IsAbsoluteLink(link))
            {
                return(link);
            }

            if (!link.StartsWith("/"))
            {
                if (!IsAbsoluteLink(baseUrl))
                {
                    baseUrl = UrlUtils.Combine(serverUrl, baseUrl);
                }

                return(UrlUtils.Combine(baseUrl, link));
            }

            return(UrlUtils.Combine(serverUrl, link));
        }
        Assembly GetAssemblyFromSource(string vpath, ILocation location)
        {
            vpath = UrlUtils.Combine(BaseVirtualDir, vpath);
            string realPath = context.Request.MapPath(vpath);

            if (!File.Exists(realPath))
            {
                throw new ParseException(location, "File " + vpath + " not found");
            }

            AddDependency(vpath);

            CompilerResults result = CachingCompiler.Compile(language, realPath, realPath, assemblies);

            if (result.NativeCompilerReturnValue != 0)
            {
                using (StreamReader sr = new StreamReader(realPath))
                {
                    throw new CompilationException(realPath, result.Errors, sr.ReadToEnd());
                }
            }

            AddAssembly(result.CompiledAssembly, true);
            return(result.CompiledAssembly);
        }
Exemplo n.º 5
0
        public string MapPath(string virtualPath)
        {
            if (!String.IsNullOrEmpty(virtualPath))
            {
                if (virtualPath.StartsWith(System.Web.Compilation.BuildManager.FAKE_VIRTUAL_PATH_PREFIX, StringComparison.Ordinal))
                {
                    return(HttpRuntime.AppDomainAppPath);
                }
            }

            if (map != null)
            {
                return(MapPathFromMapper(virtualPath));
            }
            else if (HttpContext.Current != null && HttpContext.Current.Request != null)
            {
                return(HttpContext.Current.Request.MapPath(virtualPath));
            }
            else if (HttpRuntime.AppDomainAppVirtualPath != null &&
                     virtualPath.StartsWith(HttpRuntime.AppDomainAppVirtualPath))
            {
                if (virtualPath == HttpRuntime.AppDomainAppVirtualPath)
                {
                    return(HttpRuntime.AppDomainAppPath);
                }
                return(UrlUtils.Combine(HttpRuntime.AppDomainAppPath,
                                        virtualPath.Substring(HttpRuntime.AppDomainAppVirtualPath.Length)));
            }

            return(virtualPath);
        }
Exemplo n.º 6
0
        public BrowserViewSettings TryGetBrowserViewSettings(EntityToken entityToken, bool showPublishedView)
        {
            const string ViewKeywordsUrl = "/InstalledPackages/Orckestra.Search.KeywordRedirect/view/viewkeywords.html";

            if (entityToken is TreeSimpleElementEntityToken castedEntityToken && castedEntityToken.Id == "OrckestraSearchKeywordRedirect")
            {
                return(new BrowserViewSettings
                {
                    Url = UrlUtils.Combine(UrlUtils.AdminRootPath, ViewKeywordsUrl),
                    ToolingOn = false
                });
            }

            if (entityToken is TreeDataFieldGroupingElementEntityToken groupingEntityToken &&
                groupingEntityToken.Type.StartsWith(typeof(RedirectKeyword).ToString()) &&
                groupingEntityToken.GroupingValues?.FirstOrDefault().Value is Guid homepageId)
            {
                return(new BrowserViewSettings
                {
                    Url = UrlUtils.Combine(UrlUtils.AdminRootPath, $"{ViewKeywordsUrl}?homePageId={homepageId}"),
                    ToolingOn = false
                });
            }

            return(null);
        }
Exemplo n.º 7
0
        private string GetCurrentUrl()
        {
            var routeData = HttpContext.Request.RequestContext.RouteData;
            var result    = "/" + UrlUtils.Combine((routeData.DataTokens["area"] ?? string.Empty).ToString(),
                                                   routeData.Values["controller"].ToString(),
                                                   routeData.Values["action"].ToString());

            return(result);
        }
Exemplo n.º 8
0
        protected override string HandleUrlProperty(string str, MemberInfo member)
        {
            if (str.StartsWith("~", StringComparison.Ordinal))
            {
                return(str);
            }

            return("~/App_Themes/" + UrlUtils.Combine(
                       System.IO.Path.GetFileName(parser.InputFile), str));
        }
Exemplo n.º 9
0
        Type GetTypeFromControlPath(string virtualPath)
        {
            if (virtualPath == null)
            {
                throw new ArgumentNullException("virtualPath");
            }

            string vpath = UrlUtils.Combine(TemplateSourceDirectory, virtualPath);

            return(BuildManager.GetCompiledType(vpath));
        }
Exemplo n.º 10
0
 static string MapUrl(string url)
 {
     if (UrlUtils.IsRelativeUrl(url))
     {
         return(UrlUtils.Combine(HttpRuntime.AppDomainAppVirtualPath, url));
     }
     else
     {
         return(UrlUtils.ResolveVirtualPathFromAppAbsolute(url));
     }
 }
        public string TryGetUrl(EntityToken entityToken)
        {
            var castedEntityToken = entityToken as TreeSimpleElementEntityToken;

            if (castedEntityToken == null || castedEntityToken.Id != "system.server.log")
            {
                return(null);
            }

            return(UrlUtils.Combine(UrlUtils.AdminRootPath, "/content/views/log/log.aspx?hideToolbar=true"));
        }
Exemplo n.º 12
0
        Type GetTypeFromControlPath(string virtualPath)
        {
            if (virtualPath == null)
            {
                throw new ArgumentNullException("virtualPath");
            }

            string vpath = UrlUtils.Combine(TemplateSourceDirectory, virtualPath);

            return(PageMapper.GetObjectType(Context, vpath));
        }
Exemplo n.º 13
0
        public override string GetFilePath()
        {
            string result = UrlUtils.Combine(app_virtual_dir, page);

            if (result == "")
            {
                return(app_virtual_dir == "/" ? app_virtual_dir : app_virtual_dir + "/");
            }

            return(result);
        }
Exemplo n.º 14
0
        public BrowserViewSettings TryGetBrowserViewSettings(EntityToken entityToken, bool showPublishedView)
        {
            var castedEntityToken = entityToken as TreeSimpleElementEntityToken;

            if (castedEntityToken == null || castedEntityToken.Id != "system.server.log")
            {
                return(null);
            }

            return(new BrowserViewSettings {
                Url = UrlUtils.Combine(UrlUtils.AdminRootPath, "/content/views/log/log.aspx?browserView=true"), ToolingOn = false
            });
        }
Exemplo n.º 15
0
            public static string GetPortalRoot(int portalId)
            {
                PortalInfo portal = PortalController.Instance.GetPortal(portalId);

                string portalRoot = UrlUtils.Combine(DotNetNuke.Common.Globals.ApplicationPath, portal.HomeDirectory);

                if (!portalRoot.StartsWith("/"))
                {
                    portalRoot = "/" + portalRoot;
                }

                return(portalRoot);
            }
Exemplo n.º 16
0
        private string DeTokeniseLinks(string content, int portalId)
        {
            var portalController = new PortalController();
            var portal           = portalController.GetPortal(portalId);
            var portalRoot       = UrlUtils.Combine(Globals.ApplicationPath, portal.HomeDirectory);

            if (!portalRoot.StartsWith("/"))
            {
                portalRoot = "/" + portalRoot;
            }
            content = content.Replace(PortalRootToken, portalRoot);

            return(content);
        }
        /// <exclude />
        public string GetResizedImageUrl(string storeId, Guid mediaId, ResizingOptions resizingOptions)
        {
            IMediaFile file = GetFileById(storeId, mediaId);

            if (file == null)
            {
                return(null);
            }

            string pathToFile = UrlUtils.Combine(file.FolderPath, file.FileName);

            pathToFile = RemoveForbiddenCharactersAndNormalize(pathToFile);

            // IIS6 doesn't have wildcard mapping by default, so removing image extension if running in "classic" app pool
            if (!HttpRuntime.UsingIntegratedPipeline)
            {
                int dotOffset = pathToFile.IndexOf(".", StringComparison.Ordinal);
                if (dotOffset >= 0)
                {
                    pathToFile = pathToFile.Substring(0, dotOffset);
                }
            }

            string mediaStore = string.Empty;

            if (!storeId.Equals(DefaultMediaStore, StringComparison.InvariantCultureIgnoreCase))
            {
                mediaStore = storeId + "/";
            }


            var url = new UrlBuilder(UrlUtils.PublicRootPath + "/media/" + mediaStore + /* UrlUtils.CompressGuid(*/ mediaId /*)*/)
            {
                PathInfo = file.LastWriteTime != null
                    ? "/" + GetDateTimeHash(file.LastWriteTime.Value.ToUniversalTime())
                    : string.Empty
            };

            if (pathToFile.Length > 0)
            {
                url.PathInfo += pathToFile;
            }

            if (resizingOptions != null && !resizingOptions.IsEmpty)
            {
                return(url + "?" + resizingOptions);
            }

            return(url.ToString());
        }
Exemplo n.º 18
0
        public BrowserViewSettings TryGetBrowserViewSettings(EntityToken entityToken, bool showPublishedView)
        {
            var castedEntityToken = entityToken as TreeSimpleElementEntityToken;

            if (castedEntityToken == null || castedEntityToken.Id != "OrckestraSearchKeywordRedirect")
            {
                return(null);
            }

            return(new BrowserViewSettings
            {
                Url = UrlUtils.Combine(UrlUtils.AdminRootPath, "/InstalledPackages/Orckestra.Search.KeywordRedirect/view/viewkeywords.html"),
                ToolingOn = false
            });
        }
Exemplo n.º 19
0
        string ResolveAdUrl(string url)
        {
            string path = url;

            if (AdvertisementFile != null && AdvertisementFile.Length > 0 && path [0] != '/' && path [0] != '~')
            {
                try {
                    new Uri(path);
                }
                catch {
                    return(UrlUtils.Combine(UrlUtils.GetDirectory(ResolveUrl(AdvertisementFile)), path));
                }
            }

            return(ResolveUrl(path));
        }
Exemplo n.º 20
0
        Type GetTypeFromControlPath(string virtualPath)
        {
            if (virtualPath == null)
            {
                throw new ArgumentNullException("virtualPath");
            }

            string vpath = UrlUtils.Combine(TemplateSourceDirectory, virtualPath);

#if NET_2_0
            return(BuildManager.GetCompiledType(vpath));
#else
            string realpath = Context.Request.MapPath(vpath);
            return(UserControlParser.GetCompiledType(vpath, realpath, Context));
#endif
        }
Exemplo n.º 21
0
        public string ApplyAppPathModifier(string virtualPath)
        {
            if (virtualPath == null)
            {
                return(null);
            }

            if (virtualPath.Length == 0)
            {
                return(context.Request.RootVirtualDir);
            }

            if (UrlUtils.IsRelativeUrl(virtualPath))
            {
                virtualPath = UrlUtils.Combine(context.Request.RootVirtualDir, virtualPath);
            }
            else if (UrlUtils.IsRooted(virtualPath))
            {
                virtualPath = UrlUtils.Canonic(virtualPath);
            }

            bool cookieless = false;

#if NET_2_0
            SessionStateSection config = WebConfigurationManager.GetWebApplicationSection("system.web/sessionState") as SessionStateSection;
            cookieless = SessionStateModule.IsCookieLess(context, config);
#else
            SessionConfig config = HttpContext.GetAppConfig("system.web/sessionState") as SessionConfig;
            cookieless = config.CookieLess;
#endif
            if (!cookieless)
            {
                return(virtualPath);
            }

            if (app_path_mod != null && virtualPath.IndexOf(app_path_mod) < 0)
            {
                if (UrlUtils.HasSessionId(virtualPath))
                {
                    virtualPath = UrlUtils.RemoveSessionId(VirtualPathUtility.GetDirectory(virtualPath), virtualPath);
                }
                return(UrlUtils.InsertSessionId(app_path_mod, virtualPath));
            }

            return(virtualPath);
        }
Exemplo n.º 22
0
 public override string GetRawUrl()
 {
     if (raw_url == null)
     {
         string q = ((query == null || query == "") ? "" : "?" + query);
         raw_url = UrlUtils.Combine(app_virtual_dir, page);
         if (path_info != "")
         {
             raw_url += "/" + path_info + q;
         }
         else
         {
             raw_url += q;
         }
     }
     return(raw_url);
 }
Exemplo n.º 23
0
        private string DeTokeniseLinks(string content, int portalId)
        {
            var portal     = PortalController.Instance.GetPortal(portalId);
            var portalRoot = UrlUtils.Combine(Globals.ApplicationPath, portal.HomeDirectory);

            if (!portalRoot.StartsWith("/"))
            {
                portalRoot = "/" + portalRoot;
            }
            if (!portalRoot.EndsWith("/"))
            {
                portalRoot = portalRoot + "/";
            }
            content = Regex.Replace(content, PortalRootToken + "\\/{0,1}", portalRoot, RegexOptions.IgnoreCase);

            return(content);
        }
Exemplo n.º 24
0
        private string TokeniseLinks(string content, int portalId)
        {
            //Replace any relative portal root reference by a token "{{PortalRoot}}"
            var portalController = new PortalController();
            var portal           = portalController.GetPortal(portalId);
            var portalRoot       = UrlUtils.Combine(Globals.ApplicationPath, portal.HomeDirectory);

            if (!portalRoot.StartsWith("/"))
            {
                portalRoot = "/" + portalRoot;
            }
            Regex exp = new Regex(portalRoot, RegexOptions.IgnoreCase);

            content = exp.Replace(content, PortalRootToken);

            return(content);
        }
Exemplo n.º 25
0
        private string TokeniseLinks(string content, int portalId)
        {
            //Replace any relative portal root reference by a token "{{PortalRoot}}"
            var portal     = PortalController.Instance.GetPortal(portalId);
            var portalRoot = UrlUtils.Combine(Globals.ApplicationPath, portal.HomeDirectory);

            if (!portalRoot.StartsWith("/"))
            {
                portalRoot = "/" + portalRoot;
            }
            if (!portalRoot.EndsWith("/"))
            {
                portalRoot = portalRoot + "/";
            }
            var exp = RegexUtils.GetCachedRegex(portalRoot, RegexOptions.IgnoreCase);

            return(exp.Replace(content, PortalRootToken));
        }
Exemplo n.º 26
0
        private PageRenderingResult RenderPage(string url, out string responseBody, out string errorMessage)
        {
            if (!url.StartsWith("http"))
            {
                url = UrlUtils.Combine(_serverUrl, url);
            }

            // Marking the link as valid, so it won't be shown multiple places and there won't be any additional requests
            _brokenLinks.TryAdd(url, BrokenLinkType.None);

            var result = HttpRequestHelper.RenderPage(url, out responseBody, out errorMessage);

            if (result == PageRenderingResult.NotFound)
            {
                _brokenLinks.TryAdd(url, BrokenLinkType.Relative);
            }

            return(result);
        }
Exemplo n.º 27
0
        static string MapPath(HttpRequest req, string virtualPath)
        {
            if (req != null)
            {
                return(req.MapPath(virtualPath));
            }

            string appRoot = HttpRuntime.AppDomainAppVirtualPath;

            if (!String.IsNullOrEmpty(appRoot) && virtualPath.StartsWith(appRoot, StringComparison.Ordinal))
            {
                if (String.Compare(virtualPath, appRoot, StringComparison.Ordinal) == 0)
                {
                    return(HttpRuntime.AppDomainAppPath);
                }
                return(UrlUtils.Combine(HttpRuntime.AppDomainAppPath, virtualPath.Substring(appRoot.Length)));
            }

            return(null);
        }
Exemplo n.º 28
0
        private static void RenderPage(IPage page)
        {
            var context = HttpContext.Current;

            if (context == null)
            {
                return;
            }

            var urlSpace = new UrlSpace(context)
            {
                ForceRelativeUrls = false
            };
            var url = PageUrls.BuildUrl(page, UrlKind.Public, urlSpace)
                      ?? PageUrls.BuildUrl(page, UrlKind.Renderer, urlSpace);

            if (string.IsNullOrEmpty(url))
            {
                return;
            }

            var    requestUrl = context.Request.Url;
            string hostName   = requestUrl.Host;

            if (!url.StartsWith("http", StringComparison.InvariantCultureIgnoreCase))
            {
                string serverUrl = new UrlBuilder(requestUrl.ToString()).ServerUrl;

                url = UrlUtils.Combine(serverUrl, url);
            }

            string cookies = context.Request.Headers["Cookie"];

            string responseBody, errorMessage;
            var    result = RenderPage(hostName, url, cookies, out responseBody, out errorMessage);

            if (result != PageRenderingResult.Successful && Interlocked.Increment(ref _errorCounter) <= MaxRenderErrorsToLog)
            {
                Log.LogWarning(LogTitle, $"Failed to render page '{url}' with the goal of collecting dymanic url providers. Result: {result}; Error: {errorMessage}");
            }
        }
Exemplo n.º 29
0
        void Execute(string path, TextWriter writer, bool preserveForm, bool isTransfer)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            if (path.IndexOf(':') != -1)
            {
                throw new ArgumentException("Invalid path.");
            }

            string queryString = null;
            int    qmark       = path.IndexOf('?');

            if (qmark != -1)
            {
                queryString = path.Substring(qmark + 1);
                path        = path.Substring(0, qmark);
            }

            string exePath    = UrlUtils.Combine(context.Request.BaseVirtualDir, path);
            bool   cookieless = false;

#if NET_2_0
            SessionStateSection config = WebConfigurationManager.GetWebApplicationSection("system.web/sessionState") as SessionStateSection;
            cookieless = SessionStateModule.IsCookieLess(context, config);
#else
            SessionConfig config = HttpContext.GetAppConfig("system.web/sessionState") as SessionConfig;
            cookieless = config.CookieLess;
#endif
            if (cookieless)
            {
                exePath = UrlUtils.RemoveSessionId(VirtualPathUtility.GetDirectory(exePath), exePath);
            }

            IHttpHandler handler = context.ApplicationInstance.GetHandler(context, exePath, true);
            Execute(handler, writer, preserveForm, exePath, queryString, isTransfer, true);
        }
Exemplo n.º 30
0
        Assembly GetAssemblyFromSource(string vpath)
        {
            vpath = UrlUtils.Combine(BaseVirtualDir, vpath);
            string realPath = MapPath(vpath, false);

            if (!File.Exists(realPath))
            {
                ThrowParseException("File " + vpath + " not found");
            }

            AddSourceDependency(vpath);

            CompilerResults    result;
            string             tmp;
            CompilerParameters parameters;
            CodeDomProvider    provider = BaseCompiler.CreateProvider(HttpContext.Current, language, out parameters, out tmp);

            if (provider == null)
            {
                throw new HttpException("Cannot find provider for language '" + language + "'.");
            }

            AssemblyBuilder abuilder = new AssemblyBuilder(provider);

            abuilder.CompilerOptions = parameters;
            abuilder.AddAssemblyReference(BuildManager.GetReferencedAssemblies() as List <Assembly>);
            abuilder.AddCodeFile(realPath);
            result = abuilder.BuildAssembly(new VirtualPath(vpath));

            if (result.NativeCompilerReturnValue != 0)
            {
                using (StreamReader reader = new StreamReader(realPath)) {
                    throw new CompilationException(realPath, result.Errors, reader.ReadToEnd());
                }
            }

            AddAssembly(result.CompiledAssembly, true);
            return(result.CompiledAssembly);
        }