Add 4.97+security
[buildfarm-server.git] / cgi-bin / register.pl
index ada9a8c45f389241af07c947fe3bf09898a27636..808cd8938af5f379b6dbc0770c6a0c9f68a55bf3 100755 (executable)
@@ -13,12 +13,12 @@ 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 $default_host);
+                       $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;
@@ -30,22 +30,18 @@ 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 $captcha = Captcha::reCAPTCHA->new;
-my $captcha_ok = $captcha->check_answer
-    (
-     $captcha_privkey, 
-     $ENV{'REMOTE_ADDR'},
-     $challenge, $response
-     );
+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)};
 
+$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})
+               $captcha_ok)
 {
     print "Content-Type: text/html\n\n";
     $template->process('register-incomplete.tt');
@@ -154,7 +150,7 @@ $from_addr =~ tr /\r\n//d;
 $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",
@@ -163,8 +159,15 @@ print $fh "\n\nName: $dummyname\n",
     "Owner: $owner <$email>\n";
 $fh->close;
 
-
-
-
-
-
+use HTTP::Tiny;
+use JSON::PP;
+HTTP::Tiny->new(timeout => 5)->post(
+    'http://127.0.0.1:2567/api/message', {
+        headers => {'content-type' => 'application/json'},
+        content => encode_json({
+            gateway => 'exim-builds',
+            username => '',
+            text => "[new application] os: $os ($osv); arch: $arch; comp: $comp ($compv)",
+        }),
+    }
+);