public void DiskSyncUpdate(ApiCall call) { Data.Models.WebSite website = null; Guid SiteId = call.GetGuidValue("SiteId"); website = Kooboo.Data.GlobalDb.WebSites.Get(SiteId); if (SiteId == default(Guid) || website == null) { return; } bool enable = call.GetBoolValue("EnableDiskSync"); string path = call.GetValue("localpath"); bool hasSamePath = Lib.Helper.StringHelper.IsSameValue(website.DiskSyncFolder, path); if (website.EnableDiskSync != enable || Lib.Helper.StringHelper.IsSameValue(website.DiskSyncFolder, path) == false) { website.EnableDiskSync = enable; website.DiskSyncFolder = path; GlobalDb.WebSites.AddOrUpdate(website); } if (enable) { // init disk.. if (!hasSamePath) { } WebSiteService.InitDiskSync(website, true); } }
public List <SimpleSiteItemViewModel> SiteList(ApiCall call) { User user = call.Context.User; if (user == null) { return(null); } var orgid = call.GetValue <Guid>("OrganizationId"); if (orgid == default(Guid)) { orgid = user.CurrentOrgId; } var sites = WebSiteService.RemoteListByUser(user.Id, orgid); List <SimpleSiteItemViewModel> result = new List <SimpleSiteItemViewModel>(); foreach (var item in sites) { var lastversion = item.SiteDb().Log.Store.LastKey; result.Add(new SimpleSiteItemViewModel { Id = item.Id, Name = item.Name, LastVersion = lastversion }); } return(result); }
public void Setup() { _webSiteRepository = Substitute.For <IRepository <WebSite> >(); _webSiteManagerData = Substitute.For <IWebSiteManagerData>(); _passwordEncryptor = Substitute.For <IPasswordEncryptor>(); _webSiteService = new WebSiteService(_webSiteManagerData, _passwordEncryptor); }
public void Post(ApiCall call) { var siteid = call.GetValue <Guid>("siteid"); var currentsite = Kooboo.Data.GlobalDb.WebSites.Get(siteid); bool shouldinitDisk = false; if (currentsite != null) { var newinfo = call.Context.Request.Model as SiteUpdate; if (!currentsite.EnableDiskSync && newinfo.EnableDiskSync) { shouldinitDisk = true; } currentsite.DiskSyncFolder = newinfo.DiskSyncFolder; currentsite.DisplayName = newinfo.DisplayName; currentsite.EnableVisitorLog = newinfo.EnableVisitorLog; currentsite.EnableConstraintFixOnSave = newinfo.EnableConstraintFixOnSave; currentsite.EnableFrontEvents = newinfo.EnableFrontEvents; currentsite.EnableDiskSync = newinfo.EnableDiskSync; currentsite.EnableMultilingual = newinfo.EnableMultilingual; currentsite.CustomSettings = newinfo.CustomSettings; currentsite.Culture = newinfo.Culture; currentsite.SitePath = newinfo.SitePath; currentsite.EnableSitePath = newinfo.EnableSitePath; currentsite.DefaultCulture = newinfo.DefaultCulture; currentsite.AutoDetectCulture = newinfo.AutoDetectCulture; currentsite.ForceSSL = newinfo.ForceSSL; currentsite.EnableJsCssBrowerCache = newinfo.EnableJsCssBrowerCache; currentsite.EnableImageBrowserCache = newinfo.EnableImageBrowserCache; currentsite.ImageCacheDays = newinfo.ImageCacheDays; currentsite.EnableSPA = newinfo.EnableSPA; currentsite.EnableVideoBrowserCache = newinfo.EnableVideoBrowserCache; currentsite.EnableJsCssCompress = newinfo.EnableJsCssCompress; currentsite.SiteType = newinfo.SiteType; currentsite.EnableCORS = newinfo.EnableCORS; currentsite.EnableSqlLog = newinfo.EnableSqlLog; currentsite.PreviewUrl = newinfo.PreviewUrl; // the cluster... GlobalDb.WebSites.AddOrUpdate(currentsite); } if (shouldinitDisk) { WebSiteService.InitDiskSync(currentsite, true); } }
public async void CheckUserBandwidth(FrontContext frontContext) { bool shouldcheck = false; if (frontContext.RenderContext.Response.StatusCode == 200) { if (Data.AppSettings.IsOnlineServer) { shouldcheck = true; } #if DEBUG shouldcheck = true; #endif } if (shouldcheck) { long length = frontContext.RenderContext.Response.OrginalLength; if (length == 0) { if (frontContext.RenderContext.Response.Body != null) { length = frontContext.RenderContext.Response.Body.Length; } } if (length == 0) { if (frontContext.RenderContext.Response.Stream != null) { length = frontContext.RenderContext.Response.Stream.Length; } } if (length > 0) { var orgid = frontContext.RenderContext.WebSite.OrganizationId; var testok = Kooboo.Data.Infrastructure.InfraManager.Test(orgid, Data.Infrastructure.InfraType.Bandwidth, length); if (!testok) { frontContext.RenderContext.Response.StatusCode = 402; var errorbody = await WebSiteService.RenderCustomError(frontContext, 402); if (!string.IsNullOrWhiteSpace(errorbody)) { frontContext.RenderContext.Response.Body = System.Text.Encoding.UTF8.GetBytes(errorbody); } } else { string url = frontContext.RenderContext.Request.Host + frontContext.RenderContext.Request.RawRelativeUrl; Kooboo.Data.Infrastructure.InfraManager.Add(orgid, Data.Infrastructure.InfraType.Bandwidth, length, url); } } } }
public bool Delete(ApiCall call) { Guid SiteId = call.GetGuidValue("SiteId"); if (SiteId == default(Guid) && call.ObjectId != default(Guid)) { SiteId = call.ObjectId; } if (SiteId != default(Guid)) { WebSiteService.Delete(SiteId, call.Context.User); return(true); } return(false); }
public PageDefaultRouteViewModel DefaultRoute(ApiCall call) { PageDefaultRouteViewModel model = new PageDefaultRouteViewModel(); var startpages = call.WebSite.StartPages(); if (startpages != null && startpages.Count() > 0) { model.StartPage = startpages.First().Id; } var pagenotfound = WebSiteService.GetCustomErrorUrl(call.WebSite, 404); Guid PageNotFoundId = default(Guid); if (!string.IsNullOrEmpty(pagenotfound)) { if (!Guid.TryParse(pagenotfound, out PageNotFoundId)) { var DbPageNotFound = call.WebSite.SiteDb().Pages.GetByUrl(pagenotfound); if (DbPageNotFound != null) { PageNotFoundId = DbPageNotFound.Id; } } } var pageerror = WebSiteService.GetCustomErrorUrl(call.WebSite, 500); Guid PageErrorId = default(Guid); if (!string.IsNullOrEmpty(pageerror)) { if (!Guid.TryParse(pageerror, out PageErrorId)) { var DbPageError = call.WebSite.SiteDb().Pages.GetByUrl(pageerror); if (DbPageError != null) { PageErrorId = DbPageError.Id; } } } model.NotFound = PageNotFoundId; model.Error = PageErrorId; return(model); }
public virtual bool Deletes(ApiCall call) { string json = call.GetValue("ids"); if (string.IsNullOrEmpty(json)) { json = call.Context.Request.Body; } List<Guid> ids = Lib.Helper.JsonHelper.Deserialize<List<Guid>>(json); if (ids != null && ids.Count() > 0) { foreach (var item in ids) { WebSiteService.Delete(item, call.Context.User); } return true; } return false; }
public async Task Invoke(RenderContext context) { FrontContext kooboocontext = new FrontContext(context); if (context.WebSite != null) { if (!Kooboo.Web.Security.AccessControl.HasWebsiteAccess(context.WebSite, context)) { if (!CheckIsBackEndOrImageUrl(kooboocontext.RenderContext.Request.RelativeUrl)) { if (context.User == null) { context.Response.Redirect(302, "/_admin/account/login?type=site&returnurl=" + System.Web.HttpUtility.UrlEncode(context.Request.RawRelativeUrl)); context.Response.End = true; return; } else { context.Response.Redirect(302, Kooboo.DataConstants.Default403Page); context.Response.End = true; return; } } } if (kooboocontext.RenderContext.IsSiteBinding || !CheckIsBackEndOrImageUrl(kooboocontext.RenderContext.Request.RelativeUrl)) { ObjectRoute.Parse(kooboocontext); if (kooboocontext.Route != null && kooboocontext.Route.objectId != default(Guid)) { await ExecuteKooboo(kooboocontext); return; } } if (kooboocontext.Route == null && !String.IsNullOrEmpty(kooboocontext.WebSite.LocalRootPath)) { await Next.Invoke(context); return; } if (!CheckIsBackEndOrImageUrl(kooboocontext.RenderContext.Request.RelativeUrl)) { if (kooboocontext.Route == null || kooboocontext.Route.objectId == default(Guid)) { if (kooboocontext.SiteDb.WebSite.ContinueDownload) { if (Data.AppSettings.IsOnlineServer && !Kooboo.Web.Security.ActionControl.CanServerDownloadMorePages(kooboocontext.SiteDb, kooboocontext.RenderContext.Request.RelativeUrl)) { kooboocontext.RenderContext.Response.StatusCode = 402; var errorbody = await WebSiteService.RenderCustomError(kooboocontext, 402); if (!string.IsNullOrWhiteSpace(errorbody)) { kooboocontext.RenderContext.Response.Body = System.Text.Encoding.UTF8.GetBytes(errorbody); } return; } else { var continuedownload = await TransferManager.continueDownload(kooboocontext.SiteDb, kooboocontext.RenderContext.Request.RawRelativeUrl); if (continuedownload != null) { ObjectRoute.Parse(kooboocontext); } } } } if (kooboocontext.Route != null && kooboocontext.Route.objectId != default(Guid)) { await ExecuteKooboo(kooboocontext); return; } else { kooboocontext.RenderContext.Response.StatusCode = 404; var errorbody = await WebSiteService.RenderCustomError(kooboocontext, 404); if (!string.IsNullOrWhiteSpace(errorbody)) { kooboocontext.RenderContext.Response.Body = System.Text.Encoding.UTF8.GetBytes(errorbody); } return; } } else { // reensure siteid... in case of the same url used for login. var siteid = Kooboo.Data.Context.WebServerContext.RequestSiteId(context.Request); if (siteid != kooboocontext.RenderContext.WebSite.Id) { var site = Kooboo.Data.GlobalDb.WebSites.Get(siteid); if (site != null) { kooboocontext.WebSite = site; } } } } if (RenderThumbnail(kooboocontext)) { return; } // access control for allow users... await Next.Invoke(context); }
public async Task ExecuteKooboo(FrontContext frontContext) { DateTime endtime = default(DateTime); if (!frontContext.WebSite.Published && frontContext.RenderContext.Request.Channel == Data.Context.RequestChannel.Default) { if ((frontContext.Route != null && frontContext.Route.DestinationConstType == ConstObjectType.Page) || frontContext.RenderContext.User == null) { frontContext.RenderContext.Response.Body = System.Text.Encoding.UTF8.GetBytes("WebSite set to offline"); frontContext.RenderContext.Response.StatusCode = 503; return; } } if (frontContext.RenderContext.Response.StatusCode == 200) { try { await RouteRenderers.RenderAsync(frontContext); endtime = DateTime.UtcNow; // check for rights... CheckUserBandwidth(frontContext); } catch (Exception ex) { Kooboo.Data.Log.Instance.Exception.Write(frontContext.RenderContext.WebSite.Name + " " + frontContext.RenderContext.Request.Url); Kooboo.Data.Log.Instance.Exception.WriteException(ex); frontContext.RenderContext.Response.StatusCode = 500; var errorbody = await WebSiteService.RenderCustomError(frontContext, 500); if (!string.IsNullOrWhiteSpace(errorbody)) { frontContext.RenderContext.Response.Body = System.Text.Encoding.UTF8.GetBytes(errorbody); } frontContext.Log.AddEntry("500", ex.Message, DateTime.UtcNow, DateTime.UtcNow, 500, ex.Message); } } if (frontContext.RenderContext.Response.StatusCode != 200) { if (string.IsNullOrEmpty(frontContext.RenderContext.Response.RedirectLocation)) { var custom = frontContext.RenderContext.GetItem <CustomStatusCode>(); if (custom == null) { frontContext.RenderContext.Response.RedirectLocation = WebSiteService.GetCustomErrorUrl(frontContext.WebSite, frontContext.RenderContext.Response.StatusCode); } } } if (frontContext.WebSite.EnableVisitorLog && frontContext.RenderContext.Request.Channel == Data.Context.RequestChannel.Default) { if (frontContext.Page != null) { string referer = frontContext.RenderContext.Request.Headers.Get("Referer"); if (!string.IsNullOrEmpty(referer)) { frontContext.Log.Referer = referer; } frontContext.Log.Url = frontContext.RenderContext.Request.RawRelativeUrl; frontContext.Log.UserAgent = frontContext.RenderContext.Request.Headers.Get("User-Agent"); frontContext.Log.ClientIP = frontContext.RenderContext.Request.IP; frontContext.Log.Begin = frontContext.StartTime; if (endtime == default(DateTime)) { endtime = DateTime.UtcNow; } frontContext.Log.End = endtime; frontContext.Log.TimeSpan = (endtime - frontContext.StartTime).TotalMilliseconds; frontContext.Log.StatusCode = Convert.ToInt16(frontContext.RenderContext.Response.StatusCode); frontContext.Log.ObjectId = frontContext.Route != null ? frontContext.Route.objectId : default(Guid); if (frontContext.RenderContext.Response.Body != null) { frontContext.Log.Size = frontContext.RenderContext.Response.Body.Length; } frontContext.SiteDb.VisitorLog.Add(frontContext.Log); } if (frontContext.RenderContext.Response.StatusCode != 200) { var log = new Data.Models.SiteErrorLog(); log.ClientIP = frontContext.RenderContext.Request.IP; log.Url = frontContext.RenderContext.Request.RawRelativeUrl; log.StatusCode = frontContext.RenderContext.Response.StatusCode; frontContext.SiteDb.ErrorLog.Add(log); } } }
public WebSiteController(WebSiteService WebSite) { _WebSite = WebSite; }
public WebSiteServiceTests() { this.webSiteMockRepository = new Mock <IWebSiteRepository>(); this.webSiteService = new WebSiteService(this.webSiteMockRepository.Object); }