/[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 15 by dpavlin, Mon Mar 13 12:56:26 2006 UTC revision 16 by dpavlin, Mon Mar 13 16:43:18 2006 UTC
# Line 18  log all conversation on irc channel Line 18  log all conversation on irc channel
18    
19  ## CONFIG  ## CONFIG
20    
21  my $NICK = 'irc-logger';  my $NICK = 'irc-logger-dev';
22  my $CONNECT =  my $CONNECT =
23    {Server => 'irc.freenode.net',    {Server => 'irc.freenode.net',
24     Nick => $NICK,     Nick => $NICK,
# Line 46  use HTTP::Status; Line 46  use HTTP::Status;
46  use DBI;  use DBI;
47  use Encode qw/from_to/;  use Encode qw/from_to/;
48  use Regexp::Common qw /URI/;  use Regexp::Common qw /URI/;
49    use CGI::Simple;
50    
51    
52  my $dbh = DBI->connect($DSN,"","", { RaiseError => 1, AutoCommit => 1 }) || die $DBI::errstr;  my $dbh = DBI->connect($DSN,"","", { RaiseError => 1, AutoCommit => 1 }) || die $DBI::errstr;
# Line 122  sub get_from_log { Line 123  sub get_from_log {
123    
124          my $sth = $dbh->prepare( $sql );          my $sth = $dbh->prepare( $sql );
125          if ($args->{search}) {          if ($args->{search}) {
126                  $sth->execute( $args->{search} );                  warn "search for '$args->{search}' returned ", $sth->rows, " results\n";
127                    $sth->execute( '%' . $args->{search} . '%' );
128          } else {          } else {
129                  $sth->execute();                  $sth->execute();
130          }          }
# Line 139  sub get_from_log { Line 141  sub get_from_log {
141                  unshift @rows, $row;                  unshift @rows, $row;
142          }          }
143    
144          my @msgs;          my @msgs = (
145                    "Showing " . ($#rows + 1) . " messages..."
146            );
147    
148          foreach my $row (@rows) {          foreach my $row (@rows) {
149    
# Line 265  POE::Session->create Line 269  POE::Session->create
269    
270                          my $what = $2;                          my $what = $2;
271    
272                          foreach my $res (get_from_log( limit => 20, search => "%${what}%" )) {                          foreach my $res (get_from_log( limit => 20, search => $what )) {
273                                  print "search [$what]: $res\n";                                  print "search [$what]: $res\n";
274                                  from_to($res, $ENCODING, 'UTF-8');                                  from_to($res, $ENCODING, 'UTF-8');
275                                  $_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res );                                  $_[KERNEL]->post( $IRC_ALIAS => privmsg => $nick, $res );
# Line 399  my $httpd = POE::Component::Server::HTTP Line 403  my $httpd = POE::Component::Server::HTTP
403  );  );
404    
405  my $style = <<'_END_OF_STYLE_';  my $style = <<'_END_OF_STYLE_';
406    p { margin: 0; padding: 0.1em; }
407  .time, .channel { color: #808080; font-size: 60%; }  .time, .channel { color: #808080; font-size: 60%; }
408  .nick { color: #0000ff; font-size: 80%; }  .nick { color: #0000ff; font-size: 80%; }
409  .message { color: #000000; font-size: 100%; }  .message { color: #000000; font-size: 100%; }
410    .search { float: right; }
411  _END_OF_STYLE_  _END_OF_STYLE_
412    
413  sub root_handler {  sub root_handler {
414          my ($request, $response) = @_;          my ($request, $response) = @_;
415          $response->code(RC_OK);          $response->code(RC_OK);
416          $response->content_type("text/html; charset=$ENCODING");          $response->content_type("text/html; charset=$ENCODING");
417    
418            my $q;
419    
420            if ( $request->method eq 'POST' ) {
421                    $q = new CGI::Simple( $request->content );
422            } elsif ( $request->uri =~ /\?(.+)$/ ) {
423                    $q = new CGI::Simple( $1 );
424            } else {
425                    $q = new CGI::Simple;
426            }
427    
428            my $search = $q->param('search') || $q->param('grep') || '';
429    
430          $response->content(          $response->content(
431                  qq{<html><head><title>$NICK</title><style type="text/css">$style</style></head><body>} .                  qq{<html><head><title>$NICK</title><style type="text/css">$style</style></head><body>
432                  "irc-logger url: " . $request->uri . '<br/>' .                  <form method="post" class="search">
433                  join("<br/>",                  <input type="text" name="search" value="$search" size="10">
434                    <input type="submit" value="search">
435                    </form>
436                    <p>
437                    } .
438                    join("</p><p>",
439                          get_from_log(                          get_from_log(
440                                  limit => 100,                                  limit => $q->param('limit') || 100,
441                                    search => $q->param('search') || $q->param('grep') || undef,
442                                  fmt => {                                  fmt => {
443                                          time => '<span class="time">%s</span> ',                                          time => '<span class="time">%s</span> ',
444                                          time_channel => '<span class="channel">%s %s</span> ',                                          time_channel => '<span class="channel">%s %s</span> ',
# Line 427  sub root_handler { Line 452  sub root_handler {
452                                  },                                  },
453                          )                          )
454                  ) .                  ) .
455                  qq{</body></html>}                  qq{</p></body></html>}
456          );          );
457          return RC_OK;          return RC_OK;
458  }  }

Legend:
Removed from v.15  
changed lines
  Added in v.16

  ViewVC Help
Powered by ViewVC 1.1.26