From c3b7f783ade3230ab9ec1278ba0f6fffb35d2a1a Mon Sep 17 00:00:00 2001 From: Michael Torbert Date: Mon, 14 Nov 2016 16:28:04 -0500 Subject: [PATCH] add back in logging of bots #428 --- modules/aioseop_bad_robots.php | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/modules/aioseop_bad_robots.php b/modules/aioseop_bad_robots.php index 4a6a72719..975d65335 100644 --- a/modules/aioseop_bad_robots.php +++ b/modules/aioseop_bad_robots.php @@ -100,13 +100,13 @@ function __construct() { status_header( 503 ); $ip = $this->validate_ip( $_SERVER['REMOTE_ADDR'] ); $user_agent = $_SERVER['HTTP_USER_AGENT']; - aiosp_log( sprintf( __( 'Blocked bot with IP %s -- matched user agent %s found in blocklist.', 'all-in-one-seo-pack' ), $ip, $user_agent )); + $this->blocked_message( sprintf( __( 'Blocked bot with IP %s -- matched user agent %s found in blocklist.', 'all-in-one-seo-pack' ), $ip, $user_agent ) ); exit(); } elseif ( $this->option_isset( 'block_refer' ) && $this->is_bad_referer() ) { status_header( 503 ); $ip = $this->validate_ip( $_SERVER['REMOTE_ADDR'] ); $referer = $_SERVER['HTTP_REFERER']; - aiosp_log( sprintf( __( 'Blocked bot with IP %s -- matched referer %s found in blocklist.', 'all-in-one-seo-pack' ), $ip, $referer )); + $this->blocked_message( sprintf( __( 'Blocked bot with IP %s -- matched referer %s found in blocklist.', 'all-in-one-seo-pack' ), $ip, $referer ) ); } } } @@ -209,6 +209,28 @@ function filter_bad_botlist( $botlist ) { return $botlist; } + + /** + * Updates blocked message. + * + * @param string $msg + */ + function blocked_message( $msg ) { + if ( empty( $this->options["{$this->prefix}blocked_log"] ) ) { + $this->options["{$this->prefix}blocked_log"] = ''; + } + $this->options["{$this->prefix}blocked_log"] = date( 'Y-m-d H:i:s' ) . " {$msg}\n" . $this->options["{$this->prefix}blocked_log"]; + if ( $this->strlen( $this->options["{$this->prefix}blocked_log"] ) > 4096 ) { + $end = $this->strrpos( $this->options["{$this->prefix}blocked_log"], "\n" ); + if ( false === $end ) { + $end = 4096; + } + $this->options["{$this->prefix}blocked_log"] = $this->substr( $this->options["{$this->prefix}blocked_log"], 0, $end ); + } + $this->update_class_option( $this->options ); + } + + /** * Filter display options. *