--- a/index.cgi Mon Jul 04 16:27:02 2011 +0200
+++ b/index.cgi Mon Jul 04 17:26:13 2011 +0200
@@ -18,17 +18,17 @@
sub insert(\%);
sub confirm($$);
-sub slurp($);
+sub read_conf($);
delete @ENV{grep /PATH$/ => keys %ENV};
$ENV{PATH} = "/usr/bin:/usr/sbin:/bin:/sbin";
my $DSN = "DBI:SQLite:var/db.sqlite3";
-my $SECRET = slurp "conf/secret"; chomp($SECRET);
-my $SELF = slurp "conf/self"; chomp($SELF);
-my $SUBJECT = slurp "conf/subject"; chomp($SUBJECT);
+my $SECRET = read_conf "conf/secret"; chomp($SECRET);
+my $SELF = read_conf "conf/self"; chomp($SELF);
my $EXPIRATION = 60; # the link is valid for XX minutes only
+my $SENDMAIL = "/usr/sbin/sendmail -t";
my %FIELDS = (
MAN => [qw[givenname surname mail]],
OPT => [qw[tel]]
@@ -37,9 +37,6 @@
my %ttconfig = (
INCLUDE_PATH => "templates",
DEBUG => 1,
- VARIABLES => {
- MAILTO => "hs+retter\@schlittermann.de"
- },
);
my $DBH = DBI->connect($DSN, undef, undef, {RaiseError=>1});
@@ -75,14 +72,15 @@
$xxx =~ s/\//_/g;
# send mail
- sendmail(To => scalar(param("mail")),
- From => "hs+retter\@schlittermann.de",
- Sender => "hs\@schlittermann.de",
- Subject => "$SUBJECT Link zur Online-Anmeldung",
- Message => "Bitte benutze den folgenden Link, um zum Anmeldeformular zu gelangen:\n"
- . "$SELF/$xxx.tmp\n"
- . "\n-- \nHeiko Schlittermann\n");
-
+ open(my $sendmail => "|$SENDMAIL")
+ or die "Can't open sendmail: $!\n";
+
+ $tt->process("mail.invitation.tpl", {
+ to => scalar(param("mail")),
+ url => "$SELF/$xxx.tmp"}, $sendmail)
+ or die $tt->error();
+ close($sendmail);
+
$sent = param("mail");
}
}
@@ -121,6 +119,14 @@
my $confirmed = param("confirm") eq "yes";
my %data = confirm($uuid => $confirmed);
+ open(my $sendmail, "|$SENDMAIL") or die "Can't open $SENDMAIL: $!\n";
+ $tt->process("mail.confirmed.tpl", {
+ to => $data{mail},
+ confirmed => $confirmed,
+ }, $sendmail)
+ or die $tt->error();
+ close($sendmail);
+
$tt->process("confirm.tpl", {
confirmed => $confirmed,
error => delete $data{error},
@@ -171,24 +177,21 @@
if (!%warn) {
my %r = insert(%value);
- sendmail(To => $value{mail},
- From => "hs\@schlittermann.de",
- "Content-Type" => "text/plain; charset=\"UTF-8\"",
- Subject => "$SUBJECT Bitte die Anmeldung bestaetigen.",
- Message => <<_EOF);
-Bitte bestaetige Deine Anmeldung. Dazu mußt Du folgenden Link in Deinem
-Browser oeffnen:
+ open(my $sendmail => "|$SENDMAIL")
+ or die "Can't open $SENDMAIL: $!\n";
-$SELF/$r{uuid}.user?confirm=yes
+ $tt->process("mail.confirm.tpl", {
+ to => $value{mail},
+ url => {
+ yes => "$SELF/$r{uuid}.user?confirm=yes",
+ no => "$SELF/$r{uuid}.user?confirm=no",
+ }
+ }, $sendmail)
+ or die $tt->error();
-Wenn alles nur ein Irrtum war, dann kannst Du Deine Daten wieder
-AUSTRAGEN und wir vergessen Deine Anmeldung. Hier ist der Link zum
-AUSTRAGEN:
+ close($sendmail);
-$SELF/$r{uuid}.user?confirm=no
-
-_EOF
$tt->process("form.ack.tpl", {
value => \%value,
timestamp => $r{timestamp},
@@ -265,31 +268,10 @@
$DBH->commit;
- if ($confirmed) {
- sendmail(
- To => $data{mail},
- From => "hs+retter\@schlittermann.de",
- Subject => "$SUBJECT Bestaetigung der Anmeldung",
- Message => <<_EOF);
-Du bist erfolgreich angemeldet. Fuer weitere Fragen kontaktiere bitte
-hs+retter\@schlittermann.de.
-_EOF
- }
- else {
- sendmail(
- To => $data{mail},
- From => "hs+retter\@schlittermann.de",
- Subject => "$SUBJECT Bestaetigung der NICHT-Anmeldung",
- Message => <<_EOF);
-Wir vergessen Deine Anmeldung. Fuer weitere Fragen kontaktiere bitte
-hs+retter\@schlittermann.de.
-_EOF
- }
-
return %data;
}
-sub slurp($) {
+sub read_conf($) {
open(my $_, $_[0]) or die "Can't open $_[0]: $!\n";
local $/ = undef;
s/^#.*//mg;