private RedirectDomain GetDomainByInbound(RedirectProtocol protocol, string domainName, int portNumber)
        {
            // Validate the input
            if (String.IsNullOrWhiteSpace(domainName))
            {
                throw new ArgumentNullException("domainName");
            }

            // Just return "null" if the table doesn't exist (since there aren't any domains anyway)
            if (!SchemaHelper.TableExist(RedirectDomain.TableName))
            {
                return(null);
            }

            // Work a bit on the input
            string protocolStr = StringUtils.ToPascalCase(protocol);

            domainName = domainName.Trim().ToLower();

            // Generate the SQL for the query
            Sql sql = new Sql().Select("*").From(RedirectDomain.TableName).Where <RedirectDomain>(
                x => x.InboundProtocolString == protocolStr && x.InboundDomain == domainName && x.InboundPort == portNumber
                );

            // Make the call to the database
            return(Database.FirstOrDefault <RedirectDomain>(sql));
        }
 public RedirectDomain AddDomain(RedirectProtocol inboundProtocol, string inboundDomain, int inboundPort, RedirectProtocol outboundProtocol, string outboundDomain, int outboundPort, IUser user)
 {
     if (user == null)
     {
         throw new ArgumentNullException("user");
     }
     return(AddDomain(inboundProtocol, inboundDomain, inboundPort, outboundProtocol, outboundDomain, outboundPort, user.Id));
 }
示例#3
0
 public bool TryGetDomain(RedirectProtocol protocol, string domainName, int portNumber, out RedirectDomain domain)
 {
     if (!HasCache)
     {
         RebuildCache();
     }
     return(_lookup.TryGetValue(GetDomainKey(protocol, domainName, portNumber), out domain));
 }
        private int GetDefaultPort(RedirectProtocol protocol)
        {
            switch (protocol)
            {
            case RedirectProtocol.Http: return(80);

            case RedirectProtocol.Https: return(443);

            default: return(0);
            }
        }
        public RedirectDomain AddDomain(RedirectProtocol inboundProtocol, string inboundDomain, int inboundPort, RedirectProtocol outboundProtocol, string outboundDomain, int outboundPort, int userId = 0)
        {
            if (String.IsNullOrWhiteSpace(inboundDomain))
            {
                throw new ArgumentNullException("inboundDomain");
            }
            if (String.IsNullOrWhiteSpace(outboundDomain))
            {
                throw new ArgumentNullException("outboundDomain");
            }

            if (!SchemaHelper.TableExist(RedirectDomain.TableName))
            {
                SchemaHelper.CreateTable <RedirectDomain>(false);
            }

            if (GetDomainByInbound(inboundProtocol, inboundDomain, inboundPort) != null)
            {
                throw new DomainsException("A domain with the specified inbound parameters already exists.");
            }

            // Initialize the new domain and populate the properties
            RedirectDomain row = new RedirectDomain {
                UniqueId         = Guid.NewGuid(),
                InboundProtocol  = inboundProtocol,
                InboundDomain    = inboundDomain.Trim().ToLower(),
                InboundPort      = inboundPort,
                OutboundProtocol = outboundProtocol,
                OutboundDomain   = outboundDomain.Trim().ToLower(),
                OutboundPort     = outboundPort,
                StatusCode       = HttpStatusCode.MovedPermanently,
                Created          = DateTime.UtcNow,
                Updated          = DateTime.UtcNow
            };

            // Attempt to add the redirect to the database
            try {
                Database.Insert(row);
            } catch (Exception ex) {
                LogHelper.Error <DomainsRepository>("Unable to insert domain into the database", ex);
                throw new Exception("Unable to insert domain into the database", ex);
            }

            // Get an updated reference to the created domain
            RedirectDomain domain = GetDomainById(row.UniqueId);

            // Update the domain in the caches across all domains
            DistributedCache.Instance.Refresh(DomainsCacheRefresher.CacheRefresherId, domain.Id);

            return(domain);
        }
        public RedirectDomain AddDomain(RedirectProtocol inboundProtocol, string inboundDomain, RedirectProtocol outboundProtocol, string outboundDomain, int userId = 0)
        {
            if (String.IsNullOrWhiteSpace(inboundDomain))
            {
                throw new ArgumentNullException("inboundDomain");
            }
            if (String.IsNullOrWhiteSpace(outboundDomain))
            {
                throw new ArgumentNullException("outboundDomain");
            }

            return(AddDomain(
                       inboundProtocol, inboundDomain, GetDefaultPort(inboundProtocol),
                       outboundProtocol, outboundDomain, GetDefaultPort(outboundProtocol),
                       userId
                       ));
        }
