Beispiel #1
0
 def validateTo(self, user):
     """
     Determine whether the recipient is local to this system or not and
     dispatch to the appropriate helper method.
     """
     siteStore = self.avatar.store.parent
     if user.dest.domain in userbase.getDomainNames(siteStore):
         return self.localValidateTo(user)
     else:
         return self.remoteValidateTo(user)
Beispiel #2
0
 def validateTo(self, user):
     """
     Determine whether the recipient is local to this system or not and
     dispatch to the appropriate helper method.
     """
     siteStore = self.avatar.store.parent
     if user.dest.domain in userbase.getDomainNames(siteStore):
         return self.localValidateTo(user)
     else:
         return self.remoteValidateTo(user)
Beispiel #3
0
    def subdomain(self, hostname):
        """
        Determine of which known domain the given hostname is a subdomain.

        @return: A two-tuple giving the subdomain part and the domain part or
            C{None} if the domain is not a subdomain of any known domain.
        """
        hostname = hostname.split(":")[0]
        for domain in getDomainNames(self.siteStore):
            if hostname.endswith("." + domain):
                username = hostname[:-len(domain) - 1]
                if username != "www":
                    return username, domain
        return None
Beispiel #4
0
    def subdomain(self, hostname):
        """
        Determine of which known domain the given hostname is a subdomain.

        @return: A two-tuple giving the subdomain part and the domain part or
            C{None} if the domain is not a subdomain of any known domain.
        """
        hostname = hostname.split(":")[0]
        for domain in getDomainNames(self.siteStore):
            if hostname.endswith("." + domain):
                username = hostname[:-len(domain) - 1]
                if username != "www":
                    return username, domain
        return None
Beispiel #5
0
 def testDomainNames(self):
     s = Store()
     acc = s
     for localpart, domain, internal in [(u'local', u'example.com', True),
                                         (u'local', u'example.net', True),
                                         (u'remote', u'example.org', False),
                                         (u'another', u'example.com', True),
                                         (u'brokenguy', None, True)]:
         userbase.LoginMethod(store=s,
                              localpart=localpart,
                              domain=domain,
                              verified=True,
                              account=s,
                              protocol=u'test',
                              internal=internal)
     self.assertEquals(userbase.getDomainNames(s),
                       [u"example.com", u"example.net"])
Beispiel #6
0
 def testDomainNames(self):
     s = Store()
     acc = s
     for localpart, domain, internal in [
         ('local', 'example.com', True),
         ('local', 'example.net', True),
         ('remote', 'example.org', False),
         ('another', 'example.com', True),
         ('brokenguy', None, True)]:
         userbase.LoginMethod(
             store=s,
             localpart=localpart,
             domain=domain,
             verified=True,
             account=s,
             protocol='test',
             internal=internal)
     self.assertEqual(userbase.getDomainNames(s), ["example.com", "example.net"])
Beispiel #7
0
    def rootURL(self, request):
        """
        Return the URL for the root of this website which is appropriate to use
        in links generated in response to the given request.

        @type request: L{twisted.web.http.Request}
        @param request: The request which is being responded to.

        @rtype: L{URL}
        @return: The location at which the root of the resource hierarchy for
            this website is available.
        """
        host = request.getHeader('host') or self.hostname
        if ':' in host:
            host = host.split(':', 1)[0]
        for domain in [self.hostname] + getDomainNames(self.store):
            if (host == domain or
                host.startswith('www.') and host[len('www.'):] == domain):
                return URL(scheme='', netloc='', pathsegs=[''])
        if request.isSecure():
            return self.encryptedRoot(self.hostname)
        else:
            return self.cleartextRoot(self.hostname)
Beispiel #8
0
    def rootURL(self, request):
        """
        Return the URL for the root of this website which is appropriate to use
        in links generated in response to the given request.

        @type request: L{twisted.web.http.Request}
        @param request: The request which is being responded to.

        @rtype: L{URL}
        @return: The location at which the root of the resource hierarchy for
            this website is available.
        """
        host = request.getHeader('host') or self.hostname
        if ':' in host:
            host = host.split(':', 1)[0]
        for domain in [self.hostname] + getDomainNames(self.store):
            if (host == domain or host.startswith('www.')
                    and host[len('www.'):] == domain):
                return URL(scheme='', netloc='', pathsegs=[''])
        if request.isSecure():
            return self.encryptedRoot(self.hostname)
        else:
            return self.cleartextRoot(self.hostname)
Beispiel #9
0
 def getAvailableDomains(self):
     """
     Return a list of domain names available on this site.
     """
     return getDomainNames(self.store)
Beispiel #10
0
 def validateFrom(self, helo, origin):
     if origin.domain in userbase.getDomainNames(self.store):
         return defer.fail(smtp.SMTPBadSender(origin))
     return defer.succeed(origin)
Beispiel #11
0
def getHostnames(store):
    """
    Like L{axiom.userbase.getDomainNames}, but also default to just
    C{['localhost']} if there are no domains.
    """
    return userbase.getDomainNames(store) or ['localhost']
Beispiel #12
0
 def validateFrom(self, helo, origin):
     if origin.domain in userbase.getDomainNames(self.store):
         return defer.fail(smtp.SMTPBadSender(origin))
     return defer.succeed(origin)
Beispiel #13
0
def getHostnames(store):
    """
    Like L{axiom.userbase.getDomainNames}, but also default to just
    C{['localhost']} if there are no domains.
    """
    return userbase.getDomainNames(store) or ['localhost']
Beispiel #14
0
 def getAvailableDomains(self):
     """
     Return a list of domain names available on this site.
     """
     return getDomainNames(self.store)