Exemplo n.º 1
0
        /// <summary>
        /// 删除记录
        /// </summary>
        /// <param name="recordId"></param>
        /// <returns></returns>
        public bool DeleteRecord(int recordId)
        {
            DomainRecord record = this.WriteDB.ReadInfo <DomainRecord>(t => t.ID == recordId);

            if (record == null)
            {
                return(this.FaildMessage("记录不存在"));
            }
            SiteDomain domain = this.ReadDB.ReadInfo <SiteDomain>(t => t.ID == record.DomainID);

            List <DomainCDN> cdnlist = this.ReadDB.ReadList <DomainCDN>(t => t.RecordID == record.ID);

            // 调用CDN接口,删除CDN记录
            foreach (DomainCDN cdn in cdnlist)
            {
                if (cdn.CDNType != CDNProviderType.Manual)
                {
                    CDNProvider provider = ProviderAgent.Instance().GetCDNProviderInfo(cdn.CDNType);
                    if (provider != null || provider.Setting != null)
                    {
                        if (!provider.Setting.Delete(cdn.CName, out string msg))
                        {
                            return(this.FaildMessage(msg));
                        }
                    }
                }
                this.WriteDB.Delete <DomainCDN>(t => t.ID == cdn.ID && t.RecordID == recordId);
            }

            // 此处调用DNSPOD接口,删除别名记录
            // do something
            this.WriteDB.Delete <DomainRecord>(t => t.ID == recordId);

            return(this.AccountInfo.Log(LogType.Site, $"删除商户{domain.SiteID}域名记录{record.SubName}.{domain.Domain}"));
        }
