#!/usr/bin/perl use strict; use warnings; use CGI; use CGI::Carp qw( fatalsToBrowser warningsToBrowser ); use HTML::Template; my $q = new CGI; print $q->header(), as_html($q); exit(); sub bloat { my $file = shift; my $search = shift; my $field = shift; my $rows = {}; open (FILE,"$file") || die "Error opening $file, RC=$!"; while () { next unless $. > 3; chomp; my @line = split /\t/, $_; next unless @line; my ($date, $time, $to, $id, $subject, $from, $event ) = @line[0,1,7,9,18,19,8]; $date =~ s/^(\d{4})\D(\d+)\D(\d+)$/$3.$2.$1/o; $time =~ s/\s+\w+$//o; if ($line[$field] =~ /$search/i) { $rows->{$from}->{$id} = {from => $from, to => $to, subject => $subject, id => $id} unless exists $rows->{$from}->{$id}; $rows->{$from}->{$id}->{events} = [] unless exists $rows->{$from}->{$id}->{events}; push @{$rows->{$from}->{$id}->{events}}, {event => $event, date => $date, time => $time,}; } } close (FILE); return $rows; } sub flatten { my $row = shift; my $set = []; @$set = map { from => $_ }, (keys %{$row}); for my $from (@$set) { push @{$from->{id}}, $_ for (keys %{$row->{$from->{from}}}); for my $msg (@{$from->{id}}) { push @{$from->{message}}, $_ for ($row->{$from->{from}}->{$msg}); } } return $set; } sub as_html { my $q = shift; my $template = HTML::Template->new( filename => "report_exch.tmpl", die_on_bad_params => 0, ); $q->param('action') eq 'analyze' ? $template->param( what => flatten(bloat($q->param('file'), $q->param('search') , $q->param('field')))) : $template->param( results => 'FALSE'); my @files = map { {file=>$_,} } <*.log>; $template->param( logs => \@files ); $template->param( fields => selection() ); return $template->output; } sub selection { my @fields = qw (0 1 7 9 18 19 8); my @result = map { {option => $_, value => shift @fields} } qw (date time to id subject from event); return \@result; } #### Entwurf V2.0
search for: 
Sender:
');">show/hide mails
" class="inner">
Recipient: 
Subject:   
');">show/hide events
" class="inner">
DateTimeEvent-ID