Solved

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

Posted on 1997-07-21
7
197 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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Ned Perl Snippet to Read Files in Directory 5 74
Run command in each subfolder using batch file 7 69
ROBOFTP UNZIP 1 53
PowerShell logging 1 16
Ever wondered how to display how many visitors you have online. In this tutorial I will show you an easy but effective way to display the number of online visitors in WhizBase. In this article I assume you have read my previous articles and know …
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…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

828 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