summaryrefslogtreecommitdiff
path: root/public_html
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2013-11-11 17:59:58 (GMT)
committerThomas Bruederli <bruederli@kolabsys.com>2013-11-21 14:12:47 (GMT)
commit94eb4a7c350b8e530f1289576bf1c3b10675a9eb (patch)
tree3f3f8ae3bb0bf0b6e47f9e1c110ee340f835dcff /public_html
parentf9e821e2ec2462720ac1d57951e6766cde4f71dc (diff)
downloadiRony-94eb4a7c350b8e530f1289576bf1c3b10675a9eb.tar.gz
Add capabilities for full HTTP payload logging
Diffstat (limited to 'public_html')
-rw-r--r--public_html/debug.php173
-rw-r--r--public_html/index.php28
2 files changed, 10 insertions, 191 deletions
diff --git a/public_html/debug.php b/public_html/debug.php
deleted file mode 100644
index 10fcea8..0000000
--- a/public_html/debug.php
+++ /dev/null
@@ -1,173 +0,0 @@
-<?php
-
-/**
- * Kolab WebDAV/CalDAV/CardDAV Debug Pipe
- *
- * @author Thomas Bruederli <bruederli@kolabsys.com>
- *
- * Copyright (C) 2013, Kolab Systems AG <contact@kolabsys.com>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-// define some environment variables used throughout the app and libraries
-define('KOLAB_DAV_ROOT', realpath('../'));
-define('KOLAB_DAV_START', microtime(true));
-
-define('RCUBE_INSTALL_PATH', KOLAB_DAV_ROOT . '/');
-define('RCUBE_CONFIG_DIR', KOLAB_DAV_ROOT . '/config/');
-
-ini_set('error_reporting', E_ALL &~ E_NOTICE &~ E_STRICT);
-
-require_once KOLAB_DAV_ROOT . '/vendor/autoload.php';
-require_once KOLAB_DAV_ROOT . '/lib/Roundcube/bootstrap.php';
-
-// Roundcube framework initialization
-$rcube = rcube::get_instance();
-$rcube->config->load_from_file(RCUBE_CONFIG_DIR . 'dav.inc.php');
-
-$base_uri = $rcube->config->get('base_uri', slashify(substr(dirname($_SERVER['SCRIPT_FILENAME']), strlen($_SERVER['DOCUMENT_ROOT']))));
-
-// quick & dirty request debugging
-$http_headers = array();
-foreach (apache_request_headers() as $hdr => $value) {
- if ($hdr == 'Destination')
- $value = str_replace($base_uri, $base_uri . 'index.php/', $value);
- $http_headers[$hdr] = "$hdr: $value";
-}
-// read HTTP request body
-$in = fopen('php://input', 'r');
-$http_body = stream_get_contents($in);
-fclose($in);
-
-$rcube->write_log('davdebug', $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . ' ' . $_SERVER['SERVER_PROTOCOL'] . "\n" .
- join("\n", $http_headers) . "\n\n" . $http_body);
-
-// fix URIs in request body
-$http_body = preg_replace("!(<\w+:href[^>]*>$base_uri)!i", '\\1index.php/', $http_body);
-$http_headers['Content-Length'] = "Content-Length: " . strlen($http_body);
-
-// forward the full request to index.php
-$rel_url = substr($_SERVER['REQUEST_URI'], strlen($base_uri));
-$host = $_SERVER['HTTP_HOST'];
-$port = 80;
-$path = $base_uri . 'index.php/' . $rel_url;
-
-// remove Host: header
-unset($http_headers['Host']);
-$response_headers = array();
-
-// re-send using curl
-$ch = curl_init();
-curl_setopt($ch, CURLOPT_URL, "http://$host:$port$path");
-curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $_SERVER['REQUEST_METHOD']);
-curl_setopt($ch, CURLOPT_POSTFIELDS, $http_body);
-curl_setopt($ch, CURLOPT_HTTPHEADER, array_values($http_headers));
-curl_setopt($ch, CURLOPT_HEADER, 0);
-curl_setopt($ch, CURLOPT_HEADERFUNCTION, function($ch, $header) use (&$response_headers){
- list($key, $val) = explode(": ", rtrim($header), 2);
- if (!empty($val)) $response_headers[$key] = $val;
- return strlen($header);
-});
-
-$result = str_replace('index.php/', '', curl_exec($ch));
-$info = curl_getinfo($ch);
-
-// send recieved HTTP status code
-$result_headers = $_SERVER['SERVER_PROTOCOL'] . " " . $info['http_code'] . " " . http_response_phrase($info['http_code']);
-header($result_headers, true);
-
-// forward response headers
-unset($response_headers['Transfer-Encoding']);
-foreach ($response_headers as $hdr => $value) {
- $value = str_replace('index.php/', '', $value);
- $result_headers .= "\n$hdr: " . $value;
- header("$hdr: " . $value, true);
-}
-
-// log response
-$rcube->write_log('davdebug', "RESPONSE:\n" . $result_headers . "\n\n" . (strpos($info['content_type'], 'image/') === false ? $result : ''));
-
-// send response body back to client
-echo $result;
-
-
-/**
- * Derived from HTTP_Request2_Response::getDefaultReasonPhrase()
- */
-function http_response_phrase($code)
-{
- static $phrases = array(
-
- // 1xx: Informational - Request received, continuing process
- 100 => 'Continue',
- 101 => 'Switching Protocols',
-
- // 2xx: Success - The action was successfully received, understood and
- // accepted
- 200 => 'OK',
- 201 => 'Created',
- 202 => 'Accepted',
- 203 => 'Non-Authoritative Information',
- 204 => 'No Content',
- 205 => 'Reset Content',
- 206 => 'Partial Content',
- 207 => 'Multi-Status',
-
- // 3xx: Redirection - Further action must be taken in order to complete
- // the request
- 300 => 'Multiple Choices',
- 301 => 'Moved Permanently',
- 302 => 'Found', // 1.1
- 303 => 'See Other',
- 304 => 'Not Modified',
- 305 => 'Use Proxy',
- 307 => 'Temporary Redirect',
-
- // 4xx: Client Error - The request contains bad syntax or cannot be
- // fulfilled
- 400 => 'Bad Request',
- 401 => 'Unauthorized',
- 402 => 'Payment Required',
- 403 => 'Forbidden',
- 404 => 'Not Found',
- 405 => 'Method Not Allowed',
- 406 => 'Not Acceptable',
- 407 => 'Proxy Authentication Required',
- 408 => 'Request Timeout',
- 409 => 'Conflict',
- 410 => 'Gone',
- 411 => 'Length Required',
- 412 => 'Precondition Failed',
- 413 => 'Request Entity Too Large',
- 414 => 'Request-URI Too Long',
- 415 => 'Unsupported Media Type',
- 416 => 'Requested Range Not Satisfiable',
- 417 => 'Expectation Failed',
-
- // 5xx: Server Error - The server failed to fulfill an apparently
- // valid request
- 500 => 'Internal Server Error',
- 501 => 'Not Implemented',
- 502 => 'Bad Gateway',
- 503 => 'Service Unavailable',
- 504 => 'Gateway Timeout',
- 505 => 'HTTP Version Not Supported',
- 509 => 'Bandwidth Limit Exceeded',
- );
-
- return $phrases[$code];
-}
-
diff --git a/public_html/index.php b/public_html/index.php
index 64f02ea..0886ebb 100644
--- a/public_html/index.php
+++ b/public_html/index.php
@@ -66,30 +66,22 @@ $required = array('libkolab', 'libcalendaring');
$rcube->plugins->init($rcube);
$rcube->plugins->load_plugins($plugins, $required);
+// enable logger
+if ($rcube->config->get('kolabdav_console') || $rcube->config->get('kolabdav_user_debug')) {
+ $logger = new \Kolab\Utils\DAVLogger((\Kolab\Utils\DAVLogger::CONSOLE | $rcube->config->get('kolabdav_http_log', 0)));
+}
// convenience function, you know it well :-)
function console()
{
- global $rcube;
+ global $rcube, $logger;
// write to global console log
if ($rcube->config->get('kolabdav_console', false)) {
call_user_func_array(array('rcube', 'console'), func_get_args());
}
-
- // dump console data per user
- if ($rcube->config->get('kolabdav_user_debug', false)) {
- $uname = \Kolab\DAV\Auth\HTTPBasic::$current_user;
- $log_dir = $rcube->config->get('log_dir', RCUBE_INSTALL_PATH . 'logs');
-
- if ($uname && $log_dir && is_writable($log_dir . '/' . $uname)) {
- $msg = array();
- foreach (func_get_args() as $arg) {
- $msg[] = !is_string($arg) ? var_export($arg, true) : $arg;
- }
-
- rcube::write_log($uname . '/console', join(";\n", $msg));
- }
+ else if ($logger) {
+ call_user_func_array(array($logger, 'console'), func_get_args());
}
}
@@ -145,9 +137,9 @@ else if ($services['WEBDAV']) {
$server = new \Sabre\DAV\Server($nodes);
$server->setBaseUri($base_uri);
-// enable logger
-if ($rcube->config->get('kolabdav_console') || $rcube->config->get('kolabdav_user_debug')) {
- $server->addPlugin(new \Kolab\Utils\DAVLogger());
+// connect logger
+if (is_object($logger)) {
+ $server->addPlugin($logger);
}
// register some plugins