Changeset 503


Ignore:
Timestamp:
May 4, 2010, 6:49:54 PM (10 years ago)
Author:
obibi
Message:

Regexps optimizations, see #12.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • postfix-logtools/poststat/anonymizer.pl

    r502 r503  
    11#!/usr/bin/env perl
    22
    3 # 2010-05-03 <vschmitt@bearstech.com>
     3# 2010-05-04 <vschmitt@bearstech.com>
    44
    55# Anonymizer for Postfix mail logs.
     
    1010
    1111while (<>) {
    12     # Only keep postfix/* related lines
    13     next unless /postfix\//;
     12    # Only keep postfix/* related lines, anonynize mail server's hostname
     13    #and move dates to a fixed offset.
     14    next unless s/^[a-zA-Z]+ \d+ ([\d:]{8}) \w+ postfix\//Apr 1 $1 host postfix\//;
    1415    # Scramble ip addresses
    15     s| (([\d]{1,3}\.){3}[\d]{1,3}) | join('.', map {int($_/3)} split(/\./, $1)) |gexo;
     16    s| (([\d]{1,3}\.){3}[\d]{1,3}) | join('.', map {int($_/3)} split(/\./, $1)) |gex;
    1617    # Scramble email addresses and message ids
    17     s/<[^<]*@[^<]*(\.[a-zA-Z]{2,6})>/<name\@domain$1>/go;
    18     s/(sasl_username=).*@.*(\.[a-zA-Z]{2,6})/$1name\@domain$2/go;
    19     s/(message-id)=<.*@.*>/$1=<$1\@domain>/go;
     18    s/<[^<]*@[^<]*(\.[a-zA-Z]{2,6})>/<name\@domain$1>/g;
     19    s/(sasl_username=).*@.*(\.[a-zA-Z]{2,6})/$1name\@domain$2/g;
     20    s/(message-id)=<.*@.*>/$1=<$1\@domain>/g;
    2021    # Scramble hostnames
    21     s/(hostname |from |connect to |client=|relay=)[\w\-\.]*/$1hostname/go
     22    s/(hostname |from |connect to |client=|relay=)[\w\-\.]*/$1hostname/g
    2223        unless /(hostname |from |client=|relay=)(localhost|ns3\.bearstech\.net)/;
    23     s/(helo=<).*>/$1hostname>/o;
    24     s/<[^<]*>:/<hostname_or_email_address>:/go;
    25     # Move dates to a fixed offset
    26     s/^[a-zA-Z]* [\d]{1,2}/Apr 1/o;
     24    s/(helo=<).*>/$1hostname>/;
     25    s/<[^<]*>:/<hostname_or_email_address>:/g;
    2726    print $_;
    2827}
Note: See TracChangeset for help on using the changeset viewer.