Compare commits
2 Commits
9c1acfaf8a
...
e15d2acd13
Author | SHA1 | Date |
---|---|---|
Jorge Pastor | e15d2acd13 | |
Jorge Pastor | 67c291cb99 |
|
@ -47,7 +47,7 @@ class MailboxAdmin(ChangePasswordAdminMixin, SelectAccountAdminMixin, ExtendedMo
|
||||||
)
|
)
|
||||||
add_fieldsets = (
|
add_fieldsets = (
|
||||||
(None, {
|
(None, {
|
||||||
'fields': ('account_link', 'name', 'password1', 'password2', 'filtering'),
|
'fields': ('account_link', 'name', 'password1', 'password2', 'filtering', 'ratelimit'),
|
||||||
}),
|
}),
|
||||||
(_("Custom filtering"), {
|
(_("Custom filtering"), {
|
||||||
'classes': ('collapse',),
|
'classes': ('collapse',),
|
||||||
|
@ -61,7 +61,7 @@ class MailboxAdmin(ChangePasswordAdminMixin, SelectAccountAdminMixin, ExtendedMo
|
||||||
)
|
)
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
(None, {
|
(None, {
|
||||||
'fields': ('name', 'password', 'is_active', 'account_link', 'filtering'),
|
'fields': ('name', 'password', 'is_active', 'account_link', 'filtering', 'ratelimit'),
|
||||||
}),
|
}),
|
||||||
(_("Custom filtering"), {
|
(_("Custom filtering"), {
|
||||||
'classes': ('collapse',),
|
'classes': ('collapse',),
|
||||||
|
|
|
@ -679,29 +679,44 @@ class RSpamdRatelimitController(ServiceController):
|
||||||
def save(self, mailbox):
|
def save(self, mailbox):
|
||||||
context = self.get_context(mailbox)
|
context = self.get_context(mailbox)
|
||||||
self.append(textwrap.dedent("""
|
self.append(textwrap.dedent("""
|
||||||
if ! grep -qx '%(user)s' /etc/rspamd/local.d/maps/usuariosbase.map; then
|
sed -i '/^%(user)s$/d' %(maps)s
|
||||||
echo '%(user)s' >> /etc/rspamd/local.d/maps/usuariosbase.map
|
echo '%(user)s' >> %(path_maps)s%(ratelimit)s.map
|
||||||
RELOAD_RSPAMD=1
|
systemctl reload rspamd.service
|
||||||
fi
|
|
||||||
""") % context
|
""") % context
|
||||||
)
|
)
|
||||||
|
|
||||||
def delete(self, mailbox):
|
def delete(self, mailbox):
|
||||||
context = self.get_context(mailbox)
|
context = self.get_context(mailbox)
|
||||||
self.append(textwrap.dedent("""
|
self.append(textwrap.dedent("""
|
||||||
if grep -qx '%(user)s' /etc/rspamd/local.d/maps/usuariosbase.map; then
|
sed -i '/^%(user)s$/d' %(maps)s
|
||||||
sed -i '/^%(user)s$/d' /etc/rspamd/local.d/maps/usuariosbase.map
|
systemctl reload rspamd.service
|
||||||
RELOAD_RSPAMD=1
|
|
||||||
fi
|
|
||||||
""") % context
|
""") % context
|
||||||
)
|
)
|
||||||
|
|
||||||
def commit(self):
|
# def commit(self):
|
||||||
self.append('[[ $RELOAD_RSPAMD -eq 1 ]] && systemctl reload rspamd.service')
|
# self.append('[[ $RELOAD_RSPAMD -eq 1 ]] && systemctl reload rspamd.service')
|
||||||
super().commit()
|
# super().commit()
|
||||||
|
|
||||||
def get_context(self, mailbox):
|
def get_context(self, mailbox):
|
||||||
|
maps = self.extract_group_maps()
|
||||||
context = {
|
context = {
|
||||||
'user': mailbox.name,
|
'user': mailbox.name,
|
||||||
|
'ratelimit': mailbox.ratelimit,
|
||||||
|
'maps': maps,
|
||||||
|
'path_maps': settings.MAILBOXES_RATELIMIT_PATH_MAPS,
|
||||||
}
|
}
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
def extract_group_maps(self):
|
||||||
|
"""
|
||||||
|
debulve string de todos los ficheros de maps assignados en settings para ratelimit
|
||||||
|
return string
|
||||||
|
"""
|
||||||
|
choice_groups = settings.MAILBOXES_RATELIMIT_GROUP
|
||||||
|
path = settings.MAILBOXES_RATELIMIT_PATH_MAPS
|
||||||
|
group_maps = ''
|
||||||
|
if len(choice_groups) > 0:
|
||||||
|
for choice in choice_groups:
|
||||||
|
group_maps += f"{path}{choice[0]}.map "
|
||||||
|
|
||||||
|
return group_maps
|
|
@ -54,6 +54,11 @@ class MailboxForm(forms.ModelForm):
|
||||||
raise ValidationError("Name length should be less than %i." % max_length)
|
raise ValidationError("Name length should be less than %i." % max_length)
|
||||||
return name
|
return name
|
||||||
|
|
||||||
|
def clean_ratelimit(self):
|
||||||
|
ratelimit = self.cleaned_data['ratelimit']
|
||||||
|
if ratelimit is None:
|
||||||
|
ratelimit = settings.MAILBOXES_RATELIMIT_GROUP_DEFAULT
|
||||||
|
return ratelimit
|
||||||
|
|
||||||
class MailboxChangeForm(UserChangeForm, MailboxForm):
|
class MailboxChangeForm(UserChangeForm, MailboxForm):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -33,6 +33,11 @@ class Mailbox(models.Model):
|
||||||
"<a href='https://tty1.net/blog/2011/sieve-tutorial_en.html'>sieve language</a>. "
|
"<a href='https://tty1.net/blog/2011/sieve-tutorial_en.html'>sieve language</a>. "
|
||||||
"This overrides any automatic junk email filtering"))
|
"This overrides any automatic junk email filtering"))
|
||||||
is_active = models.BooleanField(_("active"), default=True)
|
is_active = models.BooleanField(_("active"), default=True)
|
||||||
|
ratelimit = models.CharField(_("ratelimit"),
|
||||||
|
max_length=100, null=True, blank=True,
|
||||||
|
choices=settings.MAILBOXES_RATELIMIT_GROUP,
|
||||||
|
default=settings.MAILBOXES_RATELIMIT_GROUP_DEFAULT,)
|
||||||
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name_plural = _("mailboxes")
|
verbose_name_plural = _("mailboxes")
|
||||||
|
|
|
@ -203,3 +203,21 @@ MAILBOXES_MOVE_ON_DELETE_PATH = Setting('MAILBOXES_MOVE_ON_DELETE_PATH',
|
||||||
help_text="Available fromat names: <tt>%s</tt>" % ', '.join(_backend_names),
|
help_text="Available fromat names: <tt>%s</tt>" % ', '.join(_backend_names),
|
||||||
validators=[Setting.string_format_validator(_backend_names)],
|
validators=[Setting.string_format_validator(_backend_names)],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
MAILBOXES_RATELIMIT_GROUP = Setting('MAILBOXES_RATELIMIT_GROUP', (
|
||||||
|
('userbase', 'base'),
|
||||||
|
('user100', '100'),
|
||||||
|
('user200', '200'),
|
||||||
|
('user500', '500'),
|
||||||
|
),
|
||||||
|
help_text="Available messages per second"
|
||||||
|
)
|
||||||
|
|
||||||
|
MAILBOXES_RATELIMIT_GROUP_DEFAULT = Setting('MAILBOXES_RATELIMIT_GROUP_DEFAULT',
|
||||||
|
'userbase',
|
||||||
|
choices=MAILBOXES_RATELIMIT_GROUP
|
||||||
|
)
|
||||||
|
|
||||||
|
MAILBOXES_RATELIMIT_PATH_MAPS = Setting('MAILBOXES_RATELIMIT_PATH_MAPS',
|
||||||
|
'/etc/rspamd/local.d/maps/',
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue