• Moderatore

    CGI e Perl per una mailform

    Ho su questa pagina un form per richieste, il mailform è su di un'altro host di un altro mio sito, il problema è che quando invio i dati mi rimanda questo messaggio...

    %1 is not a valid Win32 application.

    Che é?

    vi post anche il file mailform.cgi è un pò lunghetto :):

    !/usr/local/bin/perl

    ######################################################################

    A&M MailForm Version 1.2

    Copyright 1999 Alex Iatskovski [EMAIL="[email protected]"][email protected][/EMAIL]

    Created 06/10/99

    Last Modified 06/15/99

    Home URL http://www.anmweb.com

    ######################################################################

    This is a MailForm program that allows you to communicate with the

    visitors of your home page without publishing your E-mail address on

    the Web. Your real E-mail address is completely hidden from spammers

    (it is not shown in web-page source in contrast to most such programs),

    but at the same time you are not losing ability to communicate with

    a civilized visitors of your Web Site. This program is using Java Script

    to display form in a nice popup window. But it works as well if Java Script

    is disabled in visitor's browser. It will work with all known Web Browsers.

    No more HTML forms programming! This script is generating all necessary

    forms dynamically on the fly.

    ######################################################################

    Installation:

    Put this script into your cgi-bin directory and make it executable

    (chmod 755 on most system). Then change variables according to your

    requirements.

    1. Make sure the very top line of script is pointed to the exact location

    of Perl program on your server.

    2. Make sure the "$mailprog" variable is pointed to the exact location of

    "sendmail" program on your server.

    3. Make sure to change "$admin_mail" variable to your real E-mal address.

    4. Make sure the "$cgiurl" variable is pointed to the exact URL of

    your script.

    To call this program from the Web pages use something like this:

    ----------Cut here----------

    <a href="/cgi-bin/mailform.cgi" target="NewWindow"

    onclick="window.open('/cgi-bin/mailform.cgi','newWindow','toolbar=0,

    location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,

    width=500,height=420');return false"><strong>Contact Us</strong></a>

    ----------End of cut----------

    IMPORTANT! This whole HTML link should be written in ONE LINE! Otherwise

    the Java Script will not work. Make sure also that the "/cgi-bin/mailform.cgi"

    part is pointed to the real location of the script. If not, you should change

    it (two times!) in above example and put it to your HTML page.This construction

    will work even with Java Script disabled browsers.

    That's all! Your program is now up and running.

    ######################################################################

    COPYRIGHT NOTICE

    (c)Copyright 1999 Alex Iatskovski All Rights Reserved.

    A&M Register program is FREEWARE BUT IT IS NOT PUBLIC DOMAIN! This

    program may be used free of charge by anyone so long as this copyright

    notice and the comments above remain intact. Any modification to this

    program except configuration user variables is strictly prohibited!

    By using this code you agree to indemnify A.Iatskovski from any liability

    that might arise from its use.

    Selling the code for this program without prior written consent

    is expressly forbidden. In other words, please ask first before

    you try and make money off of my program.

    Obtain permission before redistributing this software over the

    Internet or in any other medium. In all cases copyright and header

    must remain intact.

    ######################################################################

    Perl's use strict directive checks to make sure variables are

    declared before use. It's a handy check to make sure you are doing

    what you think you are doing. Always

    use strict;

    Make sure your Perl version is not earlier than this one

    require 5.003;

    ######################################################################

    Define Variables

    Mail program path

    my ($mailprog) = '/usr/sbin/sendmail';

    Admin E-mail

    my ($admin_mail) = '[email protected]';

    CGI URL

    my ($cgiurl) = 'http://www.hotelvillamarina.eu/cgi-bin/mailform.cgi';

    Global Vars, don't change!

    my ($buffer, @pairs, $pair, $name, $value, %FORM);

    Done

    ######################################################################

    ###################################

    Do not edit below this line

    ###################################

    Antihacker's rooting

    if ($ENV{'QUERY_STRING'} ne '') {
    my ($text) = <<EOT;
    To be a hacker indicates to be a man with more than just one cerebral bend.
    What do you attempt to do here boy? These tries do not roll on this server!
    If you have something to say - speak up, if not - get lost and say your mother
    that your stupid attempt to hack this Web Site was logged by server's security staff.
    EOT
    &error($text);
    }
    else {
    &parse_form();
    }

    if ($FORM{'action'} eq 'send_form') {
    &check_form();
    &mail_form();
    &show_thanks();
    }
    else {
    &main_form();
    }

    ###############
    sub parse_form {
    ###############
    # Read in text
    $ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/;
    if ($ENV{'REQUEST_METHOD'} eq "POST"){
    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
    }
    else {
    $buffer = $ENV{'QUERY_STRING'};
    }
    # Split information into name/value pairs
    @pairs = split(/&/, $buffer);
    foreach $pair (@pairs){
    ($name, $value) = split(/=/, $pair);
    $value =~ tr/+/ /;
    $value =~ s/%(..)/pack("C", hex($1))/eg;
    $FORM{$name} = $value;
    }
    }

    ##############
    sub main_form {
    ##############
    my $title = 'Contact Us';
    my $text = <<EOF;
    <FORM ACTION="$cgiurl" METHOD="POST">
    <INPUT TYPE="text" SIZE="30" NAME="nome" VALUE="Nome" MAXLENGTH="30">
    <BR><BR>
    <INPUT TYPE="text" SIZE="30" NAME="cognome" VALUE="Cognome" MAXLENGTH="30">
    <BR><BR>
    <INPUT TYPE="text" SIZE="30" NAME="email" VALUE="Your E-mail" MAXLENGTH="30">
    <BR><BR>
    <INPUT TYPE="text" SIZE="30" NAME="via" VALUE="via" MAXLENGTH="30">
    <BR><BR>
    <INPUT TYPE="text" SIZE="30" NAME="cap" VALUE="CAP" MAXLENGTH="30">
    <BR><BR>
    <INPUT TYPE="text" SIZE="30" NAME="città" VALUE="città" MAXLENGTH="30">
    <BR><BR>
    <INPUT TYPE="text" SIZE="30" NAME="provincia" VALUE="provincia" MAXLENGTH="30">
    <BR><BR>
    <INPUT TYPE="text" SIZE="30" NAME="stato" VALUE="stato" MAXLENGTH="30">
    <BR><BR>
    <TEXTAREA NAME="richiesta" ROWS="5" COLS="50">Type your text here</TEXTAREA>
    <BR><BR>
    <select name="Per quale albergo?">
    <option value="Tutti e tre" selected>Tutti e tre</option>
    <option value="Hotel Villa Marina">Hotel Villa Marina</option>
    <option value="Hotel Nuovo Bristol">Hotel Nuovo Bristol</option>
    <option value="Hotel Corallo">Hote Corallo</option>
    </select><br><br>
    <select name="come ci hai trovato">
    <option value="amici e/o parenti" selected>amici e/o parenti</option>
    <option value="motori di ricerca">motori di ricerca</option>
    <option value="opuscoli pubblicitari">opuscoli pubblicitari</option>
    <option value="portali turistici e non">portali turistici e non</option>
    </select><br><br>
    <INPUT TYPE="submit" NAME="submit" VALUE="Send Comments"> 
    <INPUT TYPE="reset" NAME="Button" VALUE="Clear Comments">
    <input type=hidden name="action" value="send_form">
    </FORM>
    EOF
    &show_form($title,$text);
    }

    ###############
    sub check_form {
    ###############
    if($FORM{'realname'} eq "Your name"){
    &error('You forgot to enter your name!');
    }
    elsif($FORM{'realname'} eq ""){
    &error('You forgot to enter your name!');
    }
    elsif(!($FORM{'email'} =~ /([\w-.]+@[\w-.]+)/)){
    &error('You forgot to enter your E-mail address!');
    }
    elsif($FORM{'subject'} eq "Subject"){
    &error('You forgot to enter a Subject!');
    }
    elsif($FORM{'subject'} eq ""){
    &error('You forgot to enter a Subject!');
    }
    elsif($FORM{'body'} eq "Type your text here"){
    &error('You forgot to write a message!');
    }
    elsif($FORM{'body'} eq ""){
    &error('You forgot to write a message!');
    }
    }

    ##############
    sub mail_form {
    ##############
    my $text = <<EOF;
    Administrator of this server forgot to enter his E-mail
    address to this program! I can't continue without correct
    E-mail address of the site administrator.
    EOF
    if ($admin_mail eq '[email protected]'){&error($text);}
    open(MAIL,"|$mailprog -t");
    print MAIL "To: $admin_mail\n";
    print MAIL "From: $FORM{'email'} ($FORM{'realname'})\n";
    print MAIL "Subject: $FORM{'subject'}\n";
    print MAIL "X-Priority: 1 (Highest)\n\n";
    print MAIL "#\n";
    print MAIL "# Entered from $ENV{'REMOTE_HOST'} ($ENV{'REMOTE_ADDR'}) with $ENV{'SERVER_PROTOCOL'}.\n";
    print MAIL "#\n\n";
    print MAIL "$FORM{'body'}\n";
    close(MAIL);
    }

    ################
    sub show_thanks {
    ################
    my $title = 'Form Input Accepted';
    my $text = <<EOF;
    <small>Your form details have been sent.</small><br>
    <h1><b>Thank you!</b></h1>
    EOF
    &show_form($title,$text);
    }

    ###################################

    Sub Error

    Usage - &error('Your text here');

    ###################################
    sub error {
    my $title = 'Error';
    my $text1 = $_[0];
    my $text = <<EOF;
    <small>The program could not complete your request. This was because:</small>
    <br><br>
    <small><b>$text1</b></small><br><br>
    <small>Click <a href="$cgiurl"><font color="#0000FF">here</font></a> to
    start over, otherwise close this window.</small>
    EOF
    &show_form($title,$text);
    }

    ###################################

    Sub main_form

    Usage - &show_form($title,$text);

    ###################################
    sub show_form {
    print "Content-type:text/html\n\n";
    print "<html>\n";
    print "<head>\n";
    print "<meta http-equiv="Content-Type" content="text/html;\n";
    print "charset=iso-8859-1">\n";
    print "<meta name="robots" content="noindex">\n";
    print "<title>$[0]</title>\n";
    print "</head>\n";
    print "<body bgcolor="#FFFFFF">\n";
    print "<div align="center">\n";
    print "<table border="0" cellpadding="0" cellspacing="0" width="100%"\n";
    print "bgcolor="#FFFFFF">\n";
    print "<tr><th align="left" colspan="3" width="100%" bgcolor="#000080"\n";
    print "nowrap>\n";
    print "<font color="#FFFFFF" size="6">\n";
    print "&nbsp;$
    [0]\n";
    print "</font>\n";
    print "</th>\n";
    print "</tr>\n";
    print "<tr>\n";
    print "<td width="10%">&nbsp;</td>\n";
    print "<td width="80%">&nbsp;</td>\n";
    print "<td width="10%">&nbsp;</td>\n";
    print "</tr>\n";
    print "<tr>\n";
    print "<td width="10%">&nbsp;</td>\n";
    print "<td width="80%">$_[1]</td>\n";
    print "<td width="10%">&nbsp;</td>\n";
    print "</tr>\n";
    print "<tr>\n";
    print "<td width="10%">&nbsp;</td>\n";
    print "<td width="80%">&nbsp;</td>\n";
    print "<td width="10%">&nbsp;</td>\n";
    print "</tr>\n";
    print "<tr>\n";
    print "<th align="right" colspan="3" width="100%" bgcolor="#000080"\n";
    print "nowrap>\n";
    print "<a href="http://www.anmweb.com/programs/" target="top">\n";
    print "<small><font color="#FFCC33">\n";
    print "A&amp;M MailForm Ver.1.2\n";
    print "</font></small></a>&nbsp;\n";
    print "</th>\n";
    print "</tr>\n";
    print "</table>\n";
    print "</div>\n";
    print "<br /><div style="z-index:3" class="smallfont" align="center">SEO by <a rel="nofollow" href="http://www.crawlability.com/vbseo/">vBSEO</a> 3.0.0 RC3</div><br /><div style="z-index:3" class="smallfont" align="center">SEO by <a rel="nofollow" href="http://www.crawlability.com/vbseo/">vBSEO</a> 3.0.0 RC3</div><br /><div style="z-index:3" class="smallfont" align="center">SEO by <a rel="nofollow" href="http://www.crawlability.com/vbseo/">vBSEO</a> 3.0.0 RC3</div><br /><div style="z-index:3" class="smallfont" align="center">SEO by <a rel="nofollow" href="http://www.crawlability.com/vbseo/">vBSEO</a> 3.0.0 RC3</div></body>\n";
    print "</html>\n";
    exit (0);
    }

    #####################

    END OF SCRIPT

    #####################