示例#7
0
        void IClassifyObjectProcessor.AfterDeserialize()
        {
            if (AutoConfig != null)
            {
                // Parse the AutoConfig
                var posQ = AutoConfig.IndexOf('?');
                if (posQ != -1)
                {
                    var q = AutoConfig.Substring(posQ);
                    if (q.StartsWith("?*&"))
                    {
                        QueryBehavior = RedirectQueryParameters.Append;
                        q             = "?" + q.Substring(3);
                    }
                    else if (q.EndsWith("&*"))
                    {
                        QueryBehavior = RedirectQueryParameters.Prepend;
                        q             = q.Remove(q.Length - 2);
                    }
                    else
                    {
                        QueryBehavior = RedirectQueryParameters.Replace;
                    }

                    QueryParameters = HttpHelper.ParseQueryString(q).ToArray();
                    AutoConfig      = AutoConfig.Remove(posQ);
                }

                if (AutoConfig.EndsWith("/*"))
                {
                    AppendSubpath = true;
                    AutoConfig    = AutoConfig.Remove(AutoConfig.Length - 2);
                }
                else if (AutoConfig.Length > 0)
                {
                    AppendSubpath = false;
                }

                if (AutoConfig.StartsWith("http://"))
                {
                    Protocol   = RedirectProtocol.Http;
                    AutoConfig = AutoConfig.Substring(7);
                }
                else if (AutoConfig.StartsWith("https://"))
                {
                    Protocol   = RedirectProtocol.Https;
                    AutoConfig = AutoConfig.Substring(8);
                }
                else if (AutoConfig.Length > 0)
                {
                    Protocol = RedirectProtocol.Keep;
                }

                if (AutoConfig.Length > 0 && !AutoConfig.StartsWith("/"))
                {
                    if (AutoConfig.StartsWith("*."))
                    {
                        PrependSubdomain = true;
                        AutoConfig       = AutoConfig.Substring(2);
                    }
                    else
                    {
                        PrependSubdomain = false;
                    }
                    var posSlash = AutoConfig.IndexOf('/');
                    Domain     = posSlash == -1 ? AutoConfig : AutoConfig.Remove(posSlash);
                    AutoConfig = posSlash == -1 ? "" : AutoConfig.Substring(posSlash);
                }

                if (AutoConfig.Length > 0)
                {
                    Path = AutoConfig;
                }
                AutoConfig = null;
            }
            else if (Path != null)
            {
                // Take query parameters from the Path and put them into QueryParameters
                var posQP = Path.IndexOf('?');
                if (posQP != -1)
                {
                    QueryParameters = HttpHelper.ParseQueryString(Path.Substring(posQP)).Concat(QueryParameters).ToArray();
                    Path            = Path.Remove(posQP);
                }
            }
        }
示例#8
0
        public bool TryGetDomain(RedirectProtocol protocol, string domainName, out RedirectDomain domain)
        {
            int portNumber = protocol == RedirectProtocol.Http ? 80 : 443;

            return(TryGetDomain(protocol, domainName, portNumber, out domain));
        }
示例#9
0
 private string GetDomainKey(RedirectProtocol protocol, string domainName, int portNumber)
 {
     return((protocol + "__" + domainName + "__" + portNumber).ToLower());
 }