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 "Status: 403 Forbidden - go away idiot\n",
92 "Content-Type: text/plain\n\n";
99 my $dummyname=""; # we'll select an animal name when we approve it.
102 # 8 random chars is enough for the dummy name
103 $secret .= substr("0123456789abcdefghijklmnopqrstuvwxyz",int(rand(36)),1);
104 $dummyname .= substr("0123456789abcdef",int(rand(16)),1);
108 $secret .= substr("0123456789abcdef",int(rand(16)),1);
111 my $db = DBI->connect($dsn,$dbuser,$dbpass);
113 my $statement = <<EOS;
115 insert into buildsystems
116 (name, secret, operating_system, os_version, compiler, compiler_version,
117 architecture, status, sys_owner, owner_email)
118 values(?,?,?,?,?,?,?,'pending',?,?)
123 my $sth=$db->prepare($statement);
124 my $rv=$sth->execute($dummyname,$secret,$os,$osv,$comp,$compv,
125 $arch,$owner,$email);
128 # everything looks OK, so tell them so
129 print "Content-type: text/html\n\n";
130 $template->process('register-ok.tt');
138 my $msg = new Mail::Send;
140 my $me = `id -un`; chomp($me);
141 my $host = `hostname`; chomp ($host);
142 $host = $default_host unless ($host =~ m/[.]/ || !defined($default_host));
144 my $from_addr = "PG Build Farm <$me\@$host>";
145 $from_addr =~ tr /\r\n//d;
147 $msg->set('From',$from_addr);
149 $msg->to(@$notifyapp);
150 $msg->subject('New Buildfarm Application');
152 print $fh "\n\nName: $dummyname\n",
155 "Comp: $comp: $compv\n",
156 "Owner: $owner <$email>\n";