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
19 $captcha_pubkey $captcha_privkey $template_dir $default_host);
21 require "$ENV{BFConfDir}/BuildFarmWeb.pl";
23 my $dsn="dbi:Pg:dbname=$dbname";
24 $dsn .= ";host=$dbhost" if $dbhost;
25 $dsn .= ";port=$dbport" if $dbport;
27 my $template_opts = { INCLUDE_PATH => $template_dir};
28 my $template = new Template($template_opts);
31 my $params = $query->Vars;
33 my ($os, $osv, $comp, $compv, $arch, $email, $owner, $challenge, $response ) =
35 qw(os osv comp compv arch email owner recaptcha_challenge_field
36 recaptcha_response_field)};
38 my $captcha = Captcha::reCAPTCHA->new;
39 my $captcha_ok = $captcha->check_answer
47 unless ($os && $osv && $comp && $compv && $arch && $email && $owner &&
48 $captcha_ok->{is_valid})
50 print "Content-Type: text/html\n\n";
51 $template->process('register-incomplete.tt');
55 # these filters should catch and dispose of idiots,
56 # although I hope they are redundant now we're using captchas.
59 {/\@pgbuildfarm\.org|Content-Type:|http:|mailto:|href=|None|Unknown/}
60 $os,$osv,$comp,$compv,$arch,$email,$owner))
63 "Status: 403 Forbidden - go away idiot\n",
64 "Content-Type: text/plain\n\n";
68 # count transitions to and from upper case
71 foreach (split "" ,"$os$osv$comp$compv$arch$owner")
87 # reject junk with too many transitions into/outof upper case
91 # disable this check now, probably redundant with captchas
92 # and we just got a false positive
97 "Status: 403 Forbidden - go away idiot\n",
98 "Content-Type: text/plain\n\n";
106 my $dummyname=""; # we'll select an animal name when we approve it.
109 # 8 random chars is enough for the dummy name
110 $secret .= substr("0123456789abcdefghijklmnopqrstuvwxyz",int(rand(36)),1);
111 $dummyname .= substr("0123456789abcdef",int(rand(16)),1);
115 $secret .= substr("0123456789abcdef",int(rand(16)),1);
118 my $db = DBI->connect($dsn,$dbuser,$dbpass);
120 my $statement = <<EOS;
122 insert into buildsystems
123 (name, secret, operating_system, os_version, compiler, compiler_version,
124 architecture, status, sys_owner, owner_email)
125 values(?,?,?,?,?,?,?,'pending',?,?)
130 my $sth=$db->prepare($statement);
131 my $rv=$sth->execute($dummyname,$secret,$os,$osv,$comp,$compv,
132 $arch,$owner,$email);
135 # everything looks OK, so tell them so
136 print "Content-type: text/html\n\n";
137 $template->process('register-ok.tt');
145 my $msg = new Mail::Send;
147 my $me = `id -un`; chomp($me);
148 my $host = `hostname`; chomp ($host);
149 $host = $default_host unless ($host =~ m/[.]/ || !defined($default_host));
151 my $from_addr = "Exim Build Farm <$me\@$host>";
152 $from_addr =~ tr /\r\n//d;
154 $msg->set('From',$from_addr);
156 $msg->to(@$notifyapp);
157 $msg->subject('New BuildFarm Application');
159 print $fh "\n\nName: $dummyname\n",
162 "Comp: $comp: $compv\n",
163 "Owner: $owner <$email>\n";