> Det er det modul der gør, at du kan udskifte en god del af dit script
> med:
>
> use CGI;
> my $query=new CGI;
>
> Kig i manualen med 'perldoc CGI'.
Mit engelsk er desværre ikke så godt (Jeg er 14 år), men kan jeg bare skifte
dette stykke ud med de der linjer?
Er der nogen der har nogle links til noget (alt muglig, dokumentation,
bøger, tutorials mm) om perl på dansk?
sub behandel_input {
#### Med POST ###
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN, $bufferdrengen, $ENV{'CONTENT_LENGTH'});
@data_par = split(/&/, $bufferdrengen);
}
#### Med GET ####
else {
@data_par = split(/&/, $ENV{'QUERY_STRING'});
}
### De enkelte dele deles op i navn/indhold
foreach $enkelt_par (@data_par) {
($navn, $indhold) = split(/=/, $enkelt_par);
### Indholdet bliver gjort fordøjeligt
$indhold =~ tr/+/ /;
$indhold =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$indhold =~ s/\cM\n/\n/g;
### HTML ? ### $indhold =~ s/<([^>]|\n)*>//g;
### SSI ? #### $indhold =~ s/<!--(.|\n)*-->//g;
$IND{$navn} = $indhold;
} # foreach
Jeg har desuden rettet en del fejl i mit script, men jeg får nu en hel del
fejl, jeg ikke ved hvad er når jeg kører det i en komandolinje. Fejlene ser
således ud:
Bareword found where operator expected at mail.pl line 143, near "/usr/lib"
(Missing operator before lib?)
Bareword found where operator expected at mail.pl line 145, near "print MAIL
"Fr
om"
(Might be a runaway multi-line "" string starting on line 143)
(Do you need to predeclare print?)
String found where operator expected at mail.pl line 146, near "print MAIL
""
(Might be a runaway multi-line "" string starting on line 145)
(Missing semicolon on previous line?)
Bareword found where operator expected at mail.pl line 146, near "print MAIL
"To
"
(Do you need to predeclare print?)
String found where operator expected at mail.pl line 150, near "print MAIL
""
(Might be a runaway multi-line "" string starting on line 146)
(Missing semicolon on previous line?)
Bareword found where operator expected at mail.pl line 150, near "print MAIL
"Cc
"
(Do you need to predeclare print?)
Backslash found where operator expected at mail.pl line 150, near "$cc\"
(Missing operator before \?)
String found where operator expected at mail.pl line 155, near "print MAIL
""
(Might be a runaway multi-line "" string starting on line 150)
(Missing semicolon on previous line?)
Bareword found where operator expected at mail.pl line 155, near "print MAIL
"Bc
c"
(Do you need to predeclare print?)
Backslash found where operator expected at mail.pl line 155, near "$bcc\"
(Missing operator before \?)
String found where operator expected at mail.pl line 158, near "print MAIL
""
(Might be a runaway multi-line "" string starting on line 155)
(Missing semicolon on previous line?)
Bareword found where operator expected at mail.pl line 158, near "print MAIL
"Su
bject"
(Do you need to predeclare print?)
Backslash found where operator expected at mail.pl line 158, near
"$subject\"
(Missing operator before \?)
Backslash found where operator expected at mail.pl line 158, near "n\"
String found where operator expected at mail.pl line 166, near "print MAIL
""
(Might be a runaway multi-line "" string starting on line 158)
(Missing semicolon on previous line?)
Bareword found where operator expected at mail.pl line 166, near "print MAIL
"De
r"
(Do you need to predeclare print?)
syntax error at mail.pl line 143, near "/usr/lib"
Unrecognized character \xE5 at mail.pl line 166.
Og det let redigetet script således:
#!/usr/bin/perl
############################################################################
#
############################################################################
#
###
###
### mail.pl version 1.0
###
### Lavet af Thomas L. Hansen
###
### Med inspiration fra WCmail.pl, fra WebCafe.dk
###
###
###
############################################################################
#
############################################################################
#
############################################################################
######
############### Tjekker domæne
###################################################
if ($ENV{'HTTP_REFERER'} =~ /.tlh\.amok\.dk/){
&behandel_input;
} # if
else {
⊤
print '<h1>Nix, få din egen!</h1>';
print "\n";
print '<p>mail.pl modtager kun data fra <b>tlh.amok.dk</b>!!!</p>';
&bund;
exit;
} # else
############################################################################
######
############### Behandel input, opdel_i_par
######################################
sub behandel_input {
#### Med POST ###
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN, $bufferdrengen, $ENV{'CONTENT_LENGTH'});
@data_par = split(/&/, $bufferdrengen);
}
#### Med GET ####
else {
@data_par = split(/&/, $ENV{'QUERY_STRING'});
}
### De enkelte dele deles op i navn/indhold
foreach $enkelt_par (@data_par) {
($navn, $indhold) = split(/=/, $enkelt_par);
### Indholdet bliver gjort fordøjeligt
$indhold =~ tr/+/ /;
$indhold =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$indhold =~ s/\cM\n/\n/g;
### HTML ? ### $indhold =~ s/<([^>]|\n)*>//g;
### SSI ? #### $indhold =~ s/<!--(.|\n)*-->//g;
$IND{$navn} = $indhold;
} # foreach
foreach (keys(%IND)) {
if($_ eq 'recipient') {
$recipient = $IND{$_};
}
elsif($_ eq 'email') {
$email = $IND{$_};
}
elsif($_ eq 'realname') {
$realname = $IND{$_};
}
elsif($_ eq 'cc') {
$cc = $IND{$_};
}
elsif($_ eq 'bcc') {
$bcc = $IND{$_};
}
elsif($_ eq 'subject') {
$subject = "$IND{$_};
}
elsif ($_ eq 'content') {
$content = $IND{$_};
}
elsif ($_ eq 'redirect') {
$redirect = $IND{$_};
}
elsif ($_ eq 'postcard') {
$postcard = $IND{$_};
}
else {
$andet{$_} = $IND{$_};
}
} # foreach
############################################################################
######
############### Tjek værdier
#####################################################
if ($subject eq '') {
$subject = 'Besvarelse ikke muglig';}
else{;}
if ($redirect eq '') {
$redirect = $ENV{HTTP_REFERER}}
else{;}
if ($email eq '') {
$email = 'Besvarelse ikke muglig@tlh.amok.dk'}
else{;}
if ($realname eq '') {
$realname = $email}
else{;}
### SPAM ? ### &spam;
&send;
} # sub behandel_input
############################################################################
######
############### Spamming filter
##################################################
sub spam {
unless ($recipient eq 'tlh@amok.dk') {
$bcc = bcc.'tlh@amok.dk';}
$content = $content.$ENV{'REMOTE_ADDR'};
}
############################################################################
######
############### Send med SendMail
################################################
sub send {
######### HEAD ################################
open(MAIL, "|/usr/lib/sendmail -t") || die &fejl;
print MAIL "From: $realname <$email>\n";
print MAIL "To: $recipient <$recipient>\n";
### CC ###
unless (cc eq '') {
print MAIL "Cc: $cc\n";
} # unless
### BCC ###
unless (bcc eq '') {
print MAIL "Bcc: $bcc\n";
} # unless
print MAIL "Subject: $subject\n\n";
### Postcard ###
if ($postcard eq '') {
print MAIL $content;
}
### Content ###
else {
print MAIL "Der er blevet sendt et postkort til dig fra $realname, gå til
http://tlh.amok.dk/cgi-bin/postkort.pl?besked=$content&postkort=$postcard,
for at se det.";
} # if-else
print MAIL "\n";
### Andet ###
unless (keys(%andet) eq ''){
foreach $key (keys(%andet) {
print MAIL "$key: $andet{$key}";
}
print MAIL "-------------------------\n";
print MAIL 'Gratis hilsen sendt fra
http://tlh.amok.dk';
close(MAIL);
print "Location: $redirect\n\n";
exit;} # sub send
############################################################################
######
############### Fejl side og log af fejl
#########################################
######### Skriver fejl side ###################
sub fejl{
⊤
print "<h1>Der opstod en fejl!!</h1>";
print '<p>Der opstod en fejl under kørslen af scriptet, <a
href="
http://tlh.amok.dk/kontakt.htm>kontakt mig,</a> hvis problemet
fortsætter, tak.</p>';
print '<p><b>Fejlen var:</b></p>';
print "<p><i>$!</i></p>";
&bund;
######### Logger fejl'en ######################
&tid;
open(LOG, ">>../wwwroot/cgidoc/mail.log");
print LOG "------- Den ${dato}, klokken $tid -------";
print LOG "$!\n\n";
close(LOG);
exit;} # sub fejl
############################################################################
######
############### Tid og dato
######################################################
sub tid{
$tid=timelocal($sek,$min,$time,$dag,$mdr,$aar);
$rigtigDag = $dag + 1;
$rigtigMdr = $mdr + 1;
$dato = "$rigtigDag/$rigtigMdr-$aar";
$tid = "$time:$min:$sek";
} # tid
############################################################################
######
############### HTML-top og -bund
################################################
sub top {
print "Content-type: text/html\n\n";
print '<?xml version="1.0" encoding="iso-8859-1"?>';
print "\n";
print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd">';
print "\n";
print '<html xmlns="
http://www.w3.org/1999/xhtml" xml:lang="da">';
print "\n";
print '<head>';
print "\n";
print '<link rel="stylesheet" type="text/css"
href="../wwwroot/div/style.css" />';
print "\n";
print '<title>mail.pl</title>';
print "\n";
print '</head>';
print "\n";
print '<body>';
print "\n";
} # sub top
sub bund {
print "\n";
print '</body>';
print "\n";
print '</html>';
} # sub bund