import pwd
import pipes
import codecs
+import ipaddress
from subprocess import Popen, PIPE
from .app import PpApplication
-__version__ = '0.6.4'
+__version__ = '0.6.5'
LOG = logging.getLogger(__name__)
VALID_MAIL_METHODS = ('smtp', 'sendmail')
self.initialized = True
+ # -------------------------------------------------------------------------
+ def is_local(self, domain):
+
+ if self.verbose > 1:
+ LOG.debug("Checking, whether {!r} is a not public zone.".format(domain))
+
+ tld = domain.split('.')[-1]
+ if tld in ('intern', 'internal', 'local', 'localdomain', 'lokal'):
+ LOG.debug("Zone {!r} has a local TLD {!r}.".format(domain, tld))
+ return True
+
+ zone_base = domain.split('.')[0]
+ if zone_base in ('intern', 'internal', 'local', 'localdomain', 'lokal'):
+ LOG.debug("Zone {!r} has a local base {!r}.".format(domain, tld))
+ return True
+
+ if tld != 'arpa':
+ if self.verbose > 2:
+ LOG.debug("Zone {!r} has a public TLD {!r}.".format(domain, tld))
+ return False
+
+ if domain.endswith('.in-addr.arpa'):
+ tupels = []
+ for tupel in reversed(domain.replace('.in-addr.arpa', '').split('.')):
+ tupels.append(tupel)
+ if self.verbose > 2:
+ LOG.debug("Got IPv4 tupels from zone {!r}: {}".format(domain, pp(tupels)))
+ bitmask = None
+ if len(tupels) == 1:
+ bitmask = 8
+ tupels.append('0')
+ tupels.append('0')
+ tupels.append('0')
+ elif len(tupels) == 2:
+ tupels.append('0')
+ tupels.append('0')
+ bitmask = 16
+ elif len(tupels) == 3:
+ bitmask = 24
+ tupels.append('0')
+ else:
+ LOG.warn("Could not interprete reverse IPv4 zone {!r}.".format(domain))
+ return False
+ net_address = '.'.join(tupels) + '/{}'.format(bitmask)
+ if self.verbose > 2:
+ LOG.debug("Got IPv4 network address of zone {!r}: {!r}.".format(domain, net_address))
+ network = ipaddress.ip_network(net_address)
+ if network.is_global:
+ if self.verbose > 1:
+ LOG.debug("The network {!r} of zone {!r} is allocated for public networks.".format(
+ net_address, domain))
+ return False
+ LOG.debug("The network {!r} of zone {!r} is allocated for local networks.".format(
+ net_address, domain))
+ return True
+
+ if self.verbose > 2:
+ LOG.debug("Zone {!r} seems to be a reverse zone for a public network.".format(domain))
+ return False
+
+
# =============================================================================
if __name__ == "__main__":