22 |
|
|
23 |
Name of log file |
Name of log file |
24 |
|
|
25 |
|
=item --follow=file.log |
26 |
|
|
27 |
|
Follows new messages in file |
28 |
|
|
29 |
=back |
=back |
30 |
|
|
31 |
=head1 DESCRIPTION |
=head1 DESCRIPTION |
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; |
my $http_port = $NICK =~ m/-dev/ ? 8001 : 8000; |
67 |
|
|
68 |
my $url = "http://$HOSTNAME:$http_port"; |
my $url = "http://$HOSTNAME:$http_port"; |
97 |
my $log_path; |
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, |
'log:s' => \$log_path, |
102 |
); |
); |
103 |
|
|
111 |
print strftime($TIMESTAMP,localtime()), ' ', join(" ",@_), $/; |
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 |
|
sub add_follow_path { |
123 |
|
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 |
# HTML formatters |
133 |
|
|
134 |
my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); |
my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); |
506 |
|
|
507 |
=cut |
=cut |
508 |
|
|
|
my $last_x_tags = 5; |
|
509 |
my @last_tags; |
my @last_tags; |
510 |
|
|
511 |
sub add_tag { |
sub add_tag { |
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 { |
675 |
|
|
676 |
}, |
}, |
677 |
irc_ping => sub { |
irc_ping => sub { |
678 |
warn "pong ", $_[ARG0], $/; |
_log( "pong ", $_[ARG0] ); |
679 |
$ping->{ $_[ARG0] }++; |
$ping->{ $_[ARG0] }++; |
680 |
}, |
}, |
681 |
irc_invite => sub { |
irc_invite => sub { |
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 |
); |
); |
937 |
|
|
938 |
my $httpd = POE::Component::Server::HTTP->new( |
my $httpd = POE::Component::Server::HTTP->new( |
939 |
Port => $http_port, |
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 |
); |
); |
987 |
my ($request, $response) = @_; |
my ($request, $response) = @_; |
988 |
$response->code(RC_OK); |
$response->code(RC_OK); |
989 |
|
|
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$/; |
return RC_OK if $request->uri =~ m/favicon.ico$/; |
994 |
|
|
995 |
my $q; |
my $q; |
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#i) { |
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 |
my $type = 'RSS'; # Atom |
1012 |
|
|
1013 |
$response->content_type( 'application/' . lc($type) . '+xml' ); |
$response->content_type( 'application/' . lc($type) . '+xml' ); |
1017 |
|
|
1018 |
my $feed = XML::Feed->new( $type ); |
my $feed = XML::Feed->new( $type ); |
1019 |
|
|
1020 |
$feed->title( "last $last_x_tags from $CHANNEL" ); |
if ( $show eq 'tags' ) { |
1021 |
$feed->link( $url ); |
$nr ||= 50; |
1022 |
$feed->description( "collects messages which have tags// in them" ); |
$feed->title( "tags from $CHANNEL" ); |
1023 |
|
$feed->link( "$url/tags" ); |
1024 |
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}} ); |
|
1025 |
my $feed_entry = XML::Feed::Entry->new($type); |
my $feed_entry = XML::Feed::Entry->new($type); |
1026 |
$feed_entry->title( $m->{nick} . '@' . $m->{time} ); |
$feed_entry->title( "$nr tags from $CHANNEL" ); |
1027 |
$feed_entry->author( $m->{nick} ); |
$feed_entry->author( $NICK ); |
1028 |
$feed_entry->link( '/#' . $m->{id} ); |
$feed_entry->link( '/#tags' ); |
|
$feed_entry->issued( DateTime::Format::Flexible->build( $m->{time} ) ); |
|
|
|
|
|
my $message = $filter->{message}->( $m->{message} ); |
|
|
$message .= "<br/>\n" unless $message =~ m!<(/p|br/?)>!; |
|
|
warn "## message = $message\n"; |
|
|
from_to( $message, $ENCODING, 'UTF-8' ); |
|
1029 |
|
|
|
#$feed_entry->summary( |
|
1030 |
$feed_entry->content( |
$feed_entry->content( |
1031 |
"<![CDATA[$message]]>" |
qq{<![CDATA[<style type="text/css">} |
1032 |
|
. $cloud->css |
1033 |
|
. qq{</style>} |
1034 |
|
. $cloud->html( $nr ) |
1035 |
|
. qq{]]>} |
1036 |
); |
); |
|
$feed_entry->category( join(', ', @{$m->{tags}}) ); |
|
1037 |
$feed->add_entry( $feed_entry ); |
$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 ); |
$response->content( $feed->as_xml ); |
1087 |
$response->content_type("text/html; charset=$ENCODING"); |
$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,sum(length(message)) as len |
select date(time) as date,count(*) as nr,sum(length(message)) as len |
1107 |
from log |
from log |
1133 |
$cal->weekdays('MON','TUE','WED','THU','FRI'); |
$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="$url?date=$row->{date}">$row->{nr}</a><br/>$row->{len} |
<a href="$url?date=$row->{date}">$row->{nr}</a><br/>$row->{len} |
1138 |
}); |
]); |
1139 |
|
|
1140 |
} |
} |
1141 |
$html .= qq{<td valign="top">} . $cal->as_HTML() . qq{</td></tr></table>}; |
$html .= qq{<td valign="top">} . $cal->as_HTML() . qq{</td></tr></table>}; |