5 Copyright (c) 2003-2010, Andrew Dunstan
7 See accompanying License file for license details
14 use Digest::SHA1 qw(sha1_hex);
20 use vars qw($dbhost $dbname $dbuser $dbpass $dbport);
24 my $sig = $query->path_info;
27 my $animal = $query->param('animal');
28 my $ts = $query->param('ts');
29 my $os_version = $query->param('new_os');
30 my $compiler_version = $query->param('new_compiler');
32 my $content = "animal=$animal\&ts=$ts";
33 $content .= "\&new_os=$os_version" if $os_version;
34 $content .= "\&new_compiler=$compiler_version" if $compiler_version;
36 require "$ENV{BFConfDir}/BuildFarmWeb.pl";
38 die "no dbname" unless $dbname;
39 die "no dbuser" unless $dbuser;
41 my $dsn="dbi:Pg:dbname=$dbname";
42 $dsn .= ";host=$dbhost" if $dbhost;
43 $dsn .= ";port=$dbport" if $dbport;
45 unless ($animal && $ts && ($os_version || $compiler_version) && $sig)
48 "Status: 490 bad parameters\nContent-Type: text/plain\n\n",
49 "bad parameters for request\n";
55 my $db = DBI->connect($dsn,$dbuser,$dbpass);
57 die $DBI::errstr unless $db;
60 "select secret from buildsystems where name = ? and status = 'approved'";
61 my $sth = $db->prepare($gethost);
62 $sth->execute($animal);
63 my ($secret)=$sth->fetchrow_array();
70 "Status: 495 Unknown System\nContent-Type: text/plain\n\n",
71 "System $animal is unknown\n";
80 my $calc_sig = sha1_hex($content,$secret);
82 if ($calc_sig ne $sig)
85 print "Status: 450 sig mismatch\nContent-Type: text/plain\n\n";
86 print "$sig mismatches $calc_sig on content:\n$content";
91 # undo escape-proofing of base64 data and decode it
92 map {tr/$@/+=/; $_ = decode_base64($_); }
93 ($os_version, $compiler_version);
97 select coalesce(b.os_version, a.os_version) as os_version,
98 coalesce(b.compiler_version, a.compiler_version) as compiler_version
99 from buildsystems as a left join
100 ( select distinct on (name) name, compiler_version, os_version
102 order by name, effective_date desc
106 and a.status = 'approved'
110 $sth = $db->prepare($get_latest);
111 my $rv = $sth->execute($animal);
114 print "Status: 460 old data fetch\nContent-Type: text/plain\n\n";
115 print "error: ",$db->errstr,"\n";
120 my ($old_os,$old_comp)=$sth->fetchrow_array();
125 $os_version ||= $old_os;
126 $compiler_version ||= $old_comp;
128 my $new_personality = q{
130 insert into personality (name, os_version, compiler_version)
136 $sth = $db->prepare($new_personality);
137 $rv = $sth->execute($animal,$os_version, $compiler_version);
141 print "Status: 470 new data insert\nContent-Type: text/plain\n\n";
142 print "error: $db->errstr\n";
153 print "Content-Type: text/plain\n\n";
154 print "request was on:\n$content\n";