mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
Fixed pdfcrendtials preventing login
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
"""PDF credentials handlers."""
|
||||
|
||||
import logging
|
||||
import os
|
||||
|
||||
from django.urls import reverse
|
||||
@@ -10,6 +11,7 @@ from django.utils.translation import gettext as _
|
||||
from modoboa.admin import signals as admin_signals
|
||||
from modoboa.core import models as core_models
|
||||
from modoboa.core import signals as core_signals
|
||||
from modoboa.lib.exceptions import InternalError
|
||||
from modoboa.parameters import tools as param_tools
|
||||
|
||||
from .documents import credentials
|
||||
@@ -25,7 +27,14 @@ def password_updated(sender, account, password, created, **kwargs):
|
||||
"generate_at_creation")
|
||||
if (generate_at_creation and not created) or account.is_superuser:
|
||||
return
|
||||
init_storage_dir()
|
||||
try:
|
||||
init_storage_dir()
|
||||
except InternalError as e:
|
||||
logger = logging.getLogger("modoboa.admin")
|
||||
logger.error(
|
||||
_("Failed to create PDF_credentials directory. "
|
||||
"Please check the permissions or the path."),
|
||||
exc_info=e)
|
||||
credentials(account, password)
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""Internal library."""
|
||||
|
||||
from io import BytesIO
|
||||
import logging
|
||||
import os
|
||||
import struct
|
||||
|
||||
@@ -18,7 +19,7 @@ from modoboa.parameters import tools as param_tools
|
||||
|
||||
|
||||
def init_storage_dir():
|
||||
"""Create the directory whare documents will be stored."""
|
||||
"""Create the directory where documents will be stored."""
|
||||
storage_dir = param_tools.get_global_parameter("storage_dir")
|
||||
if os.path.exists(storage_dir) and os.access(storage_dir, os.W_OK):
|
||||
return
|
||||
@@ -66,17 +67,24 @@ def crypt_and_save_to_file(content, filename, length, chunksize=64*512):
|
||||
iv = os.urandom(16)
|
||||
cipher = _get_cipher(iv)
|
||||
encryptor = cipher.encryptor()
|
||||
with open(filename, "wb") as fp:
|
||||
fp.write(struct.pack(b"<Q", length))
|
||||
fp.write(iv)
|
||||
while True:
|
||||
chunk = content.read(chunksize)
|
||||
if not len(chunk):
|
||||
break
|
||||
elif len(chunk) % 16:
|
||||
chunk += b" " * (16 - len(chunk) % 16)
|
||||
fp.write(encryptor.update(force_bytes(chunk)))
|
||||
fp.write(encryptor.finalize())
|
||||
try:
|
||||
with open(filename, "wb") as fp:
|
||||
fp.write(struct.pack(b"<Q", length))
|
||||
fp.write(iv)
|
||||
while True:
|
||||
chunk = content.read(chunksize)
|
||||
if not len(chunk):
|
||||
break
|
||||
elif len(chunk) % 16:
|
||||
chunk += b" " * (16 - len(chunk) % 16)
|
||||
fp.write(encryptor.update(force_bytes(chunk)))
|
||||
fp.write(encryptor.finalize())
|
||||
except FileNotFoundError as e:
|
||||
logger = logging.getLogger("modoboa.admin")
|
||||
logger.error(
|
||||
_("Failed to create PDF_credentials file. "
|
||||
"Please check the permissions or the path."),
|
||||
exc_info=e)
|
||||
|
||||
|
||||
def decrypt_file(filename, chunksize=24*1024):
|
||||
|
||||
+4
-3
@@ -14,18 +14,19 @@ authors = [
|
||||
]
|
||||
description = "Mail hosting made simple"
|
||||
readme = "README.rst"
|
||||
requires-python = ">=3.7"
|
||||
requires-python = ">=3.8"
|
||||
classifiers = [
|
||||
"Development Status :: 5 - Production/Stable",
|
||||
"Environment :: Web Environment",
|
||||
"Framework :: Django :: 2.2",
|
||||
"Framework :: Django :: 4.2",
|
||||
"Intended Audience :: System Administrators",
|
||||
"License :: OSI Approved :: ISC License (ISCL)",
|
||||
"Operating System :: OS Independent",
|
||||
"Programming Language :: Python :: 3",
|
||||
"Programming Language :: Python :: 3.7",
|
||||
"Programming Language :: Python :: 3.8",
|
||||
"Programming Language :: Python :: 3.9",
|
||||
"Programming Language :: Python :: 3.10",
|
||||
"Programming Language :: Python :: 3.11",
|
||||
"Topic :: Communications :: Email",
|
||||
"Topic :: Internet :: WWW/HTTP",
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user