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 |
|
|
81 |
use HTML::CalendarMonthSimple; |
use HTML::CalendarMonthSimple; |
82 |
use Getopt::Long; |
use Getopt::Long; |
83 |
use DateTime; |
use DateTime; |
84 |
|
use URI::Escape; |
85 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
86 |
|
use DateTime::Format::ISO8601; |
87 |
|
use Carp qw/confess/; |
88 |
|
use XML::Feed; |
89 |
|
use DateTime::Format::Flexible; |
90 |
|
|
91 |
|
my $use_twitter = 1; |
92 |
|
eval { require Net::Twitter; }; |
93 |
|
$use_twitter = 0 if ($@); |
94 |
|
|
95 |
my $import_dircproxy; |
my $import_dircproxy; |
96 |
my $log_path; |
my $log_path; |
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 |
$sql .= " where date(time) = ? " if ($args->{date}); |
my $new_date = eval { DateTime::Format::ISO8601->parse_datetime( $date )->ymd; }; |
324 |
$sql .= " order by log.time desc"; |
if ( $@ ) { |
325 |
$sql .= " limit " . $args->{limit} if ($args->{limit}); |
warn "invalid date $date\n"; |
326 |
|
$new_date = DateTime->now->ymd; |
327 |
|
} |
328 |
|
return $new_date; |
329 |
|
} |
330 |
|
|
331 |
|
my @where; |
332 |
|
my @args; |
333 |
|
|
|
my $sth = $dbh->prepare( $sql ); |
|
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'"; |
340 |
$sth->execute(); |
} |
341 |
_log "tag '$tag' returned ", $sth->rows, " results ", $context || ''; |
|
342 |
} elsif (my $date = $args->{date}) { |
if ($args->{tag} && $tags->{ $args->{tag} }) { |
343 |
$sth->execute($date); |
push @where, 'id in (' . join(',', @{ $tags->{ $args->{tag} } }) . ')'; |
344 |
_log "found ", $sth->rows, " messages for date $date ", $context || ''; |
_log "search for tags $args->{tag}"; |
|
} else { |
|
|
$sth->execute(); |
|
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 ( my $twitter = ( $nick, $channel, 'twitter' ) ) { |
if ( $use_twitter ) { |
648 |
_log("FIXME: send twitter for $nick on $channel [$twitter]"); |
if ( my $twitter = meta( $nick, $NICK, 'twitter' ) ) { |
649 |
|
my ($login,$passwd) = split(/\s+/,$twitter,2); |
650 |
|
_log("sending twitter for $nick/$login on $channel "); |
651 |
|
my $bot = Net::Twitter->new( username=>$login, password=>$passwd ); |
652 |
|
$bot->update("<${channel}> $msg"); |
653 |
|
} |
654 |
} |
} |
655 |
|
|
656 |
}, |
}, |
697 |
|
|
698 |
my $sth = $dbh->prepare(qq{ |
my $sth = $dbh->prepare(qq{ |
699 |
select |
select |
700 |
nick, |
trim(both '_' from nick) as nick, |
701 |
count(*) as count, |
count(*) as count, |
702 |
sum(length(message)) as len |
sum(length(message)) as len |
703 |
from log |
from log |
704 |
group by nick |
group by trim(both '_' from nick) |
705 |
order by len desc,count desc |
order by len desc,count desc |
706 |
limit $nr |
limit $nr |
707 |
}); |
}); |
777 |
if ( ! defined( $1 ) ) { |
if ( ! defined( $1 ) ) { |
778 |
my $sth = $dbh->prepare(qq{ select name,value,changed from meta where nick = ? and channel = ? }); |
my $sth = $dbh->prepare(qq{ select name,value,changed from meta where nick = ? and channel = ? }); |
779 |
$sth->execute( $nick, $channel ); |
$sth->execute( $nick, $channel ); |
780 |
$res = "config for $nick "; |
$res = "config for $nick on $channel"; |
781 |
while ( my ($n,$v) = $sth->fetchrow_array ) { |
while ( my ($n,$v) = $sth->fetchrow_array ) { |
782 |
$res .= "| $n = $v"; |
$res .= " | $n = $v"; |
783 |
} |
} |
784 |
} elsif ( ! $2 ) { |
} elsif ( ! $2 ) { |
785 |
my $val = meta( $nick, $channel, $1 ); |
my $val = meta( $nick, $channel, $1 ); |
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%; } |
927 |
.nick { color: #000000; font-size: 80%; padding: 2px; font-family: courier, courier new, monospace ; } |
.nick { color: #000000; font-size: 80%; padding: 2px; font-family: courier, courier new, monospace ; } |
928 |
.message { color: #000000; font-size: 100%; } |
.message { color: #000000; font-size: 100%; } |
929 |
.search { float: right; } |
.search { float: right; } |
930 |
|
a:link.tag, a:visited.tag { border: 1px dashed #ccc; backgound: #ccc; text-decoration: none } |
931 |
|
a:hover.tag { border: 1px solid #eee } |
932 |
|
hr { border: 1px dashed #ccc; height: 1px; clear: both; } |
933 |
|
/* |
934 |
.col-0 { background: #ffff66 } |
.col-0 { background: #ffff66 } |
935 |
.col-1 { background: #a0ffff } |
.col-1 { background: #a0ffff } |
936 |
.col-2 { background: #99ff99 } |
.col-2 { background: #99ff99 } |
937 |
.col-3 { background: #ff9999 } |
.col-3 { background: #ff9999 } |
938 |
.col-4 { background: #ff66ff } |
.col-4 { background: #ff66ff } |
939 |
a:link.tag, a:visited.tag { border: 1px dashed #ccc; backgound: #ccc; text-decoration: none } |
*/ |
940 |
a:hover.tag { border: 1px solid #eee } |
.calendar { border: 1px solid red; width: 100%; } |
941 |
hr { border: 1px dashed #ccc; height: 1px; clear: both; } |
.month { border: 0px; width: 100%; } |
942 |
_END_OF_STYLE_ |
_END_OF_STYLE_ |
943 |
|
|
944 |
my $max_color = 4; |
$max_color = 0; |
945 |
|
|
946 |
my %nick_enumerator; |
my @cols = qw( |
947 |
|
#ffcccc #ccffe6 #ccccff #e6ccff #ffccff #ffcce6 #ff9999 #ffcc99 #ffff99 |
948 |
|
#ccff99 #99ff99 #99ffcc #99ccff #9999ff #cc99ff #ff6666 #ffb366 #ffff66 |
949 |
|
#66ff66 #66ffb3 #66b3ff #6666ff #ff3333 #33ff33 #3399ff #3333ff #ff3399 |
950 |
|
#a0a0a0 #ff0000 #ffff00 #80ff00 #0000ff #8000ff #ff00ff #ff0080 #994d00 |
951 |
|
#999900 #009900 #cc0066 #c0c0c0 #ccff99 #99ff33 #808080 #660033 #ffffff |
952 |
|
); |
953 |
|
|
954 |
|
foreach my $c (@cols) { |
955 |
|
$style .= ".col-${max_color} { background: $c }\n"; |
956 |
|
$max_color++; |
957 |
|
} |
958 |
|
warn "defined $max_color colors for users...\n"; |
959 |
|
|
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 |
|
$nr = $last_x_tags if $nr > $last_x_tags; |
1014 |
|
|
1015 |
|
$feed->title( "last $nr tagged messages from $CHANNEL" ); |
1016 |
|
$feed->link( $url ); |
1017 |
|
$feed->description( "collects messages which have tags// in them" ); |
1018 |
|
|
1019 |
|
foreach my $m ( @last_tags ) { |
1020 |
|
# warn dump( $m ); |
1021 |
|
#my $tags = join(' ', @{$m->{tags}} ); |
1022 |
|
my $feed_entry = XML::Feed::Entry->new($type); |
1023 |
|
$feed_entry->title( $m->{nick} . '@' . $m->{time} ); |
1024 |
|
$feed_entry->author( $m->{nick} ); |
1025 |
|
$feed_entry->link( '/#' . $m->{id} ); |
1026 |
|
$feed_entry->issued( DateTime::Format::Flexible->build( $m->{time} ) ); |
1027 |
|
|
1028 |
|
my $message = $filter->{message}->( $m->{message} ); |
1029 |
|
$message .= "<br/>\n" unless $message =~ m!<(/p|br/?)>!; |
1030 |
|
# warn "## message = $message\n"; |
1031 |
|
from_to( $message, $ENCODING, 'UTF-8' ); |
1032 |
|
|
1033 |
|
#$feed_entry->summary( |
1034 |
|
$feed_entry->content( |
1035 |
|
"<![CDATA[$message]]>" |
1036 |
|
); |
1037 |
|
$feed_entry->category( join(', ', @{$m->{tags}}) ); |
1038 |
|
$feed->add_entry( $feed_entry ); |
1039 |
|
|
1040 |
|
$nr--; |
1041 |
|
last if $nr <= 0; |
1042 |
|
|
1043 |
|
} |
1044 |
|
|
1045 |
|
} else { |
1046 |
|
warn "!! unknown rss request for $show\n"; |
1047 |
|
return RC_DENY; |
1048 |
|
} |
1049 |
|
|
1050 |
|
$response->content( $feed->as_xml ); |
1051 |
|
return RC_OK; |
1052 |
|
} |
1053 |
|
|
1054 |
|
if ( $@ ) { |
1055 |
|
warn "$@"; |
1056 |
|
} |
1057 |
|
|
1058 |
|
$response->content_type("text/html; charset=$ENCODING"); |
1059 |
|
|
1060 |
my $html = |
my $html = |
1061 |
qq{<html><head><title>$NICK</title><style type="text/css">$style} . |
qq{<html><head><title>$NICK</title><style type="text/css">$style} |
1062 |
$cloud->css . |
. $cloud->css |
1063 |
qq{</style></head><body>} . |
. qq{</style></head><body>} |
1064 |
qq{ |
. qq{ |
1065 |
<form method="post" class="search" action="/"> |
<form method="post" class="search" action="/"> |
1066 |
<input type="text" name="search" value="$search" size="10"> |
<input type="text" name="search" value="$search" size="10"> |
1067 |
<input type="submit" value="search"> |
<input type="submit" value="search"> |
1068 |
</form> |
</form> |
1069 |
} . |
} |
1070 |
$cloud->html(500) . |
. $cloud->html(500) |
1071 |
qq{<p>}; |
. qq{<p>}; |
1072 |
if ($request->url =~ m#/history#) { |
|
1073 |
|
if ($request->url =~ m#/tags?#) { |
1074 |
|
# nop |
1075 |
|
} elsif ($request->url =~ m#/history#) { |
1076 |
my $sth = $dbh->prepare(qq{ |
my $sth = $dbh->prepare(qq{ |
1077 |
select date(time) as date,count(*) as nr |
select date(time) as date,count(*) as nr,sum(length(message)) as len |
1078 |
from log |
from log |
1079 |
group by date(time) |
group by date(time) |
1080 |
order by date(time) desc |
order by date(time) desc |
1081 |
}); |
}); |
1082 |
$sth->execute(); |
$sth->execute(); |
1083 |
my ($l_yyyy,$l_mm) = (0,0); |
my ($l_yyyy,$l_mm) = (0,0); |
1084 |
|
$html .= qq{<table class="calendar"><tr>}; |
1085 |
my $cal; |
my $cal; |
1086 |
|
my $ord = 0; |
1087 |
while (my $row = $sth->fetchrow_hashref) { |
while (my $row = $sth->fetchrow_hashref) { |
1088 |
# this is probably PostgreSQL specific, expects ISO date |
# this is probably PostgreSQL specific, expects ISO date |
1089 |
my ($yyyy,$mm,$dd) = split(/-/, $row->{date}); |
my ($yyyy,$mm,$dd) = split(/-/, $row->{date}); |
1090 |
if ($yyyy != $l_yyyy || $mm != $l_mm) { |
if ($yyyy != $l_yyyy || $mm != $l_mm) { |
1091 |
$html .= $cal->as_HTML() if ($cal); |
if ( $cal ) { |
1092 |
|
$html .= qq{<td valign="top">} . $cal->as_HTML() . qq{</td>}; |
1093 |
|
$ord++; |
1094 |
|
$html .= qq{</tr><tr>} if ( $ord % 3 == 0 ); |
1095 |
|
} |
1096 |
$cal = new HTML::CalendarMonthSimple('month'=>$mm,'year'=>$yyyy); |
$cal = new HTML::CalendarMonthSimple('month'=>$mm,'year'=>$yyyy); |
1097 |
$cal->border(2); |
$cal->border(1); |
1098 |
|
$cal->width('30%'); |
1099 |
|
$cal->cellheight('5em'); |
1100 |
|
$cal->tableclass('month'); |
1101 |
|
#$cal->cellclass('day'); |
1102 |
|
$cal->sunday('SUN'); |
1103 |
|
$cal->saturday('SAT'); |
1104 |
|
$cal->weekdays('MON','TUE','WED','THU','FRI'); |
1105 |
($l_yyyy,$l_mm) = ($yyyy,$mm); |
($l_yyyy,$l_mm) = ($yyyy,$mm); |
1106 |
} |
} |
1107 |
$cal->setcontent($dd, qq{ |
$cal->setcontent($dd, qq[ |
1108 |
<a href="/?date=$row->{date}">$row->{nr}</a> |
<a href="$url?date=$row->{date}">$row->{nr}</a><br/>$row->{len} |
1109 |
}); |
]); |
1110 |
|
|
1111 |
} |
} |
1112 |
$html .= $cal->as_HTML() if ($cal); |
$html .= qq{<td valign="top">} . $cal->as_HTML() . qq{</td></tr></table>}; |
1113 |
|
|
1114 |
} else { |
} else { |
1115 |
$html .= join("</p><p>", |
$html .= join("</p><p>", |
1116 |
get_from_log( |
get_from_log( |
1117 |
limit => $q->param('last') || $q->param('date') ? undef : 100, |
limit => ( $q->param('last') || $q->param('date') ) ? undef : 100, |
1118 |
search => $search || undef, |
search => $search || undef, |
1119 |
tag => $q->param('tag') || undef, |
tag => $q->param('tag') || undef, |
1120 |
date => $q->param('date') || undef, |
date => $q->param('date') || undef, |
1121 |
fmt => { |
fmt => { |
1122 |
date => sub { |
date => sub { |
1123 |
my $date = shift || return; |
my $date = shift || return; |
1124 |
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>}; |
1125 |
}, |
}, |
1126 |
time => '<span class="time">%s</span> ', |
time => '<span class="time">%s</span> ', |
1127 |
time_channel => '<span class="channel">%s %s</span> ', |
time_channel => '<span class="channel">%s %s</span> ', |
1129 |
me_nick => '***%s ', |
me_nick => '***%s ', |
1130 |
message => '<span class="message">%s</span>', |
message => '<span class="message">%s</span>', |
1131 |
}, |
}, |
1132 |
filter => { |
filter => $filter, |
|
message => sub { |
|
|
my $m = shift || return; |
|
|
$m =~ s/($escape_re)/$escape{$1}/gs; |
|
|
$m =~ s#($RE{URI}{HTTP})#<a href="$1">$1</a>#gs; |
|
|
$m =~ s#$tag_regex#<a href="?tag=$1" class="tag">$1</a>#g; |
|
|
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>'; |
|
|
}, |
|
|
}, |
|
1133 |
) |
) |
1134 |
); |
); |
1135 |
} |
} |
1140 |
</body></html>}; |
</body></html>}; |
1141 |
|
|
1142 |
$response->content( $html ); |
$response->content( $html ); |
1143 |
|
warn "<< ", $request->method, " ", $request->uri, " created ", length($html), " bytes\n"; |
1144 |
return RC_OK; |
return RC_OK; |
1145 |
} |
} |
1146 |
|
|