Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions kippo.cfg.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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=
75 changes: 75 additions & 0 deletions kippo/dblog/irc.py
Original file line number Diff line number Diff line change
@@ -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: