CGI script wont work.

  • ajdegans
  • Born
  • Born
  • ajdegans
  • Posts: 4
  • Loc: netherlands

Post 3+ Months Ago

Hi, im fairly new to CGI scripting. So i took some parts of code and made email forms.

One works!! But the second won't work. the cgi below is that particular file:

Code: [ Select ]
#!/usr/bin/perl
$sendmail_location = "/usr/sbin/sendmail";

read(STDIN, $formbuffer, $ENV{'CONTENT_LENGTH'});
@formpairs = split(/&/, $formbuffer);
foreach $formpair (@formpairs) {
    ($formname, $formvalue) = split(/=/, $formpair);
    $formvalue =~ tr/+/ /;
    $formvalue =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  $formvalue =~ s/<([^>]|\n)*>//g;
    if ($FORM{$formname}) { $FORM{$formname} = $FORM{$formname}.",".$formvalue; }
    else { $FORM{$formname} = $formvalue; }
}


foreach $require (split(/\,/,$FORM{'require'})) {
if ($require eq "email" || $require eq "to") {
unless ($FORM{$require}=~ /\@/ && $FORM{$require}=~ /\./) {
$error .= "Error in $require.<BR>";
}
}
unless ($FORM{$require}) {
$error .= "Missing $require.<BR>";
}
}

unless ($FORM{'sendpage'}) {
$error .= "Missing confirmation page url<BR>";
}

if ($error) {
print "Content-type: text/html\n\n";
print qq(<CENTER><FONT COLOR="#000000"><B>Error</B><BR>-------------------------<BR>$error</FONT></CENTER>);
exit;
}

if ($FORM{'jounaam'}) {
$yeshow = qq(
Naam, $FORM{'jounaam'}
);
}

if ($FORM{'pakket'}) {
$yeshow = qq(
Pakket, $FORM{'pakket'}
);
}

if ($FORM{'email'}) {
$yeshow = qq(
E-mail, $FORM{'email'}
);
}

if ($FORM{'adres'}) {
$yeshow = qq(
Adres, $FORM{'adres'}
);
}

if ($FORM{'postcode'}) {
$yeshow = qq(
Postcode, $FORM{'postcode'}
);
}

if ($FORM{'plaats'}) {
$yeshow = qq(
Plaats, $FORM{'plaats'}
);
}

if ($FORM{'land'}) {
$yeshow = qq(
Land, $FORM{'land'}
);
}

if ($FORM{'telefoon'}) {
$yeshow = qq(
Telefoon, $FORM{'telefoon'}
);
}

if ($FORM{'gsm'}) {
$yeshow = qq(
gsm, $FORM{'gsm'}
);
}

if ($FORM{'message'}) {
$yeshow = qw(
From, $FORM{'message'}
);
}

if ($FORM{'hoekomjehier'}) {
$yeshow = qq(
Hoe kom je hier, $FORM{'hoekomjehier'}
);
}

open (MAIL, "|$sendmail_location -t") || die "Can't open $sendmail_location!\n";
print MAIL "From: $FORM{'jounaam'} <$FORM{'email'}>\n";
print MAIL "To: $FORM{'to'}\n";
print MAIL "Subject: $FORM{'subject'}\n\n";
print MAIL <<EOF;
$yeshow

$FORM{'message'}


EOF
close (MAIL);

