1c29dc6e4SAndreas Gohr<?php 2c29dc6e4SAndreas Gohr/** 3c29dc6e4SAndreas Gohr * Information and debugging functions 4c29dc6e4SAndreas Gohr * 5c29dc6e4SAndreas Gohr * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6c29dc6e4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 7c29dc6e4SAndreas Gohr */ 8fa8adffeSAndreas Gohrif(!defined('DOKU_INC')) die('meh.'); 93d7760aaSAndreas Gohrif(!defined('DOKU_MESSAGEURL')) define('DOKU_MESSAGEURL','http://update.dokuwiki.org/check/'); 10c29dc6e4SAndreas Gohr 11c29dc6e4SAndreas Gohr/** 12c29dc6e4SAndreas Gohr * Check for new messages from upstream 13c29dc6e4SAndreas Gohr * 14c29dc6e4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 15c29dc6e4SAndreas Gohr */ 16c29dc6e4SAndreas Gohrfunction checkUpdateMessages(){ 17c29dc6e4SAndreas Gohr global $conf; 18c29dc6e4SAndreas Gohr global $INFO; 19ef362bb8SAnika Henke global $updateVersion; 20c29dc6e4SAndreas Gohr if(!$conf['updatecheck']) return; 21f8cc712eSAndreas Gohr if($conf['useacl'] && !$INFO['ismanager']) return; 22c29dc6e4SAndreas Gohr 23c29dc6e4SAndreas Gohr $cf = $conf['cachedir'].'/messages.txt'; 24c29dc6e4SAndreas Gohr $lm = @filemtime($cf); 25c29dc6e4SAndreas Gohr 26c29dc6e4SAndreas Gohr // check if new messages needs to be fetched 278d3d7569SAnika Henke if($lm < time()-(60*60*24) || $lm < @filemtime(DOKU_INC.DOKU_SCRIPT)){ 28*c07c5d93SRobert Nitsch dbglog("checkUpdatesMessages(): downloading messages.txt"); 29c29dc6e4SAndreas Gohr $http = new DokuHTTPClient(); 30c29dc6e4SAndreas Gohr $http->timeout = 8; 31ef362bb8SAnika Henke $data = $http->get(DOKU_MESSAGEURL.$updateVersion); 32c29dc6e4SAndreas Gohr io_saveFile($cf,$data); 33*c07c5d93SRobert Nitsch @touch($cf); 34c29dc6e4SAndreas Gohr }else{ 35*c07c5d93SRobert Nitsch dbglog("checkUpdatesMessages(): messages.txt up to date"); 36c29dc6e4SAndreas Gohr $data = io_readFile($cf); 37c29dc6e4SAndreas Gohr } 38c29dc6e4SAndreas Gohr 39c29dc6e4SAndreas Gohr // show messages through the usual message mechanism 40c29dc6e4SAndreas Gohr $msgs = explode("\n%\n",$data); 41c29dc6e4SAndreas Gohr foreach($msgs as $msg){ 42c29dc6e4SAndreas Gohr if($msg) msg($msg,2); 43c29dc6e4SAndreas Gohr } 44c29dc6e4SAndreas Gohr} 45c29dc6e4SAndreas Gohr 46c29dc6e4SAndreas Gohr 47c29dc6e4SAndreas Gohr/** 4825c07f93SAnika Henke * Return DokuWiki's version (split up in date and type) 49c29dc6e4SAndreas Gohr * 50c29dc6e4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 51c29dc6e4SAndreas Gohr */ 5225c07f93SAnika Henkefunction getVersionData(){ 5325c07f93SAnika Henke $version = array(); 54c29dc6e4SAndreas Gohr //import version string 55e9208eb1SAndreas Gohr if(@file_exists(DOKU_INC.'VERSION')){ 56c29dc6e4SAndreas Gohr //official release 5725c07f93SAnika Henke $version['date'] = trim(io_readfile(DOKU_INC.'VERSION')); 5825c07f93SAnika Henke $version['type'] = 'Release'; 595cf31920SAndreas Gohr }elseif(is_dir(DOKU_INC.'.git')){ 605cf31920SAndreas Gohr $version['type'] = 'Git'; 6125c07f93SAnika Henke $version['date'] = 'unknown'; 62e570ed43SAndreas Gohr 635cf31920SAndreas Gohr $inventory = DOKU_INC.'.git/logs/HEAD'; 645cf31920SAndreas Gohr if(is_file($inventory)){ 65e570ed43SAndreas Gohr $sz = filesize($inventory); 665cf31920SAndreas Gohr $seek = max(0,$sz-2000); // read from back of the file 67e570ed43SAndreas Gohr $fh = fopen($inventory,'rb'); 68c29dc6e4SAndreas Gohr fseek($fh,$seek); 69c29dc6e4SAndreas Gohr $chunk = fread($fh,2000); 70c29dc6e4SAndreas Gohr fclose($fh); 715cf31920SAndreas Gohr $chunk = trim($chunk); 72b838050eSPiyush Mishra $chunk = @array_pop(explode("\n",$chunk)); //last log line 73b838050eSPiyush Mishra $chunk = @array_shift(explode("\t",$chunk)); //strip commit msg 745cf31920SAndreas Gohr $chunk = explode(" ",$chunk); 755cf31920SAndreas Gohr array_pop($chunk); //strip timezone 765cf31920SAndreas Gohr $date = date('Y-m-d',array_pop($chunk)); 775cf31920SAndreas Gohr if($date) $version['date'] = $date; 785cf31920SAndreas Gohr } 79c29dc6e4SAndreas Gohr }else{ 8025c07f93SAnika Henke $version['date'] = 'unknown'; 8125c07f93SAnika Henke $version['type'] = 'snapshot?'; 82c29dc6e4SAndreas Gohr } 835cf31920SAndreas Gohr return $version; 84c29dc6e4SAndreas Gohr} 85c29dc6e4SAndreas Gohr 86c29dc6e4SAndreas Gohr/** 8725c07f93SAnika Henke * Return DokuWiki's version (as a string) 8825c07f93SAnika Henke * 8925c07f93SAnika Henke * @author Anika Henke <anika@selfthinker.org> 9025c07f93SAnika Henke */ 9125c07f93SAnika Henkefunction getVersion(){ 9225c07f93SAnika Henke $version = getVersionData(); 9325c07f93SAnika Henke return $version['type'].' '.$version['date']; 9425c07f93SAnika Henke} 9525c07f93SAnika Henke 9625c07f93SAnika Henke/** 97c29dc6e4SAndreas Gohr * Run a few sanity checks 98c29dc6e4SAndreas Gohr * 99c29dc6e4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 100c29dc6e4SAndreas Gohr */ 101c29dc6e4SAndreas Gohrfunction check(){ 102c29dc6e4SAndreas Gohr global $conf; 103c29dc6e4SAndreas Gohr global $INFO; 104c29dc6e4SAndreas Gohr 1053f803e5eSGina Haeussge if ($INFO['isadmin'] || $INFO['ismanager']){ 106c29dc6e4SAndreas Gohr msg('DokuWiki version: '.getVersion(),1); 1073f803e5eSGina Haeussge } 108c29dc6e4SAndreas Gohr 109ab91da89SAndreas Gohr if(version_compare(phpversion(),'5.1.2','<')){ 110ab91da89SAndreas Gohr msg('Your PHP version is too old ('.phpversion().' vs. 5.1.2+ needed)',-1); 111c29dc6e4SAndreas Gohr }else{ 112c29dc6e4SAndreas Gohr msg('PHP version '.phpversion(),1); 113c29dc6e4SAndreas Gohr } 114c29dc6e4SAndreas Gohr 11573038c47SAndreas Gohr $mem = (int) php_to_byte(ini_get('memory_limit')); 11673038c47SAndreas Gohr if($mem){ 11773038c47SAndreas Gohr if($mem < 16777216){ 11873038c47SAndreas Gohr msg('PHP is limited to less than 16MB RAM ('.$mem.' bytes). Increase memory_limit in php.ini',-1); 11973038c47SAndreas Gohr }elseif($mem < 20971520){ 12073038c47SAndreas Gohr msg('PHP is limited to less than 20MB RAM ('.$mem.' bytes), you might encounter problems with bigger pages. Increase memory_limit in php.ini',-1); 12173038c47SAndreas Gohr }elseif($mem < 33554432){ 12273038c47SAndreas Gohr msg('PHP is limited to less than 32MB RAM ('.$mem.' bytes), but that should be enough in most cases. If not, increase memory_limit in php.ini',0); 12373038c47SAndreas Gohr }else{ 12473038c47SAndreas Gohr msg('More than 32MB RAM ('.$mem.' bytes) available.',1); 12573038c47SAndreas Gohr } 12673038c47SAndreas Gohr } 12773038c47SAndreas Gohr 128c29dc6e4SAndreas Gohr if(is_writable($conf['changelog'])){ 129c29dc6e4SAndreas Gohr msg('Changelog is writable',1); 130c29dc6e4SAndreas Gohr }else{ 131c29dc6e4SAndreas Gohr if (@file_exists($conf['changelog'])) { 132c29dc6e4SAndreas Gohr msg('Changelog is not writable',-1); 133c29dc6e4SAndreas Gohr } 134c29dc6e4SAndreas Gohr } 135c29dc6e4SAndreas Gohr 136c29dc6e4SAndreas Gohr if (isset($conf['changelog_old']) && @file_exists($conf['changelog_old'])) { 1372cdbda06SAnika Henke msg('Old changelog exists', 0); 138c29dc6e4SAndreas Gohr } 139c29dc6e4SAndreas Gohr 140c29dc6e4SAndreas Gohr if (@file_exists($conf['changelog'].'_failed')) { 1412cdbda06SAnika Henke msg('Importing old changelog failed', -1); 142c29dc6e4SAndreas Gohr } else if (@file_exists($conf['changelog'].'_importing')) { 143c29dc6e4SAndreas Gohr msg('Importing old changelog now.', 0); 144c29dc6e4SAndreas Gohr } else if (@file_exists($conf['changelog'].'_import_ok')) { 1452cdbda06SAnika Henke msg('Old changelog imported', 1); 146c29dc6e4SAndreas Gohr if (!plugin_isdisabled('importoldchangelog')) { 1472cdbda06SAnika Henke msg('Importoldchangelog plugin not disabled after import', -1); 148c29dc6e4SAndreas Gohr } 149c29dc6e4SAndreas Gohr } 150c29dc6e4SAndreas Gohr 151c29dc6e4SAndreas Gohr if(is_writable($conf['datadir'])){ 152c29dc6e4SAndreas Gohr msg('Datadir is writable',1); 153c29dc6e4SAndreas Gohr }else{ 154c29dc6e4SAndreas Gohr msg('Datadir is not writable',-1); 155c29dc6e4SAndreas Gohr } 156c29dc6e4SAndreas Gohr 157c29dc6e4SAndreas Gohr if(is_writable($conf['olddir'])){ 158c29dc6e4SAndreas Gohr msg('Attic is writable',1); 159c29dc6e4SAndreas Gohr }else{ 160c29dc6e4SAndreas Gohr msg('Attic is not writable',-1); 161c29dc6e4SAndreas Gohr } 162c29dc6e4SAndreas Gohr 163c29dc6e4SAndreas Gohr if(is_writable($conf['mediadir'])){ 164c29dc6e4SAndreas Gohr msg('Mediadir is writable',1); 165c29dc6e4SAndreas Gohr }else{ 166c29dc6e4SAndreas Gohr msg('Mediadir is not writable',-1); 167c29dc6e4SAndreas Gohr } 168c29dc6e4SAndreas Gohr 169c29dc6e4SAndreas Gohr if(is_writable($conf['cachedir'])){ 170c29dc6e4SAndreas Gohr msg('Cachedir is writable',1); 171c29dc6e4SAndreas Gohr }else{ 172c29dc6e4SAndreas Gohr msg('Cachedir is not writable',-1); 173c29dc6e4SAndreas Gohr } 174c29dc6e4SAndreas Gohr 175c29dc6e4SAndreas Gohr if(is_writable($conf['lockdir'])){ 176c29dc6e4SAndreas Gohr msg('Lockdir is writable',1); 177c29dc6e4SAndreas Gohr }else{ 178c29dc6e4SAndreas Gohr msg('Lockdir is not writable',-1); 179c29dc6e4SAndreas Gohr } 180c29dc6e4SAndreas Gohr 1814c7ecf15SGuy Brand if(is_writable(DOKU_CONF)){ 1824c7ecf15SGuy Brand msg('conf directory is writable',1); 1834c7ecf15SGuy Brand }else{ 1844c7ecf15SGuy Brand msg('conf directory is not writable',-1); 1854c7ecf15SGuy Brand } 1864c7ecf15SGuy Brand 1870d487d8fSAndreas Gohr if($conf['authtype'] == 'plain'){ 188defb7d57SAnika Henke global $config_cascade; 189defb7d57SAnika Henke if(is_writable($config_cascade['plainauth.users']['default'])){ 190c29dc6e4SAndreas Gohr msg('conf/users.auth.php is writable',1); 191c29dc6e4SAndreas Gohr }else{ 192c29dc6e4SAndreas Gohr msg('conf/users.auth.php is not writable',0); 193c29dc6e4SAndreas Gohr } 1940d487d8fSAndreas Gohr } 195c29dc6e4SAndreas Gohr 196c29dc6e4SAndreas Gohr if(function_exists('mb_strpos')){ 197c29dc6e4SAndreas Gohr if(defined('UTF8_NOMBSTRING')){ 198c29dc6e4SAndreas Gohr msg('mb_string extension is available but will not be used',0); 199c29dc6e4SAndreas Gohr }else{ 200c29dc6e4SAndreas Gohr msg('mb_string extension is available and will be used',1); 2014222b898SAndreas Gohr if(ini_get('mbstring.func_overload') != 0){ 2024222b898SAndreas Gohr msg('mb_string function overloading is enabled, this will cause problems and should be disabled',-1); 2034222b898SAndreas Gohr } 204c29dc6e4SAndreas Gohr } 205c29dc6e4SAndreas Gohr }else{ 206c29dc6e4SAndreas Gohr msg('mb_string extension not available - PHP only replacements will be used',0); 207c29dc6e4SAndreas Gohr } 208c29dc6e4SAndreas Gohr 209c29dc6e4SAndreas Gohr if($conf['allowdebug']){ 210c29dc6e4SAndreas Gohr msg('Debugging support is enabled. If you don\'t need it you should set $conf[\'allowdebug\'] = 0',-1); 211c29dc6e4SAndreas Gohr }else{ 212c29dc6e4SAndreas Gohr msg('Debugging support is disabled',1); 213c29dc6e4SAndreas Gohr } 214c29dc6e4SAndreas Gohr 2153d3c095dSMike Frysinger if($INFO['userinfo']['name']){ 216c1791678SAndreas Gohr msg('You are currently logged in as '.$_SERVER['REMOTE_USER'].' ('.$INFO['userinfo']['name'].')',0); 217c1791678SAndreas Gohr msg('You are part of the groups '.join($INFO['userinfo']['grps'],', '),0); 2183d3c095dSMike Frysinger }else{ 2193d3c095dSMike Frysinger msg('You are currently not logged in',0); 2203d3c095dSMike Frysinger } 2213d3c095dSMike Frysinger 222c29dc6e4SAndreas Gohr msg('Your current permission for this page is '.$INFO['perm'],0); 223c29dc6e4SAndreas Gohr 224c29dc6e4SAndreas Gohr if(is_writable($INFO['filepath'])){ 225c29dc6e4SAndreas Gohr msg('The current page is writable by the webserver',0); 226c29dc6e4SAndreas Gohr }else{ 227c29dc6e4SAndreas Gohr msg('The current page is not writable by the webserver',0); 228c29dc6e4SAndreas Gohr } 229c29dc6e4SAndreas Gohr 230c29dc6e4SAndreas Gohr if($INFO['writable']){ 231c29dc6e4SAndreas Gohr msg('The current page is writable by you',0); 232c29dc6e4SAndreas Gohr }else{ 2332cdbda06SAnika Henke msg('The current page is not writable by you',0); 234c29dc6e4SAndreas Gohr } 2353b1dfc83SAndreas Gohr 2363b1dfc83SAndreas Gohr $check = wl('','',true).'data/_dummy'; 2373b1dfc83SAndreas Gohr $http = new DokuHTTPClient(); 2383b1dfc83SAndreas Gohr $http->timeout = 6; 2393b1dfc83SAndreas Gohr $res = $http->get($check); 2403b1dfc83SAndreas Gohr if(strpos($res,'data directory') !== false){ 2413b1dfc83SAndreas Gohr msg('It seems like the data directory is accessible from the web. 2423b1dfc83SAndreas Gohr Make sure this directory is properly protected 2433b1dfc83SAndreas Gohr (See <a href="http://www.dokuwiki.org/security">security</a>)',-1); 2443b1dfc83SAndreas Gohr }elseif($http->status == 404 || $http->status == 403){ 2453b1dfc83SAndreas Gohr msg('The data directory seems to be properly protected',1); 2463b1dfc83SAndreas Gohr }else{ 2473b1dfc83SAndreas Gohr msg('Failed to check if the data directory is accessible from the web. 2483b1dfc83SAndreas Gohr Make sure this directory is properly protected 2493b1dfc83SAndreas Gohr (See <a href="http://www.dokuwiki.org/security">security</a>)',-1); 2503b1dfc83SAndreas Gohr } 25126f7dbf5SMichael Hamann 25226f7dbf5SMichael Hamann // Check for corrupted search index 25326f7dbf5SMichael Hamann $lengths = idx_listIndexLengths(); 25426f7dbf5SMichael Hamann $index_corrupted = false; 25526f7dbf5SMichael Hamann foreach ($lengths as $length) { 25626f7dbf5SMichael Hamann if (count(idx_getIndex('w', $length)) != count(idx_getIndex('i', $length))) { 25726f7dbf5SMichael Hamann $index_corrupted = true; 25826f7dbf5SMichael Hamann break; 25926f7dbf5SMichael Hamann } 26026f7dbf5SMichael Hamann } 26126f7dbf5SMichael Hamann 26226f7dbf5SMichael Hamann foreach (idx_getIndex('metadata', '') as $index) { 26326f7dbf5SMichael Hamann if (count(idx_getIndex($index.'_w', '')) != count(idx_getIndex($index.'_i', ''))) { 26426f7dbf5SMichael Hamann $index_corrupted = true; 26526f7dbf5SMichael Hamann break; 26626f7dbf5SMichael Hamann } 26726f7dbf5SMichael Hamann } 26826f7dbf5SMichael Hamann 26926f7dbf5SMichael Hamann if ($index_corrupted) 2703d94d9edSMichael Hamann msg('The search index is corrupted. It might produce wrong results and most 2713d94d9edSMichael Hamann probably needs to be rebuilt. See 27226f7dbf5SMichael Hamann <a href="http://www.dokuwiki.org/faq:searchindex">faq:searchindex</a> 2733d94d9edSMichael Hamann for ways to rebuild the search index.', -1); 27426f7dbf5SMichael Hamann elseif (!empty($lengths)) 2753d94d9edSMichael Hamann msg('The search index seems to be working', 1); 27626f7dbf5SMichael Hamann else 2773d94d9edSMichael Hamann msg('The search index is empty. See 27826f7dbf5SMichael Hamann <a href="http://www.dokuwiki.org/faq:searchindex">faq:searchindex</a> 2793d94d9edSMichael Hamann for help on how to fix the search index. If the default indexer 2803d94d9edSMichael Hamann isn\'t used or the wiki is actually empty this is normal.'); 281c29dc6e4SAndreas Gohr} 282c29dc6e4SAndreas Gohr 283c29dc6e4SAndreas Gohr/** 284c29dc6e4SAndreas Gohr * print a message 285c29dc6e4SAndreas Gohr * 286c29dc6e4SAndreas Gohr * If HTTP headers were not sent yet the message is added 287c29dc6e4SAndreas Gohr * to the global message array else it's printed directly 288c29dc6e4SAndreas Gohr * using html_msgarea() 289c29dc6e4SAndreas Gohr * 290c29dc6e4SAndreas Gohr * 291c29dc6e4SAndreas Gohr * Levels can be: 292c29dc6e4SAndreas Gohr * 293c29dc6e4SAndreas Gohr * -1 error 294c29dc6e4SAndreas Gohr * 0 info 295c29dc6e4SAndreas Gohr * 1 success 296c29dc6e4SAndreas Gohr * 297c29dc6e4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 298c29dc6e4SAndreas Gohr * @see html_msgarea 299c29dc6e4SAndreas Gohr */ 300c29dc6e4SAndreas Gohrfunction msg($message,$lvl=0,$line='',$file=''){ 301cc58224cSMichael Hamann global $MSG, $MSG_shown; 302c29dc6e4SAndreas Gohr $errors[-1] = 'error'; 303c29dc6e4SAndreas Gohr $errors[0] = 'info'; 304c29dc6e4SAndreas Gohr $errors[1] = 'success'; 305c29dc6e4SAndreas Gohr $errors[2] = 'notify'; 306c29dc6e4SAndreas Gohr 307c29dc6e4SAndreas Gohr if($line || $file) $message.=' ['.basename($file).':'.$line.']'; 308c29dc6e4SAndreas Gohr 309c29dc6e4SAndreas Gohr if(!isset($MSG)) $MSG = array(); 310c29dc6e4SAndreas Gohr $MSG[]=array('lvl' => $errors[$lvl], 'msg' => $message); 311cc58224cSMichael Hamann if(isset($MSG_shown) || headers_sent()){ 312c29dc6e4SAndreas Gohr if(function_exists('html_msgarea')){ 313c29dc6e4SAndreas Gohr html_msgarea(); 314c29dc6e4SAndreas Gohr }else{ 315c29dc6e4SAndreas Gohr print "ERROR($lvl) $message"; 316c29dc6e4SAndreas Gohr } 31769266de5SDominik Eckelmann unset($GLOBALS['MSG']); 318c29dc6e4SAndreas Gohr } 319c29dc6e4SAndreas Gohr} 320c29dc6e4SAndreas Gohr 321c29dc6e4SAndreas Gohr/** 322c29dc6e4SAndreas Gohr * print debug messages 323c29dc6e4SAndreas Gohr * 324c29dc6e4SAndreas Gohr * little function to print the content of a var 325c29dc6e4SAndreas Gohr * 326c29dc6e4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 327c29dc6e4SAndreas Gohr */ 328c29dc6e4SAndreas Gohrfunction dbg($msg,$hidden=false){ 32913493794SAndreas Gohr if($hidden){ 33013493794SAndreas Gohr echo "<!--\n"; 331c29dc6e4SAndreas Gohr print_r($msg); 33213493794SAndreas Gohr echo "\n-->"; 33313493794SAndreas Gohr }else{ 33413493794SAndreas Gohr echo '<pre class="dbg">'; 33513493794SAndreas Gohr echo hsc(print_r($msg,true)); 33613493794SAndreas Gohr echo '</pre>'; 33713493794SAndreas Gohr } 338c29dc6e4SAndreas Gohr} 339c29dc6e4SAndreas Gohr 340c29dc6e4SAndreas Gohr/** 341c29dc6e4SAndreas Gohr * Print info to a log file 342c29dc6e4SAndreas Gohr * 343c29dc6e4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 344c29dc6e4SAndreas Gohr */ 3450699d739SAndreas Gohrfunction dbglog($msg,$header=''){ 346c29dc6e4SAndreas Gohr global $conf; 3475bd930ffSMichael Hamann // The debug log isn't automatically cleaned thus only write it when 3485bd930ffSMichael Hamann // debugging has been enabled by the user. 3495bd930ffSMichael Hamann if($conf['allowdebug'] !== 1) return; 350c7408a63SAndreas Gohr if(is_object($msg) || is_array($msg)){ 351c7408a63SAndreas Gohr $msg = print_r($msg,true); 352c7408a63SAndreas Gohr } 353c7408a63SAndreas Gohr 3540699d739SAndreas Gohr if($header) $msg = "$header\n$msg"; 3550699d739SAndreas Gohr 356c29dc6e4SAndreas Gohr $file = $conf['cachedir'].'/debug.log'; 357c29dc6e4SAndreas Gohr $fh = fopen($file,'a'); 358c29dc6e4SAndreas Gohr if($fh){ 359c29dc6e4SAndreas Gohr fwrite($fh,date('H:i:s ').$_SERVER['REMOTE_ADDR'].': '.$msg."\n"); 360c29dc6e4SAndreas Gohr fclose($fh); 361c29dc6e4SAndreas Gohr } 362c29dc6e4SAndreas Gohr} 363c29dc6e4SAndreas Gohr 364db09e31eSAndreas Gohr/** 365db09e31eSAndreas Gohr * Print a reversed, prettyprinted backtrace 366db09e31eSAndreas Gohr * 367db09e31eSAndreas Gohr * @author Gary Owen <gary_owen@bigfoot.com> 368db09e31eSAndreas Gohr */ 369db09e31eSAndreas Gohrfunction dbg_backtrace(){ 370db09e31eSAndreas Gohr // Get backtrace 371db09e31eSAndreas Gohr $backtrace = debug_backtrace(); 372db09e31eSAndreas Gohr 373db09e31eSAndreas Gohr // Unset call to debug_print_backtrace 374db09e31eSAndreas Gohr array_shift($backtrace); 375db09e31eSAndreas Gohr 376db09e31eSAndreas Gohr // Iterate backtrace 377db09e31eSAndreas Gohr $calls = array(); 378db09e31eSAndreas Gohr $depth = count($backtrace) - 1; 379db09e31eSAndreas Gohr foreach ($backtrace as $i => $call) { 380db09e31eSAndreas Gohr $location = $call['file'] . ':' . $call['line']; 381db09e31eSAndreas Gohr $function = (isset($call['class'])) ? 382db09e31eSAndreas Gohr $call['class'] . $call['type'] . $call['function'] : $call['function']; 383db09e31eSAndreas Gohr 3848259f1aaSAndreas Gohr $params = array(); 385db09e31eSAndreas Gohr if (isset($call['args'])){ 3868259f1aaSAndreas Gohr foreach($call['args'] as $arg){ 3878259f1aaSAndreas Gohr if(is_object($arg)){ 3888259f1aaSAndreas Gohr $params[] = '[Object '.get_class($arg).']'; 3898259f1aaSAndreas Gohr }elseif(is_array($arg)){ 3908259f1aaSAndreas Gohr $params[] = '[Array]'; 3918259f1aaSAndreas Gohr }elseif(is_null($arg)){ 3928259f1aaSAndreas Gohr $param[] = '[NULL]'; 3938259f1aaSAndreas Gohr }else{ 3948259f1aaSAndreas Gohr $params[] = (string) '"'.$arg.'"'; 395db09e31eSAndreas Gohr } 3968259f1aaSAndreas Gohr } 3978259f1aaSAndreas Gohr } 3988259f1aaSAndreas Gohr $params = implode(', ',$params); 399db09e31eSAndreas Gohr 4008259f1aaSAndreas Gohr $calls[$depth - $i] = sprintf('%s(%s) called at %s', 401db09e31eSAndreas Gohr $function, 402db09e31eSAndreas Gohr str_replace("\n", '\n', $params), 403db09e31eSAndreas Gohr $location); 404db09e31eSAndreas Gohr } 405db09e31eSAndreas Gohr ksort($calls); 406db09e31eSAndreas Gohr 407db09e31eSAndreas Gohr return implode("\n", $calls); 408db09e31eSAndreas Gohr} 409db09e31eSAndreas Gohr 41024297a69SAndreas Gohr/** 41124297a69SAndreas Gohr * Remove all data from an array where the key seems to point to sensitive data 41224297a69SAndreas Gohr * 41324297a69SAndreas Gohr * This is used to remove passwords, mail addresses and similar data from the 41424297a69SAndreas Gohr * debug output 41524297a69SAndreas Gohr * 41624297a69SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 41724297a69SAndreas Gohr */ 41824297a69SAndreas Gohrfunction debug_guard(&$data){ 41924297a69SAndreas Gohr foreach($data as $key => $value){ 42024297a69SAndreas Gohr if(preg_match('/(notify|pass|auth|secret|ftp|userinfo|token|buid|mail|proxy)/i',$key)){ 42124297a69SAndreas Gohr $data[$key] = '***'; 42224297a69SAndreas Gohr continue; 42324297a69SAndreas Gohr } 42424297a69SAndreas Gohr if(is_array($value)) debug_guard($data[$key]); 42524297a69SAndreas Gohr } 42624297a69SAndreas Gohr} 427