New server, FileBin instead of $ENV{BFConfDir}, and custom Captcha
[buildfarm-server.git] / cgi-bin / register.pl
index b15a0e24cf88862c4699a604aff695217f641617..80663b67aefb6ad09f9751bf7950ff38b2ce718a 100755 (executable)
@@ -1,15 +1,24 @@
 #!/usr/bin/perl
 
+=comment
+
+Copyright (c) 2003-2010, Andrew Dunstan
+
+See accompanying License file for license details
+
+=cut 
+
 use strict;
 use DBI;
 use Template;
 use CGI;
 use Template;
-use Captcha::reCAPTCHA;
 
-use vars qw($dbhost $dbname $dbuser $dbpass $dbport $notifyapp $captcha_pubkey $captcha_privkey $template_dir);
+use vars qw($dbhost $dbname $dbuser $dbpass $dbport $notifyapp 
+                       $template_dir $default_host);
 
-require "$ENV{BFConfDir}/BuildFarmWeb.pl";
+use FindBin qw($RealBin);
+require "$RealBin/../BuildFarmWeb.pl";
 
 my $dsn="dbi:Pg:dbname=$dbname";
 $dsn .= ";host=$dbhost" if $dbhost;
@@ -21,29 +30,30 @@ my $query = new CGI;
 
 my $params = $query->Vars;
 
-my ($os, $osv, $comp, $compv, $arch, $email, $owner, $challenge, $response ) = @{$params}{
-       qw(os osv comp compv arch email owner recaptcha_challenge_field recaptcha_response_field)};
+my ($os, $osv, $comp, $compv, $arch, $email, $owner, $arg1, $arg2, $argop, $res ) = 
+  @{$params}{qw(os osv comp compv arch email owner arg1 arg2 op res)};
 
-my $captcha = Captcha::reCAPTCHA->new;
-my $captcha_ok = $captcha->check_answer
-    (
-     $captcha_privkey, 
-     $ENV{'REMOTE_ADDR'},
-     $challenge, $response
-     );
+$argop = '-' if !$argop or $argop ne '+';
+$arg1 = int($arg1 || 0);
+$arg2 = int($arg2 || 0);
+$res = int($res || 0);
+my $captcha_ok = ($arg1 and $argop and $arg2 and $res
+                  and int(eval "$arg1 $argop $arg2") == $res) ? 1 : 0;
 
-
-unless ($os && $osv && $comp && $compv && $arch && $email && $owner && $captcha_ok->{is_valid})
+unless ($os && $osv && $comp && $compv && $arch && $email && $owner && 
+               $captcha_ok)
 {
     print "Content-Type: text/html\n\n";
     $template->process('register-incomplete.tt');
     exit;
 }
 
-# some idiot has a script that tries to talk to me
-# this should catch and dispose of him
-if ((grep {/rgergerger|\@pgbuildfarm\.org|Content-Type:|http:|mailto:|href=|None|Unknown/} $os,$osv,$comp,$compv,$arch,$email,$owner)
-    || ($email =~ /john.*\@aol.com/) )
+# these filters  should catch and dispose of idiots, 
+# although I hope they are redundant now we're using captchas.
+
+if ((grep 
+   {/\@pgbuildfarm\.org|Content-Type:|http:|mailto:|href=|None|Unknown/} 
+        $os,$osv,$comp,$compv,$arch,$email,$owner))
 {
     print 
        "Status: 403 Forbidden - go away idiot\n",
@@ -71,6 +81,12 @@ foreach (split "" ,"$os$osv$comp$compv$arch$owner")
 }
 
 # reject junk with too many transitions into/outof upper case
+
+=comment
+
+# disable this check now, probably redundant with captchas 
+# and we just got a false positive
+
 if ($counttrans > 20)
 {
     print 
@@ -79,6 +95,7 @@ if ($counttrans > 20)
     exit;   
 }
 
+=cut
 
 
 my $secret = "";
@@ -123,14 +140,17 @@ use Mail::Send;
 
 my $msg = new Mail::Send;
 
-my $me = `id -un`;
+my $me = `id -un`; chomp($me);
+my $host = `hostname`; chomp ($host);
+$host = $default_host unless ($host =~ m/[.]/ || !defined($default_host));
 
-my $host = `hostname`;
+my $from_addr = "Exim Build Farm <$me\@$host>";
+$from_addr =~ tr /\r\n//d;
 
-$msg->set('From',"PG Build Farm <$me\@$host>");
+$msg->set('From',$from_addr);
 
 $msg->to(@$notifyapp);
-$msg->subject('New Buildfarm Application');
+$msg->subject('New BuildFarm Application');
 my $fh = $msg->open;
 print $fh "\n\nName: $dummyname\n",
     "OS: $os: $osv\n",
@@ -138,9 +158,3 @@ print $fh "\n\nName: $dummyname\n",
     "Comp: $comp: $compv\n",
     "Owner: $owner <$email>\n";
 $fh->close;
-
-
-
-
-
-