root/branches/release-36/mt-check.cgi.pre

Revision 1822, 18.6 kB (checked in by fumiakiy, 8 months ago)

Added Scalar::Util in the list of optional modules in mt-check.cgi. Check and hide appropriately if the required module for Async Job Queue feature is not available. BugId:77208

  • Property svn:keywords set to Author Date Id Revision
Line 
1 #!/usr/bin/perl -w
2
3 # Movable Type (r) Open Source (C) 2001-2008 Six Apart, Ltd.
4 # This program is distributed under the terms of the
5 # GNU General Public License, version 2.
6 #
7 # $Id$
8
9 use strict;
10 sub BEGIN {
11     my $dir;
12     if (eval { require File::Spec; 1; }) {
13         if (!($dir = $ENV{MT_HOME})) {
14             if ($0 =~ m!(.*[/\\])!) {
15                 $dir = $1;
16             } else {
17                 $dir = './';
18             }
19             $ENV{MT_HOME} = $dir;
20         }
21         unshift @INC, File::Spec->catdir($dir, 'lib');
22         unshift @INC, File::Spec->catdir($dir, 'extlib');
23     }
24 }
25
26 my $cfg_exist;
27 my $mt_static_path = q();
28 my $mt_cgi_path;
29 if ((-f File::Spec->catfile($ENV{MT_HOME}, 'mt-config.cgi')) ||
30     (-f File::Spec->catfile($ENV{MT_HOME}, 'mt.cfg'))) {
31     $cfg_exist = 1;
32     my $file_handle = open(CFG, $ENV{MT_HOME}.'/mt.cfg') || open(CFG, $ENV{MT_HOME}.'/mt-config.cgi');
33     my $line;
34     while ($line = <CFG>) {
35         next if $line !~ /\S/ || $line =~ /^#/;
36         if ($line =~ s/StaticWebPath[\s]*([^\n]*)/$1/) {
37             $mt_static_path = $line;
38             chomp($mt_static_path);
39         }
40         elsif ($line =~ s/CGIPath[\s]*([^\n]*)/$1/) {
41             $mt_cgi_path = $line;
42             chomp($mt_cgi_path);
43         }
44     }
45     if ( !$mt_static_path && $mt_cgi_path ) {
46         $mt_cgi_path .= '/' if $mt_cgi_path !~ m|/$|;
47         $mt_static_path = $mt_cgi_path . 'mt-static/';
48     }
49 }
50
51 local $| = 1;
52
53 use CGI;
54 my $cgi = new CGI;
55 my $view = $cgi->param("view");
56 my $version = $cgi->param("version");
57 $version ||= '__PRODUCT_VERSION_ID__';
58
59 my ($mt, $LH);
60 my $lang = '__BUILD_LANGUAGE__';
61 eval {
62     require MT::App::Wizard;
63     $mt = MT::App::Wizard->new();
64     my $cfg = $mt->config;
65     $cfg->PublishCharset('utf-8');
66     $cfg->DefaultLanguage($lang);
67     require MT::L10N;
68     $LH = $mt ? $mt->language_handle : MT::L10N->get_handle($lang);
69 };
70
71 sub trans_templ {
72     my($text) = @_;
73     return $mt->translate_templatized($text) if $mt;
74     $text =~ s!(<MT_TRANS(?:\s+((?:\w+)\s*=\s*(["'])(?:<[^>]+?>|[^\3]+?)+?\3))+?\s*/?>)!
75         my($msg, %args) = ($1);
76         #print $msg;
77         while ($msg =~ /\b(\w+)\s*=\s*(["'])((?:<[^>]+?>|[^\2])*?)\2/g) {  #"
78             $args{$1} = $3;
79         }
80         $args{params} = '' unless defined $args{params};
81         my @p = map decode_html($_),
82                 split /\s*%%\s*/, $args{params};
83         @p = ('') unless @p;
84         my $translation = translate($args{phrase}, @p);
85         $translation =~ s/([\\'])/\\$1/sg if $args{escape};
86         $translation;
87     !ge;
88     $text;
89 }
90
91 sub translate {
92     return (
93         $mt ? $mt->translate(@_)
94             : $LH ? $LH->maketext(@_)
95                   : merge_params(@_)
96     );
97 }
98
99 sub decode_html {
100     my($html) = @_;
101     if ($cfg_exist && (eval 'use MT::Util; 1')) {
102         return MT::Util::decode_html($html);
103     } else {
104         $html =~ s#&quot;#"#g;
105         $html =~ s#&lt;#<#g;
106         $html =~ s#&gt;#>#g;
107         $html =~ s#&amp;#&#g;
108     }
109     $html;
110 }
111
112 sub merge_params {
113     my ($msg, @param) = @_;
114     my $cnt = 1;
115     foreach my $p (@param) {
116         $msg =~ s/\[_$cnt\]/$p/g;
117         $cnt++;
118     }
119     $msg;
120 }
121
122 print "Content-Type: text/html; charset=utf-8\n\n";
123 if (!$view) {
124     print trans_templ(<<HTML);
125
126 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
127 <html xmlns="http://www.w3.org/1999/xhtml">
128
129 <head>
130     <meta http-equiv="content-type" content="text/html; charset=utf-8" />
131     <meta http-equiv="content-language" content="$lang" />
132    
133     <title><MT_TRANS phrase="Movable Type System Check"> [mt-check.cgi]</title>
134    
135     <style type=\"text/css\">
136         <!--
137        
138             body {
139                 font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
140                 font-size: 13px;
141                 margin: 0;
142                 padding: 0;
143                 background-color: #fff;
144             }
145            
146             body.has-static {
147                 background: #fff url('$mt_static_path/images/chromeless/chromeless_top_bg.gif') repeat-x;
148             }
149            
150             body.has-static #header {
151                 background: url('$mt_static_path/images/chromeless/movable-type-logo.gif') no-repeat 25px 15px;
152                 height: 55px;
153             }
154            
155             #content {
156                 margin: 20px 20px 100px;
157             }
158            
159             h1 {
160                 margin: 0;
161                 padding: 10px;
162                 text-align: center;
163                 font-size: 22px;
164                 color: #fff;
165                 background: #000;
166             }
167             body.has-static #header h1 {
168                 display: none;
169             }
170            
171             h2 {
172                 margin-top: 2em;
173                 margin-bottom: .5em;
174                 font-size: 24px;
175                 font-weight: normal;
176             }
177             h2#system-info {
178                 margin-top: 1em;
179             }
180            
181             h3 {
182                 color: #333;
183                 font-size: 16px;
184                 margin-bottom: 0px;
185             }
186    
187             p, ul {
188                 margin: 0 0 .75em 0;
189                 padding: 0;
190             }
191            
192             ul {
193                 padding-left: 20px;
194             }
195            
196             .msg {
197                 margin: 0 0 10px 0;
198                 padding: 16px 10px 16px 46px;
199                 background-repeat: no-repeat;
200             }
201             .msg-info {
202                 background-color: #eaf2ff;
203                 background-image: url('$mt_static_path/images/icon_info.gif');
204                 background-position: 12px center;
205                 border: 1px solid #999;
206             }
207
208                         .ready {
209                                 color: #fff;
210                                 background-color: #9C6;
211                 border: 0;
212                 padding-left: 5px;
213                         }
214
215             .msg-success {
216                 background-color: #CFC;
217                 background-image: url('$mt_static_path/images/icon_success.png');
218                 background-position: 12px .75em;
219                 font-size: 24px;
220             }
221             .msg-success h2 {
222                 margin-top: 0;
223             }
224             .msg-success p {
225                 font-size: 13px;
226             }
227
228             .info {
229                 margin-left: 60px;
230                 margin-right: 60px;
231                 padding: 20px;
232                 border: 1px solid #eaf2ff;
233                 background: #eaf2ff;
234                 color: #000;
235             }
236
237             .installed {
238                 color: #93b06b;
239                 padding-top: 0px;
240                 margin-top: 0px;
241             }
242
243             .warning {
244                 padding-top: 0px;
245                 margin-top: 4px;
246                 border-left: 1px solid red;
247                 padding-left: 10px;
248                 margin-left: 20px;
249             }
250            
251             ul.version {
252                 margin-bottom: 0;
253             }
254        
255         //-->
256     </style>
257
258 </head>
259
260 HTML
261     if ($mt_static_path) {
262         print "<body class=\"has-static\">\n";
263     } else {
264         print "<body>\n";
265     }
266     print trans_templ(<<HTML);
267 <div id="header"><h1><MT_TRANS phrase="Movable Type System Check"> [mt-check.cgi]</h1></div>
268
269 <div id="content">
270 <p class="msg msg-info"><MT_TRANS phrase="The mt-check.cgi script provides you with information on your system's configuration and determines whether you have all of the components you need to run Movable Type."></p>
271 HTML
272 }
273
274 my $is_good = 1;
275 my (@REQ, @DATA, @OPT);
276
277 my @CORE_REQ = (
278     [ 'CGI', 0, 1, translate('CGI is required for all Movable Type application functionality.') ],
279
280     [ 'Image::Size', 0, 1, translate('Image::Size is required for file uploads (to determine the size of uploaded images in many different formats).') ],
281
282     [ 'File::Spec', 0.8, 1, translate('File::Spec is required for path manipulation across operating systems.') ],
283
284     [ 'CGI::Cookie', 0, 1, translate('CGI::Cookie is required for cookie authentication.') ],
285 );
286
287 my @CORE_DATA = (
288     [ 'DBI', 1.21, 0, translate('DBI is required to store data in database.') ],
289
290     [ 'DBD::mysql', 0, 0, translate('DBI and DBD::mysql are required if you want to use the MySQL database backend.') ],
291
292     [ 'DBD::Pg', 1.32, 0, translate('DBI and DBD::Pg are required if you want to use the PostgreSQL database backend.') ],
293
294     [ 'DBD::SQLite', 0, 0, translate('DBI and DBD::SQLite are required if you want to use the SQLite database backend.') ],
295
296     [ 'DBD::SQLite2', 0, 0, translate('DBI and DBD::SQLite2 are required if you want to use the SQLite 2.x database backend.') ],
297
298 );
299
300 my @CORE_OPT = (
301     [ 'HTML::Entities', 0, 0, translate('HTML::Entities is needed to encode some characters, but this feature can be turned off using the NoHTMLEntities option in the configuration file.') ],
302
303     [ 'LWP::UserAgent', 0, 0, translate('LWP::UserAgent is optional; It is needed if you wish to use the TrackBack system, the weblogs.com ping, or the MT Recently Updated ping.') ],
304
305     [ 'HTML::Parser', 0, 0, translate('HTML::Parser is optional; It is needed if you wish to use the TrackBack system, the weblogs.com ping, or the MT Recently Updated ping.') ],
306
307     [ 'SOAP::Lite', 0.50, 0, translate('SOAP::Lite is optional; It is needed if you wish to use the MT XML-RPC server implementation.') ],
308
309     [ 'File::Temp', 0, 0, translate('File::Temp is optional; It is needed if you would like to be able to overwrite existing files when you upload.') ],
310
311     [ 'Scalar::Util', 0, 1, translate('Scalar::Util is optional; It is needed if you want to use the Publish Queue feature.')],
312
313     [ 'List::Util', 0, 1, translate('List::Util is optional; It is needed if you want to use the Publish Queue feature.')],
314
315     [ 'Image::Magick', 0, 0, translate('Image::Magick is optional; It is needed if you would like to be able to create thumbnails of uploaded images.') ],
316
317     [ 'Storable', 0, 0, translate('Storable is optional; it is required by certain MT plugins available from third parties.')],
318
319     [ 'Crypt::DSA', 0, 0, translate('Crypt::DSA is optional; if it is installed, comment registration sign-ins will be accelerated.')],
320
321     [ 'MIME::Base64', 0, 0, translate('MIME::Base64 is required in order to enable comment registration.')],
322
323     [ 'XML::Atom', 0, 0, translate('XML::Atom is required in order to use the Atom API.')],
324
325     [ 'Cache::Memcached', 0, 0, translate('Cache::Memcached and memcached server/daemon is required in order to use memcached as caching mechanism used by Movable Type.')],
326
327     [ 'Archive::Tar', 0, 0, translate('Archive::Tar is required in order to archive files in backup/restore operation.')],
328
329     [ 'IO::Compress::Gzip', 0, 0, translate('IO::Compress::Gzip is required in order to compress files in backup/restore operation.')],
330        
331     [ 'IO::Uncompress::Gunzip', 0, 0, translate('IO::Uncompress::Gunzip is required in order to decompress files in backup/restore operation.')],
332    
333     [ 'Archive::Zip', 0, 0, translate('Archive::Zip is required in order to archive files in backup/restore operation.')],
334
335     [ 'XML::SAX', 0, 0, translate('XML::SAX and/or its dependencies is required in order to restore.')],
336
337     [ 'Digest::SHA1', 0, 0, translate('Digest::SHA1 and its dependencies are required in order to allow commenters to be authenticated by OpenID providers including Vox and LiveJournal.')],
338     [ 'Mail::Sendmail', 0, 0, translate('Mail::Sendmail is required for sending mail via SMTP Server.')],
339 );
340
341 use Cwd;
342 my $cwd = '';
343 {
344     my($bad);
345     local $SIG{__WARN__} = sub { $bad++ };
346     eval { $cwd = Cwd::getcwd() };
347     if ($bad || $@) {
348         eval { $cwd = Cwd::cwd() };
349         if ($@ && $@ !~ /Insecure \$ENV{PATH}/) {
350             die $@;
351         }
352     }
353 }
354
355 my $ver = ref($^V) eq 'version' ? $^V->normal : ( $^V ? join('.', unpack 'C*', $^V) : $] );
356 my $perl_ver_check = '';
357 if ($] < 5.006001) {  # our minimal requirement for support
358     $perl_ver_check = <<EOT;
359 <p class="warning"><MT_TRANS phrase="The version of Perl installed on your server ([_1]) is lower than the minimum supported version ([_2]). Please upgrade to at least Perl [_2]." params="$ver%%5.6.1"></p>
360 EOT
361 }
362 my $config_check = '';
363 if (!$cfg_exist) {
364     $config_check = <<CONFIG;
365 <p class="warning"><MT_TRANS phrase="Movable Type configuration file was not found."></p>
366 CONFIG
367 }
368 my $server = $ENV{SERVER_SOFTWARE};
369 my $inc_path = join "<br />\n", @INC;
370 print trans_templ(<<INFO);
371 <h2 id="system-info"><MT_TRANS phrase="System Information"></h2>
372 $perl_ver_check
373 $config_check
374 INFO
375 if ($version) {
376     # sanitize down to letters numbers dashes and period
377     $version =~ s/[^a-zA-Z0-9\-\.]//g;
378 print trans_templ(<<INFO);
379 <ul class="version">
380     <li><strong><MT_TRANS phrase="Movable Type version:"></strong> <code>$version</code></li>
381 </ul>
382 INFO
383 }
384 print trans_templ(<<INFO);
385 <ul>
386         <li><strong><MT_TRANS phrase="Current working directory:"></strong> <code>$cwd</code></li>
387         <li><strong><MT_TRANS phrase="MT home directory:"></strong> <code>$ENV{MT_HOME}</code></li>
388         <li><strong><MT_TRANS phrase="Operating system:"></strong> $^O</li>
389         <li><strong><MT_TRANS phrase="Perl version:"></strong> <code>$ver</code></li>
390         <li><strong><MT_TRANS phrase="Perl include path:"></strong><br /> <code>$inc_path</code></li>
391 INFO
392 if ($server) {
393 print trans_templ(<<INFO);
394     <li><strong><MT_TRANS phrase="Web server:"></strong> <code>$server</code></li>
395 INFO
396 }
397
398 ## Try to create a new file in the current working directory. This
399 ## isn't a perfect test for running under cgiwrap/suexec, but it
400 ## is a pretty good test.
401 my $TMP = "test$$.tmp";
402 local *FH;
403 if (open(FH, ">$TMP")) {
404     close FH;
405     unlink($TMP);
406     print trans_templ('    <li><MT_TRANS phrase="(Probably) Running under cgiwrap or suexec"></li>' . "\n");
407 }
408
409 print "\n\n</ul>\n";
410
411 exit if $ENV{QUERY_STRING} && $ENV{QUERY_STRING} eq 'sys-check';
412
413 if ($mt) {
414     my $req = $mt->registry("required_packages");
415     foreach my $key (keys %$req) {
416         next if $key eq 'DBI';
417         my $pkg = $req->{$key};
418         push @REQ, [ $key, $pkg->{version} || 0, 1, $pkg->{label}, $key, $pkg->{link} ];
419     }
420     my $drivers = $mt->object_drivers;
421     foreach my $key (keys %$drivers) {
422         my $driver = $drivers->{$key};
423         my $label = $driver->{label};
424         my $link = 'http://search.cpan.org/dist/' . $driver->{dbd_package};
425         $link =~ s/::/-/g;
426         push @DATA, [ $driver->{dbd_package}, $driver->{dbd_version}, 0,
427             $mt->translate("The [_1] database driver is required to use [_2].", $driver->{dbd_package}, $label),
428             $label, $link ];
429     }
430     unshift @DATA, [ 'DBI', 1.21, 0, translate('DBI is required to store data in database.') ]
431         if @DATA;
432     my $opt = $mt->registry("optional_packages");
433     foreach my $key (keys %$opt) {
434         my $pkg = $opt->{$key};
435         push @OPT, [ $key, $pkg->{version} || 0, 0, $pkg->{label}, $key, $pkg->{link} ];
436     }
437 }
438 @REQ  = @CORE_REQ  unless @REQ;
439 @DATA = @CORE_DATA unless @DATA;
440 @OPT  = @CORE_OPT  unless @OPT;
441
442 for my $list (\@REQ, \@DATA, \@OPT) {
443     my $data = ($list == \@DATA);
444     my $req = ($list == \@REQ);
445     my $type;
446     my $phrase;
447
448     if (!$view) {
449         $phrase = translate("Checking for");
450     } else {
451         $phrase = translate("Installed");
452     }
453
454     if ($data) {
455         $type = translate("Data Storage");
456     } elsif ($req) {
457         $type = translate("Required");
458     } else {
459         $type = translate("Optional");
460     }
461     print trans_templ(qq{<h2><MT_TRANS phrase="[_1] [_2] Modules" params="$phrase%%$type"></h2>\n\t<div>\n});
462     if (!$req && !$data) {
463         if (!$view) {
464         print trans_templ(<<MSG);
465     <p class="msg msg-info"><MT_TRANS phrase="The following modules are <strong>optional</strong>. If your server does not have these modules installed, you only need to install them if you require the functionality that the module provides."></p>
466
467 MSG
468        }
469     }
470     if ($data) {
471         if (!$view) {
472         print trans_templ(<<MSG);
473         <p class="msg msg-info"><MT_TRANS phrase="Some of the following modules are required by the various data storage options in Movable Type. In order run the system, your server needs to have DBI and at least one of the other modules installed."></p>
474
475 MSG
476         }
477     }
478     my $got_one_data = 0;
479     my $dbi_is_okay = 0;
480     for my $ref (@$list) {
481         my($mod, $ver, $req, $desc) = @$ref;
482         if ('CODE' eq ref($desc)) {
483             $desc = $desc->();
484         }
485         print "<blockquote>\n" if $mod =~ m/^DBD::/;
486         print "    <h3>$mod" .
487             ($ver ? " (version &gt;= $ver)" : "") . "</h3>";
488         eval("use $mod" . ($ver ? " $ver;" : ";"));
489         if ($@) {
490             $is_good = 0 if $req;
491             my $msg = $ver ?
492                       trans_templ(qq{<p class="warning"><MT_TRANS phrase="Either your server does not have [_1] installed, the version that is installed is too old, or [_1] requires another module that is not installed." params="$mod"> }) :
493                       trans_templ(qq{<p class="warning"><MT_TRANS phrase="Your server does not have [_1] installed, or [_1] requires another module that is not installed." params="$mod"> });
494             $msg   .= $desc .
495                       trans_templ(qq{ <MT_TRANS phrase="Please consult the installation instructions for help in installing [_1]." params="$mod"></p>\n\n});
496             print $msg . "\n\n";
497         } else {
498             if ($data) {
499                 $dbi_is_okay = 1 if $mod eq 'DBI';
500                 if ($mod eq 'DBD::mysql') {
501                     if ($DBD::mysql::VERSION == 3.0000) {
502                         print trans_templ(qq{<p class="warning"><MT_TRANS phrase="The DBD::mysql version you have installed is known to be incompatible with Movable Type. Please install the current release available from CPAN."></p>});
503                     }
504                 }
505                 if (!$dbi_is_okay) {
506                     print trans_templ(qq{<p class="warning"><MT_TRANS phrase="The $mod is installed properly, but requires an updated DBI module. Please see note above regarding the DBI module requirements."></p>});
507                 } else {
508                     $got_one_data = 1;
509                 }
510             }
511             print trans_templ(qq{<p class="installed"><MT_TRANS phrase="Your server has [_1] installed (version [_2])." params="$mod%%} . $mod->VERSION . qq{"></p>\n\n});
512         }
513         print "</blockquote>\n" if $mod =~ m/^DBD::/;
514     }
515     $is_good &= $got_one_data if $data;
516     print "\n\t</div>\n\n";
517 }
518
519 if ($is_good && $cfg_exist) {
520     if (!$view) {
521     print trans_templ(<<HTML);
522    
523     <div class="msg msg-success">
524         <h2><MT_TRANS phrase="Movable Type System Check Successful"></h2>
525         <p><strong><MT_TRANS phrase="You're ready to go!"></strong> <MT_TRANS phrase="Your server has all of the required modules installed; you do not need to perform any additional module installations. Continue with the installation instructions."></p>
526     </div>
527
528 </div>
529
530 HTML
531     }
532 }
533
534 print "</body>\n\n</html>\n";
Note: See TracBrowser for help on using the browser.