Leser: 17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#!/usr/bin/perl use strict; use warnings; my @lines_found; for my $file (glob('/kunden/homepages/20/d264326328/htdocs/logs/access.log*')) { next unless(-f $file); if(open(my $fh, '<', $file)) { while(my $line=<$fh>) { push(@lines_found,$line) if($line=~m!"(?:POST |GET .*=(?:htt|ft|ph)p(?::|%3a)(?:/|%2f)).* HTTP/[0-9]\.[0-9]" [23][0-9]{2}!i) } close($fh); } else { warn "ERROR open $file ($!)\n"; } } print $_ for(@lines_found);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#!/usr/bin/perl use strict; use warnings; use IO::Uncompress::Gunzip; use File::Type; my $ft = File::Type->new(); my @lines_found; for my $file (glob('/home/httpd/thttpd.log*')) { next unless(-f $file); my $fh=undef; if($ft->mime_type($file)=~/gzip/) { unless($fh=IO::Uncompress::Gunzip->new($file)) { warn "ERROR open compressed $file ($IO::Uncompress::Gunzip::GunzipError)"; } } else { unless(open($fh, '<', $file)) { warn "ERROR open $file ($!)\n"; } } if($fh) { while(my $line=<$fh>) { push(@lines_found,$line) if($line=~m!"(?:POST |GET .*=(?:htt|ft|ph)p(?::|%3a)(?:/|%2f)).* HTTP/[0-9]\.[0-9]" [23][0-9]{2}!i) } close($fh); } } print $_ for(@lines_found);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
use strict; use warnings; use Carp; sub run { my ($self) = shift; my $args = $self->{args}; my $post_method = "POST"; my $get_method = "GET .*=(htt|ft|ph)p(:|%3[aA])(/|%2[fF])"; my $method_string = '\"('.$post_method.' |'.$get_method.')'; if ( (defined $args->{method}) && ($#{$args->{method}} + 1 == 1) ) { if (grep lc($_) eq "post", @{$args->{method}}) { $method_string = '\"'.$post_method; } elsif (grep lc($_) eq "get", @{$args->{method}}) { $method_string = '\"('.$get_method.')'; } } my $command = "find ".$args->{docroot}."/logs/ -maxdepth 1 -type f -name access.log\* | xargs -r -n1 -P10 /bin/zgrep -E \" ".$method_string.".* HTTP/[0-9]\\\.[0-9]\\\" [23][0-9]{2}\""; open FH, "-|", $command; local $/; my $output=<FH>; close FH; return $output; } 1;
(defined $args->{method}) && ($#{$args->{method}} + 1 == 1)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
sub run { my ($self) = shift; my $args = $self->{args}; my $post_method = 'POST'; my $get_method = 'GET .*=(htt|ft|ph)p(:|%3[aA])(/|%2[fF])'; my $method_string = qq!"($post_method |$get_method)!; if ( defined($args->{method}) && @{$args->{method}}==1 ) { if (lc($args->{method}->[0]) eq 'post') { $method_string = qq!"$post_method!; } elsif (lc($args->{method}->[0]) eq 'get') { $method_string = qq!"($get_method)!; } } my $command = qq!find $args->{docroot}/logs/ -maxdepth 1 -type f -name access.log\* | xargs -r -n1 -P10 /bin/zgrep -E '$method_string.* HTTP/[0-9]\.[0-9]" [23][0-9]{2}'!; open FH, "-|", $command; local $/; my $output=<FH>; close FH; return $output; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
#!/usr/bin/perl use strict; use warnings; use IO::Uncompress::Gunzip; use File::Type; my $ft = File::Type->new(); my @lines_found; my @files=glob('/kunden/homepages/20/d264326328/htdocs/logs/access.log*'); my %pipes; while(@files || keys(%pipes)) { if(keys(%pipes) >= 10 || @files==0) { for my $child (keys(%pipes)) { my $fh=$pipes{$child}; if(eof($fh)) { delete($pipes{$child}); next; } eval{ local $SIG{ALRM}=sub{die()}; alarm(1); while(<$fh>) { push(@lines_found,$_); } alarm(0); }; } next; } next unless(@files); my $file=shift(@files); next unless(-f $file); my $pid=open(my $child, '-|'); die("Fork failed!") unless(defined($pid)); if($pid) { $pipes{$pid}=$child; next; } child($file); } print $_ for(@lines_found); sub child { my $file=shift; my $fh=undef; my $ftype=$ft->mime_type($file); if($ftype=~/gzip/) { unless($fh=IO::Uncompress::Gunzip->new($file)) { warn "ERROR open Copressed $file ($IO::Uncompress::Gunzip::GunzipError)"; } } elsif($ftype=~/octet-stream|text/) { unless(open($fh, '<', $file)) { warn "ERROR open $file ($!)\n"; } } else { warn("ERROR open $file Filetype unknown ($ftype)\n"); } if($fh) { while(my $line=<$fh>) { print $line if($line=~m!"(?:POST |GET .*=(?:htt|ft|ph)p(?::|%3a)(?:/|%2f)).* HTTP/[0-9]\.[0-9]" [23][0-9]{2}!i) } close($fh); } exit; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
sub init { my ($self) = shift; $self->setWanted($self->{args}->{docroot}."/logs/access.log*"); } sub run { my ($self) = shift; my $args = $self->{args}; # default method strings my $post_method = "POST"; my $get_method = "GET .*=(htt|ft|ph)p(:|%3[aA])(/|%2[fF])"; my $method_string = '\"('.$post_method.' |'.$get_method.')'; # redefine method string if it is given from the client if ( (defined $args->{method}) && ($#{$args->{method}} + 1 == 1) ) { if (grep lc($_) eq "post", @{$args->{method}}) { $method_string = '\"'.$post_method; } elsif (grep lc($_) eq "get", @{$args->{method}}) { $method_string = '\"('.$get_method.')'; } } # we fork several processes here to have the results faster. somehow grep takes a looooooooooooooong time to have a look over the logfiles. FIXME? foreach (keys %{$self->{files}}) { my $pid = fork(); # parent if ($pid) { $result->{$pid} = (); # child } elsif ($pid == 0) { my $cmd = '/bin/zgrep -E " '.$method_string.'.* HTTP/[0-9]\.[0-9]\" [23][0-9]{2}" '.$_." 2>/dev/null"; print `$cmd`; exit(0); } else { main::error("Could not fork: $!"); exit(1); } } foreach (keys %$result) { waitpid($_, 0); } return; }
1 2 3 4 5
elsif ($pid == 0) { my $cmd = '/bin/zgrep -E " '.$method_string.'.* HTTP/[0-9]\.[0-9]\" [23][0-9]{2}" '.$_." 2>/dev/null"; print `$cmd`; exit(0); }
1 2 3 4
elsif ($pid == 0) { exec('/bin/zgrep -E " '.$method_string.'.* HTTP/[0-9]\.[0-9]\" [23][0-9]{2}" '.$_." 2>/dev/null"); die(Fehler); }
1 2 3 4 5
local $SIG{CHLD}=sub{ my $pid=wait(); delete($result->{$pid}) }; sleep 1 while(keys(%$result));