Exemple #1
0
 public ModulePath(string moduleName, Site site)
 {
     ModuleName = moduleName;
     Site = site;
     PhysicalPath = PhysicalPathAccessor(moduleName);
     VirtualPath = VirtualPathAccessor(moduleName);
 }
Exemple #2
0
        public static ActionResult CreateRedirectResult(Site site, FrontRequestChannel channel, string url, string rawUrl, int? statusCode, RedirectType redirectType, bool appendErrorPath = true)
        {
            var redirectUrl = url;
            if (!UrlUtility.IsAbsoluteUrl(redirectUrl))
            {
                redirectUrl = UrlUtility.ResolveUrl(redirectUrl);
                //WrapperUrl will cause endless loop if site host by ASP.NET development server when transfer redirect.
                if (redirectType != RedirectType.Transfer || Settings.IsHostByIIS)
                {
                    redirectUrl = FrontUrlHelper.WrapperUrl(redirectUrl, site, channel).ToString();
                }
            }
            if (appendErrorPath == true)
            {
                if (!string.IsNullOrEmpty(rawUrl))
                {
                    redirectUrl = redirectUrl.AddQueryParam("returnUrl", rawUrl);
                }
                //if (statusCode != null)
                //{
                //    redirectUrl = redirectUrl.AddQueryParam("statusCode", statusCode.ToString());
                //}
            }
            switch (redirectType)
            {
                case RedirectType.Moved_Permanently_301:
                    return new Redirect301Result(redirectUrl);

                case RedirectType.Transfer:
                    return new TransferResult(redirectUrl, statusCode ?? 200);
                case RedirectType.Found_Redirect_302:
                default:
                    return new RedirectResult(redirectUrl);
            }
        }
        public override void ExecuteResult(ControllerContext context)
        {
            string siteName = context.HttpContext.Request.QueryString["cms_siteName"];
            string pageName = context.HttpContext.Request.QueryString["cms_pageName"];

            if (string.IsNullOrEmpty(siteName) || string.IsNullOrEmpty(pageName))
            {
                context.HttpContext.Response.StatusCode = 404;
                return;
            }
            var site = new Site(siteName).AsActual();
            if (site == null)
            {
                context.HttpContext.Response.StatusCode = 404;
                return;
            }
            var page = new Page(site, pageName).AsActual();
            if (page == null || page.PagePositions == null)
            {
                context.HttpContext.Response.StatusCode = 404;
                return;
            }
            var proxyPosition = page.PagePositions.OfType<ProxyPosition>().FirstOrDefault();
            if (proxyPosition == null)
            {
                context.HttpContext.Response.StatusCode = 404;
                return;
            }
            var remoteUrl = context.HttpContext.Request.RawUrl;
            var content = _proxyRender.Render(new ProxyRenderContext(context, null, proxyPosition, remoteUrl));
            if (content != null && !string.IsNullOrEmpty(content.ToString()))
            {
                context.HttpContext.Response.Write(content.ToString());
            }
        }
Exemple #4
0
 public Label(Site site, string category, string name, string value)
     : this()
 {
     this.Site = site;
     this.Category = category;
     this.Name = name;
     this.Value = value;
 }
Exemple #5
0
 public void Add(Site site, Label label)
 {
     if (string.IsNullOrEmpty(label.UUID))
     {
         label.UUID = UniqueIdGenerator.GetInstance().GetBase32UniqueId(10);
     }
     this._labelProvider.Add(label);
 }
Exemple #6
0
 private static byte[] GetKey(Site site)
 {
     if (site == null)
     {
         throw new ArgumentNullException("SecurityHelper 需要 Site.Current context.");
     }
     return ASCIIEncoding.ASCII.GetBytes(site.Security.EncryptKey);
 }
Exemple #7
0
        public virtual IEnumerable<StyleFile> AllStylesEnumerable(Site site, string themeName)
        {
            var theme = new Theme(site, themeName);

            var fileNames = EnumerateCssFilesWithPath(site, themeName);

            fileNames = FileOrderHelper.OrderFiles(GetOrderFile(site, themeName), fileNames);

            return fileNames.Select(it => new StyleFile(theme, it).LastVersion());
        }
Exemple #8
0
 public virtual void Delete(Site site, string fileName)
 {
     AssemblyFile assemblyFile = new AssemblyFile(site, fileName);
     if (assemblyFile.Exists())
     {
         assemblyFile.Delete();
     }
     DeleteFromBin(site, fileName);
     EnsureAssembliesExistsInBin(site);
 }
