Solved

How to perform / call CGI_LIB_PL.pl ?

Posted on 1998-12-20
3
202 Views
Last Modified: 2010-03-05
I have an email form which contains the javascript (for user to pick email address) and I downloaded the perl script (CGI_LIB_PL.pl) for decoding the user input for the textarea.  I know the CGI_LIB_PL.pl is a standard perl lib which will perform the decoding.  

Additional Note:
1. What the /cgi-bin/CGI_LIB_PL.pl does is to convert the input from HTML format into whatever readable (If we do not use this perl script, it can't read some special char.  example: all spaces become +'s)

Problem:  See the document below.  When I use the email form to send out email, it just returned a CGI timeout page for me.  

Question:  
1. Am I using the right way to call the CGI_LIB_PL.pl?  
2. Do I have to use an additional perl script to tell the CGI_LIB_PL.pl what to do?  If so, how?


Please see the following
    ===============================================================
    function doMail()
       {
       // Reset each variable each time button is clicked
       address="";
       checked1=false;
       checked2=false;
       checked3=false;
       checked4=false;

       // Next 4 if's check to see which addresses are checked
       if (document.email.email1.checked==1)
          {
          address+=document.email.email1.value;
          checked1=true;
          }
       if (document.email.email2.checked==1)
          {
          if(checked1==true)
             {
                  address+=",";
             }
          address+=document.email.email2.value;
          checked2=true;
          }
       if (document.email.email3.checked==1)
          {
          if(checked1==true || checked2==true)
             {
                address+=",";
             }
          address+=document.email.email3.value;
          checked3=true;
          }
       if (document.email.email4.checked==1)
          {
          if(checked1==true || checked2==true || checked3==true)
             {
                address+=",";
             }
          address+=document.email.email4.value;
          checked4=true;
          }

       // Alert message if no address is checked
       if(checked1==false&&checked2==false&&checked3==false&&checked4==false)
          alert("\nYou must select an address from the list first.");

       else
          document.mesgForm.action="mailto:"+address+""
       }


    </script>

    <form name="email">
      <p><input type="checkbox" name="email1" value="cathy@aol.com">Cathy<br>
      <input type="checkbox" name="email2" value="123456@skytel.com">Email Pager<br>
      <input type="checkbox" name="email3" value="john@aol.com">John<br>
      <input type="checkbox" name="email4" value="KK@sfsu.edu">KK</p>
      <p>&nbsp;</p>
    </form>

    <form method="post" action="/cgi-bin/CGI_LIB_PL.pl" name="mesgForm" onsubmit="doMail()">
      <p><textarea name="message" rows="5" cols="30"></textarea><br>
      <br>
      <input type="reset" value="Reset Form"> <input type="submit" value="Send Message"> </p>
    </form>
    </body>
    </html>
0
Comment
Question by:cklh
  • 2
3 Comments
 

Author Comment

by:cklh
Comment Utility
Adjusted points to 50
0
 

Author Comment

by:cklh
Comment Utility
This is the CGI_LIB_PL.pl script that I downloaded.....

===============================================================

#!/usr/local/bin/perl -- -*- C -*-
# Perl Routines to Manipulate CGI input
# S.E.Brenner@bioc.cam.ac.uk
# $Header: /cys/people/brenner/http/cgi-bin/RCS/cgi-lib.pl,v 1.8 1995/04/07 21:35:29 brenner Exp $
#
# Copyright 1994 Steven E. Brenner  
# Unpublished work.
# Permission granted to use and modify this library so long as the
# copyright above is maintained, modifications are documented, and
# credit is given for any use of the library.
#
# Thanks are due to many people for reporting bugs and suggestions
# especially Meng Weng Wong, Maki Watanabe, Bo Frese Rasmussen,
# Andrew Dalke, Mark-Jason Dominus and Dave Dittrich.
# For more information, see:
#     http://www.bio.cam.ac.uk/web/form.html      
#     http://www.seas.upenn.edu/~mengwong/forms/  
# Minimalist http form and script (http://www.bio.cam.ac.uk/web/minimal.cgi):
#
# require "cgi-lib.pl";
# if (&ReadParse(*input)) {
#    print &PrintHeader, &PrintVariables(%input);
# } else {
#   print &PrintHeader,'<form><input type="submit">Data: <input name="myfield">';
#}
# ReadParse
# Reads in GET or POST data, converts it to unescaped text, and puts
# one key=value in each member of the list "@in"
# Also creates key/value pairs in %in, using '\0' to separate multiple
# selections
# Returns TRUE if there was input, FALSE if there was no input
# UNDEF may be used in the future to indicate some failure.
# Now that cgi scripts can be put in the normal file space, it is useful
# to combine both the form and the script in one place.  If no parameters
# are given (i.e., ReadParse returns FALSE), then a form could be output.
# If a variable-glob parameter (e.g., *cgi_input) is passed to ReadParse,
# information is stored there, rather than in $in, @in, and %in.
sub ReadParse {
  local (*in) = @_ if @_;
  local ($i, $key, $val);
  # Read in text
  if (&MethGet) {
    $in = $ENV{'QUERY_STRING'};
  } elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
    read(STDIN,$in,$ENV{'CONTENT_LENGTH'});
  }
  @in = split(/&/,$in);
  foreach $i (0 .. $#in) {
    # Convert plus's to spaces
    $in[$i] =~ s/\+/ /g;
    # Split into key and value.  
    ($key, $val) = split(/=/,$in[$i],2); # splits on the first =.
    # Convert %XX from hex numbers to alphanumeric
    $key =~ s/%(..)/pack("c",hex($1))/ge;
    $val =~ s/%(..)/pack("c",hex($1))/ge;
    # Associate key and value
    $in{$key} .= "\0" if (defined($in{$key})); # \0 is the multiple separator
    $in{$key} .= $val;
  }
  return length($in);
}

