use cgi_utils; use Navigation_bar; use Sspec; use CGI qw(:all); use Far; use cgi_tables; use Fdi_display_file; use Odi_keyed_file; use cgi_site_params; use Farrsh; #use strict; my $total_file_count = 0; my $image_file_count = 0; my @all_files = (); my @image_files = (); my $total_size = 0; my $image_size = 0; my $redir; my $progname = "estimate_edtup_size.cgi"; my $lbxnum; my @lbxnum; my $query = new CGI; my $podid; my @all_dirs; my $all_dirs; my $outfile; my $event; my $asterisk = "*"; my $aspec; my $this_dir; my $env = &get_environment; my $dirname = "/usr/$env/data/editspecs/acct"; my $date; my $sspec = new Sspec; my @datadir; my $siteCode = $sspec->get_site; my $host = get_host; my $domain = get_domain; my $runhost = "ipm0"; my $bpath = "html/custom"; my $nav = new Navigation_bar; $nav->add ( gif => "Main_Menu.gif", href => path_to_script ("main_menu.cgi",$host), desc => "Return to Main Menu"); if(param('redir_to_host')) {&redir_to_host;} if (defined($lbxnum=param('lbxnum'))) { &header1; &getfiles; &footer; } if (!defined($lbxnum=param('lbxnum'))) { &header1; &initask; &footer; } ########################################################## sub header1 { print header, start_html('-title'=> 'Edtup Size Estimate'), $nav->display, br; print center (h2("Edtup Size Estimate")); br; } ######################################################### sub header2{ br; print center (h3("Size Estimate Results")); } ########################################################### sub footer { print br,hr,"\n", center(a({'-href'=>"http://$runhost.$domain/usr/$env/$bpath/custom_menu.cgi", '-onmouseover'=>"self.status='Return to Custom Menu'; return true;"}, "Return to Custom Menu"), "|", a ({'-href'=>"http://$runhost.$domain/usr/$env/$bpath/$progname", '-onmouseover'=>"self.status='Return to Edtup Size Estimate'; return true;"}, "Edtup Size Estimate"),"\n"); } ########################################################## sub initask { print center(start_form('-method'=>"POST",'-action'=>"http://$host.$domain/usr/$env/$bpath/$progname"), "Enter a valid lockbox number:", "\n", textfield('-name'=>"lbxnum",'-size'=>6, '-maxlength'=>6), "\n", br, br, hidden('-name'=>"redir_to_host", '-value'=>"redir_to_host"), "\n", submit('-value'=>"Get Files", '-name'=>"Submit"), "\n", end_form, "\n"); } ########################################################## sub getfiles { $lbxnum = param('lbxnum'); unless($lbxnum=~/\d{6}/) { print center (h2("An error occurred, the lockbox number $lbxnum is invalid")); return; } @all_dirs = glob("/usr/$env/data/lb/$lbxnum/rd/????????/outputs/w?"); my $no_webs = @all_dirs; if ($no_webs == "0") { print center (h2("Verify Lockbox number $lbxnum, there are no Image Transmissions or Lockbox number does not exist")); return; } $outfile = "$lbxnum.csv"; open (OUT, ">/usr/$env/log/$outfile"); # || die "Couldn't open output file $outfile"; print OUT "Lockbox,Date,Event,Image Files,Total Files,Image Size in MB, Total Size in MB\n"; foreach my $this_dir (@all_dirs) { my ($date, $event) = (split(/\//,$this_dir))[7,9]; $total_file_count = 0; $image_file_count = 0; @all_files = (); @image_files = (); $total_size = 0; $image_size = 0; read_dir_recursive($this_dir); # Convert from bytes to MB $image_size /= 1048576; $total_size /= 1048576; print "Lbx=$lbxnum....Date=$date....Event=$event....Image_Files=$image_file_count....Total_Files=$total_file_count....Image_Size in MB=$image_size....Total_Size in MB=$total_size\n", br,br; #print OUT "Lbx=$lbxnum,Date=$date,Event=$event,Image_Files=$image_file_count,Total_Files=$total_file_count,Image_Size in MB=$im age_size,Total_Size in MB=$total_size\n"; } close(OUT); } ############################################################# sub redir_to_host { $lbxnum = param ('lbxnum'); if ($lbxnum=~/\d{6}/) #change to check for 6 digits { $aspec = new Odi_file ("$dirname", "$siteCode-$lbxnum"); unless ($aspec->{read_successfully}) { print center (h2("the lockbox number $lbxnum does not exist")); return; } $podid = $aspec->{info}{"PodID"}; } else { print center (h2("the lockbox number $lbxnum is invalid")); return; } $redir = "http://oos0$podid.$domain/usr/$env/$bpath/$progname?getfiles=g&lbxnum=$lbxnum"; print CGI->redirect(-uri=>$redir); } ################################################################### # Sub to read a directory recursively and update variables ################################################################## sub read_dir_recursive { my $dir = shift; opendir( WEBDIR, $dir); my @files = grep !/^\.\.?$/, readdir(WEBDIR); closedir(WEBDIR); foreach (@files) { next if (-l "$dir/$_"); if (-f "$dir/$_") { my $size = (stat("$dir/$_"))[7]; #print "Web Files $_ $size",br; push(@all_files, "$dir/$_"); $total_file_count++; $total_size += $size; if (/jpg$|gif$/) { $image_file_count++; push(@image_files, "$dir/$_"); $image_size += $size; } } if (-d "$dir/$_") { read_dir_recursive("$dir/$_"); } } }