?
Solved

Need changes to this perl script

Posted on 1997-07-26
1
Medium Priority
?
162 Views
Last Modified: 2013-12-25
This cgi script is running now on my server

                  as you see it takes a password and delivers a .wav file

                  except right now the file comes up as text in the browser

                  i need the exact changes that would need to be made

                  to make the .wav file prompt the

                  user for a "save as" and and then allow for download

                  of the song??

                  exact detailed changes please!!!

I Need You To MAKE THE CHANGES IN THE SCRIPT AND REPRINT

THE CHANGE.... it's no use just telling me where

because i already tried that and always get "server error"

so please make the changes and REPRINT the script here

thanks

                  #!/usr/bin/perl
                  #
                  # WEB900.PL (Verifies web900 codes)
                  #
                  # - Original script and file locking 1/24/96 Bert Love
                  #
                  # - Modified the location of the challenge, good and bad HTML files for
                  # - security reasons. The $oordir variable is the out-of-reach directory.
                  # - 5/21/96 S. Thomas
                  #

                  #
                  # File locations
                  #
                  # oordir - Set this to the directory just out of reach of the web server
                  directory.
                  # - Conventionally, this is the directory just above public_html:
                  # /usr2
                  # /usr2/shane (this is oordir)
                  # /usr2/shane/public_html (this is the top of the HTTP dirs)
                  # /usr2/shane/public_html/cgi-bin

                  $oordir = '/usr/home/igor3000/webauth';
                  $webfile = "/$oordir/web.data";
                  $formfile = "/$oordir/webchall.html";
                  $goodfile = "$oordir/song.ra";
                  $badfile = "$oordir/bad.html";
                  $logfile = "$oordir/web.log";

                  #
                  # You shouldn't need to touch anything below this line!
                  #

                  require "ctime.pl";
                  chop($date = &ctime(time));
                  $WEBLEN = 8; # fixed record length in webfile

                  # copy the values of these environment variables
                  $method = $ENV{"REQUEST_METHOD"};
                  $type = $ENV{"CONTENT_TYPE"};

                  # if the script was called with the GET method,
                  # output the form
                  if($method eq "GET") {
                  &send_file($formfile);
                  exit;
                  }

                  # check for the POST method and the HTML form's MIME-type
                  if($method ne "POST" || $type ne
                  "application/x-www-form-urlencoded") {
                  &system_error("Web authorization code must come from a Form\n");
                  exit;
                  }

                  # read form data from standard input
                  %input_values = &break_input;

                  # convert from the strange URL syntax to normal ascii
                  # and translate non-UNIX line endings to UNIX convention
                  $number = &normalize_query($input_values{"number"});
                  $email = &normalize_query($input_values{"email"});

                  # verify number is seven digits
                  if(length($number) != 7) {
                  &system_error("Sorry, but that number is not valid\n");
                  exit;
                  }

                  # open Web file for read/write and lock
                  unless(open(WEB,"+<$webfile")) {
                  &system_error("Could not open web data file.\n");
                  exit;
                  }
                  #flock(WEB, $LOCK_EX);
                  seek(WEB, 0, 0);

                  # open log file as append and lock
                  unless(open(WLOG,">>$logfile")) {
                  # flock(WEB, $LOCK_UN);
                  &system_error("Could not open log file.\n");
                  exit;
                  }
                  #flock(WLOG, $LOCK_EX);
                  #seek(WLOG, 0, 2);

                  $goodbad=$badfile;
                  SEARCH:
                  for ($recnum = 0; read(WEB, $goodnum, $WEBLEN); $recnum++) {
                  $goodnum =~ tr/0-9//cd;
                  if($number eq $goodnum) { # got the number
                  $goodbad=$goodfile;
                  seek(WLOG, 0, 2); # make sure we're at end
                  print (WLOG $date, " ", $number, " ", $email, "\n");
                  seek(WEB, -$WEBLEN, 1);
                  $goodnum =~ tr/0-9/x/;
                  print WEB $goodnum;
                  last SEARCH;
                  }
                  seek(WEB, $recnum*$WEBLEN, 0);
                  }

                  # unlock and close files
                  #flock(WEB, $LOCK_UN);
                  #flock(WLOG, $LOCK_UN);
                  close(WEB);
                  close(WLOG);
                  chmod(0666, $logfile);

                  # send the good or bad news
                  &send_file($goodbad);
                  exit;

                  ##
                  ## SUBROUTINES
                  ##

                  # read CONTENT_LENGTH bytes from the standard input and decode
                  # the URL format input, breaking it into an associative array
                  # of HTML variable names and their values.
                  sub break_input {
                  local ($i);
                  read(STDIN,$input,$ENV{'CONTENT_LENGTH'});
                  @form_names = split('&',$input);
                  foreach $i(@form_names) {
                  ($html_name,$html_value) = split('=',$i);
                  $input_values{$html_name} = $html_value;
                  }
                  return %input_values;
                  }

                  # handle system errors
                  sub system_error {
                  local($errmsg) = @_;
                  &print_header("System Error");
                  print $errmsg;
                  &print_footer;
                  }

                  # given a title, print the return header
                  sub print_header {
                  local($title) = @_;
                  print "Content-type: text/html\n\n";
                  print "<HTML>\n";
                  print "<HEAD>\n";
                  print "<TITLE>$title</TITLE>\n";
                  print "</HEAD>\n";
                  print "<BODY>\n";
                  print "<H1>$title</H1>\n";
                  }

                  # finish off HTML page
                  sub print_footer {
                  print "</BODY>\n";
                  print "</HTML>\n";
                  }

                  # URL syntax converts most non-alphanumeric characters into a
                  # percentage sign, followed by the character's value in hex.
                  sub normalize_query {
                  local($value) = @_;
                  $value =~ tr/+/ /;
                  $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
                  return $value;
                  }

                  # send specified HTML file
                  sub send_file {
                  local($file) = @_;
                      unless(open(FILE,$file)) {
                  &system_error("Failed to open file $file\n");
                  exit;
                  }
                  print "Content-type: text/html\n\n";
                  while (<FILE>) {
                  print;
                  }
                  close(FILE);
                  }
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
1 Comment
 
LVL 1

Accepted Solution

by:
wormzer earned 100 total points
ID: 1829419
You're going to have to change your 'content-type:' to something else other than text/html.  This triggers the browser to print it on the screen.  You want it to be something else... I think it would be audio/x-wav for sending a wav file.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
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…
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…
Suggested Courses

762 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