From e17decc4c2b175e1b2e3cd79f7c8b4c39c1f70f1 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Tue, 3 Feb 2015 07:52:14 -0500
Subject: Better handle log/temp directory misconfiguration

---
 program/lib/Roundcube/bootstrap.php    | 11 +++++++----
 program/lib/Roundcube/rcube_config.php | 10 ++++++++--
 2 files changed, 15 insertions(+), 6 deletions(-)

(limited to 'program/lib')

diff --git a/program/lib/Roundcube/bootstrap.php b/program/lib/Roundcube/bootstrap.php
index af87beb24..cc2347406 100644
--- a/program/lib/Roundcube/bootstrap.php
+++ b/program/lib/Roundcube/bootstrap.php
@@ -490,8 +490,11 @@ function rcube_autoload($classname)
  */
 function rcube_pear_error($err)
 {
-    error_log(sprintf("%s (%s): %s",
-        $err->getMessage(),
-        $err->getCode(),
-        $err->getUserinfo()), 0);
+    $msg = sprintf("ERROR: %s (%s)", $err->getMessage(), $err->getCode());
+
+    if ($info = $err->getUserinfo()) {
+        $msg .= ': ' . $info;
+    }
+
+    error_log($msg, 0);
 }
diff --git a/program/lib/Roundcube/rcube_config.php b/program/lib/Roundcube/rcube_config.php
index 3fae931d7..89e45449d 100644
--- a/program/lib/Roundcube/rcube_config.php
+++ b/program/lib/Roundcube/rcube_config.php
@@ -233,8 +233,14 @@ class rcube_config
             $this->prop['skin'] = self::DEFAULT_SKIN;
 
         // fix paths
-        $this->prop['log_dir'] = $this->prop['log_dir'] ? realpath(unslashify($this->prop['log_dir'])) : RCUBE_INSTALL_PATH . 'logs';
-        $this->prop['temp_dir'] = $this->prop['temp_dir'] ? realpath(unslashify($this->prop['temp_dir'])) : RCUBE_INSTALL_PATH . 'temp';
+        foreach (array('log_dir' => 'logs', 'temp_dir' => 'temp') as $key => $dir) {
+            foreach (array($this->prop[$key], '../' . $this->prop[$key], RCUBE_INSTALL_PATH . $dir) as $path) {
+                if ($path && ($realpath = realpath(unslashify($path)))) {
+                    $this->prop[$key] = $realpath;
+                    break;
+                }
+            }
+        }
 
         // fix default imap folders encoding
         foreach (array('drafts_mbox', 'junk_mbox', 'sent_mbox', 'trash_mbox') as $folder) {
-- 
cgit v1.2.3