From 930a3ceac0aeb42474fb0a6129517aaa15b794b4 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak <alec@alec.pl> Date: Wed, 18 May 2016 13:53:51 -0400 Subject: [PATCH] Fix bug where errors could have been not logged when per_user_logging=true --- program/lib/Roundcube/rcube.php | 37 +++++++++++++++++-------------------- CHANGELOG | 1 + 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 7dd6a6a..b6f161e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -8,6 +8,7 @@ - Managesieve: Support 'duplicate' extension [RFC 7352] - Managesieve: Unhide advanced rule controls if there are inputs with errors - Managesieve: Display warning message when filter form contains errors +- Fix bug where errors could have been not logged when per_user_logging=true RELEASE 1.2.0 ------------- diff --git a/program/lib/Roundcube/rcube.php b/program/lib/Roundcube/rcube.php index 6193715..a49a71f 100644 --- a/program/lib/Roundcube/rcube.php +++ b/program/lib/Roundcube/rcube.php @@ -1142,12 +1142,16 @@ // trigger logging hook if (is_object(self::$instance) && is_object(self::$instance->plugins)) { - $log = self::$instance->plugins->exec_hook('write_log', array('name' => $name, 'date' => $date, 'line' => $line)); + $log = self::$instance->plugins->exec_hook('write_log', + array('name' => $name, 'date' => $date, 'line' => $line)); + $name = $log['name']; $line = $log['line']; $date = $log['date']; - if ($log['abort']) + + if ($log['abort']) { return true; + } } // add session ID to the log @@ -1169,32 +1173,25 @@ // per-user logging is activated if (self::$instance && self::$instance->config->get('per_user_logging', false) && self::$instance->get_user_id()) { $log_dir = self::$instance->get_user_log_dir(); - if (empty($log_dir)) + if (empty($log_dir) && $name != 'errors') { return false; + } } - else if (!empty($log['dir'])) { - $log_dir = $log['dir']; - } - else if (self::$instance) { - $log_dir = self::$instance->config->get('log_dir'); + + if (empty($log_dir)) { + if (!empty($log['dir'])) { + $log_dir = $log['dir']; + } + else if (self::$instance) { + $log_dir = self::$instance->config->get('log_dir'); + } } if (empty($log_dir)) { $log_dir = RCUBE_INSTALL_PATH . 'logs'; } - // try to open specific log file for writing - $logfile = $log_dir.'/'.$name; - - if ($fp = @fopen($logfile, 'a')) { - fwrite($fp, $line); - fflush($fp); - fclose($fp); - return true; - } - - trigger_error("Error writing to log file $logfile; Please check permissions", E_USER_WARNING); - return false; + return file_put_contents("$log_dir/$name", $line, FILE_APPEND) !== false; } /** -- Gitblit v1.9.1