20 |
|
|
21 |
=item --log=irc-logger.log |
=item --log=irc-logger.log |
22 |
|
|
|
Name of log file |
|
|
|
|
|
=item --follow=file.log |
|
|
|
|
|
Follows new messages in file |
|
|
|
|
23 |
=back |
=back |
24 |
|
|
25 |
=head1 DESCRIPTION |
=head1 DESCRIPTION |
44 |
$CHANNEL = '#irc-logger' if ($HOSTNAME =~ m/llin/); |
$CHANNEL = '#irc-logger' if ($HOSTNAME =~ m/llin/); |
45 |
my $IRC_ALIAS = "log"; |
my $IRC_ALIAS = "log"; |
46 |
|
|
|
# default log to follow and announce messages |
|
|
my $follows_path = 'follows.log'; |
|
|
|
|
47 |
my $DSN = 'DBI:Pg:dbname=' . $NICK; |
my $DSN = 'DBI:Pg:dbname=' . $NICK; |
48 |
|
|
|
# log output encoding |
|
|
my $ENCODING = 'ISO-8859-2'; |
|
49 |
my $TIMESTAMP = '%Y-%m-%d %H:%M:%S'; |
my $TIMESTAMP = '%Y-%m-%d %H:%M:%S'; |
50 |
|
|
51 |
my $sleep_on_error = 5; |
my $sleep_on_error = 5; |
63 |
|
|
64 |
## END CONFIG |
## END CONFIG |
65 |
|
|
66 |
use POE qw(Component::IRC Wheel::FollowTail Component::Server::HTTP); |
use POE qw(Component::IRC Component::Server::HTTP); |
67 |
use HTTP::Status; |
use HTTP::Status; |
68 |
use DBI; |
use DBI; |
|
use Encode qw/from_to is_utf8/; |
|
69 |
use Regexp::Common qw /URI/; |
use Regexp::Common qw /URI/; |
70 |
use CGI::Simple; |
use CGI::Simple; |
71 |
use HTML::TagCloud; |
use HTML::TagCloud; |
88 |
my $log_path; |
my $log_path; |
89 |
GetOptions( |
GetOptions( |
90 |
'import-dircproxy:s' => \$import_dircproxy, |
'import-dircproxy:s' => \$import_dircproxy, |
|
'follows:s' => \$follows_path, |
|
91 |
'log:s' => \$log_path, |
'log:s' => \$log_path, |
92 |
); |
); |
93 |
|
|
98 |
open(STDOUT, '>', $log_path) || warn "can't redirect log to $log_path: $!"; |
open(STDOUT, '>', $log_path) || warn "can't redirect log to $log_path: $!"; |
99 |
|
|
100 |
sub _log { |
sub _log { |
101 |
my $out = strftime($TIMESTAMP,localtime()) . ' ' . join(" ",@_) . $/; |
print strftime($TIMESTAMP,localtime()) . ' ' . join(" ",@_) . $/; |
|
from_to( $out, 'UTF-8', $ENCODING ); |
|
|
print $out; |
|
|
} |
|
|
|
|
|
# LOG following |
|
|
|
|
|
my %FOLLOWS = |
|
|
( |
|
|
# ACCESS => "/var/log/apache/access.log", |
|
|
# ERROR => "/var/log/apache/error.log", |
|
|
); |
|
|
|
|
|
sub add_follow_path { |
|
|
my $path = shift; |
|
|
my $name = $path; |
|
|
$name =~ s/\..*$//; |
|
|
warn "# using $path to announce messages from $name\n"; |
|
|
$FOLLOWS{$name} = $path; |
|
102 |
} |
} |
103 |
|
|
|
add_follow_path( $follows_path ) if ( -e $follows_path ); |
|
|
|
|
104 |
# HTML formatters |
# HTML formatters |
105 |
|
|
106 |
my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); |
my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); |
144 |
}; |
}; |
145 |
|
|
146 |
my $dbh = DBI->connect($DSN,"","", { RaiseError => 1, AutoCommit => 1 }) || die $DBI::errstr; |
my $dbh = DBI->connect($DSN,"","", { RaiseError => 1, AutoCommit => 1 }) || die $DBI::errstr; |
147 |
|
$dbh->do( qq{ set client_encoding = 'UTF-8' } ); |
148 |
|
|
149 |
my $sql_schema = { |
my $sql_schema = { |
150 |
log => qq{ |
log => qq{ |
501 |
return unless ($arg->{id} && $arg->{message}); |
return unless ($arg->{id} && $arg->{message}); |
502 |
|
|
503 |
my $m = $arg->{message}; |
my $m = $arg->{message}; |
|
from_to('UTF-8', 'iso-8859-2', $m) if (is_utf8($m)); |
|
504 |
|
|
505 |
my @tags; |
my @tags; |
506 |
|
|
628 |
_log("can't fetch RSS ", $args->{url}); |
_log("can't fetch RSS ", $args->{url}); |
629 |
return; |
return; |
630 |
} |
} |
631 |
|
|
632 |
my ( $total, $updates ) = ( 0, 0 ); |
my ( $total, $updates ) = ( 0, 0 ); |
633 |
for my $entry ($feed->entries) { |
for my $entry ($feed->entries) { |
634 |
$total++; |
$total++; |
635 |
|
|
636 |
# seen allready? |
# seen allready? |
637 |
return if $_rss->{$feed->link}->{seen}->{$entry->id}++ > 0; |
next if $_rss->{$feed->link}->{seen}->{$entry->id}++ > 0; |
638 |
|
|
639 |
sub prefix { |
sub prefix { |
640 |
my ($txt,$var) = @_; |
my ($txt,$var) = @_; |
641 |
|
$var =~ s/\s+/ /gs; |
642 |
$var =~ s/^\s+//g; |
$var =~ s/^\s+//g; |
643 |
|
$var =~ s/\s+$//g; |
644 |
return $txt . $var if $var; |
return $txt . $var if $var; |
645 |
} |
} |
646 |
|
|
647 |
my $msg; |
my $msg; |
648 |
$msg .= prefix( 'From: ' , $feed->title ); |
$msg .= prefix( 'From: ' , $args->{name} || $feed->title ); |
649 |
$msg .= prefix( ' by ' , $entry->author ); |
$msg .= prefix( ' by ' , $entry->author ); |
650 |
$msg .= prefix( ' -- ' , $entry->link ); |
$msg .= prefix( ' | ' , $entry->title ); |
651 |
|
$msg .= prefix( ' | ' , $entry->link ); |
652 |
# $msg .= prefix( ' id ' , $entry->id ); |
# $msg .= prefix( ' id ' , $entry->id ); |
653 |
|
|
654 |
if ( $args->{kernel} && $send_rss_msgs ) { |
if ( $args->{kernel} && $send_rss_msgs ) { |
|
warn "# sending to $CHANNEL\n"; |
|
655 |
$send_rss_msgs--; |
$send_rss_msgs--; |
656 |
|
_log('>>', $msg); |
657 |
|
$sth_insert_log->execute( $CHANNEL, 1, $NICK, $msg, 'now()' ); |
658 |
$args->{kernel}->post( $IRC_ALIAS => notice => $CHANNEL, $msg ); |
$args->{kernel}->post( $IRC_ALIAS => notice => $CHANNEL, $msg ); |
659 |
$updates++; |
$updates++; |
|
#$sth_insert_log->execute( $CHANNEL, 1, $NICK, $msg, undef ); |
|
|
_log('RSS', $msg); |
|
660 |
} |
} |
661 |
} |
} |
662 |
|
|
695 |
my $kernel = shift; |
my $kernel = shift; |
696 |
my $last_t = $_rss->{last_poll} || time(); |
my $last_t = $_rss->{last_poll} || time(); |
697 |
my $t = time(); |
my $t = time(); |
698 |
if ( $last_t - $t > $rss_min_delay ) { |
if ( $t - $last_t > $rss_min_delay ) { |
699 |
$_rss->{last_poll} = $t; |
$_rss->{last_poll} = $t; |
700 |
_log rss_fetch_all( $kernel ); |
_log rss_fetch_all( $kernel ); |
701 |
} |
} |
708 |
# POE handing part |
# POE handing part |
709 |
# |
# |
710 |
|
|
|
my $SKIPPING = 0; # if skipping, how many we've done |
|
|
my $SEND_QUEUE; # cache |
|
711 |
my $ping; # ping stats |
my $ping; # ping stats |
712 |
|
|
713 |
POE::Component::IRC->new($IRC_ALIAS); |
POE::Component::IRC->new($IRC_ALIAS); |
899 |
$res = rss_fetch_all( $_[KERNEL] ); |
$res = rss_fetch_all( $_[KERNEL] ); |
900 |
} elsif ($msg =~ m/^rss-clean/) { |
} elsif ($msg =~ m/^rss-clean/) { |
901 |
$_rss = undef; |
$_rss = undef; |
902 |
|
$dbh->do( qq{ update feeds set last_update = now() - delay } ); |
903 |
$res = "OK, cleaned RSS cache"; |
$res = "OK, cleaned RSS cache"; |
904 |
|
} elsif ($msg =~ m/^rss-list/) { |
905 |
|
my $sth = $dbh->prepare(qq{ select url,name,last_update,active from feeds }); |
906 |
|
$sth->execute; |
907 |
|
while (my @row = $sth->fetchrow_array) { |
908 |
|
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, join(' | ',@row) ); |
909 |
|
} |
910 |
|
$res = ''; |
911 |
} elsif ($msg =~ m!^rss-(add|remove|stop|start)\s+(http://\S+)\s*(.*)!) { |
} elsif ($msg =~ m!^rss-(add|remove|stop|start)\s+(http://\S+)\s*(.*)!) { |
912 |
my $sql = { |
my $sql = { |
913 |
add => qq{ insert into feeds (url,name) values (?,?) }, |
add => qq{ insert into feeds (url,name) values (?,?) }, |
914 |
# remove => qq{ delete from feeds where url = ? and name = ? }, |
# remove => qq{ delete from feeds where url = ? and name = ? }, |
915 |
start => qq{ update feeds set active = true where url = ? -- ? }, |
start => qq{ update feeds set active = true where url = ? }, |
916 |
stop => qq{ update feeds set active = false where url = ? -- ? }, |
stop => qq{ update feeds set active = false where url = ? }, |
917 |
|
|
918 |
}; |
}; |
919 |
if (my $q = $sql->{$1} ) { |
if (my $q = $sql->{$1} ) { |
920 |
my $sth = $dbh->prepare( $q ); |
my $sth = $dbh->prepare( $q ); |
921 |
warn "## SQL $q ( $2 | $3 )\n"; |
my @data = ( $2 ); |
922 |
eval { $sth->execute( $2, $3 ) }; |
push @data, $3 if ( $q =~ s/\?//g == 2 ); |
923 |
|
warn "## $1 SQL $q with ",dump( @data ),"\n"; |
924 |
|
eval { $sth->execute( @data ) }; |
925 |
} |
} |
926 |
|
|
927 |
$res ||= "OK, RSS $1 : $2 - $3"; |
$res = "OK, RSS $1 : $2 - $3"; |
928 |
} |
} |
929 |
|
|
930 |
if ($res) { |
if ($res) { |
1192 |
} |
} |
1193 |
$cal->setcontent($dd, qq[ |
$cal->setcontent($dd, qq[ |
1194 |
<a href="$url?date=$row->{date}">$row->{nr}</a><br/>$row->{len} |
<a href="$url?date=$row->{date}">$row->{nr}</a><br/>$row->{len} |
1195 |
]); |
]) if $cal; |
1196 |
|
|
1197 |
} |
} |
1198 |
$html .= qq{<td valign="top">} . $cal->as_HTML() . qq{</td></tr></table>}; |
$html .= qq{<td valign="top">} . $cal->as_HTML() . qq{</td></tr></table>}; |