add backend rspamd ratelimit basic

This commit is contained in:
Jorge Pastor 2024-06-27 18:08:46 +02:00
parent 17e0497ed8
commit 9c1acfaf8a
1 changed files with 39 additions and 0 deletions

View File

@ -666,3 +666,42 @@ class RoundcubeIdentityController(ServiceController):
verbose_name = _("Roundcube Identity Controller") verbose_name = _("Roundcube Identity Controller")
model = 'mailboxes.Mailbox' model = 'mailboxes.Mailbox'
class RSpamdRatelimitController(ServiceController):
"""
rspamd ratelimit to user
"""
verbose_name = _("rspamd ratelimit user")
model = 'mailboxes.Mailbox'
def save(self, mailbox):
context = self.get_context(mailbox)
self.append(textwrap.dedent("""
if ! grep -qx '%(user)s' /etc/rspamd/local.d/maps/usuariosbase.map; then
echo '%(user)s' >> /etc/rspamd/local.d/maps/usuariosbase.map
RELOAD_RSPAMD=1
fi
""") % context
)
def delete(self, mailbox):
context = self.get_context(mailbox)
self.append(textwrap.dedent("""
if grep -qx '%(user)s' /etc/rspamd/local.d/maps/usuariosbase.map; then
sed -i '/^%(user)s$/d' /etc/rspamd/local.d/maps/usuariosbase.map
RELOAD_RSPAMD=1
fi
""") % context
)
def commit(self):
self.append('[[ $RELOAD_RSPAMD -eq 1 ]] && systemctl reload rspamd.service')
super().commit()
def get_context(self, mailbox):
context = {
'user': mailbox.name,
}
return context