#!/usr/bin/perl
$thisdir = "/var/www/vhosts/bariloche.com.ar/lactancia";
$templatefile = "$thisdir/template_contactenos.htm";
$mailprog = "/usr/sbin/sendmail";
&Parse;
if ($FORM{step} eq 1) {
if (!$FORM{nombre}) {
$error = "Ingrese su nombre para realizar la consulta";
}
elsif (!$FORM{pais}) {
$error = "Ingrese su país de residencia para realizar la consulta";
}
elsif (!$FORM{email}) {
$error = "Ingrese su email para realizar la consulta";
}
elsif (!$FORM{consulta}) {
$error = "Ingrese su consulta para poder enviarla";
}
else {
$from = "www\@bariloche.com.ar";
$subject = "Consulta de ''$FORM{nombre} $FORM{apellido}''";
$email = "muleo\@bariloche.com.ar";
open (MAIL,"|$mailprog -oi -t -f $from");
print MAIL qq~To: $email
From: "$FORM{nombre}" <$FORM{email}>
Subject: $subject
Solicitud de consulta desde el sitio Web
Nombre: $FORM{nombre}
E-Mail: $FORM{email}
País de residencia: $FORM{pais}
Ciudad de residencia: $FORM{ciudad}
Telefono: $FORM{telefono}
Nombre del bebe: $FORM{bebe}
Fecha de nacimiento: $FORM{nacio}
Peso al nacer: $FORM{peso}
Consulta:
$FORM{consulta}
~;
close (MAIL);
$templatefile = "$thisdir/template_contactenos_listo.htm";
}
}
print "Content-type: text/html\n\n";
my %namespace = (
NOMBRE => $FORM{nombre},
EMAIL => $FORM{email},
PAIS => $FORM{pais},
CIUDAD => $FORM{ciudad},
TELEFONO => $FORM{telefono},
BEBE => $FORM{bebe},
NACIO => $FORM{nacio},
PESO => $FORM{peso},
CONSULTA => $FORM{consulta},
ERROR => $error,
NOTICIAS => $noticias
);
&Template($templatefile,\%namespace);
exit;
sub Template {
my ($templatefile,$r_namespace) = @_;
my ($template);
$| = 1;
if (!open(TEMPLATE,"$templatefile")) {
print "No puedo abrir la plantilla $templatefile";
exit;
}
else {
open(TEMPLATE,"$templatefile");
{
local($/) = undef;
$template = ;
}
close(TEMPLATE);
}
$template =~ s/\$([A-Z]+)/$r_namespace->{$1}/g;
print $template;
}
sub Parse {
local($name, $value, $buffer, $pair, $hold, @pairs);
if($ENV{'REQUEST_METHOD'} eq 'GET') {
@pairs = split(/&/, $ENV{'QUERY_STRING'});
} else {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
}
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/\n//g;
$value =~ s///g;
$value =~ s/\s-\w.+//g;
$value =~ s/system\(.+//g;
$value =~ s/grep//g;
$value =~ s/\srm\s//g;
$value =~ s/\srf\s//g;
$value =~ s/\.\.([\/\:]|$)//g;
$value =~ s/< *((SCRIPT)|(APPLET)|(EMBED))[^>]+>//ig;
$name =~ s/<.+>?//g;
$name =~ s///g;
$name =~ s/^\s-\w.+//g;
$name =~ s/system\(.+//g;
$name =~ s/grep//g;
$name =~ s/\srm\s//g;
$name =~ s/\srf\s//g;
$name =~ s/\.\.([\/\:]|$)//g;
$name =~ s/< *((SCRIPT)|(APPLET)|(EMBED))[^>]+>//ig;
$FORM{$name} = $value;
}
}