Add SSL support
parent
b45c1e94f7
commit
4969c0d603
|
@ -34,7 +34,7 @@ def run_phenny(config):
|
||||||
|
|
||||||
def connect(config):
|
def connect(config):
|
||||||
p = bot.Phenny(config)
|
p = bot.Phenny(config)
|
||||||
p.run(config.host, config.port)
|
p.run(config.host, config.port, config.ssl)
|
||||||
|
|
||||||
try: Watcher()
|
try: Watcher()
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
|
|
9
irc.py
9
irc.py
|
@ -64,15 +64,18 @@ class Bot(asynchat.async_chat):
|
||||||
self.__write(args, text)
|
self.__write(args, text)
|
||||||
except Exception, e: pass
|
except Exception, e: pass
|
||||||
|
|
||||||
def run(self, host, port=6667):
|
def run(self, host, port=6667, ssl=False):
|
||||||
self.initiate_connect(host, port)
|
self.initiate_connect(host, port, ssl)
|
||||||
|
|
||||||
def initiate_connect(self, host, port):
|
def initiate_connect(self, host, port, ssl):
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
message = 'Connecting to %s:%s...' % (host, port)
|
message = 'Connecting to %s:%s...' % (host, port)
|
||||||
print >> sys.stderr, message,
|
print >> sys.stderr, message,
|
||||||
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
|
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
self.connect((host, port))
|
self.connect((host, port))
|
||||||
|
if ssl:
|
||||||
|
import ssl
|
||||||
|
self.socket = ssl.wrap_socket(self.socket)
|
||||||
try: asyncore.loop()
|
try: asyncore.loop()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
13
phenny
13
phenny
|
@ -25,8 +25,12 @@ def check_python_version():
|
||||||
def create_default_config(fn):
|
def create_default_config(fn):
|
||||||
f = open(fn, 'w')
|
f = open(fn, 'w')
|
||||||
print >> f, trim("""\
|
print >> f, trim("""\
|
||||||
|
import os
|
||||||
|
|
||||||
nick = 'phenny'
|
nick = 'phenny'
|
||||||
host = 'irc.example.net'
|
host = 'irc.example.net'
|
||||||
|
port = 6667
|
||||||
|
ssl = False
|
||||||
channels = ['#example', '#test']
|
channels = ['#example', '#test']
|
||||||
owner = 'yournickname'
|
owner = 'yournickname'
|
||||||
|
|
||||||
|
@ -44,7 +48,7 @@ def create_default_config(fn):
|
||||||
|
|
||||||
# Directories to load user modules from
|
# Directories to load user modules from
|
||||||
# e.g. /path/to/my/modules
|
# e.g. /path/to/my/modules
|
||||||
extra = []
|
extra = ['os.path.expanduser("~/.phenny/modules")']
|
||||||
|
|
||||||
# Services to load: maps channel names to white or black lists
|
# Services to load: maps channel names to white or black lists
|
||||||
external = {
|
external = {
|
||||||
|
@ -59,7 +63,8 @@ def create_default_config(fn):
|
||||||
|
|
||||||
def create_dotdir(dotdir):
|
def create_dotdir(dotdir):
|
||||||
print 'Creating a config directory at ~/.phenny...'
|
print 'Creating a config directory at ~/.phenny...'
|
||||||
try: os.mkdir(dotdir)
|
try:
|
||||||
|
os.mkdir(dotdir)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print >> sys.stderr, 'There was a problem creating %s:' % dotdir
|
print >> sys.stderr, 'There was a problem creating %s:' % dotdir
|
||||||
print >> sys.stderr, e.__class__, str(e)
|
print >> sys.stderr, e.__class__, str(e)
|
||||||
|
@ -68,6 +73,7 @@ def create_dotdir(dotdir):
|
||||||
|
|
||||||
print 'Creating a default config file at ~/.phenny/default.py...'
|
print 'Creating a default config file at ~/.phenny/default.py...'
|
||||||
default = os.path.join(dotdir, 'default.py')
|
default = os.path.join(dotdir, 'default.py')
|
||||||
|
os.mkdir(os.path.join(dotdir, 'modules'))
|
||||||
create_default_config(default)
|
create_default_config(default)
|
||||||
|
|
||||||
print 'Done; now you can edit default.py, and run phenny! Enjoy.'
|
print 'Done; now you can edit default.py, and run phenny! Enjoy.'
|
||||||
|
@ -135,6 +141,9 @@ def main(argv=None):
|
||||||
if not hasattr(module, 'port'):
|
if not hasattr(module, 'port'):
|
||||||
module.port = 6667
|
module.port = 6667
|
||||||
|
|
||||||
|
if not hasattr(module, 'ssl'):
|
||||||
|
module.ssl = False
|
||||||
|
|
||||||
if not hasattr(module, 'password'):
|
if not hasattr(module, 'password'):
|
||||||
module.password = None
|
module.password = None
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue