/[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 133 by dpavlin, Sat Apr 5 21:08:27 2008 UTC revision 150 by dpavlin, Sat Oct 8 18:43:21 2011 UTC
# Line 18  use Carp qw/confess/; Line 18  use Carp qw/confess/;
18  use XML::Feed;  use XML::Feed;
19  use DateTime::Format::Flexible;  use DateTime::Format::Flexible;
20  use Encode;  use Encode;
21    #use Redis 2.0;
22    
23  =head1 NAME  =head1 NAME
24    
# Line 139  my $filter = { Line 140  my $filter = {
140                  # protect HTML from wiki modifications                  # protect HTML from wiki modifications
141                  sub e {                  sub e {
142                          my $t = shift;                          my $t = shift;
143                          return 'uri_unescape{' . uri_escape($t, '^a-zA-Z0-9') . '}';                          eval { $t = 'uri_unescape{' . uri_escape($t, '^a-zA-Z0-9') . '}'; };
144                            return $t;
145                  }                  }
146    
147                  $m =~ s/($escape_re)/$escape{$1}/gs;                  $m =~ s/($escape_re)/$escape{$1}/gs;
148                  $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;
149                  $m =~ s#\/(\w+)\/#<i>$1</i>#gs;  #               $m =~ s#\/(\w+)\/#<i>$1</i>#gs;
150                  $m =~ s#$tag_regex#e(qq{<a href="$url?tag=$1" class="tag">$1</a>})#egs;                  $m =~ s#$tag_regex#e(qq{<a href="$url?tag=$1" class="tag">$1</a>})#egs;
151                  $m =~ s#\*(\w+)\*#<b>$1</b>#gs;                  $m =~ s#\*(\w+)\*#<b>$1</b>#gs;
152                  $m =~ s#_(\w+)_#<u>$1</u>#gs;                  $m =~ s#_(\w+)_#<u>$1</u>#gs;
# Line 255  sub meta { Line 257  sub meta {
257    
258                  eval { $sth->execute( $value, $nick, $channel, $name ) };                  eval { $sth->execute( $value, $nick, $channel, $name ) };
259    
260                  # error or no result                  if ( $@ ) {
261                  if ( $@ || ! $sth->rows ) {                          # error
262                            _log("META ERROR: $@");
263                    } elsif ( ! $sth->rows ) {
264                            # no result -> add new
265                          $sth = $dbh->prepare(qq{ insert into meta (value,nick,channel,name,changed) values (?,?,?,?,now()) });                          $sth = $dbh->prepare(qq{ insert into meta (value,nick,channel,name,changed) values (?,?,?,?,now()) });
266                          $sth->execute( $value, $nick, $channel, $name );                          eval { $sth->execute( $value, $nick, $channel, $name ); };
267                          warn "## created $nick/$channel/$name = $value\n";                          if ( $@ ) {
268                                    _log "META ERROR: $@";
269                            } else {
270                                    _log "META: created $nick/$channel/$name = $value\n";
271                            }
272                  } else {                  } else {
273                          warn "## updated $nick/$channel/$name = $value\n";                          _log "META: updated $nick/$channel/$name = $value\n";
274                  }                  }
275    
276                  return $value;                  return $value;
# Line 556  sub save_message { Line 565  sub save_message {
565                  " " . $a->{message};                  " " . $a->{message};
566    
567          eval { $sth_insert_log->execute($a->{channel}, $a->{me}, $a->{nick}, $a->{message}, $a->{time}); };          eval { $sth_insert_log->execute($a->{channel}, $a->{me}, $a->{nick}, $a->{message}, $a->{time}); };
568          _log "ERROR: can't archive ", $a->{message} if $@;  
569          $cloud->add_tag( id => $dbh->last_insert_id(undef,undef,"log",undef), %$a );          eval {
570            my @channel = ( 'channel' , $a->{channel}, $a->{nick} );
571            push @channel, 'me' if $a->{me};
572    #       my $redis = Redis->new( server => '192.168.1.61:6379' );
573    #       $redis->publish( join(' ',@channel), $a->{message} );
574            };
575    
576            if ( $@ ) {
577                    _log "ERROR: can't archive ", $a->{message};
578            } else {
579                    $cloud->add_tag( id => $dbh->last_insert_id(undef,undef,"log",undef), %$a );
580            }
581  }  }
582    
583    
584  if ($import_dircproxy) {  if ($import_dircproxy) {
585            my ( $from_time, $date_time ) = $dbh->selectrow_array(qq{
586                    select date_part('epoch',max(time)),max(time) from log
587            });
588    
589            warn "IMPORT $date_time [$from_time]\n";
590    
591          open(my $l, $import_dircproxy) || die "can't open $import_dircproxy: $!";          open(my $l, $import_dircproxy) || die "can't open $import_dircproxy: $!";
592          warn "importing $import_dircproxy...\n";          warn "importing $import_dircproxy...\n";
593          my $tz_offset = 1 * 60 * 60;    # TZ GMT+2          my $tz_offset = 1 * 60 * 60;    # TZ GMT+2
# Line 570  if ($import_dircproxy) { Line 596  if ($import_dircproxy) {
596                  if (/^@(\d+)\s(\S+)\s(.+)$/) {                  if (/^@(\d+)\s(\S+)\s(.+)$/) {
597                          my ($time, $nick, $msg) = ($1,$2,$3);                          my ($time, $nick, $msg) = ($1,$2,$3);
598    
599                            next if $time <= $from_time;
600    
601                          my $dt = DateTime->from_epoch( epoch => $time + $tz_offset );                          my $dt = DateTime->from_epoch( epoch => $time + $tz_offset );
602    
603                          my $me = 0;                          my $me = 0;
# Line 626  sub rss_parse_xml { Line 654  sub rss_parse_xml {
654    
655          warn "## RSS fetch first $send_rss_msgs items from", $args->{url} if $debug;          warn "## RSS fetch first $send_rss_msgs items from", $args->{url} if $debug;
656    
657          my $feed = XML::Feed->parse( \$args->{xml} );          my $feed;
658            eval { $feed = XML::Feed->parse( \$args->{xml} ) };
659          if ( ! $feed ) {          if ( ! $feed ) {
660                  _log "can't fetch RSS ", $args->{url}, XML::Feed->errstr;                  _log "can't fetch RSS ", $args->{url}, XML::Feed->errstr;
661                  return;                  return;
# Line 1161  sub root_handler { Line 1190  sub root_handler {
1190    
1191          return RC_OK if $request->uri =~ m/favicon.ico$/;          return RC_OK if $request->uri =~ m/favicon.ico$/;
1192    
1193            if ( $request->uri =~ m/robots.txt$/ ) {
1194                    $response->content_type( 'text/plain' );
1195                    $response->content( qq{
1196    
1197    User-Agent: *
1198    Disallow: /
1199    
1200                    });
1201                    return RC_OK;
1202            }
1203    
1204          my $q;          my $q;
1205    
1206          if ( $request->method eq 'POST' ) {          if ( $request->method eq 'POST' ) {
# Line 1283  sub root_handler { Line 1323  sub root_handler {
1323                          $rc = RC_DENY;                          $rc = RC_DENY;
1324                  }                  }
1325    
1326                  $response->content( $feed->as_xml );                  eval { $response->content( $feed->as_xml ); };
1327                    $rc = RC_INTERNAL_SERVER_ERROR if $@;
1328                  return $rc;                  return $rc;
1329          }          }
1330    
# Line 1296  sub root_handler { Line 1337  sub root_handler {
1337          my $html =          my $html =
1338                  qq{<html><head><title>$NICK</title><style type="text/css">$style}                  qq{<html><head><title>$NICK</title><style type="text/css">$style}
1339                  . $cloud->css                  . $cloud->css
1340                  . qq{</style></head><body>}                  . qq{</style>
1341                    <meta name="google-site-verification" content="oe-LvUiNiQRPpc_uB-3rY4MWvFifkmLf276WzAvTL5U" />  
1342                    </head><body>}
1343                  . qq{                  . qq{
1344                  <form method="post" class="search" action="/">                  <form method="post" class="search" action="/">
1345                  <input type="text" name="search" value="$search" size="10">                  <input type="text" name="search" value="$search" size="10">
# Line 1350  sub root_handler { Line 1393  sub root_handler {
1393          } else {          } else {
1394                  $html .= join("</p><p>",                  $html .= join("</p><p>",
1395                          get_from_log(                          get_from_log(
1396                                  limit => ( $q->param('last') || $q->param('date') ) ? undef : 100,                                  limit => ( $q->param('date') ? undef : $q->param('last') || 100 ),
1397                                  search => $search || undef,                                  search => $search || undef,
1398                                  tag => $q->param('tag') || undef,                                  tag => $q->param('tag') || undef,
1399                                  date => $q->param('date') || undef,                                  date => $q->param('date') || undef,
# Line 1375  sub root_handler { Line 1418  sub root_handler {
1418          <p>See <a href="/history">history</a> of all messages.</p>          <p>See <a href="/history">history</a> of all messages.</p>
1419          </body></html>};          </body></html>};
1420    
1421          $response->content( decode('utf-8',$html) );          $response->content( $html );
1422          warn "<< ", $request->method, " ", $request->uri, " created ", length($html), " bytes\n";          warn "<< ", $request->method, " ", $request->uri, " created ", length($html), " bytes\n";
1423          return RC_OK;          return RC_OK;
1424  }  }
# Line 1415  sub html { Line 1458  sub html {
1458          }          }
1459    
1460    my $html = qq{<div id="htmltagcloud">};    my $html = qq{<div id="htmltagcloud">};
1461    foreach my $tag (@tags) {    foreach my $tag ( sort { lc($a->{name}) cmp lc($b->{name}) } @tags) {
1462      $html .=  sprintf(qq{<span class="tag tagcloud%d"><a href="%s" title="%s">%s</a></span>\n},      $html .=  sprintf(qq{<span class="tag tagcloud%d"><a href="%s" title="%s">%s</a></span>\n},
1463                  $tag->{level}, $tag->{url}, $tag->{count}, $tag->{name}                  $tag->{level}, $tag->{url}, $tag->{count}, $tag->{name}
1464          );          );

Legend:
Removed from v.133  
changed lines
  Added in v.150

  ViewVC Help
Powered by ViewVC 1.1.26