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 use FindBin qw($RealBin);
37 require "$RealBin/../BuildFarmWeb.pl";
39 die "no dbname" unless $dbname;
40 die "no dbuser" unless $dbuser;
42 my $dsn="dbi:Pg:dbname=$dbname";
43 $dsn .= ";host=$dbhost" if $dbhost;
44 $dsn .= ";port=$dbport" if $dbport;
46 unless ($animal && $ts && ($os_version || $compiler_version) && $sig)
49 "Status: 490 bad parameters\nContent-Type: text/plain\n\n",
50 "bad parameters for request\n";
56 my $db = DBI->connect($dsn,$dbuser,$dbpass);
58 die $DBI::errstr unless $db;
61 "select secret from buildsystems where name = ? and status = 'approved'";
62 my $sth = $db->prepare($gethost);
63 $sth->execute($animal);
64 my ($secret)=$sth->fetchrow_array();
71 "Status: 495 Unknown System\nContent-Type: text/plain\n\n",
72 "System $animal is unknown\n";
81 my $calc_sig = sha1_hex($content,$secret);
83 if ($calc_sig ne $sig)
86 print "Status: 450 sig mismatch\nContent-Type: text/plain\n\n";
87 print "$sig mismatches $calc_sig on content:\n$content";
92 # undo escape-proofing of base64 data and decode it
93 map {tr/$@/+=/; $_ = decode_base64($_); }
94 ($os_version, $compiler_version);
98 select coalesce(b.os_version, a.os_version) as os_version,
99 coalesce(b.compiler_version, a.compiler_version) as compiler_version
100 from buildsystems as a left join
101 ( select distinct on (name) name, compiler_version, os_version
103 order by name, effective_date desc
107 and a.status = 'approved'
111 $sth = $db->prepare($get_latest);
112 my $rv = $sth->execute($animal);
115 print "Status: 460 old data fetch\nContent-Type: text/plain\n\n";
116 print "error: ",$db->errstr,"\n";
121 my ($old_os,$old_comp)=$sth->fetchrow_array();
126 $os_version ||= $old_os;
127 $compiler_version ||= $old_comp;
129 my $new_personality = q{
131 insert into personality (name, os_version, compiler_version)
137 $sth = $db->prepare($new_personality);
138 $rv = $sth->execute($animal,$os_version, $compiler_version);
142 print "Status: 470 new data insert\nContent-Type: text/plain\n\n";
143 print "error: $db->errstr\n";
154 print "Content-Type: text/plain\n\n";
155 print "request was on:\n$content\n";