| 1 |
<!-- BEGIN COPY CODE - BPS Error logging code --> |
| 2 |
|
| 3 |
<?php |
| 4 |
// Copy this Security Log logging code from BEGIN COPY CODE above to END COPY CODE below and paste it right after <?php get_header(); > in |
| 5 |
// your Theme's 404.php template file located in your themes folder /wp-content/themes/your-theme-folder-name/404.php. |
| 6 |
$bpsProLog = WP_CONTENT_DIR . '/bps-backup/logs/http_error_log.txt'; |
| 7 |
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']); |
| 8 |
$timeNow = time(); |
| 9 |
$gmt_offset = get_option( 'gmt_offset' ) * 3600; |
| 10 |
|
| 11 |
$GDPR_Options = get_option('bulletproof_security_options_gdpr'); |
| 12 |
|
| 13 |
if ( isset($GDPR_Options['bps_gdpr_on_off']) && $GDPR_Options['bps_gdpr_on_off'] != 'On' ) { |
| 14 |
|
| 15 |
$bpsPro_remote_addr = false; |
| 16 |
|
| 17 |
if ( array_key_exists('REMOTE_ADDR', $_SERVER) ) { |
| 18 |
$bpsPro_remote_addr = $_SERVER['REMOTE_ADDR']; |
| 19 |
} |
| 20 |
|
| 21 |
$bpsPro_http_client_ip = false; |
| 22 |
|
| 23 |
if ( array_key_exists('HTTP_CLIENT_IP', $_SERVER) ) { |
| 24 |
$bpsPro_http_client_ip = $_SERVER['HTTP_CLIENT_IP']; |
| 25 |
} |
| 26 |
|
| 27 |
$bpsPro_http_forwarded = false; |
| 28 |
|
| 29 |
if ( array_key_exists('HTTP_FORWARDED', $_SERVER) ) { |
| 30 |
$bpsPro_http_forwarded = $_SERVER['HTTP_FORWARDED']; |
| 31 |
} |
| 32 |
|
| 33 |
$bpsPro_http_x_forwarded_for = false; |
| 34 |
|
| 35 |
if ( array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER) ) { |
| 36 |
$bpsPro_http_x_forwarded_for = $_SERVER['HTTP_X_FORWARDED_FOR']; |
| 37 |
} |
| 38 |
|
| 39 |
$bpsPro_http_x_cluster_client_ip = false; |
| 40 |
|
| 41 |
if ( array_key_exists('HTTP_X_CLUSTER_CLIENT_IP', $_SERVER) ) { |
| 42 |
$bpsPro_http_x_cluster_client_ip = $_SERVER['HTTP_X_CLUSTER_CLIENT_IP']; |
| 43 |
} |
| 44 |
|
| 45 |
$bpsPro_http_referrer = false; |
| 46 |
|
| 47 |
if ( array_key_exists('HTTP_REFERER', $_SERVER) ) { |
| 48 |
$bpsPro_http_referrer = $_SERVER['HTTP_REFERER']; |
| 49 |
} |
| 50 |
|
| 51 |
$bpsPro_http_user_agent = false; |
| 52 |
|
| 53 |
if ( array_key_exists('HTTP_USER_AGENT', $_SERVER) ) { |
| 54 |
$bpsPro_http_user_agent = $_SERVER['HTTP_USER_AGENT']; |
| 55 |
} |
| 56 |
|
| 57 |
} else { |
| 58 |
|
| 59 |
$bpsPro_remote_addr = 'GDPR Compliance On'; |
| 60 |
$bpsPro_http_client_ip = 'GDPR Compliance On'; |
| 61 |
$bpsPro_http_forwarded = 'GDPR Compliance On'; |
| 62 |
$bpsPro_http_x_forwarded_for = 'GDPR Compliance On'; |
| 63 |
$bpsPro_http_x_cluster_client_ip = 'GDPR Compliance On'; |
| 64 |
|
| 65 |
$bpsPro_http_referrer = false; |
| 66 |
|
| 67 |
if ( array_key_exists('HTTP_REFERER', $_SERVER) ) { |
| 68 |
$bpsPro_http_referrer = $_SERVER['HTTP_REFERER']; |
| 69 |
} |
| 70 |
|
| 71 |
$bpsPro_http_user_agent = false; |
| 72 |
|
| 73 |
if ( array_key_exists('HTTP_USER_AGENT', $_SERVER) ) { |
| 74 |
$bpsPro_http_user_agent = $_SERVER['HTTP_USER_AGENT']; |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
$post_limit = get_option('bulletproof_security_options_sec_log_post_limit'); |
| 79 |
$query_string = parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY); |
| 80 |
|
| 81 |
if ( $post_limit['bps_security_log_post_none'] == '1' ) { |
| 82 |
$request_body = file_get_contents( 'php://input', false, NULL, 0, 5 ); |
| 83 |
|
| 84 |
} else { |
| 85 |
|
| 86 |
if ( $post_limit['bps_security_log_post_limit'] == '1' ) { |
| 87 |
$request_body = file_get_contents( 'php://input', false, NULL, 0, 500 ); |
| 88 |
} else { |
| 89 |
$request_body = file_get_contents( 'php://input', false, NULL, 0, 250000 ); // roughly 250KB Max Limit |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
if ( ! get_option( 'gmt_offset' ) ) { |
| 94 |
$timestamp = date("F j, Y g:i a", time() ); |
| 95 |
} else { |
| 96 |
$timestamp = date_i18n(get_option('date_format'), strtotime("11/15-1976")) . ' - ' . date_i18n(get_option('time_format'), $timeNow + $gmt_offset); |
| 97 |
} |
| 98 |
|
| 99 |
$event = 'The server has not found anything matching the Request-URI.'; |
| 100 |
$solution = 'N/A - 404 Not Found'; |
| 101 |
|
| 102 |
if ( ! empty($request_body) ) { |
| 103 |
|
| 104 |
if ( $post_limit['bps_security_log_post_none'] == '1' ) { |
| 105 |
$request_body = 'BPS Security Log option set to: Do Not Log POST Request Body Data'; |
| 106 |
} |
| 107 |
|
| 108 |
$log_contents = "\r\n" . '[404 POST Not Found Request: ' . $timestamp . ']' . "\r\n" . 'BPS: ' . $bps_version . "\r\n" . 'WP: ' . $wp_version . "\r\n" . 'Event Code: ' . $event . "\r\n" . 'Solution: ' . $solution . "\r\n" . 'REMOTE_ADDR: '.$bpsPro_remote_addr . "\r\n" . 'Host Name: ' . $hostname . "\r\n" . 'SERVER_PROTOCOL: ' . $_SERVER['SERVER_PROTOCOL'] . "\r\n" . 'HTTP_CLIENT_IP: ' . $bpsPro_http_client_ip . "\r\n" . 'HTTP_FORWARDED: ' . $bpsPro_http_forwarded . "\r\n" . 'HTTP_X_FORWARDED_FOR: ' . $bpsPro_http_x_forwarded_for . "\r\n" . 'HTTP_X_CLUSTER_CLIENT_IP: ' . $bpsPro_http_x_cluster_client_ip."\r\n" . 'REQUEST_METHOD: POST'."\r\n" . 'HTTP_REFERER: '.$bpsPro_http_referrer."\r\n" . 'REQUEST_URI: '.$_SERVER['REQUEST_URI']."\r\n" . 'QUERY_STRING: '.$query_string. "\r\n" . 'HTTP_USER_AGENT: '.$bpsPro_http_user_agent . "\r\n" . 'REQUEST BODY: ' . $request_body . "\r\n"; |
| 109 |
|
| 110 |
if ( is_writable( $bpsProLog ) ) { |
| 111 |
|
| 112 |
if ( ! $handle = fopen( $bpsProLog, 'a' ) ) { |
| 113 |
exit; |
| 114 |
} |
| 115 |
|
| 116 |
if ( fwrite( $handle, $log_contents) === false ) { |
| 117 |
exit; |
| 118 |
} |
| 119 |
|
| 120 |
fclose($handle); |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
if ( empty($request_body) ) { |
| 125 |
|
| 126 |
$log_contents = "\r\n" . '[404 GET Not Found Request: ' . $timestamp . ']' . "\r\n" . 'BPS: ' . $bps_version . "\r\n" . 'WP: ' . $wp_version . "\r\n" . 'Event Code: ' . $event . "\r\n" . 'Solution: ' . $solution . "\r\n" . 'REMOTE_ADDR: '.$bpsPro_remote_addr . "\r\n" . 'Host Name: ' . $hostname . "\r\n" . 'SERVER_PROTOCOL: ' . $_SERVER['SERVER_PROTOCOL'] . "\r\n" . 'HTTP_CLIENT_IP: ' . $bpsPro_http_client_ip . "\r\n" . 'HTTP_FORWARDED: ' . $bpsPro_http_forwarded . "\r\n" . 'HTTP_X_FORWARDED_FOR: ' . $bpsPro_http_x_forwarded_for . "\r\n" . 'HTTP_X_CLUSTER_CLIENT_IP: ' . $bpsPro_http_x_cluster_client_ip."\r\n" . 'REQUEST_METHOD: '.$_SERVER['REQUEST_METHOD']."\r\n" . 'HTTP_REFERER: '.$bpsPro_http_referrer."\r\n" . 'REQUEST_URI: '.$_SERVER['REQUEST_URI']."\r\n" . 'QUERY_STRING: '.$query_string."\r\n" . 'HTTP_USER_AGENT: '.$bpsPro_http_user_agent."\r\n"; |
| 127 |
|
| 128 |
if ( is_writable( $bpsProLog ) ) { |
| 129 |
|
| 130 |
if ( ! $handle = fopen( $bpsProLog, 'a' ) ) { |
| 131 |
exit; |
| 132 |
} |
| 133 |
|
| 134 |
if ( fwrite( $handle, $log_contents) === false ) { |
| 135 |
exit; |
| 136 |
} |
| 137 |
|
| 138 |
fclose($handle); |
| 139 |
} |
| 140 |
} |
| 141 |
?> |
| 142 |
<!-- END COPY CODE - BPS Error logging code --> |