Exemplo n.º 2
0
        public Task GetRecordInfo([FromForm] int id, [FromForm] int siteId)
        {
            DomainRecord record = SiteAgent.Instance().GetRecordInfo(id);

            if (record == null)
            {
                return(this.ShowError("记录不存在"));
            }
            SiteDomain domain = SiteAgent.Instance().GetDomainInfo(siteId, record.DomainID);

            if (domain == null)
            {
                return(this.ShowError("记录数据错误"));
            }
            return(this.GetResult(new
            {
                record.ID,
                record.DomainID,
                record.CDNType,
                record.CName,
                record.Status,
                record.SubName,
                domain.Domain
            }));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 添加域名
        /// </summary>
        /// <param name="siteId">商户ID</param>
        /// <param name="domain">根域名</param>
        /// <param name="subName">子域名</param>
        /// <param name="provider">CDN供应商(如果是商户操作,供应商为系统默认值,不可被商户自主选择)</param>
        /// <returns></returns>
        protected bool AddDomain(int siteId, string domain, string[] subName, CDNProviderType provider)
        {
            domain = WebAgent.GetTopDomain(domain);
            if (string.IsNullOrEmpty(domain))
            {
                return(this.FaildMessage("域名错误"));
            }
            if (this.ReadDB.Exists <SiteDomain>(t => t.Domain == domain))
            {
                return(this.FaildMessage("域名已被添加"));
            }
            foreach (string name in subName)
            {
                if (!Regex.IsMatch(name, @"^@$|^\*$|^\w+$"))
                {
                    return(this.FaildMessage($"子域名{name}不符合规范"));
                }
            }
            using (DbExecutor db = NewExecutor(IsolationLevel.ReadCommitted))
            {
                SiteDomain siteDomain = new SiteDomain()
                {
                    SiteID = siteId,
                    Domain = domain
                };
                siteDomain.AddIdentity(db);

                foreach (string name in subName.Distinct())
                {
                    // 添加域名记录
                    DomainRecord record = new DomainRecord()
                    {
                        CDNType  = provider,
                        CName    = this.CreateRecordCName(name, domain),
                        DomainID = siteDomain.ID,
                        Status   = DomainRecord.RecordStatus.Wait,
                        SubName  = name
                    };
                    record.AddIdentity(db);

                    // 添加CDN记录
                    DomainCDN cdn = new DomainCDN()
                    {
                        RecordID = record.ID,
                        Https    = provider == CDNProviderType.Manual ? DomainCDN.CDNStatus.None : DomainCDN.CDNStatus.Wait,
                        CName    = string.Empty,
                        CDNType  = provider,
                        Status   = provider == CDNProviderType.Manual ? DomainCDN.CDNStatus.None : DomainCDN.CDNStatus.Wait
                    };
                    cdn.Add(db);
                }
                db.Commit();
            }

            return(true);
        }
Exemplo n.º 4
0
        public async Task <bool> AddSiteDomainAsync(string siteId, string domainKey, bool isDefault)
        {
            Ensure.NotNull(siteId);
            Ensure.NotNull(domainKey);

            var client = await GetClientAsync(siteId);

            var domainExists = await DomainExistsAsync(domainKey);

            if (domainExists)
            {
                return(false);
            }
            else
            {
                //If IsDefault True, then clear any other default domains
                //as this domain will be the default
                var defaultDomain = await GetDefaultDomainAsync(siteId);

                if (defaultDomain != null)
                {
                    defaultDomain.IsDefault = false;
                    _db.SiteDomains.Update(defaultDomain);
                    _db.SaveChanges();
                }


                // Save the site domain
                var siteDomain = new SiteDomain()
                {
                    SiteId    = siteId,
                    DomainKey = NormalizeDomain(domainKey),
                    IsDefault = isDefault
                };

                _db.SiteDomains.Add(siteDomain);
                await _db.SaveChangesAsync();


                // Register OIDC Redirect Uris
                await _oidcTenantManager.AddUriAsync(
                    client.TenantKey,
                    siteDomain.ToSignInRedirectUri(),
                    Identity.Models.TenantUriType.OidcSignin
                    );

                await _oidcTenantManager.AddUriAsync(
                    client.TenantKey,
                    siteDomain.ToPostLogoutRedirectUri(),
                    Identity.Models.TenantUriType.OidcPostLogout
                    );

                return(true);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 添加域名解析记录
        /// </summary>
        /// <param name="siteId"></param>
        /// <param name="domainId"></param>
        /// <param name="subName"></param>
        /// <param name="provider"></param>
        /// <returns></returns>
        public new bool AddDomainRecord(int siteId, int domainId, string subName, CDNProviderType provider)
        {
            if (!IsCDNProvider(provider))
            {
                return(this.FaildMessage("当前不支持该供应商"));
            }
            SiteDomain domain = base.GetDomainInfo(siteId, domainId);

            return(base.AddDomainRecord(siteId, domainId, subName, provider) &&
                   this.AccountInfo.Log(LogType.Site, $"给商户{siteId}添加域名记录{subName}.{domain.Domain}"));
        }
Exemplo n.º 6
0
        public JsonResult AddEditSiteDomain(SiteDomain siteDomain)
        {
            if (ModelState.IsValid)
            {
                db.AddEditSiteDomain(siteDomain);
            }

            string status  = !string.IsNullOrEmpty(siteDomain.my_domain)  ? "updated" : "saved";
            string message = $"Site / Domain has been {status} successfully";

            return(Json(message, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 7
0
        private string BuildDefaultUrl(HttpContext httpContext, SiteDomain defaultDomain)
        {
            // TODO: Extend SiteDomain object with UseHttps rather than checking the request
            var host     = defaultDomain.DomainKey;
            var protocol = httpContext.Request.IsHttps ? "https://" : "http://";

            if (host.EndsWith("/"))
            {
                host = host.Substring(0, host.Length - 1);
            }

            return(protocol + host);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 添加域名记录
        /// </summary>
        /// <param name="siteId">商户ID</param>
        /// <param name="domainId">根域名ID</param>
        /// <param name="subName">子域名</param>
        /// <param name="provider">CDN供应商(如果是商户操作,供应商为系统默认值,不可被商户自主选择)</param>
        /// <returns></returns>
        protected bool AddDomainRecord(int siteId, int domainId, string subName, CDNProviderType provider)
        {
            if (string.IsNullOrEmpty(subName) || !Regex.IsMatch(subName, @"^@$|^\*$|^\w+$"))
            {
                return(this.FaildMessage($"子域名{subName}不符合规范"));
            }
            SiteDomain domain = this.GetDomainInfo(siteId, domainId);

            if (domain == null)
            {
                return(this.FaildMessage("域名ID错误"));
            }

            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                if (db.Exists <DomainRecord>(t => t.DomainID == domainId && t.SubName == subName))
                {
                    return(this.FaildMessage("子域名记录已经存在"));
                }

                DomainRecord record = new DomainRecord()
                {
                    CDNType  = provider,
                    CName    = this.CreateRecordCName(subName, domain.Domain),
                    DomainID = domainId,
                    Status   = DomainRecord.RecordStatus.Wait,
                    SubName  = subName
                };
                record.AddIdentity(db);

                // 添加CDN记录
                DomainCDN cdn = new DomainCDN()
                {
                    RecordID = record.ID,
                    Https    = provider == CDNProviderType.Manual ? DomainCDN.CDNStatus.None : DomainCDN.CDNStatus.Wait,
                    CName    = string.Empty,
                    CDNType  = provider,
                    Status   = provider == CDNProviderType.Manual ? DomainCDN.CDNStatus.None : DomainCDN.CDNStatus.Wait
                };
                cdn.Add(db);

                db.Commit();
            }
            return(true);
        }
Exemplo n.º 9
0
        public int AddEditSiteDomain(SiteDomain siteDomain)
        {
            string sqlCommand = "spAddEditSiteDomain";

            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("@my_domain", siteDomain.my_domain);
            parameters.Add("@nmd", siteDomain.nmd);

            using (SqlCommand cmd = General.GetCommand(sqlCommand, parameters))
            {
                if (cmd.Connection.State == ConnectionState.Closed)
                {
                    cmd.Connection.Open();
                }

                return(cmd.ExecuteNonQuery());
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// 删除域名
        /// </summary>
        /// <param name="domainId"></param>
        /// <returns></returns>
        public bool DeleteDomain(int domainId)
        {
            SiteDomain domain = domainId == 0 ? null : this.WriteDB.ReadInfo <SiteDomain>(t => t.ID == domainId);

            if (domain == null)
            {
                this.FaildMessage("该域名不存在");
            }
            List <DomainRecord> records = this.ReadDB.ReadList <DomainRecord>(t => t.DomainID == domain.ID);

            foreach (DomainRecord record in records)
            {
                if (!this.DeleteRecord(record.ID))
                {
                    return(false);
                }
            }
            this.WriteDB.Delete <SiteDomain>(t => t.ID == domainId);
            return(this.AccountInfo.Log(LogType.Site, $"删除商户{domain.SiteID}域名:{domain.Domain}"));
        }
Exemplo n.º 11
0
        public Task GetDomainClipboard([FromForm] int siteId, [FromForm] int domainId)
        {
            SiteDomain domain = SiteAgent.Instance().GetDomainInfo(siteId, domainId);

            if (domain == null)
            {
                return(this.ShowError("域名错误"));
            }
            IEnumerable <DomainRecord> records = SiteAgent.Instance().GetDomainRecordList(domainId).Where(t => t.Status == DomainRecord.RecordStatus.Finish);

            if (records.Count() == 0)
            {
                return(this.ShowError("没有已完成的记录"));
            }

            List <string> clipboard = new List <string>();

            foreach (DomainRecord record in records)
            {
                clipboard.Add($"域名:{record.SubName}.{domain.Domain} 指向到(别名记录) {record.CName}");
            }
            return(this.GetResult(clipboard));
        }
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnSave_Click( object sender, EventArgs e )
        {
            Site site;

            if ( Page.IsValid )
            {
                var rockContext = new RockContext();
                SiteService siteService = new SiteService( rockContext );
                SiteDomainService siteDomainService = new SiteDomainService( rockContext );
                bool newSite = false;

                int siteId = int.Parse( hfSiteId.Value );

                if ( siteId == 0 )
                {
                    newSite = true;
                    site = new Rock.Model.Site();
                    siteService.Add( site );
                }
                else
                {
                    site = siteService.Get( siteId );
                }

                site.Name = tbSiteName.Text;
                site.Description = tbDescription.Text;
                site.Theme = ddlTheme.Text;
                site.DefaultPageId = ppDefaultPage.PageId;
                site.DefaultPageRouteId = ppDefaultPage.PageRouteId;
                site.LoginPageId = ppLoginPage.PageId;
                site.LoginPageRouteId = ppLoginPage.PageRouteId;
                site.CommunicationPageId = ppCommunicationPage.PageId;
                site.CommunicationPageRouteId = ppCommunicationPage.PageRouteId;
                site.RegistrationPageId = ppRegistrationPage.PageId;
                site.RegistrationPageRouteId = ppRegistrationPage.PageRouteId;
                site.PageNotFoundPageId = ppPageNotFoundPage.PageId;
                site.PageNotFoundPageRouteId = ppPageNotFoundPage.PageRouteId;
                site.ErrorPage = tbErrorPage.Text;
                site.GoogleAnalyticsCode = tbGoogleAnalytics.Text;
                site.FacebookAppId = tbFacebookAppId.Text;
                site.FacebookAppSecret = tbFacebookAppSecret.Text;

                var currentDomains = tbSiteDomains.Text.SplitDelimitedValues().ToList<string>();
                site.SiteDomains = site.SiteDomains ?? new List<SiteDomain>();

                // Remove any deleted domains
                foreach ( var domain in site.SiteDomains.Where( w => !currentDomains.Contains( w.Domain ) ).ToList() )
                {
                    site.SiteDomains.Remove( domain );
                    siteDomainService.Delete( domain );
                }

                foreach ( string domain in currentDomains )
                {
                    SiteDomain sd = site.SiteDomains.Where( d => d.Domain == domain ).FirstOrDefault();
                    if ( sd == null )
                    {
                        sd = new SiteDomain();
                        sd.Domain = domain;
                        sd.Guid = Guid.NewGuid();
                        site.SiteDomains.Add( sd );
                    }
                }

                if ( !site.DefaultPageId.HasValue && !newSite )
                {
                    ppDefaultPage.ShowErrorMessage( "Default Page is required." );
                    return;
                }

                if ( !site.IsValid )
                {
                    // Controls will render the error messages
                    return;
                }

                rockContext.WrapTransaction( () =>
                {
                    rockContext.SaveChanges();

                    if ( newSite )
                    {
                        Rock.Security.Authorization.CopyAuthorization( RockPage.Layout.Site, site, rockContext );
                    }
                } );

                SiteCache.Flush( site.Id );

                // Create the default page is this is a new site
                if ( !site.DefaultPageId.HasValue && newSite )
                {
                    var siteCache = SiteCache.Read( site.Id );

                    // Create the layouts for the site, and find the first one
                    LayoutService.RegisterLayouts( Request.MapPath( "~" ), siteCache );

                    var layoutService = new LayoutService( rockContext );
                    var layouts = layoutService.GetBySiteId( siteCache.Id );
                    Layout layout = layouts.FirstOrDefault( l => l.FileName.Equals( "FullWidth", StringComparison.OrdinalIgnoreCase ) );
                    if ( layout == null )
                    {
                        layout = layouts.FirstOrDefault();
                    }
                    if ( layout != null )
                    {
                        var pageService = new PageService( rockContext );
                        var page = new Page();
                        page.LayoutId = layout.Id;
                        page.PageTitle = siteCache.Name + " Home Page";
                        page.InternalName = page.PageTitle;
                        page.BrowserTitle = page.PageTitle;
                        page.EnableViewState = true;
                        page.IncludeAdminFooter = true;
                        page.MenuDisplayChildPages = true;

                        var lastPage = pageService.GetByParentPageId( null ).
                            OrderByDescending( b => b.Order ).FirstOrDefault();

                        page.Order = lastPage != null ? lastPage.Order + 1 : 0;
                        pageService.Add( page );

                        rockContext.SaveChanges();

                        site = siteService.Get( siteCache.Id );
                        site.DefaultPageId = page.Id;

                        rockContext.SaveChanges();

                        SiteCache.Flush( site.Id );
                    }
                }

                var qryParams = new Dictionary<string, string>();
                qryParams["siteId"] = site.Id.ToString();

                NavigateToPage( RockPage.Guid, qryParams );
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Site site;

            if (Page.IsValid)
            {
                var               rockContext       = new RockContext();
                PageService       pageService       = new PageService(rockContext);
                SiteService       siteService       = new SiteService(rockContext);
                SiteDomainService siteDomainService = new SiteDomainService(rockContext);
                bool              newSite           = false;

                int siteId = hfSiteId.Value.AsInteger();

                if (siteId == 0)
                {
                    newSite = true;
                    site    = new Rock.Model.Site();
                    siteService.Add(site);
                }
                else
                {
                    site = siteService.Get(siteId);
                }

                site.Name                      = tbSiteName.Text;
                site.Description               = tbDescription.Text;
                site.Theme                     = ddlTheme.Text;
                site.DefaultPageId             = ppDefaultPage.PageId;
                site.DefaultPageRouteId        = ppDefaultPage.PageRouteId;
                site.LoginPageId               = ppLoginPage.PageId;
                site.LoginPageRouteId          = ppLoginPage.PageRouteId;
                site.ChangePasswordPageId      = ppChangePasswordPage.PageId;
                site.ChangePasswordPageRouteId = ppChangePasswordPage.PageRouteId;
                site.CommunicationPageId       = ppCommunicationPage.PageId;
                site.CommunicationPageRouteId  = ppCommunicationPage.PageRouteId;
                site.RegistrationPageId        = ppRegistrationPage.PageId;
                site.RegistrationPageRouteId   = ppRegistrationPage.PageRouteId;
                site.PageNotFoundPageId        = ppPageNotFoundPage.PageId;
                site.PageNotFoundPageRouteId   = ppPageNotFoundPage.PageRouteId;
                site.ErrorPage                 = tbErrorPage.Text;
                site.GoogleAnalyticsCode       = tbGoogleAnalytics.Text;
                site.RequiresEncryption        = cbRequireEncryption.Checked;
                site.EnabledForShortening      = cbEnableForShortening.Checked;
                site.EnableMobileRedirect      = cbEnableMobileRedirect.Checked;
                site.MobilePageId              = ppMobilePage.PageId;
                site.ExternalUrl               = tbExternalURL.Text;
                site.AllowedFrameDomains       = tbAllowedFrameDomains.Text;
                site.RedirectTablets           = cbRedirectTablets.Checked;
                site.EnablePageViews           = cbEnablePageViews.Checked;

                site.AllowIndexing         = cbAllowIndexing.Checked;
                site.IsIndexEnabled        = cbEnableIndexing.Checked;
                site.IndexStartingLocation = tbIndexStartingLocation.Text;

                site.PageHeaderContent = cePageHeaderContent.Text;

                int?existingIconId = null;
                if (site.FavIconBinaryFileId != imgSiteIcon.BinaryFileId)
                {
                    existingIconId           = site.FavIconBinaryFileId;
                    site.FavIconBinaryFileId = imgSiteIcon.BinaryFileId;
                }

                int?existingLogoId = null;
                if (site.SiteLogoBinaryFileId != imgSiteLogo.BinaryFileId)
                {
                    existingLogoId            = site.SiteLogoBinaryFileId;
                    site.SiteLogoBinaryFileId = imgSiteLogo.BinaryFileId;
                }

                var currentDomains = tbSiteDomains.Text.SplitDelimitedValues().ToList <string>();
                site.SiteDomains = site.SiteDomains ?? new List <SiteDomain>();

                // Remove any deleted domains
                foreach (var domain in site.SiteDomains.Where(w => !currentDomains.Contains(w.Domain)).ToList())
                {
                    site.SiteDomains.Remove(domain);
                    siteDomainService.Delete(domain);
                }

                int order = 0;
                foreach (string domain in currentDomains)
                {
                    SiteDomain sd = site.SiteDomains.Where(d => d.Domain == domain).FirstOrDefault();
                    if (sd == null)
                    {
                        sd        = new SiteDomain();
                        sd.Domain = domain;
                        sd.Guid   = Guid.NewGuid();
                        site.SiteDomains.Add(sd);
                    }
                    sd.Order = order++;
                }

                if (!site.DefaultPageId.HasValue && !newSite)
                {
                    ppDefaultPage.ShowErrorMessage("Default Page is required.");
                    return;
                }

                if (!site.IsValid)
                {
                    // Controls will render the error messages
                    return;
                }

                rockContext.WrapTransaction(() =>
                {
                    rockContext.SaveChanges();

                    SaveAttributes(new Page().TypeId, "SiteId", site.Id.ToString(), PageAttributesState, rockContext);

                    if (existingIconId.HasValue)
                    {
                        BinaryFileService binaryFileService = new BinaryFileService(rockContext);
                        var binaryFile = binaryFileService.Get(existingIconId.Value);
                        if (binaryFile != null)
                        {
                            // marked the old images as IsTemporary so they will get cleaned up later
                            binaryFile.IsTemporary = true;
                            rockContext.SaveChanges();
                        }
                    }

                    if (existingLogoId.HasValue)
                    {
                        BinaryFileService binaryFileService = new BinaryFileService(rockContext);
                        var binaryFile = binaryFileService.Get(existingLogoId.Value);
                        if (binaryFile != null)
                        {
                            // marked the old images as IsTemporary so they will get cleaned up later
                            binaryFile.IsTemporary = true;
                            rockContext.SaveChanges();
                        }
                    }

                    if (newSite)
                    {
                        Rock.Security.Authorization.CopyAuthorization(RockPage.Layout.Site, site, rockContext, Authorization.EDIT);
                        Rock.Security.Authorization.CopyAuthorization(RockPage.Layout.Site, site, rockContext, Authorization.ADMINISTRATE);
                        Rock.Security.Authorization.CopyAuthorization(RockPage.Layout.Site, site, rockContext, Authorization.APPROVE);
                    }
                });

                // add/update for the InteractionChannel for this site and set the RetentionPeriod
                var interactionChannelService   = new InteractionChannelService(rockContext);
                int channelMediumWebsiteValueId = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.INTERACTIONCHANNELTYPE_WEBSITE.AsGuid()).Id;
                var interactionChannelForSite   = interactionChannelService.Queryable()
                                                  .Where(a => a.ChannelTypeMediumValueId == channelMediumWebsiteValueId && a.ChannelEntityId == site.Id).FirstOrDefault();

                if (interactionChannelForSite == null)
                {
                    interactionChannelForSite = new InteractionChannel();
                    interactionChannelForSite.ChannelTypeMediumValueId = channelMediumWebsiteValueId;
                    interactionChannelForSite.ChannelEntityId          = site.Id;
                    interactionChannelService.Add(interactionChannelForSite);
                }

                interactionChannelForSite.Name = site.Name;
                interactionChannelForSite.RetentionDuration     = nbPageViewRetentionPeriodDays.Text.AsIntegerOrNull();
                interactionChannelForSite.ComponentEntityTypeId = EntityTypeCache.Get <Rock.Model.Page>().Id;

                rockContext.SaveChanges();


                // Create the default page is this is a new site
                if (!site.DefaultPageId.HasValue && newSite)
                {
                    var siteCache = SiteCache.Get(site.Id);

                    // Create the layouts for the site, and find the first one
                    LayoutService.RegisterLayouts(Request.MapPath("~"), siteCache);

                    var    layoutService = new LayoutService(rockContext);
                    var    layouts       = layoutService.GetBySiteId(siteCache.Id);
                    Layout layout        = layouts.FirstOrDefault(l => l.FileName.Equals("FullWidth", StringComparison.OrdinalIgnoreCase));
                    if (layout == null)
                    {
                        layout = layouts.FirstOrDefault();
                    }

                    if (layout != null)
                    {
                        var page = new Page();
                        page.LayoutId              = layout.Id;
                        page.PageTitle             = siteCache.Name + " Home Page";
                        page.InternalName          = page.PageTitle;
                        page.BrowserTitle          = page.PageTitle;
                        page.EnableViewState       = true;
                        page.IncludeAdminFooter    = true;
                        page.MenuDisplayChildPages = true;

                        var lastPage = pageService.GetByParentPageId(null).OrderByDescending(b => b.Order).FirstOrDefault();

                        page.Order = lastPage != null ? lastPage.Order + 1 : 0;
                        pageService.Add(page);

                        rockContext.SaveChanges();

                        site = siteService.Get(siteCache.Id);
                        site.DefaultPageId = page.Id;

                        rockContext.SaveChanges();
                    }
                }

                var qryParams = new Dictionary <string, string>();
                qryParams["siteId"] = site.Id.ToString();

                NavigateToPage(RockPage.Guid, qryParams);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnSave_Click( object sender, EventArgs e )
        {
            Site site;
            SiteDomain sd;
            bool newSite = false;

            using ( new UnitOfWorkScope() )
            {
                SiteService siteService = new SiteService();
                SiteDomainService siteDomainService = new SiteDomainService();

                int siteId = 0;
                if ( !int.TryParse( hfSiteId.Value, out siteId ) )
                {
                    siteId = 0;
                }

                if ( siteId == 0 )
                {
                    newSite = true;
                    site = new Rock.Model.Site();
                    siteService.Add( site, CurrentPersonId );
                }
                else
                {
                    site = siteService.Get( siteId );
                    foreach ( var domain in site.SiteDomains.ToList() )
                    {
                        siteDomainService.Delete( domain, CurrentPersonId );
                    }

                    site.SiteDomains.Clear();
                }

                site.Name = tbSiteName.Text;
                site.Description = tbDescription.Text;
                site.Theme = ddlTheme.Text;
                site.DefaultPageId = int.Parse( ddlDefaultPage.SelectedValue );

                foreach ( string domain in tbSiteDomains.Text.SplitDelimitedValues() )
                {
                    sd = new SiteDomain();
                    sd.Domain = domain;
                    sd.Guid = Guid.NewGuid();
                    site.SiteDomains.Add( sd );
                }

                site.FaviconUrl = tbFaviconUrl.Text;
                site.AppleTouchIconUrl = tbAppleTouchIconUrl.Text;
                site.FacebookAppId = tbFacebookAppId.Text;
                site.FacebookAppSecret = tbFacebookAppSecret.Text;

                if ( !site.IsValid )
                {
                    // Controls will render the error messages
                    return;
                }

                siteService.Save( site, CurrentPersonId );

                if ( newSite )
                {
                    Rock.Security.Authorization.CopyAuthorization( CurrentPage.Site, site, CurrentPersonId );
                }

                SiteCache.Flush( site.Id );

                BindGrid();

                pnlDetails.Visible = false;
                pnlList.Visible = true;
            }
        }
Exemplo n.º 15
0
        public ActionResult EditSiteDomain(SiteDomainModel model)
        {
            TryUpdateModel(model);

            if (ModelState.IsValid)
            {
                var siteDomain = new SiteDomain
                {
                    Description = model.Description,
                    Language = model.Language ?? string.Empty,
                    PropertyType = model.PropertyType,
                    SiteDomainID = model.SiteDomainID
                };

                siteDomain.Set();
            }

            return RedirectToAction("SiteBranding");
        }
Exemplo n.º 16
0
        public ActionResult EditSiteDomain(int? siteDomainID)
        {
            var model = new SiteDomainModel();

            if (siteDomainID != null)
            {
                var siteDomain = new SiteDomain(Convert.ToInt32(siteDomainID));

                model.Description = siteDomain.Description;
                model.Language = siteDomain.Language;
                model.PropertyType = siteDomain.PropertyType;
                model.SiteDomainID = siteDomain.SiteDomainID;
            }

            return View(model);
        }
Exemplo n.º 17
0
        public ActionResult DeleteSiteDomain(int? siteDomainID)
        {
            if (siteDomainID != null)
            {
                var siteDomain = new SiteDomain(Convert.ToInt32(siteDomainID));

                siteDomain.Delete();
            }

            return RedirectToAction("SiteBranding");
        }
Exemplo n.º 18
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Site site;

            if (Page.IsValid)
            {
                var               rockContext       = new RockContext();
                SiteService       siteService       = new SiteService(rockContext);
                SiteDomainService siteDomainService = new SiteDomainService(rockContext);
                bool              newSite           = false;

                int siteId = hfSiteId.Value.AsInteger();

                if (siteId == 0)
                {
                    newSite = true;
                    site    = new Rock.Model.Site();
                    siteService.Add(site);
                }
                else
                {
                    site = siteService.Get(siteId);
                }

                site.Name                        = tbSiteName.Text;
                site.Description                 = tbDescription.Text;
                site.Theme                       = ddlTheme.Text;
                site.DefaultPageId               = ppDefaultPage.PageId;
                site.DefaultPageRouteId          = ppDefaultPage.PageRouteId;
                site.LoginPageId                 = ppLoginPage.PageId;
                site.LoginPageRouteId            = ppLoginPage.PageRouteId;
                site.ChangePasswordPageId        = ppChangePasswordPage.PageId;
                site.ChangePasswordPageRouteId   = ppChangePasswordPage.PageRouteId;
                site.CommunicationPageId         = ppCommunicationPage.PageId;
                site.CommunicationPageRouteId    = ppCommunicationPage.PageRouteId;
                site.RegistrationPageId          = ppRegistrationPage.PageId;
                site.RegistrationPageRouteId     = ppRegistrationPage.PageRouteId;
                site.PageNotFoundPageId          = ppPageNotFoundPage.PageId;
                site.PageNotFoundPageRouteId     = ppPageNotFoundPage.PageRouteId;
                site.ErrorPage                   = tbErrorPage.Text;
                site.GoogleAnalyticsCode         = tbGoogleAnalytics.Text;
                site.RequiresEncryption          = cbRequireEncryption.Checked;
                site.EnableMobileRedirect        = cbEnableMobileRedirect.Checked;
                site.MobilePageId                = ppMobilePage.PageId;
                site.ExternalUrl                 = tbExternalURL.Text;
                site.AllowedFrameDomains         = tbAllowedFrameDomains.Text;
                site.RedirectTablets             = cbRedirectTablets.Checked;
                site.EnablePageViews             = cbEnablePageViews.Checked;
                site.PageViewRetentionPeriodDays = nbPageViewRetentionPeriodDays.Text.AsIntegerOrNull();

                site.AllowIndexing     = cbAllowIndexing.Checked;
                site.PageHeaderContent = cePageHeaderContent.Text;

                var currentDomains = tbSiteDomains.Text.SplitDelimitedValues().ToList <string>();
                site.SiteDomains = site.SiteDomains ?? new List <SiteDomain>();

                // Remove any deleted domains
                foreach (var domain in site.SiteDomains.Where(w => !currentDomains.Contains(w.Domain)).ToList())
                {
                    site.SiteDomains.Remove(domain);
                    siteDomainService.Delete(domain);
                }

                foreach (string domain in currentDomains)
                {
                    SiteDomain sd = site.SiteDomains.Where(d => d.Domain == domain).FirstOrDefault();
                    if (sd == null)
                    {
                        sd        = new SiteDomain();
                        sd.Domain = domain;
                        sd.Guid   = Guid.NewGuid();
                        site.SiteDomains.Add(sd);
                    }
                }

                if (!site.DefaultPageId.HasValue && !newSite)
                {
                    ppDefaultPage.ShowErrorMessage("Default Page is required.");
                    return;
                }

                if (!site.IsValid)
                {
                    // Controls will render the error messages
                    return;
                }

                rockContext.WrapTransaction(() =>
                {
                    rockContext.SaveChanges();

                    if (newSite)
                    {
                        Rock.Security.Authorization.CopyAuthorization(RockPage.Layout.Site, site, rockContext, Authorization.EDIT);
                        Rock.Security.Authorization.CopyAuthorization(RockPage.Layout.Site, site, rockContext, Authorization.ADMINISTRATE);
                        Rock.Security.Authorization.CopyAuthorization(RockPage.Layout.Site, site, rockContext, Authorization.APPROVE);
                    }
                });

                SiteCache.Flush(site.Id);

                // Create the default page is this is a new site
                if (!site.DefaultPageId.HasValue && newSite)
                {
                    var siteCache = SiteCache.Read(site.Id);

                    // Create the layouts for the site, and find the first one
                    LayoutService.RegisterLayouts(Request.MapPath("~"), siteCache);

                    var    layoutService = new LayoutService(rockContext);
                    var    layouts       = layoutService.GetBySiteId(siteCache.Id);
                    Layout layout        = layouts.FirstOrDefault(l => l.FileName.Equals("FullWidth", StringComparison.OrdinalIgnoreCase));
                    if (layout == null)
                    {
                        layout = layouts.FirstOrDefault();
                    }

                    if (layout != null)
                    {
                        var pageService = new PageService(rockContext);
                        var page        = new Page();
                        page.LayoutId              = layout.Id;
                        page.PageTitle             = siteCache.Name + " Home Page";
                        page.InternalName          = page.PageTitle;
                        page.BrowserTitle          = page.PageTitle;
                        page.EnableViewState       = true;
                        page.IncludeAdminFooter    = true;
                        page.MenuDisplayChildPages = true;

                        var lastPage = pageService.GetByParentPageId(null).OrderByDescending(b => b.Order).FirstOrDefault();

                        page.Order = lastPage != null ? lastPage.Order + 1 : 0;
                        pageService.Add(page);

                        rockContext.SaveChanges();

                        site = siteService.Get(siteCache.Id);
                        site.DefaultPageId = page.Id;

                        rockContext.SaveChanges();

                        SiteCache.Flush(site.Id);
                    }
                }

                var qryParams = new Dictionary <string, string>();
                qryParams["siteId"] = site.Id.ToString();

                NavigateToPage(RockPage.Guid, qryParams);
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Site       site;
            SiteDomain sd;
            bool       newSite = false;

            using (new UnitOfWorkScope())
            {
                SiteService       siteService       = new SiteService();
                SiteDomainService siteDomainService = new SiteDomainService();

                int siteId = 0;
                if (!int.TryParse(hfSiteId.Value, out siteId))
                {
                    siteId = 0;
                }

                if (siteId == 0)
                {
                    newSite = true;
                    site    = new Rock.Model.Site();
                    siteService.Add(site, CurrentPersonId);
                }
                else
                {
                    site = siteService.Get(siteId);
                    foreach (var domain in site.SiteDomains.ToList())
                    {
                        siteDomainService.Delete(domain, CurrentPersonId);
                    }

                    site.SiteDomains.Clear();
                }

                site.Name          = tbSiteName.Text;
                site.Description   = tbDescription.Text;
                site.Theme         = ddlTheme.Text;
                site.DefaultPageId = int.Parse(ddlDefaultPage.SelectedValue);

                foreach (string domain in tbSiteDomains.Text.SplitDelimitedValues())
                {
                    sd        = new SiteDomain();
                    sd.Domain = domain;
                    sd.Guid   = Guid.NewGuid();
                    site.SiteDomains.Add(sd);
                }

                site.FaviconUrl        = tbFaviconUrl.Text;
                site.AppleTouchIconUrl = tbAppleTouchIconUrl.Text;
                site.FacebookAppId     = tbFacebookAppId.Text;
                site.FacebookAppSecret = tbFacebookAppSecret.Text;

                if (!site.IsValid)
                {
                    // Controls will render the error messages
                    return;
                }

                siteService.Save(site, CurrentPersonId);

                if (newSite)
                {
                    Rock.Security.Authorization.CopyAuthorization(CurrentPage.Site, site, CurrentPersonId);
                }

                SiteCache.Flush(site.Id);

                BindGrid();

                pnlDetails.Visible = false;
                pnlList.Visible    = true;
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            using (new Rock.Data.UnitOfWorkScope())
            {
                Site              site;
                SiteService       siteService       = new SiteService();
                SiteDomainService siteDomainService = new SiteDomainService();
                bool              newSite           = false;

                int siteId = int.Parse(hfSiteId.Value);

                if (siteId == 0)
                {
                    newSite = true;
                    site    = new Rock.Model.Site();
                    siteService.Add(site, CurrentPersonId);
                }
                else
                {
                    site = siteService.Get(siteId);
                }

                site.Name               = tbSiteName.Text;
                site.Description        = tbDescription.Text;
                site.Theme              = ddlTheme.Text;
                site.DefaultPageId      = int.Parse(ppDefaultPage.SelectedValue);
                site.LoginPageReference = tbLoginPageReference.Text;

                var currentDomains = tbSiteDomains.Text.SplitDelimitedValues().ToList <string>();
                site.SiteDomains = site.SiteDomains ?? new List <SiteDomain>();

                // Remove any deleted domains
                foreach (var domain in site.SiteDomains.Where(w => !currentDomains.Contains(w.Domain)).ToList())
                {
                    site.SiteDomains.Remove(domain);
                    siteDomainService.Delete(domain, CurrentPersonId);
                }

                foreach (string domain in currentDomains)
                {
                    SiteDomain sd = site.SiteDomains.Where(d => d.Domain == domain).FirstOrDefault();
                    if (sd == null)
                    {
                        sd        = new SiteDomain();
                        sd.Domain = domain;
                        sd.Guid   = Guid.NewGuid();
                        site.SiteDomains.Add(sd);
                    }
                }

                site.FaviconUrl                = tbFaviconUrl.Text;
                site.AppleTouchIconUrl         = tbAppleTouchIconUrl.Text;
                site.FacebookAppId             = tbFacebookAppId.Text;
                site.FacebookAppSecret         = tbFacebookAppSecret.Text;
                site.RegistrationPageReference = tbRegistrationPageReference.Text;
                site.ErrorPage = tbErrorPage.Text;

                if (!site.IsValid)
                {
                    // Controls will render the error messages
                    return;
                }

                RockTransactionScope.WrapTransaction(() =>
                {
                    siteService.Save(site, CurrentPersonId);

                    if (newSite)
                    {
                        Rock.Security.Authorization.CopyAuthorization(CurrentPage.Site, site, CurrentPersonId);
                    }
                });

                SiteCache.Flush(site.Id);
            }

            NavigateToParentPage();
        }
Exemplo n.º 21
0
        public ActionResult EditSiteDomain(SiteDomainModel model)
        {
            TryUpdateModel(model);

            if (ModelState.IsValid)
            {
                SiteDomain siteDomain = new SiteDomain();

                siteDomain.Description = model.Description;
                siteDomain.Language = ( model.Language == null) ? string.Empty : model.Language;
                siteDomain.PropertyType = model.PropertyType;
                siteDomain.SiteDomainID = model.SiteDomainID;

                siteDomain.Set();
            }

            return RedirectToAction("SiteBranding");
        }
Exemplo n.º 22
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Site site;

            if (Page.IsValid)
            {
                using (new Rock.Data.UnitOfWorkScope())
                {
                    SiteService       siteService       = new SiteService();
                    SiteDomainService siteDomainService = new SiteDomainService();
                    bool newSite = false;

                    int siteId = int.Parse(hfSiteId.Value);

                    if (siteId == 0)
                    {
                        newSite = true;
                        site    = new Rock.Model.Site();
                        siteService.Add(site, CurrentPersonId);
                    }
                    else
                    {
                        site = siteService.Get(siteId);
                    }

                    site.Name                    = tbSiteName.Text;
                    site.Description             = tbDescription.Text;
                    site.Theme                   = ddlTheme.Text;
                    site.DefaultPageId           = ppDefaultPage.PageId;
                    site.DefaultPageRouteId      = ppDefaultPage.PageRouteId;
                    site.LoginPageId             = ppLoginPage.PageId;
                    site.LoginPageRouteId        = ppLoginPage.PageRouteId;
                    site.RegistrationPageId      = ppRegistrationPage.PageId;
                    site.RegistrationPageRouteId = ppRegistrationPage.PageRouteId;
                    site.PageNotFoundPageId      = ppPageNotFoundPage.PageId;
                    site.PageNotFoundPageRouteId = ppPageNotFoundPage.PageRouteId;
                    site.ErrorPage               = tbErrorPage.Text;
                    site.GoogleAnalyticsCode     = tbGoogleAnalytics.Text;
                    site.FacebookAppId           = tbFacebookAppId.Text;
                    site.FacebookAppSecret       = tbFacebookAppSecret.Text;

                    var currentDomains = tbSiteDomains.Text.SplitDelimitedValues().ToList <string>();
                    site.SiteDomains = site.SiteDomains ?? new List <SiteDomain>();

                    // Remove any deleted domains
                    foreach (var domain in site.SiteDomains.Where(w => !currentDomains.Contains(w.Domain)).ToList())
                    {
                        site.SiteDomains.Remove(domain);
                        siteDomainService.Delete(domain, CurrentPersonId);
                    }

                    foreach (string domain in currentDomains)
                    {
                        SiteDomain sd = site.SiteDomains.Where(d => d.Domain == domain).FirstOrDefault();
                        if (sd == null)
                        {
                            sd        = new SiteDomain();
                            sd.Domain = domain;
                            sd.Guid   = Guid.NewGuid();
                            site.SiteDomains.Add(sd);
                        }
                    }

                    if (!site.DefaultPageId.HasValue && !newSite)
                    {
                        ppDefaultPage.ShowErrorMessage("Default Page is required.");
                        return;
                    }

                    if (!site.IsValid)
                    {
                        // Controls will render the error messages
                        return;
                    }

                    RockTransactionScope.WrapTransaction(() =>
                    {
                        siteService.Save(site, CurrentPersonId);

                        if (newSite)
                        {
                            Rock.Security.Authorization.CopyAuthorization(RockPage.Layout.Site, site, CurrentPersonId);
                        }
                    });

                    SiteCache.Flush(site.Id);

                    // Create the default page is this is a new site
                    if (!site.DefaultPageId.HasValue && newSite)
                    {
                        var siteCache = SiteCache.Read(site.Id);

                        // Create the layouts for the site, and find the first one
                        var layoutService = new LayoutService();
                        layoutService.RegisterLayouts(Request.MapPath("~"), siteCache, CurrentPersonId);

                        var    layouts = layoutService.GetBySiteId(siteCache.Id);
                        Layout layout  = layouts.FirstOrDefault(l => l.FileName.Equals("FullWidth", StringComparison.OrdinalIgnoreCase));
                        if (layout == null)
                        {
                            layout = layouts.FirstOrDefault();
                        }
                        if (layout != null)
                        {
                            var pageService = new PageService();
                            var page        = new Page();
                            page.LayoutId              = layout.Id;
                            page.PageTitle             = siteCache.Name + " Home Page";
                            page.InternalName          = page.PageTitle;
                            page.BrowserTitle          = page.PageTitle;
                            page.EnableViewState       = true;
                            page.IncludeAdminFooter    = true;
                            page.MenuDisplayChildPages = true;

                            var lastPage = pageService.GetByParentPageId(null).
                                           OrderByDescending(b => b.Order).FirstOrDefault();

                            page.Order = lastPage != null ? lastPage.Order + 1 : 0;
                            pageService.Add(page, CurrentPersonId);
                            pageService.Save(page, CurrentPersonId);

                            site = siteService.Get(siteCache.Id);
                            site.DefaultPageId = page.Id;
                            siteService.Save(site, CurrentPersonId);

                            SiteCache.Flush(site.Id);
                        }
                    }
                }

                var qryParams = new Dictionary <string, string>();
                qryParams["siteId"] = site.Id.ToString();

                NavigateToPage(RockPage.Guid, qryParams);
            }
        }
Exemplo n.º 23
0
        /// <summary>
        /// 切换域名记录的CDN供应商
        /// </summary>
        /// <param name="recordId">域名记录</param>
        /// <param name="type">CDN供应商</param>
        /// <param name="cname">自定义的别名记录</param>
        /// <returns></returns>
        public bool UpdateCDNProvider(int recordId, CDNProviderType type, string cname)
        {
            DomainRecord record = this.GetRecordInfo(recordId);

            if (record == null)
            {
                return(this.FaildMessage("域名记录错误"));
            }
            if (type == CDNProviderType.Manual && string.IsNullOrEmpty(cname))
            {
                return(this.FaildMessage("请手动设置CDN别名"));
            }
            if (!IsCDNProvider(type))
            {
                return(this.FaildMessage("当前不支持该供应商"));
            }

            SiteDomain domain = this.ReadDB.ReadInfo <SiteDomain>(t => t.ID == record.DomainID);

            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                bool isExists = db.Exists <DomainCDN>(t => t.RecordID == recordId && t.CDNType == type);
                switch (type)
                {
                case CDNProviderType.Manual:
                {
                    if (isExists)
                    {
                        db.Update(new DomainCDN()
                            {
                                Status = DomainCDN.CDNStatus.Finish,
                                CName  = cname
                            }, t => t.RecordID == recordId && t.CDNType == type, t => t.Status, t => t.CName);
                    }
                    else
                    {
                        new DomainCDN()
                        {
                            RecordID = recordId,
                            CName    = cname,
                            Status   = DomainCDN.CDNStatus.Finish,
                            CDNType  = type
                        }.Add(db);
                    }

                    record.Status = DomainRecord.RecordStatus.Finish;

                    db.AddCallback(() =>
                        {
                            // 调用DNS供应商的接口,设定记录的别名指向到此处手动设定的CDN别名地址
                        });
                }
                break;

                default:
                {
                    if (isExists)
                    {
                        db.Update(new DomainCDN()
                            {
                                Status = DomainCDN.CDNStatus.Wait
                            }, t => t.RecordID == recordId && t.CDNType == type, t => t.Status);
                    }
                    else
                    {
                        new DomainCDN()
                        {
                            RecordID = recordId,
                            Status   = DomainCDN.CDNStatus.Wait,
                            CDNType  = type
                        }.Add(db);
                    }
                    record.Status = DomainRecord.RecordStatus.Wait;
                }
                break;
                }

                record.CDNType = type;
                record.Update(db, t => t.Status, t => t.CDNType);

                db.Commit();
            }
            return(this.AccountInfo.Log(LogType.Site, $"设定域名{record.SubName}.{domain.Domain}的CDN供应商为:{type.GetDescription()}"));
        }