allow dot in stage name
[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 && $stage)
31 {
32     my $db = DBI->connect($dsn,$dbuser,$dbpass);
33
34     die $DBI::errstr unless $db;
35
36     my $statement = q(
37
38         select branch, log_text
39         from build_status_log
40         where sysname = ? and snapshot = ? and log_stage = ? || '.log'
41
42         );
43
44
45     
46     my $sth=$db->prepare($statement);
47     $sth->execute($system,$logdate,$stage);
48     my $row=$sth->fetchrow_arrayref;
49     my ($branch, $logtext) = ("unknown","no log text found");
50     if ($row)
51     {
52         $branch = $row->[0];
53         $logtext =$row->[1];
54     }
55     $sth->finish;
56     $db->disconnect;
57
58     print "Content-Type: text/plain\n\n", $logtext,
59
60     "-------------------------------------------------\n\n",
61     "Hosting for the PostgreSQL Buildfarm is generously ",
62     "provided by: CommandPrompt, The PostgreSQL Company";
63
64     exit;
65
66 }
67
68 else 
69 {
70     print "Status: 460 bad parameters\n",
71     "Content-Type: text/plain\n\n";
72     exit;
73 }
74
75 if ($system && $logdate)
76 {
77
78     my $db = DBI->connect($dsn,$dbuser,$dbpass);
79
80     die $DBI::errstr unless $db;
81
82     my $statement = q(
83
84                 select log_archive
85                 from build_status
86                 where sysname = ? and snapshot = ?
87
88                 );
89
90
91     
92     my $sth=$db->prepare($statement);
93     $sth->execute($system,$logdate);
94     my $row=$sth->fetchrow_arrayref;
95     $tgz=$row->[0];
96     $sth->finish;
97     $db->disconnect;
98
99 }
100
101 unless ($stage)
102 {
103
104     print 
105         "Content-Type: application/x-gzip\n", 
106         "Content-Disposition: attachment; filename=buildfarmlog.tgz\n",
107         "\n",
108         $tgz;
109     exit;
110 }
111
112 my $template = "buildlogXXXXXX";
113 my ($fh, $filename) = tempfile($template, 
114                                                            DIR => '/home/community/pgbuildfarm/buildlogs',
115                                                            UNLINK => 1);
116 print $fh $tgz;
117 close($fh);
118
119 my $output = `tar -z -O -xf $filename $stage.log 2>&1`;
120
121 print "Content-Type: text/plain\n\n", $output,
122
123     "-------------------------------------------------\n\n",
124     "Hosting for the PostgreSQL Buildfarm is generously ",
125     "provided by: CommandPrompt, The PostgreSQL Company";
126
127 ; exit;
128
129 # using <pre> like this on huge files can make browsers choke
130
131 print "Content-Type: text/html\n\n";
132
133 print <<EOHTML;
134 <html>
135 <body>
136 <pre>
137 $output
138 </pre>
139 </body>
140 </html>
141
142 EOHTML