config/main.inc.php.dist lib/kolab_sync_logger.php lib/kolab_sync.php
Aleksander Machniak
machniak at kolabsys.com
Tue Nov 12 16:23:16 CET 2013
config/main.inc.php.dist | 3 +++
lib/kolab_sync.php | 46 ++++++++++++++++++++++++++++++++++++++++++----
lib/kolab_sync_logger.php | 8 ++++----
3 files changed, 49 insertions(+), 8 deletions(-)
New commits:
commit 9a2d2a8317a5a5f5b7e5b7cb8e4f17ddc5310248
Author: Aleksander Machniak <alec at alec.pl>
Date: Tue Nov 12 16:21:52 2013 +0100
Implemented activesync_user_debug option. When enabled debugging
information will be logged only for users which have existing
folder in logs directory.
diff --git a/config/main.inc.php.dist b/config/main.inc.php.dist
index 016e08b..a57c4e6 100644
--- a/config/main.inc.php.dist
+++ b/config/main.inc.php.dist
@@ -8,6 +8,9 @@ $rcmail_config['activesync_debug'] = true;
// Enables logging to a separate directory for every user/device
$rcmail_config['activesync_user_log'] = false;
+// Enable per-user debugging only if /var/log/syncroton/<username>/ folder exists
+$rcmail_config['activesync_user_debug'] = false;
+
// If specified all ActiveSync-related logs will be saved to this file
// Note: This doesn't change Roundcube Framework log locations
$rcmail_config['activesync_log_file'] = null;
diff --git a/lib/kolab_sync.php b/lib/kolab_sync.php
index 544a388..a845d0c 100644
--- a/lib/kolab_sync.php
+++ b/lib/kolab_sync.php
@@ -131,7 +131,7 @@ class kolab_sync extends rcube
}
// Set log directory per-user
- $this->set_log_dir($_SERVER['PHP_AUTH_USER']);
+ $this->set_log_dir($this->username ?: $_SERVER['PHP_AUTH_USER']);
// Save user password for Roundcube Framework
$this->password = $_SERVER['PHP_AUTH_PW'];
@@ -200,6 +200,8 @@ class kolab_sync extends rcube
if ($auth['valid'] && !$auth['abort']
&& ($userid = $this->login($auth['user'], $auth['pass'], $auth['host']))
) {
+ // set real username
+ $this->username = $auth['user'];
return $userid;
}
@@ -350,15 +352,30 @@ class kolab_sync extends rcube
return;
}
- if (!$this->config->get('activesync_user_log')) {
+ $user_debug = $this->config->get('activesync_user_debug');
+ $user_log = $user_debug || $this->config->get('activesync_user_log');
+
+ if (!$user_log) {
return;
}
- $log_dir = $this->config->get('log_dir');
+ $log_dir = $this->config->get('log_dir');
$log_dir .= DIRECTORY_SEPARATOR . $username;
+ // in user_debug mode enable logging only if user directory exists
+ if ($user_debug) {
+ if (!is_dir($log_dir)) {
+ return;
+ }
+ }
+ else if (!is_dir($log_dir)) {
+ if (!mkdir($log_dir, 0770)) {
+ return;
+ }
+ }
+
if (!empty($_GET['DeviceId'])) {
- $log_dir .= '_' . $_GET['DeviceId'];
+ $log_dir .= DIRECTORY_SEPARATOR . $_GET['DeviceId'];
}
if (!is_dir($log_dir)) {
@@ -367,6 +384,27 @@ class kolab_sync extends rcube
}
}
+ // make sure we're using debug mode where possible,
+ if ($user_debug) {
+ $this->config->set('debug_level', 1);
+ $this->config->set('memcache_debug', true);
+ $this->config->set('imap_debug', true);
+ $this->config->set('ldap_debug', true);
+ $this->config->set('smtp_debug', true);
+ $this->config->set('sql_debug', true);
+
+ // SQL/IMAP debug need to be set directly on the object instance
+ // it's already initialized/configured
+ if ($db = $this->get_dbh()) {
+ $db->set_debug(true);
+ }
+ if ($storage = $this->get_storage()) {
+ $storage->set_debug(true);
+ }
+
+ $this->logger->mode = kolab_sync_logger::DEBUG;
+ }
+
$this->config->set('log_dir', $log_dir);
// re-set PHP error logging
diff --git a/lib/kolab_sync_logger.php b/lib/kolab_sync_logger.php
index 7f1b664..95fd519 100644
--- a/lib/kolab_sync_logger.php
+++ b/lib/kolab_sync_logger.php
@@ -27,14 +27,14 @@
*/
class kolab_sync_logger extends Zend_Log
{
- private static $mode;
+ public $mode;
/**
* Constructor
*/
function __construct($mode = null)
{
- self::$mode = intval($mode);
+ $this->mode = intval($mode);
$r = new ReflectionClass($this);
$this->_priorities = $r->getConstants();
@@ -43,7 +43,7 @@ class kolab_sync_logger extends Zend_Log
public function __call($method, $params)
{
$method = strtoupper($method);
- if ($this->_priorities[$method] <= self::$mode) {
+ if ($this->_priorities[$method] <= $this->mode) {
$this->log(array_shift($params), $method);
}
}
@@ -69,7 +69,7 @@ class kolab_sync_logger extends Zend_Log
$mode = $this->_priorities[$method];
}
- if ($mode > self::$mode) {
+ if ($mode > $this->mode) {
return;
}
More information about the commits
mailing list