print "Location: $FORM{'sendpage'}\n\n";
exit;
  1. #!/usr/bin/perl
  2. $sendmail_location = "/usr/sbin/sendmail";
  3. read(STDIN, $formbuffer, $ENV{'CONTENT_LENGTH'});
  4. @formpairs = split(/&/, $formbuffer);
  5. foreach $formpair (@formpairs) {
  6.     ($formname, $formvalue) = split(/=/, $formpair);
  7.     $formvalue =~ tr/+/ /;
  8.     $formvalue =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  9.   $formvalue =~ s/<([^>]|\n)*>//g;
  10.     if ($FORM{$formname}) { $FORM{$formname} = $FORM{$formname}.",".$formvalue; }
  11.     else { $FORM{$formname} = $formvalue; }
  12. }
  13. foreach $require (split(/\,/,$FORM{'require'})) {
  14. if ($require eq "email" || $require eq "to") {
  15. unless ($FORM{$require}=~ /\@/ && $FORM{$require}=~ /\./) {
  16. $error .= "Error in $require.<BR>";
  17. }
  18. }
  19. unless ($FORM{$require}) {
  20. $error .= "Missing $require.<BR>";
  21. }
  22. }
  23. unless ($FORM{'sendpage'}) {
  24. $error .= "Missing confirmation page url<BR>";
  25. }
  26. if ($error) {
  27. print "Content-type: text/html\n\n";
  28. print qq(<CENTER><FONT COLOR="#000000"><B>Error</B><BR>-------------------------<BR>$error</FONT></CENTER>);
  29. exit;
  30. }
  31. if ($FORM{'jounaam'}) {
  32. $yeshow = qq(
  33. Naam, $FORM{'jounaam'}
  34. );
  35. }
  36. if ($FORM{'pakket'}) {
  37. $yeshow = qq(
  38. Pakket, $FORM{'pakket'}
  39. );
  40. }
  41. if ($FORM{'email'}) {
  42. $yeshow = qq(
  43. E-mail, $FORM{'email'}
  44. );
  45. }
  46. if ($FORM{'adres'}) {
  47. $yeshow = qq(
  48. Adres, $FORM{'adres'}
  49. );
  50. }
  51. if ($FORM{'postcode'}) {
  52. $yeshow = qq(
  53. Postcode, $FORM{'postcode'}
  54. );
  55. }
  56. if ($FORM{'plaats'}) {
  57. $yeshow = qq(
  58. Plaats, $FORM{'plaats'}
  59. );
  60. }
  61. if ($FORM{'land'}) {
  62. $yeshow = qq(
  63. Land, $FORM{'land'}
  64. );
  65. }
  66. if ($FORM{'telefoon'}) {
  67. $yeshow = qq(
  68. Telefoon, $FORM{'telefoon'}
  69. );
  70. }
  71. if ($FORM{'gsm'}) {
  72. $yeshow = qq(
  73. gsm, $FORM{'gsm'}
  74. );
  75. }
  76. if ($FORM{'message'}) {
  77. $yeshow = qw(
  78. From, $FORM{'message'}
  79. );
  80. }
  81. if ($FORM{'hoekomjehier'}) {
  82. $yeshow = qq(
  83. Hoe kom je hier, $FORM{'hoekomjehier'}
  84. );
  85. }
  86. open (MAIL, "|$sendmail_location -t") || die "Can't open $sendmail_location!\n";
  87. print MAIL "From: $FORM{'jounaam'} <$FORM{'email'}>\n";
  88. print MAIL "To: $FORM{'to'}\n";
  89. print MAIL "Subject: $FORM{'subject'}\n\n";
  90. print MAIL <<EOF;
  91. $yeshow
  92. $FORM{'message'}
  93. EOF
  94. close (MAIL);
  95. print "Location: $FORM{'sendpage'}\n\n";
  96. exit;


Maybe someone can find wrong code. Me i think the part with:
Code: [ Select ]
if ($FORM{'jounaam'}) {
$yeshow = qq(
Naam, $FORM{'jounaam'}
);
}

if ($FORM{'pakket'}) {
$yeshow = qq(
Pakket, $FORM{'pakket'}
);
}

if ($FORM{'email'}) {
$yeshow = qq(
E-mail, $FORM{'email'}
);
}

if ($FORM{'adres'}) {
$yeshow = qq(
Adres, $FORM{'adres'}
);
}

if ($FORM{'postcode'}) {
$yeshow = qq(
Postcode, $FORM{'postcode'}
);
}

if ($FORM{'plaats'}) {
$yeshow = qq(
Plaats, $FORM{'plaats'}
);
}

if ($FORM{'land'}) {
$yeshow = qq(
Land, $FORM{'land'}
);
}

if ($FORM{'telefoon'}) {
$yeshow = qq(
Telefoon, $FORM{'telefoon'}
);
}

if ($FORM{'gsm'}) {
$yeshow = qq(
gsm, $FORM{'gsm'}
);
}

if ($FORM{'message'}) {
$yeshow = qw(
From, $FORM{'message'}
);
}

