PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 3.0.1
Defender Security – Malware Scanner, Login Security & Firewall v3.0.1
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 / table-lockout.php

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

139 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WP_Defender\Component;
4
5 use WP_Defender\Component;
6 use WP_Defender\Model\Lockout_Ip;
7 use WP_Defender\Model\Lockout_Log;
8 use WP_Defender\Traits\Formats;
9
10 class Table_Lockout extends Component {
11 use Formats;
12
13 public const STATUS_BAN = 'ban', STATUS_NOT_BAN = 'not_ban', STATUS_ALLOWLIST = 'allowlist';
14 public const SORT_DESC = 'latest', SORT_ASC = 'oldest', SORT_BY_IP = 'ip', SORT_BY_UA = 'user_agent';
15 public const LIMIT_20 = '20', LIMIT_50 = '50', LIMIT_100 = '100', LIMIT_ALL = '-1';
16
17 /**
18 * Get IP status.
19 *
20 * @param string $ip
21 *
22 * @return string|void
23 */
24 public function get_ip_status_text( $ip ) {
25 $bl_component = new \WP_Defender\Component\Blacklist_Lockout();
26 if ( $bl_component->is_ip_whitelisted( $ip ) ) {
27 return __( 'Is allowlisted', 'wpdef' );
28 }
29 if ( $bl_component->is_blacklist( $ip ) ) {
30 return __( 'Is blocklisted', 'wpdef' );
31 }
32
33 $model = Lockout_Ip::get( $ip );
34 if ( ! is_object( $model ) ) {
35 return __( 'Not banned', 'wpdef' );
36 }
37
38 if ( Lockout_Ip::STATUS_BLOCKED === $model->status ) {
39 return __( 'Banned', 'wpdef' );
40 } elseif ( Lockout_Ip::STATUS_NORMAL === $model->status ) {
41 return __( 'Not banned', 'wpdef' );
42 }
43 }
44
45 /**
46 * Get types.
47 *
48 * @return array
49 */
50 private function get_types() {
51
52 return array(
53 'all' => __( 'All', 'wpdef' ),
54 Lockout_Log::AUTH_FAIL => __( 'Failed login attempts', 'wpdef' ),
55 Lockout_Log::AUTH_LOCK => __( 'Login lockout', 'wpdef' ),
56 Lockout_Log::ERROR_404 => __( '404 error', 'wpdef' ),
57 Lockout_Log::LOCKOUT_404 => __( '404 lockout', 'wpdef' ),
58 Lockout_Log::LOCKOUT_UA => __( 'User Agent Lockout', 'wpdef' ),
59 );
60 }
61
62 /**
63 * Get ban statuses.
64 *
65 * @return array
66 */
67 private function ban_status() {
68
69 return array(
70 'all' => __( 'All', 'wpdef' ),
71 self::STATUS_NOT_BAN => __( 'Not Banned', 'wpdef' ),
72 self::STATUS_BAN => __( 'Banned', 'wpdef' ),
73 self::STATUS_ALLOWLIST => __( 'Allowlisted', 'wpdef' ),
74 );
75 }
76
77 /**
78 * Get type.
79 *
80 * @param string $type
81 *
82 * @return mixed|null
83 */
84 public function get_type( $type ) {
85 $types = array(
86 Lockout_Log::AUTH_FAIL => __( 'Failed login attempts', 'wpdef' ),
87 Lockout_Log::AUTH_LOCK => __( 'Login lockout', 'wpdef' ),
88 Lockout_Log::ERROR_404 => __( '404 error', 'wpdef' ),
89 Lockout_Log::ERROR_404_IGNORE => __( '404 error', 'wpdef' ),
90 Lockout_Log::LOCKOUT_404 => __( '404 lockout', 'wpdef' ),
91 Lockout_Log::LOCKOUT_UA => __( 'User Agent Lockout', 'wpdef' ),
92 );
93
94 if ( isset( $types[ $type ] ) ) {
95 return $types[ $type ];
96 }
97
98 return null;
99 }
100
101 /**
102 * @return array
103 */
104 private function sort_values() {
105
106 return array(
107 self::SORT_DESC => __( 'Latest', 'wpdef' ),
108 self::SORT_ASC => __( 'Oldest', 'wpdef' ),
109 self::SORT_BY_IP => __( 'IP Address', 'wpdef' ),
110 self::SORT_BY_UA => __( 'User agent', 'wpdef' ),
111 );
112 }
113
114 /**
115 * @return array
116 */
117 private function limit_per_page() {
118
119 return array(
120 self::LIMIT_20 => __( '20', 'wpdef' ),
121 self::LIMIT_50 => __( '50', 'wpdef' ),
122 self::LIMIT_100 => __( '100', 'wpdef' ),
123 self::LIMIT_ALL => __( 'All', 'wpdef' ),
124 );
125 }
126
127 /**
128 * @return array
129 */
130 public function get_filters() {
131 return array(
132 'lockout_types' => $this->get_types(),
133 'ban_status' => $this->ban_status(),
134 'sort_values' => $this->sort_values(),
135 'limit_logs' => $this->limit_per_page(),
136 );
137 }
138 }
139