guestbook/src/post.cgi

69 lines
1.6 KiB
Perl

#!/usr/bin/perl
use POSIX qw(strftime);
use CGI;
use DBD::Pg;
my $q = CGI->new;
my $username = "CHANGEME";
my $password = "CHANGEME";
my $host = "CHANGEME";
my $dbh = DBI->connect("dbi:Pg:dbname=guestbook;host=$host;port=5432",
$username,
$password,
{AutoCommit => 1, RaiseError => 1, PrintError => 1}
);
my $now = time();
my $Date = strftime('%Y-%m-%d', localtime($now));
print $q->header;
my $Name = $q->param("name");
my $Website = $q->param("website");
my $Email = $q->param("email");
my $Comment = $q->param("comment");
my $Country = $q->param("country");
my $Captcha = $q->param("captcha");
if ($Name eq "") {
print "Eres marrón\n";
die;
}
if ($Comment eq "") {
print "Pero di algo desgraciado\n";
die;
}
if (!$Website eq "") {
unless ($Website =~ /^(http|https):\/\//) {
print "El sitio web introducido no es valido (no empieza por http:// o https://)";
die;
}
}
if (!$Email eq "") {
unless ($Email =~ /.*@.*.\..*/ || $Email eq "sage") {
print "Pon un correo maricon";
die;
}
}
if (length($Comment) > 200 ||length($Email) > 25 ||length($Name) > 25) {
print "Enhorabuena has superado el límite de caracteres";
die;
}
unless ($Captcha eq "Sol" || $Captcha eq "sol") {
print "El filtro funciona bien :)";
die;
}
my $req = $dbh->prepare('INSERT INTO guestbook(NAME, EMAIL, COMMENT, DATE, COUNTRY, website) VALUES (?, ?, ?, ?, ?, ?)');
$req->execute($Name, $Email, $Comment, $Date, $Country, $Website);
print "<head>";
print "<meta http-equiv=\"refresh\" content=\"0; url=/guestbook/guestbook.cgi\" />";
print "</head>";
print "<p>Añadido satisfactoriamente</p>";