From 2effc93ea4e603121f9fec005dd7cab10819af05 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Wed, 23 Nov 2011 16:34:39 +0000 Subject: [PATCH] * CalDAV/CardDAV/GroupDAV new user preference to log requests and responses to Apache error-log --- groupdav.php | 2 +- phpgwapi/inc/class.groupdav.inc.php | 43 +++++++++++++++++++++-- phpgwapi/inc/class.groupdav_hooks.inc.php | 10 +++--- 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/groupdav.php b/groupdav.php index 2d123f4c0d..81a0e222a9 100644 --- a/groupdav.php +++ b/groupdav.php @@ -44,4 +44,4 @@ $headertime = microtime(true); $groupdav = new groupdav(); $groupdav->ServeRequest(); -error_log(sprintf('GroupDAV %s request: status "%s", took %5.3f s'.($headertime?' (header include took %5.3f s)':''),$_SERVER['REQUEST_METHOD'].($_SERVER['REQUEST_METHOD']=='REPORT'?' '.$groupdav->propfind_options['root']['name']:'').' '.$_SERVER['PATH_INFO'],$groupdav->_http_status,microtime(true)-$starttime,$headertime-$starttime)); +//error_log(sprintf('GroupDAV %s: status "%s", took %5.3f s'.($headertime?' (header include took %5.3f s)':''),$_SERVER['REQUEST_METHOD'].($_SERVER['REQUEST_METHOD']=='REPORT'?' '.$groupdav->propfind_options['root']['name']:'').' '.$_SERVER['PATH_INFO'],$groupdav->_http_status,microtime(true)-$starttime,$headertime-$starttime)); diff --git a/phpgwapi/inc/class.groupdav.inc.php b/phpgwapi/inc/class.groupdav.inc.php index e1eafe3d12..d4c38bdfb9 100644 --- a/phpgwapi/inc/class.groupdav.inc.php +++ b/phpgwapi/inc/class.groupdav.inc.php @@ -351,7 +351,7 @@ class groupdav extends HTTP_WebDAV_Server { // principals collection $files['files'][] = $this->add_collection('/principals/', array( - 'displayname' => lang('Accounts'), + 'displayname' => lang('Accounts'), )); // todo: account_selection owngroups and none!!! foreach($this->accounts->search(array('type' => 'both')) as $account) @@ -1235,7 +1235,7 @@ class groupdav extends HTTP_WebDAV_Server } if ($path[0] == '/') { - $path = substr($path, 1); + $path = substr($path, 1); } $parts = explode('/', $this->_unslashify($path)); @@ -1293,4 +1293,43 @@ class groupdav extends HTTP_WebDAV_Server self::mkprop('write-content',''), ))); } + + /** + * Serve WebDAV HTTP request + * + * Reimplemented to add logging, currently only to Apache error-log + */ + function ServeRequest() + { + if (($debug_level=$GLOBALS['egw_info']['user']['preferences']['groupdav']['debug_level']) === 'r' || + $debug_level === 'f' || $this->debug) + { + $starttime = microtime(true); + $this->store_request = true; + ob_start(); + } + parent::ServeRequest(); + + if ($starttime) + { + error_log($_SERVER['REQUEST_METHOD'].' '.$_SERVER['PATH_INFO'].' HTTP/1.1'); + // reconstruct headers + foreach($_SERVER as $name => $value) + { + list($type,$name) = explode('_',$name,2); + if ($type == 'HTTP' || $type == 'CONTENT') error_log(str_replace(' ','-',ucwords(strtolower(($type=='HTTP'?'':$type.' ').str_replace('_',' ',$name)))).': '.$value); + } + if ($this->request) + { + error_log(''); + foreach(explode("\n",$this->request) as $line) error_log($line); + } + error_log('HTTP/1.1 '.$this->_http_status); + foreach(headers_list() as $line) error_log($line); + if (($content = ob_get_flush())) error_log(''); + if (strlen($content) > 1024 && $debug_level !== 'f') $content = substr($content,0,1024)."\n*** LOG TRUNKATED "; + $content .= sprintf('*** %s --> "%s" took %5.3f s',$_SERVER['REQUEST_METHOD'].($_SERVER['REQUEST_METHOD']=='REPORT'?' '.$this->propfind_options['root']['name']:'').' '.$_SERVER['PATH_INFO'],$this->_http_status,microtime(true)-$starttime)."\n"; + foreach(explode("\n",$content) as $line) error_log($line); + } + } } diff --git a/phpgwapi/inc/class.groupdav_hooks.inc.php b/phpgwapi/inc/class.groupdav_hooks.inc.php index dbd2989e4d..d26febedf3 100644 --- a/phpgwapi/inc/class.groupdav_hooks.inc.php +++ b/phpgwapi/inc/class.groupdav_hooks.inc.php @@ -120,10 +120,12 @@ class groupdav_hooks 'name' => 'debug_level', 'help' => 'Enables debug-messages to Apache/PHP error-log, allowing to diagnose problems on a per user basis.', 'values' => array( - '0' => '0 - off', - '1' => '1 - function calls', - '2' => '2 - more info', - '3' => '3 - complete $_SERVER array', + '0' => 'Off', + 'r' => 'Requests and truncated responses', + 'f' => 'Requests and full responses', + '1' => 'Debug 1 - function calls', + '2' => 'Debug 2 - more info', + '3' => 'Debug 3 - complete $_SERVER array', ), 'xmlrpc' => true, 'admin' => false,