Lunarpages Web Hosting Forum

Author Topic: novice.cgi help!!!!  (Read 7899 times)

Offline SlavicMarket

  • Trekkie
  • **
  • Posts: 13
novice.cgi help!!!!
« on: January 04, 2004, 03:02:50 PM »
:?
Can someone please help me?
Since FormMail shut down life has been hell! My forms all worked from that script, and I couldnt be more satisfied..
I looked for alternatives, such as cgiemail, but man, that script is such a pain.

I added a new cgi script, novice.cgi... however I cant get it to work.
I got the permissions correctly, the file was uploaded as ascii, did everything by the manual of the script, but it still doesnt work. Perhaps someone know CGI and can tell me what to do? The script is below
----------------------------------------------------------------------------------

#!/usr/bin/perl
## make sure the path to pearl is correct above. ##

##########################################################################################
##  FILE: novice.cgi                                                                    ##
##                                                                                      ##
##  Novice Forms                                  Version 1.1                           ##
##  © Copyright 2000-2003 Seth Michael Knorr      mail@sethknorr.com                    ##
##                                                                                      ##
##                       http://www.noviceforms.com/                                    ##
##         Please contact me with any bugs found, or any bug fixes.                     ##
##                                                                                      ##
##         This script is a spin off of the original ©Biz Mail Form                     ##
##                                                                                      ##
##########################################################################################
##                                                                                      ##
##  There is no email support provided for this script, the only support can be         ##
##  found at our web site: http://www.noviceforms.com/                                  ##
##                                                                                      ##
##                                                                                      ##
##  ANY PERSON(S) MAY USE AND MODIFY THESE SCRIPT(S) FREE OF CHARGE FOR EITHER BUSINESS ##
##  OR PERSONAL, HOWEVER AT ALL TIMES HEADERS AND COPYRIGHT MUST ALWAYS REMAIN IN TACT. ##
##                                                                                      ##
##  REDISTRIBUTION FOR PROFIT IS PROHIBITED WITH OUT THE CONSENT OF SETH KNORR.         ##
##                                                                                      ##
##  By using this code you agree to indemnify Seth M. Knorr from any liability that     ##
##  might arise from its use.                                                           ##
##                                                                                      ##
##                                                                                      ##
##########################################################################################


## $sendto and $ccto is Where form submissions will be sent,         ##
## (REMEMBER THE \ BEFORE THE @ SIGN example: \@)                    ##
## $sendto = "sendto\@yourdomain.com";  CORRECT WAY!!!!              ##
## $sendto = "sendto@yourdomain.com";  WILL NOT WORK!!!!             ##


   $sendto = "orderforms\@slavicmarket.biz";   ## (REMEMBER THE \ BEFORE THE @ SIGN)##

   $ccto = "orderforms\@slavicmarket.biz";        ## (REMEMBER THE \ BEFORE THE @ SIGN)##


## $mailprog  Is the path to sendmail or your SMTP server - on your server or web space ##

        $mailprog = "/usr/lib/sendmail";


## to use @okurls to verify the url the form is submited by; set $setokurl to 1 and      ##
## set $setokurl to 0 if you do not want to use @okurls to verfiy form submission URL    ##

        $setokurl = "0";

        @okurls = ("http://www.yourdomain.com", "http://yourdomain.com", "34.344.344.344");



####################################################################################################
#############                                                                          #############
#############   N O   N E E D   T O   E D I T   A N Y   V A R I A B L E S   B E L O W  #############
#############                                                                          #############
####################################################################################################


    my($offset) = @_;
    $offset = $offset * 86400;

    my($sec, $min, $hour, $dayofmonth, $mon, $year, $weekday, $dayofyear, $IsDST) = localtime(time + $offset);
    $year = $year + 1900;
    my(@months) = ("JA", "FB", "MR", "AP", "MY", "JN", "JL", "AG", "SP", "Oc", "NV", "DE");
    my($monthname) = $months[$mon];
    my(@monthsnum) = ("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12");
    my($monthnamenum) = $monthsnum[$mon];

    my(@monthsactual) = ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
    my($monthnameactual) = $monthsactual[$mon];


    my(@days) = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");
    my($dayname) = $days[$weekday-1];

${'monthname'} = "$monthname";
${'monthnamenum'} = "$monthnamenum";
${'dayofmonth'} = "$dayofmonth";

${'hour'} = "$hour";

if ($hour <= 13){
$hour = "$hourplus";
$newhour = ($hourplus-12);

}else{
$newhour = "$hour";
}


