wfAlerts.php
7.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<?php
abstract class wfBaseAlert {
public abstract function send();
}
class wfBlockAlert extends wfBaseAlert {
private $IP;
private $reason;
private $secsToGo;
/**
* wfBlockAlert constructor.
* @param $IP
* @param $reason
* @param $secsToGo
*/
public function __construct($IP, $reason, $secsToGo) {
$this->IP = $IP;
$this->reason = $reason;
$this->secsToGo = $secsToGo;
}
public function send() {
if (wfConfig::get('alertOn_block')) {
$message = sprintf(/* translators: IP address. */ __('Wordfence has blocked IP address %s.', 'wordfence'), $this->IP) . "\n";
$message .= sprintf(/* translators: Description of firewall action. */ __('The reason is: "%s".', 'wordfence'), $this->reason);
if ($this->secsToGo > 0) {
$message .= "\n" . sprintf(/* translators: Time until. */ __('The duration of the block is %s.', 'wordfence'), wfUtils::makeDuration($this->secsToGo, true));
}
wordfence::alert(sprintf(/* translators: IP address. */__('Blocking IP %s', 'wordfence'), $this->IP), $message, $this->IP);
}
}
}
class wfAutoUpdatedAlert extends wfBaseAlert {
private $version;
/**
* @param $version
*/
public function __construct($version) {
$this->version = $version;
}
public function send() {
if (wfConfig::get('alertOn_update') == '1' && $this->version) {
wordfence::alert(sprintf(/* translators: Software version. */ __("Wordfence Upgraded to version %s", 'wordfence'), $this->version), sprintf(/* translators: Software version. */ __("Your Wordfence installation has been upgraded to version %s", 'wordfence'), $this->version), false);
}
}
}
class wfWafDeactivatedAlert extends wfBaseAlert {
private $username;
private $IP;
/**
* @param $username
* @param $IP
*/
public function __construct($username, $IP) {
$this->username = $username;
$this->IP = $IP;
}
public function send() {
if (wfConfig::get('alertOn_wafDeactivated')) {
wordfence::alert(__('Wordfence WAF Deactivated', 'wordfence'), sprintf(/* translators: WP username. */__('A user with username "%s" deactivated the Wordfence Web Application Firewall on your WordPress site.', 'wordfence'), $this->username), $this->IP);
}
}
}
class wfWordfenceDeactivatedAlert extends wfBaseAlert {
private $username;
private $IP;
/**
* @param $username
* @param $IP
*/
public function __construct($username, $IP) {
$this->username = $username;
$this->IP = $IP;
}
public function send() {
if (wfConfig::get('alertOn_wordfenceDeactivated')) {
wordfence::alert(__("Wordfence Deactivated", 'wordfence'), sprintf(/* translators: WP username. */ __("A user with username \"%s\" deactivated Wordfence on your WordPress site.", 'wordfence'), $this->username), $this->IP);
}
}
}
class wfLostPasswdFormAlert extends wfBaseAlert {
private $user;
private $IP;
/**
* @param $user
* @param $IP
*/
public function __construct($user, $IP) {
$this->user = $user;
$this->IP = $IP;
}
public function send() {
if (wfConfig::get('alertOn_lostPasswdForm')) {
wordfence::alert(__("Password recovery attempted", 'wordfence'), sprintf(/* translators: Email address. */__("Someone tried to recover the password for user with email address: %s", 'wordfence'), wp_kses($this->user->user_email, array())), $this->IP);
}
}
}
class wfLoginLockoutAlert extends wfBaseAlert {
private $IP;
private $reason;
/**
* @param $IP
* @param $reason
*/
public function __construct($IP, $reason) {
$this->IP = $IP;
$this->reason = $reason;
}
public function send() {
if (wfConfig::get('alertOn_loginLockout')) {
$message = sprintf(
/* translators: 1. IP address. 2. Description of firewall action. */
__('A user with IP address %1$s has been locked out from signing in or using the password recovery form for the following reason: %2$s.', 'wordfence'), $this->IP, $this->reason);
if (wfBlock::lockoutDuration() > 0) {
$message .= "\n" . sprintf(/* translators: Time until. */ __('The duration of the lockout is %s.', 'wordfence'), wfUtils::makeDuration(wfBlock::lockoutDuration(), true));
}
wordfence::alert(__('User locked out from signing in', 'wordfence'), $message, $this->IP);
}
}
}
class wfAdminLoginAlert extends wfBaseAlert {
private $cookieName;
private $username;
private $IP;
private $cookieValue;
/**
* @param $cookieName
* @param $cookieValue
* @param $username
* @param $IP
*/
public function __construct($cookieName, $cookieValue, $username, $IP) {
$this->cookieName = $cookieName;
$this->cookieValue = $cookieValue;
$this->username = $username;
$this->IP = $IP;
}
public function send() {
if (wfConfig::get('alertOn_adminLogin')) {
$shouldAlert = true;
if (wfConfig::get('alertOn_firstAdminLoginOnly') && isset($_COOKIE[$this->cookieName])) {
$shouldAlert = !hash_equals($this->cookieValue, $_COOKIE[$this->cookieName]);
}
if ($shouldAlert) {
wordfence::alert(__("Admin Login", 'wordfence'), sprintf(/* translators: WP username. */ __("A user with username \"%s\" who has administrator access signed in to your WordPress site.", 'wordfence'), $this->username), $this->IP);
}
}
}
}
class wfNonAdminLoginAlert extends wfBaseAlert {
private $cookieName;
private $username;
private $IP;
private $cookieValue;
/**
* @param $cookieName
* @param $cookieValue
* @param $username
* @param $IP
*/
public function __construct($cookieName, $cookieValue, $username, $IP) {
$this->cookieName = $cookieName;
$this->cookieValue = $cookieValue;
$this->username = $username;
$this->IP = $IP;
}
public function send() {
if (wfConfig::get('alertOn_nonAdminLogin')) {
$shouldAlert = true;
if (wfConfig::get('alertOn_firstNonAdminLoginOnly') && isset($_COOKIE[$this->cookieName])) {
$shouldAlert = !hash_equals($this->cookieValue, $_COOKIE[$this->cookieName]);
}
if ($shouldAlert) {
wordfence::alert(__("User login", 'wordfence'), sprintf(/* translators: WP username. */ __("A non-admin user with username \"%s\" signed in to your WordPress site.", 'wordfence'), $this->username), $this->IP);
}
}
}
}
class wfBreachLoginAlert extends wfBaseAlert {
private $username;
private $lostPasswordUrl;
private $supportUrl;
private $IP;
/**
* @param $username
* @param $lostPasswordUrl
* @param $supportUrl
* @param $IP
*/
public function __construct($username, $lostPasswordUrl, $supportUrl, $IP) {
$this->username = $username;
$this->lostPasswordUrl = $lostPasswordUrl;
$this->supportUrl = $supportUrl;
$this->IP = $IP;
}
public function send() {
if (wfConfig::get('alertOn_breachLogin')) {
wordfence::alert(__('User login blocked for insecure password', 'wordfence'), sprintf(
/* translators: 1. WP username. 2. Reset password URL. 3. Support URL. */
__('A user with username "%1$s" tried to sign in to your WordPress site. Access was denied because the password being used exists on lists of passwords leaked in data breaches. Attackers use such lists to break into sites and install malicious code. Please change or reset the password (%2$s) to reactivate this account. Learn More: %3$s', 'wordfence'), $this->username, $this->lostPasswordUrl, $this->supportUrl), $this->IP);
}
}
}
class wfIncreasedAttackRateAlert extends wfBaseAlert {
private $message;
/**
* @param $message
*/
public function __construct($message) {
$this->message = $message;
}
public function send() {
wordfence::alert(__('Increased Attack Rate', 'wordfence'), $this->message, false);
}
}