/[irc-logger]/trunk/bin/irc-logger.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/bin/irc-logger.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 78 by dpavlin, Wed Feb 20 19:37:34 2008 UTC revision 84 by dpavlin, Thu Mar 6 18:03:05 2008 UTC
# Line 22  Import log from C<dircproxy> to C<irc-lo Line 22  Import log from C<dircproxy> to C<irc-lo
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
# Line 46  my $CHANNEL = '#razmjenavjestina'; Line 50  my $CHANNEL = '#razmjenavjestina';
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    
# Line 59  my $TIMESTAMP = '%Y-%m-%d %H:%M:%S'; Line 60  my $TIMESTAMP = '%Y-%m-%d %H:%M:%S';
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";
# Line 93  my $import_dircproxy; Line 97  my $import_dircproxy;
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    
# Line 106  sub _log { Line 111  sub _log {
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 = ('<'=>'&lt;', '>'=>'&gt;', '&'=>'&amp;', '"'=>'&quot;');  my %escape = ('<'=>'&lt;', '>'=>'&gt;', '&'=>'&amp;', '"'=>'&quot;');
# Line 483  my $cloud = HTML::TagCloud->new; Line 506  my $cloud = HTML::TagCloud->new;
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 {
# Line 622  POE::Session->create( inline_states => Line 644  POE::Session->create( inline_states =>
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 {
# Line 653  POE::Session->create( inline_states => Line 675  POE::Session->create( inline_states =>
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 {
# Line 859  POE::Session->create( inline_states => Line 881  POE::Session->create( inline_states =>
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            );            );
# Line 914  POE::Session->create( inline_states => Line 937  POE::Session->create( inline_states =>
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  );  );
# Line 959  sub root_handler { Line 987  sub root_handler {
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;
# Line 973  sub root_handler { Line 1004  sub root_handler {
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(?:/(tags)(?:=(\d+))?)?#i) {          if ($request->url =~ m#/rss(?:/(tags|last-tag)\w*(?:=(\d+))?)?#i) {
1008                  my $show = lc($1);                  my $show = lc($1);
1009                  my $arg = $2 || 50;                  my $nr = $2;
1010    
1011                  my $type = 'RSS';       # Atom                  my $type = 'RSS';       # Atom
1012    
# Line 987  sub root_handler { Line 1018  sub root_handler {
1018                  my $feed = XML::Feed->new( $type );                  my $feed = XML::Feed->new( $type );
1019    
1020                  if ( $show eq 'tags' ) {                  if ( $show eq 'tags' ) {
1021                            $nr ||= 50;
1022                          $feed->title( "tags from $CHANNEL" );                          $feed->title( "tags from $CHANNEL" );
1023                          $feed->link( "$url/tags" );                          $feed->link( "$url/tags" );
1024                          $feed->description( "tag cloud created from messages on channel $CHANNEL which have tags// in them" );                          $feed->description( "tag cloud created from messages on channel $CHANNEL which have tags// in them" );
1025                          my $feed_entry = XML::Feed::Entry->new($type);                          my $feed_entry = XML::Feed::Entry->new($type);
1026                          $feed_entry->title( "$arg tags from $CHANNEL" );                          $feed_entry->title( "$nr tags from $CHANNEL" );
1027                          $feed_entry->author( $NICK );                          $feed_entry->author( $NICK );
1028                          $feed_entry->link( '/#tags'  );                          $feed_entry->link( '/#tags'  );
1029    
# Line 999  sub root_handler { Line 1031  sub root_handler {
1031                                  qq{<![CDATA[<style type="text/css">}                                  qq{<![CDATA[<style type="text/css">}
1032                                  . $cloud->css                                  . $cloud->css
1033                                  . qq{</style>}                                  . qq{</style>}
1034                                  . $cloud->html( $arg )                                  . $cloud->html( $nr )
1035                                  . qq{]]>}                                  . qq{]]>}
1036                          );                          );
1037                          $feed->add_entry( $feed_entry );                          $feed->add_entry( $feed_entry );
1038    
1039                  } else {                  } elsif ( $show eq 'last-tag' ) {
1040    
1041                          $feed->title( "last $last_x_tags from $CHANNEL" );                          $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 );                          $feed->link( $url );
1046                          $feed->description( "collects messages which have tags// in them" );                          $feed->description( "collects messages which have tags// in them" );
1047    
# Line 1021  sub root_handler { Line 1056  sub root_handler {
1056    
1057                                  my $message = $filter->{message}->( $m->{message} );                                  my $message = $filter->{message}->( $m->{message} );
1058                                  $message .= "<br/>\n" unless $message =~ m!<(/p|br/?)>!;                                  $message .= "<br/>\n" unless $message =~ m!<(/p|br/?)>!;
1059                                  warn "## message = $message\n";  #                               warn "## message = $message\n";
1060                                  from_to( $message, $ENCODING, 'UTF-8' );                                  from_to( $message, $ENCODING, 'UTF-8' );
1061    
1062                                  #$feed_entry->summary(                                  #$feed_entry->summary(
# Line 1030  sub root_handler { Line 1065  sub root_handler {
1065                                  );                                  );
1066                                  $feed_entry->category( join(', ', @{$m->{tags}}) );                                  $feed_entry->category( join(', ', @{$m->{tags}}) );
1067                                  $feed->add_entry( $feed_entry );                                  $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 );
# Line 1090  sub root_handler { Line 1133  sub root_handler {
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>};

Legend:
Removed from v.78  
changed lines
  Added in v.84

  ViewVC Help
Powered by ViewVC 1.1.26