/usr/bin/wg-testEnvironment is in webgui 7.10.29-3.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 | #!/usr/bin/perl
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use strict;
use File::Basename ();
use File::Spec;
my $webguiRoot;
BEGIN {
$webguiRoot = '/usr/share/webgui';
unshift @INC, File::Spec->catdir($webguiRoot, 'lib');
}
use CPAN;
use Getopt::Long;
use Pod::Usage;
use Cwd ();
my ($os, $prereq, $dbi, $dbDrivers, $simpleReport, $help, $noprompt);
GetOptions(
'noprompt' => \$noprompt,
'simpleReport'=>\$simpleReport,
'help'=>\$help,
);
pod2usage( verbose => 2 ) if $help;
print "\nWebGUI is checking your system environment:\n\n";
$prereq = 1;
printTest("Operating System");
printResult(getOs());
printTest("WebGUI Root");
printResult($webguiRoot);
###################################
# Checking Perl
###################################
printTest("Perl Interpreter");
if ($] >= 5.008009) {
printResult("OK");
} else {
failAndExit("Please upgrade to 5.8.9 or later! Cannot continue without Perl 5.8.9 or higher.");
}
##Doing this as a global is not nice, but it works
my $missingModule = 0;
checkModule("LWP", 5.833 );
checkModule("HTML::Form", 5.800, 2 );
checkModule("Net::DNS", 0.66, );
checkModule("Try::Tiny", 0.07, );
checkModule("HTTP::Request", 1.40 );
checkModule("HTTP::Headers", 1.61 );
checkModule("Test::More", 0.96, 2 );
checkModule("Test::MockObject", 1.02, 2 );
checkModule("Test::Deep", 0.095, );
checkModule("Test::LongString", 0.13, 2 );
checkModule("Test::Exception", 0.27, 2 );
checkModule("Test::Differences", 0.5, 2 );
checkModule("Test::Class", 0.31, 2 );
checkModule("Test::MockTime", 0.09, 2 );
checkModule("Pod::Coverage", 0.19, 2 );
checkModule("Text::Balanced", 2.00, 2 );
checkModule("Digest::MD5", 2.38 );
checkModule("DBI", 1.607 );
checkModule("DBD::mysql", 4.010 );
checkModule("HTML::Parser", 3.60 );
checkModule("Archive::Tar", 1.44 );
checkModule("Archive::Zip", 1.26 );
checkModule("IO::Zlib", 1.09 );
checkModule("Compress::Zlib", 2.015 );
checkModule("Net::SMTP", 2.31 );
checkModule("MIME::Tools", 5.427 );
checkModule("Net::POP3", 2.29 );
checkModule("Tie::IxHash", 1.21 );
checkModule("Tie::CPHash", 1.04 );
checkModule("XML::Simple", 2.18 );
checkModule("DateTime", 0.4501 );
checkModule("Time::HiRes", 1.9719 );
checkModule("DateTime::Format::Strptime", 1.0800 );
checkModule("DateTime::Format::Mail", 0.3001 );
checkModule("DateTime::Format::HTTP", 0.38 );
checkModule("Image::Magick", "6.0" );
checkModule("Log::Log4perl", 1.20 );
checkModule("Net::LDAP", 0.39 );
checkModule("HTML::Highlight", 0.20 );
checkModule("HTML::TagFilter", 1.03 );
checkModule("HTML::Template", 2.9 );
checkModule("HTML::Template::Expr", 0.07, 2 );
checkModule("Template", 2.20, 2 );
checkModule("XML::FeedPP", 0.40 );
checkModule("XML::FeedPP::MediaRSS", 0.02 );
checkModule("JSON", 2.12 );
checkModule("JSON::PP", 0.00 );
checkModule("Config::JSON", "1.3.1" );
checkModule("Text::CSV_XS", "0.64" );
checkModule("Net::CIDR::Lite", 0.20 );
checkModule("Finance::Quote", 1.15 );
checkModule("POE", 1.005 );
checkModule("POE::Component::IKC::Server", 0.2001 );
checkModule("POE::Component::Client::HTTP", 0.88 );
checkModule("Apache2::Request", 2.08 );
checkModule("URI::Escape", "3.29" );
checkModule("POSIX" );
checkModule("List::Util" );
checkModule("Color::Calc" );
checkModule("Text::Aspell", 0.01,2 );
checkModule("Weather::Com::Finder", "0.5.3" );
checkModule("Class::InsideOut", "1.09" );
checkModule("HTML::TagCloud", "0.34" );
checkModule("Image::ExifTool", "7.67" );
checkModule("Archive::Any", "0.0932" );
checkModule("Path::Class", '0.16' );
checkModule("Exception::Class", "1.26" );
checkModule("List::MoreUtils", "0.22" );
checkModule("File::Path", "2.07" );
checkModule("Module::Find", "0.06" );
checkModule("Class::C3", "0.21" );
checkModule("Params::Validate", "0.91" );
checkModule('JavaScript::Packer', '1.002' );
checkModule('CSS::Packer', '1.000' );
checkModule('HTML::Packer', "1.000" );
checkModule('Business::Tax::VAT::Validation', '0.20' );
checkModule('Crypt::SSLeay', '0.57' );
checkModule('Scope::Guard', '0.20' );
checkModule('Digest::SHA', '5.47' );
checkModule("CSS::Minifier::XS", "0.03" );
checkModule("JavaScript::Minifier::XS", "0.05" );
checkModule("Readonly", "1.03" );
checkModule("Business::PayPal::API", "0.62" );
checkModule("Business::OnlinePayment", "3.01" );
checkModule("Business::OnlinePayment::AuthorizeNet", "3.22" );
checkModule("Locales", "0.10" );
checkModule("Test::Harness", "3.17" );
checkModule("DateTime::Event::ICal", "0.10" );
checkModule("Cache::FastMmap", "1.35" );
checkModule("Test::Tester", "0" );
checkModule("Test::Log::Dispatch", "0" );
checkModule("CHI", "0.34" );
checkModule('IO::Socket::SSL', );
checkModule('Net::Twitter', "3.13006" );
checkModule('PerlIO::eol', "0.14" );
checkModule('Monkey::Patch', '0.03' );
checkModule('Kwargs', );
checkModule('Data::ICal', '0.16' );
checkModule('common::sense', '3.2' );
checkModule('Geo::Coder::Googlev3', '0.07' );
checkModule('Storable', '2.00' );
failAndExit("Required modules are missing, running no more checks.") if $missingModule;
###################################
# Checking WebGUI
###################################
printTest("WebGUI modules");
if (eval { require WebGUI } && eval { require WebGUI::SQL } && eval { require WebGUI::Config }) {
printResult("OK");
} else {
failAndExit("Not Found. Perhaps you're running this script from the wrong place.");
}
###################################
# Checking Version
###################################
my $version = getLatestWebguiVersion();
printTest("Your version");
if ($version eq $WebGUI::VERSION."-".$WebGUI::STATUS) {
printResult("You are using the latest version - $WebGUI::VERSION-$WebGUI::STATUS");
} else {
printResult("You are using ".$WebGUI::VERSION."-".$WebGUI::STATUS." and ".$version." is available.");
}
printTest("Locating WebGUI configs");
my $configs = WebGUI::Config->readAllConfigs($webguiRoot);
printResult("OK");
foreach my $filename (keys %{$configs}) {
print "\n";
###################################
# Checking Config File
###################################
printTest("Checking config file");
printResult($filename);
###################################
# Checking uploads folder
###################################
printTest("Verifying uploads folder");
if (opendir(DIR,$configs->{$filename}->get("uploadsPath"))) {
printResult("OK");
closedir(DIR);
} else {
printResult("Appears to be missing!");
}
printTest("Verifying DSN");
my $dsnok = 0;
if ($configs->{$filename}->get("dsn") !~ /\DBI\:\w+\:\w+/) {
printResult("DSN is improperly formatted.");
} else {
printResult("OK");
$dsnok = 1;
}
###################################
# Checking database
###################################
if ($dsnok) {
printTest("Verifying database connection");
my ($dbh, $test);
unless (eval {$dbh = DBI->connect($configs->{$filename}->get("dsn"),$configs->{$filename}->get("dbuser"),$configs->{$filename}->get("dbpass"))}) {
printResult("Can't connect with info provided!");
} else {
printResult("OK");
$dbh->disconnect();
}
}
}
print "\nTesting complete!\n\n";
#----------------------------------------
sub checkModule {
my $module = shift;
my $version = shift || 0;
my $skipInstall = shift;
my $afterinstall = shift;
unless (defined $afterinstall) { $afterinstall = 0; }
printTest("Checking for module $module");
my $statement = "require ".$module.";";
# we tried installing, now what?
if ($afterinstall == 1) {
failAndExit("Install of $module failed!") unless eval($statement);
# //todo: maybe need to check new install module version
printResult("OK");
return;
}
# let's see if the module is installed
elsif (eval($statement)) {
$statement = '$'.$module."::VERSION";
my $currentVersion = eval($statement);
# is it the correct version
if ($currentVersion >= $version) {
printResult("OK");
}
# not the correct version, now what?
else {
# do nothing we're just reporting the modules.
if ($simpleReport) {
printResult("Outdated - Current: ".$currentVersion." / Required: ".$version);
}
# do nothing, this module isn't required
elsif ( $skipInstall == 2 ) {
printResult("Outdated - Current: ".$currentVersion." / Required: ".$version.", but it's optional anyway");
}
# if we're an admin let's offer to install it
elsif (isRootRequirementMet()) {
my $installThisModule = defined $noprompt ? "y" : "n";
if ( $installThisModule eq "n" ) {
$installThisModule
= prompt ("$currentVersion is installed, but we need at least "
. "$version, do you want to upgrade it now?", "y", "y", "n");
}
# does the user wish to install it
if ($installThisModule eq "y") {
installModule($module);
checkModule($module,$version,$skipInstall,1);
}
# user doesn't wish to install it
else {
printResult("Upgrade aborted by user input.");
}
}
# we're not root so lets skip it
else {
printResult("Outdated - Current: ".$currentVersion." / Required: ".$version
.", but you're not root, so you need to ask your administrator to upgrade it.");
}
}
# module isn't installed, now what?
} else {
# skip optional module
if ($skipInstall == 2) {
printResult("Not Installed, but it's optional anyway");
}
# skip
elsif ($simpleReport) {
printResult("Not Installed");
$missingModule = 1;
}
# if we're root lets try and install it
elsif ( isRootRequirementMet()) {
my $installThisModule = defined $noprompt ? "y" : "n";
if ( $installThisModule eq "n" ) {
$installThisModule
= prompt ("Not installed, do you want to install it now?",
"y", "y", "n"
);
}
# user wishes to upgrade
if ($installThisModule eq "y") {
installModule($module);
checkModule($module,$version,$skipInstall,1);
}
# install aborted by user
else {
printResult("Install aborted by user input.");
$missingModule = 1;
}
}
# can't install, not root
else {
printResult("Not installed, but you're not root, so you need to ask your administrator to install it.");
$missingModule = 1;
}
}
}
#----------------------------------------
sub failAndExit {
my $exitmessage = shift;
print $exitmessage."\n\n";
exit;
}
#----------------------------------------
sub getLatestWebguiVersion {
printTest("Getting current WebGUI version");
my $currentversionUserAgent = new LWP::UserAgent;
$currentversionUserAgent->env_proxy;
$currentversionUserAgent->agent("WebGUI-Check/2.1");
$currentversionUserAgent->timeout(30);
$currentversionUserAgent->env_proxy();
my $header = new HTTP::Headers;
my $referer = "http://".`hostname`."/webgui-cli-version";
chomp $referer;
$header->referer($referer);
my $currentversionRequest = new HTTP::Request (GET => "http://update.webgui.org/latest-version.txt", $header);
my $currentversionResponse = $currentversionUserAgent->request($currentversionRequest);
my $version = $currentversionResponse->content;
chomp $version;
if ($currentversionResponse->is_error || $version eq "") {
printResult("Failed! Continuing without it.");
}
else {
printResult("OK");
}
return $version;
}
#----------------------------------------
sub getOs {
if ($^O =~ /MSWin32/i || $^O =~ /^Win/i) {
return "Windowsish";
}
return "Linuxish";
}
#----------------------------------------
sub installModule {
my $module = shift;
print "Attempting to install ".$module."...\n";
my $cwd = Cwd::cwd;
CPAN::Shell->install($module);
chdir $cwd;
}
#----------------------------------------
sub isIn {
my $key = shift;
$_ eq $key and return 1 for @_;
return 0;
}
#----------------------------------------
sub isRootRequirementMet {
if (getOs() eq "Linuxish") {
return ($< == 0);
} else {
return 1;
}
}
#----------------------------------------
sub printTest {
my $test = shift;
print sprintf("%-50s", $test.": ");
}
#----------------------------------------
sub printResult {
my $result = shift;
print "$result\n";
}
#----------------------------------------
sub prompt {
my $question = shift;
my $default = shift;
my @answers = @_; # the rest are answers
print "\n".$question." ";
print "{".join("|",@answers)."} " if ($#answers > 0);
print "[".$default."] " if (defined $default);
my $answer = <STDIN>;
chomp $answer;
$answer = $default if ($answer eq "");
$answer = prompt($question,$default,@answers) if (($#answers > 0 && !(isIn($answer,@answers))) || $answer eq "");
return $answer;
}
__END__
=head1 NAME
testEnvironment - Test Perl environment for proper WebGUI support.
=head1 SYNOPSIS
testEnvironment --simpleReport
testEnvironment --help
=head1 DESCRIPTION
This WebGUI utility script tests the current Perl environment to make
sure all of WebGUI's dependencies are satisfied. It also checks for
proper installation of WebGUI's libraries.
If any of the required Perl modules is not available or outdated, the
script will ask if it should attempt installation using CPAN. This will
only be possible if the script is being run as a superuser.
The script will attempt to find out the latest available version from
L<http://update.webgui.org>, and compare with the currently installed one.
=over
=item B<--simpleReport>
Prints the status report to standard output, but does not attempt
to upgrade any outdated or missing Perl modules.
=item B<--help>
Shows this documentation, then exits.
=back
=head1 AUTHOR
Copyright 2001-2009 Plain Black Corporation.
=cut
|