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

Revision 2579, 19.0 kB (checked in by fumiakiy, 6 months ago)

Removing Text::Balanced from extlib; the module depends on another XS module. Added Text::Balanced to mt-check for Perl 5.6.1 users. BugId:80080

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