index.cgi
changeset 10 fd14fab1744d
parent 7 c89c297e5d53
child 9 32a383000254
--- a/index.cgi	Mon Jul 04 17:26:13 2011 +0200
+++ b/index.cgi	Mon Jul 04 21:30:38 2011 +0200
@@ -25,10 +25,12 @@
 $ENV{PATH} = "/usr/bin:/usr/sbin:/bin:/sbin";
 
 my $DSN = "DBI:SQLite:var/db.sqlite3";
-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 $EXPIRATION = 60;  # expiration time of the first link
+my $SECRET = read_conf "conf/secret";
+my $SELF = read_conf "conf/self";   
+my $SENDER = read_conf "conf/sender";
+my $SENDMAIL = "/usr/sbin/sendmail -f $SENDER -t";
+
 my %FIELDS = (
     MAN => [qw[givenname surname mail]],
     OPT => [qw[tel]]
@@ -36,7 +38,6 @@
 
 my %ttconfig = (
     INCLUDE_PATH => "templates",
-    DEBUG => 1,
 );
 
 my $DBH = DBI->connect($DSN, undef, undef, {RaiseError=>1});
@@ -79,12 +80,14 @@
 		    to   => scalar(param("mail")),
 		    url  => "$SELF/$xxx.tmp"}, $sendmail)
 		or die $tt->error();
-		close($sendmail);
+		close($sendmail)
+			or die "problem sending mail to "
+				. param("mail");
 
 		$sent = param("mail");
 	    }
 	}
-	$tt->process("access.tpl", {
+	$tt->process("html.access.tpl", {
 	    sent => $sent,
 	    warn => %warn ? \%warn : undef,
 	    expires => $EXPIRATION,
@@ -107,7 +110,7 @@
 	    time() - $time < (60 * $EXPIRATION) or die "EXPIRED";
 	};
 	if ($@) {
-	    $tt->process("denied.tpl", {
+	    $tt->process("html.denied.tpl", {
 		url => $SELF,
 	    }) or die $tt->error();
 	    exit 0;
@@ -127,7 +130,7 @@
 	or die $tt->error();
 	close($sendmail);
 
-	$tt->process("confirm.tpl", {
+	$tt->process("html.confirm.tpl", {
 	    confirmed => $confirmed,
 	    error => delete $data{error},
 	    value => \%data}) or die $tt->error();
@@ -192,7 +195,7 @@
 
 	    close($sendmail);
 
-	    $tt->process("form.ack.tpl", {
+	    $tt->process("html.form.ack.tpl", {
 		value => \%value,
 		timestamp => $r{timestamp},
 		uuid => $r{uuid},
@@ -203,7 +206,7 @@
 
 
     ## Formular
-    $tt->process("form.tpl", {
+    $tt->process("html.form.tpl", {
 	warn => %warn ? \%warn : undef,
 	value => {
 	    givenname => scalar param("givenname"),
@@ -272,8 +275,10 @@
 }
 
 sub read_conf($) {
-    open(my $_, $_[0]) or die "Can't open $_[0]: $!\n";
     local $/ = undef;
+    open(my $f, $_[0]) or die "Can't open $_[0]: $!\n";
+    my $_ = <$f>;
     s/^#.*//mg;
-    return <$_>;
+    /^\s*(.*?)\s*$/s;
+    return $1;
 }