#!/usr/local/bin/perl ############################################################################### # Set up all needed modules and objects ############################################################################### use strict; use Getopt::Long; use FindBin; use lib qw (../lib/perl ../../lib/perl); use vars qw ($sbeams $sbeamsMOD $q $dbh $current_contact_id $current_username $PROG_NAME $USAGE %OPTIONS $QUIET $VERBOSE $DEBUG $DATABASE $current_work_group_id $current_work_group_name $current_project_id $current_project_name $TABLE_NAME $PROGRAM_FILE_NAME $CATEGORY $DB_TABLE_NAME $PK_COLUMN_NAME @MENU_OPTIONS); #use CGI; use CGI::Carp qw(fatalsToBrowser croak); use SBEAMS::Connection qw($q); use SBEAMS::Connection::Settings; use SBEAMS::Connection::Tables; use SBEAMS::Connection::TableInfo; #$q = new CGI; $sbeams = new SBEAMS::Connection; use SBEAMS::Inkjet; use SBEAMS::Inkjet::Settings; use SBEAMS::Inkjet::Tables; use SBEAMS::Inkjet::TableInfo; $sbeamsMOD = new SBEAMS::Inkjet; $sbeamsMOD->setSBEAMS($sbeams); $sbeams->setSBEAMS_SUBDIR($SBEAMS_SUBDIR); ############################################################################### # Set program name and usage banner for command like use ############################################################################### $PROG_NAME = $FindBin::Script; $USAGE = <InterfaceEntry with pointer to the subroutine to execute if # the authentication succeeds. ############################################################################### sub main { #### Do the SBEAMS authentication and exit if a username is not returned exit unless ($current_username = $sbeams->Authenticate( #connect_read_only=>1, #allow_anonymous_access=>1, #permitted_work_groups_ref=>['Proteomics_user','Proteomics_admin'], )); #### Read in the default input parameters my %parameters; my $n_params_found = $sbeams->parse_input_parameters( q=>$q,parameters_ref=>\%parameters); #$sbeams->printDebuggingInfo($q); #### Define standard variables my $file_name = $parameters{'FILE_NAME'} || die "ERROR: file not passed"; my $action =$parameters{'action'} || "download"; my $project_id = $sbeams->getCurrent_project_id; my $output_dir; if ($file_name =~ /\.map$/ || $file_name=~/\.key$/) { $output_dir = "/net/arrays/Slide_Templates"; }elsif ($file_name =~/\.doc/){ $output_dir = "/net/" }else { $output_dir = "$FILE_BASE_DIR/$project_id"; } if ($action eq 'download') { #### Verify user has permission to access the file if ($sbeams->get_best_permission <= $DATA_READER_ID){ print "Content-type: application/force-download \n"; print "Content-Disposition: filename=$file_name\n\n"; my $buffer; open (DATA, "$output_dir/$file_name") || die "Couldn't open $file_name"; while(read(DATA, $buffer, 1024)) { print $buffer; } }else { $sbeams->printPageHeader(); print qq~


You Do Not Have Access To View This File

Contact PI or another administrator for permission

~; $sbeamsMOD->printPageFooter(); } }else { #### Start printing the page $sbeamsMOD->printPageHeader(); #### Verify user has permission to access the file if ($sbeams->get_best_permission <= $DATA_READER_ID){ my $file = "$output_dir/$file_name"; printFile(file=>$file); } else{ print qq~


You Do Not Have Access To View This File

Contact PI or another administrator for permission

~; } $sbeamsMOD->printPageFooter(); } } # end main ############################################################################### # printFile # # A very simple script. Throw the contents of the file within
 tags and
# we're done
###############################################################################
sub printFile {
  my %args = @_;

  my $file = $args{'file'};
  my $error = 0;

  open(INFILE, "< $file") || sub{$error = -1;};

  if ($error == 0) {
      print qq~ 
 ~;
      while () {
	  print qq~ $_ ~;
      }
      print qq~ 
~; } else{ print qq~ $file

FILE COULD NOT BE OPENED FOR VIEWING

Please report this to Michael Johnson
~; } } # end printFile