32 |
|
|
33 |
## CONFIG |
## CONFIG |
34 |
|
|
35 |
my $HOSTNAME = `hostname`; |
my $HOSTNAME = `hostname -f`; |
36 |
|
chomp($HOSTNAME); |
37 |
|
|
38 |
my $NICK = 'irc-logger'; |
my $NICK = 'irc-logger'; |
39 |
$NICK .= '-dev' if ($HOSTNAME =~ m/llin/); |
$NICK .= '-dev' if ($HOSTNAME =~ m/llin/); |
59 |
|
|
60 |
my $sleep_on_error = 5; |
my $sleep_on_error = 5; |
61 |
|
|
62 |
|
# number of last tags to keep in circular buffer |
63 |
|
my $last_x_tags = 50; |
64 |
|
|
65 |
|
my $http_port = $NICK =~ m/-dev/ ? 8001 : 8000; |
66 |
|
|
67 |
|
my $url = "http://$HOSTNAME:$http_port"; |
68 |
|
|
69 |
## END CONFIG |
## END CONFIG |
70 |
|
|
71 |
|
|
84 |
use URI::Escape; |
use URI::Escape; |
85 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
86 |
use DateTime::Format::ISO8601; |
use DateTime::Format::ISO8601; |
87 |
|
use Carp qw/confess/; |
88 |
|
use XML::Feed; |
89 |
|
use DateTime::Format::Flexible; |
90 |
|
|
91 |
my $use_twitter = 1; |
my $use_twitter = 1; |
92 |
eval { require Net::Twitter; }; |
eval { require Net::Twitter; }; |
99 |
'log:s' => \$log_path, |
'log:s' => \$log_path, |
100 |
); |
); |
101 |
|
|
102 |
|
$SIG{__DIE__} = sub { |
103 |
|
confess "fatal error"; |
104 |
|
}; |
105 |
|
|
106 |
open(STDOUT, '>', $log_path) || warn "can't redirect log to $log_path: $!"; |
open(STDOUT, '>', $log_path) || warn "can't redirect log to $log_path: $!"; |
107 |
|
|
108 |
sub _log { |
sub _log { |
109 |
print strftime($TIMESTAMP,localtime()), ' ', join(" ",@_), $/; |
print strftime($TIMESTAMP,localtime()), ' ', join(" ",@_), $/; |
110 |
} |
} |
111 |
|
|
112 |
|
# HTML formatters |
113 |
|
|
114 |
|
my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); |
115 |
|
my $escape_re = join '|' => keys %escape; |
116 |
|
|
117 |
|
my $tag_regex = '\b([\w-_]+)//'; |
118 |
|
|
119 |
|
my %nick_enumerator; |
120 |
|
my $max_color = 0; |
121 |
|
|
122 |
|
my $filter = { |
123 |
|
message => sub { |
124 |
|
my $m = shift || return; |
125 |
|
|
126 |
|
# protect HTML from wiki modifications |
127 |
|
sub e { |
128 |
|
my $t = shift; |
129 |
|
return 'uri_unescape{' . uri_escape($t) . '}'; |
130 |
|
} |
131 |
|
|
132 |
|
$m =~ s/($escape_re)/$escape{$1}/gs; |
133 |
|
$m =~ s#($RE{URI}{HTTP})#e(qq{<a href="$1">$1</a>})#egs || |
134 |
|
$m =~ s#\/(\w+)\/#<i>$1</i>#gs; |
135 |
|
$m =~ s#$tag_regex#e(qq{<a href="$url?tag=$1" class="tag">$1</a>})#egs; |
136 |
|
$m =~ s#\*(\w+)\*#<b>$1</b>#gs; |
137 |
|
$m =~ s#_(\w+)_#<u>$1</u>#gs; |
138 |
|
|
139 |
|
$m =~ s#uri_unescape{([^}]+)}#uri_unescape($1)#egs; |
140 |
|
return $m; |
141 |
|
}, |
142 |
|
nick => sub { |
143 |
|
my $n = shift || return; |
144 |
|
if (! $nick_enumerator{$n}) { |
145 |
|
my $max = scalar keys %nick_enumerator; |
146 |
|
$nick_enumerator{$n} = $max + 1; |
147 |
|
} |
148 |
|
return '<span class="nick col-' . |
149 |
|
( $nick_enumerator{$n} % $max_color ) . |
150 |
|
'">' . $n . '</span>'; |
151 |
|
}, |
152 |
|
}; |
153 |
|
|
154 |
my $dbh = DBI->connect($DSN,"","", { RaiseError => 1, AutoCommit => 1 }) || die $DBI::errstr; |
my $dbh = DBI->connect($DSN,"","", { RaiseError => 1, AutoCommit => 1 }) || die $DBI::errstr; |
155 |
|
|
156 |
my $sql_schema = { |
my $sql_schema = { |
250 |
|
|
251 |
|
|
252 |
my $tags; |
my $tags; |
|
my $tag_regex = '\b([\w-_]+)//'; |
|
253 |
|
|
254 |
=head2 get_from_log |
=head2 get_from_log |
255 |
|
|
286 |
sub get_from_log { |
sub get_from_log { |
287 |
my $args = {@_}; |
my $args = {@_}; |
288 |
|
|
289 |
$args->{fmt} ||= { |
if ( ! $args->{fmt} ) { |
290 |
date => '[%s] ', |
$args->{fmt} = { |
291 |
time => '{%s} ', |
date => '[%s] ', |
292 |
time_channel => '{%s %s} ', |
time => '{%s} ', |
293 |
nick => '%s: ', |
time_channel => '{%s %s} ', |
294 |
me_nick => '***%s ', |
nick => '%s: ', |
295 |
message => '%s', |
me_nick => '***%s ', |
296 |
}; |
message => '%s', |
297 |
|
}; |
298 |
|
} |
299 |
|
|
300 |
my $sql_message = qq{ |
my $sql_message = qq{ |
301 |
select |
select |
318 |
|
|
319 |
my $sql = $context ? $sql_context : $sql_message; |
my $sql = $context ? $sql_context : $sql_message; |
320 |
|
|
321 |
$sql .= " where message ilike ? or nick ilike ? " if ($args->{search}); |
sub check_date { |
322 |
$sql .= " where id in (" . join(",", @{ $tags->{ $args->{tag} } }) . ") " if ($args->{tag} && $tags->{ $args->{tag} }); |
my $date = shift || return; |
323 |
if ($args->{date}) { |
my $new_date = eval { DateTime::Format::ISO8601->parse_datetime( $date )->ymd; }; |
|
my $date = eval { DateTime::Format::ISO8601->parse_datetime( $args->{date} )->ymd; }; |
|
324 |
if ( $@ ) { |
if ( $@ ) { |
325 |
warn "invalid date ", $args->{date}, $/; |
warn "invalid date $date\n"; |
326 |
$date = DateTime->now->ymd; |
$new_date = DateTime->now->ymd; |
327 |
} |
} |
328 |
$sql .= " where date(time) = ? "; |
return $new_date; |
|
$args->{date} = $date; |
|
329 |
} |
} |
|
$sql .= " order by log.time desc"; |
|
|
$sql .= " limit " . $args->{limit} if ($args->{limit}); |
|
330 |
|
|
331 |
my $sth = $dbh->prepare( $sql ); |
my @where; |
332 |
|
my @args; |
333 |
|
|
334 |
if (my $search = $args->{search}) { |
if (my $search = $args->{search}) { |
335 |
$search =~ s/^\s+//; |
$search =~ s/^\s+//; |
336 |
$search =~ s/\s+$//; |
$search =~ s/\s+$//; |
337 |
$sth->execute( ( '%' . $search . '%' ) x 2 ); |
push @where, 'message ilike ? or nick ilike ?'; |
338 |
_log "search for '$search' returned ", $sth->rows, " results ", $context || ''; |
push @args, ( ( '%' . $search . '%' ) x 2 ); |
339 |
} elsif (my $tag = $args->{tag}) { |
_log "search for '$search'"; |
|
$sth->execute(); |
|
|
_log "tag '$tag' returned ", $sth->rows, " results ", $context || ''; |
|
|
} elsif (my $date = $args->{date}) { |
|
|
$sth->execute($date); |
|
|
_log "found ", $sth->rows, " messages for date $date ", $context || ''; |
|
|
} else { |
|
|
$sth->execute(); |
|
340 |
} |
} |
341 |
|
|
342 |
|
if ($args->{tag} && $tags->{ $args->{tag} }) { |
343 |
|
push @where, 'id in (' . join(',', @{ $tags->{ $args->{tag} } }) . ')'; |
344 |
|
_log "search for tags $args->{tag}"; |
345 |
|
} |
346 |
|
|
347 |
|
if (my $date = $args->{date} ) { |
348 |
|
$date = check_date( $date ); |
349 |
|
push @where, 'date(time) = ?'; |
350 |
|
push @args, $date; |
351 |
|
_log "search for date $date"; |
352 |
|
} |
353 |
|
|
354 |
|
$sql .= " where " . join(" and ", @where) if @where; |
355 |
|
|
356 |
|
$sql .= " order by log.time desc"; |
357 |
|
$sql .= " limit " . $args->{limit} if ($args->{limit}); |
358 |
|
|
359 |
|
#warn "### sql: $sql ", dump( @args ); |
360 |
|
|
361 |
|
my $sth = $dbh->prepare( $sql ); |
362 |
|
eval { $sth->execute( @args ) }; |
363 |
|
return if $@; |
364 |
|
|
365 |
my $last_row = { |
my $last_row = { |
366 |
date => '', |
date => '', |
367 |
time => '', |
time => '', |
482 |
|
|
483 |
=head2 add_tag |
=head2 add_tag |
484 |
|
|
485 |
add_tag( id => 42, message => 'irc message' ); |
add_tag( id => 42, message => 'irc message', nick => 'foobar' [, me => 1 ] ); |
486 |
|
|
487 |
=cut |
=cut |
488 |
|
|
489 |
|
my @last_tags; |
490 |
|
|
491 |
sub add_tag { |
sub add_tag { |
492 |
my $arg = {@_}; |
my $arg = {@_}; |
493 |
|
|
496 |
my $m = $arg->{message}; |
my $m = $arg->{message}; |
497 |
from_to('UTF-8', 'iso-8859-2', $m) if (is_utf8($m)); |
from_to('UTF-8', 'iso-8859-2', $m) if (is_utf8($m)); |
498 |
|
|
499 |
|
my @tags; |
500 |
|
|
501 |
while ($m =~ s#$tag_regex##s) { |
while ($m =~ s#$tag_regex##s) { |
502 |
my $tag = $1; |
my $tag = $1; |
503 |
next if (! $tag || $tag =~ m/https?:/i); |
next if (! $tag || $tag =~ m/https?:/i); |
504 |
push @{ $tags->{$tag} }, $arg->{id}; |
push @{ $tags->{$tag} }, $arg->{id}; |
505 |
#warn "+tag $tag: $arg->{id}\n"; |
#warn "+tag $tag: $arg->{id}\n"; |
506 |
$cloud->add($tag, "?tag=$tag", scalar @{$tags->{$tag}} + 1); |
$cloud->add($tag, "$url?tag=$tag", scalar @{$tags->{$tag}} + 1); |
507 |
|
push @tags, $tag; |
508 |
|
|
509 |
|
} |
510 |
|
|
511 |
|
if ( @tags ) { |
512 |
|
pop @last_tags if $#last_tags == $last_x_tags; |
513 |
|
unshift @last_tags, { tags => [ @tags ], %$arg }; |
514 |
} |
} |
515 |
|
|
516 |
} |
} |
517 |
|
|
518 |
=head2 seed_tags |
=head2 seed_tags |
522 |
=cut |
=cut |
523 |
|
|
524 |
sub seed_tags { |
sub seed_tags { |
525 |
my $sth = $dbh->prepare(qq{ select id,message from log where message like '%//%' }); |
my $sth = $dbh->prepare(qq{ select id,message,nick,me,time from log where message like '%//%' order by time asc }); |
526 |
$sth->execute; |
$sth->execute; |
527 |
while (my $row = $sth->fetchrow_hashref) { |
while (my $row = $sth->fetchrow_hashref) { |
528 |
add_tag( %$row ); |
add_tag( %$row ); |
529 |
} |
} |
530 |
|
|
531 |
foreach my $tag (keys %$tags) { |
foreach my $tag (keys %$tags) { |
532 |
$cloud->add($tag, "?tag=$tag", scalar @{$tags->{$tag}} + 1); |
$cloud->add($tag, "$url?tag=$tag", scalar @{$tags->{$tag}} + 1); |
533 |
} |
} |
534 |
} |
} |
535 |
|
|
542 |
channel => '#foobar', |
channel => '#foobar', |
543 |
me => 0, |
me => 0, |
544 |
nick => 'dpavlin', |
nick => 'dpavlin', |
545 |
msg => 'test message', |
message => 'test message', |
546 |
time => '2006-06-25 18:57:18', |
time => '2006-06-25 18:57:18', |
547 |
); |
); |
548 |
|
|
554 |
|
|
555 |
sub save_message { |
sub save_message { |
556 |
my $a = {@_}; |
my $a = {@_}; |
557 |
|
confess "have msg" if $a->{msg}; |
558 |
$a->{me} ||= 0; |
$a->{me} ||= 0; |
559 |
$a->{time} ||= strftime($TIMESTAMP,localtime()); |
$a->{time} ||= strftime($TIMESTAMP,localtime()); |
560 |
|
|
561 |
_log |
_log |
562 |
$a->{channel}, " ", |
$a->{channel}, " ", |
563 |
$a->{me} ? "***" . $a->{nick} : "<" . $a->{nick} . ">", |
$a->{me} ? "***" . $a->{nick} : "<" . $a->{nick} . ">", |
564 |
" " . $a->{msg}; |
" " . $a->{message}; |
565 |
|
|
566 |
from_to($a->{msg}, 'UTF-8', $ENCODING); |
from_to($a->{message}, 'UTF-8', $ENCODING); |
567 |
|
|
568 |
$sth->execute($a->{channel}, $a->{me}, $a->{nick}, $a->{msg}, $a->{time}); |
$sth->execute($a->{channel}, $a->{me}, $a->{nick}, $a->{message}, $a->{time}); |
569 |
add_tag( id => $dbh->last_insert_id(undef,undef,"log",undef), |
add_tag( id => $dbh->last_insert_id(undef,undef,"log",undef), %$a ); |
|
message => $a->{msg}); |
|
570 |
} |
} |
571 |
|
|
572 |
|
|
573 |
if ($import_dircproxy) { |
if ($import_dircproxy) { |
574 |
open(my $l, $import_dircproxy) || die "can't open $import_dircproxy: $!"; |
open(my $l, $import_dircproxy) || die "can't open $import_dircproxy: $!"; |
575 |
warn "importing $import_dircproxy...\n"; |
warn "importing $import_dircproxy...\n"; |
576 |
my $tz_offset = 2 * 60 * 60; # TZ GMT+2 |
my $tz_offset = 1 * 60 * 60; # TZ GMT+2 |
577 |
while(<$l>) { |
while(<$l>) { |
578 |
chomp; |
chomp; |
579 |
if (/^@(\d+)\s(\S+)\s(.+)$/) { |
if (/^@(\d+)\s(\S+)\s(.+)$/) { |
591 |
channel => $CHANNEL, |
channel => $CHANNEL, |
592 |
me => $me, |
me => $me, |
593 |
nick => $nick, |
nick => $nick, |
594 |
msg => $msg, |
message => $msg, |
595 |
time => $dt->ymd . " " . $dt->hms, |
time => $dt->ymd . " " . $dt->hms, |
596 |
) if ($nick !~ m/^-/); |
) if ($nick !~ m/^-/); |
597 |
|
|
633 |
my $channel = $_[ARG1]->[0]; |
my $channel = $_[ARG1]->[0]; |
634 |
my $msg = $_[ARG2]; |
my $msg = $_[ARG2]; |
635 |
|
|
636 |
save_message( channel => $channel, me => 0, nick => $nick, msg => $msg); |
save_message( channel => $channel, me => 0, nick => $nick, message => $msg); |
637 |
meta( $nick, $channel, 'last-msg', $msg ); |
meta( $nick, $channel, 'last-msg', $msg ); |
638 |
}, |
}, |
639 |
irc_ctcp_action => sub { |
irc_ctcp_action => sub { |
642 |
my $channel = $_[ARG1]->[0]; |
my $channel = $_[ARG1]->[0]; |
643 |
my $msg = $_[ARG2]; |
my $msg = $_[ARG2]; |
644 |
|
|
645 |
save_message( channel => $channel, me => 1, nick => $nick, msg => $msg); |
save_message( channel => $channel, me => 1, nick => $nick, message => $msg); |
646 |
|
|
647 |
if ( $use_twitter ) { |
if ( $use_twitter ) { |
648 |
if ( my $twitter = meta( $nick, $NICK, 'twitter' ) ) { |
if ( my $twitter = meta( $nick, $NICK, 'twitter' ) ) { |
915 |
# http server |
# http server |
916 |
|
|
917 |
my $httpd = POE::Component::Server::HTTP->new( |
my $httpd = POE::Component::Server::HTTP->new( |
918 |
Port => $NICK =~ m/-dev/ ? 8001 : 8000, |
Port => $http_port, |
919 |
ContentHandler => { '/' => \&root_handler }, |
ContentHandler => { '/' => \&root_handler }, |
920 |
Headers => { Server => 'irc-logger' }, |
Headers => { Server => 'irc-logger' }, |
921 |
); |
); |
922 |
|
|
|
my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); |
|
|
my $escape_re = join '|' => keys %escape; |
|
|
|
|
923 |
my $style = <<'_END_OF_STYLE_'; |
my $style = <<'_END_OF_STYLE_'; |
924 |
p { margin: 0; padding: 0.1em; } |
p { margin: 0; padding: 0.1em; } |
925 |
.time, .channel { color: #808080; font-size: 60%; } |
.time, .channel { color: #808080; font-size: 60%; } |
941 |
.month { border: 0px; width: 100%; } |
.month { border: 0px; width: 100%; } |
942 |
_END_OF_STYLE_ |
_END_OF_STYLE_ |
943 |
|
|
944 |
my $max_color = 4; |
$max_color = 0; |
945 |
|
|
946 |
my @cols = qw( |
my @cols = qw( |
947 |
#ffcccc #ccffe6 #ccccff #e6ccff #ffccff #ffcce6 #ff9999 #ffcc99 #ffff99 |
#ffcccc #ccffe6 #ccccff #e6ccff #ffccff #ffcce6 #ff9999 #ffcc99 #ffff99 |
951 |
#999900 #009900 #cc0066 #c0c0c0 #ccff99 #99ff33 #808080 #660033 #ffffff |
#999900 #009900 #cc0066 #c0c0c0 #ccff99 #99ff33 #808080 #660033 #ffffff |
952 |
); |
); |
953 |
|
|
|
$max_color = 0; |
|
954 |
foreach my $c (@cols) { |
foreach my $c (@cols) { |
955 |
$style .= ".col-${max_color} { background: $c }\n"; |
$style .= ".col-${max_color} { background: $c }\n"; |
956 |
$max_color++; |
$max_color++; |
957 |
} |
} |
958 |
warn "defined $max_color colors for users...\n"; |
warn "defined $max_color colors for users...\n"; |
959 |
|
|
|
my %nick_enumerator; |
|
|
|
|
960 |
sub root_handler { |
sub root_handler { |
961 |
my ($request, $response) = @_; |
my ($request, $response) = @_; |
962 |
$response->code(RC_OK); |
$response->code(RC_OK); |
963 |
$response->content_type("text/html; charset=$ENCODING"); |
|
964 |
|
return RC_OK if $request->uri =~ m/favicon.ico$/; |
965 |
|
|
966 |
my $q; |
my $q; |
967 |
|
|
975 |
|
|
976 |
my $search = $q->param('search') || $q->param('grep') || ''; |
my $search = $q->param('search') || $q->param('grep') || ''; |
977 |
|
|
978 |
|
if ($request->url =~ m#/rss(?:/(tags|last-tag?)\w+(?:=(\d+))?)?#i) { |
979 |
|
my $show = lc($1); |
980 |
|
my $nr = $2; |
981 |
|
|
982 |
|
my $type = 'RSS'; # Atom |
983 |
|
|
984 |
|
$response->content_type( 'application/' . lc($type) . '+xml' ); |
985 |
|
|
986 |
|
my $html = '<!-- error -->'; |
987 |
|
#warn "create $type feed from ",dump( @last_tags ); |
988 |
|
|
989 |
|
my $feed = XML::Feed->new( $type ); |
990 |
|
|
991 |
|
if ( $show eq 'tags' ) { |
992 |
|
$nr ||= 50; |
993 |
|
$feed->title( "tags from $CHANNEL" ); |
994 |
|
$feed->link( "$url/tags" ); |
995 |
|
$feed->description( "tag cloud created from messages on channel $CHANNEL which have tags// in them" ); |
996 |
|
my $feed_entry = XML::Feed::Entry->new($type); |
997 |
|
$feed_entry->title( "$nr tags from $CHANNEL" ); |
998 |
|
$feed_entry->author( $NICK ); |
999 |
|
$feed_entry->link( '/#tags' ); |
1000 |
|
|
1001 |
|
$feed_entry->content( |
1002 |
|
qq{<![CDATA[<style type="text/css">} |
1003 |
|
. $cloud->css |
1004 |
|
. qq{</style>} |
1005 |
|
. $cloud->html( $nr ) |
1006 |
|
. qq{]]>} |
1007 |
|
); |
1008 |
|
$feed->add_entry( $feed_entry ); |
1009 |
|
|
1010 |
|
} elsif ( $show eq 'last-tag' ) { |
1011 |
|
|
1012 |
|
$nr ||= $last_x_tags; |
1013 |
|
|
1014 |
|
$feed->title( "last $nr tagged messages from $CHANNEL" ); |
1015 |
|
$feed->link( $url ); |
1016 |
|
$feed->description( "collects messages which have tags// in them" ); |
1017 |
|
|
1018 |
|
foreach my $m ( @last_tags ) { |
1019 |
|
# warn dump( $m ); |
1020 |
|
#my $tags = join(' ', @{$m->{tags}} ); |
1021 |
|
my $feed_entry = XML::Feed::Entry->new($type); |
1022 |
|
$feed_entry->title( $m->{nick} . '@' . $m->{time} ); |
1023 |
|
$feed_entry->author( $m->{nick} ); |
1024 |
|
$feed_entry->link( '/#' . $m->{id} ); |
1025 |
|
$feed_entry->issued( DateTime::Format::Flexible->build( $m->{time} ) ); |
1026 |
|
|
1027 |
|
my $message = $filter->{message}->( $m->{message} ); |
1028 |
|
$message .= "<br/>\n" unless $message =~ m!<(/p|br/?)>!; |
1029 |
|
# warn "## message = $message\n"; |
1030 |
|
from_to( $message, $ENCODING, 'UTF-8' ); |
1031 |
|
|
1032 |
|
#$feed_entry->summary( |
1033 |
|
$feed_entry->content( |
1034 |
|
"<![CDATA[$message]]>" |
1035 |
|
); |
1036 |
|
$feed_entry->category( join(', ', @{$m->{tags}}) ); |
1037 |
|
$feed->add_entry( $feed_entry ); |
1038 |
|
|
1039 |
|
$nr--; |
1040 |
|
last if $nr <= 0; |
1041 |
|
|
1042 |
|
} |
1043 |
|
|
1044 |
|
} else { |
1045 |
|
warn "!! unknown rss request for $show\n"; |
1046 |
|
return RC_DENY; |
1047 |
|
} |
1048 |
|
|
1049 |
|
$response->content( $feed->as_xml ); |
1050 |
|
return RC_OK; |
1051 |
|
} |
1052 |
|
|
1053 |
|
if ( $@ ) { |
1054 |
|
warn "$@"; |
1055 |
|
} |
1056 |
|
|
1057 |
|
$response->content_type("text/html; charset=$ENCODING"); |
1058 |
|
|
1059 |
my $html = |
my $html = |
1060 |
qq{<html><head><title>$NICK</title><style type="text/css">$style} . |
qq{<html><head><title>$NICK</title><style type="text/css">$style} |
1061 |
$cloud->css . |
. $cloud->css |
1062 |
qq{</style></head><body>} . |
. qq{</style></head><body>} |
1063 |
qq{ |
. qq{ |
1064 |
<form method="post" class="search" action="/"> |
<form method="post" class="search" action="/"> |
1065 |
<input type="text" name="search" value="$search" size="10"> |
<input type="text" name="search" value="$search" size="10"> |
1066 |
<input type="submit" value="search"> |
<input type="submit" value="search"> |
1067 |
</form> |
</form> |
1068 |
} . |
} |
1069 |
$cloud->html(500) . |
. $cloud->html(500) |
1070 |
qq{<p>}; |
. qq{<p>}; |
1071 |
if ($request->url =~ m#/history#) { |
|
1072 |
|
if ($request->url =~ m#/tags?#) { |
1073 |
|
# nop |
1074 |
|
} elsif ($request->url =~ m#/history#) { |
1075 |
my $sth = $dbh->prepare(qq{ |
my $sth = $dbh->prepare(qq{ |
1076 |
select date(time) as date,count(*) as nr,sum(length(message)) as len |
select date(time) as date,count(*) as nr,sum(length(message)) as len |
1077 |
from log |
from log |
1103 |
$cal->weekdays('MON','TUE','WED','THU','FRI'); |
$cal->weekdays('MON','TUE','WED','THU','FRI'); |
1104 |
($l_yyyy,$l_mm) = ($yyyy,$mm); |
($l_yyyy,$l_mm) = ($yyyy,$mm); |
1105 |
} |
} |
1106 |
$cal->setcontent($dd, qq{ |
$cal->setcontent($dd, qq[ |
1107 |
<a href="/?date=$row->{date}">$row->{nr}</a><br/>$row->{len} |
<a href="$url?date=$row->{date}">$row->{nr}</a><br/>$row->{len} |
1108 |
}); |
]); |
1109 |
|
|
1110 |
} |
} |
1111 |
$html .= qq{<td valign="top">} . $cal->as_HTML() . qq{</td></tr></table>}; |
$html .= qq{<td valign="top">} . $cal->as_HTML() . qq{</td></tr></table>}; |
1113 |
} else { |
} else { |
1114 |
$html .= join("</p><p>", |
$html .= join("</p><p>", |
1115 |
get_from_log( |
get_from_log( |
1116 |
limit => $q->param('last') || $q->param('date') ? undef : 100, |
limit => ( $q->param('last') || $q->param('date') ) ? undef : 100, |
1117 |
search => $search || undef, |
search => $search || undef, |
1118 |
tag => $q->param('tag') || undef, |
tag => $q->param('tag') || undef, |
1119 |
date => $q->param('date') || undef, |
date => $q->param('date') || undef, |
1120 |
fmt => { |
fmt => { |
1121 |
date => sub { |
date => sub { |
1122 |
my $date = shift || return; |
my $date = shift || return; |
1123 |
qq{<hr/><div class="date"><a href="/?date=$date">$date</a></div>}; |
qq{<hr/><div class="date"><a href="$url?date=$date">$date</a></div>}; |
1124 |
}, |
}, |
1125 |
time => '<span class="time">%s</span> ', |
time => '<span class="time">%s</span> ', |
1126 |
time_channel => '<span class="channel">%s %s</span> ', |
time_channel => '<span class="channel">%s %s</span> ', |
1128 |
me_nick => '***%s ', |
me_nick => '***%s ', |
1129 |
message => '<span class="message">%s</span>', |
message => '<span class="message">%s</span>', |
1130 |
}, |
}, |
1131 |
filter => { |
filter => $filter, |
|
message => sub { |
|
|
my $m = shift || return; |
|
|
|
|
|
# protect HTML from wiki modifications |
|
|
sub e { |
|
|
my $t = shift; |
|
|
return 'uri_unescape{' . uri_escape($t) . '}'; |
|
|
} |
|
|
|
|
|
$m =~ s/($escape_re)/$escape{$1}/gs; |
|
|
$m =~ s#($RE{URI}{HTTP})#e(qq{<a href="$1">$1</a>})#egs; |
|
|
$m =~ s#$tag_regex#e(qq{<a href="?tag=$1" class="tag">$1</a>})#egs; |
|
|
$m =~ s#\*(\w+)\*#<b>$1</b>#gs; |
|
|
$m =~ s#_(\w+)_#<u>$1</u>#gs; |
|
|
$m =~ s#\/(\w+)\/#<i>$1</i>#gs; |
|
|
|
|
|
$m =~ s#uri_unescape{([^}]+)}#uri_unescape($1)#egs; |
|
|
return $m; |
|
|
}, |
|
|
nick => sub { |
|
|
my $n = shift || return; |
|
|
if (! $nick_enumerator{$n}) { |
|
|
my $max = scalar keys %nick_enumerator; |
|
|
$nick_enumerator{$n} = $max + 1; |
|
|
} |
|
|
return '<span class="nick col-' . |
|
|
( $nick_enumerator{$n} % $max_color ) . |
|
|
'">' . $n . '</span>'; |
|
|
}, |
|
|
}, |
|
1132 |
) |
) |
1133 |
); |
); |
1134 |
} |
} |
1139 |
</body></html>}; |
</body></html>}; |
1140 |
|
|
1141 |
$response->content( $html ); |
$response->content( $html ); |
1142 |
|
warn "<< ", $request->method, " ", $request->uri, " created ", length($html), " bytes\n"; |
1143 |
return RC_OK; |
return RC_OK; |
1144 |
} |
} |
1145 |
|
|