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 |
|
|
49 |
my $TIMESTAMP = '%Y-%m-%d %H:%M:%S'; |
my $TIMESTAMP = '%Y-%m-%d %H:%M:%S'; |
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; |
69 |
use Regexp::Common qw /URI/; |
use Regexp::Common qw /URI/; |
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 |
|
|
101 |
print strftime($TIMESTAMP,localtime()) . ' ' . join(" ",@_) . $/; |
print strftime($TIMESTAMP,localtime()) . ' ' . join(" ",@_) . $/; |
102 |
} |
} |
103 |
|
|
|
# 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; |
|
|
} |
|
|
|
|
|
add_follow_path( $follows_path ) if ( -e $follows_path ); |
|
|
|
|
104 |
# HTML formatters |
# HTML formatters |
105 |
|
|
106 |
my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); |
my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); |
642 |
} |
} |
643 |
|
|
644 |
my $msg; |
my $msg; |
645 |
$msg .= prefix( 'From: ' , $feed->title ); |
$msg .= prefix( 'From: ' , $args->{name} || $feed->title ); |
646 |
$msg .= prefix( ' by ' , $entry->author ); |
$msg .= prefix( ' by ' , $entry->author ); |
647 |
$msg .= prefix( ' -- ' , $entry->link ); |
$msg .= prefix( ' -- ' , $entry->link ); |
648 |
# $msg .= prefix( ' id ' , $entry->id ); |
# $msg .= prefix( ' id ' , $entry->id ); |
691 |
my $kernel = shift; |
my $kernel = shift; |
692 |
my $last_t = $_rss->{last_poll} || time(); |
my $last_t = $_rss->{last_poll} || time(); |
693 |
my $t = time(); |
my $t = time(); |
694 |
if ( $last_t - $t > $rss_min_delay ) { |
if ( $t - $last_t > $rss_min_delay ) { |
695 |
$_rss->{last_poll} = $t; |
$_rss->{last_poll} = $t; |
696 |
_log rss_fetch_all( $kernel ); |
_log rss_fetch_all( $kernel ); |
697 |
} |
} |
704 |
# POE handing part |
# POE handing part |
705 |
# |
# |
706 |
|
|
|
my $SKIPPING = 0; # if skipping, how many we've done |
|
|
my $SEND_QUEUE; # cache |
|
707 |
my $ping; # ping stats |
my $ping; # ping stats |
708 |
|
|
709 |
POE::Component::IRC->new($IRC_ALIAS); |
POE::Component::IRC->new($IRC_ALIAS); |
895 |
$res = rss_fetch_all( $_[KERNEL] ); |
$res = rss_fetch_all( $_[KERNEL] ); |
896 |
} elsif ($msg =~ m/^rss-clean/) { |
} elsif ($msg =~ m/^rss-clean/) { |
897 |
$_rss = undef; |
$_rss = undef; |
898 |
|
$dbh->do( qq{ update feeds set last_update = now() - delay } ); |
899 |
$res = "OK, cleaned RSS cache"; |
$res = "OK, cleaned RSS cache"; |
900 |
|
} elsif ($msg =~ m/^rss-list/) { |
901 |
|
my $sth = $dbh->prepare(qq{ select url,name,last_update,active from feeds }); |
902 |
|
$sth->execute; |
903 |
|
while (my @row = $sth->fetchrow_array) { |
904 |
|
$_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, join(' | ',@row) ); |
905 |
|
} |
906 |
|
$res = ''; |
907 |
} elsif ($msg =~ m!^rss-(add|remove|stop|start)\s+(http://\S+)\s*(.*)!) { |
} elsif ($msg =~ m!^rss-(add|remove|stop|start)\s+(http://\S+)\s*(.*)!) { |
908 |
my $sql = { |
my $sql = { |
909 |
add => qq{ insert into feeds (url,name) values (?,?) }, |
add => qq{ insert into feeds (url,name) values (?,?) }, |
910 |
# remove => qq{ delete from feeds where url = ? and name = ? }, |
# remove => qq{ delete from feeds where url = ? and name = ? }, |
911 |
start => qq{ update feeds set active = true where url = ? -- ? }, |
start => qq{ update feeds set active = true where url = ? }, |
912 |
stop => qq{ update feeds set active = false where url = ? -- ? }, |
stop => qq{ update feeds set active = false where url = ? }, |
913 |
|
|
914 |
}; |
}; |
915 |
if (my $q = $sql->{$1} ) { |
if (my $q = $sql->{$1} ) { |
916 |
my $sth = $dbh->prepare( $q ); |
my $sth = $dbh->prepare( $q ); |
917 |
warn "## SQL $q ( $2 | $3 )\n"; |
my @data = ( $2 ); |
918 |
eval { $sth->execute( $2, $3 ) }; |
push @data, $3 if ( $q =~ s/\?//g == 2 ); |
919 |
|
warn "## $1 SQL $q with ",dump( @data ),"\n"; |
920 |
|
eval { $sth->execute( @data ) }; |
921 |
} |
} |
922 |
|
|
923 |
$res ||= "OK, RSS $1 : $2 - $3"; |
$res = "OK, RSS $1 : $2 - $3"; |
924 |
} |
} |
925 |
|
|
926 |
if ($res) { |
if ($res) { |