Exemple #9
0
 public static IElementRepository GetElementRepository(Site site)
 {
     var repository = site.ObjectCache().Get(cacheKey);
     if (repository == null)
     {
         repository = new CacheElementRepository(() => EngineContext.Current.Resolve<IElementRepositoryFactory>().CreateRepository(site));
         site.ObjectCache().Add(cacheKey, repository, new System.Runtime.Caching.CacheItemPolicy()
         {
             SlidingExpiration = TimeSpan.Parse("00:30:00")
         });
     }
     return (IElementRepository)repository;
 }
Exemple #10
0
 public virtual void Update(Site site, Label @new, Label old)
 {
     if (@new.Site == null)
     {
         @new.Site = site;
     }
     //renew the UUID when UUID is null
     if (string.IsNullOrEmpty(@new.UUID))
     {
         @new.UUID = UniqueIdGenerator.GetInstance().GetBase32UniqueId(10);
     }
     this._labelProvider.Update(@new, old);
 }
        public MembershipAuthentication(Site site, Bsc.Dmtds.Membership.Models.Membership membership, HttpContextBase httpContextBase)
        {
            if (site == null)
            {
                throw new ArgumentNullException("site");
            }
            if (httpContextBase == null)
            {
                throw new ArgumentNullException("httpContextBase");
            }
            this._site = site;
            this._membership = membership;

            this._httpContext = httpContextBase;
        }
Exemple #12
0
 public static string Decrypt(Site site, string cryptedString)
 {
     if (String.IsNullOrEmpty(cryptedString))
     {
         return cryptedString;
     }
     var key = GetKey(site.AsActual());
     DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
     MemoryStream memoryStream = new MemoryStream
             (Convert.FromBase64String(cryptedString));
     CryptoStream cryptoStream = new CryptoStream(memoryStream,
         cryptoProvider.CreateDecryptor(key, key), CryptoStreamMode.Read);
     StreamReader reader = new StreamReader(cryptoStream);
     return reader.ReadToEnd();
 }
Exemple #13
0
        /// <summary>
        /// Label with inline-editing.
        /// </summary>
        /// <param name="defaultValue">The default value.</param>
        /// <param name="key">The key.</param>
        /// <param name="category">The category.</param>
        /// <param name="site">The site.</param>
        /// <returns></returns>
        public static IHtmlString Label(this string defaultValue, string key, string category, Site site)
        {
            string value = LabelValue(defaultValue, key, category, site);

            if (Settings.IsWebApplication && Page_Context.Current.Initialized && Page_Context.Current.EnabledInlineEditing(EditingType.Label))
            {
                value = string.Format("<var start=\"true\" editType=\"label\" dataType=\"{0}\" key=\"{1}\" category=\"{2}\" style=\"display:none;\"></var>{3}<var end=\"true\" style=\"display:none;\"></var>"
                    , Sites.View.FieldDataType.Text.ToString()
                    , HttpUtility.HtmlEncode(key)
                    , HttpUtility.HtmlEncode(category)
                    , value);
            }

            return new HtmlString(value);
        }
Exemple #14
0
        public virtual DiagnosisResult Diagnosis(Site site)
        {
            DiagnosisResult result = new DiagnosisResult();

            result.WebApplicationInformation = WebBaseEvent.ApplicationInformation;
            result.ContentProvider = Bsc.Dmtds.Content.Persistence.Providers.DefaultProviderFactory.Name;

            result.DiagnosisItems = new[] {
                CheckCms_Data(),
                CheckDbConnection(),
                CheckSmtp(site),
                CheckDomain(site)
            };

            return result;
        }
Exemple #15
0
        public bool Map(Site site, string inputUrl, out string outputUrl, out RedirectType redirectType)
        {
            outputUrl = string.Empty;
            redirectType = RedirectType.Found_Redirect_302;
            if (string.IsNullOrEmpty(inputUrl))
            {
                return false;
            }
            var mapSettings = Services.ServiceFactory.UrlRedirectManager.All(site, "");
            //inputUrl = inputUrl.Trim('/');
            if (!inputUrl.StartsWith("/"))
            {
                inputUrl = "/" + inputUrl;
            }
            foreach (var setting in mapSettings)
            {
                var inputPattern = setting.InputUrl;//.Trim('/');
                if (setting.Regex)
                {
                    try
                    {
                        if (Regex.IsMatch(inputUrl, inputPattern, RegexOptions.IgnoreCase))
                        {
                            outputUrl = Regex.Replace(inputUrl, inputPattern, setting.OutputUrl, RegexOptions.IgnoreCase);
                            redirectType = setting.RedirectType;
                            return true;
                        }
                    }
                    catch (Exception e)
                    {
                        Bsc.Dmtds.Common.HealthMonitoring.Log.LogException(e);
                    }

                }
                else
                {
                    if (inputUrl.EqualsOrNullEmpty(inputPattern, StringComparison.CurrentCultureIgnoreCase))
                    {
                        outputUrl = setting.OutputUrl;
                        redirectType = setting.RedirectType;
                        return true;
                    }
                }
            }
            return false;
        }
