PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 3.1.0
Defender Security – Malware Scanner, Login Security & Firewall v3.1.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
defender-security / src / model / setting / two-fa.php

two-fa.php in Defender Security – Malware Scanner, Login Security & Firewall 3.1.0, at src/model/setting/two-fa.php

198 lines 4.7 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\Model\Setting;
4
5 use Calotes\Model\Setting;
6
7 class Two_Fa extends Setting {
8 public $table = 'wd_2auth_settings';
9
10 /**
11 * Feature status.
12 *
13 * @defender_property
14 *
15 * @var bool
16 */
17 public $enabled = false;
18
19 /**
20 * @defender_property
21 * @var bool
22 */
23 public $lost_phone = true;
24
25 /**
26 * @defender_property
27 * @var bool
28 */
29 public $force_auth = false;
30
31 /**
32 * @var string
33 * @defender_property
34 */
35 public $force_auth_mess = '';
36
37 /**
38 * @var array
39 * @defender_property
40 */
41 public $user_roles = [];
42
43 /**
44 * @var array
45 * @defender_property
46 */
47 public $force_auth_roles = [];
48
49 /**
50 * @var bool
51 * @defender_property
52 */
53 public $custom_graphic = false;
54 /**
55 * @var string
56 * @defender_property
57 */
58 public $custom_graphic_url = '';
59
60 /**
61 * @var array
62 */
63 public $is_conflict = array();
64
65 /**
66 * @var string
67 * @defender_property
68 */
69 public $email_subject = '';
70
71 /**
72 * @var string
73 * @defender_property
74 */
75 public $email_sender = '';
76
77 /**
78 * @defender_property
79 * @var string
80 */
81 public $email_body = '';
82
83 /**
84 * @var string
85 * @defender_property
86 */
87 public $app_title = '';
88
89 /**
90 * @var string
91 */
92 public $app_text = '';
93
94 /**
95 * @return array
96 */
97 public function get_default_values() {
98
99 return array(
100 'custom_graphic_url' => defender_asset_url( '/assets/img/2factor-disabled.svg' ),
101 'email_subject' => __( 'Your OTP code', 'wpdef' ),
102 'email_sender' => 'admin',
103 'email_body' => 'Hi {{display_name}},
104
105 Your temporary password is {{passcode}}. To finish logging in, copy and paste the temporary password into the Password field on the login screen.',
106 'app_title' => '',
107 'message' => __( 'You are required to setup two-factor authentication to use this site.', 'wpdef' ),
108 );
109 }
110
111 protected function before_load() {
112 // Default we will load all rules.
113 $default_values = $this->get_default_values();
114 if ( function_exists( 'get_editable_roles' ) ) {
115 // We only need this inside admin, no need to load the user.php everywhere.
116 $this->user_roles = array_keys( get_editable_roles() );
117 }
118 // Define some other defaults.
119 $this->custom_graphic_url = $default_values['custom_graphic_url'];
120 $this->email_subject = $default_values['email_subject'];
121 $this->email_sender = $default_values['email_sender'];
122 $this->email_body = $default_values['email_body'];
123 $this->app_title = empty( $default_values['app_title'] )
124 ? get_bloginfo( 'name' )
125 : $default_values['app_title'];
126 $this->force_auth_mess = $default_values['message'];
127 $this->app_text = __( 'Open your authentication app and type the 6 digit passcode to log in to your account.', 'wpdef' );
128 }
129
130 /**
131 * @param $plugin
132 *
133 * @return bool|int
134 */
135 public function is_conflict( $plugin ) {
136 if ( in_array( $plugin, $this->is_conflict ) ) {
137 return true;
138 } elseif ( in_array( '!' . $plugin, $this->is_conflict ) ) {
139 return false;
140 }
141
142 return 0;
143 }
144
145 /**
146 * @param $plugin
147 */
148 public function mark_as_conflict( $plugin ) {
149 if ( ! in_array( $plugin, $this->is_conflict ) ) {
150 $this->is_conflict[] = $plugin;
151 $this->save();
152 }
153 }
154
155 /**
156 * @param $plugin
157 */
158 public function mark_as_un_conflict( $plugin ) {
159 if ( ( $i = array_search( $plugin, $this->is_conflict ) ) !== false ) {
160 unset( $this->is_conflict[ $i ] );
161 }
162 if ( ! in_array( '!' . $plugin, $this->is_conflict ) ) {
163 $this->is_conflict [] = '!' . $plugin;
164 }
165 $this->save();
166 }
167
168 /**
169 * Define labels for settings key.
170 *
171 * @param string|null $key
172 *
173 * @return string|array|null
174 */
175 public function labels( $key = null ) {
176 $labels = array(
177 'enabled' => __( 'Mask Login Area', 'wpdef' ),
178 'user_roles' => __( 'Enabled user roles', 'wpdef' ),
179 'force_auth_roles' => __( 'Force users to log in with two-factor authentication', 'wpdef' ),
180 'lost_phone' => __( 'Allow lost phone recovery option', 'wpdef' ),
181 'email_subject' => __( 'Subject', 'wpdef' ),
182 'email_body' => __( 'Body', 'wpdef' ),
183 'email_sender' => __( 'Sender', 'wpdef' ),
184 'force_auth' => __( 'Force 2FA on user roles', 'wpdef' ),
185 'force_auth_mess' => __( 'Force 2FA login warning message', 'wpdef' ),
186 'custom_graphic' => __( 'Use custom login branding graphic', 'wpdef' ),
187 'custom_graphic_url' => __( 'Custom Graphic', 'wpdef' ),
188 'app_title' => __( 'App Title', 'wpdef' ),
189 );
190
191 if ( ! is_null( $key ) ) {
192 return $labels[ $key ] ?? null;
193 }
194
195 return $labels;
196 }
197 }
198