From a30e0ad438842d5a2800aac6b6db0e9beddbae8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Sun, 21 Apr 2024 11:48:35 +0200 Subject: [PATCH] Infer file/line location in rcube::raise_error() from backtrace (#9422) * \n\s+'file' => __FILE__, * \n\s+'line' => __LINE__, * 'line' => __LINE__, 'file' => __FILE__, * 'file' => __FILE__, 'line' => __LINE__, * rest * more * improve cs * more cs * revert rcube_utils::preg_error changes * impl file/line from backtrace * Revert "revert rcube_utils::preg_error changes" --- index.php | 5 +++- plugins/enigma/bin/import_keys.sh | 4 +-- plugins/enigma/lib/enigma_driver_gnupg.php | 10 +++---- plugins/enigma/lib/enigma_engine.php | 1 - .../filesystem_attachments.php | 5 ---- plugins/identicon/identicon_engine.php | 6 ++-- .../lib/Roundcube/rcube_sieve_engine.php | 6 ++-- .../markasjunk/drivers/amavis_blacklist.php | 2 +- plugins/markasjunk/drivers/sa_blacklist.php | 2 +- plugins/markasjunk/markasjunk.php | 4 --- plugins/password/drivers/chpasswd.php | 2 -- plugins/password/drivers/dbmail.php | 2 -- .../password/drivers/dovecot_passwdfile.php | 4 +-- plugins/password/drivers/expect.php | 2 -- plugins/password/drivers/gearman.php | 4 --- plugins/password/drivers/httpapi.php | 8 +++--- plugins/password/drivers/kpasswd.php | 2 -- plugins/password/drivers/ldap_exop.php | 4 +-- plugins/password/drivers/ldap_ppolicy.php | 2 +- plugins/password/drivers/ldap_samba_ad.php | 4 +-- plugins/password/drivers/ldap_simple.php | 4 +-- plugins/password/drivers/mailcow.php | 2 +- plugins/password/drivers/miab.php | 2 +- plugins/password/drivers/pam.php | 4 --- plugins/password/drivers/pw_usermod.php | 2 -- plugins/password/drivers/pwned.php | 2 -- plugins/password/drivers/sasl.php | 2 -- plugins/password/drivers/smb.php | 2 -- plugins/password/drivers/tinycp.php | 2 +- plugins/password/drivers/virtualmin.php | 4 --- plugins/password/drivers/xmail.php | 4 --- plugins/password/drivers/zxcvbn.php | 2 -- plugins/password/password.php | 22 +++++++-------- plugins/zipdownload/zipdownload.php | 2 -- program/actions/login/oauth_backchannel.php | 4 --- program/actions/mail/compose.php | 6 ++-- program/actions/mail/send.php | 10 +------ program/actions/mail/viewsource.php | 2 -- program/actions/utils/save_pref.php | 2 -- program/actions/utils/spell.php | 2 -- program/actions/utils/spell_html.php | 2 -- program/include/rcmail.php | 8 +----- program/include/rcmail_attachment_handler.php | 2 +- program/include/rcmail_oauth.php | 28 ++----------------- program/include/rcmail_output_html.php | 8 +----- program/include/rcmail_sendmail.php | 7 +++-- program/lib/Roundcube/db/sqlite.php | 4 +-- program/lib/Roundcube/rcube.php | 16 +++++++---- program/lib/Roundcube/rcube_cache.php | 4 +-- program/lib/Roundcube/rcube_config.php | 4 +-- program/lib/Roundcube/rcube_db.php | 11 ++++---- program/lib/Roundcube/rcube_imap.php | 8 +++--- program/lib/Roundcube/rcube_ldap.php | 10 +++---- program/lib/Roundcube/rcube_plugin.php | 2 +- program/lib/Roundcube/rcube_plugin_api.php | 24 ++++++++-------- program/lib/Roundcube/rcube_session.php | 4 +-- program/lib/Roundcube/rcube_tnef_decoder.php | 2 -- program/lib/Roundcube/rcube_user.php | 2 +- program/lib/Roundcube/rcube_utils.php | 14 ++++++++-- program/lib/Roundcube/rcube_washtml.php | 4 +-- program/lib/Roundcube/session/memcache.php | 4 +-- program/lib/Roundcube/session/memcached.php | 4 +-- program/lib/Roundcube/session/redis.php | 4 +-- 63 files changed, 127 insertions(+), 210 deletions(-) diff --git a/index.php b/index.php index 1dc8c2704..83d9be2f9 100644 --- a/index.php +++ b/index.php @@ -262,7 +262,10 @@ if (empty($RCMAIL->user->ID)) { // check access to disabled actions $disabled_actions = (array) $RCMAIL->config->get('disabled_actions'); if (in_array($RCMAIL->task . '.' . ($RCMAIL->action ?: 'index'), $disabled_actions)) { - rcube::raise_error(['code' => 404, 'message' => 'Action disabled'], true, true); + rcube::raise_error([ + 'code' => 404, + 'message' => 'Action disabled', + ], true, true); } } diff --git a/plugins/enigma/bin/import_keys.sh b/plugins/enigma/bin/import_keys.sh index f625f2ac6..4832497a5 100755 --- a/plugins/enigma/bin/import_keys.sh +++ b/plugins/enigma/bin/import_keys.sh @@ -157,7 +157,7 @@ function import_dir($user_id, $dir, $dry_run = false) if ($datasize > $maxsize) { rcube::raise_error([ - 'code' => 605, 'line' => __LINE__, 'file' => __FILE__, + 'code' => 605, 'message' => "Enigma: Failed to save {$file}. Size exceeds max_allowed_packet.", ], true, false); @@ -177,7 +177,7 @@ function import_dir($user_id, $dir, $dry_run = false) if ($db->is_error($result)) { rcube::raise_error([ - 'code' => 605, 'line' => __LINE__, 'file' => __FILE__, + 'code' => 605, 'message' => "Enigma: Failed to save {$file} into database.", ], true, false); } diff --git a/plugins/enigma/lib/enigma_driver_gnupg.php b/plugins/enigma/lib/enigma_driver_gnupg.php index fe318bf80..116bfe4f0 100644 --- a/plugins/enigma/lib/enigma_driver_gnupg.php +++ b/plugins/enigma/lib/enigma_driver_gnupg.php @@ -602,7 +602,7 @@ class enigma_driver_gnupg extends enigma_driver // @phpstan-ignore-next-line if (!is_array($data)) { rcube::raise_error([ - 'code' => 605, 'line' => __LINE__, 'file' => __FILE__, + 'code' => 605, 'message' => "Enigma: Failed to sync {$file} ({$file_id}). Decode error.", ], true, false); @@ -631,7 +631,7 @@ class enigma_driver_gnupg extends enigma_driver @unlink($tmpfile); rcube::raise_error([ - 'code' => 605, 'line' => __LINE__, 'file' => __FILE__, + 'code' => 605, 'message' => "Enigma: Failed to sync {$file}.", ], true, false); } @@ -699,7 +699,7 @@ class enigma_driver_gnupg extends enigma_driver if ($datasize > $maxsize) { rcube::raise_error([ - 'code' => 605, 'line' => __LINE__, 'file' => __FILE__, + 'code' => 605, 'message' => "Enigma: Failed to save {$file}. Size exceeds max_allowed_packet.", ], true, false); @@ -711,7 +711,7 @@ class enigma_driver_gnupg extends enigma_driver if ($db->is_error($result)) { rcube::raise_error([ - 'code' => 605, 'line' => __LINE__, 'file' => __FILE__, + 'code' => 605, 'message' => "Enigma: Failed to save {$file} into database.", ], true, false); @@ -733,7 +733,7 @@ class enigma_driver_gnupg extends enigma_driver if ($db->is_error($result)) { rcube::raise_error([ - 'code' => 605, 'line' => __LINE__, 'file' => __FILE__, + 'code' => 605, 'message' => "Enigma: Failed to delete {$file} from database.", ], true, false); diff --git a/plugins/enigma/lib/enigma_engine.php b/plugins/enigma/lib/enigma_engine.php index c36020064..7450c54a7 100644 --- a/plugins/enigma/lib/enigma_engine.php +++ b/plugins/enigma/lib/enigma_engine.php @@ -1428,7 +1428,6 @@ class enigma_engine if ($result->getCode() != enigma_error::BADPASS) { rcube::raise_error([ 'code' => 600, - 'file' => __FILE__, 'line' => $line, 'message' => 'Enigma plugin: ' . $result->getMessage(), ], true, $abort); diff --git a/plugins/filesystem_attachments/filesystem_attachments.php b/plugins/filesystem_attachments/filesystem_attachments.php index 099132016..c895e802e 100644 --- a/plugins/filesystem_attachments/filesystem_attachments.php +++ b/plugins/filesystem_attachments/filesystem_attachments.php @@ -36,7 +36,6 @@ class filesystem_attachments extends rcube_plugin $plugin = $this->api->get_plugin($plugin_name); if (($plugin instanceof self) && $plugin->initialized) { rcube::raise_error([ - 'file' => __FILE__, 'line' => __LINE__, 'message' => "Can use only one plugin for attachments/file uploads! Using '{$plugin_name}', ignoring others.", ], true, false); return; @@ -203,8 +202,6 @@ class filesystem_attachments extends rcube_plugin // We allow that, but we'll let to know the user about the misconfiguration. if ($file_path == sys_get_temp_dir()) { rcube::raise_error([ - 'file' => __FILE__, - 'line' => __LINE__, 'message' => "Detected 'temp_dir' change. " . "Access to '{$temp_dir}' restricted by filesystem permissions or open_basedir", ], true, false); @@ -213,8 +210,6 @@ class filesystem_attachments extends rcube_plugin } rcube::raise_error([ - 'file' => __FILE__, - 'line' => __LINE__, 'message' => sprintf("%s can't read %s (not in temp_dir)", $rcmail->get_user_name(), substr($path, 0, 512)), ], true, false); diff --git a/plugins/identicon/identicon_engine.php b/plugins/identicon/identicon_engine.php index b31019a21..3bf15a105 100644 --- a/plugins/identicon/identicon_engine.php +++ b/plugins/identicon/identicon_engine.php @@ -132,12 +132,10 @@ class identicon_engine $this->generateGD(); } else { // log an error - $error = [ + rcube::raise_error([ 'code' => 500, 'message' => "PHP-GD module not found. It's required by identicon plugin.", - ]; - - rcube::raise_error($error, true, false); + ], true, false); } } diff --git a/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php b/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php index a811a7c43..f6c7d5764 100644 --- a/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php +++ b/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php @@ -221,8 +221,6 @@ class rcube_sieve_engine if ($error) { rcube::raise_error([ 'code' => 403, - 'file' => __FILE__, - 'line' => __LINE__, 'message' => "Unable to connect to managesieve on {$host}:{$port}", ], true, false); } @@ -510,7 +508,7 @@ class rcube_sieve_engine // check request size limit if ($max_post && count($_POST, \COUNT_RECURSIVE) >= $max_post) { rcube::raise_error([ - 'code' => 500, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 500, 'message' => 'Request size limit exceeded (one of max_input_vars/suhosin.request.max_vars/suhosin.post.max_vars)', ], true, false); $this->rc->output->show_message('managesieve.filtersaveerror', 'error'); @@ -518,7 +516,7 @@ class rcube_sieve_engine // check request depth limits elseif ($max_depth && count($_POST['_header']) > $max_depth) { rcube::raise_error([ - 'code' => 500, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 500, 'message' => 'Request size limit exceeded (one of suhosin.request.max_array_depth/suhosin.post.max_array_depth)', ], true, false); $this->rc->output->show_message('managesieve.filtersaveerror', 'error'); diff --git a/plugins/markasjunk/drivers/amavis_blacklist.php b/plugins/markasjunk/drivers/amavis_blacklist.php index 094ea2db1..cb2ecd897 100644 --- a/plugins/markasjunk/drivers/amavis_blacklist.php +++ b/plugins/markasjunk/drivers/amavis_blacklist.php @@ -55,7 +55,7 @@ class markasjunk_amavis_blacklist if (is_file($config_file) && !$rcube->config->load_from_file($config_file)) { rcube::raise_error([ - 'code' => 527, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 527, 'message' => "Failed to load config from {$config_file}", ], true, false); diff --git a/plugins/markasjunk/drivers/sa_blacklist.php b/plugins/markasjunk/drivers/sa_blacklist.php index ed2320072..828983b7b 100644 --- a/plugins/markasjunk/drivers/sa_blacklist.php +++ b/plugins/markasjunk/drivers/sa_blacklist.php @@ -70,7 +70,7 @@ class markasjunk_sa_blacklist if (is_file($config_file) && !$rcube->config->load_from_file($config_file)) { rcube::raise_error([ - 'code' => 527, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 527, 'message' => "Failed to load config from {$config_file}", ], true, false); diff --git a/plugins/markasjunk/markasjunk.php b/plugins/markasjunk/markasjunk.php index 3f982a1f6..6fe033251 100644 --- a/plugins/markasjunk/markasjunk.php +++ b/plugins/markasjunk/markasjunk.php @@ -315,8 +315,6 @@ class markasjunk extends rcube_plugin if (!is_readable($driver)) { rcube::raise_error([ 'code' => 600, - 'file' => __FILE__, - 'line' => __LINE__, 'message' => "markasjunk plugin: Unable to open driver file {$driver}", ], true, false); } @@ -326,8 +324,6 @@ class markasjunk extends rcube_plugin if (!class_exists($class, false) || !method_exists($class, 'spam') || !method_exists($class, 'ham')) { rcube::raise_error([ 'code' => 600, - 'file' => __FILE__, - 'line' => __LINE__, 'message' => "markasjunk plugin: Broken driver: {$driver}", ], true, false); } diff --git a/plugins/password/drivers/chpasswd.php b/plugins/password/drivers/chpasswd.php index dcf5f0155..59cbc4457 100644 --- a/plugins/password/drivers/chpasswd.php +++ b/plugins/password/drivers/chpasswd.php @@ -43,8 +43,6 @@ class rcube_chpasswd_password rcube::raise_error([ 'code' => 600, - 'file' => __FILE__, - 'line' => __LINE__, 'message' => "Password plugin: Unable to execute {$cmd}", ], true, false); diff --git a/plugins/password/drivers/dbmail.php b/plugins/password/drivers/dbmail.php index 3f4ed20fe..669b364f9 100644 --- a/plugins/password/drivers/dbmail.php +++ b/plugins/password/drivers/dbmail.php @@ -48,8 +48,6 @@ class rcube_dbmail_password rcube::raise_error([ 'code' => 600, - 'file' => __FILE__, - 'line' => __LINE__, 'message' => "Password plugin: Unable to execute {$curdir}/chgdbmailusers", ], true, false); diff --git a/plugins/password/drivers/dovecot_passwdfile.php b/plugins/password/drivers/dovecot_passwdfile.php index 0754ad934..3864e18fa 100644 --- a/plugins/password/drivers/dovecot_passwdfile.php +++ b/plugins/password/drivers/dovecot_passwdfile.php @@ -48,7 +48,7 @@ class rcube_dovecot_passwdfile_password if (empty($fp)) { rcube::raise_error([ - 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 600, 'message' => "Password plugin: Unable to read password file {$mailuserfile}.", ], true, false); @@ -79,7 +79,7 @@ class rcube_dovecot_passwdfile_password fclose($fp); rcube::raise_error([ - 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 600, 'message' => "Password plugin: Failed to save file {$mailuserfile}.", ], true, false); diff --git a/plugins/password/drivers/expect.php b/plugins/password/drivers/expect.php index 4562fdaf8..93ba51100 100644 --- a/plugins/password/drivers/expect.php +++ b/plugins/password/drivers/expect.php @@ -62,8 +62,6 @@ class rcube_expect_password rcube::raise_error([ 'code' => 600, - 'file' => __FILE__, - 'line' => __LINE__, 'message' => "Password plugin: Unable to execute {$cmd}", ], true, false); diff --git a/plugins/password/drivers/gearman.php b/plugins/password/drivers/gearman.php index 8a0ffbc1f..b40759a46 100644 --- a/plugins/password/drivers/gearman.php +++ b/plugins/password/drivers/gearman.php @@ -50,15 +50,11 @@ class rcube_gearman_password rcube::raise_error([ 'code' => 600, - 'file' => __FILE__, - 'line' => __LINE__, 'message' => "Password plugin: Gearman authentication failed for user {$username}", ], true, false); } else { rcube::raise_error([ 'code' => 600, - 'file' => __FILE__, - 'line' => __LINE__, 'message' => 'Password plugin: PECL Gearman module not loaded', ], true, false); } diff --git a/plugins/password/drivers/httpapi.php b/plugins/password/drivers/httpapi.php index 3fd8778ce..829d0fbed 100644 --- a/plugins/password/drivers/httpapi.php +++ b/plugins/password/drivers/httpapi.php @@ -81,7 +81,7 @@ class rcube_httpapi_password $params['query'] = $vars; } else { rcube::raise_error([ - 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 600, 'message' => 'Password plugin: Invalid httpapi method', ], true, false); @@ -95,7 +95,7 @@ class rcube_httpapi_password $result = $response->getBody(); } catch (Exception $e) { rcube::raise_error([ - 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 600, 'message' => 'Password plugin: ' . $e->getMessage(), ], true, false); @@ -105,7 +105,7 @@ class rcube_httpapi_password // Non-2xx response codes mean the password change failed if ($response_code < 200 || $response_code > 299) { rcube::raise_error([ - 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 600, 'message' => "Password plugin: Unexpected response code {$response_code}: " . substr($result, 0, 1024), ], true, false); @@ -116,7 +116,7 @@ class rcube_httpapi_password // If configured, check the body of the response if ($expect && !preg_match($expect, $result)) { rcube::raise_error([ - 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 600, 'message' => 'Password plugin: Unexpected response body: ' . substr($result, 0, 1024), ], true, false); diff --git a/plugins/password/drivers/kpasswd.php b/plugins/password/drivers/kpasswd.php index b63235e2b..9381f3b64 100644 --- a/plugins/password/drivers/kpasswd.php +++ b/plugins/password/drivers/kpasswd.php @@ -34,8 +34,6 @@ class rcube_kpasswd_password rcube::raise_error([ 'code' => 600, - 'file' => __FILE__, - 'line' => __LINE__, 'message' => "Password plugin: Unable to execute {$cmd}", ], true, false); diff --git a/plugins/password/drivers/ldap_exop.php b/plugins/password/drivers/ldap_exop.php index 2cc5a4866..5237111b2 100644 --- a/plugins/password/drivers/ldap_exop.php +++ b/plugins/password/drivers/ldap_exop.php @@ -35,8 +35,8 @@ class rcube_ldap_exop_password extends rcube_ldap_simple_password { if (!function_exists('ldap_exop_passwd')) { rcube::raise_error([ - 'code' => 100, 'type' => 'ldap', - 'file' => __FILE__, 'line' => __LINE__, + 'code' => 100, + 'type' => 'ldap', 'message' => 'ldap_exop_passwd not supported', ], true); diff --git a/plugins/password/drivers/ldap_ppolicy.php b/plugins/password/drivers/ldap_ppolicy.php index 214cd3bfb..4a30650be 100644 --- a/plugins/password/drivers/ldap_ppolicy.php +++ b/plugins/password/drivers/ldap_ppolicy.php @@ -87,7 +87,7 @@ class rcube_ldap_ppolicy_password return PASSWORD_CONNECT_ERROR; default: rcube::raise_error([ - 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 600, 'message' => "Password plugin: Failed to execute command: {$cmd}. Output: {$result}. Error: {$stderr}", ], true, false); } diff --git a/plugins/password/drivers/ldap_samba_ad.php b/plugins/password/drivers/ldap_samba_ad.php index 63d51421d..8094a6d3e 100644 --- a/plugins/password/drivers/ldap_samba_ad.php +++ b/plugins/password/drivers/ldap_samba_ad.php @@ -36,8 +36,8 @@ class rcube_ldap_samba_ad_password extends rcube_ldap_simple_password { if (!function_exists('ldap_mod_replace')) { rcube::raise_error([ - 'code' => 100, 'type' => 'ldap', - 'file' => __FILE__, 'line' => __LINE__, + 'code' => 100, + 'type' => 'ldap', 'message' => 'ldap_mod_replace() not supported', ], true); diff --git a/plugins/password/drivers/ldap_simple.php b/plugins/password/drivers/ldap_simple.php index 3c96e0996..b5ff6a4ea 100644 --- a/plugins/password/drivers/ldap_simple.php +++ b/plugins/password/drivers/ldap_simple.php @@ -130,8 +130,8 @@ class rcube_ldap_simple_password $this->_debug('S: NOT OK'); rcube::raise_error([ - 'code' => 100, 'type' => 'ldap', - 'file' => __FILE__, 'line' => __LINE__, + 'code' => 100, + 'type' => 'ldap', 'message' => 'Could not connect to LDAP server', ], true); diff --git a/plugins/password/drivers/mailcow.php b/plugins/password/drivers/mailcow.php index 7fe52b8bc..642c9a2f1 100644 --- a/plugins/password/drivers/mailcow.php +++ b/plugins/password/drivers/mailcow.php @@ -71,7 +71,7 @@ class rcube_mailcow_password } rcube::raise_error([ - 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 600, 'message' => "Password plugin: Problem with Mailcow API: {$result}", ], true, false); diff --git a/plugins/password/drivers/miab.php b/plugins/password/drivers/miab.php index 0109547a1..7e16c0c7e 100644 --- a/plugins/password/drivers/miab.php +++ b/plugins/password/drivers/miab.php @@ -65,7 +65,7 @@ class rcube_miab_password } rcube::raise_error([ - 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 600, 'message' => "Password plugin: Unable to change password. {$result}", ], true, false); diff --git a/plugins/password/drivers/pam.php b/plugins/password/drivers/pam.php index 93cd40935..aada15138 100644 --- a/plugins/password/drivers/pam.php +++ b/plugins/password/drivers/pam.php @@ -37,16 +37,12 @@ class rcube_pam_password } else { rcube::raise_error([ 'code' => 600, - 'file' => __FILE__, - 'line' => __LINE__, 'message' => "Password plugin: PAM authentication failed for user {$username}: {$error}", ], true, false); } } else { rcube::raise_error([ 'code' => 600, - 'file' => __FILE__, - 'line' => __LINE__, 'message' => 'Password plugin: PECL-PAM module not loaded', ], true, false); } diff --git a/plugins/password/drivers/pw_usermod.php b/plugins/password/drivers/pw_usermod.php index 04ef5f8c8..562a31d16 100644 --- a/plugins/password/drivers/pw_usermod.php +++ b/plugins/password/drivers/pw_usermod.php @@ -45,8 +45,6 @@ class rcube_pw_usermod_password rcube::raise_error([ 'code' => 600, - 'file' => __FILE__, - 'line' => __LINE__, 'message' => "Password plugin: Unable to execute {$cmd}", ], true, false); diff --git a/plugins/password/drivers/pwned.php b/plugins/password/drivers/pwned.php index 11b3fdb9a..b61442a74 100644 --- a/plugins/password/drivers/pwned.php +++ b/plugins/password/drivers/pwned.php @@ -157,8 +157,6 @@ class rcube_pwned_password } catch (Exception $e) { rcube::raise_error([ 'message' => "Error fetching {$url} : {$e->getMessage()}", - 'file' => __FILE__, - 'line' => __LINE__, ], true, false); } diff --git a/plugins/password/drivers/sasl.php b/plugins/password/drivers/sasl.php index a4481cd55..49b556513 100644 --- a/plugins/password/drivers/sasl.php +++ b/plugins/password/drivers/sasl.php @@ -51,8 +51,6 @@ class rcube_sasl_password rcube::raise_error([ 'code' => 600, - 'file' => __FILE__, - 'line' => __LINE__, 'message' => "Password plugin: Unable to execute {$curdir}/chgsaslpasswd", ], true, false); diff --git a/plugins/password/drivers/smb.php b/plugins/password/drivers/smb.php index 0a7676c6a..8d3c96a3a 100644 --- a/plugins/password/drivers/smb.php +++ b/plugins/password/drivers/smb.php @@ -61,8 +61,6 @@ class rcube_smb_password rcube::raise_error([ 'code' => 600, - 'file' => __FILE__, - 'line' => __LINE__, 'message' => "Password plugin: Unable to execute {$cmd}", ], true, false); diff --git a/plugins/password/drivers/tinycp.php b/plugins/password/drivers/tinycp.php index 6fd5ecea6..cacdff6e3 100644 --- a/plugins/password/drivers/tinycp.php +++ b/plugins/password/drivers/tinycp.php @@ -53,7 +53,7 @@ class rcube_tinycp_password if ($error_message) { rcube::raise_error([ - 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 600, 'message' => "Password driver: {$error_message}", ], true, false); diff --git a/plugins/password/drivers/virtualmin.php b/plugins/password/drivers/virtualmin.php index bc9ff97b8..ac6d81c99 100644 --- a/plugins/password/drivers/virtualmin.php +++ b/plugins/password/drivers/virtualmin.php @@ -45,8 +45,6 @@ class rcube_virtualmin_password } else { rcube::raise_error([ 'code' => 600, - 'file' => __FILE__, - 'line' => __LINE__, 'message' => "Password plugin: Unable to execute {$curdir}/chgvirtualminpasswd " . "or domain for mail-user '{$username}' not known to Virtualmin", ], true, false); @@ -65,8 +63,6 @@ class rcube_virtualmin_password rcube::raise_error([ 'code' => 600, - 'file' => __FILE__, - 'line' => __LINE__, 'message' => "Password plugin: Unable to execute {$curdir}/chgvirtualminpasswd", ], true, false); diff --git a/plugins/password/drivers/xmail.php b/plugins/password/drivers/xmail.php index d409863d4..57bb0eb7f 100644 --- a/plugins/password/drivers/xmail.php +++ b/plugins/password/drivers/xmail.php @@ -50,8 +50,6 @@ class rcube_xmail_password if (!$xmail->connect()) { rcube::raise_error([ 'code' => 600, - 'file' => __FILE__, - 'line' => __LINE__, 'message' => 'Password plugin: Unable to connect to mail server', ], true, false); @@ -62,8 +60,6 @@ class rcube_xmail_password $xmail->close(); rcube::raise_error([ 'code' => 600, - 'file' => __FILE__, - 'line' => __LINE__, 'message' => 'Password plugin: Unable to change password', ], true, false); diff --git a/plugins/password/drivers/zxcvbn.php b/plugins/password/drivers/zxcvbn.php index b4003187e..bde7f5227 100644 --- a/plugins/password/drivers/zxcvbn.php +++ b/plugins/password/drivers/zxcvbn.php @@ -52,8 +52,6 @@ class rcube_zxcvbn_password if (!class_exists('ZxcvbnPhp\Zxcvbn')) { rcube::raise_error([ 'code' => 600, - 'file' => __FILE__, - 'line' => __LINE__, 'message' => 'Password plugin: Zxcvbn library not found.', ], true, true); } diff --git a/plugins/password/password.php b/plugins/password/password.php index cf7674128..2a0429aa2 100644 --- a/plugins/password/password.php +++ b/plugins/password/password.php @@ -433,7 +433,7 @@ class password extends rcube_plugin if (!file_exists($file)) { rcube::raise_error([ - 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 600, 'message' => "Password plugin: Driver file does not exist ({$file})", ], true, false); return false; @@ -443,7 +443,7 @@ class password extends rcube_plugin if (!class_exists($class, false) || (!method_exists($class, 'save') && !method_exists($class, 'check_strength'))) { rcube::raise_error([ - 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 600, 'message' => "Password plugin: Broken driver {$driver}", ], true, false); return false; @@ -582,7 +582,7 @@ class password extends rcube_plugin $crypted = hash('sha1', $password, true); } else { rcube::raise_error([ - 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 600, 'message' => 'Password plugin: Your PHP installation does not have the hash() nor sha1() function', ], true, true); } @@ -601,7 +601,7 @@ class password extends rcube_plugin $crypted = hash('sha1', $password . $salt, true); } else { rcube::raise_error([ - 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 600, 'message' => 'Password plugin: Your PHP installation does not have the hash() nor sha1() function', ], true, true); } @@ -618,7 +618,7 @@ class password extends rcube_plugin $crypted = hash('sha256', $password . $salt, true); } else { rcube::raise_error([ - 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 600, 'message' => 'Password plugin: Your PHP installation does not have the hash() function', ], true, true); } @@ -634,7 +634,7 @@ class password extends rcube_plugin $crypted = hash('sha512', $password . $salt, true); } else { rcube::raise_error([ - 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 600, 'message' => 'Password plugin: Your PHP installation does not have the hash() function', ], true, true); } @@ -662,7 +662,7 @@ class password extends rcube_plugin $crypted = strtoupper($crypted); } else { rcube::raise_error([ - 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 600, 'message' => 'Password plugin: Your PHP installation does not have hash() function', ], true, true); } @@ -686,7 +686,7 @@ class password extends rcube_plugin if (!$pipe) { rcube::raise_error([ - 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 600, 'message' => "Password plugin: Failed to execute command: {$command}", ], true, true); } @@ -705,7 +705,7 @@ class password extends rcube_plugin if (!preg_match('/^\{' . $method . '\}/', $crypted)) { rcube::raise_error([ - 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 600, 'message' => "Password plugin: Failed to execute command: {$command}. Error: {$stderr}", ], true, true); } @@ -738,7 +738,7 @@ class password extends rcube_plugin break; default: rcube::raise_error([ - 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 600, 'message' => 'Password plugin: Hash method not supported.', ], true, true); } @@ -746,7 +746,7 @@ class password extends rcube_plugin // @phpstan-ignore-next-line if ($crypted === null || $crypted === '' || $crypted === false) { rcube::raise_error([ - 'code' => 600, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 600, 'message' => "Password plugin: Failed to hash password ({$method}). Check for configuration issues.", ], true, true); } diff --git a/plugins/zipdownload/zipdownload.php b/plugins/zipdownload/zipdownload.php index 027409af3..75048ff14 100644 --- a/plugins/zipdownload/zipdownload.php +++ b/plugins/zipdownload/zipdownload.php @@ -32,8 +32,6 @@ class zipdownload extends rcube_plugin if (!class_exists('ZipArchive', false)) { rcmail::raise_error([ 'code' => 520, - 'file' => __FILE__, - 'line' => __LINE__, 'message' => 'php-zip extension is required for the zipdownload plugin', ], true, false); return; diff --git a/program/actions/login/oauth_backchannel.php b/program/actions/login/oauth_backchannel.php index 7d7c2245d..b94649c87 100644 --- a/program/actions/login/oauth_backchannel.php +++ b/program/actions/login/oauth_backchannel.php @@ -73,16 +73,12 @@ class rcmail_action_login_oauth_backchannel extends rcmail_action } catch (Exception $e) { rcube::raise_error([ 'message' => $e->getMessage(), - 'file' => __FILE__, - 'line' => __LINE__, ], true, false); $answer['error_description'] = 'Error decoding JWT'; } } else { rcube::raise_error([ 'message' => sprintf('oidc backchannel called from %s without any parameter', rcube_utils::remote_addr()), - 'file' => __FILE__, - 'line' => __LINE__, ], true, false); } diff --git a/program/actions/mail/compose.php b/program/actions/mail/compose.php index d0087a4e4..ef479bb4f 100644 --- a/program/actions/mail/compose.php +++ b/program/actions/mail/compose.php @@ -66,7 +66,9 @@ class rcmail_action_mail_compose extends rcmail_action_mail_index !isset($_SESSION['last_compose_session']) || self::$COMPOSE_ID != $_SESSION['last_compose_session'] ) { - rcube::raise_error(['code' => 450], false, true); + rcube::raise_error([ + 'code' => 450, + ], false, true); } } @@ -496,7 +498,7 @@ class rcmail_action_mail_compose extends rcmail_action_mail_index if (empty($spellcheck_langs)) { if ($err = $spellchecker->error()) { rcube::raise_error([ - 'code' => 500, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 500, 'message' => 'Spell check engine error: ' . trim($err), ], true, false); } diff --git a/program/actions/mail/send.php b/program/actions/mail/send.php index d6647cca4..77b604b09 100644 --- a/program/actions/mail/send.php +++ b/program/actions/mail/send.php @@ -40,8 +40,6 @@ class rcmail_action_mail_send extends rcmail_action if (!isset($COMPOSE['id'])) { rcube::raise_error([ 'code' => 500, - 'file' => __FILE__, - 'line' => __LINE__, 'message' => 'Invalid compose ID', ], true, false); @@ -131,8 +129,6 @@ class rcmail_action_mail_send extends rcmail_action ); rcube_utils::preg_error([ - 'line' => __LINE__, - 'file' => __FILE__, 'message' => 'Could not format HTML!', ], true); } @@ -151,7 +147,7 @@ class rcmail_action_mail_send extends rcmail_action if ($error = $spellchecker->error()) { rcube::raise_error([ - 'code' => 500, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 500, 'message' => 'Spellcheck error: ' . $error, ], true, false); } else { @@ -249,8 +245,6 @@ class rcmail_action_mail_send extends rcmail_action rcube::raise_error([ 'code' => 800, 'type' => 'imap', - 'file' => __FILE__, - 'line' => __LINE__, 'message' => "Could not delete message from {$drafts_mbox}", ], true, false); } @@ -362,8 +356,6 @@ class rcmail_action_mail_send extends rcmail_action $message_body = preg_replace($dispurl, '"cid:' . $cid . '"', $message_body); rcube_utils::preg_error([ - 'line' => __LINE__, - 'file' => __FILE__, 'message' => 'Could not replace an image reference!', ], true); diff --git a/program/actions/mail/viewsource.php b/program/actions/mail/viewsource.php index bac5ad931..370590750 100644 --- a/program/actions/mail/viewsource.php +++ b/program/actions/mail/viewsource.php @@ -75,8 +75,6 @@ class rcmail_action_mail_viewsource extends rcmail_action } else { rcube::raise_error([ 'code' => 500, - 'file' => __FILE__, - 'line' => __LINE__, 'message' => "Message UID {$uid} not found", ], true, true); } diff --git a/program/actions/utils/save_pref.php b/program/actions/utils/save_pref.php index adb0f4748..567e94acf 100644 --- a/program/actions/utils/save_pref.php +++ b/program/actions/utils/save_pref.php @@ -52,8 +52,6 @@ class rcmail_action_utils_save_pref extends rcmail_action if (!in_array($name, $whitelist) || ($sessname && !in_array($sessname, $whitelist_sess))) { rcube::raise_error([ 'code' => 500, - 'file' => __FILE__, - 'line' => __LINE__, 'message' => sprintf('Hack attempt detected (user: %s)', $rcmail->get_user_name()), ], true, false); diff --git a/program/actions/utils/spell.php b/program/actions/utils/spell.php index 1b67f4891..dc5f55cd2 100644 --- a/program/actions/utils/spell.php +++ b/program/actions/utils/spell.php @@ -56,8 +56,6 @@ class rcmail_action_utils_spell extends rcmail_action if ($error = $spellchecker->error()) { rcube::raise_error([ 'code' => 500, - 'file' => __FILE__, - 'line' => __LINE__, 'message' => 'Spellcheck error: ' . $error, ], true, false); diff --git a/program/actions/utils/spell_html.php b/program/actions/utils/spell_html.php index 9baa0ba29..614735cb1 100644 --- a/program/actions/utils/spell_html.php +++ b/program/actions/utils/spell_html.php @@ -56,8 +56,6 @@ class rcmail_action_utils_spell_html extends rcmail_action if ($error = $spellchecker->error()) { rcube::raise_error([ 'code' => 500, - 'file' => __FILE__, - 'line' => __LINE__, 'message' => 'Spellcheck error: ' . $error, ], true, false); diff --git a/program/include/rcmail.php b/program/include/rcmail.php index ad24efa5c..de332923b 100644 --- a/program/include/rcmail.php +++ b/program/include/rcmail.php @@ -289,7 +289,7 @@ class rcmail extends rcube $this->output->send($this->task); // if we arrive here, something went wrong - $error = ['code' => 404, 'line' => __LINE__, 'file' => __FILE__, 'message' => 'Invalid request']; + $error = ['code' => 404, 'message' => 'Invalid request']; self::raise_error($error, true, true); } @@ -369,8 +369,6 @@ class rcmail extends rcube self::raise_error([ 'code' => 700, - 'file' => __FILE__, - 'line' => __LINE__, 'message' => "Addressbook source ({$id}) not found!", ], true, true); } @@ -795,16 +793,12 @@ class rcmail extends rcube if (!$user) { self::raise_error([ 'code' => 620, - 'file' => __FILE__, - 'line' => __LINE__, 'message' => 'Failed to create a user record. Maybe aborted by a plugin?', ], true, false); } } else { self::raise_error([ 'code' => 621, - 'file' => __FILE__, - 'line' => __LINE__, 'message' => "Access denied for new user {$username}. 'auto_create_user' is disabled", ], true, false); } diff --git a/program/include/rcmail_attachment_handler.php b/program/include/rcmail_attachment_handler.php index 1426579c6..c30a5e8bf 100644 --- a/program/include/rcmail_attachment_handler.php +++ b/program/include/rcmail_attachment_handler.php @@ -357,7 +357,7 @@ class rcmail_attachment_handler header('Location: ' . $_SERVER['REQUEST_URI'] . '&_redirected=1'); } else { rcube::raise_error([ - 'code' => 500, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 500, 'message' => 'Unable to get/display message part. IMAP connection error', ], true, true); } diff --git a/program/include/rcmail_oauth.php b/program/include/rcmail_oauth.php index 67b670e41..2c7df80ec 100644 --- a/program/include/rcmail_oauth.php +++ b/program/include/rcmail_oauth.php @@ -182,8 +182,6 @@ class rcmail_oauth // will stops on error rcube::raise_error([ 'message' => "PKCE method not supported (oauth_pkce='{$this->options['pkce']}')", - 'file' => __FILE__, - 'line' => __LINE__, ], true, true); } @@ -193,8 +191,6 @@ class rcmail_oauth // will stops on error rcube::raise_error([ 'message' => "use of key `{$key}` in `oauth_user_create_map` is not allowed", - 'file' => __FILE__, - 'line' => __LINE__, ], true, true); } } @@ -244,8 +240,6 @@ class rcmail_oauth if (empty($data[$config_key])) { rcube::raise_error([ 'message' => "key {$config_key} not found in answer of {$config_uri}", - 'file' => __FILE__, - 'line' => __LINE__, ], true, false); } else { $this->options[$options_key] = $data[$config_key]; @@ -257,16 +251,12 @@ class rcmail_oauth if (!in_array($this->options['pkce'], $data['code_challenge_methods_supported'])) { rcube::raise_error([ 'message' => "OAuth server does not support this PKCE method (oauth_pkce='{$this->options['pkce']}')", - 'file' => __FILE__, - 'line' => __LINE__, ], true, false); } } } catch (Exception $e) { rcube::raise_error([ 'message' => "Error fetching {$config_uri} : {$e->getMessage()}", - 'file' => __FILE__, - 'line' => __LINE__, ], true, false); } } @@ -499,8 +489,6 @@ class rcmail_oauth // log error about missing config options rcube::raise_error([ 'message' => "Missing required OAuth config options 'oauth_auth_uri', 'oauth_client_id'", - 'file' => __FILE__, - 'line' => __LINE__, ], true, false); return; } @@ -686,8 +674,6 @@ class rcmail_oauth rcube::raise_error([ 'message' => $this->last_error . '; ' . $formatter->format($e->getRequest(), $e->getResponse()), - 'file' => __FILE__, - 'line' => __LINE__, ], true, false); } catch (Exception $e) { $this->last_error = 'OAuth token request failed: ' . $e->getMessage(); @@ -695,8 +681,6 @@ class rcmail_oauth rcube::raise_error([ 'message' => $this->last_error, - 'file' => __FILE__, - 'line' => __LINE__, ], true, false); } @@ -760,8 +744,6 @@ class rcmail_oauth $formatter = new MessageFormatter(); rcube::raise_error([ 'message' => $this->last_error . '; ' . $formatter->format($e->getRequest(), $e->getResponse()), - 'file' => __FILE__, - 'line' => __LINE__, ], true, false); // refrehsing token failed, mark session as expired @@ -772,8 +754,6 @@ class rcmail_oauth $this->last_error = 'OAuth refresh token request failed: ' . $e->getMessage(); rcube::raise_error([ 'message' => $this->last_error, - 'file' => __FILE__, - 'line' => __LINE__, ], true, false); } @@ -790,7 +770,9 @@ class rcmail_oauth public function schedule_token_revocation($sub): void { if ($this->cache === null) { - rcube::raise_error(['message' => 'received a token revocation request, you must activate `oauth_cache` to enable this feature'], true, false); + rcube::raise_error([ + 'message' => 'received a token revocation request, you must activate `oauth_cache` to enable this feature', + ], true, false); return; } $this->cache->set("revoke_{$sub}", time()); @@ -1157,8 +1139,6 @@ class rcmail_oauth if (!rcube_utils::check_email($value, false)) { rcube::raise_error([ 'message' => "user_create: ignoring invalid email '{$value}' (from claim '{$oidc_claim}')", - 'file' => __FILE__, - 'line' => __LINE__, ], true, false); continue 2; // continue on next foreach iteration } @@ -1171,8 +1151,6 @@ class rcmail_oauth if (!preg_match('/^[a-z0-9_]{2,8}$/i', $value)) { rcube::raise_error([ 'message' => "user_create: ignoring language '{$value}' (from claim '{$oidc_claim}')", - 'file' => __FILE__, - 'line' => __LINE__, ], true, false); continue 2; // continue on next foreach iteration } diff --git a/program/include/rcmail_output_html.php b/program/include/rcmail_output_html.php index 5db6a0586..deb15e60c 100644 --- a/program/include/rcmail_output_html.php +++ b/program/include/rcmail_output_html.php @@ -321,8 +321,6 @@ class rcmail_output_html extends rcmail_output // @phpstan-ignore-next-line if (!is_string($skin) || strpos($skin, '/') !== false || strpos($skin, '\\') !== false) { rcube::raise_error([ - 'file' => __FILE__, - 'line' => __LINE__, 'message' => 'Invalid skin name', ], true, false); @@ -642,8 +640,6 @@ class rcmail_output_html extends rcmail_output if ($exit != 'recur' && $this->app->plugins->is_processing('render_page')) { rcube::raise_error([ 'code' => 505, - 'file' => __FILE__, - 'line' => __LINE__, 'message' => 'Recursion alert: ignoring output->send()', ], true, false); @@ -776,7 +772,7 @@ class rcmail_output_html extends rcmail_output if (is_readable($path)) { rcube::raise_error([ - 'code' => 502, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 502, 'message' => "Using deprecated template '{$dname}' in {$skin_path}/templates. Please rename to '{$realname}'", ], true, false); } @@ -797,8 +793,6 @@ class rcmail_output_html extends rcmail_output if (!$path || ($templ = @file_get_contents($path)) === false) { rcube::raise_error([ 'code' => 404, - 'line' => __LINE__, - 'file' => __FILE__, 'message' => 'Error loading template for ' . $realname, ], true, $write); diff --git a/program/include/rcmail_sendmail.php b/program/include/rcmail_sendmail.php index 699ab043f..aa0f0f865 100644 --- a/program/include/rcmail_sendmail.php +++ b/program/include/rcmail_sendmail.php @@ -552,7 +552,7 @@ class rcmail_sendmail if (is_a($msg, 'PEAR_Error')) { rcube::raise_error([ - 'code' => 650, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 650, 'message' => 'Could not create message: ' . $msg->getMessage(), ], true, false); } else { @@ -563,8 +563,9 @@ class rcmail_sendmail // raise error if saving failed if (!$saved) { - rcube::raise_error(['code' => 800, 'type' => 'imap', - 'file' => __FILE__, 'line' => __LINE__, + rcube::raise_error([ + 'code' => 800, + 'type' => 'imap', 'message' => "Could not save message in {$store_target}", ], true, false); } diff --git a/program/lib/Roundcube/db/sqlite.php b/program/lib/Roundcube/db/sqlite.php index c783e38f5..b2c8fe056 100644 --- a/program/lib/Roundcube/db/sqlite.php +++ b/program/lib/Roundcube/db/sqlite.php @@ -62,8 +62,8 @@ class rcube_db_sqlite extends rcube_db $this->db_error_msg = sprintf('[%s] %s', $error[1], $error[2]); rcube::raise_error([ - 'code' => 500, 'type' => 'db', - 'line' => __LINE__, 'file' => __FILE__, + 'code' => 500, + 'type' => 'db', 'message' => $this->db_error_msg, ], true, false); } diff --git a/program/lib/Roundcube/rcube.php b/program/lib/Roundcube/rcube.php index 58ed30f9b..69354e038 100644 --- a/program/lib/Roundcube/rcube.php +++ b/program/lib/Roundcube/rcube.php @@ -321,7 +321,7 @@ class rcube if (!class_exists($driver_class)) { self::raise_error([ - 'code' => 700, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 700, 'message' => "Storage driver class ({$driver}) not found!", ], true, true); } @@ -919,8 +919,6 @@ class rcube if ($cipher === false) { self::raise_error([ - 'file' => __FILE__, - 'line' => __LINE__, 'message' => "Failed to encrypt data with configured cipher method: {$method}!", ], true, false); @@ -1420,6 +1418,15 @@ class rcube $arg['code'] = 500; } + $prevStackFrame = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0]; + if ( + !isset($arg['file']) && isset($prevStackFrame['file']) + && !isset($arg['line']) && isset($prevStackFrame['line']) + ) { + $arg['file'] = $prevStackFrame['file']; + $arg['line'] = $prevStackFrame['line']; + } + $cli = \PHP_SAPI == 'cli'; $arg['cli'] = $cli; @@ -1789,7 +1796,7 @@ class rcube if (is_a($mime_result, 'PEAR_Error')) { self::raise_error([ - 'code' => 650, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 650, 'message' => 'Could not create message: ' . $mime_result->getMessage(), ], true, false); return false; @@ -1813,7 +1820,6 @@ class rcube if (!$sent) { self::raise_error([ 'code' => 800, 'type' => 'smtp', - 'line' => __LINE__, 'file' => __FILE__, 'message' => implode("\n", $response), ], true, false); diff --git a/program/lib/Roundcube/rcube_cache.php b/program/lib/Roundcube/rcube_cache.php index 48f5a861c..28f24d137 100644 --- a/program/lib/Roundcube/rcube_cache.php +++ b/program/lib/Roundcube/rcube_cache.php @@ -67,8 +67,8 @@ class rcube_cache if (!class_exists($class)) { rcube::raise_error([ - 'code' => 600, 'type' => 'db', - 'line' => __LINE__, 'file' => __FILE__, + 'code' => 600, + 'type' => 'db', 'message' => "Configuration error. Unsupported cache driver: {$driver}", ], true, true); } diff --git a/program/lib/Roundcube/rcube_config.php b/program/lib/Roundcube/rcube_config.php index beb63c1f9..d58131311 100644 --- a/program/lib/Roundcube/rcube_config.php +++ b/program/lib/Roundcube/rcube_config.php @@ -544,7 +544,7 @@ class rcube_config // Bomb out if the requested key does not exist if (!array_key_exists($key, $this->prop) || empty($this->prop[$key])) { rcube::raise_error([ - 'code' => 500, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 500, 'message' => "Request for unconfigured crypto key \"{$key}\"", ], true, true); } @@ -579,7 +579,7 @@ class rcube_config } rcube::raise_error([ - 'code' => 500, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 500, 'message' => 'Invalid mail_header_delimiter setting', ], true, false); } diff --git a/program/lib/Roundcube/rcube_db.php b/program/lib/Roundcube/rcube_db.php index b799d6770..dfb19bd8a 100644 --- a/program/lib/Roundcube/rcube_db.php +++ b/program/lib/Roundcube/rcube_db.php @@ -85,8 +85,8 @@ class rcube_db if (!$driver || !class_exists($class)) { rcube::raise_error([ - 'code' => 600, 'type' => 'db', - 'line' => __LINE__, 'file' => __FILE__, + 'code' => 600, + 'type' => 'db', 'message' => "Configuration error. Unsupported database driver: {$driver}", ], true, true); } @@ -186,8 +186,8 @@ class rcube_db $this->db_error_msg = $e->getMessage(); rcube::raise_error([ - 'code' => 500, 'type' => 'db', - 'line' => __LINE__, 'file' => __FILE__, + 'code' => 500, + 'type' => 'db', 'message' => $this->db_error_msg, ], true, false); @@ -553,7 +553,8 @@ class rcube_db if (empty($this->options['ignore_errors'])) { rcube::raise_error([ - 'code' => 500, 'type' => 'db', 'line' => __LINE__, 'file' => __FILE__, + 'code' => 500, + 'type' => 'db', 'message' => $this->db_error_msg . " (SQL Query: {$query})", ], true, false); } diff --git a/program/lib/Roundcube/rcube_imap.php b/program/lib/Roundcube/rcube_imap.php index 17a10598e..38a7eb23b 100644 --- a/program/lib/Roundcube/rcube_imap.php +++ b/program/lib/Roundcube/rcube_imap.php @@ -108,8 +108,8 @@ class rcube_imap extends rcube_storage $this->options['ssl_mode'] = $use_ssl == 'imaps' ? 'ssl' : $use_ssl; } elseif ($use_ssl) { rcube::raise_error([ - 'code' => 403, 'type' => 'imap', - 'file' => __FILE__, 'line' => __LINE__, + 'code' => 403, + 'type' => 'imap', 'message' => 'OpenSSL not available', ], true, false); @@ -194,8 +194,8 @@ class rcube_imap extends rcube_storage $user, $host, rcube_utils::remote_ip(), $this->conn->error); rcube::raise_error([ - 'code' => 403, 'type' => 'imap', - 'file' => __FILE__, 'line' => __LINE__, + 'code' => 403, + 'type' => 'imap', 'message' => $message, ], true, false); } diff --git a/program/lib/Roundcube/rcube_ldap.php b/program/lib/Roundcube/rcube_ldap.php index e85ca7104..3b3a7b50d 100644 --- a/program/lib/Roundcube/rcube_ldap.php +++ b/program/lib/Roundcube/rcube_ldap.php @@ -428,8 +428,8 @@ class rcube_ldap extends rcube_addressbook $replaces['%dn'] = $conf['search_dn_default']; } else { rcube::raise_error([ - 'code' => 100, 'type' => 'ldap', - 'file' => __FILE__, 'line' => __LINE__, + 'code' => 100, + 'type' => 'ldap', 'message' => 'DN not found using LDAP search.', ], true); continue; @@ -494,8 +494,8 @@ class rcube_ldap extends rcube_addressbook if (empty($this->ldap->conn)) { rcube::raise_error([ - 'code' => 100, 'type' => 'ldap', - 'file' => __FILE__, 'line' => __LINE__, + 'code' => 100, + 'type' => 'ldap', 'message' => 'Could not connect to any LDAP server', ], true); @@ -1573,7 +1573,7 @@ class rcube_ldap extends rcube_addressbook if ($res === false) { rcube::raise_error([ - 'code' => 505, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 505, 'message' => "Expression parse error on: ({$code})", ], true, false); continue; diff --git a/program/lib/Roundcube/rcube_plugin.php b/program/lib/Roundcube/rcube_plugin.php index 9caa528ed..c5996daf3 100644 --- a/program/lib/Roundcube/rcube_plugin.php +++ b/program/lib/Roundcube/rcube_plugin.php @@ -159,7 +159,7 @@ abstract class rcube_plugin if (($is_local = is_file($fpath)) && !$rcube->config->load_from_file($fpath)) { rcube::raise_error([ - 'code' => 527, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 527, 'message' => "Failed to load config from {$fpath}", ], true, false); return false; diff --git a/program/lib/Roundcube/rcube_plugin_api.php b/program/lib/Roundcube/rcube_plugin_api.php index 831f5c0cc..e1e981b4c 100644 --- a/program/lib/Roundcube/rcube_plugin_api.php +++ b/program/lib/Roundcube/rcube_plugin_api.php @@ -140,7 +140,7 @@ class rcube_plugin_api // trigger fatal error if still not loaded if (!$loaded) { rcube::raise_error([ - 'code' => 520, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 520, 'message' => "Required plugin {$plugin_name} was not loaded", ], true, true); } @@ -168,7 +168,7 @@ class rcube_plugin_api // Validate the plugin name to prevent from path traversal if (preg_match('/[^a-zA-Z0-9_-]/', $plugin_name)) { rcube::raise_error([ - 'code' => 520, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 520, 'message' => "Invalid plugin name: {$plugin_name}", ], true, false); @@ -182,7 +182,7 @@ class rcube_plugin_api if (!is_readable($fn)) { if ($require) { rcube::raise_error([ - 'code' => 520, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 520, 'message' => "Failed to load plugin file {$fn}", ], true, false); } @@ -197,7 +197,7 @@ class rcube_plugin_api // instantiate class if exists if (!class_exists($plugin_name, false)) { rcube::raise_error([ - 'code' => 520, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 520, 'message' => "No plugin class {$plugin_name} found in {$fn}", ], true, false); @@ -299,7 +299,7 @@ class rcube_plugin_api // Validate the plugin name to prevent from path traversal if (preg_match('/[^a-zA-Z0-9_-]/', $plugin_name)) { rcube::raise_error([ - 'code' => 520, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 520, 'message' => "Invalid plugin name: {$plugin_name}", ], true, false); @@ -440,7 +440,7 @@ class rcube_plugin_api if (is_callable($callback)) { if (isset($this->deprecated_hooks[$hook])) { rcube::raise_error([ - 'code' => 522, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 522, 'message' => "Deprecated hook name. {$hook} -> " . $this->deprecated_hooks[$hook], ], true, false); $hook = $this->deprecated_hooks[$hook]; @@ -448,7 +448,7 @@ class rcube_plugin_api $this->handlers[$hook][] = $callback; } else { rcube::raise_error([ - 'code' => 521, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 521, 'message' => "Invalid callback function for {$hook}", ], true, false); } @@ -531,7 +531,7 @@ class rcube_plugin_api $this->actionmap[$action] = $owner; } else { rcube::raise_error([ - 'code' => 523, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 523, 'message' => "Cannot register action {$action}; already taken by another plugin", ], true, false); } @@ -553,7 +553,7 @@ class rcube_plugin_api call_user_func($this->actions[$action]); } elseif ($rcmail->action != 'refresh') { rcube::raise_error([ - 'code' => 524, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 524, 'message' => "No handler found for action {$action}", ], true, true); } @@ -581,7 +581,7 @@ class rcube_plugin_api $this->objectsmap[$name] = $owner; } else { rcube::raise_error([ - 'code' => 525, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 525, 'message' => "Cannot register template handler {$name};" . ' already taken by another plugin or no output object available', ], true, false); @@ -603,13 +603,13 @@ class rcube_plugin_api if ($task != asciiwords($task, true)) { rcube::raise_error([ - 'code' => 526, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 526, 'message' => "Invalid task name: {$task}." . ' Only characters [a-z0-9_.-] are allowed', ], true, false); } elseif (in_array($task, rcmail::$main_tasks)) { rcube::raise_error([ - 'code' => 526, 'file' => __FILE__, 'line' => __LINE__, + 'code' => 526, 'message' => "Cannot register task {$task};" . ' already taken by another plugin or the application itself', ], true, false); diff --git a/program/lib/Roundcube/rcube_session.php b/program/lib/Roundcube/rcube_session.php index 530b44d7b..2ee5793d4 100644 --- a/program/lib/Roundcube/rcube_session.php +++ b/program/lib/Roundcube/rcube_session.php @@ -69,8 +69,8 @@ abstract class rcube_session implements SessionHandlerInterface if (!class_exists($class)) { rcube::raise_error([ - 'code' => 604, 'type' => 'session', - 'line' => __LINE__, 'file' => __FILE__, + 'code' => 604, + 'type' => 'session', 'message' => 'Failed to find session driver. Check session_storage config option', ], true, true); } diff --git a/program/lib/Roundcube/rcube_tnef_decoder.php b/program/lib/Roundcube/rcube_tnef_decoder.php index 4a92de87c..9f0aa1946 100644 --- a/program/lib/Roundcube/rcube_tnef_decoder.php +++ b/program/lib/Roundcube/rcube_tnef_decoder.php @@ -178,8 +178,6 @@ class rcube_tnef_decoder } catch (Exception $e) { // ignore the body rcube::raise_error([ - 'file' => __FILE__, - 'line' => __LINE__, 'message' => 'Failed to extract RTF/HTML content from TNEF attachment', ], true, false); } diff --git a/program/lib/Roundcube/rcube_user.php b/program/lib/Roundcube/rcube_user.php index 2bf2ad617..85736a480 100644 --- a/program/lib/Roundcube/rcube_user.php +++ b/program/lib/Roundcube/rcube_user.php @@ -721,7 +721,7 @@ class rcube_user } } else { rcube::raise_error([ - 'code' => 500, 'line' => __LINE__, 'file' => __FILE__, + 'code' => 500, 'message' => 'Failed to create new user', ], true, false); } diff --git a/program/lib/Roundcube/rcube_utils.php b/program/lib/Roundcube/rcube_utils.php index 92dc3a040..199e38d5d 100644 --- a/program/lib/Roundcube/rcube_utils.php +++ b/program/lib/Roundcube/rcube_utils.php @@ -809,7 +809,6 @@ class rcube_utils } $rcube->raise_error([ - 'file' => __FILE__, 'line' => __LINE__, 'message' => "Specified host is not trusted. Using 'localhost'.", ], true, false); } @@ -1578,7 +1577,18 @@ class rcube_utils $errstr .= ' Consider raising pcre.recursion_limit!'; } - $error = array_merge(['code' => 620, 'line' => __LINE__, 'file' => __FILE__], $error); + if (!isset($error['code'])) { + $error['code'] = 620; + } + + $prevStackFrame = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0]; + if ( + !isset($error['file']) && isset($prevStackFrame['file']) + && !isset($error['line']) && isset($prevStackFrame['line']) + ) { + $error['file'] = $prevStackFrame['file']; + $error['line'] = $prevStackFrame['line']; + } if (!empty($error['message'])) { $error['message'] .= ' ' . $errstr; diff --git a/program/lib/Roundcube/rcube_washtml.php b/program/lib/Roundcube/rcube_washtml.php index 204c753d1..c435f58b3 100644 --- a/program/lib/Roundcube/rcube_washtml.php +++ b/program/lib/Roundcube/rcube_washtml.php @@ -561,7 +561,7 @@ class rcube_washtml if (empty($this->max_nesting_level_error)) { $this->max_nesting_level_error = true; rcube::raise_error([ - 'code' => 500, 'line' => __LINE__, 'file' => __FILE__, + 'code' => 500, 'message' => "Maximum nesting level exceeded (xdebug.max_nesting_level={$this->max_nesting_level})", ], true, false); } @@ -746,7 +746,7 @@ class rcube_washtml $html = preg_replace($html_search, $html_replace, $html); - $err = ['line' => __LINE__, 'file' => __FILE__, 'message' => 'Could not clean up HTML!']; + $err = ['message' => 'Could not clean up HTML!']; if ($html === null && rcube_utils::preg_error($err)) { return ''; } diff --git a/program/lib/Roundcube/session/memcache.php b/program/lib/Roundcube/session/memcache.php index a498c86f4..668175c51 100644 --- a/program/lib/Roundcube/session/memcache.php +++ b/program/lib/Roundcube/session/memcache.php @@ -45,8 +45,8 @@ class rcube_session_memcache extends rcube_session if (!$this->memcache) { rcube::raise_error([ - 'code' => 604, 'type' => 'memcache', - 'line' => __LINE__, 'file' => __FILE__, + 'code' => 604, + 'type' => 'memcache', 'message' => 'Failed to connect to memcached. Please check configuration', ], true, true); } diff --git a/program/lib/Roundcube/session/memcached.php b/program/lib/Roundcube/session/memcached.php index a92dadf65..ca9926986 100644 --- a/program/lib/Roundcube/session/memcached.php +++ b/program/lib/Roundcube/session/memcached.php @@ -45,8 +45,8 @@ class rcube_session_memcached extends rcube_session if (!$this->memcache) { rcube::raise_error([ - 'code' => 604, 'type' => 'memcache', - 'line' => __LINE__, 'file' => __FILE__, + 'code' => 604, + 'type' => 'memcache', 'message' => 'Failed to connect to memcached. Please check configuration', ], true, true); } diff --git a/program/lib/Roundcube/session/redis.php b/program/lib/Roundcube/session/redis.php index acb103683..1f329483a 100644 --- a/program/lib/Roundcube/session/redis.php +++ b/program/lib/Roundcube/session/redis.php @@ -43,8 +43,8 @@ class rcube_session_redis extends rcube_session if (!$this->redis) { rcube::raise_error([ - 'code' => 604, 'type' => 'redis', - 'line' => __LINE__, 'file' => __FILE__, + 'code' => 604, + 'type' => 'redis', 'message' => 'Failed to connect to redis. Please check configuration', ], true, true); }