diff --git a/plugins/changehost.py b/plugins/changehost.py index d080993..c3c58bb 100644 --- a/plugins/changehost.py +++ b/plugins/changehost.py @@ -30,12 +30,8 @@ def _changehost(irc, target, args): "Changehost will not function correctly!", irc.name) return - # Match against both the user's IP and real host. - target_host = irc.getHostmask(target, realhost=True) - target_ip = irc.getHostmask(target, ip=True) - for host_glob, host_template in changehost_hosts.items(): - if ircmatch.match(0, host_glob, target_host) or ircmatch.match(0, host_glob, target_ip): + if irc.matchHost(host_glob, target): # This uses template strings for simple substitution: # https://docs.python.org/3/library/string.html#template-strings template = string.Template(host_template) diff --git a/plugins/opercmds.py b/plugins/opercmds.py index a81f0ae..f5cd492 100644 --- a/plugins/opercmds.py +++ b/plugins/opercmds.py @@ -1,14 +1,6 @@ """ opercmds.py: Provides a subset of network management commands. """ - -# ircmatch library from https://github.com/mammon-ircd/ircmatch -# (pip install ircmatch) -try: - import ircmatch -except ImportError: - ircmatch = None - from pylinkirc import utils from pylinkirc.log import log @@ -19,41 +11,28 @@ def checkban(irc, source, args): Oper only. If a nick or hostmask is given, return whether the given banmask will match it. Otherwise, returns a list of connected users that would be affected by such a ban, up to 50 results.""" irc.checkAuthenticated(source, allowOper=False) - if ircmatch is None: - irc.reply("Error: missing ircmatch module (install it via 'pip install ircmatch').") - return - try: banmask = args[0] except IndexError: irc.reply("Error: Not enough arguments. Needs 1-2: banmask, nick or hostmask to check (optional).") return - # Casemapping value (0 is rfc1459, 1 is ascii) used by ircmatch. - if irc.proto.casemapping == 'rfc1459': - casemapping = 0 - else: - casemapping = 1 - - try: targetmask = args[1] except IndexError: # No hostmask was given, return a list of affected users. - irc.msg(source, "Checking matches for \x02%s\x02:" % banmask, notice=True) + irc.msg(source, "Checking for hosts that match \x02%s\x02:" % banmask, notice=True) results = 0 for uid, userobj in irc.users.copy().items(): - targetmask = irc.getHostmask(uid) - if ircmatch.match(casemapping, banmask, targetmask): + if irc.matchHost(banmask, uid): if results < 50: # XXX rather arbitrary limit - serverobj = irc.servers[irc.getServer(uid)] s = "\x02%s\x02 (%s@%s) [%s] {\x02%s\x02}" % (userobj.nick, userobj.ident, - userobj.host, userobj.realname, serverobj.name) + userobj.host, userobj.realname, irc.getFriendlyName(irc.getServer(uid))) # Always reply in private to prevent information leaks. - irc.msg(source, s, notice=True) + irc.reply(s, private=True) results += 1 else: if results: @@ -62,15 +41,9 @@ def checkban(irc, source, args): else: irc.msg(source, "No results found.", notice=True) else: - # Target can be both a nick (of an online user) or a hostmask. - uid = irc.nickToUid(targetmask) - if uid: - targetmask = irc.getHostmask(uid) - elif not utils.isHostmask(targetmask): - irc.reply("Error: Invalid nick or hostmask '%s'." % targetmask) - return - - if ircmatch.match(casemapping, banmask, targetmask): + # Target can be both a nick (of an online user) or a hostmask. irc.matchHost() handles this + # automatically. + if irc.matchHost(banmask, targetmask): irc.reply('Yes, \x02%s\x02 matches \x02%s\x02.' % (targetmask, banmask)) else: irc.reply('No, \x02%s\x02 does not match \x02%s\x02.' % (targetmask, banmask))