Add README Copyright and License notices, pus minor tidying.
[buildfarm-server.git] / cgi-bin / show_stage_log.pl
index dbc364925c7b001cca1c11144dfed1501f1a9940..7fd6438de7fe399fc6413c56d33b0afed9c943fd 100755 (executable)
@@ -1,5 +1,13 @@
 #!/usr/bin/perl
 
+=comment
+
+Copyright (c) 2003-2010, Andrew Dunstan
+
+See accompanying License file for license details
+
+=cut 
+
 use strict;
 use DBI;
 use Template;
@@ -23,75 +31,49 @@ my $query = new CGI;
 
 my $system = $query->param('nm'); $system =~ s/[^a-zA-Z0-9_ -]//g;
 my $logdate = $query->param('dt');$logdate =~ s/[^a-zA-Z0-9_ -]//g;
-my $stage = $query->param('stg');$stage =~ s/[^a-zA-Z0-9_ -]//g;
+my $stage = $query->param('stg');$stage =~ s/[^a-zA-Z0-9._ -]//g;
 
 use vars qw($tgz);
 
-if ($system && $logdate)
+if ($system && $logdate && $stage)
 {
-
     my $db = DBI->connect($dsn,$dbuser,$dbpass);
 
     die $DBI::errstr unless $db;
 
     my $statement = q(
 
-               select log_archive
-               from build_status
-               where sysname = ? and snapshot = ?
+        select branch, log_text
+        from build_status_log
+        where sysname = ? and snapshot = ? and log_stage = ? || '.log'
 
-               );
+        );
 
 
     
     my $sth=$db->prepare($statement);
-    $sth->execute($system,$logdate);
+    $sth->execute($system,$logdate,$stage);
     my $row=$sth->fetchrow_arrayref;
-    $tgz=$row->[0];
+    my ($branch, $logtext) = ("unknown","no log text found");
+    if ($row)
+    {
+        $branch = $row->[0];
+        $logtext =$row->[1];
+    }
     $sth->finish;
     $db->disconnect;
 
-}
-
-unless ($stage)
-{
-
-    print 
-       "Content-Type: application/x-gzip\n", 
-       "Content-Disposition: attachment; filename=buildfarmlog.tgz\n",
-       "\n",
-       $tgz;
-    exit;
-}
-
-my $template = "buildlogXXXXXX";
-my ($fh, $filename) = tempfile($template, 
-                                                          DIR => '/home/community/pgbuildfarm/buildlogs',
-                                                          UNLINK => 1);
-print $fh $tgz;
-close($fh);
-
-my $output = `tar -z -O -xf $filename $stage.log 2>&1`;
-
-print "Content-Type: text/plain\n\n", $output,
+    print "Content-Type: text/plain\n\n", $logtext,
 
     "-------------------------------------------------\n\n",
     "Hosting for the PostgreSQL Buildfarm is generously ",
     "provided by: CommandPrompt, The PostgreSQL Company";
 
-; exit;
-
-# using <pre> like this on huge files can make browsers choke
-
-print "Content-Type: text/html\n\n";
+}
 
-print <<EOHTML;
-<html>
-<body>
-<pre>
-$output
-</pre>
-</body>
-</html>
+else 
+{
+    print "Status: 460 bad parameters\n",
+    "Content-Type: text/plain\n\n";
+}
 
-EOHTML