Skip to content

Commit

Permalink
add back in logging of bots awesomemotive#428
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeltorbert committed Nov 14, 2016
1 parent fba31a3 commit c3b7f78
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions modules/aioseop_bad_robots.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
}
}
}
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit c3b7f78

Please sign in to comment.