if ($min <= 9){
$newmin = "0$min";
}else{
$newmin = "$min";
}


$footer = "<br><br><br><br><br><center><font face='Arial'><a href='http://www.noviceforms.com/' target='_blank'><font color='#ff0000'>Form processing script provided by Novice Forms</font></a> </center></font>";

$backbutton = "<br><br><b>Hit your browsers back button and resubmit the form.</b>";

if($ENV{'REQUEST_METHOD'} eq "GET") {
&
}else{
&get_form_data;
&
}

sub nopost {

print "Content-type: text/html\n\n";

print <<"MYMAINtext";

<html>

<head>
<title>Novice Forms & & & &  Version 1.1 </title>
</head><body bgcolor="#cfcfcf">
<center>


<table width=500 border=1><tr><td bgcolor="#000080">
<br><br>
<font face="Arial" color="#ffffff">
<center>
Novice Forms & & & & & & &  Version 1.1<br><br>

 & Copyright 2000-2003 Seth Knorr<br><br>
A free download of this script can be found at: <a href="http://www.noviceforms.com/" target="_blank"> <font color="#ff0000"><b> http://www.noviceforms.com/ </b></font></a>
</font></center>
<br><br>
</td></tr></table>
</center>

</body></html>

MYMAINtext

exit;

}


sub get_form_data {

   read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
   @pairs=split(/&/,$buffer);
   foreach $pair (@pairs)
   {
      @a = split(/=/,$pair);
      $name=$a[0];
      $value=$a[1];
      $value2=$a[1],;
      $name =~ s/\+/ /g;
      $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
      $value =~ s/~!/ ~!/g;
      $value =~ s/\+/ /g;
      $value =~ s/(\r)+/\-\-/g;
      $value =~ s/\n+//g;
      $value =~ s/(\-\-)+/\n/g;
                $value =~ s|\&|\&\;|g;
                $value =~ s|<|\<\;|g;
                $value =~ s|>|\>\;|g;
                $value =~ s|\n|<br>\n|g;

      push (@POST,$name);
      push (@POST,$value);


   }
   %POST=@POST;
   %POST;
   %formname=@formname;
   %formname;
   %formvalue=@formvalue;
   %formvalue;


   }


sub main {

    @sortfields = split(/,/,$POST{'sort'});

    @required = split(/,/,$POST{'required'});

for ($indexreq = 0; $indexreq < @required; $indexreq++) {
$myrequired = $required[$indexreq];
$myformreq = $POST{"$myrequired"};


  if ($myrequired eq "email"){
      if (!$myformreq || $myformreq =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/ || $myformreq !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z0-9]+)(\]?)$/){
      &missing_email;
      }
  }
  elsif (!$myformreq){
  &format_error;
  }

}


## START $setokurl  ##

                     if ($setokurl =~ /1/){

  $url = "0";
  $referer = "$ENV{'HTTP_REFERER'}";


  foreach $myokurls (@okurls) {
     if ($referer =~ /$myokurls/) {
      $url = "1";
      }

  }
  if ( $url == 0) {

  &bad_okurl;
  }

                     }


## END $setokurl  ##


         &


         if (! $POST{'success_page'}){
         &
         }else{
         print "Location: $POST{'success_page'}\n\n";
         }



}  ## END "SUB MAIN" ##

sub success {


print "Content-type: text/html\n\n";

   print <<"Myformatsuccess";

<html>
<head>
<title>Thank You.</title>
</head>
<body>
<BR><BR><CENTER>
<h2>Your form has been submitted successfully!</h2>


</CENTER>


$footer

</body>
</html>

Myformatsuccess


exit;

}


sub missing_email {

$title = "<title>Missing or invalid format of email!</title>";
$errormessage = "<h2>Missing or invalid format of email.</h2><b>The email Field must be filled in and in the proper format!</b>";

print "Content-type: text/html\n\n";

   print <<"missingemailERROR";

$title

$errormessage

$backbutton

$footer

missingemailERROR

exit;

}


sub bad_okurl {

$title = "<title>Invalid Reffering URL.</title>";
$errormessage = "<h2>Invalid Referring URL.</h2><b>If you are the administrator, edit the \@okurls in the novice.cgi script or turn this feature off.</b>";


print "Content-type: text/html\n\n";

   print <<"badurlERROR";

$title
$errormessage
$footer

badurlERROR

exit;

}



