18 |
|
|
19 |
Import log from C<dircproxy> to C<irc-logger> database |
Import log from C<dircproxy> to C<irc-logger> database |
20 |
|
|
21 |
|
=item --log=irc-logger.log |
22 |
|
|
23 |
|
Name of log file |
24 |
|
|
25 |
|
=item --follow=file.log |
26 |
|
|
27 |
|
Follows new messages in file |
28 |
|
|
29 |
|
=back |
30 |
|
|
31 |
=head1 DESCRIPTION |
=head1 DESCRIPTION |
32 |
|
|
33 |
log all conversation on irc channel |
log all conversation on irc channel |
36 |
|
|
37 |
## CONFIG |
## CONFIG |
38 |
|
|
39 |
my $HOSTNAME = `hostname`; |
my $HOSTNAME = `hostname -f`; |
40 |
|
chomp($HOSTNAME); |
41 |
|
|
42 |
my $NICK = 'irc-logger'; |
my $NICK = 'irc-logger'; |
43 |
$NICK .= '-dev' if ($HOSTNAME =~ m/llin/); |
$NICK .= '-dev' if ($HOSTNAME =~ m/llin/); |
50 |
$CHANNEL = '#irc-logger' if ($HOSTNAME =~ m/llin/); |
$CHANNEL = '#irc-logger' if ($HOSTNAME =~ m/llin/); |
51 |
my $IRC_ALIAS = "log"; |
my $IRC_ALIAS = "log"; |
52 |
|
|
53 |
my %FOLLOWS = |
# default log to follow and announce messages |
54 |
( |
my $follows_path = 'follows.log'; |
|
ACCESS => "/var/log/apache/access.log", |
|
|
ERROR => "/var/log/apache/error.log", |
|
|
); |
|
55 |
|
|
56 |
my $DSN = 'DBI:Pg:dbname=' . $NICK; |
my $DSN = 'DBI:Pg:dbname=' . $NICK; |
57 |
|
|
60 |
|
|
61 |
my $sleep_on_error = 5; |
my $sleep_on_error = 5; |
62 |
|
|
63 |
|
# number of last tags to keep in circular buffer |
64 |
|
my $last_x_tags = 50; |
65 |
|
|
66 |
|
my $http_port = $NICK =~ m/-dev/ ? 8001 : 8000; |
67 |
|
|
68 |
|
my $url = "http://$HOSTNAME:$http_port"; |
69 |
|
|
70 |
## END CONFIG |
## END CONFIG |
71 |
|
|
72 |
|
|
82 |
use HTML::CalendarMonthSimple; |
use HTML::CalendarMonthSimple; |
83 |
use Getopt::Long; |
use Getopt::Long; |
84 |
use DateTime; |
use DateTime; |
85 |
|
use URI::Escape; |
86 |
|
use Data::Dump qw/dump/; |
87 |
|
use DateTime::Format::ISO8601; |
88 |
|
use Carp qw/confess/; |
89 |
|
use XML::Feed; |
90 |
|
use DateTime::Format::Flexible; |
91 |
|
|
92 |
|
my $use_twitter = 1; |
93 |
|
eval { require Net::Twitter; }; |
94 |
|
$use_twitter = 0 if ($@); |
95 |
|
|
96 |
my $import_dircproxy; |
my $import_dircproxy; |
97 |
|
my $log_path; |
98 |
GetOptions( |
GetOptions( |
99 |
'import-dircproxy:s' => \$import_dircproxy, |
'import-dircproxy:s' => \$import_dircproxy, |
100 |
|
'follows:s' => \$follows_path, |
101 |
|
'log:s' => \$log_path, |
102 |
); |
); |
103 |
|
|
104 |
my $dbh = DBI->connect($DSN,"","", { RaiseError => 1, AutoCommit => 1 }) || die $DBI::errstr; |
$SIG{__DIE__} = sub { |
105 |
|
confess "fatal error"; |
106 |
|
}; |
107 |
|
|
108 |
|
open(STDOUT, '>', $log_path) || warn "can't redirect log to $log_path: $!"; |
109 |
|
|
110 |
|
sub _log { |
111 |
|
print strftime($TIMESTAMP,localtime()), ' ', join(" ",@_), $/; |
112 |
|
} |
113 |
|
|
114 |
|
# LOG following |
115 |
|
|
116 |
|
my %FOLLOWS = |
117 |
|
( |
118 |
|
# ACCESS => "/var/log/apache/access.log", |
119 |
|
# ERROR => "/var/log/apache/error.log", |
120 |
|
); |
121 |
|
|
122 |
eval { |
sub add_follow_path { |
123 |
$dbh->do(qq{ select count(*) from log }); |
my $path = shift; |
124 |
|
my $name = $path; |
125 |
|
$name =~ s/\..*$//; |
126 |
|
warn "# using $path to announce messages from $name\n"; |
127 |
|
$FOLLOWS{$name} = $path; |
128 |
|
} |
129 |
|
|
130 |
|
add_follow_path( $follows_path ) if ( -e $follows_path ); |
131 |
|
|
132 |
|
# HTML formatters |
133 |
|
|
134 |
|
my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); |
135 |
|
my $escape_re = join '|' => keys %escape; |
136 |
|
|
137 |
|
my $tag_regex = '\b([\w-_]+)//'; |
138 |
|
|
139 |
|
my %nick_enumerator; |
140 |
|
my $max_color = 0; |
141 |
|
|
142 |
|
my $filter = { |
143 |
|
message => sub { |
144 |
|
my $m = shift || return; |
145 |
|
|
146 |
|
# protect HTML from wiki modifications |
147 |
|
sub e { |
148 |
|
my $t = shift; |
149 |
|
return 'uri_unescape{' . uri_escape($t) . '}'; |
150 |
|
} |
151 |
|
|
152 |
|
$m =~ s/($escape_re)/$escape{$1}/gs; |
153 |
|
$m =~ s#($RE{URI}{HTTP})#e(qq{<a href="$1">$1</a>})#egs || |
154 |
|
$m =~ s#\/(\w+)\/#<i>$1</i>#gs; |
155 |
|
$m =~ s#$tag_regex#e(qq{<a href="$url?tag=$1" class="tag">$1</a>})#egs; |
156 |
|
$m =~ s#\*(\w+)\*#<b>$1</b>#gs; |
157 |
|
$m =~ s#_(\w+)_#<u>$1</u>#gs; |
158 |
|
|
159 |
|
$m =~ s#uri_unescape{([^}]+)}#uri_unescape($1)#egs; |
160 |
|
return $m; |
161 |
|
}, |
162 |
|
nick => sub { |
163 |
|
my $n = shift || return; |
164 |
|
if (! $nick_enumerator{$n}) { |
165 |
|
my $max = scalar keys %nick_enumerator; |
166 |
|
$nick_enumerator{$n} = $max + 1; |
167 |
|
} |
168 |
|
return '<span class="nick col-' . |
169 |
|
( $nick_enumerator{$n} % $max_color ) . |
170 |
|
'">' . $n . '</span>'; |
171 |
|
}, |
172 |
}; |
}; |
173 |
|
|
174 |
if ($@) { |
my $dbh = DBI->connect($DSN,"","", { RaiseError => 1, AutoCommit => 1 }) || die $DBI::errstr; |
|
warn "creating database table in $DSN\n"; |
|
|
$dbh->do(<<'_SQL_SCHEMA_'); |
|
175 |
|
|
176 |
|
my $sql_schema = { |
177 |
|
log => ' |
178 |
create table log ( |
create table log ( |
179 |
id serial, |
id serial, |
180 |
time timestamp default now(), |
time timestamp default now(), |
188 |
create index log_time on log(time); |
create index log_time on log(time); |
189 |
create index log_channel on log(channel); |
create index log_channel on log(channel); |
190 |
create index log_nick on log(nick); |
create index log_nick on log(nick); |
191 |
|
', |
192 |
|
meta => ' |
193 |
|
create table meta ( |
194 |
|
nick text not null, |
195 |
|
channel text not null, |
196 |
|
name text not null, |
197 |
|
value text, |
198 |
|
changed timestamp default now(), |
199 |
|
primary key(nick,channel,name) |
200 |
|
); |
201 |
|
', |
202 |
|
}; |
203 |
|
|
204 |
|
foreach my $table ( keys %$sql_schema ) { |
205 |
|
|
206 |
|
eval { |
207 |
|
$dbh->do(qq{ select count(*) from $table }); |
208 |
|
}; |
209 |
|
|
210 |
|
if ($@) { |
211 |
|
warn "creating database table $table in $DSN\n"; |
212 |
|
$dbh->do( $sql_schema->{ $table } ); |
213 |
|
} |
214 |
|
} |
215 |
|
|
216 |
|
|
217 |
|
=head2 meta |
218 |
|
|
219 |
|
Set or get some meta data into database |
220 |
|
|
221 |
|
meta('nick','channel','var_name', $var_value ); |
222 |
|
|
223 |
|
$var_value = meta('nick','channel','var_name'); |
224 |
|
( $var_value, $changed ) = meta('nick','channel','var_name'); |
225 |
|
|
226 |
|
=cut |
227 |
|
|
228 |
|
sub meta { |
229 |
|
my ($nick,$channel,$name,$value) = @_; |
230 |
|
|
231 |
|
# normalize channel name |
232 |
|
$channel =~ s/^#//; |
233 |
|
|
234 |
|
if (defined($value)) { |
235 |
|
|
236 |
|
my $sth = $dbh->prepare(qq{ update meta set value = ?, changed = now() where nick = ? and channel = ? and name = ? }); |
237 |
|
|
238 |
|
eval { $sth->execute( $value, $nick, $channel, $name ) }; |
239 |
|
|
240 |
|
# error or no result |
241 |
|
if ( $@ || ! $sth->rows ) { |
242 |
|
$sth = $dbh->prepare(qq{ insert into meta (value,nick,channel,name,changed) values (?,?,?,?,now()) }); |
243 |
|
$sth->execute( $value, $nick, $channel, $name ); |
244 |
|
_log "created $nick/$channel/$name = $value"; |
245 |
|
} else { |
246 |
|
_log "updated $nick/$channel/$name = $value "; |
247 |
|
} |
248 |
|
|
249 |
|
return $value; |
250 |
|
|
251 |
|
} else { |
252 |
|
|
253 |
|
my $sth = $dbh->prepare(qq{ select value,changed from meta where nick = ? and channel = ? and name = ? }); |
254 |
|
$sth->execute( $nick, $channel, $name ); |
255 |
|
my ($v,$c) = $sth->fetchrow_array; |
256 |
|
_log "fetched $nick/$channel/$name = $v [$c]"; |
257 |
|
return ($v,$c) if wantarray; |
258 |
|
return $v; |
259 |
|
|
260 |
_SQL_SCHEMA_ |
} |
261 |
} |
} |
262 |
|
|
263 |
|
|
264 |
|
|
265 |
my $sth = $dbh->prepare(qq{ |
my $sth = $dbh->prepare(qq{ |
266 |
insert into log |
insert into log |
267 |
(channel, me, nick, message, time) |
(channel, me, nick, message, time) |
268 |
values (?,?,?,?,?) |
values (?,?,?,?,?) |
269 |
}); |
}); |
270 |
|
|
271 |
|
|
272 |
my $tags; |
my $tags; |
|
my $tag_regex = '\b([\w-_]+)//'; |
|
273 |
|
|
274 |
=head2 get_from_log |
=head2 get_from_log |
275 |
|
|
306 |
sub get_from_log { |
sub get_from_log { |
307 |
my $args = {@_}; |
my $args = {@_}; |
308 |
|
|
309 |
$args->{fmt} ||= { |
if ( ! $args->{fmt} ) { |
310 |
date => '[%s] ', |
$args->{fmt} = { |
311 |
time => '{%s} ', |
date => '[%s] ', |
312 |
time_channel => '{%s %s} ', |
time => '{%s} ', |
313 |
nick => '%s: ', |
time_channel => '{%s %s} ', |
314 |
me_nick => '***%s ', |
nick => '%s: ', |
315 |
message => '%s', |
me_nick => '***%s ', |
316 |
}; |
message => '%s', |
317 |
|
}; |
318 |
|
} |
319 |
|
|
320 |
my $sql_message = qq{ |
my $sql_message = qq{ |
321 |
select |
select |
338 |
|
|
339 |
my $sql = $context ? $sql_context : $sql_message; |
my $sql = $context ? $sql_context : $sql_message; |
340 |
|
|
341 |
$sql .= " where message ilike ? or nick ilike ? " if ($args->{search}); |
sub check_date { |
342 |
$sql .= " where id in (" . join(",", @{ $tags->{ $args->{tag} } }) . ") " if ($args->{tag} && $tags->{ $args->{tag} }); |
my $date = shift || return; |
343 |
$sql .= " where date(time) = ? " if ($args->{date}); |
my $new_date = eval { DateTime::Format::ISO8601->parse_datetime( $date )->ymd; }; |
344 |
$sql .= " order by log.time desc"; |
if ( $@ ) { |
345 |
$sql .= " limit " . $args->{limit} if ($args->{limit}); |
warn "invalid date $date\n"; |
346 |
|
$new_date = DateTime->now->ymd; |
347 |
|
} |
348 |
|
return $new_date; |
349 |
|
} |
350 |
|
|
351 |
|
my @where; |
352 |
|
my @args; |
353 |
|
|
|
my $sth = $dbh->prepare( $sql ); |
|
354 |
if (my $search = $args->{search}) { |
if (my $search = $args->{search}) { |
355 |
$search =~ s/^\s+//; |
$search =~ s/^\s+//; |
356 |
$search =~ s/\s+$//; |
$search =~ s/\s+$//; |
357 |
$sth->execute( ( '%' . $search . '%' ) x 2 ); |
push @where, 'message ilike ? or nick ilike ?'; |
358 |
warn "search for '$search' returned ", $sth->rows, " results ", $context || '', "\n"; |
push @args, ( ( '%' . $search . '%' ) x 2 ); |
359 |
} elsif (my $tag = $args->{tag}) { |
_log "search for '$search'"; |
|
$sth->execute(); |
|
|
warn "tag '$tag' returned ", $sth->rows, " results ", $context || '', "\n"; |
|
|
} elsif (my $date = $args->{date}) { |
|
|
$sth->execute($date); |
|
|
warn "found ", $sth->rows, " messages for date $date ", $context || '', "\n"; |
|
|
} else { |
|
|
$sth->execute(); |
|
360 |
} |
} |
361 |
|
|
362 |
|
if ($args->{tag} && $tags->{ $args->{tag} }) { |
363 |
|
push @where, 'id in (' . join(',', @{ $tags->{ $args->{tag} } }) . ')'; |
364 |
|
_log "search for tags $args->{tag}"; |
365 |
|
} |
366 |
|
|
367 |
|
if (my $date = $args->{date} ) { |
368 |
|
$date = check_date( $date ); |
369 |
|
push @where, 'date(time) = ?'; |
370 |
|
push @args, $date; |
371 |
|
_log "search for date $date"; |
372 |
|
} |
373 |
|
|
374 |
|
$sql .= " where " . join(" and ", @where) if @where; |
375 |
|
|
376 |
|
$sql .= " order by log.time desc"; |
377 |
|
$sql .= " limit " . $args->{limit} if ($args->{limit}); |
378 |
|
|
379 |
|
#warn "### sql: $sql ", dump( @args ); |
380 |
|
|
381 |
|
my $sth = $dbh->prepare( $sql ); |
382 |
|
eval { $sth->execute( @args ) }; |
383 |
|
return if $@; |
384 |
|
|
385 |
my $last_row = { |
my $last_row = { |
386 |
date => '', |
date => '', |
387 |
time => '', |
time => '', |
502 |
|
|
503 |
=head2 add_tag |
=head2 add_tag |
504 |
|
|
505 |
add_tag( id => 42, message => 'irc message' ); |
add_tag( id => 42, message => 'irc message', nick => 'foobar' [, me => 1 ] ); |
506 |
|
|
507 |
=cut |
=cut |
508 |
|
|
509 |
|
my @last_tags; |
510 |
|
|
511 |
sub add_tag { |
sub add_tag { |
512 |
my $arg = {@_}; |
my $arg = {@_}; |
513 |
|
|
516 |
my $m = $arg->{message}; |
my $m = $arg->{message}; |
517 |
from_to('UTF-8', 'iso-8859-2', $m) if (is_utf8($m)); |
from_to('UTF-8', 'iso-8859-2', $m) if (is_utf8($m)); |
518 |
|
|
519 |
|
my @tags; |
520 |
|
|
521 |
while ($m =~ s#$tag_regex##s) { |
while ($m =~ s#$tag_regex##s) { |
522 |
my $tag = $1; |
my $tag = $1; |
523 |
next if (! $tag || $tag =~ m/https?:/i); |
next if (! $tag || $tag =~ m/https?:/i); |
524 |
push @{ $tags->{$tag} }, $arg->{id}; |
push @{ $tags->{$tag} }, $arg->{id}; |
525 |
#warn "+tag $tag: $arg->{id}\n"; |
#warn "+tag $tag: $arg->{id}\n"; |
526 |
$cloud->add($tag, "?tag=$tag", scalar @{$tags->{$tag}} + 1); |
$cloud->add($tag, "$url?tag=$tag", scalar @{$tags->{$tag}} + 1); |
527 |
|
push @tags, $tag; |
528 |
|
|
529 |
|
} |
530 |
|
|
531 |
|
if ( @tags ) { |
532 |
|
pop @last_tags if $#last_tags == $last_x_tags; |
533 |
|
unshift @last_tags, { tags => [ @tags ], %$arg }; |
534 |
} |
} |
535 |
|
|
536 |
} |
} |
537 |
|
|
538 |
=head2 seed_tags |
=head2 seed_tags |
542 |
=cut |
=cut |
543 |
|
|
544 |
sub seed_tags { |
sub seed_tags { |
545 |
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 }); |
546 |
$sth->execute; |
$sth->execute; |
547 |
while (my $row = $sth->fetchrow_hashref) { |
while (my $row = $sth->fetchrow_hashref) { |
548 |
add_tag( %$row ); |
add_tag( %$row ); |
549 |
} |
} |
550 |
|
|
551 |
foreach my $tag (keys %$tags) { |
foreach my $tag (keys %$tags) { |
552 |
$cloud->add($tag, "?tag=$tag", scalar @{$tags->{$tag}} + 1); |
$cloud->add($tag, "$url?tag=$tag", scalar @{$tags->{$tag}} + 1); |
553 |
} |
} |
554 |
} |
} |
555 |
|
|
562 |
channel => '#foobar', |
channel => '#foobar', |
563 |
me => 0, |
me => 0, |
564 |
nick => 'dpavlin', |
nick => 'dpavlin', |
565 |
msg => 'test message', |
message => 'test message', |
566 |
time => '2006-06-25 18:57:18', |
time => '2006-06-25 18:57:18', |
567 |
); |
); |
568 |
|
|
574 |
|
|
575 |
sub save_message { |
sub save_message { |
576 |
my $a = {@_}; |
my $a = {@_}; |
577 |
|
confess "have msg" if $a->{msg}; |
578 |
$a->{me} ||= 0; |
$a->{me} ||= 0; |
579 |
$a->{time} ||= strftime($TIMESTAMP,localtime()); |
$a->{time} ||= strftime($TIMESTAMP,localtime()); |
580 |
|
|
581 |
print |
_log |
|
$a->{time}, " ", |
|
582 |
$a->{channel}, " ", |
$a->{channel}, " ", |
583 |
$a->{me} ? "***" . $a->{nick} : "<" . $a->{nick} . ">", |
$a->{me} ? "***" . $a->{nick} : "<" . $a->{nick} . ">", |
584 |
" " . $a->{msg} . "\n"; |
" " . $a->{message}; |
585 |
|
|
586 |
from_to($a->{msg}, 'UTF-8', $ENCODING); |
from_to($a->{message}, 'UTF-8', $ENCODING); |
587 |
|
|
588 |
$sth->execute($a->{channel}, $a->{me}, $a->{nick}, $a->{msg}, $a->{time}); |
$sth->execute($a->{channel}, $a->{me}, $a->{nick}, $a->{message}, $a->{time}); |
589 |
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}); |
|
590 |
} |
} |
591 |
|
|
592 |
|
|
593 |
if ($import_dircproxy) { |
if ($import_dircproxy) { |
594 |
open(my $l, $import_dircproxy) || die "can't open $import_dircproxy: $!"; |
open(my $l, $import_dircproxy) || die "can't open $import_dircproxy: $!"; |
595 |
warn "importing $import_dircproxy...\n"; |
warn "importing $import_dircproxy...\n"; |
596 |
my $tz_offset = 2 * 60 * 60; # TZ GMT+2 |
my $tz_offset = 1 * 60 * 60; # TZ GMT+2 |
597 |
while(<$l>) { |
while(<$l>) { |
598 |
chomp; |
chomp; |
599 |
if (/^@(\d+)\s(\S+)\s(.+)$/) { |
if (/^@(\d+)\s(\S+)\s(.+)$/) { |
611 |
channel => $CHANNEL, |
channel => $CHANNEL, |
612 |
me => $me, |
me => $me, |
613 |
nick => $nick, |
nick => $nick, |
614 |
msg => $msg, |
message => $msg, |
615 |
time => $dt->ymd . " " . $dt->hms, |
time => $dt->ymd . " " . $dt->hms, |
616 |
) if ($nick !~ m/^-/); |
) if ($nick !~ m/^-/); |
617 |
|
|
618 |
} else { |
} else { |
619 |
warn "can't parse: $_\n"; |
_log "can't parse: $_"; |
620 |
} |
} |
621 |
} |
} |
622 |
close($l); |
close($l); |
631 |
|
|
632 |
my $SKIPPING = 0; # if skipping, how many we've done |
my $SKIPPING = 0; # if skipping, how many we've done |
633 |
my $SEND_QUEUE; # cache |
my $SEND_QUEUE; # cache |
634 |
|
my $ping; # ping stats |
635 |
|
|
636 |
POE::Component::IRC->new($IRC_ALIAS); |
POE::Component::IRC->new($IRC_ALIAS); |
637 |
|
|
644 |
$_[KERNEL]->post($IRC_ALIAS => join => $CHANNEL); |
$_[KERNEL]->post($IRC_ALIAS => join => $CHANNEL); |
645 |
$_[KERNEL]->post($IRC_ALIAS => join => '#logger'); |
$_[KERNEL]->post($IRC_ALIAS => join => '#logger'); |
646 |
$_[KERNEL]->yield("heartbeat"); # start heartbeat |
$_[KERNEL]->yield("heartbeat"); # start heartbeat |
647 |
# $_[KERNEL]->yield("my_add", $_) for keys %FOLLOWS; |
$_[KERNEL]->yield("my_add", $_) for keys %FOLLOWS; |
648 |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "IDENTIFY $NICK" ); |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "IDENTIFY $NICK" ); |
649 |
}, |
}, |
650 |
irc_public => sub { |
irc_public => sub { |
653 |
my $channel = $_[ARG1]->[0]; |
my $channel = $_[ARG1]->[0]; |
654 |
my $msg = $_[ARG2]; |
my $msg = $_[ARG2]; |
655 |
|
|
656 |
save_message( channel => $channel, me => 0, nick => $nick, msg => $msg); |
save_message( channel => $channel, me => 0, nick => $nick, message => $msg); |
657 |
|
meta( $nick, $channel, 'last-msg', $msg ); |
658 |
}, |
}, |
659 |
irc_ctcp_action => sub { |
irc_ctcp_action => sub { |
660 |
my $kernel = $_[KERNEL]; |
my $kernel = $_[KERNEL]; |
662 |
my $channel = $_[ARG1]->[0]; |
my $channel = $_[ARG1]->[0]; |
663 |
my $msg = $_[ARG2]; |
my $msg = $_[ARG2]; |
664 |
|
|
665 |
save_message( channel => $channel, me => 1, nick => $nick, msg => $msg); |
save_message( channel => $channel, me => 1, nick => $nick, message => $msg); |
666 |
|
|
667 |
|
if ( $use_twitter ) { |
668 |
|
if ( my $twitter = meta( $nick, $NICK, 'twitter' ) ) { |
669 |
|
my ($login,$passwd) = split(/\s+/,$twitter,2); |
670 |
|
_log("sending twitter for $nick/$login on $channel "); |
671 |
|
my $bot = Net::Twitter->new( username=>$login, password=>$passwd ); |
672 |
|
$bot->update("<${channel}> $msg"); |
673 |
|
} |
674 |
|
} |
675 |
|
|
676 |
}, |
}, |
677 |
|
irc_ping => sub { |
678 |
|
_log( "pong ", $_[ARG0] ); |
679 |
|
$ping->{ $_[ARG0] }++; |
680 |
|
}, |
681 |
|
irc_invite => sub { |
682 |
|
my $kernel = $_[KERNEL]; |
683 |
|
my $nick = (split /!/, $_[ARG0])[0]; |
684 |
|
my $channel = $_[ARG1]; |
685 |
|
|
686 |
|
warn "invited to $channel by $nick"; |
687 |
|
|
688 |
|
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, "how nice of you to invite me to $channel, I'll be right there..." ); |
689 |
|
$_[KERNEL]->post($IRC_ALIAS => join => $channel); |
690 |
|
|
691 |
|
}, |
692 |
irc_msg => sub { |
irc_msg => sub { |
693 |
my $kernel = $_[KERNEL]; |
my $kernel = $_[KERNEL]; |
694 |
my $nick = (split /!/, $_[ARG0])[0]; |
my $nick = (split /!/, $_[ARG0])[0]; |
695 |
my $msg = $_[ARG2]; |
my $msg = $_[ARG2]; |
696 |
|
my $channel = $_[ARG1]->[0]; |
697 |
from_to($msg, 'UTF-8', $ENCODING); |
from_to($msg, 'UTF-8', $ENCODING); |
698 |
|
|
699 |
my $res = "unknown command '$msg', try /msg $NICK help!"; |
my $res = "unknown command '$msg', try /msg $NICK help!"; |
700 |
my @out; |
my @out; |
701 |
|
|
702 |
print "<< $msg\n"; |
_log "<< $msg"; |
703 |
|
|
704 |
if ($msg =~ m/^help/i) { |
if ($msg =~ m/^help/i) { |
705 |
|
|
707 |
|
|
708 |
} elsif ($msg =~ m/^msg\s+(\S+)\s+(.*)$/i) { |
} elsif ($msg =~ m/^msg\s+(\S+)\s+(.*)$/i) { |
709 |
|
|
710 |
print ">> /msg $1 $2\n"; |
_log ">> /msg $1 $2"; |
711 |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $1, $2 ); |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $1, $2 ); |
712 |
$res = ''; |
$res = ''; |
713 |
|
|
717 |
|
|
718 |
my $sth = $dbh->prepare(qq{ |
my $sth = $dbh->prepare(qq{ |
719 |
select |
select |
720 |
nick, |
trim(both '_' from nick) as nick, |
721 |
count(*) as count, |
count(*) as count, |
722 |
sum(length(message)) as len |
sum(length(message)) as len |
723 |
from log |
from log |
724 |
group by nick |
group by trim(both '_' from nick) |
725 |
order by len desc,count desc |
order by len desc,count desc |
726 |
limit $nr |
limit $nr |
727 |
}); |
}); |
734 |
$res .= join(" | ", @users); |
$res .= join(" | ", @users); |
735 |
} elsif ($msg =~ m/^last.*?\s*(\d*)/i) { |
} elsif ($msg =~ m/^last.*?\s*(\d*)/i) { |
736 |
|
|
737 |
foreach my $res (get_from_log( limit => ($1 || 100) )) { |
my $limit = $1 || meta( $nick, $channel, 'last-size' ) || 10; |
738 |
print "last: $res\n"; |
|
739 |
|
foreach my $res (get_from_log( limit => $limit )) { |
740 |
|
_log "last: $res"; |
741 |
from_to($res, $ENCODING, 'UTF-8'); |
from_to($res, $ENCODING, 'UTF-8'); |
742 |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res ); |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res ); |
743 |
} |
} |
752 |
limit => 20, |
limit => 20, |
753 |
search => $what, |
search => $what, |
754 |
)) { |
)) { |
755 |
print "search [$what]: $res\n"; |
_log "search [$what]: $res"; |
756 |
from_to($res, $ENCODING, 'UTF-8'); |
from_to($res, $ENCODING, 'UTF-8'); |
757 |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res ); |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res ); |
758 |
} |
} |
778 |
} |
} |
779 |
|
|
780 |
my @nicks; |
my @nicks; |
781 |
foreach my $nick (sort { $stat->{from}->{$a} cmp $stat->{from}->{$b} } keys %{ $stat->{from} }) { |
foreach my $nick (sort { $stat->{from}->{$a} <=> $stat->{from}->{$b} } keys %{ $stat->{from} }) { |
782 |
push @nicks, $nick . $stat->{from}->{$nick} == 1 ? '' : |
push @nicks, $nick . ( $stat->{from}->{$nick} == 1 ? '' : |
783 |
"(" . $stat->{from}->{$nick} . ")"; |
"(" . $stat->{from}->{$nick} . ")" |
784 |
|
); |
785 |
} |
} |
786 |
|
|
787 |
$res = |
$res = |
788 |
"+ " . ( $stat->{vote}->{'+'} || 0 ) . " : " . |
"$what ++ " . ( $stat->{vote}->{'+'} || 0 ) . |
789 |
"- " . ( $stat->{vote}->{'-'} || 0 ) . |
" : " . ( $stat->{vote}->{'-'} || 0 ) . " --" . |
790 |
" from " . ( join(", ", @nicks) || 'nobody' ); |
" from " . ( join(", ", @nicks) || 'nobody' ); |
791 |
|
|
792 |
|
$_[KERNEL]->post( $IRC_ALIAS => notice => $nick, $res ); |
793 |
|
|
794 |
|
} elsif ($msg =~ m/^ping/) { |
795 |
|
$res = "ping = " . dump( $ping ); |
796 |
|
} elsif ($msg =~ m/^conf(?:ig)*\s*(last-size|twitter)*\s*(.*)/) { |
797 |
|
if ( ! defined( $1 ) ) { |
798 |
|
my $sth = $dbh->prepare(qq{ select name,value,changed from meta where nick = ? and channel = ? }); |
799 |
|
$sth->execute( $nick, $channel ); |
800 |
|
$res = "config for $nick on $channel"; |
801 |
|
while ( my ($n,$v) = $sth->fetchrow_array ) { |
802 |
|
$res .= " | $n = $v"; |
803 |
|
} |
804 |
|
} elsif ( ! $2 ) { |
805 |
|
my $val = meta( $nick, $channel, $1 ); |
806 |
|
$res = "current $1 = " . ( $val ? $val : 'undefined' ); |
807 |
|
} else { |
808 |
|
my $validate = { |
809 |
|
'last-size' => qr/^\d+/, |
810 |
|
'twitter' => qr/^\w+\s+\w+/, |
811 |
|
}; |
812 |
|
|
813 |
|
my ( $op, $val ) = ( $1, $2 ); |
814 |
|
|
815 |
|
if ( my $regex = $validate->{$op} ) { |
816 |
|
if ( $val =~ $regex ) { |
817 |
|
meta( $nick, $channel, $op, $val ); |
818 |
|
$res = "saved $op = $val"; |
819 |
|
} else { |
820 |
|
$res = "config option $op = $val doesn't validate against $regex"; |
821 |
|
} |
822 |
|
} else { |
823 |
|
$res = "config option $op doesn't exist"; |
824 |
|
} |
825 |
|
} |
826 |
} |
} |
827 |
|
|
828 |
if ($res) { |
if ($res) { |
829 |
print ">> [$nick] $res\n"; |
_log ">> [$nick] $res"; |
830 |
from_to($res, $ENCODING, 'UTF-8'); |
from_to($res, $ENCODING, 'UTF-8'); |
831 |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res ); |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res ); |
832 |
} |
} |
833 |
|
|
834 |
}, |
}, |
835 |
irc_477 => sub { |
irc_477 => sub { |
836 |
print "# irc_477: ",$_[ARG1], "\n"; |
_log "# irc_477: ",$_[ARG1]; |
837 |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "register $NICK" ); |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "register $NICK" ); |
838 |
}, |
}, |
839 |
irc_505 => sub { |
irc_505 => sub { |
840 |
print "# irc_505: ",$_[ARG1], "\n"; |
_log "# irc_505: ",$_[ARG1]; |
841 |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "register $NICK" ); |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "register $NICK" ); |
842 |
# $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "set hide email on" ); |
# $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "set hide email on" ); |
843 |
# $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "set email dpavlin\@rot13.org" ); |
# $_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "set email dpavlin\@rot13.org" ); |
844 |
}, |
}, |
845 |
irc_registered => sub { |
irc_registered => sub { |
846 |
warn "## indetify $NICK\n"; |
_log "## registrated $NICK"; |
847 |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "IDENTIFY $NICK" ); |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "IDENTIFY $NICK" ); |
848 |
}, |
}, |
849 |
irc_disconnected => sub { |
irc_disconnected => sub { |
850 |
warn "## disconnected, reconnecting again\n"; |
_log "## disconnected, reconnecting again"; |
851 |
$_[KERNEL]->post($IRC_ALIAS => connect => $CONNECT); |
$_[KERNEL]->post($IRC_ALIAS => connect => $CONNECT); |
852 |
}, |
}, |
853 |
irc_socketerr => sub { |
irc_socketerr => sub { |
854 |
warn "## socket error... sleeping for $sleep_on_error seconds and retry"; |
_log "## socket error... sleeping for $sleep_on_error seconds and retry"; |
855 |
sleep($sleep_on_error); |
sleep($sleep_on_error); |
856 |
$_[KERNEL]->post($IRC_ALIAS => connect => $CONNECT); |
$_[KERNEL]->post($IRC_ALIAS => connect => $CONNECT); |
857 |
}, |
}, |
862 |
# }, |
# }, |
863 |
_child => sub {}, |
_child => sub {}, |
864 |
_default => sub { |
_default => sub { |
865 |
printf "%s #%s %s %s\n", |
_log sprintf "sID:%s %s %s", |
866 |
strftime($TIMESTAMP,localtime()), $_[SESSION]->ID, $_[ARG0], |
$_[SESSION]->ID, $_[ARG0], |
867 |
ref($_[ARG1]) eq "ARRAY" ? join(",", map { ref($_) eq "ARRAY" ? join(";", @{$_}) : $_ } @{ $_[ARG1] }) : |
ref($_[ARG1]) eq "ARRAY" ? join(",", map { ref($_) eq "ARRAY" ? join(";", @{$_}) : $_ } @{ $_[ARG1] }) : |
868 |
$_[ARG1] ? $_[ARG1] : |
$_[ARG1] ? $_[ARG1] : |
869 |
""; |
""; |
881 |
Filename => $FOLLOWS{$trailing}, |
Filename => $FOLLOWS{$trailing}, |
882 |
InputEvent => 'got_line', |
InputEvent => 'got_line', |
883 |
); |
); |
884 |
|
warn "+++ following $trailing at $FOLLOWS{$trailing}\n"; |
885 |
}, |
}, |
886 |
got_line => sub { |
got_line => sub { |
887 |
$_[KERNEL]->post($session => my_tailed => |
warn "+++ $trailing : $_[ARG0]\n"; |
888 |
time, $trailing, $_[ARG0]); |
$_[KERNEL]->post($session => my_tailed => time, $trailing, $_[ARG0]); |
889 |
}, |
}, |
890 |
}, |
}, |
891 |
); |
); |
936 |
# http server |
# http server |
937 |
|
|
938 |
my $httpd = POE::Component::Server::HTTP->new( |
my $httpd = POE::Component::Server::HTTP->new( |
939 |
Port => $NICK =~ m/-dev/ ? 8001 : 8000, |
Port => $http_port, |
940 |
|
PreHandler => { |
941 |
|
'/' => sub { |
942 |
|
$_[0]->header(Connection => 'close') |
943 |
|
} |
944 |
|
}, |
945 |
ContentHandler => { '/' => \&root_handler }, |
ContentHandler => { '/' => \&root_handler }, |
946 |
Headers => { Server => 'irc-logger' }, |
Headers => { Server => 'irc-logger' }, |
947 |
); |
); |
948 |
|
|
|
my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); |
|
|
my $escape_re = join '|' => keys %escape; |
|
|
|
|
949 |
my $style = <<'_END_OF_STYLE_'; |
my $style = <<'_END_OF_STYLE_'; |
950 |
p { margin: 0; padding: 0.1em; } |
p { margin: 0; padding: 0.1em; } |
951 |
.time, .channel { color: #808080; font-size: 60%; } |
.time, .channel { color: #808080; font-size: 60%; } |
953 |
.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 ; } |
954 |
.message { color: #000000; font-size: 100%; } |
.message { color: #000000; font-size: 100%; } |
955 |
.search { float: right; } |
.search { float: right; } |
956 |
|
a:link.tag, a:visited.tag { border: 1px dashed #ccc; backgound: #ccc; text-decoration: none } |
957 |
|
a:hover.tag { border: 1px solid #eee } |
958 |
|
hr { border: 1px dashed #ccc; height: 1px; clear: both; } |
959 |
|
/* |
960 |
.col-0 { background: #ffff66 } |
.col-0 { background: #ffff66 } |
961 |
.col-1 { background: #a0ffff } |
.col-1 { background: #a0ffff } |
962 |
.col-2 { background: #99ff99 } |
.col-2 { background: #99ff99 } |
963 |
.col-3 { background: #ff9999 } |
.col-3 { background: #ff9999 } |
964 |
.col-4 { background: #ff66ff } |
.col-4 { background: #ff66ff } |
965 |
a:link.tag, a:visited.tag { border: 1px dashed #ccc; backgound: #ccc; text-decoration: none } |
*/ |
966 |
a:hover.tag { border: 1px solid #eee } |
.calendar { border: 1px solid red; width: 100%; } |
967 |
hr { border: 1px dashed #ccc; height: 1px; clear: both; } |
.month { border: 0px; width: 100%; } |
968 |
_END_OF_STYLE_ |
_END_OF_STYLE_ |
969 |
|
|
970 |
my $max_color = 4; |
$max_color = 0; |
971 |
|
|
972 |
my %nick_enumerator; |
my @cols = qw( |
973 |
|
#ffcccc #ccffe6 #ccccff #e6ccff #ffccff #ffcce6 #ff9999 #ffcc99 #ffff99 |
974 |
|
#ccff99 #99ff99 #99ffcc #99ccff #9999ff #cc99ff #ff6666 #ffb366 #ffff66 |
975 |
|
#66ff66 #66ffb3 #66b3ff #6666ff #ff3333 #33ff33 #3399ff #3333ff #ff3399 |
976 |
|
#a0a0a0 #ff0000 #ffff00 #80ff00 #0000ff #8000ff #ff00ff #ff0080 #994d00 |
977 |
|
#999900 #009900 #cc0066 #c0c0c0 #ccff99 #99ff33 #808080 #660033 #ffffff |
978 |
|
); |
979 |
|
|
980 |
|
foreach my $c (@cols) { |
981 |
|
$style .= ".col-${max_color} { background: $c }\n"; |
982 |
|
$max_color++; |
983 |
|
} |
984 |
|
warn "defined $max_color colors for users...\n"; |
985 |
|
|
986 |
sub root_handler { |
sub root_handler { |
987 |
my ($request, $response) = @_; |
my ($request, $response) = @_; |
988 |
$response->code(RC_OK); |
$response->code(RC_OK); |
989 |
$response->content_type("text/html; charset=$ENCODING"); |
|
990 |
|
# this doesn't seem to work, so moved to PreHandler |
991 |
|
#$response->header(Connection => 'close'); |
992 |
|
|
993 |
|
return RC_OK if $request->uri =~ m/favicon.ico$/; |
994 |
|
|
995 |
my $q; |
my $q; |
996 |
|
|
1004 |
|
|
1005 |
my $search = $q->param('search') || $q->param('grep') || ''; |
my $search = $q->param('search') || $q->param('grep') || ''; |
1006 |
|
|
1007 |
|
if ($request->url =~ m#/rss(?:/(tags|last-tag)\w*(?:=(\d+))?)?#i) { |
1008 |
|
my $show = lc($1); |
1009 |
|
my $nr = $2; |
1010 |
|
|
1011 |
|
my $type = 'RSS'; # Atom |
1012 |
|
|
1013 |
|
$response->content_type( 'application/' . lc($type) . '+xml' ); |
1014 |
|
|
1015 |
|
my $html = '<!-- error -->'; |
1016 |
|
#warn "create $type feed from ",dump( @last_tags ); |
1017 |
|
|
1018 |
|
my $feed = XML::Feed->new( $type ); |
1019 |
|
|
1020 |
|
if ( $show eq 'tags' ) { |
1021 |
|
$nr ||= 50; |
1022 |
|
$feed->title( "tags from $CHANNEL" ); |
1023 |
|
$feed->link( "$url/tags" ); |
1024 |
|
$feed->description( "tag cloud created from messages on channel $CHANNEL which have tags// in them" ); |
1025 |
|
my $feed_entry = XML::Feed::Entry->new($type); |
1026 |
|
$feed_entry->title( "$nr tags from $CHANNEL" ); |
1027 |
|
$feed_entry->author( $NICK ); |
1028 |
|
$feed_entry->link( '/#tags' ); |
1029 |
|
|
1030 |
|
$feed_entry->content( |
1031 |
|
qq{<![CDATA[<style type="text/css">} |
1032 |
|
. $cloud->css |
1033 |
|
. qq{</style>} |
1034 |
|
. $cloud->html( $nr ) |
1035 |
|
. qq{]]>} |
1036 |
|
); |
1037 |
|
$feed->add_entry( $feed_entry ); |
1038 |
|
|
1039 |
|
} elsif ( $show eq 'last-tag' ) { |
1040 |
|
|
1041 |
|
$nr ||= $last_x_tags; |
1042 |
|
$nr = $last_x_tags if $nr > $last_x_tags; |
1043 |
|
|
1044 |
|
$feed->title( "last $nr tagged messages from $CHANNEL" ); |
1045 |
|
$feed->link( $url ); |
1046 |
|
$feed->description( "collects messages which have tags// in them" ); |
1047 |
|
|
1048 |
|
foreach my $m ( @last_tags ) { |
1049 |
|
# warn dump( $m ); |
1050 |
|
#my $tags = join(' ', @{$m->{tags}} ); |
1051 |
|
my $feed_entry = XML::Feed::Entry->new($type); |
1052 |
|
$feed_entry->title( $m->{nick} . '@' . $m->{time} ); |
1053 |
|
$feed_entry->author( $m->{nick} ); |
1054 |
|
$feed_entry->link( '/#' . $m->{id} ); |
1055 |
|
$feed_entry->issued( DateTime::Format::Flexible->build( $m->{time} ) ); |
1056 |
|
|
1057 |
|
my $message = $filter->{message}->( $m->{message} ); |
1058 |
|
$message .= "<br/>\n" unless $message =~ m!<(/p|br/?)>!; |
1059 |
|
# warn "## message = $message\n"; |
1060 |
|
from_to( $message, $ENCODING, 'UTF-8' ); |
1061 |
|
|
1062 |
|
#$feed_entry->summary( |
1063 |
|
$feed_entry->content( |
1064 |
|
"<![CDATA[$message]]>" |
1065 |
|
); |
1066 |
|
$feed_entry->category( join(', ', @{$m->{tags}}) ); |
1067 |
|
$feed->add_entry( $feed_entry ); |
1068 |
|
|
1069 |
|
$nr--; |
1070 |
|
last if $nr <= 0; |
1071 |
|
|
1072 |
|
} |
1073 |
|
|
1074 |
|
} else { |
1075 |
|
warn "!! unknown rss request for $show\n"; |
1076 |
|
return RC_DENY; |
1077 |
|
} |
1078 |
|
|
1079 |
|
$response->content( $feed->as_xml ); |
1080 |
|
return RC_OK; |
1081 |
|
} |
1082 |
|
|
1083 |
|
if ( $@ ) { |
1084 |
|
warn "$@"; |
1085 |
|
} |
1086 |
|
|
1087 |
|
$response->content_type("text/html; charset=$ENCODING"); |
1088 |
|
|
1089 |
my $html = |
my $html = |
1090 |
qq{<html><head><title>$NICK</title><style type="text/css">$style} . |
qq{<html><head><title>$NICK</title><style type="text/css">$style} |
1091 |
$cloud->css . |
. $cloud->css |
1092 |
qq{</style></head><body>} . |
. qq{</style></head><body>} |
1093 |
qq{ |
. qq{ |
1094 |
<form method="post" class="search" action="/"> |
<form method="post" class="search" action="/"> |
1095 |
<input type="text" name="search" value="$search" size="10"> |
<input type="text" name="search" value="$search" size="10"> |
1096 |
<input type="submit" value="search"> |
<input type="submit" value="search"> |
1097 |
</form> |
</form> |
1098 |
} . |
} |
1099 |
$cloud->html(500) . |
. $cloud->html(500) |
1100 |
qq{<p>}; |
. qq{<p>}; |
1101 |
if ($request->url =~ m#/history#) { |
|
1102 |
|
if ($request->url =~ m#/tags?#) { |
1103 |
|
# nop |
1104 |
|
} elsif ($request->url =~ m#/history#) { |
1105 |
my $sth = $dbh->prepare(qq{ |
my $sth = $dbh->prepare(qq{ |
1106 |
select date(time) as date,count(*) as nr |
select date(time) as date,count(*) as nr,sum(length(message)) as len |
1107 |
from log |
from log |
1108 |
group by date(time) |
group by date(time) |
1109 |
order by date(time) desc |
order by date(time) desc |
1110 |
}); |
}); |
1111 |
$sth->execute(); |
$sth->execute(); |
1112 |
my ($l_yyyy,$l_mm) = (0,0); |
my ($l_yyyy,$l_mm) = (0,0); |
1113 |
|
$html .= qq{<table class="calendar"><tr>}; |
1114 |
my $cal; |
my $cal; |
1115 |
|
my $ord = 0; |
1116 |
while (my $row = $sth->fetchrow_hashref) { |
while (my $row = $sth->fetchrow_hashref) { |
1117 |
# this is probably PostgreSQL specific, expects ISO date |
# this is probably PostgreSQL specific, expects ISO date |
1118 |
my ($yyyy,$mm,$dd) = split(/-/, $row->{date}); |
my ($yyyy,$mm,$dd) = split(/-/, $row->{date}); |
1119 |
if ($yyyy != $l_yyyy || $mm != $l_mm) { |
if ($yyyy != $l_yyyy || $mm != $l_mm) { |
1120 |
$html .= $cal->as_HTML() if ($cal); |
if ( $cal ) { |
1121 |
|
$html .= qq{<td valign="top">} . $cal->as_HTML() . qq{</td>}; |
1122 |
|
$ord++; |
1123 |
|
$html .= qq{</tr><tr>} if ( $ord % 3 == 0 ); |
1124 |
|
} |
1125 |
$cal = new HTML::CalendarMonthSimple('month'=>$mm,'year'=>$yyyy); |
$cal = new HTML::CalendarMonthSimple('month'=>$mm,'year'=>$yyyy); |
1126 |
$cal->border(2); |
$cal->border(1); |
1127 |
|
$cal->width('30%'); |
1128 |
|
$cal->cellheight('5em'); |
1129 |
|
$cal->tableclass('month'); |
1130 |
|
#$cal->cellclass('day'); |
1131 |
|
$cal->sunday('SUN'); |
1132 |
|
$cal->saturday('SAT'); |
1133 |
|
$cal->weekdays('MON','TUE','WED','THU','FRI'); |
1134 |
($l_yyyy,$l_mm) = ($yyyy,$mm); |
($l_yyyy,$l_mm) = ($yyyy,$mm); |
1135 |
} |
} |
1136 |
$cal->setcontent($dd, qq{ |
$cal->setcontent($dd, qq[ |
1137 |
<a href="/?date=$row->{date}">$row->{nr}</a> |
<a href="$url?date=$row->{date}">$row->{nr}</a><br/>$row->{len} |
1138 |
}); |
]); |
1139 |
|
|
1140 |
} |
} |
1141 |
$html .= $cal->as_HTML() if ($cal); |
$html .= qq{<td valign="top">} . $cal->as_HTML() . qq{</td></tr></table>}; |
1142 |
|
|
1143 |
} else { |
} else { |
1144 |
$html .= join("</p><p>", |
$html .= join("</p><p>", |
1145 |
get_from_log( |
get_from_log( |
1146 |
limit => $q->param('last') || $q->param('date') ? undef : 100, |
limit => ( $q->param('last') || $q->param('date') ) ? undef : 100, |
1147 |
search => $search || undef, |
search => $search || undef, |
1148 |
tag => $q->param('tag') || undef, |
tag => $q->param('tag') || undef, |
1149 |
date => $q->param('date') || undef, |
date => $q->param('date') || undef, |
1150 |
fmt => { |
fmt => { |
1151 |
date => sub { |
date => sub { |
1152 |
my $date = shift || return; |
my $date = shift || return; |
1153 |
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>}; |
1154 |
}, |
}, |
1155 |
time => '<span class="time">%s</span> ', |
time => '<span class="time">%s</span> ', |
1156 |
time_channel => '<span class="channel">%s %s</span> ', |
time_channel => '<span class="channel">%s %s</span> ', |
1158 |
me_nick => '***%s ', |
me_nick => '***%s ', |
1159 |
message => '<span class="message">%s</span>', |
message => '<span class="message">%s</span>', |
1160 |
}, |
}, |
1161 |
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>'; |
|
|
}, |
|
|
}, |
|
1162 |
) |
) |
1163 |
); |
); |
1164 |
} |
} |
1169 |
</body></html>}; |
</body></html>}; |
1170 |
|
|
1171 |
$response->content( $html ); |
$response->content( $html ); |
1172 |
|
warn "<< ", $request->method, " ", $request->uri, " created ", length($html), " bytes\n"; |
1173 |
return RC_OK; |
return RC_OK; |
1174 |
} |
} |
1175 |
|
|