Exemple #16
0
        public static IHtmlString GeneratePageUrl(UrlHelper urlHelper, Site site, Page page, object values, FrontRequestChannel channel)
        {
            RouteValueDictionary routeValues = RouteValuesHelpers.GetRouteValues(values);

            page = page.AsActual();

            if (page == null)
            {
                return new HtmlString("");
            }
            if (page.Route != null && !string.IsNullOrEmpty(page.Route.ExternalUrl))
            {
                return new HtmlString(page.Route.ExternalUrl);
            }

            var pageRoute = page.Route.ToMvcRoute();

            routeValues = RouteValuesHelpers.MergeRouteValues(pageRoute.Defaults, routeValues);

            var routeVirtualPath = pageRoute.GetVirtualPath(urlHelper.RequestContext, routeValues);
            if (routeVirtualPath == null)
            {
                throw new InvalidPageRouteException(page);
            }
            //string contentUrl = routeVirtualPath.VirtualPath;//don't decode the url. why??
            //if do not decode the url, the route values contains Chinese character will cause bad request.
            string contentUrl = HttpUtility.UrlDecode(routeVirtualPath.VirtualPath);
            string pageUrl = contentUrl;
            if (!string.IsNullOrEmpty(contentUrl) || (string.IsNullOrEmpty(pageUrl) && !page.IsDefault))
            {
                pageUrl = UrlUtility.Combine(page.VirtualPath, contentUrl);
            }
            if (string.IsNullOrEmpty(pageUrl))
            {
                pageUrl = urlHelper.Content("~/");
            }
            else
            {
                pageUrl = HttpUtility.UrlDecode(
                urlHelper.RouteUrl("Page", new { PageUrl = new HtmlString(pageUrl) }));
            }
            var url = FrontUrlHelper.WrapperUrl(pageUrl, site, channel, page.RequireHttps);

            return url;
        }
Exemple #17
0
 /// <summary>
 /// Encrypts the specified original string.
 /// </summary>
 /// <param name="site">The site.</param>
 /// <param name="plainText">The plain string.</param>
 /// <returns></returns>
 /// <exception cref="System.ArgumentNullException">The string which needs to be encrypted can not be null.</exception>
 public static string Encrypt(Site site, string plainText)
 {
     if (String.IsNullOrEmpty(plainText))
     {
         return plainText;
     }
     var key = GetKey(site);
     DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
     MemoryStream memoryStream = new MemoryStream();
     CryptoStream cryptoStream = new CryptoStream(memoryStream,
         cryptoProvider.CreateEncryptor(key, key), CryptoStreamMode.Write);
     StreamWriter writer = new StreamWriter(cryptoStream);
     writer.Write(plainText);
     writer.Flush();
     cryptoStream.FlushFinalBlock();
     writer.Flush();
     return Convert.ToBase64String(memoryStream.GetBuffer(), 0, (int)memoryStream.Length);
 }
