Solved

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

Posted on 1997-07-21
7
194 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Powershell script : Get-ADOrganizationalUnit in windows list box 2 159
.csv files 5 93
Recursive folder search vbscript 7 47
powershell md/mkdir/New-item   -Quiet 10 40
Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

776 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