6 use Digest::SHA1 qw(sha1_hex);
12 use vars qw($dbhost $dbname $dbuser $dbpass $dbport);
16 my $sig = $query->path_info;
19 my $animal = $query->param('animal');
20 my $ts = $query->param('ts');
21 my $os_version = $query->param('new_os');
22 my $compiler_version = $query->param('new_compiler');
24 my $content = "animal=$animal\&ts=$ts";
25 $content .= "\&new_os=$os_version" if $os_version;
26 $content .= "\&new_compiler=$compiler_version" if $compiler_version;
28 require "$ENV{BFConfDir}/BuildFarmWeb.pl";
30 die "no dbname" unless $dbname;
31 die "no dbuser" unless $dbuser;
33 my $dsn="dbi:Pg:dbname=$dbname";
34 $dsn .= ";host=$dbhost" if $dbhost;
35 $dsn .= ";port=$dbport" if $dbport;
37 unless ($animal && $ts && ($os_version || $compiler_version) && $sig)
40 "Status: 490 bad parameters\nContent-Type: text/plain\n\n",
41 "bad parameters for request\n";
47 my $db = DBI->connect($dsn,$dbuser,$dbpass);
49 die $DBI::errstr unless $db;
52 "select secret from buildsystems where name = ? and status = 'approved'";
53 my $sth = $db->prepare($gethost);
54 $sth->execute($animal);
55 my ($secret)=$sth->fetchrow_array();
62 "Status: 495 Unknown System\nContent-Type: text/plain\n\n",
63 "System $animal is unknown\n";
72 my $calc_sig = sha1_hex($content,$secret);
74 if ($calc_sig ne $sig)
77 print "Status: 450 sig mismatch\nContent-Type: text/plain\n\n";
78 print "$sig mismatches $calc_sig on content:\n$content";
83 # undo escape-proofing of base64 data and decode it
84 map {tr/$@/+=/; $_ = decode_base64($_); }
85 ($os_version, $compiler_version);
89 select coalesce(b.os_version, a.os_version) as os_version,
90 coalesce(b.compiler_version, a.compiler_version) as compiler_version
91 from buildsystems as a left join
92 ( select distinct on (name) name, compiler_version, os_version
94 order by name, effective_date desc
98 and a.status = 'approved'
102 $sth = $db->prepare($get_latest);
103 my $rv = $sth->execute($animal);
106 print "Status: 460 old data fetch\nContent-Type: text/plain\n\n";
107 print "error: ",$db->errstr,"\n";
112 my ($old_os,$old_comp)=$sth->fetchrow_array();
117 $os_version ||= $old_os;
118 $compiler_version ||= $old_comp;
120 my $new_personality = q{
122 insert into personality (name, os_version, compiler_version)
128 $sth = $db->prepare($new_personality);
129 $rv = $sth->execute($animal,$os_version, $compiler_version);
133 print "Status: 470 new data insert\nContent-Type: text/plain\n\n";
134 print "error: $db->errstr\n";
145 print "Content-Type: text/plain\n\n";
146 print "request was on:\n$content\n";