Problem in CGI script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mopiforu
    New Member
    • Dec 2007
    • 5

    Problem in CGI script

    hi,

    I am trying to create a web application where i have a form to upload a file,which is then processed by a cgi script and gives me out the output,
    here is the code which i use,

    Code:
    # Configuration
    my $EXECUTABLE_DIRECTORY = "/web_server/Test";
    my $CREATE_DIRECTORY = "//web_server/Output";
    
    
    my $cgi = CGI->new();
    my $pdb_file = $cgi->param("upfile");
    $pdb_file =~ s/.*[\/\\](.*)/$1/; 
    die "Missing PDB file \n" if(!$pdb_file);
    print STDERR "PDB file is $pdb_file\n";
    my $mode = 'SH';					
    
    my $read_file = $cgi->upload("upfile"); 
     open (UPFILE,">$CREATE_DIRECTORY/$pdb_file"); 
     while ( <$pdb_file> )  { 
       print UPFILE; 
       print ;
     } 
     close UPFILE; 
    	
    
    if ($mode eq 'SH'){
    	system "$EXECUTABLE_DIRECTORY/pdb2alm $CREATE_DIRECTORY/$pdb_file > $CREATE_DIRECTORY/query.alm";
    	system "$EXECUTABLE_DIRECTORY/command_arg_alm_exp $CREATE_DIRECTORY/query.alm > $CREATE_DIRECTORY/distances_SH.log" ;
    	open(IN,"<$CREATE_DIRECTORY/distances_SH.log");
    	my $line;
    	my %lig_name;
    	while($line=<IN>){
    		chomp $line;
    		my @words = split(' ', $line);
    		$lig_name{$words[1]} = $words[0];
    		}
    	close IN;
    	my $count=1;
    	foreach my $key (sort { $lig_name{$a} <=> $lig_name{$b} }keys %lig_name){
    		open(FILE,"</Users/gunasekp/SH/ligand/ligand_$key.pdb");
    		if($count<=10){
    			while(<FILE>){
    			if($_ =~ /(COMPND)\s+(\w+)\s+(.*)/){
    				print "$count    ",$3,"     ",$lig_name{$key},"\n";
    				}
    			}
    		}
    		$count++;
    	}
    	......code continues
    the problem is when i see the error log it says the

    " malformed header from script. Bad header=COMPND Y 2p-DEOXY-N6-(S)STYR: /Users/gunasekp/Sites/cgi-bin/automate_cgi.pl
    sh: line 1: /Users/gunasekp/web_server/Output/query.alm: Permission denied
    sh: line 1: /Users/gunasekp/web_server/Output/distances_SH.lo g: Permission denied "

    2)(pdb2alm and command_....) are executable c++ files which are placed in a directory in harddisk and whose configuration is (drwxr-xr-x and for files -rwxrwxrwx)
    3) the output files like query.alm are written to directory whose configuration is (drwxrwxrwx and for files -rw-r--r--)

    help me to solve this problems?

    Prasad.
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    Originally posted by mopiforu
    hi,

    I am trying to create a web application where i have a form to upload a file,which is then processed by a cgi script and gives me out the output,
    here is the code which i use,

    Code:
    # Configuration
    my $EXECUTABLE_DIRECTORY = "/web_server/Test";
    my $CREATE_DIRECTORY = "//web_server/Output";
    
    
    my $cgi = CGI->new();
    my $pdb_file = $cgi->param("upfile");
    $pdb_file =~ s/.*[\/\\](.*)/$1/; 
    die "Missing PDB file \n" if(!$pdb_file);
    print STDERR "PDB file is $pdb_file\n";
    my $mode = 'SH';					
    
    my $read_file = $cgi->upload("upfile"); 
     open (UPFILE,">$CREATE_DIRECTORY/$pdb_file"); 
     while ( <$pdb_file> )  { 
       print UPFILE; 
       print ;
     } 
     close UPFILE; 
    	
    
    if ($mode eq 'SH'){
    	system "$EXECUTABLE_DIRECTORY/pdb2alm $CREATE_DIRECTORY/$pdb_file > $CREATE_DIRECTORY/query.alm";
    	system "$EXECUTABLE_DIRECTORY/command_arg_alm_exp $CREATE_DIRECTORY/query.alm > $CREATE_DIRECTORY/distances_SH.log" ;
    	open(IN,"<$CREATE_DIRECTORY/distances_SH.log");
    	my $line;
    	my %lig_name;
    	while($line=<IN>){
    		chomp $line;
    		my @words = split(' ', $line);
    		$lig_name{$words[1]} = $words[0];
    		}
    	close IN;
    	my $count=1;
    	foreach my $key (sort { $lig_name{$a} <=> $lig_name{$b} }keys %lig_name){
    		open(FILE,"</Users/gunasekp/SH/ligand/ligand_$key.pdb");
    		if($count<=10){
    			while(<FILE>){
    			if($_ =~ /(COMPND)\s+(\w+)\s+(.*)/){
    				print "$count    ",$3,"     ",$lig_name{$key},"\n";
    				}
    			}
    		}
    		$count++;
    	}
    	......code continues
    the problem is when i see the error log it says the

    " malformed header from script. Bad header=COMPND Y 2p-DEOXY-N6-(S)STYR: /Users/gunasekp/Sites/cgi-bin/automate_cgi.pl
    sh: line 1: /Users/gunasekp/web_server/Output/query.alm: Permission denied
    sh: line 1: /Users/gunasekp/web_server/Output/distances_SH.lo g: Permission denied "

    2)(pdb2alm and command_....) are executable c++ files which are placed in a directory in harddisk and whose configuration is (drwxr-xr-x and for files -rwxrwxrwx)
    3) the output files like query.alm are written to directory whose configuration is (drwxrwxrwx and for files -rw-r--r--)

    help me to solve this problems?

    Prasad.
    The first thing that you need to do is put the pragmas "use strict" and "use warnings" at the beginning of your script. This will ensure that all is right with syntax and such.

    Next, if you look at this line:

    [code=perl]
    my $CREATE_DIRECTO RY = "//web_server/Output";
    [/code]

    Why is the begining of this double slashed? In the variable before this one, it is single slashed. I can only assume you are working on Unix, and if you are, this should be single slashed.

    Regards,

    Jeff

    Comment

    • mopiforu
      New Member
      • Dec 2007
      • 5

      #3
      that is a typo while copy and paste,
      in my code i have only single slash anda ll the pragmas are at the top.,thats a bit of code not the full one.

      Comment

      • numberwhun
        Recognized Expert Moderator Specialist
        • May 2007
        • 3467

        #4
        Originally posted by mopiforu
        that is a typo while copy and paste,
        in my code i have only single slash anda ll the pragmas are at the top.,thats a bit of code not the full one.
        Ok, if that is the case, then I would check all of my permissions, especially on the output directory as you are clearly getting "Permission Denied" errors. Check to ensure that you can create files in that directory as whatever user you are executing as.

        Regards,

        Jeff

        Comment

        Working...