[ Index ] [ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]

PHP Cross Reference of TXP stable 4.0.6

title

Body

[close]

/textpattern/include/ -> txp_diag.php (source)

   1  <?php
   2  
   3  /*
   4      This is Textpattern
   5   
   6      Copyright 2005 by Dean Allen
   7      www.textpattern.com
   8      All rights reserved
   9  
  10      Use of this software indicates acceptance of the Textpattern license agreement 
  11  
  12  $HeadURL: http://svn.textpattern.com/releases/4.0.6/source/textpattern/include/txp_diag.php $
  13  $LastChangedRevision: 2791 $
  14  
  15  */
  16  
  17      if (!defined('txpinterface')) die('txpinterface is undefined.');
  18  
  19  //-------------------------------------------------------------
  20  
  21      define("cs",': ');
  22      define("ln",str_repeat('-', 24).n);
  23  
  24      global $files;
  25      
  26      $files = array(
  27          '/../index.php',
  28          '/css.php',
  29          '/include/txp_admin.php',
  30          '/include/txp_article.php',
  31          '/include/txp_auth.php',
  32          '/include/txp_category.php',
  33          '/include/txp_css.php',
  34          '/include/txp_diag.php',
  35          '/include/txp_discuss.php',
  36          '/include/txp_file.php',
  37          '/include/txp_form.php',
  38          '/include/txp_image.php',
  39          '/include/txp_import.php',
  40          '/include/txp_link.php',
  41          '/include/txp_list.php',
  42          '/include/txp_log.php',
  43          '/include/txp_page.php',
  44          '/include/txp_plugin.php',
  45          '/include/txp_prefs.php',
  46          '/include/txp_preview.php',
  47          '/include/txp_section.php',
  48          '/include/txp_tag.php',
  49          '/index.php',
  50          '/lib/IXRClass.php',
  51          '/lib/admin_config.php',
  52          '/lib/class.thumb.php',
  53          '/lib/classTextile.php',
  54          '/lib/constants.php',
  55          '/lib/taglib.php',
  56          '/lib/txplib_admin.php',
  57          '/lib/txplib_db.php',
  58          '/lib/txplib_forms.php',
  59          '/lib/txplib_head.php',
  60          '/lib/txplib_html.php',
  61          '/lib/txplib_misc.php',
  62          '/lib/txplib_update.php',
  63          '/lib/txplib_wrapper.php',
  64          '/publish.php',
  65          '/publish/atom.php',
  66          '/publish/comment.php',
  67          '/publish/log.php',
  68          '/publish/rss.php',
  69          '/publish/search.php',
  70          '/publish/taghandlers.php',
  71          '/update/_to_1.0.0.php',
  72          '/update/_to_4.0.2.php',
  73          '/update/_to_4.0.3.php',
  74          '/update/_to_4.0.4.php',
  75          '/update/_to_4.0.5.php',
  76          '/update/_to_4.0.6.php',
  77          '/update/_update.php'
  78      );
  79  
  80      if ($event == 'diag') {
  81          require_privs('diag');
  82  
  83          $step = gps('step');
  84          doDiagnostics();
  85      }
  86  
  87  
  88  	function apache_module($m) {
  89          $modules = apache_get_modules();
  90          return in_array($m, $modules);
  91      }
  92  
  93  	function test_tempdir($dir) {
  94          $f = realpath(tempnam($dir, 'txp_'));
  95          if (is_file($f)) {
  96              @unlink($f);
  97              return true;
  98          }
  99      }
 100  
 101  	function list_txp_tables() {
 102          $table_names = array(PFX.'textpattern');
 103          $rows = getRows("SHOW TABLES LIKE '".PFX."txp\_%'");
 104          foreach ($rows as $row)
 105              $table_names[] = array_shift($row);
 106          return $table_names;
 107      }
 108  
 109  	function check_tables($tables, $type='FAST', $warnings=0) {
 110          $msgs = array();
 111          foreach ($tables as $table) {
 112              $rs = getRows("CHECK TABLE $table $type");
 113              if ($rs) {
 114                  foreach ($rs as $r)
 115                      if ($r['Msg_type'] != 'status' and ($warnings or $r['Msg_type'] != 'warning'))
 116                          $msgs[] = $table.cs.$r['Msg_type'].cs.$r['Msg_text'];
 117              }
 118          }
 119          return $msgs;
 120      }
 121  
 122  	function doDiagnostics()
 123      {
 124          global $prefs, $files, $txpcfg, $step;
 125          extract(get_prefs());
 126          
 127      $urlparts = parse_url(hu);
 128      $mydomain = $urlparts['host'];
 129      $server_software = (@$_SERVER['SERVER_SOFTWARE'] || @$_SERVER['HTTP_HOST']) 
 130                          ? ( (@$_SERVER['SERVER_SOFTWARE']) ?  @$_SERVER['SERVER_SOFTWARE'] :  $_SERVER['HTTP_HOST'] )
 131                          : '';
 132      $is_apache = ($server_software and stristr($server_software, 'Apache')) 
 133                     or (is_callable('apache_get_version'));
 134      $real_doc_root = (isset($_SERVER['DOCUMENT_ROOT'])) ? realpath($_SERVER['DOCUMENT_ROOT']) : '';
 135      
 136      // ini_get() returns string values passed via php_value as a string, not boolean
 137      $is_register_globals = ( (strcasecmp(ini_get('register_globals'),'on')===0) or (ini_get('register_globals')==='1'));
 138  
 139      $fail = array(
 140  
 141          'php_version_4_3_0_required' =>
 142          (!is_callable('version_compare') or version_compare(PHP_VERSION, '4.3.0', '<'))
 143          ? gTxt('php_version_4_3_0_required')
 144          : '',
 145  
 146          'path_to_site_missing' =>
 147          (!isset($path_to_site))
 148          ? gTxt('path_to_site_missing')
 149          : '',
 150  
 151          'dns_lookup_fails' =>    
 152          (@gethostbyname($mydomain) == $mydomain)
 153          ?    gTxt('dns_lookup_fails').cs. $mydomain
 154          :    '',
 155  
 156          'path_to_site_inacc' =>
 157          (!@is_dir($path_to_site))
 158          ?    gTxt('path_to_site_inacc').cs.$path_to_site
 159          :     '',
 160  
 161          'site_trailing_slash' =>
 162          (rtrim($siteurl, '/') != $siteurl)
 163          ?    gTxt('site_trailing_slash').cs.$path_to_site
 164          :    '',
 165  
 166          'index_inaccessible' =>
 167          (!@is_file($path_to_site."/index.php") or !@is_readable($path_to_site."/index.php"))
 168          ?    "{$path_to_site}/index.php ".gTxt('is_inaccessible')
 169          :    '',
 170  
 171          'dir_not_writable' =>
 172          trim(
 173              ((!@is_writable($path_to_site.'/'.$img_dir))
 174              ?    str_replace('{dirtype}', gTxt('img_dir'), gTxt('dir_not_writable')).": {$path_to_site}/{$img_dir}".n
 175              :    '').
 176              ((!@is_writable($file_base_path))
 177              ?    str_replace('{dirtype}', gTxt('file_base_path'), gTxt('dir_not_writable')).": {$file_base_path}".n
 178              :    '').
 179              ((!@is_writable($tempdir))
 180              ?    str_replace('{dirtype}', gTxt('tempdir'), gTxt('dir_not_writable')).": {$tempdir}".n
 181              :    '')),
 182  
 183          'cleanurl_only_apache' =>
 184          ($permlink_mode != 'messy' and !$is_apache )
 185          ? gTxt('cleanurl_only_apache')
 186          : '',
 187  
 188          'htaccess_missing' =>    
 189          ($permlink_mode != 'messy' and !@is_readable($path_to_site.'/.htaccess'))
 190          ?    gTxt('htaccess_missing')
 191          :    '',
 192  
 193          'mod_rewrite_missing' =>
 194          ($permlink_mode != 'messy' and is_callable('apache_get_modules') and !apache_module('mod_rewrite'))
 195          ? gTxt('mod_rewrite_missing')
 196          : '',
 197  
 198          'file_uploads_disabled' =>
 199          (!ini_get('file_uploads'))
 200          ?    gTxt('file_uploads_disabled')
 201          :    '',
 202  
 203          'setup_still_exists' =>
 204          (@is_dir(txpath . DS. 'setup'))
 205          ?    txpath.DS."setup".DS.' '.gTxt('still_exists')
 206          :    '',
 207  
 208          'no_temp_dir' =>
 209          (empty($tempdir))
 210          ? gTxt('no_temp_dir')
 211          : '',
 212  
 213          'warn_mail_unavailable' =>
 214          (!is_callable('mail'))
 215          ? gTxt('warn_mail_unavailable')
 216          : '',
 217  
 218          'warn_register_globals_or_update' =>
 219          ( $is_register_globals && 
 220            (    version_compare(phpversion(),'4.4.0','<=') 
 221              or ( version_compare(phpversion(),'5.0.0','>=') and version_compare(phpversion(),'5.0.5','<=') )
 222          ))
 223          ? gTxt('warn_register_globals_or_update')
 224          : '',
 225  
 226      );
 227  
 228      if ($permlink_mode != 'messy') {
 229          $rs = safe_column("name","txp_section", "1");
 230          foreach ($rs as $name) {
 231              if ($name and @file_exists($path_to_site.'/'.$name))
 232                  $fail['old_placeholder_exists'] = gTxt('old_placeholder').": {$path_to_site}/{$name}";
 233          }
 234      }
 235  
 236      $missing = array();
 237      foreach ($files as $f) {
 238          if (!is_readable(txpath . $f))
 239              $missing[] = txpath . $f;
 240      }
 241  
 242      if ($missing)
 243          $fail['missing_files'] = gTxt('missing_files').cs.join(', ', $missing);
 244  
 245  
 246      foreach ($fail as $k=>$v)
 247          if (empty($v)) unset($fail[$k]);
 248  
 249      # Find the highest revision number
 250      $file_revs = array();
 251      $rev = 0;
 252      foreach ($files as $f) {
 253          $lines = @file(txpath . $f);
 254          if ($lines) {
 255              foreach ($lines as $line) {
 256                  if (preg_match('/^\$'.'LastChangedRevision: (\w+) \$/', $line, $match)) {
 257                      $file_revs[$f] = $match[1];
 258                      if (intval($match[1]) > $rev)
 259                          $rev = intval($match[1]);
 260                  }
 261              }
 262          }
 263      }
 264  
 265      # Check revs & md5 against stable release, if possible
 266      $dev_files = $old_files = $modified_files = array();
 267      if ($cs = @file(txpath.'/checksums.txt')) {
 268          foreach ($cs as $c) {
 269              if (preg_match('@^(\S+): r?(\S+) \((.*)\)$@', trim($c), $m)) {
 270                  list(,$file,$r,$md5) = $m;
 271                  if (!empty($file_revs[$file]) and $r and $file_revs[$file] < $r) {
 272                      $old_files[] = $file;
 273                  }
 274                  elseif (!empty($file_revs[$file]) and $r and $file_revs[$file] > $r) {
 275                      $dev_files[] = $file;
 276                  }
 277                  elseif (@is_readable(txpath . $file) and ($sum=md5_file(txpath . $file)) != $md5) {
 278                      $modified_files[] = $file;
 279                  }
 280              }
 281          }
 282      }
 283  
 284      # files that haven't been updated
 285      if ($old_files)
 286          $fail['old_files'] = gTxt('old_files').cs.n.t.join(', '.n.t, $old_files);
 287  
 288      # files that don't match their checksums
 289      if ($modified_files)
 290          $fail['modified_files'] = gTxt('modified_files').cs.n.t.join(', '.n.t, $modified_files);
 291  
 292      # running development code in live mode is not recommended
 293      if ($dev_files and $production_status == 'live')
 294          $fail['dev_version_live'] = gTxt('dev_version_live').cs.n.t.join(', '.n.t, $dev_files);
 295  
 296      # anything might break if arbitrary functions are disabled
 297      if (ini_get('disable_functions')) {
 298          $disabled_funcs = array_map('trim', explode(',', ini_get('disable_functions')));
 299          # commonly disabled functions that we don't need
 300          $disabled_funcs = array_diff($disabled_funcs, array(
 301              'imagefilltoborder',
 302              'exec',
 303              'system',
 304              'dl',
 305              'passthru',
 306              'chown',
 307              'shell_exec',
 308              'popen',
 309              'proc_open',
 310          ));
 311          if ($disabled_funcs)
 312              $fail['some_php_functions_disabled'] = gTxt('some_php_functions_disabled').cs.join(', ',$disabled_funcs);
 313      }
 314  
 315      # not sure about this one
 316      #if (strncmp(php_sapi_name(), 'cgi', 3) == 0 and ini_get('cgi.rfc2616_headers'))
 317      #    $fail['cgi_header_config'] = gTxt('cgi_header_config');
 318  
 319      $guess_site_url = $_SERVER['HTTP_HOST'] . preg_replace('#[/\\\\]$#','',dirname(dirname($_SERVER['SCRIPT_NAME'])));
 320      if ($siteurl and strip_prefix($siteurl, 'www.') != strip_prefix($guess_site_url, 'www.'))
 321          $fail['site_url_mismatch'] = gTxt('site_url_mismatch').cs.$guess_site_url;
 322          
 323      # test clean URL server vars
 324      if (hu) {
 325          if (ini_get('allow_url_fopen') and ($permlink_mode != 'messy')) {
 326              $s = md5(uniqid(rand(), true));
 327              $pretext_data = @file(hu.$s.'/?txpcleantest=1');
 328              if ($pretext_data) {
 329                  $pretext_req = trim(@$pretext_data[0]);
 330                  if ($pretext_req != md5('/'.$s.'/?txpcleantest=1'))
 331                      $fail['clean_url_data_failed'] = gTxt('clean_url_data_failed').cs.htmlspecialchars($pretext_req);
 332              }
 333              else
 334                  $fail['clean_url_test_failed'] = gTxt('clean_url_test_failed');
 335          }
 336      }
 337  
 338      if ($tables = list_txp_tables()) {
 339          $table_errors = check_tables($tables);
 340          if ($table_errors)
 341              $fail['mysql_table_errors'] = gTxt('mysql_table_errors').cs.n.t.join(', '.n.t, $table_errors);
 342      }
 343  
 344      $active_plugins = array();
 345      if ($rows = safe_rows('name, version, code_md5, md5(code) as md5', 'txp_plugin', 'status > 0')) {
 346          foreach ($rows as $row) {
 347              $n = $row['name'].'-'.$row['version'];
 348              if (strtolower($row['md5']) != strtolower($row['code_md5']))
 349                  $n .= 'm';
 350              $active_plugins[] = $n;
 351          }
 352      }
 353  
 354      // check GD info
 355      if (function_exists('gd_info')) {
 356          $gd_info = gd_info();
 357  
 358          $gd_support = array();
 359  
 360          if ($gd_info['GIF Create Support']) {
 361              $gd_support[] = 'GIF';
 362          }
 363  
 364          if ($gd_info['JPG Support']) {
 365              $gd_support[] = 'JPG';
 366          }
 367  
 368          if ($gd_info['PNG Support']) {
 369              $gd_support[] = 'PNG';
 370          }
 371  
 372          if ($gd_support) {
 373              $gd_support = join(', ', $gd_support);
 374          } else {
 375              $gd_support = gTxt('none');
 376          }
 377  
 378          $gd = gTxt('gd_info', array(
 379              '{version}'   => $gd_info['GD Version'], 
 380              '{supported}' => $gd_support
 381          ));
 382      } else {
 383          $gd = gTxt('gd_unavailable');
 384      }
 385  
 386      if ( realpath($prefs['tempdir']) == realpath($prefs['plugin_cache_dir']) )
 387      {
 388          $fail['tmp_plugin_paths_match'] = gTxt('tmp_plugin_paths_match');
 389      }
 390  
 391      echo 
 392      pagetop(gTxt('tab_diagnostics'),''),
 393      startTable('list'),
 394      tr(td(hed(gTxt('preflight_check'),1)));
 395  
 396  
 397      if ($fail) {
 398          foreach ($fail as $help => $message)
 399              echo tr(tda(nl2br($message).sp.popHelp($help), ' class="not-ok"'));
 400      }
 401      else {
 402          echo tr(tda(gTxt('all_checks_passed'), ' class="ok"'));
 403      }
 404  
 405      echo tr(td(hed(gTxt('diagnostic_info'),1)));
 406  
 407  
 408      $fmt_date = '%Y-%m-%d %H:%M:%S';
 409      
 410      $out = array(
 411          '<textarea cols="78" rows="18" readonly="readonly" style="width: 500px; height: 300px;">',
 412  
 413          gTxt('txp_version').cs.txp_version.' ('.($rev ? 'r'.$rev : 'unknown revision').')'.n,
 414  
 415          gTxt('last_update').cs.gmstrftime($fmt_date, $dbupdatetime).'/'.gmstrftime($fmt_date, @filemtime(txpath.'/update/_update.php')).n,
 416  
 417          gTxt('document_root').cs.@$_SERVER['DOCUMENT_ROOT']. (($real_doc_root != @$_SERVER['DOCUMENT_ROOT']) ? ' ('.$real_doc_root.')' : '') .n,
 418  
 419          '$path_to_site'.cs.$path_to_site.n,
 420  
 421          gTxt('txp_path').cs.txpath.n,
 422  
 423          gTxt('permlink_mode').cs.$permlink_mode.n,
 424  
 425          (ini_get('open_basedir')) ? 'open_basedir: '.ini_get('open_basedir').n : '',
 426  
 427          (ini_get('upload_tmp_dir')) ? 'upload_tmp_dir: '.ini_get('upload_tmp_dir').n : '',
 428  
 429          gTxt('tempdir').cs.$tempdir.n,
 430  
 431          gTxt('web_domain').cs.$siteurl.n,
 432  
 433          (getenv('TZ')) ? 'TZ: '.getenv('TZ').n : '',
 434  
 435          gTxt('php_version').cs.phpversion().n,
 436  
 437          ($is_register_globals) ? gTxt('register_globals').cs.$is_register_globals.n : '',
 438  
 439          gTxt('gd_library').cs.$gd.n,
 440  
 441          gTxt('server_time').cs.strftime('%Y-%m-%d %H:%M:%S').n,
 442  
 443          'MySQL'.cs.mysql_get_server_info().n,
 444  
 445          gTxt('locale').cs.$locale.n,
 446  
 447          (isset($_SERVER['SERVER_SOFTWARE'])) ? gTxt('server').cs.$_SERVER['SERVER_SOFTWARE'].n : '',
 448  
 449          (is_callable('apache_get_version')) ? gTxt('apache_version').cs.apache_get_version().n : '',
 450  
 451          gTxt('php_sapi_mode').cs.PHP_SAPI.n,
 452  
 453          gTxt('rfc2616_headers').cs.ini_get('cgi.rfc2616_headers').n,
 454  
 455          gTxt('os_version').cs.php_uname('s').' '.php_uname('r').n,
 456  
 457          ($active_plugins ? gTxt('active_plugins').cs.join(', ', $active_plugins).n : ''),
 458  
 459          $fail
 460          ? n.gTxt('preflight_check').cs.n.ln.join("\n", $fail).n.ln
 461          : '',
 462  
 463          (is_readable($path_to_site.'/.htaccess'))
 464          ?    n.gTxt('htaccess_contents').cs.n.ln.htmlspecialchars(join('',file($path_to_site.'/.htaccess'))).n.ln
 465          :    ''
 466      );
 467  
 468      if ($step == 'high') {
 469          $mysql_client_encoding = (is_callable('mysql_client_encoding')) ? mysql_client_encoding() : '-';
 470          $out[] = n.'Charset (default/config)'.cs.$mysql_client_encoding.'/'.@$txpcfg['dbcharset'].n;
 471  
 472          $result = safe_query("SHOW variables like 'character_se%'");
 473          while ($row = mysql_fetch_row($result))
 474          {
 475              $out[] = $row[0].cs.$row[1].n;
 476              if ($row[0] == 'character_set_connection') $conn_char = $row[1];
 477          }
 478  
 479          $table_names = array(PFX.'textpattern');
 480          $result = safe_query("SHOW TABLES LIKE '".PFX."txp\_%'");
 481          while ($row = mysql_fetch_row($result))
 482          {
 483              $table_names[] = $row[0];
 484          }
 485          $table_msg = array();
 486          foreach ($table_names as $table)
 487          {
 488              $ctr = safe_query("SHOW CREATE TABLE ". $table."");
 489              if (!$ctr)
 490              {
 491                  unset($table_names[$table]);
 492                  continue;
 493              }
 494              $ctcharset = preg_replace('#^CREATE TABLE.*SET=([^ ]+)[^)]*$#is','\\1',mysql_result($ctr,0,'Create Table'));
 495              if (isset($conn_char) && !stristr($ctcharset,'CREATE') && ($conn_char != $ctcharset))
 496                  $table_msg[] = "$table is $ctcharset";
 497              $ctr = safe_query("CHECK TABLE ". $table);
 498              if (in_array(mysql_result($ctr,0,'Msg_type'), array('error','warning')) )
 499                  $table_msg[] = $table .cs. mysql_result($ctr,0,'Msg_Text');
 500          }
 501          if ($table_msg == array())
 502              $table_msg = (count($table_names) < 17) ?  array('-') : array('OK');
 503          $out[] = count($table_names).' Tables'.cs. implode(', ',$table_msg).n;
 504  
 505          $extns = get_loaded_extensions();
 506          $extv = array();
 507          foreach ($extns as $e) {
 508              $extv[] = $e . (phpversion($e) ? '/' . phpversion($e) : '');
 509          }
 510          $out[] = n.gTxt('php_extensions').cs.join(', ', $extv).n;
 511  
 512          if (is_callable('apache_get_modules'))
 513              $out[] = n.gTxt('apache_modules').cs.join(', ', apache_get_modules()).n;
 514              
 515          if (@is_array($pretext_data) and count($pretext_data) > 1) {
 516              $out[] = n.gTxt('pretext_data').cs.htmlspecialchars(join('', array_slice($pretext_data, 1, 20))).n;
 517          }
 518  
 519          $out[] = n;
 520  
 521          foreach ($files as $f) {
 522              $rev = '';
 523              $checksum = '';
 524  
 525              if (is_callable('md5_file') and is_readable(txpath . $f)) {
 526                  $checksum = md5_file(txpath . $f);
 527              }
 528  
 529              if (isset($file_revs[$f]))
 530                  $rev = $file_revs[$f];
 531  
 532              $out[] = "$f" .cs. ($rev ? "r".$rev : gTxt('unknown')).' ('.($checksum ? $checksum : gTxt('unknown')).')'.n;
 533          }
 534      }
 535  
 536      $out[] = '</textarea>'.br;
 537      
 538      $dets = array('low'=>gTxt('low'),'high'=>gTxt('high'));
 539      
 540      $out[] = 
 541          form(
 542              eInput('diag').n.
 543              gTxt('detail').cs.
 544              selectInput('step', $dets, $step, 0, 1)
 545          );
 546  
 547      echo tr(td(join('',$out))),
 548  
 549      endTable();
 550      }
 551      
 552  ?>


Generated: Mon Feb 18 03:42:45 2008 Cross-referenced by PHPXref 0.7