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