From b95afa146457135faffd724a1658c4c118ba285d Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Sun, 6 Dec 2020 20:07:45 -0500 Subject: [PATCH 1/2] preemptively filter out masks from amodes in atheme import --- distrib/atheme/atheme2json.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/distrib/atheme/atheme2json.py b/distrib/atheme/atheme2json.py index 5dd9aaa9..78768adc 100755 --- a/distrib/atheme/atheme2json.py +++ b/distrib/atheme/atheme2json.py @@ -2,9 +2,12 @@ import json import logging +import re import sys from collections import defaultdict +MASK_MAGIC_REGEX = re.compile(r'[*?!@]') + def to_unixnano(timestamp): return int(timestamp) * (10**9) @@ -100,6 +103,8 @@ def convert(infile): # channel access lists # CA #mychannel shivaram +AFORafhioqrstv 1600134478 shivaram chname, username, flags, set_at = parts[1], parts[2], parts[3], int(parts[4]) + if MASK_MAGIC_REGEX.search(username): + continue chname = parts[1] chdata = out['channels'][chname] flags = parts[3] From 468b5a4a3967e1ac5bdf4c2d1c3cf2822bb96942 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Sun, 6 Dec 2020 20:50:06 -0500 Subject: [PATCH 2/2] fix #1403 Handle the case where atheme had a successor, but didn't correctly elect them as founder (?) --- distrib/atheme/atheme2json.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/distrib/atheme/atheme2json.py b/distrib/atheme/atheme2json.py index 78768adc..b2971edf 100755 --- a/distrib/atheme/atheme2json.py +++ b/distrib/atheme/atheme2json.py @@ -140,14 +140,31 @@ def convert(infile): chdata['amode'][username] = 'h' elif 'v' in flags or 'V' in flags: chdata['amode'][username] = 'v' + elif 'S' in flags: + # take the first entry as the successor + if not chdata.get('successor'): + chdata['successor'] = username else: pass # do some basic integrity checks + def validate_user(name): + if not name: + return False + return bool(out['users'].get(name)) + + invalid_channels = [] + for chname, chdata in out['channels'].items(): - founder = chdata.get('founder') - if founder not in out['users']: - raise ValueError("no user corresponding to channel founder", chname, chdata.get('founder')) + if not validate_user(chdata.get('founder')): + if validate_user(chdata.get('successor')): + chdata['founder'] = chdata['successor'] + else: + invalid_channels.append(chname) + + for chname in invalid_channels: + logging.warning("Unable to find a valid founder for channel %s, discarding it", chname) + del out['channels'][chname] return out