Source files of fsfe.org, pdfreaders.org, freeyourandroid.org, ilovefs.org, drm.info, and test.fsfe.org. Contribute: https://fsfe.org/contribute/web/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pdfpetition.pl 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/usr/bin/env perl
  2. use 5.008;
  3. =head1 DESCRIPTION
  4. PDFreaders petition form processing script.
  5. =head1 AUTHOR
  6. 2015 - Paul Hänsch <paul@fsfe.org>
  7. Previous authors: Sam Tuke <mail@samtuke.com>, extending Alexander Kahl <e-user@fsfe.org>
  8. =cut
  9. use open ":encoding(utf8)";
  10. use open IN => ":encoding(utf8)", OUT => ":utf8";
  11. use Cwd qw (abs_path);
  12. use File::Basename qw (dirname);
  13. my $root;
  14. BEGIN { $root = abs_path (dirname (__FILE__).'/..') };
  15. use lib "$root/tools";
  16. use CGI;
  17. use DateTime;
  18. use Template;
  19. use WebBuild::FormValidation;
  20. use WebBuild::DynamicContent;
  21. use strict;
  22. use warnings;
  23. use constant TEMPLATE => "$root/templates/pdfreaders-petition-mail.tt2.xml";
  24. use constant UPLOAD => "$root/upload/pdfreaders";
  25. # Start actual logic
  26. my $form = WebBuild::FormValidation->new;
  27. my $query = CGI->new;
  28. my $lang = $query->param('lang');
  29. if (not $lang) {$lang = "en";}
  30. unless ($lang =~ m/^[a-z]{2}$/ and -f "$root/campaigns/pdfreaders/petition.$lang.html")
  31. {
  32. $lang = 'en';
  33. }
  34. $form->validates_presence_of ('name');
  35. $form->validates_presence_of ('surname');
  36. $form->validates_presence_of ('country');
  37. $form->validate_format ('email', type => 'email');
  38. if ($form->has_errors)
  39. {
  40. print "Location: /campaigns/pdfreaders/petition-error.$lang.html\n\n";
  41. exit;
  42. }
  43. elsif ($query->param ('url')) # Bot!!
  44. {
  45. exit;
  46. }
  47. # Record data here
  48. my $template = Template->new ({ INCLUDE_PATH => "$root/templates" });
  49. my $mail;
  50. my $dt = DateTime->now;
  51. my $data = { country => $query->param ('country'),
  52. date => sprintf ('%d-%.2d-%.2d', $dt->year, $dt->month, $dt->day),
  53. name => $query->param ('name'),
  54. surname => $query->param ('surname'),
  55. email => $query->param ('email'),
  56. group => $query->param ('group') || '',
  57. newsletter => $query->param ('newsletter') || '' };
  58. $template->process ('pdfreaders-petition-mail.tt2', $data, \$mail);
  59. open MAIL, "|/usr/lib/sendmail -t";
  60. print MAIL $mail;
  61. close MAIL;
  62. print "Location: /campaigns/pdfreaders/petition-success.$lang.html\n\n";