# PrintHeader
# Returns the magic line which tells WWW that we're an HTML document
sub PrintHeader {
  return "Content-type: text/html\n\n";
}

# MethGet
# Return true if this cgi call was using the GET request, false otherwise
sub MethGet {
  return ($ENV{'REQUEST_METHOD'} eq "GET");
}
# MyURL
# Returns a URL to the script
sub MyURL  {
  return  'http://' . $ENV{'SERVER_NAME'} .  $ENV{'SCRIPT_NAME'};
}
# CgiError
# Prints out an error message which which containes appropriate headers,
# markup, etcetera.
# Parameters:
#  If no parameters, gives a generic error message
#  Otherwise, the first parameter will be the title and the rest will
#  be given as different paragraphs of the body
sub CgiError {
  local (@msg) = @_;
  local ($i,$name);
  if (!@msg) {
    $name = &MyURL;
    @msg = ("Error: script $name encountered fatal error");
  };
  print &PrintHeader;
  print "<html><head><title>$msg[0]</title></head>\n";
  print "<body><h1>$msg[0]</h1>\n";
  foreach $i (1 .. $#msg) {
    print "<p>$msg[$i]</p>\n";
  }
  print "</body></html>\n";
}
# PrintVariables
# Nicely formats variables in an associative array passed as a parameter
# And returns the HTML string.
sub PrintVariables {
  local (%in) = @_;
  local ($old, $out, $output);
  $old = $*;  $* =1;
  $output .=  "<DL COMPACT>";
  foreach $key (sort keys(%in)) {
    foreach (split("\0", $in{$key})) {
      ($out = $_) =~ s/\n/<BR>/g;
      $output .=  "<DT><B>$key</B><DD><I>$out</I><BR>";
    }
  }
  $output .=  "</DL>";
  $* = $old;
  return $output;
}
# PrintVariablesShort
# Nicely formats variables in an associative array passed as a parameter
# Using one line per pair (unless value is multiline)
# And returns the HTML string.

sub PrintVariablesShort {
  local (%in) = @_;
  local ($old, $out, $output);
  $old = $*;  $* =1;
  foreach $key (sort keys(%in)) {
    foreach (split("\0", $in{$key})) {
      ($out = $_) =~ s/\n/<BR>/g;
      $output .= "<B>$key</B> is <I>$out</I><BR>";
    }
  }
  $* = $old;
  return $output;
}
1; #return true
0
 

Accepted Solution

by:
Thomy earned 50 total points
Comment Utility
It seems you missunderstand a bit the mechanism of CGI. A CGI-program is not executed on the client maschine like java-script, it runs on the web-server when you submit the form with action="/cgi-bin/myscript.pl".
The script "CGI_LIB_PL.pl" contains only some functions that helps you writing cgi-programs in perl. But you need to put them on your webserver into its cgi-bin directory.

You don't need the java-script, you have to write a cgi-program, which could use this CGI_LIB_PL.pl (I think name should be "cgi-lib.pl").
This library offers you some functions that parses the query-string and decodes data entered in your textarea.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

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

13 Experts available now in Live!

Get 1:1 Help Now