5 Copyright (c) 2003-2010, Andrew Dunstan
7 See accompanying License file for license details
17 use vars qw($dbhost $dbname $dbuser $dbpass $dbport $notifyapp
18 $template_dir $default_host);
20 use FindBin qw($RealBin);
21 require "$RealBin/../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, $arg1, $arg2, $argop, $res ) =
34 @{$params}{qw(os osv comp compv arch email owner arg1 arg2 op res)};
36 $argop = '-' if !$argop or $argop ne '+';
37 $arg1 = int($arg1 || 0);
38 $arg2 = int($arg2 || 0);
39 $res = int($res || 0);
40 my $captcha_ok = ($arg1 and $argop and $arg2 and $res
41 and int(eval "$arg1 $argop $arg2") == $res) ? 1 : 0;
43 unless ($os && $osv && $comp && $compv && $arch && $email && $owner &&
46 print "Content-Type: text/html\n\n";
47 $template->process('register-incomplete.tt');
51 # these filters should catch and dispose of idiots,
52 # although I hope they are redundant now we're using captchas.
55 {/\@pgbuildfarm\.org|Content-Type:|http:|mailto:|href=|None|Unknown/}
56 $os,$osv,$comp,$compv,$arch,$email,$owner))
59 "Status: 403 Forbidden - go away idiot\n",
60 "Content-Type: text/plain\n\n";
64 # count transitions to and from upper case
67 foreach (split "" ,"$os$osv$comp$compv$arch$owner")
83 # reject junk with too many transitions into/outof upper case
87 # disable this check now, probably redundant with captchas
88 # and we just got a false positive
93 "Status: 403 Forbidden - go away idiot\n",
94 "Content-Type: text/plain\n\n";
102 my $dummyname=""; # we'll select an animal name when we approve it.
105 # 8 random chars is enough for the dummy name
106 $secret .= substr("0123456789abcdefghijklmnopqrstuvwxyz",int(rand(36)),1);
107 $dummyname .= substr("0123456789abcdef",int(rand(16)),1);
111 $secret .= substr("0123456789abcdef",int(rand(16)),1);
114 my $db = DBI->connect($dsn,$dbuser,$dbpass);
116 my $statement = <<EOS;
118 insert into buildsystems
119 (name, secret, operating_system, os_version, compiler, compiler_version,
120 architecture, status, sys_owner, owner_email)
121 values(?,?,?,?,?,?,?,'pending',?,?)
126 my $sth=$db->prepare($statement);
127 my $rv=$sth->execute($dummyname,$secret,$os,$osv,$comp,$compv,
128 $arch,$owner,$email);
131 # everything looks OK, so tell them so
132 print "Content-type: text/html\n\n";
133 $template->process('register-ok.tt');
141 my $msg = new Mail::Send;
143 my $me = `id -un`; chomp($me);
144 my $host = `hostname`; chomp ($host);
145 $host = $default_host unless ($host =~ m/[.]/ || !defined($default_host));
147 my $from_addr = "Exim Build Farm <$me\@$host>";
148 $from_addr =~ tr /\r\n//d;
150 $msg->set('From',$from_addr);
152 $msg->to(@$notifyapp);
153 $msg->subject('New BuildFarm Application');
155 print $fh "\n\nName: $dummyname\n",
158 "Comp: $comp: $compv\n",
159 "Owner: $owner <$email>\n";
164 HTTP::Tiny->new(timeout => 5)->post(
165 'http://127.0.0.1:2567/api/message', {
166 headers => {'content-type' => 'application/json'},
167 content => encode_json({
168 gateway => 'exim-builds',
170 text => "[new application] os: $os ($osv); arch: $arch; comp: $comp ($compv)",