#######################################################
#                                                     #
#  Proxy Rights Checker                               #
#     proxy.pl                                        #
#                                                     #
#######################################################

#######################################################
# Peter Toussaint                                     #
# peter.toussaint@unisa.ac.za                         #
# University of South Africa, Pretoria, South Africa  #
#######################################################


#######################################################
# This is a fairly simple script and since we are     #
# in the process of migrating, I will not make it     #
# fancy, I only need it once and it doesn't exists.   #
# Get your log (with extention .log) from GWCheck     #
# or from a scheduled event on the POA('s)            #
#                                                     #
# Do an Analy/Fix on Contents and collect statistics  #
# on the user databases alone.                        #
# On the logging tab, tick Verbose logging            #
# Be aware that the logs created this wy are BIG      #
# place all logs in one folder and run the script     #
# in this folder.                                     #
#######################################################



#######################################################
#Open new CSV file and create the headers             #
#######################################################
open (FL1, ">proxylist.csv")  || die("Target File Error $!");

print FL1 "Post Office.Domain,User,Proxy Given To,Proxy Code,Read Mail,Write Mail,Read Appointment,Write Appointment,Read Reminders,Write Rreminders,Read Tasks,Write Tasks,Subscribe Alarms,Subscribe Notifications,Modify Options,Traverse Folders,Read Private\n";


#######################################################
#Get all logfiles and put them in an array            #
#   enter the path to your logfiles below             #
#######################################################

$path='u:\groupwise\proxy'; #enter the path to your log files here

chdir $path;

while (defined($nextname = <*.log>)) {
        @logs = (@logs," $nextname");
}

foreach $logs (@logs) {
  open (FL, "<$logs") || die("Source File Error $!");

  while (<FL>) {

#######################################################
# Find name of Postoffice and Domain                  #
#######################################################   
     if ($_ =~ /Processing post office/) {
            @words = split; 
            $poffice = uc($words[4]);
            
}
#######################################################
# Find Username                                       #
#######################################################
      if ($_ =~ /Checking user =/) {
            @words = split; 
            $user = uc($words[3]);

}
#######################################################
# Find username proxy given to and proxy code         #
#######################################################
      if ($_ =~ /Access granted for user/) {
            @words = split; 
            $proxy = uc($words[4]);
            $access = uc($words[6]);

#######################################################
# Find special rights                                 #
#######################################################
if ($proxy eq "<MINIMUM") {
            $proxy = "Minimum User Access";
            $access= uc($words[8]); }
elsif ($proxy eq "<ALL") {
            $proxy = "All User Access";
            $access= uc($words[8]); }
elsif ($proxy eq "\"UNKNOWN") {
            $proxy = "Unknown Global User";
            $access= uc($words[8]); }

print FL1 $poffice.",";
print FL1 $user.",";

print FL1 $proxy.",";

print FL1 $access.",";


$alarms = "N";
$modify = "N";
$private = "N";
$notify = "N";
$appw = "N";
$appr = "N";
$taskw = "N";
$taskr = "N";
$reminw = "N";
$reminr = "N";
$mailw = "N";
$mailr = "N";
$folder = "N";
if ($access >= 8192) {
$alarms = "Y";
$access = $access - 8192;}
if ($access >= 2048) {
$folder = "Y";
$access = $access - 2048;}
if ($access >= 1024) {
$modify = "Y";
$access = $access - 1024;}
if ($access >= 512) {
$private = "Y";
$access = $access - 512;}
if ($access >= 256) {
$notify = "Y";
$access = $access - 256;}
if ($access >= 128) {
$appw = "Y";
$access = $access - 128;}
if ($access >= 64) {
$appr = "Y";
$access = $access - 64;}
if ($access >= 32) {
$taskw = "Y";
$access = $access - 32;}
if ($access >= 16) {
$taskr = "Y";
$access = $access - 16;}
if ($access >= 8) {
$reminw = "Y";
$access = $access - 8;}
if ($access >= 4) {
$reminr = "Y";
$access = $access - 4;}
if ($access >= 2) {
$mailw = "Y";
$access = $access - 2;}
if ($access >= 1) {
$mailr = "Y";
$access = $access - 1;}
print  FL1 $mailr.",";
print FL1 $mailw.",";
print FL1 $appr.",";
print FL1 $appw.",";
print FL1 $reminr.",";
print FL1 $reminw.",";
print FL1 $taskr.",";
print FL1 $taskw.",";
print FL1 $alarms.",";
print FL1 $notify.",";
print FL1 $modify.",";
print FL1 $folder.",";
print FL1 $private."\n";

}


}}
