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/); |
60 |
my $sleep_on_error = 5; |
my $sleep_on_error = 5; |
61 |
|
|
62 |
my $http_port = $NICK =~ m/-dev/ ? 8001 : 8000; |
my $http_port = $NICK =~ m/-dev/ ? 8001 : 8000; |
63 |
my $http_hostname = `hostname`; |
|
64 |
chomp( $http_hostname ); |
my $url = "http://$HOSTNAME:$http_port"; |
65 |
|
|
66 |
## END CONFIG |
## END CONFIG |
67 |
|
|
129 |
$m =~ s/($escape_re)/$escape{$1}/gs; |
$m =~ s/($escape_re)/$escape{$1}/gs; |
130 |
$m =~ s#($RE{URI}{HTTP})#e(qq{<a href="$1">$1</a>})#egs || |
$m =~ s#($RE{URI}{HTTP})#e(qq{<a href="$1">$1</a>})#egs || |
131 |
$m =~ s#\/(\w+)\/#<i>$1</i>#gs; |
$m =~ s#\/(\w+)\/#<i>$1</i>#gs; |
132 |
$m =~ s#$tag_regex#e(qq{<a href="?tag=$1" class="tag">$1</a>})#egs; |
$m =~ s#$tag_regex#e(qq{<a href="$url?tag=$1" class="tag">$1</a>})#egs; |
133 |
$m =~ s#\*(\w+)\*#<b>$1</b>#gs; |
$m =~ s#\*(\w+)\*#<b>$1</b>#gs; |
134 |
$m =~ s#_(\w+)_#<u>$1</u>#gs; |
$m =~ s#_(\w+)_#<u>$1</u>#gs; |
135 |
|
|
501 |
next if (! $tag || $tag =~ m/https?:/i); |
next if (! $tag || $tag =~ m/https?:/i); |
502 |
push @{ $tags->{$tag} }, $arg->{id}; |
push @{ $tags->{$tag} }, $arg->{id}; |
503 |
#warn "+tag $tag: $arg->{id}\n"; |
#warn "+tag $tag: $arg->{id}\n"; |
504 |
$cloud->add($tag, "?tag=$tag", scalar @{$tags->{$tag}} + 1); |
$cloud->add($tag, "$url?tag=$tag", scalar @{$tags->{$tag}} + 1); |
505 |
push @tags, $tag; |
push @tags, $tag; |
506 |
|
|
507 |
} |
} |
508 |
|
|
509 |
if ( @tags ) { |
if ( @tags ) { |
510 |
shift @last_tags if $#last_tags == $last_x_tags; |
pop @last_tags if $#last_tags == $last_x_tags; |
511 |
push @last_tags, { tags => [ @tags ], %$arg }; |
unshift @last_tags, { tags => [ @tags ], %$arg }; |
512 |
} |
} |
513 |
|
|
514 |
} |
} |
520 |
=cut |
=cut |
521 |
|
|
522 |
sub seed_tags { |
sub seed_tags { |
523 |
my $sth = $dbh->prepare(qq{ select id,message,nick,me,time 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 }); |
524 |
$sth->execute; |
$sth->execute; |
525 |
while (my $row = $sth->fetchrow_hashref) { |
while (my $row = $sth->fetchrow_hashref) { |
526 |
add_tag( %$row ); |
add_tag( %$row ); |
527 |
} |
} |
528 |
|
|
529 |
foreach my $tag (keys %$tags) { |
foreach my $tag (keys %$tags) { |
530 |
$cloud->add($tag, "?tag=$tag", scalar @{$tags->{$tag}} + 1); |
$cloud->add($tag, "$url?tag=$tag", scalar @{$tags->{$tag}} + 1); |
531 |
} |
} |
532 |
} |
} |
533 |
|
|
959 |
my ($request, $response) = @_; |
my ($request, $response) = @_; |
960 |
$response->code(RC_OK); |
$response->code(RC_OK); |
961 |
|
|
962 |
|
return RC_OK if $request->uri =~ m/favicon.ico$/; |
963 |
|
|
964 |
my $q; |
my $q; |
965 |
|
|
966 |
if ( $request->method eq 'POST' ) { |
if ( $request->method eq 'POST' ) { |
975 |
|
|
976 |
if ($request->url =~ m#/rss#i) { |
if ($request->url =~ m#/rss#i) { |
977 |
my $type = 'RSS'; # Atom |
my $type = 'RSS'; # Atom |
|
my $url = "http://$http_hostname:$http_port"; |
|
978 |
|
|
979 |
$response->content_type("application/$type+xml"); |
$response->content_type( 'application/' . lc($type) . '+xml' ); |
980 |
|
|
981 |
my $html = '<!-- error -->'; |
my $html = '<!-- error -->'; |
982 |
warn "create $type feed from ",dump( @last_tags ); |
#warn "create $type feed from ",dump( @last_tags ); |
983 |
|
|
984 |
my $feed = XML::Feed->new( $type ); |
my $feed = XML::Feed->new( $type ); |
985 |
|
|
986 |
$feed->title( "last $last_x_tags from $CHANNEL" ); |
$feed->title( "last $last_x_tags from $CHANNEL" ); |
987 |
$feed->link( "http://$http_hostname:$http_port" ); |
$feed->link( $url ); |
988 |
$feed->description( "collects messages which have tags// in them" ); |
$feed->description( "collects messages which have tags// in them" ); |
989 |
|
|
990 |
foreach my $m ( @last_tags ) { |
foreach my $m ( @last_tags ) { |
991 |
warn dump( $m ); |
# warn dump( $m ); |
992 |
#my $tags = join(' ', @{$m->{tags}} ); |
#my $tags = join(' ', @{$m->{tags}} ); |
993 |
my $feed_entry = XML::Feed::Entry->new($type); |
my $feed_entry = XML::Feed::Entry->new($type); |
994 |
$feed_entry->title( $m->{nick} . '@' . $m->{time} ); |
$feed_entry->title( $m->{nick} . '@' . $m->{time} ); |
995 |
$feed_entry->author( $m->{nick} ); |
$feed_entry->author( $m->{nick} ); |
996 |
# $feed_entry->link( ); |
$feed_entry->link( '/#' . $m->{id} ); |
997 |
$feed_entry->issued( DateTime::Format::Flexible->build( $m->{time} ) ); |
$feed_entry->issued( DateTime::Format::Flexible->build( $m->{time} ) ); |
998 |
$feed_entry->summary( |
|
999 |
'<![CDATA[' . |
my $message = $filter->{message}->( $m->{message} ); |
1000 |
# $filter->{nick}->( $m->{nick} ) . |
$message .= "<br/>\n" unless $message =~ m!<(/p|br/?)>!; |
1001 |
# '<tt>' . $m->{nick} . '</tt> ' . |
warn "## message = $message\n"; |
1002 |
$filter->{message}->( $m->{message} ) . |
from_to( $message, $ENCODING, 'UTF-8' ); |
1003 |
']]>' |
|
1004 |
|
#$feed_entry->summary( |
1005 |
|
$feed_entry->content( |
1006 |
|
"<![CDATA[$message]]>" |
1007 |
); |
); |
1008 |
$feed_entry->category( join(', ', @{$m->{tags}}) ); |
$feed_entry->category( join(', ', @{$m->{tags}}) ); |
1009 |
$feed->add_entry( $feed_entry ); |
$feed->add_entry( $feed_entry ); |
1031 |
} . |
} . |
1032 |
$cloud->html(500) . |
$cloud->html(500) . |
1033 |
qq{<p>}; |
qq{<p>}; |
1034 |
if ($request->url =~ m#/history#) { |
|
1035 |
|
if ($request->url =~ m#/tags?#) { |
1036 |
|
# nop |
1037 |
|
} elsif ($request->url =~ m#/history#) { |
1038 |
my $sth = $dbh->prepare(qq{ |
my $sth = $dbh->prepare(qq{ |
1039 |
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 |
1040 |
from log |
from log |
1067 |
($l_yyyy,$l_mm) = ($yyyy,$mm); |
($l_yyyy,$l_mm) = ($yyyy,$mm); |
1068 |
} |
} |
1069 |
$cal->setcontent($dd, qq{ |
$cal->setcontent($dd, qq{ |
1070 |
<a href="/?date=$row->{date}">$row->{nr}</a><br/>$row->{len} |
<a href="$url?date=$row->{date}">$row->{nr}</a><br/>$row->{len} |
1071 |
}); |
}); |
1072 |
|
|
1073 |
} |
} |
1083 |
fmt => { |
fmt => { |
1084 |
date => sub { |
date => sub { |
1085 |
my $date = shift || return; |
my $date = shift || return; |
1086 |
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>}; |
1087 |
}, |
}, |
1088 |
time => '<span class="time">%s</span> ', |
time => '<span class="time">%s</span> ', |
1089 |
time_channel => '<span class="channel">%s %s</span> ', |
time_channel => '<span class="channel">%s %s</span> ', |
1102 |
</body></html>}; |
</body></html>}; |
1103 |
|
|
1104 |
$response->content( $html ); |
$response->content( $html ); |
1105 |
|
warn "<< ", $request->method, " ", $request->uri, " created ", length($html), " bytes\n"; |
1106 |
return RC_OK; |
return RC_OK; |
1107 |
} |
} |
1108 |
|
|