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 $sysnotes = $query->param('sysnotes');
30 my $content = "animal=$animal\&sysnotes=$sysnotes";
32 require "$ENV{BFConfDir}/BuildFarmWeb.pl";
34 die "no dbname" unless $dbname;
35 die "no dbuser" unless $dbuser;
37 my $dsn="dbi:Pg:dbname=$dbname";
38 $dsn .= ";host=$dbhost" if $dbhost;
39 $dsn .= ";port=$dbport" if $dbport;
41 unless ($animal && defined($sysnotes) && $sig)
44 "Status: 490 bad parameters\nContent-Type: text/plain\n\n",
45 "bad parameters for request\n";
51 my $db = DBI->connect($dsn,$dbuser,$dbpass);
53 die $DBI::errstr unless $db;
56 "select secret from buildsystems where name = ? and status = 'approved'";
57 my $sth = $db->prepare($gethost);
58 $sth->execute($animal);
59 my ($secret)=$sth->fetchrow_array();
66 "Status: 495 Unknown System\nContent-Type: text/plain\n\n",
67 "System $animal is unknown\n";
76 my $calc_sig = sha1_hex($content,$secret);
78 if ($calc_sig ne $sig)
81 print "Status: 450 sig mismatch\nContent-Type: text/plain\n\n";
82 print "$sig mismatches $calc_sig on content:\n$content";
87 # undo escape-proofing of base64 data and decode it
88 map {tr/$@/+=/; $_ = decode_base64($_); }
94 set sys_notes = nullif($2,''),
96 when coalesce($2,'') <> '' then now()
100 and status = 'approved'
104 $sth = $db->prepare($set_notes);
105 my $rv = $sth->execute($animal,$sysnotes);
108 print "Status: 460 old data fetch\nContent-Type: text/plain\n\n";
109 print "error: ",$db->errstr,"\n";
120 print "Content-Type: text/plain\n\n";
121 print "request was on:\n$content\n";