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 |
|
|
60 |
|
|
61 |
my $sleep_on_error = 5; |
my $sleep_on_error = 5; |
62 |
|
|
63 |
my $http_port = $NICK =~ m/-dev/ ? 8001 : 8000; |
# number of last tags to keep in circular buffer |
64 |
my $http_hostname = `hostname`; |
my $last_x_tags = 50; |
|
chomp( $http_hostname ); |
|
65 |
|
|
66 |
## END CONFIG |
# don't pull rss feeds more often than this |
67 |
|
my $rss_min_delay = 60; |
68 |
|
$rss_min_delay = 15; |
69 |
|
|
70 |
|
my $http_port = $NICK =~ m/-dev/ ? 8001 : 8000; |
71 |
|
|
72 |
|
my $url = "http://$HOSTNAME:$http_port"; |
73 |
|
|
74 |
|
## END CONFIG |
75 |
|
|
76 |
use POE qw(Component::IRC Wheel::FollowTail Component::Server::HTTP); |
use POE qw(Component::IRC Wheel::FollowTail Component::Server::HTTP); |
77 |
use HTTP::Status; |
use HTTP::Status; |
99 |
my $log_path; |
my $log_path; |
100 |
GetOptions( |
GetOptions( |
101 |
'import-dircproxy:s' => \$import_dircproxy, |
'import-dircproxy:s' => \$import_dircproxy, |
102 |
|
'follows:s' => \$follows_path, |
103 |
'log:s' => \$log_path, |
'log:s' => \$log_path, |
104 |
); |
); |
105 |
|
|
113 |
print strftime($TIMESTAMP,localtime()), ' ', join(" ",@_), $/; |
print strftime($TIMESTAMP,localtime()), ' ', join(" ",@_), $/; |
114 |
} |
} |
115 |
|
|
116 |
|
# LOG following |
117 |
|
|
118 |
|
my %FOLLOWS = |
119 |
|
( |
120 |
|
# ACCESS => "/var/log/apache/access.log", |
121 |
|
# ERROR => "/var/log/apache/error.log", |
122 |
|
); |
123 |
|
|
124 |
|
sub add_follow_path { |
125 |
|
my $path = shift; |
126 |
|
my $name = $path; |
127 |
|
$name =~ s/\..*$//; |
128 |
|
warn "# using $path to announce messages from $name\n"; |
129 |
|
$FOLLOWS{$name} = $path; |
130 |
|
} |
131 |
|
|
132 |
|
add_follow_path( $follows_path ) if ( -e $follows_path ); |
133 |
|
|
134 |
# HTML formatters |
# HTML formatters |
135 |
|
|
136 |
my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); |
my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); |
154 |
$m =~ s/($escape_re)/$escape{$1}/gs; |
$m =~ s/($escape_re)/$escape{$1}/gs; |
155 |
$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 || |
156 |
$m =~ s#\/(\w+)\/#<i>$1</i>#gs; |
$m =~ s#\/(\w+)\/#<i>$1</i>#gs; |
157 |
$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; |
158 |
$m =~ s#\*(\w+)\*#<b>$1</b>#gs; |
$m =~ s#\*(\w+)\*#<b>$1</b>#gs; |
159 |
$m =~ s#_(\w+)_#<u>$1</u>#gs; |
$m =~ s#_(\w+)_#<u>$1</u>#gs; |
160 |
|
|
176 |
my $dbh = DBI->connect($DSN,"","", { RaiseError => 1, AutoCommit => 1 }) || die $DBI::errstr; |
my $dbh = DBI->connect($DSN,"","", { RaiseError => 1, AutoCommit => 1 }) || die $DBI::errstr; |
177 |
|
|
178 |
my $sql_schema = { |
my $sql_schema = { |
179 |
log => ' |
log => qq{ |
180 |
create table log ( |
create table log ( |
181 |
id serial, |
id serial, |
182 |
time timestamp default now(), |
time timestamp default now(), |
190 |
create index log_time on log(time); |
create index log_time on log(time); |
191 |
create index log_channel on log(channel); |
create index log_channel on log(channel); |
192 |
create index log_nick on log(nick); |
create index log_nick on log(nick); |
193 |
', |
}, |
194 |
meta => ' |
meta => q{ |
195 |
create table meta ( |
create table meta ( |
196 |
nick text not null, |
nick text not null, |
197 |
channel text not null, |
channel text not null, |
198 |
name text not null, |
name text not null, |
199 |
value text, |
value text, |
200 |
changed timestamp default now(), |
changed timestamp default 'now()', |
201 |
primary key(nick,channel,name) |
primary key(nick,channel,name) |
202 |
); |
); |
203 |
', |
}, |
204 |
|
feeds => qq{ |
205 |
|
create table feeds ( |
206 |
|
id serial, |
207 |
|
url text not null, |
208 |
|
name text, |
209 |
|
delay interval not null default '30 sec', --'5 min', |
210 |
|
active boolean default true, |
211 |
|
last_update timestamp default 'now()', |
212 |
|
polls int default 0, |
213 |
|
updates int default 0 |
214 |
|
); |
215 |
|
create unique index feeds_url on feeds(url); |
216 |
|
insert into feeds (url,name) values ('http://wiki.razmjenavjestina.org/feed/workspace/razmjenavjestina?category=Recent%20Changes','wiki'); |
217 |
|
}, |
218 |
}; |
}; |
219 |
|
|
220 |
foreach my $table ( keys %$sql_schema ) { |
foreach my $table ( keys %$sql_schema ) { |
522 |
|
|
523 |
=cut |
=cut |
524 |
|
|
|
my $last_x_tags = 5; |
|
525 |
my @last_tags; |
my @last_tags; |
526 |
|
|
527 |
sub add_tag { |
sub add_tag { |
539 |
next if (! $tag || $tag =~ m/https?:/i); |
next if (! $tag || $tag =~ m/https?:/i); |
540 |
push @{ $tags->{$tag} }, $arg->{id}; |
push @{ $tags->{$tag} }, $arg->{id}; |
541 |
#warn "+tag $tag: $arg->{id}\n"; |
#warn "+tag $tag: $arg->{id}\n"; |
542 |
$cloud->add($tag, "?tag=$tag", scalar @{$tags->{$tag}} + 1); |
$cloud->add($tag, "$url?tag=$tag", scalar @{$tags->{$tag}} + 1); |
543 |
push @tags, $tag; |
push @tags, $tag; |
544 |
|
|
545 |
} |
} |
546 |
|
|
547 |
if ( @tags ) { |
if ( @tags ) { |
548 |
shift @last_tags if $#last_tags == $last_x_tags; |
pop @last_tags if $#last_tags == $last_x_tags; |
549 |
push @last_tags, { tags => [ @tags ], %$arg }; |
unshift @last_tags, { tags => [ @tags ], %$arg }; |
550 |
} |
} |
551 |
|
|
552 |
} |
} |
558 |
=cut |
=cut |
559 |
|
|
560 |
sub seed_tags { |
sub seed_tags { |
561 |
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 }); |
562 |
$sth->execute; |
$sth->execute; |
563 |
while (my $row = $sth->fetchrow_hashref) { |
while (my $row = $sth->fetchrow_hashref) { |
564 |
add_tag( %$row ); |
add_tag( %$row ); |
565 |
} |
} |
566 |
|
|
567 |
foreach my $tag (keys %$tags) { |
foreach my $tag (keys %$tags) { |
568 |
$cloud->add($tag, "?tag=$tag", scalar @{$tags->{$tag}} + 1); |
$cloud->add($tag, "$url?tag=$tag", scalar @{$tags->{$tag}} + 1); |
569 |
} |
} |
570 |
} |
} |
571 |
|
|
640 |
exit; |
exit; |
641 |
} |
} |
642 |
|
|
643 |
|
# |
644 |
|
# RSS follow |
645 |
|
# |
646 |
|
|
647 |
|
my $_rss; |
648 |
|
|
649 |
|
|
650 |
|
sub rss_fetch { |
651 |
|
my ($args) = @_; |
652 |
|
|
653 |
|
# how many messages to send out when feed is seen for the first time? |
654 |
|
my $send_rss_msgs = 1; |
655 |
|
|
656 |
|
my $feed = XML::Feed->parse(URI->new( $args->{url} )); |
657 |
|
if ( ! $feed ) { |
658 |
|
_log("can't fetch RSS ", $args->{url}); |
659 |
|
return; |
660 |
|
} |
661 |
|
my $updates = 0; |
662 |
|
for my $entry ($feed->entries) { |
663 |
|
|
664 |
|
# seen allready? |
665 |
|
return if $_rss->{$feed->link}->{seen}->{$entry->id}++ > 0; |
666 |
|
|
667 |
|
sub prefix { |
668 |
|
my ($txt,$var) = @_; |
669 |
|
$var =~ s/^\s+//g; |
670 |
|
return $txt . $var if $var; |
671 |
|
} |
672 |
|
|
673 |
|
my $msg; |
674 |
|
$msg .= prefix( 'From: ' , $feed->title ); |
675 |
|
$msg .= prefix( ' by ' , $entry->author ); |
676 |
|
$msg .= prefix( ' -- ' , $entry->link ); |
677 |
|
# $msg .= prefix( ' id ' , $entry->id ); |
678 |
|
|
679 |
|
_log('RSS', $msg); |
680 |
|
|
681 |
|
if ( $args->{kernel} && $send_rss_msgs ) { |
682 |
|
warn "# sending to $CHANNEL\n"; |
683 |
|
$send_rss_msgs--; |
684 |
|
$args->{kernel}->post( $IRC_ALIAS => notice => $CHANNEL, $msg ); |
685 |
|
$updates++; |
686 |
|
} |
687 |
|
} |
688 |
|
|
689 |
|
my $sql = qq{ update feeds set last_update = now(), polls = polls + 1 }; |
690 |
|
$sql .= qq{, updates = updates + $updates } if $updates; |
691 |
|
$sql .= qq{where id = } . $args->{id}; |
692 |
|
$dbh->do( $sql ); |
693 |
|
|
694 |
|
return $updates; |
695 |
|
} |
696 |
|
|
697 |
|
sub rss_fetch_all { |
698 |
|
my $kernel = shift; |
699 |
|
my $sql = qq{ |
700 |
|
select id, url, name |
701 |
|
from feeds |
702 |
|
where active is true |
703 |
|
}; |
704 |
|
# limit to newer feeds only if we are not sending messages out |
705 |
|
$sql .= qq{ and last_update + delay < now() } if $kernel; |
706 |
|
my $sth = $dbh->prepare( $sql ); |
707 |
|
$sth->execute(); |
708 |
|
warn "# ",$sth->rows," active RSS feeds\n"; |
709 |
|
my $count = 0; |
710 |
|
while (my $row = $sth->fetchrow_hashref) { |
711 |
|
warn "+++ fetch RSS feed: ",dump( $row ); |
712 |
|
$row->{kernel} = $kernel if $kernel; |
713 |
|
$count += rss_fetch( $row ); |
714 |
|
} |
715 |
|
return "OK, fetched $count posts from " . $sth->rows . " feeds"; |
716 |
|
} |
717 |
|
|
718 |
|
my $rss_last_poll = time(); |
719 |
|
|
720 |
|
sub rss_check_updates { |
721 |
|
my $kernel = shift; |
722 |
|
my $t = time(); |
723 |
|
if ( $rss_last_poll - $t > $rss_min_delay ) { |
724 |
|
$rss_last_poll = $t; |
725 |
|
_log rss_fetch_all( $kernel ); |
726 |
|
} |
727 |
|
} |
728 |
|
|
729 |
|
# seed rss seen cache so we won't send out all items on startup |
730 |
|
_log rss_fetch_all; |
731 |
|
|
732 |
# |
# |
733 |
# POE handing part |
# POE handing part |
739 |
|
|
740 |
POE::Component::IRC->new($IRC_ALIAS); |
POE::Component::IRC->new($IRC_ALIAS); |
741 |
|
|
742 |
POE::Session->create( inline_states => |
POE::Session->create( inline_states => { |
743 |
{_start => sub { |
_start => sub { |
744 |
$_[KERNEL]->post($IRC_ALIAS => register => 'all'); |
$_[KERNEL]->post($IRC_ALIAS => register => 'all'); |
745 |
$_[KERNEL]->post($IRC_ALIAS => connect => $CONNECT); |
$_[KERNEL]->post($IRC_ALIAS => connect => $CONNECT); |
746 |
}, |
}, |
748 |
$_[KERNEL]->post($IRC_ALIAS => join => $CHANNEL); |
$_[KERNEL]->post($IRC_ALIAS => join => $CHANNEL); |
749 |
$_[KERNEL]->post($IRC_ALIAS => join => '#logger'); |
$_[KERNEL]->post($IRC_ALIAS => join => '#logger'); |
750 |
$_[KERNEL]->yield("heartbeat"); # start heartbeat |
$_[KERNEL]->yield("heartbeat"); # start heartbeat |
751 |
# $_[KERNEL]->yield("my_add", $_) for keys %FOLLOWS; |
$_[KERNEL]->yield("my_add", $_) for keys %FOLLOWS; |
752 |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "IDENTIFY $NICK" ); |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "IDENTIFY $NICK" ); |
753 |
}, |
}, |
754 |
irc_public => sub { |
irc_public => sub { |
779 |
|
|
780 |
}, |
}, |
781 |
irc_ping => sub { |
irc_ping => sub { |
782 |
warn "pong ", $_[ARG0], $/; |
_log( "pong ", $_[ARG0] ); |
783 |
$ping->{ $_[ARG0] }++; |
$ping->{ $_[ARG0] }++; |
784 |
|
rss_check_updates( $_[KERNEL] ); |
785 |
}, |
}, |
786 |
irc_invite => sub { |
irc_invite => sub { |
787 |
my $kernel = $_[KERNEL]; |
my $kernel = $_[KERNEL]; |
788 |
my $nick = (split /!/, $_[ARG0])[0]; |
my $nick = (split /!/, $_[ARG0])[0]; |
789 |
my $channel = $_[ARG1]; |
my $channel = $_[ARG1]; |
790 |
|
|
791 |
warn "invited to $channel by $nick"; |
_log "invited to $channel by $nick"; |
792 |
|
|
793 |
$_[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..." ); |
794 |
$_[KERNEL]->post($IRC_ALIAS => join => $channel); |
$_[KERNEL]->post($IRC_ALIAS => join => $channel); |
928 |
$res = "config option $op doesn't exist"; |
$res = "config option $op doesn't exist"; |
929 |
} |
} |
930 |
} |
} |
931 |
|
} elsif ($msg =~ m/^rss-update/) { |
932 |
|
$res = rss_fetch_all( $_[KERNEL] ); |
933 |
|
} elsif ($msg =~ m/^rss-clean/) { |
934 |
|
$_rss = undef; |
935 |
|
$res = "OK, cleaned RSS cache"; |
936 |
|
} elsif ($msg =~ m!^rss-(add|remove|stop|start)\s+(http://\S+)\s*(.*)!) { |
937 |
|
my $sql = { |
938 |
|
add => qq{ insert into feeds (url,name) values (?,?) }, |
939 |
|
# remove => qq{ delete from feeds where url = ? and name = ? }, |
940 |
|
start => qq{ update feeds set active = true where url = ? -- ? }, |
941 |
|
stop => qq{ update feeds set active = false where url = ? -- ? }, |
942 |
|
|
943 |
|
}; |
944 |
|
if (my $q = $sql->{$1} ) { |
945 |
|
my $sth = $dbh->prepare( $q ); |
946 |
|
warn "## SQL $q ( $2 | $3 )\n"; |
947 |
|
eval { $sth->execute( $2, $3 ) }; |
948 |
|
} |
949 |
|
|
950 |
|
$res ||= "OK, RSS $1 : $2 - $3"; |
951 |
} |
} |
952 |
|
|
953 |
if ($res) { |
if ($res) { |
956 |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res ); |
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res ); |
957 |
} |
} |
958 |
|
|
959 |
|
rss_check_updates( $_[KERNEL] ); |
960 |
}, |
}, |
961 |
irc_477 => sub { |
irc_477 => sub { |
962 |
_log "# irc_477: ",$_[ARG1]; |
_log "# irc_477: ",$_[ARG1]; |
1007 |
Filename => $FOLLOWS{$trailing}, |
Filename => $FOLLOWS{$trailing}, |
1008 |
InputEvent => 'got_line', |
InputEvent => 'got_line', |
1009 |
); |
); |
1010 |
|
warn "+++ following $trailing at $FOLLOWS{$trailing}\n"; |
1011 |
}, |
}, |
1012 |
got_line => sub { |
got_line => sub { |
1013 |
$_[KERNEL]->post($session => my_tailed => |
warn "+++ $trailing : $_[ARG0]\n"; |
1014 |
time, $trailing, $_[ARG0]); |
$_[KERNEL]->post($session => my_tailed => time, $trailing, $_[ARG0]); |
1015 |
}, |
}, |
1016 |
}, |
}, |
1017 |
); |
); |
1063 |
|
|
1064 |
my $httpd = POE::Component::Server::HTTP->new( |
my $httpd = POE::Component::Server::HTTP->new( |
1065 |
Port => $http_port, |
Port => $http_port, |
1066 |
|
PreHandler => { |
1067 |
|
'/' => sub { |
1068 |
|
$_[0]->header(Connection => 'close') |
1069 |
|
} |
1070 |
|
}, |
1071 |
ContentHandler => { '/' => \&root_handler }, |
ContentHandler => { '/' => \&root_handler }, |
1072 |
Headers => { Server => 'irc-logger' }, |
Headers => { Server => 'irc-logger' }, |
1073 |
); |
); |
1113 |
my ($request, $response) = @_; |
my ($request, $response) = @_; |
1114 |
$response->code(RC_OK); |
$response->code(RC_OK); |
1115 |
|
|
1116 |
|
# this doesn't seem to work, so moved to PreHandler |
1117 |
|
#$response->header(Connection => 'close'); |
1118 |
|
|
1119 |
|
return RC_OK if $request->uri =~ m/favicon.ico$/; |
1120 |
|
|
1121 |
my $q; |
my $q; |
1122 |
|
|
1123 |
if ( $request->method eq 'POST' ) { |
if ( $request->method eq 'POST' ) { |
1130 |
|
|
1131 |
my $search = $q->param('search') || $q->param('grep') || ''; |
my $search = $q->param('search') || $q->param('grep') || ''; |
1132 |
|
|
1133 |
if ($request->url =~ m#/rss#i) { |
if ($request->url =~ m#/rss(?:/(tags|last-tag|follow.*)\w*(?:=(\d+))?)?#i) { |
1134 |
|
my $show = lc($1); |
1135 |
|
my $nr = $2; |
1136 |
|
|
1137 |
my $type = 'RSS'; # Atom |
my $type = 'RSS'; # Atom |
|
my $url = "http://$http_hostname:$http_port"; |
|
1138 |
|
|
1139 |
$response->content_type("application/$type+xml"); |
$response->content_type( 'application/' . lc($type) . '+xml' ); |
1140 |
|
|
1141 |
my $html = '<!-- error -->'; |
my $html = '<!-- error -->'; |
1142 |
warn "create $type feed from ",dump( @last_tags ); |
#warn "create $type feed from ",dump( @last_tags ); |
1143 |
|
|
1144 |
my $feed = XML::Feed->new( $type ); |
my $feed = XML::Feed->new( $type ); |
1145 |
|
$feed->link( $url ); |
1146 |
|
|
1147 |
$feed->title( "last $last_x_tags from $CHANNEL" ); |
if ( $show eq 'tags' ) { |
1148 |
$feed->link( "http://$http_hostname:$http_port" ); |
$nr ||= 50; |
1149 |
$feed->description( "collects messages which have tags// in them" ); |
$feed->title( "tags from $CHANNEL" ); |
1150 |
|
$feed->link( "$url/tags" ); |
1151 |
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}} ); |
|
1152 |
my $feed_entry = XML::Feed::Entry->new($type); |
my $feed_entry = XML::Feed::Entry->new($type); |
1153 |
$feed_entry->title( $m->{nick} . '@' . $m->{time} ); |
$feed_entry->title( "$nr tags from $CHANNEL" ); |
1154 |
$feed_entry->author( $m->{nick} ); |
$feed_entry->author( $NICK ); |
1155 |
# $feed_entry->link( ); |
$feed_entry->link( '/#tags' ); |
1156 |
$feed_entry->issued( DateTime::Format::Flexible->build( $m->{time} ) ); |
|
1157 |
$feed_entry->summary( |
$feed_entry->content( |
1158 |
'<![CDATA[' . |
qq{<![CDATA[<style type="text/css">} |
1159 |
# $filter->{nick}->( $m->{nick} ) . |
. $cloud->css |
1160 |
# '<tt>' . $m->{nick} . '</tt> ' . |
. qq{</style>} |
1161 |
$filter->{message}->( $m->{message} ) . |
. $cloud->html( $nr ) |
1162 |
']]>' |
. qq{]]>} |
1163 |
); |
); |
|
$feed_entry->category( join(', ', @{$m->{tags}}) ); |
|
1164 |
$feed->add_entry( $feed_entry ); |
$feed->add_entry( $feed_entry ); |
1165 |
|
|
1166 |
|
} elsif ( $show eq 'last-tag' ) { |
1167 |
|
|
1168 |
|
$nr ||= $last_x_tags; |
1169 |
|
$nr = $last_x_tags if $nr > $last_x_tags; |
1170 |
|
|
1171 |
|
$feed->title( "last $nr tagged messages from $CHANNEL" ); |
1172 |
|
$feed->description( "collects messages which have tags// in them" ); |
1173 |
|
|
1174 |
|
foreach my $m ( @last_tags ) { |
1175 |
|
# warn dump( $m ); |
1176 |
|
#my $tags = join(' ', @{$m->{tags}} ); |
1177 |
|
my $feed_entry = XML::Feed::Entry->new($type); |
1178 |
|
$feed_entry->title( $m->{nick} . '@' . $m->{time} ); |
1179 |
|
$feed_entry->author( $m->{nick} ); |
1180 |
|
$feed_entry->link( '/#' . $m->{id} ); |
1181 |
|
$feed_entry->issued( DateTime::Format::Flexible->build( $m->{time} ) ); |
1182 |
|
|
1183 |
|
my $message = $filter->{message}->( $m->{message} ); |
1184 |
|
$message .= "<br/>\n" unless $message =~ m!<(/p|br/?)>!; |
1185 |
|
# warn "## message = $message\n"; |
1186 |
|
from_to( $message, $ENCODING, 'UTF-8' ); |
1187 |
|
|
1188 |
|
#$feed_entry->summary( |
1189 |
|
$feed_entry->content( |
1190 |
|
"<![CDATA[$message]]>" |
1191 |
|
); |
1192 |
|
$feed_entry->category( join(', ', @{$m->{tags}}) ); |
1193 |
|
$feed->add_entry( $feed_entry ); |
1194 |
|
|
1195 |
|
$nr--; |
1196 |
|
last if $nr <= 0; |
1197 |
|
|
1198 |
|
} |
1199 |
|
|
1200 |
|
} elsif ( $show =~ m/^follow/ ) { |
1201 |
|
|
1202 |
|
$feed->title( "Feeds which this bot follows" ); |
1203 |
|
|
1204 |
|
my $sth = $dbh->prepare( qq{ select * from feeds order by last_update desc } ); |
1205 |
|
$sth->execute; |
1206 |
|
while (my $row = $sth->fetchrow_hashref) { |
1207 |
|
my $feed_entry = XML::Feed::Entry->new($type); |
1208 |
|
$feed_entry->title( $row->{name} ); |
1209 |
|
$feed_entry->link( $row->{url} ); |
1210 |
|
$feed_entry->issued( DateTime::Format::Flexible->build( $row->{last_update} ) ); |
1211 |
|
$feed_entry->content( |
1212 |
|
'<![CDATA[<pre>' . dump( $row ) . '</pre>]]>' |
1213 |
|
); |
1214 |
|
$feed->add_entry( $feed_entry ); |
1215 |
|
} |
1216 |
|
|
1217 |
|
} else { |
1218 |
|
_log "unknown rss request ",$request->url; |
1219 |
|
return RC_DENY; |
1220 |
} |
} |
1221 |
|
|
1222 |
$response->content( $feed->as_xml ); |
$response->content( $feed->as_xml ); |
1230 |
$response->content_type("text/html; charset=$ENCODING"); |
$response->content_type("text/html; charset=$ENCODING"); |
1231 |
|
|
1232 |
my $html = |
my $html = |
1233 |
qq{<html><head><title>$NICK</title><style type="text/css">$style} . |
qq{<html><head><title>$NICK</title><style type="text/css">$style} |
1234 |
$cloud->css . |
. $cloud->css |
1235 |
qq{</style></head><body>} . |
. qq{</style></head><body>} |
1236 |
qq{ |
. qq{ |
1237 |
<form method="post" class="search" action="/"> |
<form method="post" class="search" action="/"> |
1238 |
<input type="text" name="search" value="$search" size="10"> |
<input type="text" name="search" value="$search" size="10"> |
1239 |
<input type="submit" value="search"> |
<input type="submit" value="search"> |
1240 |
</form> |
</form> |
1241 |
} . |
} |
1242 |
$cloud->html(500) . |
. $cloud->html(500) |
1243 |
qq{<p>}; |
. qq{<p>}; |
1244 |
if ($request->url =~ m#/history#) { |
|
1245 |
|
if ($request->url =~ m#/tags?#) { |
1246 |
|
# nop |
1247 |
|
} elsif ($request->url =~ m#/history#) { |
1248 |
my $sth = $dbh->prepare(qq{ |
my $sth = $dbh->prepare(qq{ |
1249 |
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 |
1250 |
from log |
from log |
1276 |
$cal->weekdays('MON','TUE','WED','THU','FRI'); |
$cal->weekdays('MON','TUE','WED','THU','FRI'); |
1277 |
($l_yyyy,$l_mm) = ($yyyy,$mm); |
($l_yyyy,$l_mm) = ($yyyy,$mm); |
1278 |
} |
} |
1279 |
$cal->setcontent($dd, qq{ |
$cal->setcontent($dd, qq[ |
1280 |
<a href="/?date=$row->{date}">$row->{nr}</a><br/>$row->{len} |
<a href="$url?date=$row->{date}">$row->{nr}</a><br/>$row->{len} |
1281 |
}); |
]); |
1282 |
|
|
1283 |
} |
} |
1284 |
$html .= qq{<td valign="top">} . $cal->as_HTML() . qq{</td></tr></table>}; |
$html .= qq{<td valign="top">} . $cal->as_HTML() . qq{</td></tr></table>}; |
1293 |
fmt => { |
fmt => { |
1294 |
date => sub { |
date => sub { |
1295 |
my $date = shift || return; |
my $date = shift || return; |
1296 |
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>}; |
1297 |
}, |
}, |
1298 |
time => '<span class="time">%s</span> ', |
time => '<span class="time">%s</span> ', |
1299 |
time_channel => '<span class="channel">%s %s</span> ', |
time_channel => '<span class="channel">%s %s</span> ', |
1312 |
</body></html>}; |
</body></html>}; |
1313 |
|
|
1314 |
$response->content( $html ); |
$response->content( $html ); |
1315 |
|
warn "<< ", $request->method, " ", $request->uri, " created ", length($html), " bytes\n"; |
1316 |
return RC_OK; |
return RC_OK; |
1317 |
} |
} |
1318 |
|
|