sub format_error {


for ($indexreq = 0; $indexreq < @required; $indexreq++) {
$myrequired = $required[$indexreq];
$myformreq = $POST{"$myrequired"};

if (!$myformreq){

$REQUIRED{"$indexreq"} = "${'LISTITEMS'}<li> $myrequired";
${'LISTITEMS'} = $REQUIRED{"$indexreq"};

}
}


$title = "<title>Missing form fields!</title>";
$errormessage = "<h2>Missing form fields!</h2><b>The Below Required Fields Where Left Blank:</b><br><br>${'LISTITEMS'}<br><br><b>Hit your browsers back button and resubmit the form.</b>";

print "Content-type: text/html\n\n";

   print <<"MyformatERROR";

$title
$errormessage
$backbutton
$footer

MyformatERROR

exit;

}


sub notify{


   $msgSubject = "Novice Form Submission" . "$POST{'subject'}";

    open(MAIL, "|$mailprog -t") || die "Can't open $mailprog!\n";
   print MAIL "To: $sendto\n";
        if ($ccto){
        print MAIL "Cc: $ccto\n";
        }
   print MAIL "From: $POST{'email'}\n";
   print MAIL "Subject: $msgSubject\n";
   print MAIL "The form below was submited by $POST{'email'} form Ip address: $ENV{'REMOTE_ADDR'} on $monthnameactual $dayofmonth, $year at $newhour:$newmin\n";
   print MAIL "-------------------------------------------------------------------------\n\n";


if (! $POST{'sort'}) {


  for ($indexval = 0; $indexval < @formvalue; $indexval++) {
  ${'myname'} = $formname[$indexval];
  ${'myvalue'} = $formvalue[$indexval];


   if (${'myname'} eq "subject" || ${'myname'} eq "required" || ${'myname'} eq "sort" || ${'myname'} eq "success_page" || ${'myname'} eq "ccto" || ${'myname'} eq "sendto"){
   $dontrun = "1";
   }else{
   $dontrun = "";
   }

   if (! $dontrun){
   print MAIL "${'myname'}:   ${'myvalue'} \n\n";
   }
  }

}else{  ##ELSE IF NO SORT FIELD ##

   for ($numsort = 0; $numsort < @sortfields; $numsort++) {
   $sfield = $sortfields[$numsort];
   ${'sfieldvalue'} = $POST{"$sfield"};
   ${'sfield'} = "$sfield";

   print MAIL "${'sfield'}:   ${'sfieldvalue'} \n\n";

   }

} ## END ELSE IF SORT FIELD ##

   close MAIL;



} ## END &
---------------------------------------------------------------------------------

Thanks for your help,

Alex

leighsww

  • Guest
novice.cgi help!!!!
« Reply #1 on: January 04, 2004, 04:28:27 PM »
This line ...

@okurls = ("http://www.yourdomain.com", "http://yourdomain.com", "34.344.344.344");

needs to have "yourdomain.com" replaced with your actual domain name.

Don't forget to upload in ASCII and chmod to 755.

Let's try that and see if that makes it work.  If still other problems, post again.  Make sure to post what your errors are saying so we can further narrow down the problem.

leighsww

  • Guest
novice.cgi help!!!!
« Reply #2 on: January 04, 2004, 04:31:01 PM »
Okay, wait.  I see that you have your "setokurl" set to zero, so I guess that won't matter.  Try putting a # in front of the "@okurl=("http: ...) code.

Offline mark363

  • Über Jedi
  • *****
  • Posts: 2589
novice.cgi help!!!!
« Reply #3 on: January 04, 2004, 04:32:11 PM »
I wonder if we'll ever actually meet the owner of "yourdomain.com" .... that'll be interesting  :|

leighsww

  • Guest
novice.cgi help!!!!
« Reply #4 on: January 04, 2004, 04:36:31 PM »
Also, I see one more problem. Change ...

$mailprog = "/usr/lib/sendmail";

change to ...

$mailprog = "/usr/sbin/sendmail";

the "lib" should be "sbin".

Offline mark363

  • Über Jedi
  • *****
  • Posts: 2589
novice.cgi help!!!!
« Reply #5 on: January 04, 2004, 04:38:35 PM »
leigh-- I'm surprised at you! Since when do you not use edits/Addendums the way we here at LF are so encouraged? Have you learned nothing in your 727 posts? Poor leigh... we may need that whip again...  :poke:

leighsww

  • Guest
novice.cgi help!!!!
« Reply #6 on: January 04, 2004, 04:42:21 PM »
LOL ... actually, mussavcom, I didn't know you were posting at the same time as me, so I made the change at the exact same time you posted.  But, because you have faster fingers than me, you must have hit the submit just a millisecond faster.