if ($FORM{'hoekomjehier'}) {
$yeshow = qq(
Hoe kom je hier, $FORM{'hoekomjehier'}
);
}
  1. if ($FORM{'jounaam'}) {
  2. $yeshow = qq(
  3. Naam, $FORM{'jounaam'}
  4. );
  5. }
  6. if ($FORM{'pakket'}) {
  7. $yeshow = qq(
  8. Pakket, $FORM{'pakket'}
  9. );
  10. }
  11. if ($FORM{'email'}) {
  12. $yeshow = qq(
  13. E-mail, $FORM{'email'}
  14. );
  15. }
  16. if ($FORM{'adres'}) {
  17. $yeshow = qq(
  18. Adres, $FORM{'adres'}
  19. );
  20. }
  21. if ($FORM{'postcode'}) {
  22. $yeshow = qq(
  23. Postcode, $FORM{'postcode'}
  24. );
  25. }
  26. if ($FORM{'plaats'}) {
  27. $yeshow = qq(
  28. Plaats, $FORM{'plaats'}
  29. );
  30. }
  31. if ($FORM{'land'}) {
  32. $yeshow = qq(
  33. Land, $FORM{'land'}
  34. );
  35. }
  36. if ($FORM{'telefoon'}) {
  37. $yeshow = qq(
  38. Telefoon, $FORM{'telefoon'}
  39. );
  40. }
  41. if ($FORM{'gsm'}) {
  42. $yeshow = qq(
  43. gsm, $FORM{'gsm'}
  44. );
  45. }
  46. if ($FORM{'message'}) {
  47. $yeshow = qw(
  48. From, $FORM{'message'}
  49. );
  50. }
  51. if ($FORM{'hoekomjehier'}) {
  52. $yeshow = qq(
  53. Hoe kom je hier, $FORM{'hoekomjehier'}
  54. );
  55. }


init is the badass thing but i have no clue to fix that :(

If someone could help :(

Thanks in advance
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9092
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

When you run this script are you getting errors? or what exactly is not working?
  • ajdegans
  • Born
  • Born
  • ajdegans
  • Posts: 4
  • Loc: netherlands

Post 3+ Months Ago

I get this error page

Code: [ Select ]
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, helpdesk@flexwebhosting.nl and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.



--------------------------------------------------------------------------------

Apache/1.3.27 Server at www.zerocom.nl Port 80
  1. Internal Server Error
  2. The server encountered an internal error or misconfiguration and was unable to complete your request.
  3. Please contact the server administrator, helpdesk@flexwebhosting.nl and inform them of the time the error occurred, and anything you might have done that may have caused the error.
  4. More information about this error may be available in the server error log.
  5. --------------------------------------------------------------------------------
  6. Apache/1.3.27 Server at www.zerocom.nl Port 80


I had it working somehow but then all form fields remained blanc. so the entire form was of no use... it didnt show up in the email. So basicly it funcioned but only a part...
  • bestempire
  • Newbie
  • Newbie
  • bestempire
  • Posts: 7

Post 3+ Months Ago

Check if you have CHMODed the file correctly and the path to Perl is right
  • ajdegans
  • Born
  • Born
  • ajdegans
  • Posts: 4
  • Loc: netherlands

Post 3+ Months Ago

i checked chmod

its: -rwxr-xr-x (755)

In the manual for another email script it works...

Also the path to perl is correct :)
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9092
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Do you have access to your server error log? More information should be there that would explain exactly why it does not work.
  • ajdegans
  • Born
  • Born
  • ajdegans
  • Posts: 4
  • Loc: netherlands

Post 3+ Months Ago

i got this from the error_log

Code: [ Select ]
syntax error at bestelformulier.cgi line 97, near ")("
Execution of bestelformulier.cgi aborted due to compilation errors.

[Thu Sep 18 17:19:10 2003] [error] [client 62.131.20.6] Premature end of script headers: /home/virtual/site59/fst/var/www/cgi-bin/bestelformulier.cgi
  1. syntax error at bestelformulier.cgi line 97, near ")("
  2. Execution of bestelformulier.cgi aborted due to compilation errors.
  3. [Thu Sep 18 17:19:10 2003] [error] [client 62.131.20.6] Premature end of script headers: /home/virtual/site59/fst/var/www/cgi-bin/bestelformulier.cgi


i guess i wrote the .cgi wrong but i have no clue whats wrong since i hardly know cgi... :)

Post Information

  • Total Posts in this topic: 7 posts
  • Users browsing this forum: No registered users and 124 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.