Add non SASL auth back to statusbot

Some networks don't support SASL and we want to support those networks.
This adds non SASL auth back to this IRC bot.

Note that networks like OFTC don't support identity-msg cap extensions.
For this reason we also remove the cap checking for authenticated nicks
in this bot. Instead we will rely on nick enforcement by nickserv.

Change-Id: I81381398b4c100990c04f454191cee52568dbdfe
This commit is contained in:
Clark Boylan 2021-05-28 13:04:04 -07:00
parent 0d29658781
commit 4aa826274d
1 changed files with 78 additions and 48 deletions

View File

@ -20,8 +20,9 @@
[ircbot]
nick=NICKNAME
pass=PASSWORD
server=irc.freenode.net
server=irc.oftc.net
port=6697
use_sasl=False
channels=foo,bar
nicks=alice,bob
@ -313,48 +314,12 @@ class AlertFile(UpdateInterface):
self.write(None)
class StatusBot(SASL, SSL, irc.bot.SingleServerIRCBot):
class BaseStatusBot(SSL, irc.bot.SingleServerIRCBot):
log = logging.getLogger("statusbot.bot")
def __init__(self, channels, nicks, publishers, successlog, thankslog,
nickname, password, server, port=6697):
super(StatusBot, self).__init__(
server_list=[(server, port)],
nickname=nickname,
realname=nickname,
ident_password=password,
channels=channels)
self.channel_list = channels
self.nicks = nicks
self.nickname = nickname
self.password = password
self.identify_msg_cap = False
self.topics = {}
self.current_topic = None
self.publishers = publishers
self.successlog = successlog
self.thankslog = thankslog
def on_welcome(self, c, e):
self.identify_msg_cap = False
self.log.debug("Requesting identify-msg capability")
c.cap('REQ', 'identify-msg')
c.cap('END')
def on_cap(self, c, e):
self.log.debug("Received cap response %s" % repr(e.arguments))
if e.arguments[0] == 'ACK' and 'identify-msg' in e.arguments[1]:
self.log.debug("identify-msg cap acked")
self.identify_msg_cap = True
def on_pubmsg(self, c, e):
if not self.identify_msg_cap:
self.log.debug("Ignoring message because identify-msg "
"cap not enabled")
return
nick = e.source.split('!')[0]
auth = e.arguments[0][0]
msg = e.arguments[0][1:]
msg = e.arguments[0]
# Unprivileged commands
if msg.startswith('#success'):
self.handle_success_command(e.target, nick, msg)
@ -365,10 +330,6 @@ class StatusBot(SASL, SSL, irc.bot.SingleServerIRCBot):
# Privileged commands
if not msg.startswith('#status'):
return
if auth != '+':
self.log.debug("Ignoring message from unauthenticated "
"user %s" % nick)
return
if nick not in self.nicks:
self.log.debug("Ignoring message from untrusted user %s" % nick)
return
@ -474,6 +435,62 @@ class StatusBot(SASL, SSL, irc.bot.SingleServerIRCBot):
time.sleep(ANTI_FLOOD_SLEEP)
class NoSASLStatusBot(BaseStatusBot):
def __init__(self, channels, nicks, publishers, successlog, thankslog,
nickname, password, server, port=6697):
super(NoSASLStatusBot, self).__init__(
server_list=[(server, port)],
nickname=nickname,
realname=nickname,
ident_password=password)
self.channel_list = channels
self.nicks = nicks
self.nickname = nickname
self.password = password
self.topics = {}
self.current_topic = None
self.publishers = publishers
self.successlog = successlog
self.thankslog = thankslog
def on_welcome(self, c, e):
self.log.debug("Identifying to nickserv")
c.privmsg("nickserv", "identify %s " % self.password)
for channel in self.channel_list:
self.log.info("Joining %s" % channel)
c.join(channel)
time.sleep(ANTI_FLOOD_SLEEP)
def on_nicknameinuse(self, c, e):
self.log.debug("Nickname in use, releasing")
c.nick(c.get_nickname() + "_")
c.privmsg("nickserv", "identify %s " % self.password)
c.privmsg("nickserv", "ghost %s %s" % (self.nickname, self.password))
c.privmsg("nickserv", "release %s %s" % (self.nickname, self.password))
time.sleep(ANTI_FLOOD_SLEEP)
c.nick(self.nickname)
class SASLStatusBot(SASL, BaseStatusBot):
def __init__(self, channels, nicks, publishers, successlog, thankslog,
nickname, password, server, port=6697):
super(SASLStatusBot, self).__init__(
server_list=[(server, port)],
nickname=nickname,
realname=nickname,
ident_password=password,
channels=channels)
self.channel_list = channels
self.nicks = nicks
self.nickname = nickname
self.password = password
self.topics = {}
self.current_topic = None
self.publishers = publishers
self.successlog = successlog
self.thankslog = thankslog
def _main(configpath):
config = ConfigParser.RawConfigParser()
config.read(configpath)
@ -490,11 +507,24 @@ def _main(configpath):
if config.has_section('twitter'):
publishers.append(Tweet(config))
bot = StatusBot(channels, nicks, publishers, successlog, thankslog,
config.get('ircbot', 'nick'),
config.get('ircbot', 'pass'),
config.get('ircbot', 'server'),
config.getint('ircbot', 'port'))
if config.has_option('ircbot', 'use_sasl'):
use_sasl = config.getboolean('ircbot', 'use_sasl')
else:
use_sasl = False
if use_sasl:
bot = SASLStatusBot(channels, nicks, publishers, successlog,
thankslog,
config.get('ircbot', 'nick'),
config.get('ircbot', 'pass'),
config.get('ircbot', 'server'),
config.getint('ircbot', 'port'))
else:
bot = NoSASLStatusBot(channels, nicks, publishers, successlog,
thankslog,
config.get('ircbot', 'nick'),
config.get('ircbot', 'pass'),
config.get('ircbot', 'server'),
config.getint('ircbot', 'port'))
bot.start()