Add 4.97+security
[buildfarm-server.git] / cgi-bin / show_stage_log.pl
1 #!/usr/bin/perl
2
3 =comment
4
5 Copyright (c) 2003-2010, Andrew Dunstan
6 Copyright (c) 2022, The Exim Maintainers
7
8 See accompanying License file for license details
9
10 =cut 
11
12 use strict;
13 use DBI;
14 use Template;
15 use CGI;
16 use File::Temp qw(tempfile);
17
18 use vars qw($dbhost $dbname $dbuser $dbpass $dbport @log_file_names);
19
20 use FindBin qw($RealBin);
21 require "$RealBin/../BuildFarmWeb.pl";
22
23 die "no dbname" unless $dbname;
24 die "no dbuser" unless $dbuser;
25
26 my $dsn="dbi:Pg:dbname=$dbname";
27 $dsn .= ";host=$dbhost" if $dbhost;
28 $dsn .= ";port=$dbport" if $dbport;
29
30 my $query = new CGI;
31
32 my $system = $query->param('nm'); $system =~ s/[^a-zA-Z0-9_ -]//g;
33 my $logdate = $query->param('dt');$logdate =~ s/[^a-zA-Z0-9_ -]//g;
34 my $stage = $query->param('stg');$stage =~ s/[^a-zA-Z0-9._ -]//g;
35 my $brnch = $query->param('branch') || 'HEAD'; $brnch =~ s/[^a-zA-Z0-9._ -]//g;
36
37 use vars qw($tgz);
38
39 if ($system && $logdate && $stage)
40 {
41     my $db = DBI->connect($dsn,$dbuser,$dbpass);
42
43     die $DBI::errstr unless $db;
44
45     if ($logdate =~ /^latest$/i)
46     {
47         my $find_latest = qq{
48             select max(snapshot) 
49             from build_status_log 
50             where sysname = ? 
51                 and snapshot > now() - interval '30 days' 
52                 and log_stage = ? || '.log'
53                 and branch = ?
54         };
55         my $logs = $db->selectcol_arrayref($find_latest,undef,$system,$stage,$brnch);
56         $logdate = shift(@$logs);
57     }
58
59     my $statement = q(
60
61         select branch, log_text
62         from build_status_log
63         where sysname = ? and snapshot = ? and log_stage = ? || '.log'
64
65         );
66     
67     my $sth=$db->prepare($statement);
68     $sth->execute($system,$logdate,$stage);
69     my $row=$sth->fetchrow_arrayref;
70     my ($branch, $logtext) = ("unknown","no log text found");
71     if ($row)
72     {
73         $branch = $row->[0];
74         $logtext =$row->[1];
75     }
76     $sth->finish;
77     $db->disconnect;
78
79     print "Content-Type: text/plain\n\nSnapshot: $logdate\n\n", $logtext,
80
81     "-------------------------------------------------\n\n",
82     "Hosting for the Exim BuildFarm is generously ",
83     "provided by: Mythic Beasts Ltd";
84
85 }
86
87 else 
88 {
89     print "Status: 460 bad parameters\n",
90     "Content-Type: text/plain\n\n";
91 }