Solved

How do i change the Folder my cgi script pulls files out of

Posted on 1997-07-21
7
191 Views
Last Modified: 2013-12-25
i am using a script to send out the correct real audio

file when a person clicks on the link..

the cgi program is now written to get the files from

my cgi bin.. i want to change the script to get the files

from a folder that is above my "public_html" folder

i am including the script below..

below that is a script i running on my server

that now reached into the folder the same folder

i will the modify the real audio cgi script to reach

for files for..

here are the scripts.. the first one

is the one to be modified...

----------------------real audio cgi script------




#!/usr/local/bin/perl



&check_input;
&play_ra;

sub check_input {
   if ($ENV{'HTTP_REFERER'} =~ /igor3000/) {


      if ($ENV{'REQUEST_METHOD'} eq 'GET') {
         # Split the name-value pairs
         @pairs = split(/&/, $ENV{'QUERY_STRING'});
      }
      elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
         # Get the input
         read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
 
         # Split the name-value pairs
         @pairs = split(/&/, $buffer);
      }
      else {
         die "Query String is not POST or GET";
      }

      foreach $pair (@pairs) {
         ($name, $value) = split(/=/, $pair);
 
         $name =~ tr/+/ /;
         $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

         $value =~ tr/+/ /;
         $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

         $value =~ s/<!--(.|\n)*-->//g;

         if ($FORM{$name} && ($value)) {
           $FORM{$name} = "$FORM{$name}, $value";
         }
         elsif ($value) {
             $FORM{$name} = $value;
         }
      }
   
   
      if ($FORM{'action'} eq 'play') {
       if ($FORM{'file'} ne '') {
        &play_ra;
        exit;
       }
       else {
        $error = "NO FILE GIVEN !!!";
        &error_html;
      }
     }

   }
   else {
    $error = "You must have special permission from the Admin to access this file.";
    &error_html;
   }


}
   

sub error_html {
  print "Content-type: text/html\n\n";
  print "<HTML><HEAD><TITLE>ERROR !!!</TITLE></HEAD>\n";
  print "<BODY>\n";
  print "<h1>ERROR !!!</h1>\n";
  print "<hr><p>The following error occured:<br>\n";
  print "<b><font size=\"+1\">$error</font></b>\n";
  print "</BODY></HTML>\n";
  exit;
}

sub play_ra {
  print "Content-type: audio/x-pn-realaudio\n\n";
  print "http://igor3000.redscull.com/cgi-bin/$FORM{'file'}";
  exit;
}

------------------------------second script--------



#!/usr/local/bin/perl

 $ref = "$ENV{'HTTP_REFERER'}";
 $file = "$ENV{'PATH_INFO'}";

 ($filename, $extention) = split(/\./, $file);
 if ($extention =~ /htm/) {
   $content = "text/html";
} elsif ($extention =~ /ra/) {
   $content = "audio/x-pn-realaudio";
} elsif ($extention =~ /wav/) {
   $content = "audio/x-wav";
 } elsif (($extention =~ /au/) || ($extention =~ /snd/)) {
   $content = "audio/basic";
 }

 if ($ref =~ "igor3000") {
   open(FILE,"/usr/home/igor3000/songs/$file");
    print "Content-Type: $content\n\n";
    print <FILE>;
   close(FILE);
 } else {
   print "content-type: text/html\n\n";
   print "<HTML><BODY>

<font size=+1 color=orange face=Arial>You cannot access this page unless you are given
special permission from the admin!</font></BODY></HTML>\n\n";
 }

---------------end second script-----



this is the section i believe that points to

the correct folder

------portion of second script-----------
 if ($ref =~ "igor3000") {
   open(FILE,"/usr/home/igor3000/songs/$file");
    print "Content-Type: $content\n\n";
    print <FILE>;
   close(FILE);
 } else {
   print "content-type: text/html\n\n";
   print "<HTML><BODY>

------------end of portion-----

this is the portion of the real audio cgi script

that i believe needs to be changed

------------first script portion-----


sub play_ra {
  print "Content-type: audio/x-pn-realaudio\n\n";
  print "http://igor3000.redscull.com/cgi-bin/$FORM{'file'}";
  exit;
}


------------

okay so my question is can you modify

the real audio script to look for the

desired files in the folder i want??

and what would the new script look like?

both scripts are tested and running right now

on my server.. (with out the modifications i wish)
0
Comment
Question by:igor3000
7 Comments
 
LVL 5

Expert Comment

by:julio011597
ID: 1829307
It seems you just have to modify first code portion to look like second one:

--//--
sub play_ra {
  open(FILE,"/path/of/your/choice/$FORM{'file'}");
  print "Content-Type: audio/x-pn-realaudio\n\n";
  print <FILE>;
  close(FILE);
}
--//--

Give the open() function the path you need (e.g.: /usr/home/igor3000/stuff).

HTH, julio
0
 

Author Comment

by:igor3000
ID: 1829308
i have no idea whether that will work

do you want my logon and password to

get in my server and try it out?
0
 
LVL 2

Expert Comment

by:Philippe
ID: 1829309

I think Julio's answer is correct.

You shouldn't reject answers before you have tried them.

 Philippe

0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 5

Expert Comment

by:julio011597
ID: 1829310
If you don't mind, igor, please try it yourself; it's just a matter of changing a few lines of code and hitting reload on your browser.

BTW, that *should* work... let me know, i'll have to resubmit the answer to get graded.

Bye, julio
0
 

Accepted Solution

by:
bron_a earned 50 total points
ID: 1829311
Make the following changes:

1)  You must use Location: ... in order to re-refer.
sub play_ra {
  print "Location: http://...\n\n";
  # type in the correct URL instead of the ...
  # be sure that the browser supports RA association
}

2) You should better use the following for opening a path:
$filename = "/usr/home/igor3000/songs/";
$filename .= $file;
# be sure that the $filename contains no new-line character!!!
if ($filename =~ /$\n/) {
  chop ($filename);
 }
open(FILE, $filename);
etc...

Be sure also that the path is correct, in Unix it's case-sensitive!


0
 
LVL 84

Expert Comment

by:ozo
ID: 1829312
I believe bron_a may have made a typo in
 if( $filename =~ /$\n/ ){
where what was meant must have been
 if( $filename =~ /\n$/ ){

(or perhaps better:
 while( $filename =~ /\n$/ ){
or to really do what the comment says:
 $filename =~ /\n+//g;
)

Also, something like
open(FILE, $filename) || die "can't open $filename because $!";
may catch such problems if they are what's occuring.
 


0
 
LVL 84

Expert Comment

by:ozo
ID: 1829313
Sorry, it seems I typoed too:
      $filename =~ /\n+//g;
should have been
      $filename =~ s/\n+//g;
(But
      $filename =~ tr/\n//d;
would have been better anyway:-)



0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
The viewer will learn how to count occurrences of each item in an array.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now