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 use FindBin qw($RealBin);
33 require "$RealBin/../BuildFarmWeb.pl";
35 die "no dbname" unless $dbname;
36 die "no dbuser" unless $dbuser;
38 my $dsn="dbi:Pg:dbname=$dbname";
39 $dsn .= ";host=$dbhost" if $dbhost;
40 $dsn .= ";port=$dbport" if $dbport;
42 unless ($animal && defined($sysnotes) && $sig)
45 "Status: 490 bad parameters\nContent-Type: text/plain\n\n",
46 "bad parameters for request\n";
52 my $db = DBI->connect($dsn,$dbuser,$dbpass);
54 die $DBI::errstr unless $db;
57 "select secret from buildsystems where name = ? and status = 'approved'";
58 my $sth = $db->prepare($gethost);
59 $sth->execute($animal);
60 my ($secret)=$sth->fetchrow_array();
67 "Status: 495 Unknown System\nContent-Type: text/plain\n\n",
68 "System $animal is unknown\n";
77 my $calc_sig = sha1_hex($content,$secret);
79 if ($calc_sig ne $sig)
82 print "Status: 450 sig mismatch\nContent-Type: text/plain\n\n";
83 print "$sig mismatches $calc_sig on content:\n$content";
88 # undo escape-proofing of base64 data and decode it
89 map {tr/$@/+=/; $_ = decode_base64($_); }
95 set sys_notes = nullif($2,''),
97 when coalesce($2,'') <> '' then now()
101 and status = 'approved'
105 $sth = $db->prepare($set_notes);
106 my $rv = $sth->execute($animal,$sysnotes);
109 print "Status: 460 old data fetch\nContent-Type: text/plain\n\n";
110 print "error: ",$db->errstr,"\n";
121 print "Content-Type: text/plain\n\n";
122 print "request was on:\n$content\n";