X-Git-Url: http://www.privoxy.org/gitweb/?a=blobdiff_plain;f=tools%2Fprivoxy-log-parser.pl;h=aed0b65bc7aa70ee0073cd922e4beb4552cdba61;hb=e35256ed11b2c93888bef4eb3b794313dd763f82;hp=d7c3dcb83537e37479adbaf0cc1ef943ec82e4a8;hpb=ee0914cfd79f008738c6abe482435a85c6bf7e9c;p=privoxy.git diff --git a/tools/privoxy-log-parser.pl b/tools/privoxy-log-parser.pl index d7c3dcb8..aed0b65b 100755 --- a/tools/privoxy-log-parser.pl +++ b/tools/privoxy-log-parser.pl @@ -8,7 +8,7 @@ # # http://www.fabiankeil.de/sourcecode/privoxy-log-parser/ # -# $Id: privoxy-log-parser.pl,v 1.120 2008/11/04 17:33:28 fk Exp $ +# $Id: privoxy-log-parser.pl,v 1.23 2009/03/14 15:31:58 fabiankeil Exp $ # # TODO: # - LOG_LEVEL_CGI, LOG_LEVEL_ERROR, LOG_LEVEL_WRITE content highlighting @@ -24,7 +24,7 @@ # - Use generic highlighting function that takes a regex and the # hash key as input. # -# Copyright (c) 2007-2008 Fabian Keil +# Copyright (c) 2007-2009 Fabian Keil # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above @@ -44,7 +44,7 @@ use warnings; 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') @@ -106,6 +106,7 @@ sub prepare_our_stuff () { CGI => 'light_green', Redirect => 'cyan', Error => 'light_red', + Crunch => 'cyan', 'Fatal error' => 'light_red', 'Gif-Deanimate' => 'blue', Force => 'red', @@ -265,7 +266,6 @@ sub paint_it ($) { return $colour_code; } - sub get_semantic_html_markup ($) { ############################################################### # Takes a string and returns a span element @@ -438,7 +438,6 @@ sub print_outro () { } } - sub get_line_end () { my $line_end = "\n"; @@ -467,7 +466,6 @@ sub get_colour_html_markup ($) { return $code; } - sub default_colours () { # XXX: Properly our $bg_code; @@ -752,7 +750,6 @@ sub highlight_matched_pattern ($$$) { return $result; } - sub highlight_matched_path ($$) { my $result = shift; # XXX: Stupid name; @@ -765,7 +762,6 @@ sub highlight_matched_path ($$) { return $result; } - sub highlight_url ($) { my $url = shift; @@ -803,7 +799,7 @@ sub handle_loglevel_header ($) { # 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) { @@ -915,6 +911,7 @@ sub handle_loglevel_header ($) { or $c =~ m/^Ignoring single quote in / or $c =~ m/^Converting tab to space in / or $c =~ m/A HTTP\/1\.1 response without/ + or $c =~ m/Disabled filter mode on behalf of the client/ ) { # XXX: Some of these may need highlighting @@ -952,6 +949,7 @@ sub handle_loglevel_header ($) { # Converting tab to space in 'X-LWS-Test: "This is quoted" this is not "this is " but "\ # this again is not' # A HTTP/1.1 response without Connection header implies keep-alive. + # Disabled filter mode on behalf of the client. } elsif ($c =~ m/^scanning headers for:/) { @@ -1183,7 +1181,6 @@ sub handle_loglevel_re_filter ($) { return $content; } - sub handle_loglevel_redirect ($) { my $c = shift; @@ -1292,7 +1289,6 @@ sub handle_loglevel_gif_deanimate ($) { return $content; } - sub handle_loglevel_request ($) { my $content = shift; @@ -1332,6 +1328,32 @@ sub handle_loglevel_request ($) { 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; @@ -1339,14 +1361,14 @@ sub handle_loglevel_connect ($) { 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 @@ -1354,14 +1376,14 @@ sub handle_loglevel_connect ($) { $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 @@ -1421,6 +1443,12 @@ sub handle_loglevel_connect ($) { $c =~ s@(?<=socks5_connect: )(.*)@$h{'error'}$1$h{'Standard'}@; + } elsif ($c =~ m/^Created new connection to/) { + + # Created new connection to www.privoxy.org:80 on socket 11. + $c = highlight_matched_host($c, '(?<=connection to )[^\s]+'); + $c =~ s@(?<=on socket )(\d+)@$h{'Number'}$1$h{'Standard'}@; + } elsif ($c =~ m/^Found reusable socket/) { # Found reusable socket 9 for www.privoxy.org:80 in slot 0. @@ -1450,17 +1478,22 @@ sub handle_loglevel_connect ($) { } elsif ($c =~ m/^Socket/) { - # Socket 18 for www.privoxy.org:80 in slot 0 is no longer usable. Closing. # Socket 16 already forgotten or never remembered. $c =~ s@(?<=Socket )(\d+)@$h{'Number'}$1$h{'Standard'}@; - $c = highlight_matched_host($c, '(?<=for )[^\s]+'); - $c =~ s@(?<=in slot )(\d+)@$h{'Number'}$1$h{'Standard'}@; } elsif ($c =~ m/^The connection to/) { - # The connection to www.privoxy.org:80 in slot 0 timed out. Closing. + # 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/) { @@ -1475,11 +1508,33 @@ sub handle_loglevel_connect ($) { $c =~ s@(?<=Actual content length: )(\d+)@$h{'Number'}$1$h{'Standard'}@; $c =~ s@(?<=received: )(\d+)@$h{'Number'}$1$h{'Standard'}@; - } elsif ($c =~ m/^Looks like we reached/ or - $c =~ m/^Unsetting keep-alive flag/) { + } 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/ 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 { @@ -1568,10 +1623,17 @@ sub handle_loglevel_info ($) { # Method HEAD implies no body. $c =~ s@(?<=Method )([^\s]+)@$h{'method'}$1$h{'Standard'}@; + } elsif ($c =~ m/^Buffer limit reached while extending /) { + + # Buffer limit reached while extending the buffer (iob). Needed: 4197470. Limit: 4194304 + $c =~ s@(?<=Needed: )(\d+)@$h{'Number'}$1$h{'Standard'}@; + $c =~ s@(?<=Limit: )(\d+)@$h{'Number'}$1$h{'Standard'}@; + } elsif ($c =~ m/^No logfile configured/ or $c =~ m/^Malformerd HTTP headers detected and MS IIS5 hack enabled/ or $c =~ m/^Invalid \"chunked\" transfer/ or - $c =~ m/^Support for/ + $c =~ m/^Support for/ or + $c =~ m/^Flushing header and buffers/ ) { # No logfile configured. Please enable it before reporting any problems. @@ -1581,6 +1643,7 @@ sub handle_loglevel_info ($) { # Invalid "chunked" transfer encoding detected and ignored. # Support for 'Connection: keep-alive' is experimental, incomplete and\ # known not to work properly in some situations. + # Flushing header and buffers. Stepping back from filtering. } else { @@ -1739,6 +1802,7 @@ sub parse_loop () { '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, @@ -1752,7 +1816,7 @@ sub parse_loop () { $output = ''; - if (m/^(\w{3} \d{2}) (\d\d:\d\d:\d\d)\.?(\d+)? (?:Privoxy\(([^\)]*)\)) ([\w -]*): (.*)$/) { + if (m/^(\w{3} \d{2}) (\d\d:\d\d:\d\d)\.?(\d+)? (?:Privoxy\()?([^\)\s]*)[\)]? ([\w -]*): (.*)$/) { # XXX: Put in req hash? $day = $1; $time_stamp = $2; @@ -1807,7 +1871,7 @@ sub parse_loop () { print_non_clf_message($content); - } elsif (m/^(\d+\.\d+\.\d+\.\d+) - - \[(.*)\] "(.*)" (\d+) (\d+)/) { + } elsif (m/^((?:\d+\.\d+\.\d+\.\d+|[:\d]+)) - - \[(.*)\] "(.*)" (\d+) (\d+)/) { # LOG_LEVEL_CLF lines look like this # 61.152.239.32 - - [04/Mar/2007:18:28:23 +0100] "GET \ @@ -1840,7 +1904,7 @@ sub VersionMessage { my $version_message; $version_message .= 'Privoxy-Log-Parser ' . PRIVOXY_LOG_PARSER_VERSION . "\n"; - $version_message .= 'Copyright (C) 2007-2008 Fabian Keil ' . "\n"; + $version_message .= 'Copyright (C) 2007-2009 Fabian Keil ' . "\n"; $version_message .= 'http://www.fabiankeil.de/sourcecode/privoxy-log-parser/' . "\n"; print $version_message;