Commit d3e2fd54 authored by Br0nek's avatar Br0nek

[anti_spam] v1.4.3 more in CHANGELOG

parent f59deb20
## [Unreleased]
### Added
- Sending confirmation message that anti spam check was passed. It can be disabled in plugin gui config.
## [1.4.3] - 2016-12-04
### Added
- Filtering 'normal' type messages
### Changed
- User from private conference conversation permanently stored in file
- Switched to GTK3
### Fixed
- Messages that was sent before correct answer was marked as received
- Chat between the two antispam plugins
## [0.4.2] - 2016-11-28
### Added
- Anti spam question functionality
- This CHANGELOG
- README with some explanation of functionality
### Changed
- homepage in manifest.ini
# Anti_spam Plugin for Gajim
This Plugin allows you to dissociate itself from the spam.
## Installation
Use special plugin, that manages automatic download and installation of others plugins, it is called Plugin Installer.
## Options
### Block pubsub
Block incoming messages from pubsub
### Message size limit
Block incoming messages that have size more than configured. Default value -1 mean that any sized messages are coming.
### Anti spam question
Block incoming messages from users not in your roster. In response, the Plugin sends a question that you configured. After correct answer(also configurable) you will receive all new messages from user.
**Attention!** All messages before correct answer will be lost.
Also you can enable this function, in Plugin config, for conference private messages. In some servers, the question in conference private does not reach your interlocutor. This can lead to the fact that you will not receive any messages from him, and he will not know it.
\ No newline at end of file
......@@ -25,7 +25,8 @@ Block some incoming messages
'''
from gi.repository import Gtk
from common import ged
import nbxmpp
from common import gajim, ged
from plugins import GajimPlugin
from plugins.helpers import log, log_calls
......@@ -45,9 +46,13 @@ class AntiSpamPlugin(GajimPlugin):
'atom-entry-received': (ged.POSTCORE,
self._nec_atom_entry_received),
'message-received': (ged.PRECORE,
self._nec_message_received_received),
'decrypted-message-received': (ged.PRECORE,
self._nec_decrypted_message_received_received),
'subscribe-presence-received': (ged.POSTCORE,
self._nec_subscribe_presence_received),
'message-outgoing': (ged.OUT_PRECORE,
self._nec_message_outgoing)
}
self.config_default_values = {
......@@ -55,8 +60,18 @@ class AntiSpamPlugin(GajimPlugin):
'disable_xhtml_muc': (False, ''),
'disable_xhtml_pm': (False, ''),
'block_subscription_requests': (False, ''),
'msgtxt_limit': (-1, ''),
'msgtxt_question': ('Please answer: 12 x 12 =', ''),
'msgtxt_answer': ('', ''),
'antispam_for_conference': (False, ''),
'conference_white_list': ([], ''), # conference private chat jid's
}
# List of outgoing jid's
# Needs to avoid chat of two anti spam plugins
# Contain all jid's where are you initiate a chat
self.outgoing_jids = []
@log_calls('AntiSpamPlugin')
def _nec_atom_entry_received(self, obj):
if self.config['block_pubsub_messages']:
......@@ -64,7 +79,7 @@ class AntiSpamPlugin(GajimPlugin):
return True
@log_calls('AntiSpamPlugin')
def _nec_decrypted_message_received_received(self, obj):
def _nec_message_received_received(self, obj):
if self.config['disable_xhtml_muc'] and obj.mtype == 'groupchat':
self.remove_xhtml(obj)
if self.config['disable_xhtml_pm'] and obj.gc_control and \
......@@ -72,6 +87,17 @@ class AntiSpamPlugin(GajimPlugin):
self.remove_xhtml(obj)
return False
@log_calls('AntiSpamPlugin')
def _nec_decrypted_message_received_received(self, obj):
if not obj.msgtxt:
return False
if self._nec_decrypted_message_received_question(obj):
return True
limit = self.config['msgtxt_limit']
if limit > -1 and len(obj.msgtxt) > limit:
return True
return False
@log_calls('AntiSpamPlugin')
def _nec_subscribe_presence_received(self, obj):
if self.config['block_subscription_requests'] and \
......@@ -79,6 +105,82 @@ class AntiSpamPlugin(GajimPlugin):
log.info('discarding subscription request from %s' % obj.jid)
return True
@log_calls('AntiSpamPlugin')
def _nec_decrypted_message_received_question(self, obj):
if obj.mtype != 'chat' and obj.mtype != 'normal':
return False
tjid = obj.jid if obj.mtype == 'normal' else obj.fjid
if tjid in self.outgoing_jids:
return False
answer = self.config['msgtxt_answer']
if len(answer) == 0:
return False
block_conference = self.config['antispam_for_conference']
is_conference = gajim.contacts.is_gc_contact(obj.conn.name, obj.fjid)
if not block_conference and is_conference:
return False
jid = obj.jid if not is_conference else obj.fjid
# If we receive conference privat message or direct message from unknown user than
# anti spam question will send in background mode, without any notification for us
# There are two methods to see who wrote you and not passed filter:
# 1. Using XML console
# 2. Running Gajim with log info messages and see logs (probably gajim.log file)
if is_conference or not gajim.contacts.get_contacts(obj.conn.name, jid):
if not self.contain_answer(obj.msgtxt, answer):
if is_conference and jid in self.config['conference_white_list']:
return False
self.send_question(obj, jid)
return True
else:
if is_conference and jid not in self.config['conference_white_list']:
self.config['conference_white_list'].append(jid)
# Need to save because 'append' method does not implement __setitem__ method
self.config.save()
return False
@log_calls('AntiSpamPlugin')
def _nec_message_outgoing(self, obj):
if obj.type_ != 'chat' and obj.type_ != 'normal':
return
if isinstance(obj.jid, list):
for i in obj.jid:
if i not in self.outgoing_jids:
self.outgoing_jids.append(i)
else:
if obj.jid not in self.outgoing_jids:
self.outgoing_jids.append(obj.jid)
def send_question(self, obj, jid):
if obj.mtype != 'chat' and obj.mtype != 'normal':
log.info('Anti_spam wrong message type: %s', obj.mtype)
return
# only for 'chat' messages
if obj.receipt_request_tag and obj.mtype == 'chat':
receipt = nbxmpp.Message(to=obj.fjid, typ='chat')
receipt.setTag('received', namespace='urn:xmpp:receipts', attrs={'id': obj.id_})
if obj.thread_id:
receipt.setThread(obj.thread_id)
gajim.connections[obj.conn.name].connection.send(receipt, now=True)
question = self.config['msgtxt_question']
log.info('Anti_spam enabled for %s, question: %s', jid, question)
message = _('Antispam enabled. Please answer the question. The message must only ' + \
'contain the answer. (Messages sent before the correct answer, will be lost): ') \
+ question
if obj.mtype == 'chat':
stanza = nbxmpp.Message(to=jid, body=message, typ=obj.mtype)
else: # for 'normal' type
stanza = nbxmpp.Message(to=jid, body=message, subject='Antispam enabled', typ=obj.mtype)
gajim.connections[obj.conn.name].connection.send(stanza, now=True)
def contain_answer(self, msg, answer):
return answer in msg.split('\n')
def remove_xhtml(self, obj):
html_node = obj.stanza.getTag('html')
if html_node:
......@@ -110,6 +212,14 @@ class AntiSpamPluginConfigDialog(GajimPluginConfigDialog):
widget.set_active(self.plugin.config['disable_xhtml_pm'])
widget = self.xml.get_object('block_subscription_requests_checkbutton')
widget.set_active(self.plugin.config['block_subscription_requests'])
widget = self.xml.get_object('message_size_limit_entry')
widget.set_text(str(self.plugin.config['msgtxt_limit']))
widget = self.xml.get_object('antispam_question')
widget.set_text(str(self.plugin.config['msgtxt_question']))
widget = self.xml.get_object('antispam_answer')
widget.set_text(str(self.plugin.config['msgtxt_answer']))
widget = self.xml.get_object('antispam_for_conference')
widget.set_active(self.plugin.config['antispam_for_conference'])
def on_block_pubsub_messages_checkbutton_toggled(self, button):
self.plugin.config['block_pubsub_messages'] = button.get_active()
......@@ -122,3 +232,25 @@ class AntiSpamPluginConfigDialog(GajimPluginConfigDialog):
def on_block_subscription_requests_checkbutton_toggled(self, button):
self.plugin.config['block_subscription_requests'] = button.get_active()
def on_message_size_limit_entry_changed(self, entry):
try:
self.plugin.config['msgtxt_limit'] = int(entry.get_text())
except Exception:
pass
def on_message_question_entry_changed(self, entry):
try:
self.plugin.config['msgtxt_question'] = entry.get_text()
except Exception:
pass
def on_message_answer_entry_changed(self, entry):
try:
self.plugin.config['msgtxt_answer'] = entry.get_text()
except Exception:
pass
def on_antispam_for_conference_checkbutton_toggled(self, button):
self.plugin.config['antispam_for_conference'] = button.get_active()
......@@ -69,6 +69,147 @@
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="box1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Message size limit:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="message_size_limit_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<signal name="changed" handler="on_message_size_limit_entry_changed"/>
</object>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkHSeparator" id="hseparator1">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">5</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label_question">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Anti spam question (Leave an empty answer field to disable this function):</property>
<property name="wrap">True</property>
<attributes>
<attribute name="style" value="italic"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="position">6</property>
<property name="padding">3</property>
</packing>
</child>
<child>
<object class="GtkVBox" id="questionbox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Question:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="antispam_question">
<property name="visible">True</property>
<property name="can_focus">True</property>
<signal name="changed" handler="on_message_question_entry_changed"/>
</object>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Answer:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="antispam_answer">
<property name="visible">True</property>
<property name="can_focus">True</property>
<signal name="changed" handler="on_message_answer_entry_changed"/>
</object>
<packing>
<property name="expand">False</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">7</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="antispam_for_conference">
<property name="label" translatable="yes">Enable for conferences</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">If checked, anti spam question will send for conference private messages</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="on_antispam_for_conference_checkbutton_toggled"/>
</object>
<packing>
<property name="expand">False</property>
<property name="position">8</property>
</packing>
</child>
</object>
</child>
</object>
......
[info]
name: Anti Spam
short_name: anti_spam
version: 0.3.1
version: 1.4.3
description: Block some incoming messages.
authors = Yann Leboulanger <asterix@lagaule.org>
Denis Fomin <fominde@gmail.com>
homepage = http://trac-plugins.gajim.org/wiki/AntiSpamPlugin
Ilya Kanyukov <ilya.kanukov@gmail.com>
homepage = https://dev.gajim.org/gajim/gajim-plugins/wikis/AntiSpamPlugin
min_gajim_version: 0.16.10
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment