[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 1997-07-21
7
Medium Priority
?
208 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

 
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 100 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

649 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