5 Copyright (c) 2003-2010, Andrew Dunstan
7 See accompanying License file for license details
15 use File::Temp qw(tempfile);
17 use vars qw($dbhost $dbname $dbuser $dbpass $dbport @log_file_names);
19 use FindBin qw($RealBin);
20 require "$RealBin/../BuildFarmWeb.pl";
22 die "no dbname" unless $dbname;
23 die "no dbuser" unless $dbuser;
25 my $dsn="dbi:Pg:dbname=$dbname";
26 $dsn .= ";host=$dbhost" if $dbhost;
27 $dsn .= ";port=$dbport" if $dbport;
31 my $system = $query->param('nm'); $system =~ s/[^a-zA-Z0-9_ -]//g;
32 my $logdate = $query->param('dt');$logdate =~ s/[^a-zA-Z0-9_ -]//g;
33 my $stage = $query->param('stg');$stage =~ s/[^a-zA-Z0-9._ -]//g;
34 my $brnch = $query->param('branch') || 'HEAD'; $brnch =~ s/[^a-zA-Z0-9._ -]//g;
38 if ($system && $logdate && $stage)
40 my $db = DBI->connect($dsn,$dbuser,$dbpass);
42 die $DBI::errstr unless $db;
44 if ($logdate =~ /^latest$/i)
50 and snapshot > now() - interval '30 days'
51 and log_stage = ? || '.log'
54 my $logs = $db->selectcol_arrayref($find_latest,undef,$system,$stage,$brnch);
55 $logdate = shift(@$logs);
60 select branch, log_text
62 where sysname = ? and snapshot = ? and log_stage = ? || '.log'
66 my $sth=$db->prepare($statement);
67 $sth->execute($system,$logdate,$stage);
68 my $row=$sth->fetchrow_arrayref;
69 my ($branch, $logtext) = ("unknown","no log text found");
78 print "Content-Type: text/plain\n\nSnapshot: $logdate\n\n", $logtext,
80 "-------------------------------------------------\n\n",
81 "Hosting for the Exim BuildFarm is generously ",
82 "provided by: Bytemark";
88 print "Status: 460 bad parameters\n",
89 "Content-Type: text/plain\n\n";