5 Copyright (c) 2003-2010, Andrew Dunstan
7 See accompanying License file for license details
16 use Captcha::reCAPTCHA;
18 use vars qw($dbhost $dbname $dbuser $dbpass $dbport $notifyapp $captcha_pubkey $captcha_privkey $template_dir $default_host);
20 require "$ENV{BFConfDir}/BuildFarmWeb.pl";
22 my $dsn="dbi:Pg:dbname=$dbname";
23 $dsn .= ";host=$dbhost" if $dbhost;
24 $dsn .= ";port=$dbport" if $dbport;
26 my $template_opts = { INCLUDE_PATH => $template_dir};
27 my $template = new Template($template_opts);
30 my $params = $query->Vars;
32 my ($os, $osv, $comp, $compv, $arch, $email, $owner, $challenge, $response ) = @{$params}{
33 qw(os osv comp compv arch email owner recaptcha_challenge_field recaptcha_response_field)};
35 my $captcha = Captcha::reCAPTCHA->new;
36 my $captcha_ok = $captcha->check_answer
44 unless ($os && $osv && $comp && $compv && $arch && $email && $owner && $captcha_ok->{is_valid})
46 print "Content-Type: text/html\n\n";
47 $template->process('register-incomplete.tt');
51 # some idiot has a script that tries to talk to me
52 # this should catch and dispose of him
53 if ((grep {/rgergerger|\@pgbuildfarm\.org|Content-Type:|http:|mailto:|href=|None|Unknown/} $os,$osv,$comp,$compv,$arch,$email,$owner)
54 || ($email =~ /john.*\@aol.com/) )
57 "Status: 403 Forbidden - go away idiot\n",
58 "Content-Type: text/plain\n\n";
62 # count transitions to and from upper case
65 foreach (split "" ,"$os$osv$comp$compv$arch$owner")
81 # reject junk with too many transitions into/outof upper case
85 "Status: 403 Forbidden - go away idiot\n",
86 "Content-Type: text/plain\n\n";
93 my $dummyname=""; # we'll select an animal name when we approve it.
96 # 8 random chars is enough for the dummy name
97 $secret .= substr("0123456789abcdefghijklmnopqrstuvwxyz",int(rand(36)),1);
98 $dummyname .= substr("0123456789abcdef",int(rand(16)),1);
102 $secret .= substr("0123456789abcdef",int(rand(16)),1);
105 my $db = DBI->connect($dsn,$dbuser,$dbpass);
107 my $statement = <<EOS;
109 insert into buildsystems
110 (name, secret, operating_system, os_version, compiler, compiler_version,
111 architecture, status, sys_owner, owner_email)
112 values(?,?,?,?,?,?,?,'pending',?,?)
117 my $sth=$db->prepare($statement);
118 my $rv=$sth->execute($dummyname,$secret,$os,$osv,$comp,$compv,
119 $arch,$owner,$email);
122 # everything looks OK, so tell them so
123 print "Content-type: text/html\n\n";
124 $template->process('register-ok.tt');
132 my $msg = new Mail::Send;
134 my $me = `id -un`; chomp($me);
135 my $host = `hostname`; chomp ($host);
136 $host = $default_host unless ($host =~ m/[.]/ || !defined($default_host));
138 my $from_addr = "PG Build Farm <$me\@$host>";
139 $from_addr =~ tr /\r\n//d;
141 $msg->set('From',$from_addr);
143 $msg->to(@$notifyapp);
144 $msg->subject('New Buildfarm Application');
146 print $fh "\n\nName: $dummyname\n",
149 "Comp: $comp: $compv\n",
150 "Owner: $owner <$email>\n";