Logformat is an IRC bot that logs into a database, and a web frontend to show these logs.
Logformat is the reincarnation of an earlier, ehrm, system that transformed log files from my irssi setup into something resembling HTML. Along the way, it employed horrible spaghetti code and chains of regular expressions.
All executable components live in bin. They share models and helpers from lib, including the basic configuration logic and database access.
The IRC bot. It will connect to one IRC network, join all channels in the database that have the join
flag set, listen for and record all messages.
A Sinatra web app that displays the logs, one day at a time, for all channels. It employs a simple ACL scheme to allow restricted access to certain channels.
A script to read, parse and store the Irssi logfiles. It tries to avoid duplicates, but since the bot's recorded messages have second precision but the logfiles only minutes, importing logs from times when the bot was listening will lead to duplication.
A pry REPL with all libraries preloaded. Currently, this is the only admin interface.
A simplistic script to dump the whole database in plain text format. Note that the format is currently not supported by the parser employed by import.rb
.
Runtime configuration is performed through environment variables. These are:
DB
: URI for database access, e.g.postgres://user:pass@localhost/database
. Default:sqlite://local.db
(i.e. thelocal.db
file in the current directory).PORT
: listen port for the web component. The web component will by default only listen on the local interface, use a web server like nginx to proxy. See below for a configuration example.BIND
: interface to bind to. Set to0.0.0.0
to bind to all interfaces. Default:127.0.0.1
SERVER
: IRC server to connect to. Default:irc.freenode.net
NICK
: Nickname to connect with. Default:logformat
Proxy to the web interface using proxy_pass
, and pass the host
header:
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
}
Currently, the default database is SQLite 3. It is also used for tests (as an in-memory databse). However, it is recommended to use Postgres for real use-cases, it is much faster and more stable. I have encountered severe concurrency problems with all but Postgres during multithreaded imports.
It is very likely that sooner or later Postgres will be the only supported database backend.
Web access to a channel is controlled by a simple list of yes/no rules (the Permission model). The default is to allow access. Users are authenticated using HTTP Basic authentication. Unauthenticated users are represented by the special "anonymous" user.
To disable anonymous access to a channel, start the console and run
channel = Channel.find(:name => '#mychannel')
channel.deny_anonymous!
To create a user and allow access to the channel for them,
user = User.create(:name => 'joe', :password => 'password', :password_confirmation => 'password')
channel.allow!(user)
Pre-built Docker images are available. When running, you most likely want to set the DB
environment variable. Commands are run in the correct bundler context. The default command is web.rb
.