PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.3.0
Defender Security – Malware Scanner, Login Security & Firewall v6.3.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
← All changes | src/model/class-lockout-log.php +42 -4 6.1.0 → 6.3.0 View file →
@@ -9,8 +9,9 @@
9 9
10 10 use WP_Defender\DB;
11 11 use Calotes\Base\Model;
12 12 use WP_Defender\Traits\Formats;
13 +use WP_Defender\Traits\Country;
13 14 use WP_Defender\Component\User_Agent;
14 15 use WP_Defender\Component\Table_Lockout;
15 16 use WP_Defender\Model\Setting\Blacklist_Lockout;
16 17 use WP_Defender\Model\Setting\User_Agent_Lockout;
@@ -20,8 +21,9 @@
20 21 */
21 22 class Lockout_Log extends DB {
22 23
23 24 use Formats;
25 + use Country;
24 26
25 27 // The Firewall log hierarchy. Parent items: 'login', '404', 'bots', 'unlock' and 'custom'.
26 28 // Group of 'login' cases.
27 29 public const AUTH_FAIL = 'auth_fail', AUTH_LOCK = 'auth_lock';
@@ -38,10 +40,8 @@
38 40 public const IP_UNLOCK = 'ip_unlock';
39 41 // Group of 'custom' cases.
40 42 public const LOCKOUT_IP_CUSTOM = 'custom_lockout';
41 43
42 - public const INFINITE_SCROLL_SIZE = 50;
43 -
44 44 /**
45 45 * Table name.
46 46 *
47 47 * @var string
@@ -112,8 +112,34 @@
112 112 */
113 113 public $country_iso_code;
114 114
115 115 /**
116 + * Factory method to instantiate and populate a Lockout_Log model with request data.
117 + *
118 + * @param string $ip The IP address.
119 + * @param string|null $tried The attempted URI, username, or user agent.
120 + *
121 + * @return self
122 + */
123 + public static function create( string $ip, ?string $tried = null ): self {
124 + $model = new self();
125 + $model->ip = $ip;
126 + $user_agent = defender_get_data_from_request( 'HTTP_USER_AGENT', 's' );
127 + $model->user_agent = '' !== $user_agent ? User_Agent::fast_cleaning( $user_agent ) : '';
128 + $model->date = time();
129 + $model->tried = $tried ?? $model->user_agent;
130 + $model->blog_id = get_current_blog_id();
131 +
132 + $ip_to_country = $model->ip_to_country( $ip );
133 +
134 + if ( isset( $ip_to_country['iso'] ) ) {
135 + $model->country_iso_code = $ip_to_country['iso'];
136 + }
137 +
138 + return $model;
139 + }
140 +
141 + /**
116 142 * Query the logs based on the provided filters and pagination settings.
117 143 *
118 144 * @param array $filters An array of filters to apply to the query. Default is an empty array.
119 145 * The following filters are supported:
@@ -266,9 +292,9 @@
266 292 return self::count( $start, $end, self::get_404_lockout_types() );
267 293 }
268 294
269 295 /**
270 - * Count UA lockout in the last 7 days.
296 + * Count all UA lockouts in the last 7 days.
271 297 *
272 298 * @return string|null
273 299 */
274 300 public static function count_ua_lockout_last_7_days(): ?string {
@@ -278,9 +304,21 @@
278 304 return self::count( $start, $end, self::get_ua_lockout_types() );
279 305 }
280 306
281 307 /**
282 - * A shortcut for quickly count lockout in last 24 hours.
308 + * Count all UA lockouts in the last 24 hours.
309 + *
310 + * @return string|null
311 + */
312 + public static function count_ua_lockouts_in_24_hours(): ?string {
313 + $start = strtotime( '-24 hours' );
314 + $end = time();
315 +
316 + return self::count( $start, $end, self::get_ua_lockout_types() );
317 + }
318 +
319 + /**
320 + * A shortcut for quickly count ALL lockouts in last 24 hours.
283 321 *
284 322 * @return string|null
285 323 */
286 324 public static function count_lockout_in_24_hours(): ?string {