Also, the only thing I edited on that post was "okurl" to "setokurl", so there is nothing in my post that I would have changed to make your post look dipsy.  :)

But anyway, I don't use addendums, I use * edited - as you must know by now.  :poke:

Offline SlavicMarket

  • Trekkie
  • **
  • Posts: 13
nope
« Reply #7 on: January 04, 2004, 04:48:37 PM »
Still doesnt work...
Everytime I keep getting the same error in the error log

Premature end of script headers: /home/slavic2/public_html/cgi-bin/novice.cgi
File does not exist: /home/slavic2/public_html/500.shtml

Offline mark363

  • Über Jedi
  • *****
  • Posts: 2589
novice.cgi help!!!!
« Reply #8 on: January 04, 2004, 04:48:37 PM »
That's not what I mean...
Quote from: leighsww
Also, I see one more problem. Change ...

$mailprog = "/usr/lib/sendmail";

change to ...

$mailprog = "/usr/sbin/sendmail";

You had that post, then the one that said 'the "lib" should be "sbin".' Then, you must've deleted the second post and stuck that sentence into the first post. Unless I'm going crazy  :o , but why :o would y:o o :o u :o think th :o at? :o

leighsww

  • Guest
novice.cgi help!!!!
« Reply #9 on: January 04, 2004, 04:50:43 PM »
Ha, Ha!!  Okay, you've caught me.  Take me to the whipping room.

Slavicmarket - make sure your html "action" is pointing correctly to where the script resides in your cgi-bin.

** EDITED - provide the link to your form on your website so we can check out the html code.

Offline mark363

  • Über Jedi
  • *****
  • Posts: 2589
novice.cgi help!!!!
« Reply #10 on: January 04, 2004, 04:53:10 PM »
Quote from: leighsww
Slavicmarket - make sure your html "action" is pointing correctly to where the script resides in your cgi-bin.

Oh, sure, try to subtly change the subject!  :whip:  You'll pay for this!!

Using my magic powers, I have put an evil spell on you. Now, everything you buy will suddenly cost ten cents extra!!!  :poke:

leighsww

  • Guest
novice.cgi help!!!!
« Reply #11 on: January 04, 2004, 04:55:18 PM »
mussavcom - stop interrupting my posts!!  You see, now every one of them has a "last edited by ..." line.  You little rascal!

Leave me alone, right now, so I can help SlavicMarket in peace!!  OR, meet me in the CHAT or FUN forum and I'll have at you there.  :poke:

*edited - oh, I've gotten off pretty cheap with just ten cents. You must not want to punish me that bad.  :love:

Offline SlavicMarket

  • Trekkie
  • **
  • Posts: 13
novice.cgi help!!!!
« Reply #12 on: January 04, 2004, 04:59:46 PM »
Yup, doubled checked... the pathway to the script is correct...

Any other ideas?

leighsww

  • Guest
Re: nope
« Reply #13 on: January 04, 2004, 05:18:38 PM »
Quote from: SlavicMarket
Still doesnt work...
Everytime I keep getting the same error in the error log

Premature end of script headers: /home/slavic2/public_html/cgi-bin/novice.cgi
File does not exist: /home/slavic2/public_html/500.shtml


Hmmm. Okay, I know it says to not forget to put the \@, but try taking out the backslash.  I think that may only be necessary on certain types of servers.

So try ...

$sendto = "orderforms@slavicmarket.biz"; ## (REMEMBER THE \ BEFORE THE @ SIGN)##

$ccto = "orderforms@slavicmarket.biz"; ## (REMEMBER THE \ BEFORE THE @ SIGN)##


and see if that works.

Danielle

  • Guest
novice.cgi help!!!!
« Reply #14 on: January 04, 2004, 05:40:58 PM »
Hi SlavicMarket,

I have looked at your account, and I do not see a file named 500.html in public_html.  You do get the error message:

File does not exist: /home/slavic2/public_html/500.shtml

This means that you do not have a file named 500.shtml in public_html.  Since I have already checked this is the case, you may have the file only on your local computer and need to upload it. Alternatively, you may not have created it or may have it in another folder.  Until you have this file (whatever it is supposed to do), you will continue to receive this error message.

A way to always check if a file exists or not is to simply go into your browser and type the absolute url to that file.  In this instance that would be http://slavicmarket.biz/500.shtml  This returns the same error that it wasn't found.

I hope this helps.