2010-05-24 13:38:06 +00:00
|
|
|
# -*- Encoding: utf-8 -*-
|
2008-07-20 15:59:27 +00:00
|
|
|
###
|
2010-05-24 13:38:06 +00:00
|
|
|
# Copyright (c) 2008-2010 Terence Simpson
|
2008-07-20 15:59:27 +00:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of version 2 of the GNU General Public License as
|
|
|
|
# published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
|
|
|
|
import supybot.utils as utils
|
|
|
|
from supybot.commands import *
|
|
|
|
import supybot.plugins as plugins
|
|
|
|
import supybot.ircutils as ircutils
|
|
|
|
import supybot.ircmsgs as ircmsgs
|
|
|
|
import supybot.callbacks as callbacks
|
|
|
|
import supybot.ircdb as ircdb
|
|
|
|
import supybot.conf as conf
|
|
|
|
import random, os, sys
|
|
|
|
|
|
|
|
def checkCapab(msg, irc):
|
|
|
|
try:
|
|
|
|
user = ircdb.users.getUser(msg.prefix[:msg.prefix.find('!')])
|
|
|
|
except:
|
|
|
|
irc.error(conf.supybot.replies.incorrectAuthentication())
|
|
|
|
return False
|
|
|
|
try:
|
|
|
|
if not user.capabilities.check('Admin'):
|
|
|
|
irc.error(conf.supybot.replies.noCapability() % 'Admin')
|
|
|
|
return False
|
|
|
|
except KeyError:
|
|
|
|
irc.error(conf.supybot.replies.noCapability() % 'Admin')
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
class IRCLogin(callbacks.Plugin):
|
|
|
|
"""Use @login to login, @reloadusers to reload the user list and @updateusers to update the user database from
|
|
|
|
launchpad"""
|
|
|
|
threaded = True
|
|
|
|
|
2010-02-20 10:31:13 +00:00
|
|
|
def __init__(self, irc):
|
|
|
|
super(IRCLogin, self).__init__(irc)
|
2010-04-28 12:09:12 +00:00
|
|
|
self._irc = irc
|
|
|
|
if hasattr(irc, 'getRealIrc'):
|
|
|
|
self._irc = irc.getRealIrc()
|
2010-02-20 10:31:13 +00:00
|
|
|
|
|
|
|
def die(self):
|
|
|
|
"""Disable identify-msg, if possible"""
|
|
|
|
if getattr(self._irc, '_Freenode_capabed', False):
|
|
|
|
# Only the CAP command can disable identify-msg not CAPAB
|
|
|
|
self._irc.queueMsg(ircmsgs.IrcMsg('CAP REQ -IDENTIFY-MSG')) # Disable identify-msg
|
|
|
|
self._irc._Freenode_capabed = self._irc._Freenode_capabed_notices = False
|
|
|
|
|
2008-07-20 15:59:27 +00:00
|
|
|
def login(self, irc, msg, args):
|
|
|
|
"""takes no arguments
|
|
|
|
|
|
|
|
Allows users who are identified to NickServ to login without a password.
|
|
|
|
"""
|
|
|
|
if not msg.tagged('identified'):
|
|
|
|
irc.error('You are not identified')
|
|
|
|
return
|
2008-11-26 14:34:47 +00:00
|
|
|
nick = msg.nick.lower()
|
|
|
|
user = None
|
2008-07-20 15:59:27 +00:00
|
|
|
try:
|
2010-04-30 12:50:43 +00:00
|
|
|
user = ircdb.users.getUser(msg.prefix)
|
2008-07-20 15:59:27 +00:00
|
|
|
except:
|
|
|
|
try:
|
2008-11-26 14:34:47 +00:00
|
|
|
user = ircdb.users.getUser(msg.prefix)
|
2008-07-20 15:59:27 +00:00
|
|
|
except:
|
2010-04-30 12:50:43 +00:00
|
|
|
for (id, obj) in ircdb.users.users.iteritems():
|
|
|
|
if obj.name.lower() == nick:
|
|
|
|
user = obj
|
|
|
|
if not user:
|
|
|
|
irc.error(conf.supybot.replies.incorrectAuthentication())
|
|
|
|
return
|
2009-10-12 18:26:35 +00:00
|
|
|
try:
|
2009-10-15 20:21:50 +00:00
|
|
|
user.addAuth(msg.prefix)
|
2009-10-12 18:26:35 +00:00
|
|
|
except:
|
|
|
|
pass
|
|
|
|
try:
|
|
|
|
ircdb.users.setUser(user, flush=False)
|
|
|
|
except:
|
|
|
|
pass
|
2008-07-20 15:59:27 +00:00
|
|
|
irc.replySuccess()
|
|
|
|
login = wrap(login)
|
|
|
|
|
2010-02-19 19:04:45 +00:00
|
|
|
@wrap
|
|
|
|
def identifymsg(self, irc, msg, args):
|
|
|
|
"""
|
|
|
|
takes no arguments.
|
|
|
|
Sends a requet for the identify-msg capability.
|
|
|
|
"""
|
2010-02-20 10:21:58 +00:00
|
|
|
self.do376(irc, msg, force=True)
|
2010-02-19 19:04:45 +00:00
|
|
|
irc.replySuccess()
|
|
|
|
|
|
|
|
@wrap
|
|
|
|
def haveidentifymsg(self, irc, msg, args):
|
2010-05-24 13:38:06 +00:00
|
|
|
""""
|
|
|
|
takes no arguments.
|
|
|
|
Displays if identify-msg is enabled or disabled.
|
|
|
|
"""
|
2010-03-28 03:34:17 +00:00
|
|
|
haveCap = getattr(self._irc, "_Freenode_capabed", False)
|
2010-02-19 19:11:10 +00:00
|
|
|
irc.reply("identify-msg is %sabled" % (haveCap and "En" or "Dis"))
|
2010-02-19 19:04:45 +00:00
|
|
|
|
2008-08-09 19:03:30 +00:00
|
|
|
def doPrivmsg(self, irc, msg):
|
2009-12-03 23:23:09 +00:00
|
|
|
if not conf.supybot.defaultIgnore(): # Only do this when defaultIgnore is set
|
2008-08-09 19:03:30 +00:00
|
|
|
return
|
|
|
|
if chr(1) in msg.args[1]:
|
|
|
|
return
|
2008-09-28 01:55:23 +00:00
|
|
|
try:
|
|
|
|
user = ircdb.users.getUser(msg.prefix)
|
|
|
|
if user.checkHostmask(msg.prefix):
|
|
|
|
return
|
|
|
|
except:
|
|
|
|
pass
|
2008-11-26 14:34:47 +00:00
|
|
|
|
|
|
|
text = callbacks.addressed(irc.nick, msg)
|
2010-01-30 15:19:53 +00:00
|
|
|
cmd = ''
|
2008-11-26 14:34:47 +00:00
|
|
|
if not text or text != "login":
|
|
|
|
if msg.args[1]:
|
2010-01-30 15:19:53 +00:00
|
|
|
if ircutils.isChannel(msg.args[0]):
|
|
|
|
if msg.args[1][0] == '@':
|
|
|
|
cmd = msg.args[1][1:]
|
2008-11-26 14:34:47 +00:00
|
|
|
else:
|
2010-01-30 15:19:53 +00:00
|
|
|
if msg.args[1][0] == '@':
|
|
|
|
cmd = msg.args[1][1:]
|
|
|
|
else:
|
|
|
|
cmd = msg.args[1]
|
2008-11-26 14:34:47 +00:00
|
|
|
if cmd != "login":
|
|
|
|
return
|
|
|
|
else:
|
2008-08-09 19:03:30 +00:00
|
|
|
return
|
2010-05-24 13:38:06 +00:00
|
|
|
self.log.info("IRCLogin: Calling login for %s" % msg.prefix)
|
2008-08-09 19:03:30 +00:00
|
|
|
self._callCommand(["login"], irc, msg, [])
|
|
|
|
|
2008-07-20 15:59:27 +00:00
|
|
|
def do290(self, irc, msg):
|
2009-11-11 14:53:30 +00:00
|
|
|
"""hyperiron CAPAB reply"""
|
2010-03-28 03:34:17 +00:00
|
|
|
self._irc._Freenode_capabed_notices = False
|
2009-11-11 14:53:30 +00:00
|
|
|
if msg.args[1].lower() == "identify-msg":
|
2010-03-28 03:34:17 +00:00
|
|
|
self._irc._Freenode_capabed = True
|
2009-11-11 14:53:30 +00:00
|
|
|
else:
|
2010-03-28 03:34:17 +00:00
|
|
|
self._irc._Freenode_capabed = False
|
2009-11-11 14:53:30 +00:00
|
|
|
|
2009-11-09 19:25:59 +00:00
|
|
|
def doCap(self, irc, msg):
|
2009-11-11 14:53:30 +00:00
|
|
|
"""ircd-seven CAP reply"""
|
|
|
|
cmd = msg.args[1].lower()
|
|
|
|
args = msg.args[2].lower()
|
|
|
|
if cmd == "ls": # Got capability listing
|
|
|
|
if "identify-msg" in args: # identify-msg is a capability on this server
|
|
|
|
irc.queueMsg(ircmsgs.IrcMsg('CAP REQ IDENTIFY-MSG')) # Request identify-msg
|
2009-11-09 19:25:59 +00:00
|
|
|
|
2009-11-11 14:53:30 +00:00
|
|
|
if cmd == "ack": # Acknowledge reply
|
|
|
|
if "identify-msg" in args: # identify-msg is set
|
2010-03-28 03:34:17 +00:00
|
|
|
self._irc._Freenode_capabed = True
|
|
|
|
self._irc._Freenode_capabed_notices = True
|
2008-07-20 15:59:27 +00:00
|
|
|
|
2009-11-11 14:53:30 +00:00
|
|
|
if cmd == 'nak': # Failure reply
|
|
|
|
if "identify-msg" in args: # identify-msg is not set
|
2010-03-28 03:34:17 +00:00
|
|
|
self._irc._Freenode_capabed = False
|
|
|
|
self._irc._Freenode_capabed_notices = False
|
2009-11-09 19:25:59 +00:00
|
|
|
|
2009-11-11 14:53:30 +00:00
|
|
|
def do421(self, irc, msg):
|
|
|
|
"""Invalid command"""
|
|
|
|
if msg.args[1].lower() == "cap":
|
|
|
|
irc.queueMsg(ircmsgs.IrcMsg("CAPAB IDENTIFY MSG"))
|
2008-07-20 15:59:27 +00:00
|
|
|
|
2009-11-11 14:53:30 +00:00
|
|
|
def do376(self, irc, msg, force=False): # End of /MOTD command.
|
2009-11-09 19:25:59 +00:00
|
|
|
"""
|
|
|
|
The new freenode ircd-seven requires using the 'CAP' command
|
|
|
|
to set capabilities, rather than hyperirons 'CAPAB' command.
|
|
|
|
You request "CAP REQ IDENTIFY-MSG" and the server will respond
|
|
|
|
with either "CAP <nick> ACK :identify-msg" to acknowledge, or
|
|
|
|
"CAP <nick> NAK :identify-msg" to indicate failure.
|
|
|
|
Other than that, it's the same.
|
|
|
|
"""
|
2010-03-28 03:34:17 +00:00
|
|
|
if not hasattr(self._irc, "_Freenode_capabed") or force: # Do this only once
|
|
|
|
self._irc._Freenode_capabed = False
|
|
|
|
self._irc._Freenode_capabed_notices = False
|
2009-11-11 14:53:30 +00:00
|
|
|
# Try the CAP command first
|
2010-02-20 10:21:58 +00:00
|
|
|
irc.queueMsg(ircmsgs.IrcMsg("CAP LS"))
|
2009-11-11 14:53:30 +00:00
|
|
|
|
|
|
|
do422 = do376
|
2008-07-20 15:59:27 +00:00
|
|
|
|
|
|
|
def inFilter(self, irc, msg):
|
2009-11-11 14:53:30 +00:00
|
|
|
"""
|
|
|
|
Strip the leading '+' or '-' from each message
|
|
|
|
"""
|
|
|
|
|
|
|
|
if msg.command not in ("PRIVMSG", "NOTICE"):
|
|
|
|
return msg
|
|
|
|
|
|
|
|
if not getattr(irc, '_Freenode_capabed', False):
|
2008-11-26 14:34:47 +00:00
|
|
|
return msg
|
2009-11-11 14:53:30 +00:00
|
|
|
|
|
|
|
if msg.command == "NOTICE" and not getattr(irc, '_Freenode_capabed_notices', False):
|
|
|
|
return msg
|
|
|
|
|
|
|
|
if msg.tagged('identified') == None:
|
|
|
|
first = msg.args[1][0]
|
|
|
|
rest = msg.args[1][1:]
|
|
|
|
msg.tag('identified', first == '+')
|
|
|
|
if first in ('+', '-'):
|
2010-03-28 04:12:37 +00:00
|
|
|
if msg.command == "NOTICE":
|
|
|
|
msg = ircmsgs.notice(msg.args[0], rest, msg=msg)
|
|
|
|
else:
|
|
|
|
msg = ircmsgs.privmsg(msg.args[0], rest, msg=msg)
|
2010-04-28 10:07:36 +00:00
|
|
|
if not ircutils.isChannel(msg.args[0]): # /msg
|
|
|
|
##TODO: check here that the user isn't already logged in
|
|
|
|
cmd = msg.args[1]
|
|
|
|
if cmd and cmd[0] in str(conf.supybot.reply.whenAddressedBy.chars()):
|
|
|
|
cmd = cmd[1:]
|
|
|
|
if cmd.lower() == 'login':
|
2010-04-28 11:45:59 +00:00
|
|
|
self.doPrivmsg(callbacks.ReplyIrcProxy(irc, msg), msg) # If the login command is given in /msg, force it through
|
|
|
|
return # Don't return the msg otherwise it'll be processed twice
|
2010-04-28 12:09:12 +00:00
|
|
|
else:
|
|
|
|
self.do376(irc, msg, True)
|
2009-11-11 14:53:30 +00:00
|
|
|
assert msg.receivedAt and msg.receivedOn and msg.receivedBy
|
|
|
|
|
2008-11-26 14:34:47 +00:00
|
|
|
if len(msg.args) >= 2 and msg.args[1] and msg.args[1][0] in ('+', '-'):
|
2009-11-11 14:53:30 +00:00
|
|
|
self.do376(irc, msg, True)
|
2008-07-20 15:59:27 +00:00
|
|
|
return msg
|
|
|
|
|
|
|
|
Class = IRCLogin
|