Do not accept messages from self JID

This commit is contained in:
Schimon Jehudah 2024-02-23 12:53:14 +00:00
parent bb9a1926f6
commit e13807442e
3 changed files with 41 additions and 31 deletions

View file

@ -143,10 +143,7 @@ class JabberClient:
xmpp.register_plugin('xep_0122') # Data Forms Validation xmpp.register_plugin('xep_0122') # Data Forms Validation
xmpp.register_plugin('xep_0153') # vCard-Based Avatars xmpp.register_plugin('xep_0153') # vCard-Based Avatars
xmpp.register_plugin('xep_0199', {'keepalive': True}) # XMPP Ping xmpp.register_plugin('xep_0199', {'keepalive': True}) # XMPP Ping
xmpp.register_plugin('xep_0203') # Delayed Delivery
xmpp.register_plugin('xep_0249') # Direct MUC Invitations xmpp.register_plugin('xep_0249') # Direct MUC Invitations
xmpp.register_plugin('xep_0297') # Stanza Forwarding
xmpp.register_plugin('xep_0356') # Privileged Entity
xmpp.register_plugin('xep_0363') # HTTP File Upload xmpp.register_plugin('xep_0363') # HTTP File Upload
xmpp.register_plugin('xep_0402') # PEP Native Bookmarks xmpp.register_plugin('xep_0402') # PEP Native Bookmarks
xmpp.register_plugin('xep_0444') # Message Reactions xmpp.register_plugin('xep_0444') # Message Reactions

View file

@ -1,2 +1,2 @@
__version__ = '0.1.16' __version__ = '0.1.17'
__version_info__ = (0, 1, 16) __version_info__ = (0, 1, 17)

View file

@ -238,20 +238,30 @@ class Slixfeed(slixmpp.ClientXMPP):
await self['xep_0115'].update_caps(jid=jid) await self['xep_0115'].update_caps(jid=jid)
# TODO Request for subscription
async def on_message(self, message): async def on_message(self, message):
jid = message["from"].bare jid = message['from'].bare
if (await get_chat_type(self, jid) == 'chat' and if jid == self.boundjid.bare:
not self.client_roster[jid]['to']): status_type = 'dnd'
XmppPresence.subscription(self, jid, 'subscribe') status_message = ('Slixfeed is not designed to receive messages '
await XmppRoster.add(self, jid) 'from itself')
status_message = '✒️ Share online status to receive updates' XmppPresence.send(self, jid, status_message,
status_type=status_type)
await asyncio.sleep(5)
status_message = ('Slixfeed news bot from RSS Task Force')
XmppPresence.send(self, jid, status_message) XmppPresence.send(self, jid, status_message)
message_subject = 'RSS News Bot' else:
message_body = 'Share online status to receive updates.' # TODO Request for subscription
XmppMessage.send_headline(self, jid, message_subject, message_body, if (await get_chat_type(self, jid) == 'chat' and
'chat') not self.client_roster[jid]['to']):
await process.message(self, message) XmppPresence.subscription(self, jid, 'subscribe')
await XmppRoster.add(self, jid)
status_message = '✒️ Share online status to receive updates'
XmppPresence.send(self, jid, status_message)
message_subject = 'RSS News Bot'
message_body = 'Share online status to receive updates.'
XmppMessage.send_headline(self, jid, message_subject,
message_body, 'chat')
await process.message(self, message)
# chat_type = message["type"] # chat_type = message["type"]
# message_body = message["body"] # message_body = message["body"]
# message_reply = message.reply # message_reply = message.reply
@ -1395,29 +1405,32 @@ class Slixfeed(slixmpp.ClientXMPP):
# form, this check is being done just in case. # form, this check is being done just in case.
jid = session['from'].bare jid = session['from'].bare
if jid == config.get_value('accounts', 'XMPP', 'operator'): if jid == config.get_value('accounts', 'XMPP', 'operator'):
if not self.is_component: # This will be changed with XEP-0222 XEP-0223 if self.is_component:
# NOTE This will be changed with XEP-0222 XEP-0223
text_info = ('Subscriber management options are '
'currently not available for Slixfeed '
'running as component. Once support for '
'XEP-0222 and XEP-0223 be added, this '
'panel will be usable for components as '
'well.')
session['has_next'] = False
session['next'] = None
session['notes'] = [['info', text_info]]
else:
form = self['xep_0004'].make_form('form', 'Admin Panel') form = self['xep_0004'].make_form('form', 'Admin Panel')
form['instructions'] = 'Administration actions' form['instructions'] = 'Administration actions'
options = form.add_field(var='action', options = form.add_field(var='action',
ftype='list-single', ftype='list-single',
label='Action', label='Manage',
desc='Select action type.', desc='Select action type.',
value='subscribers', value='subscribers',
required=True) required=True)
options.addOption('Manage bookmarks', 'bookmarks') options.addOption('Bookmarks', 'bookmarks')
options.addOption('Manage contacts', 'roster') options.addOption('Contacts', 'roster')
options.addOption('Manage subscribers', 'subscribers') options.addOption('Subscribers', 'subscribers')
session['payload'] = form session['payload'] = form
session['next'] = self._handle_admin_action session['next'] = self._handle_admin_action
session['has_next'] = True session['has_next'] = True
else:
text_info = ('Subscriber management options are currently not '
'available for Slixfeed running as component. '
'Once support for XEP-0222 and XEP-0223 be added, '
'this panel will be usable for components as well.')
session['has_next'] = False
session['next'] = None
session['notes'] = [['info', text_info]]
else: else:
logging.warning('An unauthorized attempt to access bookmarks has ' logging.warning('An unauthorized attempt to access bookmarks has '
'been detected!\n' 'been detected!\n'
@ -1824,7 +1837,7 @@ class Slixfeed(slixmpp.ClientXMPP):
session['next'] = self._handle_subscribers_complete session['next'] = self._handle_subscribers_complete
session['allow_prev'] = True session['allow_prev'] = True
session['payload'] = form session['payload'] = form
session['prev'] = self._handle_admin session['prev'] = self._handle_advanced
return session return session