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 |
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 |
|
|
58 |
|
# log output encoding |
59 |
my $ENCODING = 'ISO-8859-2'; |
my $ENCODING = 'ISO-8859-2'; |
60 |
my $TIMESTAMP = '%Y-%m-%d %H:%M:%S'; |
my $TIMESTAMP = '%Y-%m-%d %H:%M:%S'; |
61 |
|
|
62 |
my $sleep_on_error = 5; |
my $sleep_on_error = 5; |
63 |
|
|
64 |
my $http_port = $NICK =~ m/-dev/ ? 8001 : 8000; |
# number of last tags to keep in circular buffer |
65 |
my $http_hostname = `hostname`; |
my $last_x_tags = 50; |
|
chomp( $http_hostname ); |
|
66 |
|
|
67 |
## END CONFIG |
# don't pull rss feeds more often than this |
68 |
|
my $rss_min_delay = 60; |
69 |
|
$rss_min_delay = 15; |
70 |
|
|
71 |
|
my $http_port = $NICK =~ m/-dev/ ? 8001 : 8000; |
72 |
|
|
73 |
|
my $url = "http://$HOSTNAME:$http_port"; |
74 |
|
|
75 |
|
## END CONFIG |
76 |
|
|
77 |
use POE qw(Component::IRC Wheel::FollowTail Component::Server::HTTP); |
use POE qw(Component::IRC Wheel::FollowTail Component::Server::HTTP); |
78 |
use HTTP::Status; |
use HTTP::Status; |
100 |
my $log_path; |
my $log_path; |
101 |
GetOptions( |
GetOptions( |
102 |
'import-dircproxy:s' => \$import_dircproxy, |
'import-dircproxy:s' => \$import_dircproxy, |
103 |
|
'follows:s' => \$follows_path, |
104 |
'log:s' => \$log_path, |
'log:s' => \$log_path, |
105 |
); |
); |
106 |
|
|
107 |
$SIG{__DIE__} = sub { |
#$SIG{__DIE__} = sub { |
108 |
confess "fatal error"; |
# confess "fatal error"; |
109 |
}; |
#}; |
110 |
|
|
111 |
open(STDOUT, '>', $log_path) || warn "can't redirect log to $log_path: $!"; |
open(STDOUT, '>', $log_path) || warn "can't redirect log to $log_path: $!"; |
112 |
|
|
113 |
sub _log { |
sub _log { |
114 |
print strftime($TIMESTAMP,localtime()), ' ', join(" ",@_), $/; |
my $out = strftime($TIMESTAMP,localtime()) . ' ' . join(" ",@_) . $/; |
115 |
|
from_to( $out, 'UTF-8', $ENCODING ); |
116 |
|
print $out; |
117 |
} |
} |
118 |
|
|
119 |
|
# LOG following |
120 |
|
|
121 |
|
my %FOLLOWS = |
122 |
|
( |
123 |
|
# ACCESS => "/var/log/apache/access.log", |
124 |
|
# ERROR => "/var/log/apache/error.log", |
125 |
|
); |
126 |
|
|
127 |
|
sub add_follow_path { |
128 |
|
my $path = shift; |
129 |
|
my $name = $path; |
130 |
|
$name =~ s/\..*$//; |
131 |
|
warn "# using $path to announce messages from $name\n"; |
132 |
|
$FOLLOWS{$name} = $path; |
133 |
|
} |
134 |
|
|
135 |
|
add_follow_path( $follows_path ) if ( -e $follows_path ); |
136 |
|
|
137 |
# HTML formatters |
# HTML formatters |
138 |
|
|
139 |
my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); |
my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); |
157 |
$m =~ s/($escape_re)/$escape{$1}/gs; |
$m =~ s/($escape_re)/$escape{$1}/gs; |
158 |
$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 || |
159 |
$m =~ s#\/(\w+)\/#<i>$1</i>#gs; |
$m =~ s#\/(\w+)\/#<i>$1</i>#gs; |
160 |
$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; |
161 |
$m =~ s#\*(\w+)\*#<b>$1</b>#gs; |
$m =~ s#\*(\w+)\*#<b>$1</b>#gs; |
162 |
$m =~ s#_(\w+)_#<u>$1</u>#gs; |
$m =~ s#_(\w+)_#<u>$1</u>#gs; |
163 |
|
|
179 |
my $dbh = DBI->connect($DSN,"","", { RaiseError => 1, AutoCommit => 1 }) || die $DBI::errstr; |
my $dbh = DBI->connect($DSN,"","", { RaiseError => 1, AutoCommit => 1 }) || die $DBI::errstr; |
180 |
|
|
181 |
my $sql_schema = { |
my $sql_schema = { |
182 |
log => ' |
log => qq{ |
183 |
create table log ( |
create table log ( |
184 |
id serial, |
id serial, |
185 |
time timestamp default now(), |
time timestamp default now(), |
193 |
create index log_time on log(time); |
create index log_time on log(time); |
194 |
create index log_channel on log(channel); |
create index log_channel on log(channel); |
195 |
create index log_nick on log(nick); |
create index log_nick on log(nick); |
196 |
', |
}, |
197 |
meta => ' |
meta => q{ |
198 |
create table meta ( |
create table meta ( |
199 |
nick text not null, |
nick text not null, |
200 |
channel text not null, |
channel text not null, |
201 |
name text not null, |
name text not null, |
202 |
value text, |
value text, |
203 |
changed timestamp default now(), |
changed timestamp default 'now()', |
204 |
primary key(nick,channel,name) |
primary key(nick,channel,name) |
205 |
); |
); |
206 |
', |
}, |
207 |
|
feeds => qq{ |
208 |
|
create table feeds ( |
209 |
|
id serial, |
210 |
|
url text not null, |
211 |
|
name text, |
212 |
|
delay interval not null default '5 min', |
213 |
|
active boolean default true, |
214 |
|
last_update timestamp default 'now()', |
215 |
|
polls int default 0, |
216 |
|
updates int default 0 |
217 |
|
); |
218 |
|
create unique index feeds_url on feeds(url); |
219 |
|
insert into feeds (url,name) values ('http://wiki.razmjenavjestina.org/feed/workspace/razmjenavjestina?category=Recent%20Changes','wiki'); |
220 |
|
}, |
221 |
}; |
}; |
222 |
|
|
223 |
foreach my $table ( keys %$sql_schema ) { |
foreach my $table ( keys %$sql_schema ) { |
281 |
|
|
282 |
|
|
283 |
|
|
284 |
my $sth = $dbh->prepare(qq{ |
my $sth_insert_log = $dbh->prepare(qq{ |
285 |
insert into log |
insert into log |
286 |
(channel, me, nick, message, time) |
(channel, me, nick, message, time) |
287 |
values (?,?,?,?,?) |
values (?,?,?,?,?) |
525 |
|
|
526 |
=cut |
=cut |
527 |
|
|
|
my $last_x_tags = 5; |
|
528 |
my @last_tags; |
my @last_tags; |
529 |
|
|
530 |
sub add_tag { |
sub add_tag { |
542 |
next if (! $tag || $tag =~ m/https?:/i); |
next if (! $tag || $tag =~ m/https?:/i); |
543 |
push @{ $tags->{$tag} }, $arg->{id}; |
push @{ $tags->{$tag} }, $arg->{id}; |
544 |
#warn "+tag $tag: $arg->{id}\n"; |
#warn "+tag $tag: $arg->{id}\n"; |
545 |
$cloud->add($tag, "?tag=$tag", scalar @{$tags->{$tag}} + 1); |
$cloud->add($tag, "$url?tag=$tag", scalar @{$tags->{$tag}} + 1); |
546 |
push @tags, $tag; |
push @tags, $tag; |
547 |
|
|
548 |
} |
} |
549 |
|
|
550 |
if ( @tags ) { |
if ( @tags ) { |
551 |
shift @last_tags if $#last_tags == $last_x_tags; |
pop @last_tags if $#last_tags == $last_x_tags; |
552 |
push @last_tags, { tags => [ @tags ], %$arg }; |
unshift @last_tags, { tags => [ @tags ], %$arg }; |
553 |
} |
} |
554 |
|
|
555 |
} |
} |
561 |
=cut |
=cut |
562 |
|
|
563 |
sub seed_tags { |
sub seed_tags { |
564 |
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 }); |
565 |
$sth->execute; |
$sth->execute; |
566 |
while (my $row = $sth->fetchrow_hashref) { |
while (my $row = $sth->fetchrow_hashref) { |
567 |
add_tag( %$row ); |
add_tag( %$row ); |
568 |
} |
} |
569 |
|
|
570 |
foreach my $tag (keys %$tags) { |
foreach my $tag (keys %$tags) { |
571 |
$cloud->add($tag, "?tag=$tag", scalar @{$tags->{$tag}} + 1); |
$cloud->add($tag, "$url?tag=$tag", scalar @{$tags->{$tag}} + 1); |
572 |
} |
} |
573 |
} |
} |
574 |
|
|
602 |
$a->{me} ? "***" . $a->{nick} : "<" . $a->{nick} . ">", |
$a->{me} ? "***" . $a->{nick} : "<" . $a->{nick} . ">", |
603 |
" " . $a->{message}; |
" " . $a->{message}; |
604 |
|
|
605 |
from_to($a->{message}, 'UTF-8', $ENCODING); |
$sth_insert_log->execute($a->{channel}, $a->{me}, $a->{nick}, $a->{message}, $a->{time}); |
|
|
|
|
$sth->execute($a->{channel}, $a->{me}, $a->{nick}, $a->{message}, $a->{time}); |
|
606 |
add_tag( id => $dbh->last_insert_id(undef,undef,"log",undef), %$a ); |
add_tag( id => $dbh->last_insert_id(undef,undef,"log",undef), %$a ); |
607 |
} |
} |
608 |
|
|
641 |
exit; |
exit; |
642 |
} |
} |
643 |
|
|
644 |
|
# |
645 |
|
# RSS follow |
646 |
|
# |
647 |
|
|
648 |
|
my $_rss; |
649 |
|
|
650 |
|
|
651 |
|
sub rss_fetch { |
652 |
|
my ($args) = @_; |
653 |
|
|
654 |
|
# how many messages to send out when feed is seen for the first time? |
655 |
|
my $send_rss_msgs = 1; |
656 |
|
|
657 |
|
_log "RSS fetch", $args->{url}; |
658 |
|
|
659 |
|
my $feed = XML::Feed->parse(URI->new( $args->{url} )); |
660 |
|
if ( ! $feed ) { |
661 |
|
_log("can't fetch RSS ", $args->{url}); |
662 |
|
return; |
663 |
|
} |
664 |
|
my ( $total, $updates ) = ( 0, 0 ); |
665 |
|
for my $entry ($feed->entries) { |
666 |
|
$total++; |
667 |
|
|
668 |
|
# seen allready? |
669 |
|
return if $_rss->{$feed->link}->{seen}->{$entry->id}++ > 0; |
670 |
|
|
671 |
|
sub prefix { |
672 |
|
my ($txt,$var) = @_; |
673 |
|
$var =~ s/^\s+//g; |
674 |
|
return $txt . $var if $var; |
675 |
|
} |
676 |
|
|
677 |
|
my $msg; |
678 |
|
$msg .= prefix( 'From: ' , $feed->title ); |
679 |
|
$msg .= prefix( ' by ' , $entry->author ); |
680 |
|
$msg .= prefix( ' -- ' , $entry->link ); |
681 |
|
# $msg .= prefix( ' id ' , $entry->id ); |
682 |
|
|
683 |
|
if ( $args->{kernel} && $send_rss_msgs ) { |
684 |
|
warn "# sending to $CHANNEL\n"; |
685 |
|
$send_rss_msgs--; |
686 |
|
$args->{kernel}->post( $IRC_ALIAS => notice => $CHANNEL, $msg ); |
687 |
|
$updates++; |
688 |
|
#$sth_insert_log->execute( $CHANNEL, 1, $NICK, $msg, undef ); |
689 |
|
_log('RSS', $msg); |
690 |
|
} |
691 |
|
} |
692 |
|
|
693 |
|
my $sql = qq{ update feeds set last_update = now(), polls = polls + 1 }; |
694 |
|
$sql .= qq{, updates = updates + $updates } if $updates; |
695 |
|
$sql .= qq{where id = } . $args->{id}; |
696 |
|
eval { $dbh->do( $sql ) }; |
697 |
|
|
698 |
|
_log "RSS got $total items of which $updates new"; |
699 |
|
|
700 |
|
return $updates; |
701 |
|
} |
702 |
|
|
703 |
|
sub rss_fetch_all { |
704 |
|
my $kernel = shift; |
705 |
|
my $sql = qq{ |
706 |
|
select id, url, name |
707 |
|
from feeds |
708 |
|
where active is true |
709 |
|
}; |
710 |
|
# limit to newer feeds only if we are not sending messages out |
711 |
|
$sql .= qq{ and last_update + delay < now() } if $kernel; |
712 |
|
my $sth = $dbh->prepare( $sql ); |
713 |
|
$sth->execute(); |
714 |
|
warn "# ",$sth->rows," active RSS feeds\n"; |
715 |
|
my $count = 0; |
716 |
|
while (my $row = $sth->fetchrow_hashref) { |
717 |
|
$row->{kernel} = $kernel if $kernel; |
718 |
|
$count += rss_fetch( $row ); |
719 |
|
} |
720 |
|
return "OK, fetched $count posts from " . $sth->rows . " feeds"; |
721 |
|
} |
722 |
|
|
723 |
|
|
724 |
|
sub rss_check_updates { |
725 |
|
my $kernel = shift; |
726 |
|
my $last_t = $_rss->{last_poll} || time(); |
727 |
|
my $t = time(); |
728 |
|
if ( $last_t - $t > $rss_min_delay ) { |
729 |
|
$_rss->{last_poll} = $t; |
730 |
|
_log rss_fetch_all( $kernel ); |
731 |
|
} |
732 |
|
} |
733 |
|
|
734 |
|
# seed rss seen cache so we won't send out all items on startup |
735 |
|
_log rss_fetch_all; |
736 |
|
|
737 |
# |
# |
738 |
# POE handing part |
# POE handing part |
744 |
|
|
745 |
POE::Component::IRC->new($IRC_ALIAS); |
POE::Component::IRC->new($IRC_ALIAS); |
746 |
|
|
747 |
POE::Session->create( inline_states => |
POE::Session->create( inline_states => { |
748 |
{_start => sub { |
_start => sub { |
749 |
$_[KERNEL]->post($IRC_ALIAS => register => 'all'); |
$_[KERNEL]->post($IRC_ALIAS => register => 'all'); |
750 |
$_[KERNEL]->post($IRC_ALIAS => connect => $CONNECT); |
$_[KERNEL]->post($IRC_ALIAS => connect => $CONNECT); |
751 |
}, |
}, |
752 |
irc_255 => sub { # server is done blabbing |
irc_255 => sub { # server is done blabbing |
753 |
$_[KERNEL]->post($IRC_ALIAS => join => $CHANNEL); |
$_[KERNEL]->post($IRC_ALIAS => join => $CHANNEL); |
|
$_[KERNEL]->post($IRC_ALIAS => join => '#logger'); |
|
|
$_[KERNEL]->yield("heartbeat"); # start heartbeat |
|
|
# $_[KERNEL]->yield("my_add", $_) for keys %FOLLOWS; |
|
754 |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "IDENTIFY $NICK" ); |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "IDENTIFY $NICK" ); |
755 |
}, |
}, |
756 |
irc_public => sub { |
irc_public => sub { |
781 |
|
|
782 |
}, |
}, |
783 |
irc_ping => sub { |
irc_ping => sub { |
784 |
warn "pong ", $_[ARG0], $/; |
_log( "pong ", $_[ARG0] ); |
785 |
$ping->{ $_[ARG0] }++; |
$ping->{ $_[ARG0] }++; |
786 |
|
rss_check_updates( $_[KERNEL] ); |
787 |
}, |
}, |
788 |
irc_invite => sub { |
irc_invite => sub { |
789 |
my $kernel = $_[KERNEL]; |
my $kernel = $_[KERNEL]; |
790 |
my $nick = (split /!/, $_[ARG0])[0]; |
my $nick = (split /!/, $_[ARG0])[0]; |
791 |
my $channel = $_[ARG1]; |
my $channel = $_[ARG1]; |
792 |
|
|
793 |
warn "invited to $channel by $nick"; |
_log "invited to $channel by $nick"; |
794 |
|
|
795 |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, "how nice of you to invite me to $channel, I'll be right there..." ); |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, "how nice of you to invite me to $channel, I'll be right there..." ); |
796 |
$_[KERNEL]->post($IRC_ALIAS => join => $channel); |
$_[KERNEL]->post($IRC_ALIAS => join => $channel); |
801 |
my $nick = (split /!/, $_[ARG0])[0]; |
my $nick = (split /!/, $_[ARG0])[0]; |
802 |
my $msg = $_[ARG2]; |
my $msg = $_[ARG2]; |
803 |
my $channel = $_[ARG1]->[0]; |
my $channel = $_[ARG1]->[0]; |
|
from_to($msg, 'UTF-8', $ENCODING); |
|
804 |
|
|
805 |
my $res = "unknown command '$msg', try /msg $NICK help!"; |
my $res = "unknown command '$msg', try /msg $NICK help!"; |
806 |
my @out; |
my @out; |
844 |
|
|
845 |
foreach my $res (get_from_log( limit => $limit )) { |
foreach my $res (get_from_log( limit => $limit )) { |
846 |
_log "last: $res"; |
_log "last: $res"; |
|
from_to($res, $ENCODING, 'UTF-8'); |
|
847 |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res ); |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res ); |
848 |
} |
} |
849 |
|
|
858 |
search => $what, |
search => $what, |
859 |
)) { |
)) { |
860 |
_log "search [$what]: $res"; |
_log "search [$what]: $res"; |
|
from_to($res, $ENCODING, 'UTF-8'); |
|
861 |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res ); |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res ); |
862 |
} |
} |
863 |
|
|
927 |
$res = "config option $op doesn't exist"; |
$res = "config option $op doesn't exist"; |
928 |
} |
} |
929 |
} |
} |
930 |
|
} elsif ($msg =~ m/^rss-update/) { |
931 |
|
$res = rss_fetch_all( $_[KERNEL] ); |
932 |
|
} elsif ($msg =~ m/^rss-clean/) { |
933 |
|
$_rss = undef; |
934 |
|
$res = "OK, cleaned RSS cache"; |
935 |
|
} elsif ($msg =~ m!^rss-(add|remove|stop|start)\s+(http://\S+)\s*(.*)!) { |
936 |
|
my $sql = { |
937 |
|
add => qq{ insert into feeds (url,name) values (?,?) }, |
938 |
|
# remove => qq{ delete from feeds where url = ? and name = ? }, |
939 |
|
start => qq{ update feeds set active = true where url = ? -- ? }, |
940 |
|
stop => qq{ update feeds set active = false where url = ? -- ? }, |
941 |
|
|
942 |
|
}; |
943 |
|
if (my $q = $sql->{$1} ) { |
944 |
|
my $sth = $dbh->prepare( $q ); |
945 |
|
warn "## SQL $q ( $2 | $3 )\n"; |
946 |
|
eval { $sth->execute( $2, $3 ) }; |
947 |
|
} |
948 |
|
|
949 |
|
$res ||= "OK, RSS $1 : $2 - $3"; |
950 |
} |
} |
951 |
|
|
952 |
if ($res) { |
if ($res) { |
953 |
_log ">> [$nick] $res"; |
_log ">> [$nick] $res"; |
|
from_to($res, $ENCODING, 'UTF-8'); |
|
954 |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res ); |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res ); |
955 |
} |
} |
956 |
|
|
957 |
|
rss_check_updates( $_[KERNEL] ); |
958 |
}, |
}, |
959 |
irc_477 => sub { |
irc_477 => sub { |
960 |
_log "# irc_477: ",$_[ARG1]; |
_log "# irc_477: ",$_[ARG1]; |
993 |
""; |
""; |
994 |
0; # false for signals |
0; # false for signals |
995 |
}, |
}, |
|
my_add => sub { |
|
|
my $trailing = $_[ARG0]; |
|
|
my $session = $_[SESSION]; |
|
|
POE::Session->create |
|
|
(inline_states => |
|
|
{_start => sub { |
|
|
$_[HEAP]->{wheel} = |
|
|
POE::Wheel::FollowTail->new |
|
|
( |
|
|
Filename => $FOLLOWS{$trailing}, |
|
|
InputEvent => 'got_line', |
|
|
); |
|
|
}, |
|
|
got_line => sub { |
|
|
$_[KERNEL]->post($session => my_tailed => |
|
|
time, $trailing, $_[ARG0]); |
|
|
}, |
|
|
}, |
|
|
); |
|
|
|
|
|
}, |
|
|
my_tailed => sub { |
|
|
my ($time, $file, $line) = @_[ARG0..ARG2]; |
|
|
## $time will be undef on a probe, or a time value if a real line |
|
|
|
|
|
## PoCo::IRC has throttling built in, but no external visibility |
|
|
## so this is reaching "under the hood" |
|
|
$SEND_QUEUE ||= |
|
|
$_[KERNEL]->alias_resolve($IRC_ALIAS)->get_heap->{send_queue}; |
|
|
|
|
|
## handle "no need to keep skipping" transition |
|
|
if ($SKIPPING and @$SEND_QUEUE < 1) { |
|
|
$_[KERNEL]->post($IRC_ALIAS => privmsg => $CHANNEL => |
|
|
"[discarded $SKIPPING messages]"); |
|
|
$SKIPPING = 0; |
|
|
} |
|
|
|
|
|
## handle potential message display |
|
|
if ($time) { |
|
|
if ($SKIPPING or @$SEND_QUEUE > 3) { # 3 msgs per 10 seconds |
|
|
$SKIPPING++; |
|
|
} else { |
|
|
my @time = localtime $time; |
|
|
$_[KERNEL]->post($IRC_ALIAS => privmsg => $CHANNEL => |
|
|
sprintf "%02d:%02d:%02d: %s: %s", |
|
|
($time[2] + 11) % 12 + 1, $time[1], $time[0], |
|
|
$file, $line); |
|
|
} |
|
|
} |
|
|
|
|
|
## handle re-probe/flush if skipping |
|
|
if ($SKIPPING) { |
|
|
$_[KERNEL]->delay($_[STATE] => 0.5); # $time will be undef |
|
|
} |
|
|
|
|
|
}, |
|
|
my_heartbeat => sub { |
|
|
$_[KERNEL]->yield(my_tailed => time, "heartbeat", "beep"); |
|
|
$_[KERNEL]->delay($_[STATE] => 10); |
|
|
} |
|
996 |
}, |
}, |
997 |
); |
); |
998 |
|
|
1000 |
|
|
1001 |
my $httpd = POE::Component::Server::HTTP->new( |
my $httpd = POE::Component::Server::HTTP->new( |
1002 |
Port => $http_port, |
Port => $http_port, |
1003 |
|
PreHandler => { |
1004 |
|
'/' => sub { |
1005 |
|
$_[0]->header(Connection => 'close') |
1006 |
|
} |
1007 |
|
}, |
1008 |
ContentHandler => { '/' => \&root_handler }, |
ContentHandler => { '/' => \&root_handler }, |
1009 |
Headers => { Server => 'irc-logger' }, |
Headers => { Server => 'irc-logger' }, |
1010 |
); |
); |
1050 |
my ($request, $response) = @_; |
my ($request, $response) = @_; |
1051 |
$response->code(RC_OK); |
$response->code(RC_OK); |
1052 |
|
|
1053 |
|
# this doesn't seem to work, so moved to PreHandler |
1054 |
|
#$response->header(Connection => 'close'); |
1055 |
|
|
1056 |
|
return RC_OK if $request->uri =~ m/favicon.ico$/; |
1057 |
|
|
1058 |
my $q; |
my $q; |
1059 |
|
|
1060 |
if ( $request->method eq 'POST' ) { |
if ( $request->method eq 'POST' ) { |
1067 |
|
|
1068 |
my $search = $q->param('search') || $q->param('grep') || ''; |
my $search = $q->param('search') || $q->param('grep') || ''; |
1069 |
|
|
1070 |
if ($request->url =~ m#/(rss|atom)#) { |
if ($request->url =~ m#/rss(?:/(tags|last-tag|follow.*)\w*(?:=(\d+))?)?#i) { |
1071 |
my $type = uc($1); |
my $show = lc($1); |
1072 |
my $url = "http://$http_hostname:$http_port"; |
my $nr = $2; |
1073 |
|
|
1074 |
$response->content_type("application/$type+xml"); |
my $type = 'RSS'; # Atom |
1075 |
|
|
1076 |
|
$response->content_type( 'application/' . lc($type) . '+xml' ); |
1077 |
|
|
1078 |
my $html = '<!-- error -->'; |
my $html = '<!-- error -->'; |
1079 |
warn "create $type feed from ",dump( @last_tags ); |
#warn "create $type feed from ",dump( @last_tags ); |
1080 |
|
|
1081 |
my $feed = XML::Feed->new( $type ); |
my $feed = XML::Feed->new( $type ); |
1082 |
|
$feed->link( $url ); |
1083 |
|
|
1084 |
$feed->title( "last $last_x_tags from $CHANNEL" ); |
if ( $show eq 'tags' ) { |
1085 |
$feed->link( "http://$http_hostname:$http_port" ); |
$nr ||= 50; |
1086 |
$feed->description( "collects messages which have tags// in them" ); |
$feed->title( "tags from $CHANNEL" ); |
1087 |
|
$feed->link( "$url/tags" ); |
1088 |
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}} ); |
|
1089 |
my $feed_entry = XML::Feed::Entry->new($type); |
my $feed_entry = XML::Feed::Entry->new($type); |
1090 |
$feed_entry->title( $m->{nick} . '@' . $m->{time} ); |
$feed_entry->title( "$nr tags from $CHANNEL" ); |
1091 |
$feed_entry->author( $m->{nick} ); |
$feed_entry->author( $NICK ); |
1092 |
# $feed_entry->link( ); |
$feed_entry->link( '/#tags' ); |
1093 |
$feed_entry->issued( DateTime::Format::Flexible->build( $m->{time} ) ); |
|
1094 |
$feed_entry->summary( |
$feed_entry->content( |
1095 |
# $filter->{nick}->( $m->{nick} ) . |
qq{<![CDATA[<style type="text/css">} |
1096 |
# '<tt>' . $m->{nick} . '</tt> ' . |
. $cloud->css |
1097 |
$filter->{message}->( $m->{message} ) |
. qq{</style>} |
1098 |
|
. $cloud->html( $nr ) |
1099 |
|
. qq{]]>} |
1100 |
); |
); |
1101 |
$feed->add_entry( $feed_entry ); |
$feed->add_entry( $feed_entry ); |
1102 |
|
|
1103 |
|
} elsif ( $show eq 'last-tag' ) { |
1104 |
|
|
1105 |
|
$nr ||= $last_x_tags; |
1106 |
|
$nr = $last_x_tags if $nr > $last_x_tags; |
1107 |
|
|
1108 |
|
$feed->title( "last $nr tagged messages from $CHANNEL" ); |
1109 |
|
$feed->description( "collects messages which have tags// in them" ); |
1110 |
|
|
1111 |
|
foreach my $m ( @last_tags ) { |
1112 |
|
# warn dump( $m ); |
1113 |
|
#my $tags = join(' ', @{$m->{tags}} ); |
1114 |
|
my $feed_entry = XML::Feed::Entry->new($type); |
1115 |
|
$feed_entry->title( $m->{nick} . '@' . $m->{time} ); |
1116 |
|
$feed_entry->author( $m->{nick} ); |
1117 |
|
$feed_entry->link( '/#' . $m->{id} ); |
1118 |
|
$feed_entry->issued( DateTime::Format::Flexible->build( $m->{time} ) ); |
1119 |
|
|
1120 |
|
my $message = $filter->{message}->( $m->{message} ); |
1121 |
|
$message .= "<br/>\n" unless $message =~ m!<(/p|br/?)>!; |
1122 |
|
# warn "## message = $message\n"; |
1123 |
|
|
1124 |
|
#$feed_entry->summary( |
1125 |
|
$feed_entry->content( |
1126 |
|
"<![CDATA[$message]]>" |
1127 |
|
); |
1128 |
|
$feed_entry->category( join(', ', @{$m->{tags}}) ); |
1129 |
|
$feed->add_entry( $feed_entry ); |
1130 |
|
|
1131 |
|
$nr--; |
1132 |
|
last if $nr <= 0; |
1133 |
|
|
1134 |
|
} |
1135 |
|
|
1136 |
|
} elsif ( $show =~ m/^follow/ ) { |
1137 |
|
|
1138 |
|
$feed->title( "Feeds which this bot follows" ); |
1139 |
|
|
1140 |
|
my $sth = $dbh->prepare( qq{ select * from feeds order by last_update desc } ); |
1141 |
|
$sth->execute; |
1142 |
|
while (my $row = $sth->fetchrow_hashref) { |
1143 |
|
my $feed_entry = XML::Feed::Entry->new($type); |
1144 |
|
$feed_entry->title( $row->{name} ); |
1145 |
|
$feed_entry->link( $row->{url} ); |
1146 |
|
$feed_entry->issued( DateTime::Format::Flexible->build( $row->{last_update} ) ); |
1147 |
|
$feed_entry->content( |
1148 |
|
'<![CDATA[<pre>' . dump( $row ) . '</pre>]]>' |
1149 |
|
); |
1150 |
|
$feed->add_entry( $feed_entry ); |
1151 |
|
} |
1152 |
|
|
1153 |
|
} else { |
1154 |
|
_log "unknown rss request ",$request->url; |
1155 |
|
return RC_DENY; |
1156 |
} |
} |
1157 |
|
|
1158 |
$response->content( $feed->as_xml ); |
$response->content( $feed->as_xml ); |
1163 |
warn "$@"; |
warn "$@"; |
1164 |
} |
} |
1165 |
|
|
1166 |
$response->content_type("text/html; charset=$ENCODING"); |
$response->content_type("text/html; charset=UTF-8"); |
1167 |
|
|
1168 |
my $html = |
my $html = |
1169 |
qq{<html><head><title>$NICK</title><style type="text/css">$style} . |
qq{<html><head><title>$NICK</title><style type="text/css">$style} |
1170 |
$cloud->css . |
. $cloud->css |
1171 |
qq{</style></head><body>} . |
. qq{</style></head><body>} |
1172 |
qq{ |
. qq{ |
1173 |
<form method="post" class="search" action="/"> |
<form method="post" class="search" action="/"> |
1174 |
<input type="text" name="search" value="$search" size="10"> |
<input type="text" name="search" value="$search" size="10"> |
1175 |
<input type="submit" value="search"> |
<input type="submit" value="search"> |
1176 |
</form> |
</form> |
1177 |
} . |
} |
1178 |
$cloud->html(500) . |
. $cloud->html(500) |
1179 |
qq{<p>}; |
. qq{<p>}; |
1180 |
if ($request->url =~ m#/history#) { |
|
1181 |
|
if ($request->url =~ m#/tags?#) { |
1182 |
|
# nop |
1183 |
|
} elsif ($request->url =~ m#/history#) { |
1184 |
my $sth = $dbh->prepare(qq{ |
my $sth = $dbh->prepare(qq{ |
1185 |
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 |
1186 |
from log |
from log |
1212 |
$cal->weekdays('MON','TUE','WED','THU','FRI'); |
$cal->weekdays('MON','TUE','WED','THU','FRI'); |
1213 |
($l_yyyy,$l_mm) = ($yyyy,$mm); |
($l_yyyy,$l_mm) = ($yyyy,$mm); |
1214 |
} |
} |
1215 |
$cal->setcontent($dd, qq{ |
$cal->setcontent($dd, qq[ |
1216 |
<a href="/?date=$row->{date}">$row->{nr}</a><br/>$row->{len} |
<a href="$url?date=$row->{date}">$row->{nr}</a><br/>$row->{len} |
1217 |
}); |
]); |
1218 |
|
|
1219 |
} |
} |
1220 |
$html .= qq{<td valign="top">} . $cal->as_HTML() . qq{</td></tr></table>}; |
$html .= qq{<td valign="top">} . $cal->as_HTML() . qq{</td></tr></table>}; |
1229 |
fmt => { |
fmt => { |
1230 |
date => sub { |
date => sub { |
1231 |
my $date = shift || return; |
my $date = shift || return; |
1232 |
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>}; |
1233 |
}, |
}, |
1234 |
time => '<span class="time">%s</span> ', |
time => '<span class="time">%s</span> ', |
1235 |
time_channel => '<span class="channel">%s %s</span> ', |
time_channel => '<span class="channel">%s %s</span> ', |
1248 |
</body></html>}; |
</body></html>}; |
1249 |
|
|
1250 |
$response->content( $html ); |
$response->content( $html ); |
1251 |
|
warn "<< ", $request->method, " ", $request->uri, " created ", length($html), " bytes\n"; |
1252 |
return RC_OK; |
return RC_OK; |
1253 |
} |
} |
1254 |
|
|