3 # irclog2html.pl Version 1.5 - 11th May 2000
4 # Copyright (C) 2000, Jeffrey W. Waugh
7 # Jeff Waugh <jdub@aphid.net>
10 # Rick Welykochy <rick@praxis.com.au>
11 # Alexander Else <aelse@uu.net>
12 # Tim Riker <Tim@Rikers.org>
14 # Released under the terms of the GNU GPL
15 # http://www.gnu.org/copyleft/gpl.html
17 # Modified by Tim Riker <Tim@Rikers.org>
18 # to work with infobot logs
20 # Usage: irclog2html <date> < logfile
22 # irclog2html will write out a colourised irc log, appending a .html
23 # extension to the output file.
25 ####################################################################################
29 $^W = 1; #RW# turn on warnings
30 use POSIX qw(strftime);
32 ####################################################################################
35 # Comment out the "table" assignment to use the plain version
38 #my $STYLE = "simplett";
40 my $STYLE = "simpletable";
42 my $colour_left = "#000099"; # nick leaving channel
43 my $colour_joined = "#009900"; # nick joining channel
44 my $colour_server = "#009900"; # server message (***)
45 my $colour_nickchange = "#009900"; # nick change
46 my $colour_action = "#CC00CC"; # nick action (/me waves)
48 my %prefs_colour_nick = (
50 "cantanker" => "#006600",
51 "chuckd" => "#339999",
54 ####################################################################################
58 my ( $channel, $date ) = @_;
62 qq{<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
65 <title>IRC log for $channel on $date</title>
66 <meta name="generator" content="irclog2html.pl">
67 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
69 <body text="#000000" bgcolor="#ffffff">
70 <h1>IRC log for $channel on $date</h1>
71 <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
73 <ins class="adsbygoogle"
74 style="display:inline-block;width:728px;height:90px"
75 data-ad-client="ca-pub-1563266826402652"
76 data-ad-slot="5026919875"></ins>
78 (adsbygoogle = window.adsbygoogle || []).push({});
80 <form action="http://www.google.com" id="cse-search-box">
82 <input type="hidden" name="cx" value="partner-pub-1563266826402652:3301963896" />
83 <input type="hidden" name="ie" value="UTF-8" />
84 <input type="text" name="q" size="55" />
85 <input type="submit" name="sa" value="Search" />
88 <script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=cse-search-box&lang=en"></script>
91 if ( $STYLE =~ /table/ ) {
92 $return .= "<table cellspacing=3 cellpadding=2 border=0>\n";
99 if ( $STYLE =~ /table/ ) {
100 $return .= "</table>\n";
104 <br>Generated by irclog2html.pl
105 Modified by <a href="http://Rikers.org">Tim Riker</a> to work with
106 <a href="http://infobot.sourceforge.net/">infobot</a>.
117 return if not $lastdate;
119 my @files = `ls $lastdate.html */$lastdate.html`;
120 foreach $filename (@files) {
122 if ( !open( OUTPUT, ">>$filename" ) ) {
123 print "Cannot open $filename for writing!\n\n";
126 print OUTPUT footer();
132 my ( $date, $time, $channel, $lineout ) = @_;
134 add_footers() if $lastdate ne $date;
138 $filename .= "$channel/" if $channel;
139 $filename .= "$date.html";
141 mkdir( $channel, oct('755') ) if ( $channel && !-d $channel );
142 if ( !open( OUTPUT, ">>$filename" ) ) {
144 #print "Cannot open $filename for writing!\n\n";
149 print OUTPUT header( $channel, $date ) if -z $filename;
151 print OUTPUT $lineout;
156 sub output_timenicktext {
157 my ( $date, $time, $channel, $nick, $text, $htmlcolour ) = @_;
160 if ( $STYLE eq "table" ) {
163 "<td bgcolor=\"$htmlcolour\"><font color=\"#ffffff\"><tt>$time</tt></font></td>"
166 "<td bgcolor=\"$htmlcolour\"><font color=\"#ffffff\"><tt>$nick</tt></font></td>";
168 "<td width=\"100%\" bgcolor=\"#eeeeee\"><tt><font color=\"$htmlcolour\">$text<\/font></tt></td></tr>\n";
170 elsif ( $STYLE eq "simpletable" ) {
171 $lineout .= "<tr bgcolor=\"#eeeeee\">";
172 $lineout .= "<td><tt>$time</tt></td>" if $time;
174 "<td><font color=\"$htmlcolour\"><tt>$nick</tt></font></td>";
175 $lineout .= "<td width=\"100%\"><tt>$text</tt></td></tr>\n";
177 elsif ( $STYLE eq "simplett" ) {
178 $lineout .= "$time " if $time;
179 $lineout .= "<\;$nick>\; $text<br>\n";
182 $lineout .= "$time " if $time;
184 "<font color=\"$htmlcolour\"><\;$nick>\; $text<\/font><br>\n";
186 output_line( $date, $time, $channel, $lineout );
189 sub output_timeservermsg {
190 my ( $date, $time, $channel, $line ) = @_;
193 if ( $STYLE =~ /table/ ) {
195 $lineout .= "<td><tt>$time</tt></td>" if $time;
196 $lineout .= "<td colspan=2><tt>$line</tt></td></tr>\n";
199 $lineout .= "$time " if $time;
200 $lineout .= "$line<br>\n";
202 output_line( $date, $time, $channel, $lineout );
206 my ( $i, $ncolours ) = @_;
207 $ncolours = 1 if $ncolours == 0;
209 my $rgbmax = 125; # tune these two for the outmost ranges of colour depth
213 0.95; # tune these for the starting and ending concentrations of R,G,B
225 my $m = $rgbmin + ( $rgbmax - $rgbmin ) * ( $ncolours - $i ) / $ncolours;
227 my $r = $rgb->[$n][0] * $m;
228 my $g = $rgb->[$n][1] * $m;
229 my $b = $rgb->[$n][2] * $m;
230 sprintf( "#%02x%02x%02x", $r, $g, $b );
233 ####################################################################################
251 my %colour_nick = %prefs_colour_nick;
253 while ( $line = <STDIN> ) {
257 if ( !$line eq "" ) {
260 if ( $line =~ s/^([0-9:\.]*) (.*)$/$2/ ) {
268 # Replace ampersands, pointies, control characters #
269 $line =~ s/&/&\;/g;
270 $line =~ s/</<\;/g;
271 $line =~ s/>/>\;/g;
272 $line =~ s/\e\[[0-1]*m//g;
273 $line =~ s/[\x00-\x1f]+//g;
275 # Replace possible URLs with links #
277 s/((http|https|ftp|gopher|news):\/\/\S*)/<a href="$1">$1<\/a>/g;
279 # Colourise the comments
280 if ( $line =~ /^<\;[^\/]*?\/\#.*?>\; .*$/ ) {
282 # Split $nick, $channel and $line
284 $nick =~ s/^<\;([^\/]*?)\/\#.*?>\; .*$/$1/;
286 $channel =~ s/^<\;[^\/]*?\/(\#.*?)>\; .*$/$1/;
288 # $nick =~ tr/[A-Z]/[a-z]/;
289 # <======= move this into another function when getting nick colour
292 $text =~ s/^<\;.*?>\; (.*)$/$1/;
293 $text =~ s/^ .*/<\;PROTECTED>\;/g;
294 $text =~ s/ / \; \;/g;
296 $htmlcolour = $colour_nick{$nick};
297 if ( !defined($htmlcolour) ) {
302 # if we've exceeded our estimate of the number of nicks, double it
303 $NICKMAX *= 2 if $nickcount >= $NICKMAX;
305 $htmlcolour = $colour_nick{$nick} =
306 html_rgb( $nickcount, $NICKMAX );
308 output_timenicktext( $date, $time, $channel, $nick, $text, $htmlcolour );
310 elsif ( $line =~ /^\* ([^ \/]+)\/(\#[^ ]+) (.+)/ ) {
311 # Colourise the /me's #
314 $text="<font color=\"$colour_action\">$3</font>";
315 $htmlcolour = $colour_nick{$nick};
316 if ( !defined($htmlcolour) ) {
321 # if we've exceeded our estimate of the number of nicks, double it
322 $NICKMAX *= 2 if $nickcount >= $NICKMAX;
324 $htmlcolour = $colour_nick{$nick} =
325 html_rgb( $nickcount, $NICKMAX );
327 output_timenicktext( $date, $time, $channel, $nick, $text, $htmlcolour );
329 elsif ( $line =~ /^>\;>\;>\; / ) {
330 $line =~ s/^>\;>\;>\; /\*\*\* /;
332 # Process changed nick results, and remember colours accordingly #
333 if ( $line =~ /\*\*\* (.*?) materializes into (.*)/ ) {
338 #$nick_old =~ s/\*\*\* (.*?) materializes into .*/$1/;
340 #$nick_new =~ s/\*\*\* (.*?) materializes into (.*)/$2/;
342 $colour_nick{$nick_new} = $colour_nick{$nick_old};
343 $colour_nick{$nick_old} = undef;
345 $line =~ s/(\*\*\* .*)/<font color=\"$colour_nickchange\">$1<\/font>/;
347 elsif ( $line =~ /\*\*\* (join|mode|topic)\/(.*?) .*/ ) {
350 s/(\*\*\* .*)/<font color=\"$colour_joined\">$1<\/font>/;
352 elsif ( $line =~ /\*\*\* (part|kick|banned)\/(.*?) .*/ ) {
355 s/(\*\*\* .*)/<font color=\"$colour_left\">$1<\/font>/;
357 elsif ( $line =~ /\*\*\* .* has signed off IRC .*/ ) {
359 # Colourise joined/left/server messages #
361 s/(\*\*\* .*)/<font color=\"$colour_left\">$1<\/font>/;
363 elsif ( $line =~ /\*\*\* / ) {
365 s/(\*\*\* .*)$/<font color=\"$colour_server\">$1<\/font>/;
367 elsif ( $line =~ /^\* .*$/ ) {
369 # Colourise the /me's #
371 s/^(\*.*)$/<font color=\"$colour_action\">$1<\/font>/;
374 output_timeservermsg( $date, $time, $channel, $line );
384 if ( !scalar @ARGV ) {
385 print "Usage: irclog2html.pl <date> < logfile\n";
387 "Example: bzcat log/2002/1104.bz2 | irclog2html.pl 20021104\n";
393 # vim:ts=4:sw=4:expandtab:tw=80