Skip to content

Commit

Permalink
Display error when Mantis log file is not writable
Browse files Browse the repository at this point in the history
Fixes #19642
  • Loading branch information
dregad committed Apr 1, 2019
1 parent c8d16e7 commit 6d288c6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions core/constant_inc.php
Expand Up @@ -259,6 +259,7 @@
define( 'ERROR_SPAM_SUSPECTED', 27 );
define( 'ERROR_FIELD_TOO_LONG', 28 );
define( 'ERROR_INVALID_FIELD_VALUE', 29 );
define( 'ERROR_LOGFILE_NOT_WRITABLE', 30 );

# ERROR_CONFIG_*
define( 'ERROR_CONFIG_OPT_NOT_FOUND', 100 );
Expand Down
21 changes: 20 additions & 1 deletion core/logging_api.php
Expand Up @@ -106,7 +106,26 @@ function log_event( $p_level, $p_msg ) {
case 'none':
break;
case 'file':
error_log( $t_php_event . PHP_EOL, 3, $t_modifiers );
if( isset( $t_modifiers ) ) {
# Detect if the log file is writable; if not, issue a one-time warning
static $s_log_writable = null;
if( $s_log_writable === null ) {
$s_log_writable = is_writable( $t_modifiers );
if( !$s_log_writable ) {
# Display warning message and write it in PHP system log as well.
# Note: to ensure the error is shown regardless of $g_display_error settings,
# we manually set the message and log it with error_log_delayed(), which will
# cause it to be displayed at page bottom.
error_parameters( $t_modifiers );
$t_message = error_string( ERROR_LOGFILE_NOT_WRITABLE );
error_log_delayed( $t_message );
error_log( 'MantisBT - ' . htmlspecialchars_decode( $t_message ) );
}
}
if( $s_log_writable ) {
error_log( $t_php_event . PHP_EOL, 3, $t_modifiers );
}
}
break;
case 'page':
global $g_log_events;
Expand Down
1 change: 1 addition & 0 deletions lang/strings_english.txt
Expand Up @@ -1770,6 +1770,7 @@ $MANTIS_ERROR[ERROR_BUG_CONFLICTING_EDIT] = 'This issue has been updated by anot
$MANTIS_ERROR[ERROR_SPAM_SUSPECTED] = 'You have reached the allowed activity limit of %d events within the last %d seconds; your action has been blocked to avoid spam, please try again later.';
$MANTIS_ERROR[ERROR_FIELD_TOO_LONG] = 'Field "%1$s" must be shorter or equal to %2$d characters long.';
$MANTIS_ERROR[ERROR_API_TOKEN_NAME_NOT_UNIQUE] = 'API token name "%s" is already being used. Please go back and select another one.';
$MANTIS_ERROR[ERROR_LOGFILE_NOT_WRITABLE] = 'The file specified in $g_log_destination "%s" is not writable.';

# dropzone.js - placeholders format is defined by the library
$s_dropzone_default_message = 'Drop files here to upload (or click)';
Expand Down

0 comments on commit 6d288c6

Please sign in to comment.