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 */ 8198564abSMichael Große 95a8d6e48SMichael Großeuse dokuwiki\HTTP\DokuHTTPClient; 1031667ec6SAndreas Gohruse dokuwiki\Logger; 11198564abSMichael Große 126c5e3c5eSPhyif(!defined('DOKU_MESSAGEURL')){ 136c5e3c5eSPhy if(in_array('ssl', stream_get_transports())) { 146c5e3c5eSPhy define('DOKU_MESSAGEURL','https://update.dokuwiki.org/check/'); 156c5e3c5eSPhy }else{ 166c5e3c5eSPhy define('DOKU_MESSAGEURL','http://update.dokuwiki.org/check/'); 176c5e3c5eSPhy } 186c5e3c5eSPhy} 19c29dc6e4SAndreas Gohr 20c29dc6e4SAndreas Gohr/** 21c29dc6e4SAndreas Gohr * Check for new messages from upstream 22c29dc6e4SAndreas Gohr * 23c29dc6e4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 24c29dc6e4SAndreas Gohr */ 25c29dc6e4SAndreas Gohrfunction checkUpdateMessages(){ 26c29dc6e4SAndreas Gohr global $conf; 27c29dc6e4SAndreas Gohr global $INFO; 28ef362bb8SAnika Henke global $updateVersion; 29c29dc6e4SAndreas Gohr if(!$conf['updatecheck']) return; 30f8cc712eSAndreas Gohr if($conf['useacl'] && !$INFO['ismanager']) return; 31c29dc6e4SAndreas Gohr 3237b21a1bSAndreas Gohr $cf = getCacheName($updateVersion, '.updmsg'); 33c29dc6e4SAndreas Gohr $lm = @filemtime($cf); 346c5e3c5eSPhy $is_http = substr(DOKU_MESSAGEURL, 0, 5) != 'https'; 35c29dc6e4SAndreas Gohr 36c29dc6e4SAndreas Gohr // check if new messages needs to be fetched 378d3d7569SAnika Henke if($lm < time()-(60*60*24) || $lm < @filemtime(DOKU_INC.DOKU_SCRIPT)){ 3863d9b820SAndreas Gohr @touch($cf); 3931667ec6SAndreas Gohr Logger::debug("checkUpdateMessages(): downloading messages to ".$cf.($is_http?' (without SSL)':' (with SSL)')); 40c29dc6e4SAndreas Gohr $http = new DokuHTTPClient(); 4163d9b820SAndreas Gohr $http->timeout = 12; 4286c04d87SAngus Gratton $resp = $http->get(DOKU_MESSAGEURL.$updateVersion); 4386c04d87SAngus Gratton if(is_string($resp) && ($resp == "" || substr(trim($resp), -1) == '%')) { 4486c04d87SAngus Gratton // basic sanity check that this is either an empty string response (ie "no messages") 4586c04d87SAngus Gratton // or it looks like one of our messages, not WiFi login or other interposed response 4686c04d87SAngus Gratton io_saveFile($cf,$resp); 478f1efc43SAndreas Gohr } else { 4831667ec6SAndreas Gohr Logger::debug("checkUpdateMessages(): unexpected HTTP response received", $http->error); 498f1efc43SAndreas Gohr } 50c29dc6e4SAndreas Gohr }else{ 5131667ec6SAndreas Gohr Logger::debug("checkUpdateMessages(): messages up to date"); 52c29dc6e4SAndreas Gohr } 53c29dc6e4SAndreas Gohr 5486c04d87SAngus Gratton $data = io_readFile($cf); 55c29dc6e4SAndreas Gohr // show messages through the usual message mechanism 56c29dc6e4SAndreas Gohr $msgs = explode("\n%\n",$data); 57c29dc6e4SAndreas Gohr foreach($msgs as $msg){ 58c29dc6e4SAndreas Gohr if($msg) msg($msg,2); 59c29dc6e4SAndreas Gohr } 60c29dc6e4SAndreas Gohr} 61c29dc6e4SAndreas Gohr 62c29dc6e4SAndreas Gohr 63c29dc6e4SAndreas Gohr/** 6425c07f93SAnika Henke * Return DokuWiki's version (split up in date and type) 65c29dc6e4SAndreas Gohr * 66c29dc6e4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 67c29dc6e4SAndreas Gohr */ 6825c07f93SAnika Henkefunction getVersionData(){ 6925c07f93SAnika Henke $version = array(); 70c29dc6e4SAndreas Gohr //import version string 7179e79377SAndreas Gohr if(file_exists(DOKU_INC.'VERSION')){ 72c29dc6e4SAndreas Gohr //official release 73d6c7b502SAndreas Gohr $version['date'] = trim(io_readFile(DOKU_INC.'VERSION')); 7425c07f93SAnika Henke $version['type'] = 'Release'; 755cf31920SAndreas Gohr }elseif(is_dir(DOKU_INC.'.git')){ 765cf31920SAndreas Gohr $version['type'] = 'Git'; 7725c07f93SAnika Henke $version['date'] = 'unknown'; 78e570ed43SAndreas Gohr 79*1b7da646SDamien Regad if (function_exists('shell_exec') 80*1b7da646SDamien Regad && $date = shell_exec("git log -1 --pretty=format:'%cd' --date=short") 81*1b7da646SDamien Regad ) { 82067b4fb9SMichael Große $version['date'] = hsc($date); 83f519f9dbSMichael Große } else if (file_exists(DOKU_INC . '.git/HEAD')) { 84f519f9dbSMichael Große // we cannot use git on the shell -- let's do it manually! 85f519f9dbSMichael Große $headCommit = trim(file_get_contents(DOKU_INC . '.git/HEAD')); 86f519f9dbSMichael Große if (strpos($headCommit, 'ref: ') === 0) { 87f519f9dbSMichael Große // it is something like `ref: refs/heads/master` 88f519f9dbSMichael Große $pathToHead = substr($headCommit, 5); 89f519f9dbSMichael Große $headCommit = trim(file_get_contents(DOKU_INC . '.git/' . $pathToHead)); 90f519f9dbSMichael Große } 91f519f9dbSMichael Große $subDir = substr($headCommit, 0, 2); 92f519f9dbSMichael Große $fileName = substr($headCommit, 2); 93be2e462dSMichael Große $gitCommitObject = DOKU_INC . ".git/objects/$subDir/$fileName"; 94a8ac20eaSGerrit Uitslag if (file_exists($gitCommitObject) && function_exists('zlib_decode')) { 95be2e462dSMichael Große $commit = zlib_decode(file_get_contents($gitCommitObject)); 96f519f9dbSMichael Große $committerLine = explode("\n", $commit)[3]; 97f519f9dbSMichael Große $committerData = explode(' ', $committerLine); 98f519f9dbSMichael Große end($committerData); 99f519f9dbSMichael Große $ts = prev($committerData); 100f519f9dbSMichael Große if ($ts && $date = date('Y-m-d', $ts)) { 101f519f9dbSMichael Große $version['date'] = $date; 102f519f9dbSMichael Große } 1035cf31920SAndreas Gohr } 10425c07f93SAnika Henke } 105c29dc6e4SAndreas Gohr }else{ 1066a34de2dSAnika Henke global $updateVersion; 1076a34de2dSAnika Henke $version['date'] = 'update version '.$updateVersion; 10825c07f93SAnika Henke $version['type'] = 'snapshot?'; 109c29dc6e4SAndreas Gohr } 1105cf31920SAndreas Gohr return $version; 111c29dc6e4SAndreas Gohr} 112c29dc6e4SAndreas Gohr 113c29dc6e4SAndreas Gohr/** 11425c07f93SAnika Henke * Return DokuWiki's version (as a string) 11525c07f93SAnika Henke * 11625c07f93SAnika Henke * @author Anika Henke <anika@selfthinker.org> 11725c07f93SAnika Henke */ 11825c07f93SAnika Henkefunction getVersion(){ 11925c07f93SAnika Henke $version = getVersionData(); 12025c07f93SAnika Henke return $version['type'].' '.$version['date']; 12125c07f93SAnika Henke} 12225c07f93SAnika Henke 12325c07f93SAnika Henke/** 124c29dc6e4SAndreas Gohr * Run a few sanity checks 125c29dc6e4SAndreas Gohr * 126c29dc6e4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 127c29dc6e4SAndreas Gohr */ 128c29dc6e4SAndreas Gohrfunction check(){ 129c29dc6e4SAndreas Gohr global $conf; 130c29dc6e4SAndreas Gohr global $INFO; 131585bf44eSChristopher Smith /* @var Input $INPUT */ 132585bf44eSChristopher Smith global $INPUT; 133c29dc6e4SAndreas Gohr 1343f803e5eSGina Haeussge if ($INFO['isadmin'] || $INFO['ismanager']){ 135c29dc6e4SAndreas Gohr msg('DokuWiki version: '.getVersion(),1); 136c29dc6e4SAndreas Gohr 1373f874cb3SAndreas Gohr if(version_compare(phpversion(),'7.2.0','<')){ 1383f874cb3SAndreas Gohr msg('Your PHP version is too old ('.phpversion().' vs. 7.2+ needed)',-1); 139c29dc6e4SAndreas Gohr }else{ 140c29dc6e4SAndreas Gohr msg('PHP version '.phpversion(),1); 141c29dc6e4SAndreas Gohr } 14208d1a8dfSAndreas Gohr } else { 1433f874cb3SAndreas Gohr if(version_compare(phpversion(),'7.2.0','<')){ 14408d1a8dfSAndreas Gohr msg('Your PHP version is too old',-1); 14508d1a8dfSAndreas Gohr } 14608d1a8dfSAndreas Gohr } 147c6e971ddSAndreas Gohr 148c6e971ddSAndreas Gohr $mem = (int) php_to_byte(ini_get('memory_limit')); 14973038c47SAndreas Gohr if($mem){ 150eb2e46caSAndreas Gohr if ($mem === -1) { 1518f8499faSpeterfromearth msg('PHP memory is unlimited', 1); 1528f8499faSpeterfromearth } else if ($mem < 16777216) { 1532b9c4a05SAndreas Gohr msg('PHP is limited to less than 16MB RAM (' . filesize_h($mem) . '). 1542b9c4a05SAndreas Gohr Increase memory_limit in php.ini', -1); 15573038c47SAndreas Gohr } else if ($mem < 20971520) { 1562b9c4a05SAndreas Gohr msg('PHP is limited to less than 20MB RAM (' . filesize_h($mem) . '), 15764159a61SAndreas Gohr you might encounter problems with bigger pages. Increase memory_limit in php.ini', -1); 15873038c47SAndreas Gohr } else if ($mem < 33554432) { 1592b9c4a05SAndreas Gohr msg('PHP is limited to less than 32MB RAM (' . filesize_h($mem) . '), 16064159a61SAndreas Gohr but that should be enough in most cases. If not, increase memory_limit in php.ini', 0); 16173038c47SAndreas Gohr } else { 162c6e971ddSAndreas Gohr msg('More than 32MB RAM (' . filesize_h($mem) . ') available.', 1); 16373038c47SAndreas Gohr } 16473038c47SAndreas Gohr } 16573038c47SAndreas Gohr 166c29dc6e4SAndreas Gohr if(is_writable($conf['changelog'])){ 167c29dc6e4SAndreas Gohr msg('Changelog is writable',1); 168c29dc6e4SAndreas Gohr }else{ 16979e79377SAndreas Gohr if (file_exists($conf['changelog'])) { 170c29dc6e4SAndreas Gohr msg('Changelog is not writable',-1); 171c29dc6e4SAndreas Gohr } 172c29dc6e4SAndreas Gohr } 173c29dc6e4SAndreas Gohr 17479e79377SAndreas Gohr if (isset($conf['changelog_old']) && file_exists($conf['changelog_old'])) { 1752cdbda06SAnika Henke msg('Old changelog exists', 0); 176c29dc6e4SAndreas Gohr } 177c29dc6e4SAndreas Gohr 17879e79377SAndreas Gohr if (file_exists($conf['changelog'].'_failed')) { 1792cdbda06SAnika Henke msg('Importing old changelog failed', -1); 18079e79377SAndreas Gohr } else if (file_exists($conf['changelog'].'_importing')) { 181c29dc6e4SAndreas Gohr msg('Importing old changelog now.', 0); 18279e79377SAndreas Gohr } else if (file_exists($conf['changelog'].'_import_ok')) { 1832cdbda06SAnika Henke msg('Old changelog imported', 1); 184c29dc6e4SAndreas Gohr if (!plugin_isdisabled('importoldchangelog')) { 1852cdbda06SAnika Henke msg('Importoldchangelog plugin not disabled after import', -1); 186c29dc6e4SAndreas Gohr } 187c29dc6e4SAndreas Gohr } 188c29dc6e4SAndreas Gohr 1894c7ecf15SGuy Brand if(is_writable(DOKU_CONF)){ 1904c7ecf15SGuy Brand msg('conf directory is writable',1); 1914c7ecf15SGuy Brand }else{ 1924c7ecf15SGuy Brand msg('conf directory is not writable',-1); 1934c7ecf15SGuy Brand } 1944c7ecf15SGuy Brand 1950d487d8fSAndreas Gohr if($conf['authtype'] == 'plain'){ 196defb7d57SAnika Henke global $config_cascade; 197defb7d57SAnika Henke if(is_writable($config_cascade['plainauth.users']['default'])){ 198c29dc6e4SAndreas Gohr msg('conf/users.auth.php is writable',1); 199c29dc6e4SAndreas Gohr }else{ 200c29dc6e4SAndreas Gohr msg('conf/users.auth.php is not writable',0); 201c29dc6e4SAndreas Gohr } 2020d487d8fSAndreas Gohr } 203c29dc6e4SAndreas Gohr 204c29dc6e4SAndreas Gohr if(function_exists('mb_strpos')){ 205c29dc6e4SAndreas Gohr if(defined('UTF8_NOMBSTRING')){ 206c29dc6e4SAndreas Gohr msg('mb_string extension is available but will not be used',0); 207c29dc6e4SAndreas Gohr }else{ 208c29dc6e4SAndreas Gohr msg('mb_string extension is available and will be used',1); 2094222b898SAndreas Gohr if(ini_get('mbstring.func_overload') != 0){ 2104222b898SAndreas Gohr msg('mb_string function overloading is enabled, this will cause problems and should be disabled',-1); 2114222b898SAndreas Gohr } 212c29dc6e4SAndreas Gohr } 213c29dc6e4SAndreas Gohr }else{ 214c29dc6e4SAndreas Gohr msg('mb_string extension not available - PHP only replacements will be used',0); 215c29dc6e4SAndreas Gohr } 216c29dc6e4SAndreas Gohr 2173161005dSAndreas Gohr if (!UTF8_PREGSUPPORT) { 218a731ed1dSAndreas Gohr msg('PHP is missing UTF-8 support in Perl-Compatible Regular Expressions (PCRE)', -1); 219a731ed1dSAndreas Gohr } 2203161005dSAndreas Gohr if (!UTF8_PROPERTYSUPPORT) { 221a731ed1dSAndreas Gohr msg('PHP is missing Unicode properties support in Perl-Compatible Regular Expressions (PCRE)', -1); 222a731ed1dSAndreas Gohr } 223a731ed1dSAndreas Gohr 224e5ab313fSAndreas Gohr $loc = setlocale(LC_ALL, 0); 225e5ab313fSAndreas Gohr if(!$loc){ 226e5ab313fSAndreas Gohr msg('No valid locale is set for your PHP setup. You should fix this',-1); 227e5ab313fSAndreas Gohr }elseif(stripos($loc,'utf') === false){ 22864159a61SAndreas Gohr msg('Your locale <code>'.hsc($loc).'</code> seems not to be a UTF-8 locale, 22964159a61SAndreas Gohr you should fix this if you encounter problems.',0); 230e5ab313fSAndreas Gohr }else{ 231e5ab313fSAndreas Gohr msg('Valid locale '.hsc($loc).' found.', 1); 232e5ab313fSAndreas Gohr } 233e5ab313fSAndreas Gohr 234c29dc6e4SAndreas Gohr if($conf['allowdebug']){ 235c29dc6e4SAndreas Gohr msg('Debugging support is enabled. If you don\'t need it you should set $conf[\'allowdebug\'] = 0',-1); 236c29dc6e4SAndreas Gohr }else{ 237c29dc6e4SAndreas Gohr msg('Debugging support is disabled',1); 238c29dc6e4SAndreas Gohr } 239c29dc6e4SAndreas Gohr 2403d3c095dSMike Frysinger if($INFO['userinfo']['name']){ 241585bf44eSChristopher Smith msg('You are currently logged in as '.$INPUT->server->str('REMOTE_USER').' ('.$INFO['userinfo']['name'].')',0); 2428368419bSSyntaxseed msg('You are part of the groups '.implode(', ', $INFO['userinfo']['grps']),0); 2433d3c095dSMike Frysinger }else{ 2443d3c095dSMike Frysinger msg('You are currently not logged in',0); 2453d3c095dSMike Frysinger } 2463d3c095dSMike Frysinger 247c29dc6e4SAndreas Gohr msg('Your current permission for this page is '.$INFO['perm'],0); 248c29dc6e4SAndreas Gohr 249322ad074SAndreas Gohr if (file_exists($INFO['filepath']) && is_writable($INFO['filepath'])) { 250322ad074SAndreas Gohr msg('The current page is writable by the webserver', 1); 251322ad074SAndreas Gohr } elseif (!file_exists($INFO['filepath']) && is_writable(dirname($INFO['filepath']))) { 252322ad074SAndreas Gohr msg('The current page can be created by the webserver', 1); 253c29dc6e4SAndreas Gohr } else { 254322ad074SAndreas Gohr msg('The current page is not writable by the webserver', -1); 255c29dc6e4SAndreas Gohr } 256c29dc6e4SAndreas Gohr 257c29dc6e4SAndreas Gohr if ($INFO['writable']) { 258322ad074SAndreas Gohr msg('The current page is writable by you', 1); 259c29dc6e4SAndreas Gohr } else { 260322ad074SAndreas Gohr msg('The current page is not writable by you', -1); 261c29dc6e4SAndreas Gohr } 2623b1dfc83SAndreas Gohr 26326f7dbf5SMichael Hamann // Check for corrupted search index 26426f7dbf5SMichael Hamann $lengths = idx_listIndexLengths(); 26526f7dbf5SMichael Hamann $index_corrupted = false; 26626f7dbf5SMichael Hamann foreach ($lengths as $length) { 26726f7dbf5SMichael Hamann if (count(idx_getIndex('w', $length)) != count(idx_getIndex('i', $length))) { 26826f7dbf5SMichael Hamann $index_corrupted = true; 26926f7dbf5SMichael Hamann break; 27026f7dbf5SMichael Hamann } 27126f7dbf5SMichael Hamann } 27226f7dbf5SMichael Hamann 27326f7dbf5SMichael Hamann foreach (idx_getIndex('metadata', '') as $index) { 27426f7dbf5SMichael Hamann if (count(idx_getIndex($index.'_w', '')) != count(idx_getIndex($index.'_i', ''))) { 27526f7dbf5SMichael Hamann $index_corrupted = true; 27626f7dbf5SMichael Hamann break; 27726f7dbf5SMichael Hamann } 27826f7dbf5SMichael Hamann } 27926f7dbf5SMichael Hamann 280d6c7b502SAndreas Gohr if($index_corrupted) { 281d6c7b502SAndreas Gohr msg( 282d6c7b502SAndreas Gohr 'The search index is corrupted. It might produce wrong results and most 2833d94d9edSMichael Hamann probably needs to be rebuilt. See 28426f7dbf5SMichael Hamann <a href="http://www.dokuwiki.org/faq:searchindex">faq:searchindex</a> 285d6c7b502SAndreas Gohr for ways to rebuild the search index.', -1 286d6c7b502SAndreas Gohr ); 287d6c7b502SAndreas Gohr } elseif(!empty($lengths)) { 2883d94d9edSMichael Hamann msg('The search index seems to be working', 1); 289d6c7b502SAndreas Gohr } else { 290d6c7b502SAndreas Gohr msg( 291d6c7b502SAndreas Gohr 'The search index is empty. See 29226f7dbf5SMichael Hamann <a href="http://www.dokuwiki.org/faq:searchindex">faq:searchindex</a> 2933d94d9edSMichael Hamann for help on how to fix the search index. If the default indexer 294d6c7b502SAndreas Gohr isn\'t used or the wiki is actually empty this is normal.' 295d6c7b502SAndreas Gohr ); 296d6c7b502SAndreas Gohr } 297d6c7b502SAndreas Gohr 298d6c7b502SAndreas Gohr // rough time check 299d6c7b502SAndreas Gohr $http = new DokuHTTPClient(); 300d6c7b502SAndreas Gohr $http->max_redirect = 0; 301d6c7b502SAndreas Gohr $http->timeout = 3; 302d6c7b502SAndreas Gohr $http->sendRequest('http://www.dokuwiki.org', '', 'HEAD'); 303d6c7b502SAndreas Gohr $now = time(); 304d6c7b502SAndreas Gohr if(isset($http->resp_headers['date'])) { 305d6c7b502SAndreas Gohr $time = strtotime($http->resp_headers['date']); 306d6c7b502SAndreas Gohr $diff = $time - $now; 307d6c7b502SAndreas Gohr 308d6c7b502SAndreas Gohr if(abs($diff) < 4) { 309d6c7b502SAndreas Gohr msg("Server time seems to be okay. Diff: {$diff}s", 1); 310d6c7b502SAndreas Gohr } else { 31164159a61SAndreas Gohr msg("Your server's clock seems to be out of sync! 31264159a61SAndreas Gohr Consider configuring a sync with a NTP server. Diff: {$diff}s"); 313d6c7b502SAndreas Gohr } 314d6c7b502SAndreas Gohr } 315d6c7b502SAndreas Gohr 316c29dc6e4SAndreas Gohr} 317c29dc6e4SAndreas Gohr 318c29dc6e4SAndreas Gohr/** 31946028c4cSAndreas Gohr * Display a message to the user 320c29dc6e4SAndreas Gohr * 321c29dc6e4SAndreas Gohr * If HTTP headers were not sent yet the message is added 322c29dc6e4SAndreas Gohr * to the global message array else it's printed directly 323c29dc6e4SAndreas Gohr * using html_msgarea() 324c29dc6e4SAndreas Gohr * 3250e20480fSPhy * Triggers INFOUTIL_MSG_SHOW 3260e20480fSPhy * 32746028c4cSAndreas Gohr * @see html_msgarea() 3286164d900SAndreas Gohr * @param string $message 3296164d900SAndreas Gohr * @param int $lvl -1 = error, 0 = info, 1 = success, 2 = notify 3306164d900SAndreas Gohr * @param string $line line number 3316164d900SAndreas Gohr * @param string $file file number 3326164d900SAndreas Gohr * @param int $allow who's allowed to see the message, see MSG_* constants 3336164d900SAndreas Gohr */ 334f755f9abSChristopher Smithfunction msg($message,$lvl=0,$line='',$file='',$allow=MSG_PUBLIC){ 335cc58224cSMichael Hamann global $MSG, $MSG_shown; 336556e996eSAndreas Gohr static $errors = [ 337556e996eSAndreas Gohr -1 => 'error', 338556e996eSAndreas Gohr 0 => 'info', 339556e996eSAndreas Gohr 1 => 'success', 340556e996eSAndreas Gohr 2 => 'notify', 341556e996eSAndreas Gohr ]; 342c29dc6e4SAndreas Gohr 343556e996eSAndreas Gohr $msgdata = [ 3440e20480fSPhy 'msg' => $message, 345556e996eSAndreas Gohr 'lvl' => $errors[$lvl], 3460e20480fSPhy 'allow' => $allow, 3470e20480fSPhy 'line' => $line, 3480e20480fSPhy 'file' => $file, 349556e996eSAndreas Gohr ]; 3500e20480fSPhy 3510e20480fSPhy $evt = new \dokuwiki\Extension\Event('INFOUTIL_MSG_SHOW', $msgdata); 3520e20480fSPhy if ($evt->advise_before()) { 3530e20480fSPhy /* Show msg normally - event could suppress message show */ 3540e20480fSPhy if($msgdata['line'] || $msgdata['file']) { 3550e20480fSPhy $basename = \dokuwiki\Utf8\PhpString::basename($msgdata['file']); 3560e20480fSPhy $msgdata['msg'] .=' ['.$basename.':'.$msgdata['line'].']'; 3570e20480fSPhy } 358c29dc6e4SAndreas Gohr 359c29dc6e4SAndreas Gohr if(!isset($MSG)) $MSG = array(); 3600e20480fSPhy $MSG[] = $msgdata; 361cc58224cSMichael Hamann if(isset($MSG_shown) || headers_sent()){ 362c29dc6e4SAndreas Gohr if(function_exists('html_msgarea')){ 363c29dc6e4SAndreas Gohr html_msgarea(); 364c29dc6e4SAndreas Gohr }else{ 3650e20480fSPhy print "ERROR(".$msgdata['lvl'].") ".$msgdata['msg']."\n"; 366c29dc6e4SAndreas Gohr } 36769266de5SDominik Eckelmann unset($GLOBALS['MSG']); 368c29dc6e4SAndreas Gohr } 369c29dc6e4SAndreas Gohr } 3700e20480fSPhy $evt->advise_after(); 3710e20480fSPhy unset($evt); 3720e20480fSPhy} 373f755f9abSChristopher Smith/** 374f755f9abSChristopher Smith * Determine whether the current user is allowed to view the message 375f755f9abSChristopher Smith * in the $msg data structure 376f755f9abSChristopher Smith * 377f755f9abSChristopher Smith * @param $msg array dokuwiki msg structure 378f755f9abSChristopher Smith * msg => string, the message 379f755f9abSChristopher Smith * lvl => int, level of the message (see msg() function) 380f755f9abSChristopher Smith * allow => int, flag used to determine who is allowed to see the message 381f755f9abSChristopher Smith * see MSG_* constants 3826164d900SAndreas Gohr * @return bool 383f755f9abSChristopher Smith */ 384f755f9abSChristopher Smithfunction info_msg_allowed($msg){ 385d3bae478SChristopher Smith global $INFO, $auth; 386d3bae478SChristopher Smith 387d3bae478SChristopher Smith // is the message public? - everyone and anyone can see it 388f755f9abSChristopher Smith if (empty($msg['allow']) || ($msg['allow'] == MSG_PUBLIC)) return true; 389d3bae478SChristopher Smith 390d3bae478SChristopher Smith // restricted msg, but no authentication 391d3bae478SChristopher Smith if (empty($auth)) return false; 392d3bae478SChristopher Smith 393f755f9abSChristopher Smith switch ($msg['allow']){ 394d3bae478SChristopher Smith case MSG_USERS_ONLY: 395d3bae478SChristopher Smith return !empty($INFO['userinfo']); 396d3bae478SChristopher Smith 397d3bae478SChristopher Smith case MSG_MANAGERS_ONLY: 398d3bae478SChristopher Smith return $INFO['ismanager']; 399d3bae478SChristopher Smith 400d3bae478SChristopher Smith case MSG_ADMINS_ONLY: 401d3bae478SChristopher Smith return $INFO['isadmin']; 402d3bae478SChristopher Smith 403d3bae478SChristopher Smith default: 40464159a61SAndreas Gohr trigger_error('invalid msg allow restriction. msg="'.$msg['msg'].'" allow='.$msg['allow'].'"', 40564159a61SAndreas Gohr E_USER_WARNING); 406d3bae478SChristopher Smith return $INFO['isadmin']; 407d3bae478SChristopher Smith } 408d3bae478SChristopher Smith 409d3bae478SChristopher Smith return false; 410d3bae478SChristopher Smith} 411d3bae478SChristopher Smith 412c29dc6e4SAndreas Gohr/** 413c29dc6e4SAndreas Gohr * print debug messages 414c29dc6e4SAndreas Gohr * 415c29dc6e4SAndreas Gohr * little function to print the content of a var 416c29dc6e4SAndreas Gohr * 417c29dc6e4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 418f50a239bSTakamura * 419f50a239bSTakamura * @param string $msg 420f50a239bSTakamura * @param bool $hidden 421c29dc6e4SAndreas Gohr */ 422c29dc6e4SAndreas Gohrfunction dbg($msg,$hidden=false){ 42313493794SAndreas Gohr if($hidden){ 42413493794SAndreas Gohr echo "<!--\n"; 425c29dc6e4SAndreas Gohr print_r($msg); 42613493794SAndreas Gohr echo "\n-->"; 42713493794SAndreas Gohr }else{ 42813493794SAndreas Gohr echo '<pre class="dbg">'; 42913493794SAndreas Gohr echo hsc(print_r($msg,true)); 43013493794SAndreas Gohr echo '</pre>'; 43113493794SAndreas Gohr } 432c29dc6e4SAndreas Gohr} 433c29dc6e4SAndreas Gohr 434c29dc6e4SAndreas Gohr/** 435cad4fbf6SAndreas Gohr * Print info to debug log file 436c29dc6e4SAndreas Gohr * 437c29dc6e4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 4380ecde6ceSAndreas Gohr * @deprecated 2020-08-13 439f50a239bSTakamura * @param string $msg 440f50a239bSTakamura * @param string $header 441c29dc6e4SAndreas Gohr */ 4420699d739SAndreas Gohrfunction dbglog($msg,$header=''){ 4430ecde6ceSAndreas Gohr dbg_deprecated('\\dokuwiki\\Logger'); 444585bf44eSChristopher Smith 4450ecde6ceSAndreas Gohr // was the msg as single line string? use it as header 446cad4fbf6SAndreas Gohr if($header === '' && is_string($msg) && strpos($msg, "\n") === false) { 4470ecde6ceSAndreas Gohr $header = $msg; 4480ecde6ceSAndreas Gohr $msg = ''; 449c7408a63SAndreas Gohr } 450c7408a63SAndreas Gohr 45131667ec6SAndreas Gohr Logger::getInstance(Logger::LOG_DEBUG)->log( 4520ecde6ceSAndreas Gohr $header, $msg 4530ecde6ceSAndreas Gohr ); 454c29dc6e4SAndreas Gohr} 455c29dc6e4SAndreas Gohr 456db09e31eSAndreas Gohr/** 4571419a485SAndreas Gohr * Log accesses to deprecated fucntions to the debug log 4581419a485SAndreas Gohr * 4591419a485SAndreas Gohr * @param string $alternative The function or method that should be used instead 46085331086SAndreas Gohr * @triggers INFO_DEPRECATION_LOG 4611419a485SAndreas Gohr */ 4621419a485SAndreas Gohrfunction dbg_deprecated($alternative = '') { 4630c5eb5e2SMichael Große \dokuwiki\Debug\DebugHelper::dbgDeprecatedFunction($alternative, 2); 46444455016SAndreas Gohr} 4651419a485SAndreas Gohr 4661419a485SAndreas Gohr/** 467db09e31eSAndreas Gohr * Print a reversed, prettyprinted backtrace 468db09e31eSAndreas Gohr * 469db09e31eSAndreas Gohr * @author Gary Owen <gary_owen@bigfoot.com> 470db09e31eSAndreas Gohr */ 471db09e31eSAndreas Gohrfunction dbg_backtrace(){ 472db09e31eSAndreas Gohr // Get backtrace 473db09e31eSAndreas Gohr $backtrace = debug_backtrace(); 474db09e31eSAndreas Gohr 475db09e31eSAndreas Gohr // Unset call to debug_print_backtrace 476db09e31eSAndreas Gohr array_shift($backtrace); 477db09e31eSAndreas Gohr 478db09e31eSAndreas Gohr // Iterate backtrace 479db09e31eSAndreas Gohr $calls = array(); 480db09e31eSAndreas Gohr $depth = count($backtrace) - 1; 481db09e31eSAndreas Gohr foreach ($backtrace as $i => $call) { 482db09e31eSAndreas Gohr $location = $call['file'] . ':' . $call['line']; 483db09e31eSAndreas Gohr $function = (isset($call['class'])) ? 484db09e31eSAndreas Gohr $call['class'] . $call['type'] . $call['function'] : $call['function']; 485db09e31eSAndreas Gohr 4868259f1aaSAndreas Gohr $params = array(); 487db09e31eSAndreas Gohr if (isset($call['args'])){ 4888259f1aaSAndreas Gohr foreach($call['args'] as $arg){ 4898259f1aaSAndreas Gohr if(is_object($arg)){ 4908259f1aaSAndreas Gohr $params[] = '[Object '.get_class($arg).']'; 4918259f1aaSAndreas Gohr }elseif(is_array($arg)){ 4928259f1aaSAndreas Gohr $params[] = '[Array]'; 4938259f1aaSAndreas Gohr }elseif(is_null($arg)){ 49459bc3b48SGerrit Uitslag $params[] = '[NULL]'; 4958259f1aaSAndreas Gohr }else{ 4968259f1aaSAndreas Gohr $params[] = (string) '"'.$arg.'"'; 497db09e31eSAndreas Gohr } 4988259f1aaSAndreas Gohr } 4998259f1aaSAndreas Gohr } 5008259f1aaSAndreas Gohr $params = implode(', ',$params); 501db09e31eSAndreas Gohr 5028259f1aaSAndreas Gohr $calls[$depth - $i] = sprintf('%s(%s) called at %s', 503db09e31eSAndreas Gohr $function, 504db09e31eSAndreas Gohr str_replace("\n", '\n', $params), 505db09e31eSAndreas Gohr $location); 506db09e31eSAndreas Gohr } 507db09e31eSAndreas Gohr ksort($calls); 508db09e31eSAndreas Gohr 509db09e31eSAndreas Gohr return implode("\n", $calls); 510db09e31eSAndreas Gohr} 511db09e31eSAndreas Gohr 51224297a69SAndreas Gohr/** 51324297a69SAndreas Gohr * Remove all data from an array where the key seems to point to sensitive data 51424297a69SAndreas Gohr * 51524297a69SAndreas Gohr * This is used to remove passwords, mail addresses and similar data from the 51624297a69SAndreas Gohr * debug output 51724297a69SAndreas Gohr * 51824297a69SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 519f50a239bSTakamura * 520f50a239bSTakamura * @param array $data 52124297a69SAndreas Gohr */ 52224297a69SAndreas Gohrfunction debug_guard(&$data){ 52324297a69SAndreas Gohr foreach($data as $key => $value){ 52424297a69SAndreas Gohr if(preg_match('/(notify|pass|auth|secret|ftp|userinfo|token|buid|mail|proxy)/i',$key)){ 52524297a69SAndreas Gohr $data[$key] = '***'; 52624297a69SAndreas Gohr continue; 52724297a69SAndreas Gohr } 52824297a69SAndreas Gohr if(is_array($value)) debug_guard($data[$key]); 52924297a69SAndreas Gohr } 53024297a69SAndreas Gohr} 531