2
# -*- Mode: perl; indent-tabs-mode: nil -*-
4
# The contents of this file are subject to the Mozilla Public
5
# License Version 1.1 (the "License"); you may not use this file
6
# except in compliance with the License. You may obtain a copy of
7
# the License at http://www.mozilla.org/MPL/
9
# Software distributed under the License is distributed on an "AS
10
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11
# implied. See the License for the specific language governing
12
# rights and limitations under the License.
14
# Contributor(s): Joel Peshkin <bugreport@peshkin.net>
15
# Byron Jones <byron@glob.com.au>
17
# testserver.pl is invoked with the baseurl of the Bugzilla installation
18
# as its only argument. It attempts to troubleshoot as many installation
22
use Bugzilla::Config qw($datadir);
23
my $envpath = $ENV{'PATH'};
27
eval "require LWP; require LWP::UserAgent;";
30
$ENV{'PATH'}= $envpath;
32
if ((@ARGV != 1) || ($ARGV[0] !~ /^https?:/))
34
print "Usage: $0 <URL to this Bugzilla installation>\n";
35
print "e.g.: $0 http://www.mycompany.com/bugzilla\n";
40
# Try to determine the GID used by the webserver.
41
my @pscmds = ('ps -eo comm,gid', 'ps -acxo command,gid', 'ps -acxo command,rgid');
43
if ($^O !~ /MSWin32/i) {
44
foreach my $pscmd (@pscmds) {
45
open PH, "$pscmd 2>/dev/null |";
46
while (my $line = <PH>) {
47
if ($line =~ /^(?:\S*\/)?(?:httpd|apache)2?\s+(\d+)$/) {
48
$sgid = $1 if $1 > $sgid;
55
# Determine the numeric GID of $webservergroup
57
if ($::webservergroup =~ /^(\d+)$/) {
60
eval { $webgroupnum = (getgrnam $::webservergroup) || 0; };
63
# Check $webservergroup against the server's GID
65
if ($::webservergroup eq "") {
67
"WARNING \$webservergroup is set to an empty string.
68
That is a very insecure practice. Please refer to the
69
Bugzilla documentation.\n";
70
} elsif ($webgroupnum == $sgid) {
71
print "TEST-OK Webserver is running under group id in \$webservergroup.\n";
74
"TEST-WARNING Webserver is running under group id not matching \$webservergroup.
75
This if the tests below fail, this is probably the problem.
76
Please refer to the webserver configuration section of the Bugzilla guide.
77
If you are using virtual hosts or suexec, this warning may not apply.\n";
79
} elsif ($^O !~ /MSWin32/i) {
81
"TEST-WARNING Failed to find the GID for the 'httpd' process, unable
82
to validate webservergroup.\n";
86
# Try to fetch a static file (front.png)
88
my $url = $ARGV[0] . "/skins/standard/index/front.png";
90
print "TEST-OK Got front picture.\n";
93
"TEST-FAILED Fetch of skins/standard/index/front.png failed
94
Your webserver could not fetch $url.
95
Check your webserver configuration and try again.\n";
99
# Try to execute a cgi script
100
my $response = fetch($ARGV[0] . "/testagent.cgi");
101
if ($response =~ /^OK/) {
102
print "TEST-OK Webserver is executing CGIs.\n";
103
} elsif ($response =~ /^#!/) {
105
"TEST-FAILED Webserver is fetching rather than executing CGI files.
106
Check the AddHandler statement in your httpd.conf file.\n";
109
print "TEST-FAILED Webserver is not executing CGI files.\n";
112
# Make sure that webserver is honoring .htaccess files
113
$::localconfig =~ s~^\./~~;
114
$url = $ARGV[0] . "/$::localconfig";
115
$response = fetch($url);
118
"TEST-FAILED Webserver is permitting fetch of $url.
119
This is a serious security problem.
120
Check your webserver configuration.\n";
123
print "TEST-OK Webserver is preventing fetch of $url.\n";
126
# Test chart generation
131
# Ensure major versions of GD and libgd match
132
# Windows's GD module include libgd.dll, guaranteed to match
133
if ($^O !~ /MSWin32/i) {
134
my $gdlib = `gdlib-config --version 2>&1` || "";
137
print "TEST-WARNING Failed to run gdlib-config; can't compare " .
141
my $gd = $GD::VERSION;
143
my $verstring = "GD version $gd, libgd version $gdlib";
145
$gdlib =~ s/^([^\.]+)\..*/$1/;
146
$gd =~ s/^([^\.]+)\..*/$1/;
149
print "TEST-OK $verstring; Major versions match.\n";
151
print "TEST-FAILED $verstring; Major versions do not match.\n";
158
my $image = new GD::Image(100, 100);
159
my $black = $image->colorAllocate(0, 0, 0);
160
my $white = $image->colorAllocate(255, 255, 255);
161
my $red = $image->colorAllocate(255, 0, 0);
162
my $blue = $image->colorAllocate(0, 0, 255);
163
$image->transparent($white);
164
$image->rectangle(0, 0, 99, 99, $black);
165
$image->arc(50, 50, 95, 75, 0, 360, $blue);
166
$image->fill(50, 50, $red);
168
if ($image->can('png')) {
169
create_file("$datadir/testgd-local.png", $image->png);
170
check_image("$datadir/testgd-local.png", 'GD');
172
print "TEST-FAILED GD doesn't support PNG generation.\n";
176
print "TEST-FAILED GD returned: $@\n";
180
eval 'use Chart::Lines';
182
print "TEST-FAILED Chart::Lines is not installed.\n";
185
my $chart = Chart::Lines->new(400, 400);
187
$chart->add_pt('foo', 30, 25);
188
$chart->add_pt('bar', 16, 32);
190
$chart->png("$datadir/testchart-local.png");
191
check_image("$datadir/testchart-local.png", "Chart");
194
print "TEST-FAILED Chart returned: $@\n";
198
eval 'use Template::Plugin::GD::Image';
200
print "TEST-FAILED Template::Plugin::GD is not installed.\n";
203
print "TEST-OK Template::Plugin::GD is installed.\n";
211
my $req = HTTP::Request->new(GET => $url);
212
my $ua = LWP::UserAgent->new;
213
my $res = $ua->request($req);
214
$rtn = ($res->is_success ? $res->content : undef);
215
} elsif ($url =~ /^https:/i) {
216
die("You need LWP installed to use https with testserver.pl");
218
my($host, $port, $file) = ('', 80, '');
219
if ($url =~ m#^http://([^:]+):(\d+)(/.*)#i) {
220
($host, $port, $file) = ($1, $2, $3);
221
} elsif ($url =~ m#^http://([^/]+)(/.*)#i) {
222
($host, $file) = ($1, $2);
224
die("Cannot parse url");
227
my $proto = getprotobyname('tcp');
228
socket(SOCK, PF_INET, SOCK_STREAM, $proto);
229
my $sin = sockaddr_in($port, inet_aton($host));
230
if (connect(SOCK, $sin)) {
232
select((select(SOCK), $| = 1)[0]);
235
print SOCK "GET $file HTTP/1.0\015\012host: $host:$port\015\012\015\012";
237
while (defined(my $line = <SOCK>)) {
238
last if $line eq "\015\012";
242
while (defined(my $line = <SOCK>)) {
246
my ($status) = $header =~ m#^HTTP/\d+\.\d+ (\d+)#;
247
$rtn = (($status =~ /^2\d\d/) ? $content : undef);
254
my ($local_file, $library) = @_;
255
my $filedata = read_file($local_file);
256
if ($filedata =~ /^\x89\x50\x4E\x47\x0D\x0A\x1A\x0A/) {
257
print "TEST-OK $library library generated a good PNG image.\n";
260
print "TEST-WARNING $library library did not generate a good PNG.\n";
265
my ($filename, $content) = @_;
266
open(FH, ">$filename")
267
or die "Failed to create $filename: $!\n";
276
or die "Failed to open $filename: $!\n";