[anti_spam] add domain blocking to plugin (#380)
This commit is contained in:
committed by
Philipp Hörist
parent
b7954ec52e
commit
a6ed314941
@@ -69,6 +69,7 @@ class AntiSpamPlugin(GajimPlugin):
|
|||||||
'msgtxt_answer': ('', ''),
|
'msgtxt_answer': ('', ''),
|
||||||
'antispam_for_conference': (False, ''),
|
'antispam_for_conference': (False, ''),
|
||||||
'conference_white_list': ([], ''), # conference private chat jid's
|
'conference_white_list': ([], ''), # conference private chat jid's
|
||||||
|
'block_domains': ('', ''), # comma separated list of domain names to block
|
||||||
}
|
}
|
||||||
|
|
||||||
# List of outgoing jid's
|
# List of outgoing jid's
|
||||||
@@ -76,6 +77,8 @@ class AntiSpamPlugin(GajimPlugin):
|
|||||||
# Contain all jid's where are you initiate a chat
|
# Contain all jid's where are you initiate a chat
|
||||||
self.outgoing_jids = []
|
self.outgoing_jids = []
|
||||||
|
|
||||||
|
self.block_domains = [h.strip() for h in self.config['block_domains'].split(",") if len(h.strip())]
|
||||||
|
|
||||||
@log_calls('AntiSpamPlugin')
|
@log_calls('AntiSpamPlugin')
|
||||||
def _nec_atom_entry_received(self, obj):
|
def _nec_atom_entry_received(self, obj):
|
||||||
if self.config['block_pubsub_messages']:
|
if self.config['block_pubsub_messages']:
|
||||||
@@ -89,12 +92,22 @@ class AntiSpamPlugin(GajimPlugin):
|
|||||||
if self.config['disable_xhtml_pm'] and obj.gc_control and \
|
if self.config['disable_xhtml_pm'] and obj.gc_control and \
|
||||||
obj.resource and obj.mtype == 'chat':
|
obj.resource and obj.mtype == 'chat':
|
||||||
self.remove_xhtml(obj)
|
self.remove_xhtml(obj)
|
||||||
|
|
||||||
|
if obj.jid.split("@", 1)[1] in self.block_domains:
|
||||||
|
log.info('discarding message from %s, domain is blocked', obj.jid)
|
||||||
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@log_calls('AntiSpamPlugin')
|
@log_calls('AntiSpamPlugin')
|
||||||
def _nec_decrypted_message_received_received(self, obj):
|
def _nec_decrypted_message_received_received(self, obj):
|
||||||
if not obj.msgtxt:
|
if not obj.msgtxt:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
if obj.jid.split("@", 1)[1] in self.block_domains:
|
||||||
|
log.info('discarding message from %s, domain is blocked', obj.jid)
|
||||||
|
return True
|
||||||
|
|
||||||
if self._nec_decrypted_message_received_question(obj):
|
if self._nec_decrypted_message_received_question(obj):
|
||||||
return True
|
return True
|
||||||
limit = self.config['msgtxt_limit']
|
limit = self.config['msgtxt_limit']
|
||||||
@@ -106,7 +119,11 @@ class AntiSpamPlugin(GajimPlugin):
|
|||||||
def _nec_subscribe_presence_received(self, obj):
|
def _nec_subscribe_presence_received(self, obj):
|
||||||
if self.config['block_subscription_requests'] and \
|
if self.config['block_subscription_requests'] and \
|
||||||
not app.contacts.get_contacts(obj.conn.name, obj.jid):
|
not app.contacts.get_contacts(obj.conn.name, obj.jid):
|
||||||
log.info('discarding subscription request from %s' % obj.jid)
|
log.info('discarding subscription request from %s', obj.jid)
|
||||||
|
return True
|
||||||
|
|
||||||
|
if obj.jid.split("@", 1)[1] in self.block_domains:
|
||||||
|
log.info('discarding subscription request from %s, domain is blocked', obj.jid)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@log_calls('AntiSpamPlugin')
|
@log_calls('AntiSpamPlugin')
|
||||||
@@ -217,6 +234,8 @@ class AntiSpamPluginConfigDialog(GajimPluginConfigDialog):
|
|||||||
widget.set_text(str(self.plugin.config['msgtxt_answer']))
|
widget.set_text(str(self.plugin.config['msgtxt_answer']))
|
||||||
widget = self.xml.get_object('antispam_for_conference')
|
widget = self.xml.get_object('antispam_for_conference')
|
||||||
widget.set_active(self.plugin.config['antispam_for_conference'])
|
widget.set_active(self.plugin.config['antispam_for_conference'])
|
||||||
|
widget = self.xml.get_object('block_domains_entry')
|
||||||
|
widget.set_text(str(self.plugin.config['block_domains']))
|
||||||
|
|
||||||
def on_block_pubsub_messages_checkbutton_toggled(self, button):
|
def on_block_pubsub_messages_checkbutton_toggled(self, button):
|
||||||
self.plugin.config['block_pubsub_messages'] = button.get_active()
|
self.plugin.config['block_pubsub_messages'] = button.get_active()
|
||||||
@@ -250,4 +269,10 @@ class AntiSpamPluginConfigDialog(GajimPluginConfigDialog):
|
|||||||
|
|
||||||
def on_antispam_for_conference_checkbutton_toggled(self, button):
|
def on_antispam_for_conference_checkbutton_toggled(self, button):
|
||||||
self.plugin.config['antispam_for_conference'] = button.get_active()
|
self.plugin.config['antispam_for_conference'] = button.get_active()
|
||||||
|
|
||||||
|
def on_block_domains_entry_changed(self, entry):
|
||||||
|
try:
|
||||||
|
block_domains = self.plugin.config['block_domains'] = entry.get_text()
|
||||||
|
self.plugin.block_domains = [h.strip() for h in block_domains.split(",") if len(h.strip())]
|
||||||
|
except Exception as e:
|
||||||
|
log.debug(str(e))
|
||||||
|
|||||||
@@ -193,6 +193,35 @@
|
|||||||
<property name="position">7</property>
|
<property name="position">7</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkVBox" id="block_domains_box">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="spacing">6</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel" id="block_domains_label">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label" translatable="yes">Block Domains:</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="position">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkEntry" id="block_domains_entry">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<signal name="changed" handler="on_block_domains_entry_changed"/>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkCheckButton" id="antispam_for_conference">
|
<object class="GtkCheckButton" id="antispam_for_conference">
|
||||||
<property name="label" translatable="yes">Enable for conferences</property>
|
<property name="label" translatable="yes">Enable for conferences</property>
|
||||||
|
|||||||
Reference in New Issue
Block a user