From 4969c0d60338cee032b04deef3fe2ddacceacc82 Mon Sep 17 00:00:00 2001 From: Brendan Molloy Date: Sun, 12 Sep 2010 21:33:15 +1000 Subject: [PATCH 1/2] Add SSL support --- __init__.py | 2 +- irc.py | 9 ++++++--- phenny | 13 +++++++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/__init__.py b/__init__.py index 5699583..03a82e8 100755 --- a/__init__.py +++ b/__init__.py @@ -34,7 +34,7 @@ def run_phenny(config): def connect(config): p = bot.Phenny(config) - p.run(config.host, config.port) + p.run(config.host, config.port, config.ssl) try: Watcher() except Exception, e: diff --git a/irc.py b/irc.py index a16c61b..5365568 100755 --- a/irc.py +++ b/irc.py @@ -64,15 +64,18 @@ class Bot(asynchat.async_chat): self.__write(args, text) except Exception, e: pass - def run(self, host, port=6667): - self.initiate_connect(host, port) + def run(self, host, port=6667, ssl=False): + self.initiate_connect(host, port, ssl) - def initiate_connect(self, host, port): + def initiate_connect(self, host, port, ssl): if self.verbose: message = 'Connecting to %s:%s...' % (host, port) print >> sys.stderr, message, self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.connect((host, port)) + if ssl: + import ssl + self.socket = ssl.wrap_socket(self.socket) try: asyncore.loop() except KeyboardInterrupt: sys.exit() diff --git a/phenny b/phenny index 5fb7d7e..f7fdcc4 100755 --- a/phenny +++ b/phenny @@ -25,8 +25,12 @@ def check_python_version(): def create_default_config(fn): f = open(fn, 'w') print >> f, trim("""\ + import os + nick = 'phenny' host = 'irc.example.net' + port = 6667 + ssl = False channels = ['#example', '#test'] owner = 'yournickname' @@ -44,7 +48,7 @@ def create_default_config(fn): # Directories to load user modules from # e.g. /path/to/my/modules - extra = [] + extra = ['os.path.expanduser("~/.phenny/modules")'] # Services to load: maps channel names to white or black lists external = { @@ -59,7 +63,8 @@ def create_default_config(fn): def create_dotdir(dotdir): print 'Creating a config directory at ~/.phenny...' - try: os.mkdir(dotdir) + try: + os.mkdir(dotdir) except Exception, e: print >> sys.stderr, 'There was a problem creating %s:' % dotdir 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...' default = os.path.join(dotdir, 'default.py') + os.mkdir(os.path.join(dotdir, 'modules')) create_default_config(default) 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'): module.port = 6667 + if not hasattr(module, 'ssl'): + module.ssl = False + if not hasattr(module, 'password'): module.password = None From 721aa3577ec9ff08fa1c4472a4c5bf36567a1763 Mon Sep 17 00:00:00 2001 From: Brendan Molloy Date: Sun, 12 Sep 2010 21:38:51 +1000 Subject: [PATCH 2/2] Add SSL support (correctly, this time.) --- phenny | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/phenny b/phenny index f7fdcc4..8d4dc66 100755 --- a/phenny +++ b/phenny @@ -25,8 +25,6 @@ def check_python_version(): def create_default_config(fn): f = open(fn, 'w') print >> f, trim("""\ - import os - nick = 'phenny' host = 'irc.example.net' port = 6667 @@ -48,7 +46,7 @@ def create_default_config(fn): # Directories to load user modules from # e.g. /path/to/my/modules - extra = ['os.path.expanduser("~/.phenny/modules")'] + extra = [] # Services to load: maps channel names to white or black lists external = { @@ -63,8 +61,7 @@ def create_default_config(fn): def create_dotdir(dotdir): print 'Creating a config directory at ~/.phenny...' - try: - os.mkdir(dotdir) + try: os.mkdir(dotdir) except Exception, e: print >> sys.stderr, 'There was a problem creating %s:' % dotdir print >> sys.stderr, e.__class__, str(e) @@ -73,7 +70,6 @@ def create_dotdir(dotdir): print 'Creating a default config file at ~/.phenny/default.py...' default = os.path.join(dotdir, 'default.py') - os.mkdir(os.path.join(dotdir, 'modules')) create_default_config(default) print 'Done; now you can edit default.py, and run phenny! Enjoy.'