Solved

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

Posted on 1997-07-21
7
188 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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 …

744 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