#
# http://www.fabiankeil.de/sourcecode/privoxy-log-parser/
#
-# $Id: privoxy-log-parser.pl,v 1.126 2008/11/26 18:05:01 fk Exp $
+# $Id: privoxy-log-parser.pl,v 1.135 2009/02/11 19:12:53 fk Exp $
#
# TODO:
# - LOG_LEVEL_CGI, LOG_LEVEL_ERROR, LOG_LEVEL_WRITE content highlighting
# - Use generic highlighting function that takes a regex and the
# hash key as input.
#
-# Copyright (c) 2007-2008 Fabian Keil <fk@fabiankeil.de>
+# Copyright (c) 2007-2009 Fabian Keil <fk@fabiankeil.de>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
use Getopt::Long;
use constant {
- PRIVOXY_LOG_PARSER_VERSION => '0.4',
+ PRIVOXY_LOG_PARSER_VERSION => '0.5',
# Feel free to mess with these ...
DEFAULT_BACKGROUND => 'black', # Choose registered colour (like 'black')
DEFAULT_TEXT_COLOUR => 'white', # Choose registered colour (like 'black')
CGI => 'light_green',
Redirect => 'cyan',
Error => 'light_red',
+ Crunch => 'cyan',
'Fatal error' => 'light_red',
'Gif-Deanimate' => 'blue',
Force => 'red',
return $colour_code;
}
-
sub get_semantic_html_markup ($) {
###############################################################
# Takes a string and returns a span element
}
}
-
sub get_line_end () {
my $line_end = "\n";
return $code;
}
-
sub default_colours () {
# XXX: Properly
our $bg_code;
return $result;
}
-
sub highlight_matched_path ($$) {
my $result = shift; # XXX: Stupid name;
return $result;
}
-
sub highlight_url ($) {
my $url = shift;
# scan: Accept: image/png,image/*;q=0.8,*/*;q=0.5
if ($c =~ m/^scan: ((?>[^:]+)):/) {
my $header = $1;
- if (!defined($header_colours{$header})) {
+ if (!defined($header_colours{$header}) and $header =~ /^[\d\w-]*$/) {
debug_message "Registering previously unknown header $1" if DEBUG_HEADER_REGISTERING;
if (REGISTER_HEADERS_WITH_THE_SAME_COLOUR) {
return $content;
}
-
sub handle_loglevel_redirect ($) {
my $c = shift;
return $content;
}
-
sub handle_loglevel_request ($) {
my $content = shift;
return $content;
}
+sub handle_loglevel_crunch ($) {
+
+ my $content = shift;
+ our %h;
+ our %reason_colours;
+
+ # Highlight crunch reason
+ foreach my $reason (keys %reason_colours) {
+ $content =~ s@($reason)@$reason_colours{$reason}$1$h{'Standard'}@g;
+ }
+
+ if ($content =~ m/\[too long, truncated\]$/) {
+
+ # Blocked: config.privoxy.org/edit-actions-submit?f=3&v=1176116716&s=7&Submit=Submit\
+ # [...]&filter... [too long, truncated]
+ $content = highlight_matched_pattern($content, 'request_', '^.*(?=\.\.\. \[too long, truncated\]$)');
+
+ } else {
+
+ # Blocked: http://ads.example.org/
+ $content = highlight_matched_pattern($content, 'request_', '(?<=: ).*');
+ }
+
+ return $content;
+}
+
sub handle_loglevel_connect ($) {
my $c = shift;
our %req;
our %h;
- if ($c =~ m/via [^\s]+ to: [^\s]+/) {
+ if ($c =~ m/^via [^\s]+ to: [^\s]+/) {
# Connect: via 10.0.0.1:8123 to: www.example.org.noconnect
$c = highlight_matched_host($c, '(?<=via )[^\s]+');
$c = highlight_matched_host($c, '(?<=to: )[^\s]+');
- } elsif ($c =~ m/connect to: .* failed: .*/) {
+ } elsif ($c =~ m/^connect to: .* failed: .*/) {
# connect to: www.example.org.noconnect failed: Operation not permitted
$c =~ s@(?<=failed: )(.*)@$h{'error'}$1$h{'Standard'}@;
- } elsif ($c =~ m/to ([^\s]*) successful$/) {
+ } elsif ($c =~ m/^to ([^\s]*) successful$/) {
# Connect: to www.nzherald.co.nz successful
return '' if SUPPRESS_SUCCESSFUL_CONNECTIONS;
$c = highlight_matched_host($c, '(?<=to )[^\s]+');
- } elsif ($c =~ m/to ([^\s]*)$/) {
+ } elsif ($c =~ m/^to ([^\s]*)$/) {
# Connect: to lists.sourceforge.net:443
$c = highlight_matched_host($c, '(?<=connection to )[^\s]+');
$c =~ s@(?<=on socket )(\d+)@$h{'Number'}$1$h{'Standard'}@;
- } elsif ($c =~ m/^Found reusable socket/) {
+ } elsif ($c =~ m/^^Found reusable socket/) {
# Found reusable socket 9 for www.privoxy.org:80 in slot 0.
$c =~ s@(?<=Found reusable socket )(\d+)@$h{'Number'}$1$h{'Standard'}@;
} elsif ($c =~ m/^The connection to/) {
- # The connection to www.privoxy.org:80 in slot 6 timed out. Closing socket 19.
+ # The connection to www.privoxy.org:80 in slot 6 timed out. Closing socket 19. Timeout is: 61.
# The connection to 10.0.0.1:80 in slot 0 is no longer usable. Closing socket 4.
$c = highlight_matched_host($c, '(?<=connection to )[^\s]+');
$c =~ s@(?<=in slot )(\d+)@$h{'Number'}$1$h{'Standard'}@;
$c =~ s@(?<=Closing socket )(\d+)@$h{'Number'}$1$h{'Standard'}@;
+ $c =~ s@(?<=Timeout is: )(\d+)@$h{'Number'}$1$h{'Standard'}@;
+
+ } elsif ($c =~ m/^Waiting for/) {
+
+ # Waiting for 1 connections to timeout.
+ $c =~ s@(?<=^Waiting for )(\d+)@$h{'Number'}$1$h{'Standard'}@;
} elsif ($c =~ m/^Initialized/) {
$c =~ s@(?<=Actual content length: )(\d+)@$h{'Number'}$1$h{'Standard'}@;
$c =~ s@(?<=received: )(\d+)@$h{'Number'}$1$h{'Standard'}@;
+ } elsif ($c =~ m/^Continuing buffering headers/) {
+
+ # Continuing buffering headers. byte_count: 19. header_offset: 517. len: 536.
+ $c =~ s@(?<=byte_count: )(\d+)@$h{'Number'}$1$h{'Standard'}@;
+ $c =~ s@(?<=header_offset: )(\d+)@$h{'Number'}$1$h{'Standard'}@;
+ $c =~ s@(?<=len: )(\d+)@$h{'Number'}$1$h{'Standard'}@;
+
+ } elsif ($c =~ m/^Received \d+ bytes while/) {
+
+ # Received 206 bytes while expecting 12103.
+ $c =~ s@(?<=Received )(\d+)@$h{'Number'}$1$h{'Standard'}@;
+ $c =~ s@(?<=expecting )(\d+)@$h{'Number'}$1$h{'Standard'}@;
+
+ } elsif ($c =~ m/^Connection from/) {
+
+ # Connection from 81.163.28.218 dropped due to ACL
+ $c =~ s@(?<=^Connection from )((?:\d+\.?){4})@$h{'Number'}$1$h{'Standard'}@;
+
} elsif ($c =~ m/^Looks like we rea/ or
- $c =~ m/^Unsetting keep-alive flag/) {
+ $c =~ m/^Unsetting keep-alive flag/ or
+ $c =~ m/^No connections to wait/) {
# Looks like we reached the end of the last chunk. We better stop reading.
# Looks like we read the end of the last chunk together with the server \
# headers. We better stop reading.
# Unsetting keep-alive flag.
+ # No connections to wait for left.
} else {
'Connect' => \&handle_loglevel_connect,
'Redirect' => \&handle_loglevel_redirect,
'Request' => \&handle_loglevel_request,
+ 'Crunch' => \&handle_loglevel_crunch,
'Gif-Deanimate' => \&handle_loglevel_gif_deanimate,
'Info' => \&handle_loglevel_info,
'CGI' => \&handle_loglevel_cgi,
my $version_message;
$version_message .= 'Privoxy-Log-Parser ' . PRIVOXY_LOG_PARSER_VERSION . "\n";
- $version_message .= 'Copyright (C) 2007-2008 Fabian Keil <fk@fabiankeil.de>' . "\n";
+ $version_message .= 'Copyright (C) 2007-2009 Fabian Keil <fk@fabiankeil.de>' . "\n";
$version_message .= 'http://www.fabiankeil.de/sourcecode/privoxy-log-parser/' . "\n";
print $version_message;