From 2c656341e29de400f081a0670364b1cf6a915bf3 Mon Sep 17 00:00:00 2001 From: James Lu Date: Mon, 11 Jul 2016 15:01:34 -0700 Subject: [PATCH] handlers: Optionally disable extended WHOIS replies for users marked as a bot Closes #271. This adds a new option, "whois_show_extensions_to_bots", to the bot: section of the config. --- coremods/handlers.py | 12 +++++++++--- example-conf.yml | 4 ++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/coremods/handlers.py b/coremods/handlers.py index 0d56a8e..aebe538 100644 --- a/coremods/handlers.py +++ b/coremods/handlers.py @@ -2,7 +2,7 @@ handlers.py - Implements miscellaneous IRC command handlers (WHOIS, services login, etc.) """ -from pylinkirc import utils +from pylinkirc import utils, conf from pylinkirc.log import log def handle_whois(irc, source, command, args): @@ -17,6 +17,7 @@ def handle_whois(irc, source, command, args): server = irc.getServer(target) or irc.sid nick = user.nick sourceisOper = ('o', None) in irc.users[source].modes + sourceisBot = (irc.umodes.get('bot'), None) in irc.users[source].modes # Get the full network name. netname = irc.serverdata.get('netname', irc.name) @@ -88,8 +89,13 @@ def handle_whois(irc, source, command, args): # Show botmode info in WHOIS. f(server, 335, source, "%s :is a bot" % nick) - # Call custom WHOIS handlers via the PYLINK_CUSTOM_WHOIS hook. - irc.callHooks([source, 'PYLINK_CUSTOM_WHOIS', {'target': target, 'server': server}]) + # Call custom WHOIS handlers via the PYLINK_CUSTOM_WHOIS hook, unless the + # caller is marked a bot and the whois_show_extensions_to_bots option is False + if (sourceisBot and conf.conf['bot'].get('whois_show_extensions_to_bots')) or (not sourceisBot): + irc.callHooks([source, 'PYLINK_CUSTOM_WHOIS', {'target': target, 'server': server}]) + else: + log.debug('(%s) coremods.handlers.handle_whois: skipping custom whois handlers because ' + 'caller %s is marked as a bot', irc.name, source) # 318: End of WHOIS. f(server, 318, source, "%s :End of /WHOIS list" % nick) diff --git a/example-conf.yml b/example-conf.yml index 8025b2a..fc60a30 100644 --- a/example-conf.yml +++ b/example-conf.yml @@ -30,6 +30,10 @@ bot: # Defaults to true if not specified. whois_use_hideoper: true + # Determines whether extended WHOIS replies should be sent to users marked + # +B (bot). For better security, it is recommended to leave this off. + whois_show_extensions_to_bots: false + # Determines whether PyLink service clients should protect themselves from # kicks, kills, etc. using IRCd-side servprotect modes. For this to work # properly, this requires that PyLink be U-Lined (on most IRCds). Defaults to