Compare commits
No commits in common. "e15d2acd131d1bfd5a898960f06dea6ce4061d32" and "9c1acfaf8a27ca3ee61f3a133c0519e1be10fd6a" have entirely different histories.
e15d2acd13
...
9c1acfaf8a
|
@ -47,7 +47,7 @@ class MailboxAdmin(ChangePasswordAdminMixin, SelectAccountAdminMixin, ExtendedMo
|
||||||
)
|
)
|
||||||
add_fieldsets = (
|
add_fieldsets = (
|
||||||
(None, {
|
(None, {
|
||||||
'fields': ('account_link', 'name', 'password1', 'password2', 'filtering', 'ratelimit'),
|
'fields': ('account_link', 'name', 'password1', 'password2', 'filtering'),
|
||||||
}),
|
}),
|
||||||
(_("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', 'ratelimit'),
|
'fields': ('name', 'password', 'is_active', 'account_link', 'filtering'),
|
||||||
}),
|
}),
|
||||||
(_("Custom filtering"), {
|
(_("Custom filtering"), {
|
||||||
'classes': ('collapse',),
|
'classes': ('collapse',),
|
||||||
|
|
|
@ -679,44 +679,29 @@ 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("""
|
||||||
sed -i '/^%(user)s$/d' %(maps)s
|
if ! grep -qx '%(user)s' /etc/rspamd/local.d/maps/usuariosbase.map; then
|
||||||
echo '%(user)s' >> %(path_maps)s%(ratelimit)s.map
|
echo '%(user)s' >> /etc/rspamd/local.d/maps/usuariosbase.map
|
||||||
systemctl reload rspamd.service
|
RELOAD_RSPAMD=1
|
||||||
|
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("""
|
||||||
sed -i '/^%(user)s$/d' %(maps)s
|
if grep -qx '%(user)s' /etc/rspamd/local.d/maps/usuariosbase.map; then
|
||||||
systemctl reload rspamd.service
|
sed -i '/^%(user)s$/d' /etc/rspamd/local.d/maps/usuariosbase.map
|
||||||
|
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,11 +54,6 @@ 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,11 +33,6 @@ 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,21 +203,3 @@ 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