mailbox not change pass on single reload

This commit is contained in:
Jorge Pastor 2023-11-22 19:15:01 +01:00
parent 80aeb8ebe2
commit 17757800b8
2 changed files with 17 additions and 7 deletions

View file

@ -213,6 +213,8 @@ class MailboxAdmin(ChangePasswordAdminMixin, SelectAccountAdminMixin, ExtendedMo
old = Mailbox.objects.get(pk=obj.pk) old = Mailbox.objects.get(pk=obj.pk)
if old.custom_filtering != obj.custom_filtering: if old.custom_filtering != obj.custom_filtering:
messages.warning(request, msg) messages.warning(request, msg)
# pass var to the backend so you don't change the password
obj.changepass = None
elif obj.custom_filtering: elif obj.custom_filtering:
messages.warning(request, msg) messages.warning(request, msg)
super(MailboxAdmin, self).save_model(request, obj, form, change) super(MailboxAdmin, self).save_model(request, obj, form, change)

View file

@ -69,13 +69,15 @@ class UNIXUserMaildirController(SieveFilteringMixin, ServiceController):
self.append(textwrap.dedent(""" self.append(textwrap.dedent("""
# Update/create %(user)s user state # Update/create %(user)s user state
if id %(user)s ; then if id %(user)s ; then
old_password=$(getent shadow %(user)s | cut -d':' -f2) if [[ "%(changepass)s" == "True" ]]; then
usermod %(user)s \\ old_password=$(getent shadow %(user)s | cut -d':' -f2)
--shell %(initial_shell)s \\ usermod %(user)s \\
--password '%(password)s' --shell %(initial_shell)s \\
if [[ "$old_password" != '%(password)s' ]]; then --password '%(password)s'
# Postfix SASL caches passwords if [[ "$old_password" != '%(password)s' ]]; then
RESTART_POSTFIX=1 # Postfix SASL caches passwords
RESTART_POSTFIX=1
fi
fi fi
else else
useradd %(user)s \\ useradd %(user)s \\
@ -135,6 +137,11 @@ class UNIXUserMaildirController(SieveFilteringMixin, ServiceController):
super().commit() super().commit()
def get_context(self, mailbox): def get_context(self, mailbox):
# Check if you have to change password
try:
changepass = mailbox.changepass
except:
changepass = True
context = { context = {
'user': mailbox.name, 'user': mailbox.name,
'group': mailbox.name, 'group': mailbox.name,
@ -144,6 +151,7 @@ class UNIXUserMaildirController(SieveFilteringMixin, ServiceController):
'maildir': os.path.join(mailbox.get_home(), 'Maildir'), 'maildir': os.path.join(mailbox.get_home(), 'Maildir'),
'initial_shell': self.SHELL, 'initial_shell': self.SHELL,
'banner': self.get_banner(), 'banner': self.get_banner(),
'changepass': changepass,
} }
context['deleted_home'] = settings.MAILBOXES_MOVE_ON_DELETE_PATH % context context['deleted_home'] = settings.MAILBOXES_MOVE_ON_DELETE_PATH % context
return context return context