install/includes/stages/sysreqs.php
changeset 851 b98798f6572d
parent 801 eb8b23f11744
child 852 e1ce6a91469b
equal deleted inserted replaced
850:ccedb36dd929 851:b98798f6572d
    20 global $failed, $warned;
    20 global $failed, $warned;
    21 
    21 
    22 $failed = false;
    22 $failed = false;
    23 $warned = false;
    23 $warned = false;
    24 
    24 
    25 function not($var)
       
    26 {
       
    27   if($var)
       
    28   {
       
    29     return false;
       
    30   } 
       
    31   else
       
    32   {
       
    33     return true;
       
    34   }
       
    35 }
       
    36 
       
    37 function run_test($code, $desc, $extended_desc, $warn = false)
    25 function run_test($code, $desc, $extended_desc, $warn = false)
    38 {
    26 {
    39   global $failed, $warned;
    27   global $failed, $warned;
    40   static $cv = true;
    28   static $cv = true;
    41   $cv = not($cv);
    29   $cv = !$cv;
    42   $val = eval($code);
    30   $val = eval($code);
    43   if($val)
    31   if($val)
    44   {
    32   {
    45     if($cv) $color='CCFFCC'; else $color='AAFFAA';
    33     if($cv) $color='CCFFCC'; else $color='AAFFAA';
    46     echo "<tr><td style='background-color: #$color; width: 500px; padding: 5px;'>$desc</td><td style='padding-left: 10px;'><img alt='Test passed' src='../images/check.png' /></td></tr>";
    34     echo "<tr><td style='background-color: #$color; width: 500px; padding: 5px;'>$desc</td><td style='padding-left: 10px;'><img alt='Test passed' src='../images/check.png' /></td></tr>";
    58 {
    46 {
    59   $r = strstr($_SERVER['SERVER_SOFTWARE'], 'Apache') ? true : false;
    47   $r = strstr($_SERVER['SERVER_SOFTWARE'], 'Apache') ? true : false;
    60   return $r;
    48   return $r;
    61 }
    49 }
    62 
    50 
    63 function config_write_test()
    51 function write_test($filename)
    64 {
    52 {
    65   if ( !is_writable(ENANO_ROOT.'/config.new.php') )
       
    66     return false;
       
    67   // We need to actually _open_ the file to make sure it can be written, because sometimes this fails even when is_writable() returns
    53   // We need to actually _open_ the file to make sure it can be written, because sometimes this fails even when is_writable() returns
    68   // true on Windows/IIS servers. Don't ask me why.
    54   // true on Windows/IIS servers. Don't ask me why.
    69   $h = @fopen( ENANO_ROOT . '/config.new.php', 'a+' );
    55   
    70   if ( !$h )
    56   $file = ENANO_ROOT . '/' . $filename;
    71     return false;
    57   if ( is_dir($file) )
    72   fclose($h);
    58   {
    73   return true;
    59     $file = rtrim($file, '/') . '/' . 'enanoinstalltest.txt';
    74 }
    60     if ( file_exists($file) )
       
    61     {
       
    62       $fp = @fopen($file, 'a+');
       
    63       if ( !$fp )
       
    64         return false;
       
    65       fclose($fp);
       
    66       unlink($file);
       
    67       return true;
       
    68     }
       
    69     else
       
    70     {
       
    71       $fp = @fopen($file, 'w');
       
    72       if ( !$fp )
       
    73         return false;
       
    74       fclose($fp);
       
    75       unlink($file);
       
    76       return true;
       
    77     }
       
    78   }
       
    79   else
       
    80   {
       
    81     if ( file_exists($file) )
       
    82     {
       
    83       $fp = @fopen($file, 'a+');
       
    84       if ( !$fp )
       
    85         return false;
       
    86       fclose($fp);
       
    87       return true;
       
    88     }
       
    89     else
       
    90     {
       
    91       $fp = @fopen($file, 'w');
       
    92       if ( !$fp )
       
    93         return false;
       
    94       fclose($fp);
       
    95       return true;
       
    96     }
       
    97   }
       
    98 }
       
    99 
       
   100 $warnings = array();
       
   101 $failed = false;
       
   102 $have_dbms = false;
       
   103 
       
   104 // Test: Apache
       
   105 $req_apache = is_apache() ? 'good' : 'bad';
       
   106 
       
   107 // Test: PHP
       
   108 if ( version_compare(PHP_VERSION, '5.2.0', '>=') )
       
   109 {
       
   110   $req_php = 'good';
       
   111 }
       
   112 else if ( version_compare(PHP_VERSION, '5.0.0', '>=') )
       
   113 {
       
   114   $warnings[] = $lang->get('sysreqs_req_help_php', array('php_version' => PHP_VERSION));
       
   115   $req_php = 'warn';
       
   116 }
       
   117 else
       
   118 {
       
   119   $failed = true;
       
   120   $req_php = 'bad';
       
   121 }
       
   122 
       
   123 $req_safemode = !intval(@ini_get('safe_mode'));
       
   124 if ( !$req_safemode )
       
   125 {
       
   126   $warnings[] = $lang->get('sysreqs_req_help_safemode');
       
   127   $failed = true;
       
   128 }
       
   129 
       
   130 // Test: MySQL
       
   131 $req_mysql = function_exists('mysql_connect');
       
   132 if ( $req_mysql )
       
   133   $have_dbms = true;
       
   134 
       
   135 // Test: PostgreSQL
       
   136 $req_pgsql = function_exists('pg_connect');
       
   137 if ( $req_pgsql )
       
   138   $have_dbms = true;
       
   139 
       
   140 if ( !$have_dbms )
       
   141   $failed = true;
       
   142 
       
   143 // Test: File uploads
       
   144 $req_uploads = intval(@ini_get('file_uploads'));
       
   145 
       
   146 // Writability test: config
       
   147 $req_config_w = write_test('config.new.php');
       
   148 
       
   149 // Writability test: .htaccess
       
   150 $req_htaccess_w = write_test('.htaccess.new');
       
   151 
       
   152 // Writability test: files
       
   153 $req_files_w = write_test('files');
       
   154 
       
   155 // Writability test: cache
       
   156 $req_cache_w = write_test('cache');
       
   157 
       
   158 if ( !$req_config_w || !$req_htaccess_w || !$req_files_w || !$req_cache_w )
       
   159   $warnings[] = $lang->get('sysreqs_req_help_writable');
       
   160 
       
   161 if ( !$req_config_w )
       
   162   $failed = true;
       
   163 
       
   164 // Extension test: GD
       
   165 $req_gd = function_exists('imagecreatefrompng') && function_exists('getimagesize') && function_exists('imagecreatetruecolor') && function_exists('imagecopyresampled');
       
   166 if ( !$req_gd )
       
   167   $warnings[] = $lang->get('sysreqs_req_help_gd2');
       
   168 
       
   169 // FS test: ImageMagick
       
   170 $req_imagick = which('convert');
       
   171 if ( !$req_imagick )
       
   172   $warnings[] = $lang->get('sysreqs_req_help_imagemagick');
       
   173 
       
   174 // Extension test: GMP
       
   175 $req_gmp = function_exists('gmp_init');
       
   176 if ( !$req_gmp )
       
   177   $warnings[] = $lang->get('sysreqs_req_help_gmp');
       
   178 
       
   179 // Extension test: Big_Int
       
   180 $req_bigint = function_exists('bi_from_str');
       
   181 if ( !$req_bigint && !$req_gmp )
       
   182   $warnings[] = $lang->get('sysreqs_req_help_bigint');
       
   183 
       
   184 // Extension test: BCMath
       
   185 $req_bcmath = function_exists('bcadd');
       
   186 if ( !$req_bcmath && !$req_bigint && !$req_gmp )
       
   187   $warnings[] = $lang->get('sysreqs_req_help_bcmath');
    75 
   188 
    76 ?>
   189 ?>
    77 <h3><?php echo $lang->get('sysreqs_heading'); ?></h3>
   190 <h3><?php echo $lang->get('sysreqs_heading'); ?></h3>
    78  <p><?php echo $lang->get('sysreqs_blurb'); ?></p>
   191  <p><?php echo $lang->get('sysreqs_blurb'); ?></p>
    79  
   192  
    80 <table border="0" cellspacing="0" cellpadding="0">
   193 <?php
    81 
   194 if ( !empty($warnings) ):
    82 <?php
   195 ?>
    83 run_test('return version_compare(\'5.2.0\', PHP_VERSION, \'<=\');', $lang->get('sysreqs_req_php5'), $lang->get('sysreqs_req_desc_php5'), true);
   196   <div class="sysreqs_warning">
    84 run_test('return function_exists(\'mysql_connect\');', $lang->get('sysreqs_req_mysql'), $lang->get('sysreqs_req_desc_mysql'), true);
   197     <h3><?php echo $lang->get('sysreqs_summary_warn_title'); ?></h3>
    85 run_test('return function_exists(\'pg_connect\');', $lang->get('sysreqs_req_postgres'), $lang->get('sysreqs_req_desc_postgres'), true);
   198     <p><?php echo $lang->get('sysreqs_summary_warn_body'); ?></p>
    86 run_test('return @ini_get(\'file_uploads\');', $lang->get('sysreqs_req_uploads'), $lang->get('sysreqs_req_desc_uploads') );
   199     <ul>
    87 run_test('return is_apache();', $lang->get('sysreqs_req_apache'), $lang->get('sysreqs_req_desc_apache'), true);
   200       <li><?php echo implode("</li>\n      <li>", $warnings); ?></li>
    88 run_test('return config_write_test();', $lang->get('sysreqs_req_config'), $lang->get('sysreqs_req_desc_config') );
   201     </ul>
    89 run_test('return file_exists(\'/usr/bin/convert\');', $lang->get('sysreqs_req_magick'), $lang->get('sysreqs_req_desc_magick'), true);
   202   </div>
    90 run_test('return is_writable(ENANO_ROOT.\'/cache/\');', $lang->get('sysreqs_req_cachewriteable'), $lang->get('sysreqs_req_desc_cachewriteable'), true);
   203 <?php
    91 run_test('return is_writable(ENANO_ROOT.\'/files/\');', $lang->get('sysreqs_req_fileswriteable'), $lang->get('sysreqs_req_desc_fileswriteable'), true);
   204 endif;
    92 if ( !function_exists('mysql_connect') && !function_exists('pg_connect') )
   205 
    93 {
   206 if ( !$have_dbms ):
    94   run_test('return false;', $lang->get('sysreqs_req_nodbdrivers'), $lang->get('sysreqs_req_desc_nodbdrivers'), false);
   207 ?>
    95 }
   208   <div class="sysreqs_error">
    96 echo '</table>';
   209     <h3><?php echo $lang->get('sysreqs_err_no_dbms_title'); ?></h3>
    97 echo '<br />';
   210     <p><?php echo $lang->get('sysreqs_err_no_dbms_body'); ?></p>
    98 if(!$failed)
   211   </div>
    99 {
   212 <?php
   100   ?>
   213 endif;
       
   214 
       
   215 if ( $failed ):
       
   216 ?>
       
   217   <div class="sysreqs_error">
       
   218     <h3><?php echo $lang->get('sysreqs_summary_fail_title'); ?></h3>
       
   219     <p><?php echo $lang->get('sysreqs_summary_fail_body'); ?></p>
       
   220   </div>
       
   221 <?php
       
   222 endif;        
       
   223 ?>
       
   224  
       
   225 <table border="0" cellspacing="0" cellpadding="0" class="sysreqs">
       
   226 
       
   227 <?php
       
   228 /*
   101   
   229   
   102   <div class="pagenav">
   230   </div>
   103   <?php
   231 <?php
   104   if($warned) {
   232 }
   105     echo '<table border="0" cellspacing="0" cellpadding="0">';
   233 else
   106     run_test('return false;', $lang->get('sysreqs_summary_warn_title'), $lang->get('sysreqs_summary_warn_body'), true);
   234 {
   107     echo '</table>';
   235   if ( $failed )
   108   } else {
   236   {
   109     echo '<table border="0" cellspacing="0" cellpadding="0">';
   237     echo '<div class="pagenav"><table border="0" cellspacing="0" cellpadding="0">';
   110     run_test('return true;', '<b>' . $lang->get('sysreqs_summary_success_title') . '</b><br />' . $lang->get('sysreqs_summary_success_body'), 'You should never see this text. Congratulations for being an Enano hacker!');
   238     run_test('return false;', $lang->get('sysreqs_summary_fail_title'), $lang->get('sysreqs_summary_fail_body'));
   111     echo '</table>';
   239     echo '</table></div>';
   112   }
   240   }
   113   ?>
   241 }
       
   242 */
       
   243 ?>
       
   244 
       
   245 <tr>
       
   246   <th colspan="2"><?php echo $lang->get('sysreqs_heading_serverenv'); ?></th>
       
   247 </tr>
       
   248 
       
   249 <tr>
       
   250   <td><?php echo $lang->get('sysreqs_req_apache'); ?></td>
       
   251   <?php
       
   252   if ( $req_apache ):
       
   253     echo '<td class="good">' . $lang->get('sysreqs_req_found') . '</td>';
       
   254   else:
       
   255     echo '<td class="bad">' . $lang->get('sysreqs_req_notfound') . '</td>';
       
   256   endif;
       
   257   ?>
       
   258 </tr>
       
   259 
       
   260 <tr>
       
   261   <td><?php echo $lang->get('sysreqs_req_php'); ?></td>
       
   262   <td class="<?php echo $req_php; ?>">v<?php echo PHP_VERSION; ?></td>
       
   263 </tr>
       
   264 
       
   265 <tr>
       
   266   <td><?php echo $lang->get('sysreqs_req_safemode'); ?></td>
       
   267   <?php
       
   268   if ( $req_safemode ):
       
   269     echo '<td class="good">' . $lang->get('sysreqs_req_disabled') . '</td>';
       
   270   else:
       
   271     echo '<td class="bad">' . $lang->get('sysreqs_req_enabled') . '</td>';
       
   272   endif;
       
   273   ?>
       
   274 </tr>
       
   275 
       
   276 <tr>
       
   277   <td><?php echo $lang->get('sysreqs_req_uploads'); ?></td>
       
   278   <?php
       
   279   if ( $req_uploads ):
       
   280     echo '<td class="good">' . $lang->get('sysreqs_req_enabled') . '</td>';
       
   281   else:
       
   282     echo '<td class="bad">' . $lang->get('sysreqs_req_disabled') . '</td>';
       
   283   endif;
       
   284   ?>
       
   285 </tr>
       
   286 
       
   287 <tr>
       
   288   <th colspan="2"><?php echo $lang->get('sysreqs_heading_dbms'); ?></th>
       
   289 </tr>
       
   290 
       
   291 <tr>
       
   292   <td><?php echo $lang->get('sysreqs_req_mysql'); ?></td>
       
   293   <?php
       
   294   if ( $req_mysql ):
       
   295     echo '<td class="good">' . $lang->get('sysreqs_req_supported') . '</td>';
       
   296   else:
       
   297     echo '<td class="bad">' . $lang->get('sysreqs_req_notfound') . '</td>';
       
   298   endif;
       
   299   ?>
       
   300 </tr>
       
   301 
       
   302 <tr>
       
   303   <td><?php echo $lang->get('sysreqs_req_postgresql'); ?></td>
       
   304   <?php
       
   305   if ( $req_pgsql ):
       
   306     echo '<td class="good">' . $lang->get('sysreqs_req_supported') . '</td>';
       
   307   else:
       
   308     echo '<td class="bad">' . $lang->get('sysreqs_req_notfound') . '</td>';
       
   309   endif;
       
   310   ?>
       
   311 </tr>
       
   312 
       
   313 <tr>
       
   314   <th colspan="2"><?php echo $lang->get('sysreqs_heading_files'); ?></th>
       
   315 </tr>
       
   316 
       
   317 <tr>
       
   318   <td>
       
   319     <?php echo $lang->get('sysreqs_req_config_writable'); ?>
       
   320   </td>
       
   321   <?php
       
   322   if ( $req_config_w ):
       
   323     echo '<td class="good">' . $lang->get('sysreqs_req_writable') . '</td>';
       
   324   else:
       
   325     echo '<td class="bad">' . $lang->get('sysreqs_req_unwritable') . '</td>';
       
   326   endif;
       
   327   ?>
       
   328 </tr>
       
   329 
       
   330 <tr>
       
   331   <td>
       
   332     <?php echo $lang->get('sysreqs_req_htaccess_writable'); ?><br />
       
   333     <small><?php echo $lang->get('sysreqs_req_hint_htaccess_writable'); ?></small>
       
   334   </td>
       
   335   <?php
       
   336   if ( $req_htaccess_w ):
       
   337     echo '<td class="good">' . $lang->get('sysreqs_req_writable') . '</td>';
       
   338   else:
       
   339     echo '<td class="bad">' . $lang->get('sysreqs_req_unwritable') . '</td>';
       
   340   endif;
       
   341   ?>
       
   342 </tr>
       
   343 
       
   344 <tr>
       
   345   <td>
       
   346     <?php echo $lang->get('sysreqs_req_files_writable'); ?>
       
   347   </td>
       
   348   <?php
       
   349   if ( $req_files_w ):
       
   350     echo '<td class="good">' . $lang->get('sysreqs_req_writable') . '</td>';
       
   351   else:
       
   352     echo '<td class="bad">' . $lang->get('sysreqs_req_unwritable') . '</td>';
       
   353   endif;
       
   354   ?>
       
   355 </tr>
       
   356 
       
   357 <tr>
       
   358   <td>
       
   359     <?php echo $lang->get('sysreqs_req_cache_writable'); ?>
       
   360   </td>
       
   361   <?php
       
   362   if ( $req_cache_w ):
       
   363     echo '<td class="good">' . $lang->get('sysreqs_req_writable') . '</td>';
       
   364   else:
       
   365     echo '<td class="bad">' . $lang->get('sysreqs_req_unwritable') . '</td>';
       
   366   endif;
       
   367   ?>
       
   368 </tr>
       
   369 
       
   370 <tr>
       
   371   <th colspan="2"><?php echo $lang->get('sysreqs_heading_images'); ?></th>
       
   372 </tr>
       
   373 
       
   374 <tr>
       
   375   <td>
       
   376     <?php echo $lang->get('sysreqs_req_gd2'); ?><br />
       
   377     <small><?php echo $lang->get('sysreqs_req_hint_gd2'); ?></small>
       
   378   </td>
       
   379   <?php
       
   380   if ( $req_gd ):
       
   381     echo '<td class="good">' . $lang->get('sysreqs_req_supported') . '</td>';
       
   382   else:
       
   383     echo '<td class="bad">' . $lang->get('sysreqs_req_notfound') . '</td>';
       
   384   endif;
       
   385   ?>
       
   386 </tr>
       
   387 
       
   388 <tr>
       
   389   <td>
       
   390     <?php echo $lang->get('sysreqs_req_imagemagick'); ?><br />
       
   391     <small><?php echo $lang->get('sysreqs_req_hint_imagemagick'); ?></small>
       
   392   </td>
       
   393   <?php
       
   394   if ( $req_imagick ):
       
   395     echo '<td class="good">' . $lang->get('sysreqs_req_found') . ' <small>(' . htmlspecialchars($req_imagick) . ')</small></td>';
       
   396   else:
       
   397     echo '<td class="bad">' . $lang->get('sysreqs_req_notfound') . '</td>';
       
   398   endif;
       
   399   ?>
       
   400 </tr>
       
   401 
       
   402 <tr>
       
   403   <th colspan="2"><?php echo $lang->get('sysreqs_heading_crypto'); ?></th>
       
   404 </tr>
       
   405 
       
   406 <tr>
       
   407   <td>
       
   408     <?php echo $lang->get('sysreqs_req_gmp'); ?><br />
       
   409     <small><?php echo $lang->get('sysreqs_req_hint_gmp'); ?></small>
       
   410   </td>
       
   411   <?php
       
   412   if ( $req_gmp ):
       
   413     echo '<td class="good">' . $lang->get('sysreqs_req_supported') . '</td>';
       
   414   else:
       
   415     echo '<td class="bad">' . $lang->get('sysreqs_req_notfound') . '</td>';
       
   416   endif;
       
   417   ?>
       
   418 </tr>
       
   419 
       
   420 <tr>
       
   421   <td>
       
   422     <?php echo $lang->get('sysreqs_req_bigint'); ?><br />
       
   423     <small><?php echo $lang->get('sysreqs_req_hint_bigint'); ?></small>
       
   424   </td>
       
   425   <?php
       
   426   if ( $req_bigint ):
       
   427     echo '<td class="good">' . $lang->get('sysreqs_req_supported') . '</td>';
       
   428   else:
       
   429     echo '<td class="bad">' . $lang->get('sysreqs_req_notfound') . '</td>';
       
   430   endif;
       
   431   ?>
       
   432 </tr>
       
   433 
       
   434 <tr>
       
   435   <td>
       
   436     <?php echo $lang->get('sysreqs_req_bcmath'); ?><br />
       
   437     <small><?php echo $lang->get('sysreqs_req_hint_bcmath'); ?></small>
       
   438   </td>
       
   439   <?php
       
   440   if ( $req_bcmath ):
       
   441     echo '<td class="good">' . $lang->get('sysreqs_req_supported') . '</td>';
       
   442   else:
       
   443     echo '<td class="bad">' . $lang->get('sysreqs_req_notfound') . '</td>';
       
   444   endif;
       
   445   ?>
       
   446 </tr>
       
   447 
       
   448 </table>
       
   449 
       
   450 <?php
       
   451 if ( !$failed ):
       
   452 ?>
   114   <form action="install.php?stage=database" method="post">
   453   <form action="install.php?stage=database" method="post">
   115     <?php
   454     <?php
   116       echo '<input type="hidden" name="language" value="' . $lang_id . '" />';
   455       echo '<input type="hidden" name="language" value="' . $lang_id . '" />';
   117     ?>
   456     ?>
   118     <table border="0">
   457     <table border="0">
   128         </p>
   467         </p>
   129       </td>
   468       </td>
   130     </tr>
   469     </tr>
   131     </table>
   470     </table>
   132   </form>
   471   </form>
   133   </div>
   472 <?php
   134 <?php
   473 endif;
   135 }
   474 ?>
   136 else
       
   137 {
       
   138   if ( $failed )
       
   139   {
       
   140     echo '<div class="pagenav"><table border="0" cellspacing="0" cellpadding="0">';
       
   141     run_test('return false;', $lang->get('sysreqs_summary_fail_title'), $lang->get('sysreqs_summary_fail_body'));
       
   142     echo '</table></div>';
       
   143   }
       
   144 }
       
   145     
       
   146 ?>