From 47b139e3078a04260693bdc9b169285fc65b39ed Mon Sep 17 00:00:00 2001 From: David Parker Date: Thu, 7 Mar 2024 11:43:33 -0500 Subject: [PATCH 1/2] Adding random suffix to log file name --- includes/functions.php | 32 ++++++++++++++++++++++++++------ includes/settings.php | 2 +- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index ad76822..403a6d3 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -273,7 +273,30 @@ function pmpromc_log( $entry ) { $logstr = "Logged On: " . date_i18n("m/d/Y H:i:s") . "\n"; $logstr .= $entry; $logstr .= "\n-------------\n"; - + + $loghandle = fopen( pmpromc_get_log_file_path(), "a+" ); + fwrite($loghandle, $logstr); + fclose($loghandle); +} + +/** + * Get the file path for the debug log file. + * + * @since TBD + * + * @return string + */ +function pmpromc_get_log_file_path() { + // Check if we have a unique file name saved already. + $pmpromc_file_name = get_option( 'pmpromc_log_file_name' ); + if ( empty( $pmpromc_file_name ) ) { + $pmpromc_file_name = 'pmpromc-log-' . uniqid() . '.txt'; + update_option( 'pmpromc_log_file_name', $pmpromc_file_name ); + } + + // Build the debug log file path. + $pmpromc_log_path = PMPROMC_DIR . "/logs/" . $pmpromc_file_name; + /** * Filter the debug log file path. * By default this points to /plugins/pmpro-mailchimp/logs/pmpromc-log.txt @@ -281,12 +304,9 @@ function pmpromc_log( $entry ) { * @param string $path * * @since 2.3.3 - * */ - $pmpromc_log_path = apply_filters( 'pmpromc_log_path', PMPROMC_DIR . "/logs/pmpromc-log.txt" ); + $pmpromc_log_path = apply_filters( 'pmpromc_log_path', $pmpromc_log_path ); - $loghandle = fopen( $pmpromc_log_path, "a+" ); - fwrite($loghandle, $logstr); - fclose($loghandle); + return $pmpromc_log_path; } diff --git a/includes/settings.php b/includes/settings.php index 92714a3..892552c 100644 --- a/includes/settings.php +++ b/includes/settings.php @@ -367,7 +367,7 @@ function pmpromc_option_logging_enabled() { -

/wp-content/plugins/pmpro-mailchimp/logs/pmpromc-log.txt' ); ?> +

' . esc_html( pmpromc_get_log_file_path() ) . '' ); ?>

Date: Thu, 7 Mar 2024 11:46:20 -0500 Subject: [PATCH 2/2] Preventing accessing log directory listings --- logs/index.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 logs/index.php diff --git a/logs/index.php b/logs/index.php new file mode 100644 index 0000000..e69de29