mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-11 04:32:36 +01:00
SSL server support for Twisted driver.
This commit is contained in:
parent
d13458726d
commit
32e0b29fcd
@ -263,6 +263,9 @@ def registerNetwork(name, password=''):
|
||||
completed.""" % name))
|
||||
registerGlobalValue(network, 'channels', SpaceSeparatedSetOfChannels([],
|
||||
"""Determines what channels the bot will join only on %s.""" % name))
|
||||
registerGlobalValue(network, 'ssl', registry.Boolean(False,
|
||||
"""Determines whether the bot will attempt to connect with SSL sockets
|
||||
to %s.""" % name))
|
||||
registerChannelValue(network.channels, 'key', registry.String('',
|
||||
"""Determines what key (if any) will be used to join the channel."""))
|
||||
return network
|
||||
|
@ -37,10 +37,15 @@ import supybot.ircdb as ircdb
|
||||
import supybot.drivers as drivers
|
||||
import supybot.ircmsgs as ircmsgs
|
||||
|
||||
from twisted.internet import reactor, error
|
||||
from twisted.internet import reactor, error, ssl
|
||||
from twisted.protocols.basic import LineReceiver
|
||||
from twisted.internet.protocol import ReconnectingClientFactory
|
||||
|
||||
try:
|
||||
from OpenSSL import SSL
|
||||
except ImportError:
|
||||
drivers.log.debug('PyOpenSSL is not available, can not connect to SSL servers.')
|
||||
|
||||
class TwistedRunnerDriver(drivers.IrcDriver):
|
||||
def name(self):
|
||||
return self.__class__.__name__
|
||||
@ -109,8 +114,21 @@ class SupyReconnectingFactory(ReconnectingClientFactory, drivers.ServersMixin):
|
||||
drivers.ServersMixin.__init__(self, irc)
|
||||
(server, port) = self._getNextServer()
|
||||
vhost = conf.supybot.protocols.irc.vhost()
|
||||
if self.networkGroup.get('ssl').value:
|
||||
self.connectSSL(server, port, vhost)
|
||||
else:
|
||||
self.connectTCP(server, port, vhost)
|
||||
|
||||
def connectTCP(self, server, port, vhost):
|
||||
"""Connect to the server with a standard TCP connection."""
|
||||
reactor.connectTCP(server, port, self, bindAddress=(vhost, 0))
|
||||
|
||||
def connectSSL(self, server, port, vhost):
|
||||
"""Connect to the server using an SSL socket."""
|
||||
drivers.log.debug('Attempting an SSL connection.')
|
||||
reactor.connectSSL(server, port, self,
|
||||
ssl.ClientContextFactory(), bindAddress=(vhost, 0))
|
||||
|
||||
def clientConnectionFailed(self, connector, r):
|
||||
drivers.log.connectError(self.currentServer, errorMsg(r))
|
||||
(connector.host, connector.port) = self._getNextServer()
|
||||
@ -129,7 +147,6 @@ class SupyReconnectingFactory(ReconnectingClientFactory, drivers.ServersMixin):
|
||||
protocol.irc = self.irc
|
||||
return protocol
|
||||
|
||||
|
||||
Driver = SupyReconnectingFactory
|
||||
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user