Пример #1
0
        public void App_BeginRequest(object sender, EventArgs e)
        {
            var context = HttpContext.Current;

            if (context == null)
            {
                return;
            }

            string domain = DbConvention.GetDomain();

            Log.Verbose($"Got a {context.Request.HttpMethod} request {context.Request.AppRelativeCurrentExecutionFilePath} on domain {domain}.");

            bool enforceSsl = DbConvention.EnforceSsl(domain);

            if (!enforceSsl)
            {
                Log.Verbose($"SSL was not enforced on domain {domain}.");
                return;
            }

            if (context.Request.Url.Scheme == "https")
            {
                context.Response.AddHeader("Strict-Transport-Security", "max-age=31536000");
            }
            else if (context.Request.Url.Scheme == "http")
            {
                string path = "https://" + context.Request.Url.Host +
                              context.Request.Url.PathAndQuery;
                context.Response.Status = "301 Moved Permanently";
                context.Response.AddHeader("Location", path);
            }
        }
Пример #2
0
        public ActionResult Index()
        {
            string domain = DbConvention.GetDomain();

            var approved  = new DomainSerializer("domains-approved.json");
            var installed = new DomainSerializer("domains-installed.json");

            if (!approved.Get().Contains(domain))
            {
                return(this.HttpNotFound());
            }

            if (installed.Get().Contains(domain))
            {
                return(this.Redirect("/"));
            }

            InstallationFactory.Setup(domain); //Background job
            return(this.Content("Installing frapid, please visit the site after a few minutes."));
        }
Пример #3
0
        public static string ToCanonicalUrl(string url = "")
        {
            if (string.IsNullOrWhiteSpace(url))
            {
                url = HttpContext.Current.Request.Url.PathAndQuery;
            }

            string domain   = DbConvention.GetDomain();
            var    approved = new DomainSerializer("DomainsApproved.json");
            var    tenant   = approved.Get().FirstOrDefault(x => x.GetSubtenants().Contains(domain.ToLowerInvariant()));

            if (tenant != null)
            {
                string protocol   = HttpContext.Current.Request.IsSecureConnection ? "https://" : "http://";
                string domainName = protocol + tenant.DomainName;
                url = UrlHelper.CombineUrl(domainName, url);
                return(url);
            }

            return(string.Empty);
        }
Пример #4
0
        public ActionResult Index()
        {
            string domain = DbConvention.GetDomain();

            var approved  = new DomainSerializer("DomainsApproved.json");
            var installed = new DomainSerializer("DomainsInstalled.json");

            if (!approved.GetTenantMembers().Any(x => x.Equals(domain)))
            {
                return(this.HttpNotFound());
            }

            if (installed.GetTenantMembers().Any(x => x.Equals(domain)))
            {
                return(this.Redirect("/"));
            }

            var setup = approved.Get().FirstOrDefault(x => x.GetSubtenants().Contains(domain.ToLowerInvariant()));

            InstallationFactory.Setup(setup); //Background job
            return(this.Content("Installing frapid, please visit the site after a few minutes."));
        }
        protected ActionResult OnAuthenticated(LoginResult result, SignInInfo model = null)
        {
            if (!result.Status)
            {
                Thread.Sleep(new Random().Next(1, 5) * 1000);
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden, JsonConvert.SerializeObject(result)));
            }

            Guid?applicationId = null;

            if (model != null)
            {
                applicationId = model.ApplicationId;
            }

            var    manager = new Provider(AppUsers.GetCatalog(), applicationId, result.LoginId);
            var    token   = manager.GetToken();
            string domain  = DbConvention.GetDomain();

            AccessTokens.Save(token, this.RemoteUser.IpAddress, this.RemoteUser.UserAgent);

            var cookie = new HttpCookie("access_token")
            {
                Value    = token.ClientToken,
                HttpOnly = true,
                Secure   = true,
                Expires  = token.ExpiresOn
            };

            //localhost cookie is not supported by most browsers.
            if (domain.ToLower() != "localhost")
            {
                cookie.Domain = domain;
            }

            this.Response.Cookies.Add(cookie);
            return(Json(token.ClientToken));
        }
Пример #6
0
        internal static string ToCdnResource(string path)
        {
            if (!path.StartsWith("/") || path.StartsWith("//") || path.ToLowerInvariant().StartsWith("/signalr"))
            {
                return(path);
            }

            var approved = new DomainSerializer("DomainsApproved.json");
            var tenant   = approved.Get().FirstOrDefault(x => x.GetSubtenants().Contains(DbConvention.GetDomain()));

            if (tenant == null)
            {
                return(path);
            }

            if (!string.IsNullOrWhiteSpace(tenant.CdnDomain))
            {
                var uri = HttpContext.Current.Request.Url;

                return(uri.Scheme + Uri.SchemeDelimiter + tenant.CdnDomain +
                       (uri.IsDefaultPort ? "" : ":" + uri.Port) + path);
            }

            return(path);
        }