Exemple #18
0
        public virtual Site MatchRule(Site site, HttpContextBase httpContext, out ABSiteSetting abSiteSetting)
        {
            var matchedSite = site;
            var ruleName = site.FullName;

            var visitRule = abSiteSetting = Get(ruleName);
            if (visitRule != null)
            {
                ABSiteRuleItem matchedRuleItem = null;
                var ruleSetting = new ABRuleSetting(null, visitRule.RuleName).AsActual();
                if (ruleSetting != null && ruleSetting.RuleItems != null)
                {
                    foreach (var item in visitRule.Items)
                    {
                        var ruleItem = ruleSetting.RuleItems.Where(it => it.Name.EqualsOrNullEmpty(item.RuleItemName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                        if (ruleItem.IsMatch(httpContext.Request))
                        {
                            if (!string.IsNullOrEmpty(item.SiteName))
                            {
                                var ruleSite = new Site(item.SiteName).AsActual();
                                if (ruleSite != null)
                                {
                                    matchedSite = ruleSite;
                                    matchedRuleItem = item;
                                    break;
                                }
                            }
                        }
                    }

                    OnRuleMatch(new SiteMatchedContext() { HttpContext = httpContext, RawSite = site, MatchedSite = matchedSite, SiteVisitRule = visitRule, MatchedRuleItem = matchedRuleItem });
                }

            }
            return matchedSite;
        }
Exemple #19
0
 public void EnsureAssembliesExistsInBin(Site site, bool overwrite = true, bool copyParent = true, bool copyChildren = false)
 {
     var files = GetFiles(site);
     foreach (var file in files)
     {
         if (!_assemblyReferences.IsSystemAssembly(file.PhysicalPath))
         {
             var fileInBin = GetAssemblyBinFilePath(file.FileName);
             if (overwrite == true || !File.Exists(fileInBin))
             {
                 File.Copy(file.PhysicalPath, fileInBin, true);
                 _assemblyReferences.AddReference(file.PhysicalPath, GetReferenceName(site));
             }
         }
     }
     //foreach (var file in files)
     //{
     //    var assembly = GetAssembly(site, file.FileName);
     //    if (assembly == null)
     //    {
     //        var fileInBin = GetAssemblyBinFilePath(file.FileName);
     //        Assembly.LoadFrom(fileInBin);
     //    }
     //}
     if (copyParent && site.Parent != null)
     {
         EnsureAssembliesExistsInBin(site.Parent, overwrite, copyParent, copyChildren);
     }
     if (copyChildren)
     {
         foreach (var child in ServiceFactory.SiteManager.ChildSites(site))
         {
             EnsureAssembliesExistsInBin(child, overwrite, copyParent, copyChildren);
         }
     }
 }
Exemple #20
0
        public static ModuleContext Create(string moduleName, Site site, ModulePosition position)
        {
            var context = new ModuleContext(moduleName, site, position);

            if (!System.IO.Directory.Exists(context.ModulePath.PhysicalPath))
            {
                throw new Exception(string.Format("The module does not exist.Module name:{0}", moduleName));
            }
            return context;
        }
Exemple #21
0
 public ModuleContext(string moduleName, Site site)
 {
     this.Site = site;
     ModuleName = moduleName;
 }
Exemple #22
0
 public ModuleContext(string moduleName, Site site, ModulePosition position)
     : this(moduleName, site)
 {
     this.FrontEndContext = new FrontEndContext(moduleName, this.GetModuleSettings(), position);
 }
Exemple #23
0
 public static ModuleContext Create(string moduleName, Site site)
 {
     return new ModuleContext(moduleName, site);
 }
Exemple #24
0
 public static FrontUrlHelper FrontUrl(this UrlHelper url, Site site, FrontRequestChannel requestChannel = FrontRequestChannel.Host)
 {
     return new FrontUrlHelper(url, site, requestChannel);
 } 
Exemple #25
0
        public ScriptBaseDirectory(Site site)
            : base(site, ScriptFile.PATH_NAME)
        {

        }
Exemple #26
0
 protected ScriptBaseDirectory(Site site, string name)
     : base(site, name)
 {
 }
Exemple #27
0
 private IEnumerable<Models.View> GetViewsInPage(Site site, Page page)
 {
     var viewPositions = page.AsActual().PagePositions.Where(it => it is ViewPosition).OrderBy(it => it.Order);
     foreach (ViewPosition viewPosition in viewPositions)
     {
         var view = new Models.View(site, viewPosition.ViewName).LastVersion();
         if (!view.Exists())
         {
             throw new BscException(string.Format("The view '{0}' does not exists.Name.", view.Name));
         }
         yield return view;
     }
 }
Exemple #28
0
 public LabelPath(Site site)
     : base(site, "Labels")
 {
 }
Exemple #29
0
 //ConcurrentDictionary<ElementCacheKey, Element> entries = new ConcurrentDictionary<ElementCacheKey, Element>(new ElementCacheKeyEqualityComparer());
 public SiteLabelRepository(Site site)
 {
     StoreRepository = new XmlElementRepository(new LabelPath(site).PhysicalPath);
 }
Exemple #30
0
 protected override Models.DirectoryResource GetRootDir(Site site)
 {
     return new ScriptBaseDirectory(site);
 }