Initial commit
[buildfarm-server.git] / cgi-bin / show_stage_log.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use DBI;
5 use Template;
6 use CGI;
7 use File::Temp qw(tempfile);
8
9 use vars qw($dbhost $dbname $dbuser $dbpass $dbport @log_file_names);
10
11
12 require "$ENV{BFConfDir}/BuildFarmWeb.pl";
13 #require "BuildFarmWeb.pl";
14
15 die "no dbname" unless $dbname;
16 die "no dbuser" unless $dbuser;
17
18 my $dsn="dbi:Pg:dbname=$dbname";
19 $dsn .= ";host=$dbhost" if $dbhost;
20 $dsn .= ";port=$dbport" if $dbport;
21
22 my $query = new CGI;
23
24 my $system = $query->param('nm'); $system =~ s/[^a-zA-Z0-9_ -]//g;
25 my $logdate = $query->param('dt');$logdate =~ s/[^a-zA-Z0-9_ -]//g;
26 my $stage = $query->param('stg');$stage =~ s/[^a-zA-Z0-9_ -]//g;
27
28 use vars qw($tgz);
29
30 if ($system && $logdate)
31 {
32
33     my $db = DBI->connect($dsn,$dbuser,$dbpass);
34
35     die $DBI::errstr unless $db;
36
37     my $statement = q(
38
39                 select log_archive
40                 from build_status
41                 where sysname = ? and snapshot = ?
42
43                 );
44
45
46     
47     my $sth=$db->prepare($statement);
48     $sth->execute($system,$logdate);
49     my $row=$sth->fetchrow_arrayref;
50     $tgz=$row->[0];
51     $sth->finish;
52     $db->disconnect;
53
54 }
55
56 unless ($stage)
57 {
58
59     print 
60         "Content-Type: application/x-gzip\n", 
61         "Content-Disposition: attachment; filename=buildfarmlog.tgz\n",
62         "\n",
63         $tgz;
64     exit;
65 }
66
67 my $template = "buildlogXXXXXX";
68 my ($fh, $filename) = tempfile($template, UNLINK => 1);
69 print $fh $tgz;
70 close($fh);
71
72 my $output = `tar -z -O -xf $filename $stage.log 2>&1`;
73
74 print "Content-Type: text/plain\n\n", $output,
75
76     "-------------------------------------------------\n\n",
77     "Hosting for the PostgreSQL Buildfarm is generously ",
78     "provided by: CommandPrompt, The PostgreSQL Company";
79
80 ; exit;
81
82 # using <pre> like this on huge files can make browsers choke
83
84 print "Content-Type: text/html\n\n";
85
86 print <<EOHTML;
87 <html>
88 <body>
89 <pre>
90 $output
91 </pre>
92 </body>
93 </html>
94
95 EOHTML