8 use Captcha::reCAPTCHA;
10 use vars qw($dbhost $dbname $dbuser $dbpass $dbport $notifyapp $captcha_pubkey $captcha_privkey $template_dir);
12 require "$ENV{BFConfDir}/BuildFarmWeb.pl";
14 my $dsn="dbi:Pg:dbname=$dbname";
15 $dsn .= ";host=$dbhost" if $dbhost;
16 $dsn .= ";port=$dbport" if $dbport;
18 my $template_opts = { INCLUDE_PATH => $template_dir};
19 my $template = new Template($template_opts);
22 my $params = $query->Vars;
24 my ($os, $osv, $comp, $compv, $arch, $email, $owner, $challenge, $response ) = @{$params}{
25 qw(os osv comp compv arch email owner recaptcha_challenge_field recaptcha_response_field)};
27 my $captcha = Captcha::reCAPTCHA->new;
28 my $captcha_ok = $captcha->check_answer
36 unless ($os && $osv && $comp && $compv && $arch && $email && $owner && $captcha_ok->{is_valid})
38 print "Content-Type: text/html\n\n";
39 $template->process('register-incomplete.tt');
43 # some idiot has a script that tries to talk to me
44 # this should catch and dispose of him
45 if ((grep {/rgergerger|\@pgbuildfarm\.org|Content-Type:|http:|mailto:|href=|None|Unknown/} $os,$osv,$comp,$compv,$arch,$email,$owner)
46 || ($email =~ /john.*\@aol.com/) )
49 "Status: 403 Forbidden - go away idiot\n",
50 "Content-Type: text/plain\n\n";
54 # count transitions to and from upper case
57 foreach (split "" ,"$os$osv$comp$compv$arch$owner")
73 # reject junk with too many transitions into/outof upper case
77 "Status: 403 Forbidden - go away idiot\n",
78 "Content-Type: text/plain\n\n";
85 my $dummyname=""; # we'll select an animal name when we approve it.
88 # 8 random chars is enough for the dummy name
89 $secret .= substr("0123456789abcdefghijklmnopqrstuvwxyz",int(rand(36)),1);
90 $dummyname .= substr("0123456789abcdef",int(rand(16)),1);
94 $secret .= substr("0123456789abcdef",int(rand(16)),1);
97 my $db = DBI->connect($dsn,$dbuser,$dbpass);
99 my $statement = <<EOS;
101 insert into buildsystems
102 (name, secret, operating_system, os_version, compiler, compiler_version,
103 architecture, status, sys_owner, owner_email)
104 values(?,?,?,?,?,?,?,'pending',?,?)
109 my $sth=$db->prepare($statement);
110 my $rv=$sth->execute($dummyname,$secret,$os,$osv,$comp,$compv,
111 $arch,$owner,$email);
114 # everything looks OK, so tell them so
115 print "Content-type: text/html\n\n";
116 $template->process('register-ok.tt');
124 my $msg = new Mail::Send;
128 my $host = `hostname`;
130 $msg->set('From',"PG Build Farm <$me\@$host>");
132 $msg->to(@$notifyapp);
133 $msg->subject('New Buildfarm Application');
135 print $fh "\n\nName: $dummyname\n",
138 "Comp: $comp: $compv\n",
139 "Owner: $owner <$email>\n";