xref: /dokuwiki/inc/infoutils.php (revision e570ed43f12144c6db4693ddd798a433a6924485)
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 Gohrrequire_once(DOKU_INC.'inc/HTTPClient.php');
11c29dc6e4SAndreas Gohr
12c29dc6e4SAndreas Gohr/**
13c29dc6e4SAndreas Gohr * Check for new messages from upstream
14c29dc6e4SAndreas Gohr *
15c29dc6e4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
16c29dc6e4SAndreas Gohr */
17c29dc6e4SAndreas Gohrfunction checkUpdateMessages(){
18c29dc6e4SAndreas Gohr    global $conf;
19c29dc6e4SAndreas Gohr    global $INFO;
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
27c29dc6e4SAndreas Gohr    if($lm < time()-(60*60*24) || $lm < @filemtime(DOKU_CONF.'msg')){
28587afae5Schris        $num = @file(DOKU_CONF.'msg');
29587afae5Schris        $num = is_array($num) ? (int) $num[0] : 0;
30c29dc6e4SAndreas Gohr        $http = new DokuHTTPClient();
31c29dc6e4SAndreas Gohr        $http->timeout = 8;
32c29dc6e4SAndreas Gohr        $data = $http->get(DOKU_MESSAGEURL.$num);
33c29dc6e4SAndreas Gohr        io_saveFile($cf,$data);
34c29dc6e4SAndreas Gohr    }else{
35c29dc6e4SAndreas Gohr        $data = io_readFile($cf);
36c29dc6e4SAndreas Gohr    }
37c29dc6e4SAndreas Gohr
38c29dc6e4SAndreas Gohr    // show messages through the usual message mechanism
39c29dc6e4SAndreas Gohr    $msgs = explode("\n%\n",$data);
40c29dc6e4SAndreas Gohr    foreach($msgs as $msg){
41c29dc6e4SAndreas Gohr        if($msg) msg($msg,2);
42c29dc6e4SAndreas Gohr    }
43c29dc6e4SAndreas Gohr}
44c29dc6e4SAndreas Gohr
45c29dc6e4SAndreas Gohr
46c29dc6e4SAndreas Gohr/**
47c29dc6e4SAndreas Gohr * Return DokuWikis version
48c29dc6e4SAndreas Gohr *
49c29dc6e4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
50c29dc6e4SAndreas Gohr */
51c29dc6e4SAndreas Gohrfunction getVersion(){
52c29dc6e4SAndreas Gohr    //import version string
53e9208eb1SAndreas Gohr    if(@file_exists(DOKU_INC.'VERSION')){
54c29dc6e4SAndreas Gohr        //official release
55e9208eb1SAndreas Gohr        return 'Release '.trim(io_readfile(DOKU_INC.'VERSION'));
56e9208eb1SAndreas Gohr    }elseif(is_dir(DOKU_INC.'_darcs')){
57*e570ed43SAndreas Gohr        if(is_file(DOKU_INC.'_darcs/inventory')){
58*e570ed43SAndreas Gohr            $inventory = DOKU_INC.'_darcs/inventory';
59*e570ed43SAndreas Gohr        }elseif(is_file(DOKU_INC.'_darcs/hashed_inventory')){
60*e570ed43SAndreas Gohr            $inventory = DOKU_INC.'_darcs/hashed_inventory';
61*e570ed43SAndreas Gohr        }else{
62*e570ed43SAndreas Gohr            return 'Darcs unknown';
63*e570ed43SAndreas Gohr        }
64*e570ed43SAndreas Gohr
65c29dc6e4SAndreas Gohr        //darcs checkout - read last 2000 bytes of inventory
66*e570ed43SAndreas Gohr        $sz   = filesize($inventory);
67c29dc6e4SAndreas Gohr        $seek = max(0,$sz-2000);
68*e570ed43SAndreas Gohr        $fh   = fopen($inventory,'rb');
69c29dc6e4SAndreas Gohr        fseek($fh,$seek);
70c29dc6e4SAndreas Gohr        $chunk = fread($fh,2000);
71c29dc6e4SAndreas Gohr        fclose($fh);
72c29dc6e4SAndreas Gohr        $inv = preg_grep('#\*\*\d{14}[\]$]#',explode("\n",$chunk));
73c29dc6e4SAndreas Gohr        $cur = array_pop($inv);
74c29dc6e4SAndreas Gohr        preg_match('#\*\*(\d{4})(\d{2})(\d{2})#',$cur,$matches);
75c29dc6e4SAndreas Gohr        return 'Darcs '.$matches[1].'-'.$matches[2].'-'.$matches[3];
76c29dc6e4SAndreas Gohr    }else{
77c29dc6e4SAndreas Gohr        return 'snapshot?';
78c29dc6e4SAndreas Gohr    }
79c29dc6e4SAndreas Gohr}
80c29dc6e4SAndreas Gohr
81c29dc6e4SAndreas Gohr/**
82c29dc6e4SAndreas Gohr * Run a few sanity checks
83c29dc6e4SAndreas Gohr *
84c29dc6e4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
85c29dc6e4SAndreas Gohr */
86c29dc6e4SAndreas Gohrfunction check(){
87c29dc6e4SAndreas Gohr    global $conf;
88c29dc6e4SAndreas Gohr    global $INFO;
89c29dc6e4SAndreas Gohr
90c29dc6e4SAndreas Gohr    msg('DokuWiki version: '.getVersion(),1);
91c29dc6e4SAndreas Gohr
92ab91da89SAndreas Gohr    if(version_compare(phpversion(),'5.1.2','<')){
93ab91da89SAndreas Gohr        msg('Your PHP version is too old ('.phpversion().' vs. 5.1.2+ needed)',-1);
94c29dc6e4SAndreas Gohr    }else{
95c29dc6e4SAndreas Gohr        msg('PHP version '.phpversion(),1);
96c29dc6e4SAndreas Gohr    }
97c29dc6e4SAndreas Gohr
9873038c47SAndreas Gohr    $mem = (int) php_to_byte(ini_get('memory_limit'));
9973038c47SAndreas Gohr    if($mem){
10073038c47SAndreas Gohr        if($mem < 16777216){
10173038c47SAndreas Gohr            msg('PHP is limited to less than 16MB RAM ('.$mem.' bytes). Increase memory_limit in php.ini',-1);
10273038c47SAndreas Gohr        }elseif($mem < 20971520){
10373038c47SAndreas 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);
10473038c47SAndreas Gohr        }elseif($mem < 33554432){
10573038c47SAndreas 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);
10673038c47SAndreas Gohr        }else{
10773038c47SAndreas Gohr            msg('More than 32MB RAM ('.$mem.' bytes) available.',1);
10873038c47SAndreas Gohr        }
10973038c47SAndreas Gohr    }
11073038c47SAndreas Gohr
111c29dc6e4SAndreas Gohr    if(is_writable($conf['changelog'])){
112c29dc6e4SAndreas Gohr        msg('Changelog is writable',1);
113c29dc6e4SAndreas Gohr    }else{
114c29dc6e4SAndreas Gohr        if (@file_exists($conf['changelog'])) {
115c29dc6e4SAndreas Gohr            msg('Changelog is not writable',-1);
116c29dc6e4SAndreas Gohr        }
117c29dc6e4SAndreas Gohr    }
118c29dc6e4SAndreas Gohr
119c29dc6e4SAndreas Gohr    if (isset($conf['changelog_old']) && @file_exists($conf['changelog_old'])) {
1202cdbda06SAnika Henke        msg('Old changelog exists', 0);
121c29dc6e4SAndreas Gohr    }
122c29dc6e4SAndreas Gohr
123c29dc6e4SAndreas Gohr    if (@file_exists($conf['changelog'].'_failed')) {
1242cdbda06SAnika Henke        msg('Importing old changelog failed', -1);
125c29dc6e4SAndreas Gohr    } else if (@file_exists($conf['changelog'].'_importing')) {
126c29dc6e4SAndreas Gohr        msg('Importing old changelog now.', 0);
127c29dc6e4SAndreas Gohr    } else if (@file_exists($conf['changelog'].'_import_ok')) {
1282cdbda06SAnika Henke        msg('Old changelog imported', 1);
129c29dc6e4SAndreas Gohr        if (!plugin_isdisabled('importoldchangelog')) {
1302cdbda06SAnika Henke            msg('Importoldchangelog plugin not disabled after import', -1);
131c29dc6e4SAndreas Gohr        }
132c29dc6e4SAndreas Gohr    }
133c29dc6e4SAndreas Gohr
134c29dc6e4SAndreas Gohr    if(is_writable($conf['datadir'])){
135c29dc6e4SAndreas Gohr        msg('Datadir is writable',1);
136c29dc6e4SAndreas Gohr    }else{
137c29dc6e4SAndreas Gohr        msg('Datadir is not writable',-1);
138c29dc6e4SAndreas Gohr    }
139c29dc6e4SAndreas Gohr
140c29dc6e4SAndreas Gohr    if(is_writable($conf['olddir'])){
141c29dc6e4SAndreas Gohr        msg('Attic is writable',1);
142c29dc6e4SAndreas Gohr    }else{
143c29dc6e4SAndreas Gohr        msg('Attic is not writable',-1);
144c29dc6e4SAndreas Gohr    }
145c29dc6e4SAndreas Gohr
146c29dc6e4SAndreas Gohr    if(is_writable($conf['mediadir'])){
147c29dc6e4SAndreas Gohr        msg('Mediadir is writable',1);
148c29dc6e4SAndreas Gohr    }else{
149c29dc6e4SAndreas Gohr        msg('Mediadir is not writable',-1);
150c29dc6e4SAndreas Gohr    }
151c29dc6e4SAndreas Gohr
152c29dc6e4SAndreas Gohr    if(is_writable($conf['cachedir'])){
153c29dc6e4SAndreas Gohr        msg('Cachedir is writable',1);
154c29dc6e4SAndreas Gohr    }else{
155c29dc6e4SAndreas Gohr        msg('Cachedir is not writable',-1);
156c29dc6e4SAndreas Gohr    }
157c29dc6e4SAndreas Gohr
158c29dc6e4SAndreas Gohr    if(is_writable($conf['lockdir'])){
159c29dc6e4SAndreas Gohr        msg('Lockdir is writable',1);
160c29dc6e4SAndreas Gohr    }else{
161c29dc6e4SAndreas Gohr        msg('Lockdir is not writable',-1);
162c29dc6e4SAndreas Gohr    }
163c29dc6e4SAndreas Gohr
1640d487d8fSAndreas Gohr    if($conf['authtype'] == 'plain'){
165c29dc6e4SAndreas Gohr        if(is_writable(DOKU_CONF.'users.auth.php')){
166c29dc6e4SAndreas Gohr            msg('conf/users.auth.php is writable',1);
167c29dc6e4SAndreas Gohr        }else{
168c29dc6e4SAndreas Gohr            msg('conf/users.auth.php is not writable',0);
169c29dc6e4SAndreas Gohr        }
1700d487d8fSAndreas Gohr    }
171c29dc6e4SAndreas Gohr
172c29dc6e4SAndreas Gohr    if(function_exists('mb_strpos')){
173c29dc6e4SAndreas Gohr        if(defined('UTF8_NOMBSTRING')){
174c29dc6e4SAndreas Gohr            msg('mb_string extension is available but will not be used',0);
175c29dc6e4SAndreas Gohr        }else{
176c29dc6e4SAndreas Gohr            msg('mb_string extension is available and will be used',1);
1774222b898SAndreas Gohr            if(ini_get('mbstring.func_overload') != 0){
1784222b898SAndreas Gohr                msg('mb_string function overloading is enabled, this will cause problems and should be disabled',-1);
1794222b898SAndreas Gohr            }
180c29dc6e4SAndreas Gohr        }
181c29dc6e4SAndreas Gohr    }else{
182c29dc6e4SAndreas Gohr        msg('mb_string extension not available - PHP only replacements will be used',0);
183c29dc6e4SAndreas Gohr    }
184c29dc6e4SAndreas Gohr
185c29dc6e4SAndreas Gohr    if($conf['allowdebug']){
186c29dc6e4SAndreas Gohr        msg('Debugging support is enabled. If you don\'t need it you should set $conf[\'allowdebug\'] = 0',-1);
187c29dc6e4SAndreas Gohr    }else{
188c29dc6e4SAndreas Gohr        msg('Debugging support is disabled',1);
189c29dc6e4SAndreas Gohr    }
190c29dc6e4SAndreas Gohr
1913d3c095dSMike Frysinger    if($INFO['userinfo']['name']){
192c1791678SAndreas Gohr        msg('You are currently logged in as '.$_SERVER['REMOTE_USER'].' ('.$INFO['userinfo']['name'].')',0);
193c1791678SAndreas Gohr        msg('You are part of the groups '.join($INFO['userinfo']['grps'],', '),0);
1943d3c095dSMike Frysinger    }else{
1953d3c095dSMike Frysinger        msg('You are currently not logged in',0);
1963d3c095dSMike Frysinger    }
1973d3c095dSMike Frysinger
198c29dc6e4SAndreas Gohr    msg('Your current permission for this page is '.$INFO['perm'],0);
199c29dc6e4SAndreas Gohr
200c29dc6e4SAndreas Gohr    if(is_writable($INFO['filepath'])){
201c29dc6e4SAndreas Gohr        msg('The current page is writable by the webserver',0);
202c29dc6e4SAndreas Gohr    }else{
203c29dc6e4SAndreas Gohr        msg('The current page is not writable by the webserver',0);
204c29dc6e4SAndreas Gohr    }
205c29dc6e4SAndreas Gohr
206c29dc6e4SAndreas Gohr    if($INFO['writable']){
207c29dc6e4SAndreas Gohr        msg('The current page is writable by you',0);
208c29dc6e4SAndreas Gohr    }else{
2092cdbda06SAnika Henke        msg('The current page is not writable by you',0);
210c29dc6e4SAndreas Gohr    }
2113b1dfc83SAndreas Gohr
2123b1dfc83SAndreas Gohr    require_once(DOKU_INC.'inc/HTTPClient.php');
2133b1dfc83SAndreas Gohr    $check = wl('','',true).'data/_dummy';
2143b1dfc83SAndreas Gohr    $http = new DokuHTTPClient();
2153b1dfc83SAndreas Gohr    $http->timeout = 6;
2163b1dfc83SAndreas Gohr    $res = $http->get($check);
2173b1dfc83SAndreas Gohr    if(strpos($res,'data directory') !== false){
2183b1dfc83SAndreas Gohr        msg('It seems like the data directory is accessible from the web.
2193b1dfc83SAndreas Gohr                Make sure this directory is properly protected
2203b1dfc83SAndreas Gohr                (See <a href="http://www.dokuwiki.org/security">security</a>)',-1);
2213b1dfc83SAndreas Gohr    }elseif($http->status == 404 || $http->status == 403){
2223b1dfc83SAndreas Gohr        msg('The data directory seems to be properly protected',1);
2233b1dfc83SAndreas Gohr    }else{
2243b1dfc83SAndreas Gohr        msg('Failed to check if the data directory is accessible from the web.
2253b1dfc83SAndreas Gohr                Make sure this directory is properly protected
2263b1dfc83SAndreas Gohr                (See <a href="http://www.dokuwiki.org/security">security</a>)',-1);
2273b1dfc83SAndreas Gohr    }
228c29dc6e4SAndreas Gohr}
229c29dc6e4SAndreas Gohr
230c29dc6e4SAndreas Gohr/**
231c29dc6e4SAndreas Gohr * print a message
232c29dc6e4SAndreas Gohr *
233c29dc6e4SAndreas Gohr * If HTTP headers were not sent yet the message is added
234c29dc6e4SAndreas Gohr * to the global message array else it's printed directly
235c29dc6e4SAndreas Gohr * using html_msgarea()
236c29dc6e4SAndreas Gohr *
237c29dc6e4SAndreas Gohr *
238c29dc6e4SAndreas Gohr * Levels can be:
239c29dc6e4SAndreas Gohr *
240c29dc6e4SAndreas Gohr * -1 error
241c29dc6e4SAndreas Gohr *  0 info
242c29dc6e4SAndreas Gohr *  1 success
243c29dc6e4SAndreas Gohr *
244c29dc6e4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
245c29dc6e4SAndreas Gohr * @see    html_msgarea
246c29dc6e4SAndreas Gohr */
247c29dc6e4SAndreas Gohrfunction msg($message,$lvl=0,$line='',$file=''){
248c29dc6e4SAndreas Gohr    global $MSG;
249c29dc6e4SAndreas Gohr    $errors[-1] = 'error';
250c29dc6e4SAndreas Gohr    $errors[0]  = 'info';
251c29dc6e4SAndreas Gohr    $errors[1]  = 'success';
252c29dc6e4SAndreas Gohr    $errors[2]  = 'notify';
253c29dc6e4SAndreas Gohr
254c29dc6e4SAndreas Gohr    if($line || $file) $message.=' ['.basename($file).':'.$line.']';
255c29dc6e4SAndreas Gohr
256c29dc6e4SAndreas Gohr    if(!headers_sent()){
257c29dc6e4SAndreas Gohr        if(!isset($MSG)) $MSG = array();
258c29dc6e4SAndreas Gohr        $MSG[]=array('lvl' => $errors[$lvl], 'msg' => $message);
259c29dc6e4SAndreas Gohr    }else{
260c29dc6e4SAndreas Gohr        $MSG = array();
261c29dc6e4SAndreas Gohr        $MSG[]=array('lvl' => $errors[$lvl], 'msg' => $message);
262c29dc6e4SAndreas Gohr        if(function_exists('html_msgarea')){
263c29dc6e4SAndreas Gohr            html_msgarea();
264c29dc6e4SAndreas Gohr        }else{
265c29dc6e4SAndreas Gohr            print "ERROR($lvl) $message";
266c29dc6e4SAndreas Gohr        }
267c29dc6e4SAndreas Gohr    }
268c29dc6e4SAndreas Gohr}
269c29dc6e4SAndreas Gohr
270c29dc6e4SAndreas Gohr/**
271c29dc6e4SAndreas Gohr * print debug messages
272c29dc6e4SAndreas Gohr *
273c29dc6e4SAndreas Gohr * little function to print the content of a var
274c29dc6e4SAndreas Gohr *
275c29dc6e4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
276c29dc6e4SAndreas Gohr */
277c29dc6e4SAndreas Gohrfunction dbg($msg,$hidden=false){
278c29dc6e4SAndreas Gohr    (!$hidden) ? print '<pre class="dbg">' : print "<!--\n";
279c29dc6e4SAndreas Gohr    print_r($msg);
280c29dc6e4SAndreas Gohr    (!$hidden) ? print '</pre>' : print "\n-->";
281c29dc6e4SAndreas Gohr}
282c29dc6e4SAndreas Gohr
283c29dc6e4SAndreas Gohr/**
284c29dc6e4SAndreas Gohr * Print info to a log file
285c29dc6e4SAndreas Gohr *
286c29dc6e4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
287c29dc6e4SAndreas Gohr */
2880699d739SAndreas Gohrfunction dbglog($msg,$header=''){
289c29dc6e4SAndreas Gohr    global $conf;
290c7408a63SAndreas Gohr    if(is_object($msg) || is_array($msg)){
291c7408a63SAndreas Gohr        $msg = print_r($msg,true);
292c7408a63SAndreas Gohr    }
293c7408a63SAndreas Gohr
2940699d739SAndreas Gohr    if($header) $msg = "$header\n$msg";
2950699d739SAndreas Gohr
296c29dc6e4SAndreas Gohr    $file = $conf['cachedir'].'/debug.log';
297c29dc6e4SAndreas Gohr    $fh = fopen($file,'a');
298c29dc6e4SAndreas Gohr    if($fh){
299c29dc6e4SAndreas Gohr        fwrite($fh,date('H:i:s ').$_SERVER['REMOTE_ADDR'].': '.$msg."\n");
300c29dc6e4SAndreas Gohr        fclose($fh);
301c29dc6e4SAndreas Gohr    }
302c29dc6e4SAndreas Gohr}
303c29dc6e4SAndreas Gohr
304db09e31eSAndreas Gohr/**
305db09e31eSAndreas Gohr * Print a reversed, prettyprinted backtrace
306db09e31eSAndreas Gohr *
307db09e31eSAndreas Gohr * @author Gary Owen <gary_owen@bigfoot.com>
308db09e31eSAndreas Gohr */
309db09e31eSAndreas Gohrfunction dbg_backtrace(){
310db09e31eSAndreas Gohr    // Get backtrace
311db09e31eSAndreas Gohr    $backtrace = debug_backtrace();
312db09e31eSAndreas Gohr
313db09e31eSAndreas Gohr    // Unset call to debug_print_backtrace
314db09e31eSAndreas Gohr    array_shift($backtrace);
315db09e31eSAndreas Gohr
316db09e31eSAndreas Gohr    // Iterate backtrace
317db09e31eSAndreas Gohr    $calls = array();
318db09e31eSAndreas Gohr    $depth = count($backtrace) - 1;
319db09e31eSAndreas Gohr    foreach ($backtrace as $i => $call) {
320db09e31eSAndreas Gohr        $location = $call['file'] . ':' . $call['line'];
321db09e31eSAndreas Gohr        $function = (isset($call['class'])) ?
322db09e31eSAndreas Gohr            $call['class'] . $call['type'] . $call['function'] : $call['function'];
323db09e31eSAndreas Gohr
3248259f1aaSAndreas Gohr        $params = array();
325db09e31eSAndreas Gohr        if (isset($call['args'])){
3268259f1aaSAndreas Gohr            foreach($call['args'] as $arg){
3278259f1aaSAndreas Gohr                if(is_object($arg)){
3288259f1aaSAndreas Gohr                    $params[] = '[Object '.get_class($arg).']';
3298259f1aaSAndreas Gohr                }elseif(is_array($arg)){
3308259f1aaSAndreas Gohr                    $params[] = '[Array]';
3318259f1aaSAndreas Gohr                }elseif(is_null($arg)){
3328259f1aaSAndreas Gohr                    $param[] = '[NULL]';
3338259f1aaSAndreas Gohr                }else{
3348259f1aaSAndreas Gohr                    $params[] = (string) '"'.$arg.'"';
335db09e31eSAndreas Gohr                }
3368259f1aaSAndreas Gohr            }
3378259f1aaSAndreas Gohr        }
3388259f1aaSAndreas Gohr        $params = implode(', ',$params);
339db09e31eSAndreas Gohr
3408259f1aaSAndreas Gohr        $calls[$depth - $i] = sprintf('%s(%s) called at %s',
341db09e31eSAndreas Gohr                $function,
342db09e31eSAndreas Gohr                str_replace("\n", '\n', $params),
343db09e31eSAndreas Gohr                $location);
344db09e31eSAndreas Gohr    }
345db09e31eSAndreas Gohr    ksort($calls);
346db09e31eSAndreas Gohr
347db09e31eSAndreas Gohr    return implode("\n", $calls);
348db09e31eSAndreas Gohr}
349db09e31eSAndreas Gohr
35024297a69SAndreas Gohr/**
35124297a69SAndreas Gohr * Remove all data from an array where the key seems to point to sensitive data
35224297a69SAndreas Gohr *
35324297a69SAndreas Gohr * This is used to remove passwords, mail addresses and similar data from the
35424297a69SAndreas Gohr * debug output
35524297a69SAndreas Gohr *
35624297a69SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
35724297a69SAndreas Gohr */
35824297a69SAndreas Gohrfunction debug_guard(&$data){
35924297a69SAndreas Gohr    foreach($data as $key => $value){
36024297a69SAndreas Gohr        if(preg_match('/(notify|pass|auth|secret|ftp|userinfo|token|buid|mail|proxy)/i',$key)){
36124297a69SAndreas Gohr            $data[$key] = '***';
36224297a69SAndreas Gohr            continue;
36324297a69SAndreas Gohr        }
36424297a69SAndreas Gohr        if(is_array($value)) debug_guard($data[$key]);
36524297a69SAndreas Gohr    }
36624297a69SAndreas Gohr}
367