| @@ -12,8 +12,9 @@ | ||
| 12 | 12 | use WP_Defender\Model\Lockout_Log; |
| 13 | 13 | use WP_Defender\Traits\File_Operations; |
| 14 | 14 | use WP_Defender\Integrations\Smartcrawl; |
| 15 | 15 | use WP_Defender\Model\Setting\User_Agent_Lockout; |
| 16 | +use WP_Defender\Model\Notification\Firewall_Notification; | |
| 16 | 17 | |
| 17 | 18 | /** |
| 18 | 19 | * Handles operations to insert a weekly rotating hash URL into the footer, |
| 19 | 20 | * and blocking IP addresses that access this URL. |
| @@ -232,22 +233,10 @@ | ||
| 232 | 233 | * @param string $uri The URI that was accessed. |
| 233 | 234 | * @param string $scenario The scenario under which the event is logged. |
| 234 | 235 | */ |
| 235 | 236 | public function log_event( $ip, $uri, $scenario ) { |
| 236 | - $model = new Lockout_Log(); | |
| 237 | - $model->ip = $ip; | |
| 238 | - $user_agent = defender_get_data_from_request( 'HTTP_USER_AGENT', 's' ); | |
| 239 | - $model->user_agent = isset( $user_agent ) ? User_Agent::fast_cleaning( $user_agent ) : null; | |
| 240 | - $model->date = time(); | |
| 241 | - $model->tried = $uri; | |
| 242 | - $model->blog_id = get_current_blog_id(); | |
| 237 | + $model = Lockout_Log::create( $ip, $uri ); | |
| 243 | 238 | |
| 244 | - $ip_to_country = $this->ip_to_country( $ip ); | |
| 245 | - | |
| 246 | - if ( isset( $ip_to_country['iso'] ) ) { | |
| 247 | - $model->country_iso_code = $ip_to_country['iso']; | |
| 248 | - } | |
| 249 | - | |
| 250 | 239 | switch ( $scenario ) { |
| 251 | 240 | case self::SCENARIO_MALICIOUS_BOT: |
| 252 | 241 | default: |
| 253 | 242 | $model->type = Lockout_Log::LOCKOUT_MALICIOUS_BOT; |
| @@ -254,8 +243,10 @@ | ||
| 254 | 243 | $model->log = esc_html__( 'Lockout occurred: Bot ignored robots.txt rules.', 'defender-security' ); |
| 255 | 244 | break; |
| 256 | 245 | } |
| 257 | 246 | $model->save(); |
| 247 | + // Notify directly because the 'defender_notify' hook isn't registered yet at firewall-time. | |
| 248 | + wd_di()->get( Firewall_Notification::class )->notify_lockout( $model ); | |
| 258 | 249 | } |
| 259 | 250 | |
| 260 | 251 | /** |
| 261 | 252 | * Creates a lockout for a blocked IP. |