Solved

How do i make my cgi write multiple outputs for one value?

Posted on 1997-11-16
6
227 Views
Last Modified: 2013-12-25
I am using a script i have found, call Real Audio Jukebox.
Except i want it to write as many urls as requested .
Example :
They type http://<address>/shadow/cgi-bin/rajb.cgi?action=play&serverpath=130.207.150.33/music/&<the part iam having problems with>file=never.ra,want.ra.
they should get a file called rajb.ram
with this output:
pnm://130.207.150.33/music/never.ra
pnm://130.207.150.33/music/want.ra

But they get,
pnm://130.207.150.33/music/never.ra,want.ra

How do i make it give me the first output example ?
Here's The Script :

#!/usr/local/bin/perl
#############################################################################
# RealAudio JukeBox              Version 1.0                                #
# Written by Sebastian Boschert  scripts@sb.nethosting.com                  #
# Copyright (C) 1997 SB-Soft     http://www.SB-SOFT.ml.org                  #
#############################################################################
# Variables #
$path = "";

# Added 'serverpath' variable to play_ra . #
# Trying to make a random link to any file #

#############################################################################
# DO NOT EDIT ANYTHING BELOW THIS LINE !!! ##################################
#############################################################################

&check_input;
&play_ra;

sub check_input {
   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;
    }
}
elsif ($FORM{'file'} eq '') {
     $error = "NO FILE WAS GIVEN !!!";
     &error_html;
     }
else {
     goto_index;
     }
}

sub goto_index {
  print "Content-type: text/html";
  print "Location:http://r70h200.res.gatech.edu/shadow/music/";
  exit;
}
   

sub error_html {
  print "Content-type: text/html\n\n";
  print "<HTML><HEAD><TITLE>ERROR !!!</TITLE></HEAD>\n";
  print "<BODY>\n";
  print "<meta http-equiv=\"REFRESH\" content=\"0; URL=http://128.61.70.200/shadow/music/\">";
  print "<h1>ERROR !!!</h1>\n";
  print "<hr><p>The following error occured:<br>\n";
  print "<b><font size=\"+1\">$error</font></b>\n";
  print "<p><hr><p>Script \&copy 1997 <a 'mailto:shadow\@full-moon.com'>Shadow</a><p>\n";
  print "</BODY></HTML>\n";
  exit;
}

sub play_ra {
  print "Content-type: audio/x-pn-realaudio\n\n\n";
# This is where the problem is #
foreach ($FORM{'file'}) {
  print "pnm://$FORM{'serverpath'}$FORM{'file'}\n";
}
  exit;
}

#EOF

The end .
0
Comment
Question by:shadow010397
  • 3
  • 2
6 Comments
 
LVL 6

Accepted Solution

by:
alamo earned 200 total points
Comment Utility
$FORM{'file'} is a comma-separated list of the files you want, so you need to split it into a list. Change the lines

foreach ($FORM{'file'}) {
 print "pnm://$FORM{'serverpath'}$FORM{'file'}\n";
}
to
foreach (split(/,/, $FORM{'file'})) {
 print "pnm://$FORM{'serverpath'}$_\n";
}

This should do the trick... please leave a comment if you have more problems, and good luck!
0
 

Author Comment

by:shadow010397
Comment Utility
why the $_ ? What does _ stand for ?
0
 
LVL 6

Expert Comment

by:alamo
Comment Utility
$_ is the default variable perl uses when you don't tell it to use a different one - since you didn't specifiy a variable on the foreach it uses $_.

The following is equivalent to what I posted, just using the variable $file instead of $_:

foreach $file (split(/,/, $FORM{'file'})) {
 print "pnm://$FORM{'serverpath'}$file\n";
}
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 84

Expert Comment

by:ozo
Comment Utility
perldoc perlvar
                 $ARG

                 $_      The default  input  and  pattern-searching  space.
                         The following pairs are equivalent:
                             while (<>) {...}    # equivalent in only while!
                             while (defined($_ = <>)) {...}

                             /^Subject:/
                             $_ =~ /^Subject:/

                             tr/a-z/A-Z/
                             $_ =~ tr/a-z/A-Z/

                             chop
                             chop($_)

                         Here are the places where Perl will assume $_ even
                         if you don't use it:

                            Various unary  functions,  including  functions
                            like  ord()  and int(), as well as the all file
                            tests (-f, -d) except for -t, which defaults to
                            STDIN.

                            Various   list   functions   like  print()  and
                            unlink().

                            The pattern matching operations m//, s///,  and
                            tr/// when used without an =~ operator.

                            The default iterator variable in a foreach loop
                            if no other variable is supplied.

                            The implicit iterator variable  in  the  grep()
                            and map() functions.

                            The default place to put an input record when a
                            <FH> operation's result is tested by itself  as
                            the  sole criterion of a while test.  Note that
                            outside of a while test, this will not  happen.
                            (Mnemonic:  underline  is understood in certain
                            operations.)

0
 

Author Comment

by:shadow010397
Comment Utility
It worked . Thanks for explaning $_. One last thing though, where
is a good online resource for CGI programming in perl and c .
0
 
LVL 6

Expert Comment

by:alamo
Comment Utility
http://www.perl.com/ is the best starting place I've found for perl resources, some say http://www.cgi-resources.com/ is good though I haven't really had a chance to explore it.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

772 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

15 Experts available now in Live!

Get 1:1 Help Now