This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
exchange:reporting:parse_allexchange.pl [2010/03/06 10:10] ben removed |
— (current) | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== parse_allExchange.pl ====== | ||
- | <code> | ||
- | #!/opt/local/bin/perl | ||
- | # | ||
- | #Take field 12 from the BES stats list and echo it out in an update | ||
- | #statement- any user in the list is a BES user, so their bes field | ||
- | #gets a '1' | ||
- | #use warnings; | ||
- | #use strict; | ||
- | use Text::CSV; | ||
- | use Text::CSV::Encoded; | ||
- | #use locale; | ||
- | |||
- | use POSIX qw(locale_h); | ||
- | #setlocale(LC_CTYPE, "iso-8859-1"); | ||
- | setlocale(LC_CTYPE, "C"); | ||
- | |||
- | my $fh; | ||
- | my $usage = "usage: ".$0." mailbox_list.csv\n"; | ||
- | |||
- | if (@ARGV) { | ||
- | $fh = shift @ARGV; | ||
- | open INFILE, "<:raw:encoding(utf-8)", "$fh" or die $usage; | ||
- | } | ||
- | else { print $usage; exit(1);} | ||
- | |||
- | open (ERRFILE, ">error_log.txt") or die "$!\n"; | ||
- | |||
- | #Generate a big list of safe/allowed ips and currently blocked ips. | ||
- | #Note "$index" is incremented by both while loops | ||
- | |||
- | while (<INFILE>) { | ||
- | |||
- | #this can spit out the bad lines, maybe soo to an output file... | ||
- | #if ( $_ =~ /[^A-Za-z0-9\s\t\\r\a`\-=\[\]\\;\',\.\/~!@#$%^&\*\(\)_+\{\}\|:\"<>\?)]/ ) { | ||
- | # print "-- ", $_ ; | ||
- | # print ERRFILE $_ ; | ||
- | # } | ||
- | if ( $_ =~ "DN,cn,displayName,legacyExchangeDN" ) { | ||
- | print "-- ", $_ ; | ||
- | print ERRFILE $_ ; | ||
- | } | ||
- | else { | ||
- | #convert to lower-case, I think I'm getting the hang of this "$_" thing... | ||
- | # $_ = lc($_); | ||
- | |||
- | #Create new CSV | ||
- | my $csv = Text::CSV::Encoded -> new ({ allow_loose_quotes => 0, encoding => "utf8" }); | ||
- | my $status = $csv->parse($_); | ||
- | my @fields = $csv->fields(); | ||
- | |||
- | #replace ' with \' in all @fields entries. NICE use of $_ again. | ||
- | foreach (@fields) { | ||
- | | ||
- | $_ =~ s/\'/\\\'/g; | ||
- | |||
- | } | ||
- | |||
- | #@fields[1] =~ s/\'/\\\'/g; | ||
- | #@fields[2] =~ s/\'/\\\'/g; | ||
- | #remove quotes from DN | ||
- | my @noquote = split(/'"'/,@fields[0]); | ||
- | #remove logon id from upn | ||
- | my @noat = split(/@/, @fields[1]); | ||
- | #print @noquote[0]; | ||
- | |||
- | #output update statements with alpha_id where displayName | ||
- | # print "update exchange_info set alpha_id=\'", @noat[0], "\' where dname\=\'", @noquote[0], "\'\;\n" | ||
- | print "insert into exchange_info (dname,cname,displayName,legacyExchangeDN) values (\'@fields[0]\',\'@fields[1]\',\'@fields[2]\',\'@fields[3]\'\)\;\n"; | ||
- | #print @fields,"\n"; | ||
- | } | ||
- | } | ||
- | |||
- | close(ERRFILE); | ||
- | |||
- | |||
- | </code> |