diff --git a/kippo.cfg.dist b/kippo.cfg.dist index ffd407f..04fc05a 100644 --- a/kippo.cfg.dist +++ b/kippo.cfg.dist @@ -199,3 +199,18 @@ interact_port = 5123 #[database_textlog] #logfile = kippo-textlog.log + + +# IRC based logging module +# +# Logs to an IRC server. The default settings are shown, nick is randomly +# generated unless specified. Channel can be either a channel or a nick +# +# To enable this module, remove the comments below, including the +# [database_irc] line. +#[database_irc] +#server=irc.efnet.org +#nick=kippobot +#channel=#kippo-events +#ssl=false +#password= diff --git a/kippo/dblog/irc.py b/kippo/dblog/irc.py new file mode 100644 index 0000000..69e0666 --- /dev/null +++ b/kippo/dblog/irc.py @@ -0,0 +1,75 @@ +from kippo.core import dblog +from asyncirc.ircbot import IRCBot +import uuid + +class DBLogger(dblog.DBLogger): + def start(self, cfg): + if cfg.has_option('database_irc', 'port'): + port = int(cfg.get('database_irc', 'port')) + else: + port = 6667 + + nick = self.getSensor() + if cfg.has_option('database_irc', 'nick'): + nick = cfg.get('database_irc', 'nick') + if nick is None: + import random + import string + nick = ''.join(random.choice(string.ascii_lowercase) for _ in range(8)) + + self.channel = '#kippo-events' + if cfg.has_option('database_irc', 'channel'): + self.channels = cfg.get('database_irc', 'channel') + + server = 'irc.efnet.org' + if cfg.has_option('database_irc', 'server'): + server = cfg.get('database_irc', 'server') + + password = None + if cfg.has_option('database_irc', 'password'): + password = cfg.get('database_irc', 'password') + + self.connection = IRCBot(server, port, nick, nick, 'Kippo', password) + self.connection.start() + + self.connection.join(self.channel) + + def write(self, session, message): + self.connection.msg(self.channel, "[%s] %s" % (session, message)) + + def createSession(self, peerIP, peerPort, hostIP, hostPort): + sid = uuid.uuid1().hex + self.write(sid, 'New connection: %s:%s' % (peerIP, peerPort)) + return sid + + def handleConnectionLost(self, session, args): + self.write(session, 'Connection lost') + + def handleLoginFailed(self, session, args): + self.write(session, 'Login failed [%s/%s]' % \ + (args['username'], args['password'])) + + def handleLoginSucceeded(self, session, args): + self.write(session, 'Login succeeded [%s/%s]' % \ + (args['username'], args['password'])) + + def handleCommand(self, session, args): + self.write(session, 'Command [%s]' % (args['input'],)) + + def handleUnknownCommand(self, session, args): + self.write(session, 'Unknown command [%s]' % (args['input'],)) + + def handleInput(self, session, args): + self.write(session, 'Input [%s] @%s' % (args['input'], args['realm'])) + + def handleTerminalSize(self, session, args): + self.write(session, 'Terminal size: %sx%s' % \ + (args['width'], args['height'])) + + def handleClientVersion(self, session, args): + self.write(session, 'Client version: [%s]' % (args['version'],)) + + def handleFileDownload(self, session, args): + self.write(session, 'File download: [%s] -> %s' % \ + (args['url'], args['outfile'])) +# vim: set sw=4 et: