PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 5.7.2
Defender Security – Malware Scanner, Login Security & Firewall v5.7.2
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
defender-security / src / component / class-table-lockout.php

class-table-lockout.php in Defender Security – Malware Scanner, Login Security & Firewall 5.7.2, at src/component/class-table-lockout.php

153 lines 5.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Handles the display and management of lockout-related data in tables.
4 *
5 * @package WP_Defender\Component
6 */
7
8 namespace WP_Defender\Component;
9
10 use WP_Defender\Component;
11 use WP_Defender\Traits\Formats;
12 use WP_Defender\Model\Lockout_Ip;
13 use WP_Defender\Model\Lockout_Log;
14
15 /**
16 * Handles the display and management of lockout-related data in tables.
17 */
18 class Table_Lockout extends Component {
19
20 use Formats;
21
22 public const STATUS_BAN = 'ban', STATUS_NOT_BAN = 'not_ban', STATUS_ALLOWLIST = 'allowlist';
23 public const SORT_DESC = 'latest', SORT_ASC = 'oldest', SORT_BY_IP = 'ip', SORT_BY_UA = 'user_agent';
24 public const LIMIT_20 = '20', LIMIT_50 = '50', LIMIT_100 = '100', LIMIT_ALL = '-1';
25
26 /**
27 * Retrieves the status text for a given IP address.
28 *
29 * @param string $ip The IP address to check.
30 *
31 * @return string The status text related to the IP address.
32 */
33 public function get_ip_status_text( $ip ): string {
34 $bl_component = new Blacklist_Lockout();
35 if ( $bl_component->is_ip_whitelisted( $ip ) ) {
36 return esc_html__( 'Is allowlisted', 'defender-security' );
37 }
38 if ( $bl_component->is_blacklist( $ip ) ) {
39 return esc_html__( 'Is blocklisted', 'defender-security' );
40 }
41
42 $model = Lockout_Ip::get( $ip );
43 if ( ! is_object( $model ) ) {
44 return esc_html__( 'Not banned', 'defender-security' );
45 }
46
47 if ( Lockout_Ip::STATUS_BLOCKED === $model->status ) {
48 return esc_html__( 'Banned', 'defender-security' );
49 } elseif ( Lockout_Ip::STATUS_NORMAL === $model->status ) {
50 return esc_html__( 'Not banned', 'defender-security' );
51 }
52
53 return '';
54 }
55
56 /**
57 * Get types.
58 *
59 * @return array
60 */
61 private function get_types(): array {
62 return array(
63 'all' => esc_html__( 'All', 'defender-security' ),
64 Lockout_Log::AUTH_FAIL => esc_html__( 'Failed login attempts', 'defender-security' ),
65 Lockout_Log::AUTH_LOCK => esc_html__( 'Login lockout', 'defender-security' ),
66 Lockout_Log::ERROR_404 => esc_html__( '404 error', 'defender-security' ),
67 Lockout_Log::LOCKOUT_404 => esc_html__( '404 lockout', 'defender-security' ),
68 Lockout_Log::LOCKOUT_UA => esc_html__( 'User Agent Lockout', 'defender-security' ),
69 Lockout_Log::LOCKOUT_MALICIOUS_BOT => esc_html__( 'Malicious Bot Lockout', 'defender-security' ),
70 Lockout_Log::LOCKOUT_FAKE_BOT => esc_html__( 'Fake Bot Lockout', 'defender-security' ),
71 // New types since 5.3.0.
72 Lockout_Log::LOCKOUT_IP_CUSTOM => esc_html__( 'Custom IP Lockout', 'defender-security' ),
73 Lockout_Log::IP_UNLOCK => esc_html__( 'IP Unlock', 'defender-security' ),
74 // New types since 5.7.0.
75 Lockout_Log::ERROR_404_XSS => esc_html__( 'XSS attempt', 'defender-security' ),
76 Lockout_Log::LOCKOUT_404_XSS => esc_html__( 'XSS lockout', 'defender-security' ),
77 Lockout_Log::ERROR_404_NON_EXISTENT_THEME => esc_html__( 'Attempt to access non-installed theme', 'defender-security' ),
78 Lockout_Log::LOCKOUT_404_NON_EXISTENT_THEME => esc_html__( 'Non-installed theme lockout', 'defender-security' ),
79 Lockout_Log::ERROR_404_NON_EXISTENT_PLUGIN => esc_html__( 'Attempt to access non-installed plugin', 'defender-security' ),
80 Lockout_Log::LOCKOUT_404_NON_EXISTENT_PLUGIN => esc_html__( 'Non-installed plugin lockout', 'defender-security' ),
81 );
82 }
83
84 /**
85 * Get ban statuses.
86 *
87 * @return array
88 */
89 private function ban_status(): array {
90 return array(
91 'all' => esc_html__( 'All', 'defender-security' ),
92 self::STATUS_NOT_BAN => esc_html__( 'Not Banned', 'defender-security' ),
93 self::STATUS_BAN => esc_html__( 'Banned', 'defender-security' ),
94 self::STATUS_ALLOWLIST => esc_html__( 'Allowlisted', 'defender-security' ),
95 );
96 }
97
98 /**
99 * Retrieves the type description based on the type key.
100 *
101 * @param string $type The type key.
102 *
103 * @return string The description of the type.
104 */
105 public function get_type( $type ): string {
106 $types = $this->get_types();
107 $types[ Lockout_Log::ERROR_404_IGNORE ] = esc_html__( '404 error', 'defender-security' );
108 return $types[ $type ] ?? '';
109 }
110
111 /**
112 * Retrieves sorting values.
113 *
114 * @return array An associative array of sorting options.
115 */
116 private function sort_values(): array {
117 return array(
118 self::SORT_DESC => esc_html__( 'Latest', 'defender-security' ),
119 self::SORT_ASC => esc_html__( 'Oldest', 'defender-security' ),
120 self::SORT_BY_IP => esc_html__( 'IP Address', 'defender-security' ),
121 self::SORT_BY_UA => esc_html__( 'User agent', 'defender-security' ),
122 );
123 }
124
125 /**
126 * Retrieves pagination limits.
127 *
128 * @return array An associative array of pagination limits.
129 */
130 private function limit_per_page(): array {
131 return array(
132 self::LIMIT_20 => '20',
133 self::LIMIT_50 => '50',
134 self::LIMIT_100 => '100',
135 self::LIMIT_ALL => esc_html__( 'All', 'defender-security' ),
136 );
137 }
138
139 /**
140 * Retrieves all filters used in the lockout table.
141 *
142 * @return array An associative array of all filters.
143 */
144 public function get_filters(): array {
145 return array(
146 'lockout_types' => $this->get_types(),
147 'ban_status' => $this->ban_status(),
148 'sort_values' => $this->sort_values(),
149 'limit_logs' => $this->limit_per_page(),
150 );
151 }
152 }
153