mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-11-21 10:24:05 +01:00
@@ -1,11 +1,14 @@
|
||||
"""Django signal handlers for admin."""
|
||||
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.management import call_command
|
||||
from django.db.models import signals
|
||||
from django.dispatch import receiver
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
import django_rq
|
||||
|
||||
from modoboa.core import models as core_models, signals as core_signals
|
||||
from modoboa.lib import exceptions, permissions, signals as lib_signals
|
||||
from modoboa.lib.cryptutils import encrypt
|
||||
@@ -44,6 +47,16 @@ def update_domain_mxs_and_mailboxes(sender, instance, **kwargs):
|
||||
alias.save(update_fields=["address"])
|
||||
|
||||
|
||||
@receiver(signals.post_save, sender=models.Domain)
|
||||
def create_dkim_key(sender, instance, **kwargs):
|
||||
if not instance.enable_dkim:
|
||||
return
|
||||
django_rq.enqueue(call_command,
|
||||
"modo",
|
||||
"manage_dkim_keys",
|
||||
f"--domain={instance.name}")
|
||||
|
||||
|
||||
@receiver(signals.post_save, sender=models.DomainAlias)
|
||||
def create_alias_for_domainalias(sender, instance, **kwargs):
|
||||
"""Create a dedicated alias for domain alias."""
|
||||
|
||||
@@ -56,8 +56,25 @@ class ManageDKIMKeys(BaseCommand):
|
||||
domain.dkim_public_key = public_key
|
||||
domain.save(update_fields=["dkim_public_key", "dkim_private_key_path"])
|
||||
|
||||
def add_arguments(self, parser):
|
||||
"""Add arguments to command."""
|
||||
parser.add_argument(
|
||||
"--domain", type=str, dest="domain", default="",
|
||||
help="Domain target for keys generation."
|
||||
)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
"""Entry point."""
|
||||
if options["domain"] != "":
|
||||
domain = models.Domain.objects.filter(name=options["domain"],
|
||||
enable_dkim=True,
|
||||
dkim_private_key_path="")
|
||||
if domain.exists():
|
||||
self.create_new_dkim_key(domain[0])
|
||||
signals.new_dkim_keys.send(sender=self.__class__,
|
||||
domains=domain)
|
||||
return
|
||||
|
||||
self.default_key_length = param_tools.get_global_parameter(
|
||||
"dkim_default_key_length")
|
||||
qset = models.Domain.objects.filter(
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
import socket
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
from dns.name import Name
|
||||
from dns.rdtypes.IN.A import A
|
||||
from dns.rdtypes.ANY.MX import MX
|
||||
@@ -67,6 +69,7 @@ _POSSIBLE_DNS_RESULTS_NO_MX = {
|
||||
"mx3.example.com": [_A_RECORD]
|
||||
}
|
||||
_POSSIBLE_IP_RESULTS = {
|
||||
settings.REDIS_HOST: socket.getaddrinfo(settings.REDIS_HOST, settings.REDIS_PORT),
|
||||
"test3.com": [_IPV4_RECORD_2],
|
||||
"mx2.example.com": [_IPV4_RECORD_2],
|
||||
"bad-response.example.com": [_BAD_IP_RECORD],
|
||||
|
||||
@@ -70,6 +70,7 @@ INSTALLED_APPS = (
|
||||
'django_otp.plugins.otp_totp',
|
||||
'django_otp.plugins.otp_static',
|
||||
'django_rename_app',
|
||||
'django_rq',
|
||||
{% if devmode %} 'djangobower',{% endif %}
|
||||
)
|
||||
|
||||
@@ -253,6 +254,26 @@ REDIS_PORT = 6379
|
||||
REDIS_QUOTA_DB = 0
|
||||
REDIS_URL = 'redis://{}:{}/{}'.format(REDIS_HOST, REDIS_PORT, REDIS_QUOTA_DB)
|
||||
|
||||
# RQ
|
||||
|
||||
RQ_QUEUES = {
|
||||
'default': {
|
||||
'HOST': REDIS_HOST,
|
||||
'PORT': REDIS_PORT,
|
||||
'DB': 0,
|
||||
},
|
||||
'high': {
|
||||
'HOST': REDIS_HOST,
|
||||
'PORT': REDIS_PORT,
|
||||
'DB': 0,
|
||||
},
|
||||
'low': {
|
||||
'HOST': REDIS_HOST,
|
||||
'PORT': REDIS_PORT,
|
||||
'DB': 0,
|
||||
}
|
||||
}
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from django.conf.urls import include, url
|
||||
from django.conf.urls import include, path
|
||||
|
||||
urlpatterns = [
|
||||
url(r'', include('modoboa.urls')),
|
||||
path(r'', include('modoboa.urls')),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user