def has_aop_in(bot, id, chan, ret): id_str = "%s!%s@%s" % tuple(id) for op in conf.get(chan.lower(), []): if "!" in op or "@" in op: # Match against a nick!user@host with wildcards. try: op = re.compile(util.wc_to_re(op), flags=re.I) except re.error: continue if op.match(id_str): yield ret(True) return else: # Match against an access name, according to 'identity'. access = yield identity.check_access(bot, id, op) if access: yield ret(True) return yield ret(False)
def check(bot, id, ret): if identify_check(id): yield ret(True); return if os.path.exists(ADMINS_FILE): with open(ADMINS_FILE) as file: admins = re.findall(r'\S+', file.read()) for admin in admins: if any(c in admin for c in '!@*?'): # Verify against a hostmask with wildcards. hostmask = '%s!%s@%s' % id if re.match(util.wc_to_re(admin), hostmask, re.I): yield ret(True); return else: # Verify an access name according to the 'identity' module. access = yield identity.check_access(bot, id, admin) if access: yield ret(True); return yield ret(False)
def match_id(query, id): id_str = '%s!%s@%s' % tuple(id) if re.search(r'!|@', query) else id.nick for part in query.split('/'): rexp = part if '$' in part else wc_to_re(part) if re.match(rexp, id_str, re.I) is not None: return True return False
def h_seen(bot, id, target, args, full_msg): chan = None match = re.match(r'(#\S+)\s*(.*)', args) if match: is_admin = yield auth.check(bot, id) if is_admin: chan = match.group(1).lower() args = match.group(2) if not chan and target: chan = target.lower() elif not chan: return if not args: return if re.search(r'!|@', args): pattern = util.wc_to_re(args) else: pattern = util.wc_to_re('%s!*@*' % args) # matching_nicks[nick.lower()] = (max_time, id_case) matching_nicks = dict() in_channel = False for cnick in channel.track_channels.get(chan, ()): cmask = yield identity.get_hostmask(bot, cnick) if re.match(pattern, cmask, re.I): cid = util.ID(*re.match(r'(.*?)!(.*?)@(.*)', cmask).groups()) matching_nicks[cid.nick.lower()] = (None, cid) in_channel = True continue state = get_state() combined_record = dict() for rmask, record in state.get(chan, dict()).iteritems(): if re.match(pattern, rmask, re.I): if 'id_case' in record: rmask = record['id_case'].encode('utf8') rid = util.ID(*re.match(r'(.*?)!(.*?)@(.*)', rmask).groups()) record = attribute_record_to(record, rid) combined_record = combine_records(combined_record, record) max_time = max( record[et]['time'] for et in EVENT_TYPES if et in record) if (rid.nick.lower() not in matching_nicks or matching_nicks[rid.nick.lower()][0] is not None and matching_nicks[rid.nick.lower()][0] < max_time): matching_nicks[rid.nick.lower()] = (max_time, rid) def nick_sort_key(nick): max_time = matching_nicks[nick.lower()][0] return -max_time if max_time is not None else None nicks = sorted(matching_nicks.iterkeys(), key=nick_sort_key) if nicks: if len(matching_nicks) > 4: nicks = nicks[:3] nicks += ['one of %d others' % (len(matching_nicks)-3)] id_name = ''.join('%s%s' % ( ' or ' if i > 0 and i+1 == len(nicks) else ', ' if i > 0 else '', '\2%s\2' % matching_nicks[nick][1].nick if nick in matching_nicks else nick ) for (i, nick) in izip(count(), nicks)) else: id_name = args reply(bot, id, target, record_string( id_name = id_name, record = combined_record, now = time.time(), in_channel = in_channel, plural = len(nicks) > 1))
'*i*.tinypic.com', ) PATH_RE = re.compile( r'\.(png|jpe?g|gif|webm)(~[^/]*)?$') CACHE_SIZE = 1024 REPEAT_S = 60*60*3 UPLOAD_RETRIES = 10 UPLOAD_RETRY_S = 60 link, install, uninstall = util.LinkSet().triple() mirror_hosts_re = re.compile( '^(%s)$' % '|'.join(util.wc_to_re(h, anchor=False) for h in MIRROR_HOSTS)) ssl_context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) chan_times = defaultdict(dict) cache_old = dict() cache_new = dict() def reload(prev): if hasattr(prev, 'chan_times') and isinstance(prev.chan_times, dict): chan_times.update(prev.chan_times) if hasattr(prev, 'cache_old') and isinstance(prev.cache_old, dict): cache_old.update(prev.cache_old) if hasattr(prev, 'cache_new') and isinstance(prev.cache_new, dict): cache_new.update(prev.cache_new)
def check_access(bot, query, name, ret): name = name.lower() if isinstance(query, tuple): nick = query.nick.lower() host = ('%s!%s@%s' % query).lower() id = query else: nick = query.lower() host = yield get_hostmask(bot, nick) if host: match = re.match(r'(.*)!(.*)@(.*)$', host) id = util.ID(*match.groups()) else: id = None # If a positive result is already cached, return that result. if nick in track_id and name in track_id[nick].access: yield ret(True) return creds = credentials.get(name, list()) creds = sorted(creds, key=lambda cred: 0 if cred[0] == 'hostmask' else 1 if cred[0] == 'access' else 2 if cred[0] == 'prev_hosts' else 3 if cred[0] == 'nickserv' else 4) has_access = False for cred in creds: if cred[0] == 'hostmask' and len(cred) > 1: # Authenticate using a hostmask with wildcards. pattern = util.wc_to_re(cred[1]) if host and re.match(pattern, host, re.I): has_access = True break elif cred[0] == 'nickserv' and len(cred) > 1: # Authenticate using NickServ STATUS. cred_nick = cred[1].lower() if cred_nick != nick: continue status = yield nickserv.status(bot, nick) if status > 1: has_access = True break elif cred[0] == 'prev_hosts' and len(cred) > 1: # Authenticate using previously authenticated hosts. if not id or name.lower() not in prev_hosts: continue userhost = '%s@%s' % (id.user, id.host) if userhost in prev_hosts[name][-cred[1]:]: has_access = True break elif cred[0] == 'access' and len(cred) > 1: # Authenticate based on a different access name. has_access = yield check_access(bot, id or nick, cred[1]) if has_access: break if has_access: yield grant_access(bot, id or nick, name) yield ret(has_access)