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; |
my $http_port = $NICK =~ m/-dev/ ? 8001 : 8000; |
66 |
my $http_hostname = `hostname`; |
|
67 |
chomp( $http_hostname ); |
my $url = "http://$HOSTNAME:$http_port"; |
68 |
|
|
69 |
## END CONFIG |
## END CONFIG |
70 |
|
|
132 |
$m =~ s/($escape_re)/$escape{$1}/gs; |
$m =~ s/($escape_re)/$escape{$1}/gs; |
133 |
$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 || |
134 |
$m =~ s#\/(\w+)\/#<i>$1</i>#gs; |
$m =~ s#\/(\w+)\/#<i>$1</i>#gs; |
135 |
$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; |
136 |
$m =~ s#\*(\w+)\*#<b>$1</b>#gs; |
$m =~ s#\*(\w+)\*#<b>$1</b>#gs; |
137 |
$m =~ s#_(\w+)_#<u>$1</u>#gs; |
$m =~ s#_(\w+)_#<u>$1</u>#gs; |
138 |
|
|
486 |
|
|
487 |
=cut |
=cut |
488 |
|
|
|
my $last_x_tags = 5; |
|
489 |
my @last_tags; |
my @last_tags; |
490 |
|
|
491 |
sub add_tag { |
sub add_tag { |
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; |
push @tags, $tag; |
508 |
|
|
509 |
} |
} |
510 |
|
|
511 |
if ( @tags ) { |
if ( @tags ) { |
512 |
shift @last_tags if $#last_tags == $last_x_tags; |
pop @last_tags if $#last_tags == $last_x_tags; |
513 |
push @last_tags, { tags => [ @tags ], %$arg }; |
unshift @last_tags, { tags => [ @tags ], %$arg }; |
514 |
} |
} |
515 |
|
|
516 |
} |
} |
522 |
=cut |
=cut |
523 |
|
|
524 |
sub seed_tags { |
sub seed_tags { |
525 |
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 }); |
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 |
|
|
961 |
my ($request, $response) = @_; |
my ($request, $response) = @_; |
962 |
$response->code(RC_OK); |
$response->code(RC_OK); |
963 |
|
|
964 |
|
return RC_OK if $request->uri =~ m/favicon.ico$/; |
965 |
|
|
966 |
my $q; |
my $q; |
967 |
|
|
968 |
if ( $request->method eq 'POST' ) { |
if ( $request->method eq 'POST' ) { |
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|atom)#) { |
if ($request->url =~ m#/rss(?:/(tags|last-tag?)\w+(?:=(\d+))?)?#i) { |
979 |
my $type = uc($1); |
my $show = lc($1); |
980 |
my $url = "http://$http_hostname:$http_port"; |
my $nr = $2; |
981 |
|
|
982 |
|
my $type = 'RSS'; # Atom |
983 |
|
|
984 |
$response->content_type("application/$type+xml"); |
$response->content_type( 'application/' . lc($type) . '+xml' ); |
985 |
|
|
986 |
my $html = '<!-- error -->'; |
my $html = '<!-- error -->'; |
987 |
warn "create $type feed from ",dump( @last_tags ); |
#warn "create $type feed from ",dump( @last_tags ); |
988 |
|
|
989 |
my $feed = XML::Feed->new( $type ); |
my $feed = XML::Feed->new( $type ); |
990 |
|
|
991 |
$feed->title( "last $last_x_tags from $CHANNEL" ); |
if ( $show eq 'tags' ) { |
992 |
$feed->link( "http://$http_hostname:$http_port" ); |
$nr ||= 50; |
993 |
$feed->description( "collects messages which have tags// in them" ); |
$feed->title( "tags from $CHANNEL" ); |
994 |
|
$feed->link( "$url/tags" ); |
995 |
foreach my $m ( @last_tags ) { |
$feed->description( "tag cloud created from messages on channel $CHANNEL which have tags// in them" ); |
|
warn dump( $m ); |
|
|
#my $tags = join(' ', @{$m->{tags}} ); |
|
996 |
my $feed_entry = XML::Feed::Entry->new($type); |
my $feed_entry = XML::Feed::Entry->new($type); |
997 |
$feed_entry->title( $m->{nick} . '@' . $m->{time} ); |
$feed_entry->title( "$nr tags from $CHANNEL" ); |
998 |
$feed_entry->author( $m->{nick} ); |
$feed_entry->author( $NICK ); |
999 |
# $feed_entry->link( ); |
$feed_entry->link( '/#tags' ); |
1000 |
$feed_entry->issued( DateTime::Format::Flexible->build( $m->{time} ) ); |
|
1001 |
$feed_entry->summary( |
$feed_entry->content( |
1002 |
# $filter->{nick}->( $m->{nick} ) . |
qq{<![CDATA[<style type="text/css">} |
1003 |
# '<tt>' . $m->{nick} . '</tt> ' . |
. $cloud->css |
1004 |
$filter->{message}->( $m->{message} ) |
. qq{</style>} |
1005 |
|
. $cloud->html( $nr ) |
1006 |
|
. qq{]]>} |
1007 |
); |
); |
1008 |
$feed->add_entry( $feed_entry ); |
$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 ); |
$response->content( $feed->as_xml ); |
1057 |
$response->content_type("text/html; charset=$ENCODING"); |
$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>}; |
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> ', |
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 |
|
|