Commit 8f48f9bf authored by Br0nek's avatar Br0nek

[anti_spam] Added anti spam question functionality

parent 82447358
## [Unreleased]
### Changed
- User from private conference conversation permanently stored in file
### Fixed
- Messages sent before correct answer marked as received
## [0.4.2] - 2016-11-28
### Added
- Anti spam question functionality
- This CHANGELOG
- README with some explanation of functionality
### Changed
- homepage in manifest.ini
\ No newline at end of file
# 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 be 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,11 +25,12 @@ Block some incoming messages
'''
import gtk
from common import ged
from common import gajim, ged
from plugins import GajimPlugin
from plugins.helpers import log, log_calls
from plugins.gui import GajimPluginConfigDialog
from common.connection_handlers_events import MessageOutgoingEvent
class AntiSpamPlugin(GajimPlugin):
......@@ -57,8 +58,14 @@ class AntiSpamPlugin(GajimPlugin):
'disable_xhtml_pm': (False, ''),
'block_subscription_requests': (False, ''),
'msgtxt_limit': (-1, ''),
'msgtxt_question': ('Please answer: 12 x 12 =', ''),
'msgtxt_answer': ('', ''),
'antispam_for_conference': (False, ''),
}
# Temporary white list
self.conference_white_list = []
@log_calls('AntiSpamPlugin')
def _nec_atom_entry_received(self, obj):
if self.config['block_pubsub_messages']:
......@@ -78,6 +85,8 @@ class AntiSpamPlugin(GajimPlugin):
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
......@@ -90,6 +99,44 @@ 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':
return False
answer = self.config['msgtxt_answer']
if len(answer) == 0:
return False
block_conference = self.config['antispam_for_conference']
is_conference = obj.jid.find('@conference.') >= 0
if not block_conference and is_conference:
return False
jid = obj.jid if not is_conference else obj.fjid
if not gajim.contacts.get_contacts(obj.conn.name, jid):
if obj.msgtxt != answer:
if is_conference and self.conference_white_list.count(jid) > 0:
return False
log.info('Info jid = %r', jid)
self.send_question(obj, jid)
return True
else:
if is_conference and self.conference_white_list.count(jid) == 0:
self.conference_white_list.append(jid)
return False
def send_question(self, obj, jid):
question = self.config['msgtxt_question']
log.info('Please answer the question: %s' % question)
message = _('Antispam enabled. Please answer the question: ') + question
current_status = gajim.config.get_per('soundevents', 'message_sent', 'enabled')
# workaround for the sound of sent message
if current_status:
gajim.config.set_per('soundevents', 'message_sent', 'enabled', False)
gajim.nec.push_outgoing_event(MessageOutgoingEvent(None,
account=obj.conn.name, jid=jid, message=message,
type_='chat', automatic_message=True))
if current_status:
gajim.config.set_per('soundevents', 'message_sent', 'enabled', current_status)
def remove_xhtml(self, obj):
html_node = obj.stanza.getTag('html')
if html_node:
......@@ -123,6 +170,12 @@ class AntiSpamPluginConfigDialog(GajimPluginConfigDialog):
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()
......@@ -141,3 +194,19 @@ class AntiSpamPluginConfigDialog(GajimPluginConfigDialog):
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()
\ No newline at end of file
......@@ -113,8 +113,114 @@
<property name="fill">True</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="fill">True</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="fill">True</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="fill">True</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" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</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="fill">True</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" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</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 be send for conference private messages</property>
<property name="xalign">0.5</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="on_antispam_for_conference_checkbutton_toggled" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">8</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
[info]
name: Anti Spam
short_name: anti_spam
version: 0.4.1
version: 0.4.2
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
max_gajim_version: 0.16.9
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