config/main.inc.php.dist lib/kolab_sync_logger.php lib/kolab_sync.php

Aleksander Machniak machniak at kolabsys.com
Fri Feb 1 09:39:50 CET 2013


 config/main.inc.php.dist  |    3 +++
 lib/kolab_sync.php        |   34 ++++++++++++++++++++++++++++++++++
 lib/kolab_sync_logger.php |    6 +++++-
 3 files changed, 42 insertions(+), 1 deletion(-)

New commits:
commit 259bfdb7320a6a5104709f488d70f3b7878d6bf0
Author: Aleksander Machniak <alec at alec.pl>
Date:   Fri Feb 1 09:38:40 2013 +0100

    Implemented logging per user/device (activesync_user_log option)

diff --git a/config/main.inc.php.dist b/config/main.inc.php.dist
index 56f5808..513700c 100644
--- a/config/main.inc.php.dist
+++ b/config/main.inc.php.dist
@@ -5,6 +5,9 @@
 // Enables ActiveSync protocol debuging
 $rcmail_config['activesync_debug'] = true;
 
+// Enables logging to a separate directory for every user/device
+$rcmail_config['activesync_user_log'] = 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 9316b7a..c2cbc16 100644
--- a/lib/kolab_sync.php
+++ b/lib/kolab_sync.php
@@ -120,6 +120,10 @@ class kolab_sync extends rcube
                 }
             }
 
+            // Set log directory per-user
+            $this->set_log_dir($_SERVER['PHP_AUTH_USER']);
+
+            // Authenticate the user
             $userid = $this->authenticate($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
         }
 
@@ -320,6 +324,36 @@ class kolab_sync extends rcube
 
 
     /**
+     * Set logging directory per-user
+     */
+    protected function set_log_dir($username)
+    {
+        if (empty($username)) {
+            return;
+        }
+
+        if (!$this->config->get('activesync_user_log')) {
+            return;
+        }
+
+        $log_dir = $this->config->get('log_dir');
+        $log_dir .= DIRECTORY_SEPARATOR . $username;
+
+        if (!empty($_GET['DeviceId'])) {
+            $log_dir .= '_' . $_GET['DeviceId'];
+        }
+
+        if (!is_dir($log_dir)) {
+            if (!mkdir($log_dir, 0770)) {
+                return;
+            }
+        }
+
+        $this->config->set('log_dir', $log_dir . DIRECTORY_SEPARATOR);
+    }
+
+
+    /**
      * Function to be executed in script shutdown
      */
     public function shutdown()
diff --git a/lib/kolab_sync_logger.php b/lib/kolab_sync_logger.php
index d7a3807..bea0beb 100644
--- a/lib/kolab_sync_logger.php
+++ b/lib/kolab_sync_logger.php
@@ -59,6 +59,7 @@ class kolab_sync_logger extends Zend_Log
         $rcube   = rcube::get_instance();
         $logfile = $rcube->config->get('activesync_log_file');
         $format  = $rcube->config->get('log_date_format', 'd-M-Y H:i:s O');
+        $log_dir = $rcube->config->get('log_dir');
         $mode    = $this->_priorities[$method];
 
         // if log_file is configured all logs will go to it
@@ -75,7 +76,10 @@ class kolab_sync_logger extends Zend_Log
                 break;
             }
 
-            $logfile = dirname(__FILE__) . '/../logs/' . $file;
+            $logfile = $log_dir . $file;
+        }
+        else if ($logfile[0] != '/') {
+            $logfile = $log_dir . $logfile;
         }
 
         if (!is_string($message)) {





More information about the commits mailing list