Correctly check for new blacklisted hashed JIDs.
This commit is contained in:
parent
a2e5f652da
commit
f167625765
4 changed files with 14 additions and 46 deletions
|
@ -295,34 +295,6 @@ class BlockList:
|
||||||
with open(filename, 'w') as f: f.write(content)
|
with open(filename, 'w') as f: f.write(content)
|
||||||
return filename
|
return filename
|
||||||
|
|
||||||
|
|
||||||
def add_entry_to_blocklist(self, jabber_id, node_id, item_id):
|
|
||||||
"""
|
|
||||||
Update blocklist file.
|
|
||||||
|
|
||||||
Parameters
|
|
||||||
----------
|
|
||||||
jabber_id : str
|
|
||||||
Jabber ID.
|
|
||||||
node_id : str
|
|
||||||
Node name.
|
|
||||||
item_id : str
|
|
||||||
Item ID.
|
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
None.
|
|
||||||
"""
|
|
||||||
if jabber_id not in self.blocklist['entries']:
|
|
||||||
self.blocklist['entries'][jabber_id] = {}
|
|
||||||
if node_id not in self.blocklist['entries'][jabber_id]:
|
|
||||||
self.blocklist['entries'][jabber_id][node_id] = []
|
|
||||||
self.blocklist['entries'][jabber_id][node_id].append(item_id)
|
|
||||||
data = self.blocklist
|
|
||||||
content = tomli_w.dumps(data)
|
|
||||||
filename = BlockList.get_filename()
|
|
||||||
with open(filename, 'w') as f: f.write(content)
|
|
||||||
|
|
||||||
class String:
|
class String:
|
||||||
|
|
||||||
def md5_hash(url):
|
def md5_hash(url):
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
__version__ = '0.0.7'
|
__version__ = '0.0.8'
|
||||||
__version_info__ = (0, 0, 7)
|
__version_info__ = (0, 0, 8)
|
||||||
|
|
|
@ -47,8 +47,8 @@ class XmppClient(slixmpp.ClientXMPP):
|
||||||
self.data_accounts = Toml.open_file(filename_accounts)
|
self.data_accounts = Toml.open_file(filename_accounts)
|
||||||
self.data_accounts_xmpp = self.data_accounts['xmpp']
|
self.data_accounts_xmpp = self.data_accounts['xmpp']
|
||||||
# A handler for blocklist.
|
# A handler for blocklist.
|
||||||
filename_blocklist = os.path.join(self.directory_shared, 'blocklist.toml')
|
self.filename_blocklist = os.path.join(self.directory_shared, 'blocklist.toml')
|
||||||
self.blocklist = Toml.open_file(filename_blocklist)
|
self.blocklist = Toml.open_file(self.filename_blocklist)
|
||||||
# A handler for blocklist.
|
# A handler for blocklist.
|
||||||
filename_rtbl = os.path.join(self.directory_config, 'rtbl.toml')
|
filename_rtbl = os.path.join(self.directory_config, 'rtbl.toml')
|
||||||
self.data_rtbl = Toml.open_file(filename_rtbl)
|
self.data_rtbl = Toml.open_file(filename_rtbl)
|
||||||
|
@ -345,21 +345,17 @@ class XmppClient(slixmpp.ClientXMPP):
|
||||||
if subscribe['pubsub']['subscription']['subscription'] == 'subscribed':
|
if subscribe['pubsub']['subscription']['subscription'] == 'subscribed':
|
||||||
rtbl_list = await XmppPubsub.get_items(self, jabber_id, node_id)
|
rtbl_list = await XmppPubsub.get_items(self, jabber_id, node_id)
|
||||||
rtbl_items = rtbl_list['pubsub']['items']
|
rtbl_items = rtbl_list['pubsub']['items']
|
||||||
|
muc_bans_sha256 = self.blocklist['entries']['xmppbl.org']['muc_bans_sha256']
|
||||||
for item in rtbl_items:
|
for item in rtbl_items:
|
||||||
exist = False
|
|
||||||
item_id = item['id']
|
item_id = item['id']
|
||||||
for jid in self.blocklist['entries']:
|
if item_id not in muc_bans_sha256: muc_bans_sha256.append(item_id)
|
||||||
for node in jid:
|
|
||||||
for item in node:
|
|
||||||
if item_id == item:
|
|
||||||
exist = True
|
|
||||||
break
|
|
||||||
if not exist:
|
|
||||||
# TODO Extract items item_payload.find(namespace + 'title')
|
# TODO Extract items item_payload.find(namespace + 'title')
|
||||||
# NOTE (Pdb)
|
# NOTE (Pdb)
|
||||||
# for i in item['payload'].iter(): i.attrib
|
# for i in item['payload'].iter(): i.attrib
|
||||||
# {'reason': 'urn:xmpp:reporting:abuse'}
|
# {'reason': 'urn:xmpp:reporting:abuse'}
|
||||||
BlockList.add_entry_to_blocklist(self, jabber_id, node_id, item_id)
|
self.blocklist['entries']['xmppbl.org']['muc_bans_sha256'] = muc_bans_sha256
|
||||||
|
Toml.save_file(self.filename_blocklist, self.blocklist)
|
||||||
|
del self.filename_blocklist
|
||||||
# subscribe['from'] = xmppbl.org
|
# subscribe['from'] = xmppbl.org
|
||||||
# subscribe['pubsub']['subscription']['node'] = 'muc_bans_sha256'
|
# subscribe['pubsub']['subscription']['node'] = 'muc_bans_sha256'
|
||||||
subscriptions = await XmppPubsub.get_node_subscriptions(self, jabber_id, node_id)
|
subscriptions = await XmppPubsub.get_node_subscriptions(self, jabber_id, node_id)
|
||||||
|
|
|
@ -47,7 +47,7 @@ class XmppGroupchat:
|
||||||
.format(room))
|
.format(room))
|
||||||
elif result == 'conflict':
|
elif result == 'conflict':
|
||||||
number = str(random.randrange(1000, 5000))
|
number = str(random.randrange(1000, 5000))
|
||||||
await XmppMuc.join(self, room, alias + '_' + number)
|
await XmppMuc.join(self, room, alias + ' #' + number)
|
||||||
else:
|
else:
|
||||||
mucs_join_success.append(room)
|
mucs_join_success.append(room)
|
||||||
logger.info('Autojoin groupchat\n'
|
logger.info('Autojoin groupchat\n'
|
||||||
|
|
Loading…
Reference in a new issue