Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/wordfenc.../models/block
File: wfBlock.php
* @param array $blockIDs
[1000] Fix | Delete
* @param bool $retrieve if true, fetch and return the deleted rows
[1001] Fix | Delete
* @return bool|array true(or an array of blocks, if $retrieve is specified) or false on failure
[1002] Fix | Delete
*/
[1003] Fix | Delete
public static function removeBlockIDs($blockIDs, $retrieve=false) {
[1004] Fix | Delete
global $wpdb;
[1005] Fix | Delete
$blocksTable = wfBlock::blocksTable();
[1006] Fix | Delete
[1007] Fix | Delete
$blockIDs = array_map('intval', $blockIDs);
[1008] Fix | Delete
$inClause = implode(', ', $blockIDs);
[1009] Fix | Delete
if($retrieve){
[1010] Fix | Delete
$blocks = $wpdb->get_results("SELECT * FROM `{$blocksTable}` WHERE `id` IN (".$inClause.")");
[1011] Fix | Delete
}
[1012] Fix | Delete
else{
[1013] Fix | Delete
$blocks=true;
[1014] Fix | Delete
}
[1015] Fix | Delete
$query = "DELETE FROM `{$blocksTable}` WHERE `id` IN (" . $inClause . ")";
[1016] Fix | Delete
if($wpdb->query($query)!==false) {
[1017] Fix | Delete
return $blocks;
[1018] Fix | Delete
}
[1019] Fix | Delete
return false;
[1020] Fix | Delete
}
[1021] Fix | Delete
[1022] Fix | Delete
/**
[1023] Fix | Delete
* Removes all IP blocks (i.e., manual, wfsn, or rate limited)
[1024] Fix | Delete
*/
[1025] Fix | Delete
public static function removeAllIPBlocks() {
[1026] Fix | Delete
global $wpdb;
[1027] Fix | Delete
$blocksTable = wfBlock::blocksTable();
[1028] Fix | Delete
$wpdb->query("DELETE FROM `{$blocksTable}` WHERE `type` IN (" . implode(', ', array(self::TYPE_IP_MANUAL, self::TYPE_IP_AUTOMATIC_TEMPORARY, self::TYPE_IP_AUTOMATIC_PERMANENT, self::TYPE_WFSN_TEMPORARY, self::TYPE_RATE_BLOCK, self::TYPE_RATE_THROTTLE, self::TYPE_LOCKOUT)) . ")");
[1029] Fix | Delete
}
[1030] Fix | Delete
[1031] Fix | Delete
/**
[1032] Fix | Delete
* Removes all country blocks
[1033] Fix | Delete
*/
[1034] Fix | Delete
public static function removeAllCountryBlocks() {
[1035] Fix | Delete
global $wpdb;
[1036] Fix | Delete
$blocksTable = wfBlock::blocksTable();
[1037] Fix | Delete
$wpdb->query("DELETE FROM `{$blocksTable}` WHERE `type` IN (" . implode(', ', array(self::TYPE_COUNTRY)) . ")");
[1038] Fix | Delete
}
[1039] Fix | Delete
[1040] Fix | Delete
/**
[1041] Fix | Delete
* Removes all blocks that were created by WFSN responses.
[1042] Fix | Delete
*/
[1043] Fix | Delete
public static function removeTemporaryWFSNBlocks() {
[1044] Fix | Delete
global $wpdb;
[1045] Fix | Delete
$blocksTable = wfBlock::blocksTable();
[1046] Fix | Delete
$wpdb->query($wpdb->prepare("DELETE FROM `{$blocksTable}` WHERE `type` = %d", self::TYPE_WFSN_TEMPORARY));
[1047] Fix | Delete
}
[1048] Fix | Delete
[1049] Fix | Delete
/**
[1050] Fix | Delete
* Converts all blocks to non-expiring whose ID is in the given array.
[1051] Fix | Delete
*
[1052] Fix | Delete
* @param array $blockIDs
[1053] Fix | Delete
*/
[1054] Fix | Delete
public static function makePermanentBlockIDs($blockIDs) {
[1055] Fix | Delete
global $wpdb;
[1056] Fix | Delete
$blocksTable = wfBlock::blocksTable();
[1057] Fix | Delete
[1058] Fix | Delete
//TODO: revise this if we support user-customizable durations
[1059] Fix | Delete
$supportedTypes = array(
[1060] Fix | Delete
self::TYPE_WFSN_TEMPORARY,
[1061] Fix | Delete
self::TYPE_RATE_BLOCK,
[1062] Fix | Delete
self::TYPE_RATE_THROTTLE,
[1063] Fix | Delete
self::TYPE_LOCKOUT,
[1064] Fix | Delete
self::TYPE_IP_AUTOMATIC_TEMPORARY,
[1065] Fix | Delete
);
[1066] Fix | Delete
[1067] Fix | Delete
$blockIDs = array_map('intval', $blockIDs);
[1068] Fix | Delete
$query = $wpdb->prepare("UPDATE `{$blocksTable}` SET `expiration` = %d, `type` = %d WHERE `id` IN (" . implode(', ', $blockIDs) . ") AND `type` IN (" . implode(', ', $supportedTypes) . ") AND (`expiration` > UNIX_TIMESTAMP())", self::DURATION_FOREVER, self::TYPE_IP_AUTOMATIC_PERMANENT);
[1069] Fix | Delete
$wpdb->query($query);
[1070] Fix | Delete
[1071] Fix | Delete
$supportedTypes = array(
[1072] Fix | Delete
self::TYPE_IP_MANUAL,
[1073] Fix | Delete
);
[1074] Fix | Delete
[1075] Fix | Delete
$blockIDs = array_map('intval', $blockIDs);
[1076] Fix | Delete
$query = $wpdb->prepare("UPDATE `{$blocksTable}` SET `expiration` = %d, `type` = %d WHERE `id` IN (" . implode(', ', $blockIDs) . ") AND `type` IN (" . implode(', ', $supportedTypes) . ") AND (`expiration` > UNIX_TIMESTAMP())", self::DURATION_FOREVER, self::TYPE_IP_MANUAL);
[1077] Fix | Delete
$wpdb->query($query);
[1078] Fix | Delete
}
[1079] Fix | Delete
[1080] Fix | Delete
/**
[1081] Fix | Delete
* Removes all specific IP blocks and lockouts that can result in the given IP being blocked.
[1082] Fix | Delete
*
[1083] Fix | Delete
* @param string $ip
[1084] Fix | Delete
*/
[1085] Fix | Delete
public static function unblockIP($ip) {
[1086] Fix | Delete
global $wpdb;
[1087] Fix | Delete
$blocksTable = wfBlock::blocksTable();
[1088] Fix | Delete
$ipHex = wfDB::binaryValueToSQLHex(wfUtils::inet_pton($ip));
[1089] Fix | Delete
$wpdb->query("DELETE FROM `{$blocksTable}` WHERE `IP` = {$ipHex}");
[1090] Fix | Delete
}
[1091] Fix | Delete
[1092] Fix | Delete
/**
[1093] Fix | Delete
* Removes all lockouts that can result in the given IP being blocked.
[1094] Fix | Delete
*
[1095] Fix | Delete
* @param string $ip
[1096] Fix | Delete
*/
[1097] Fix | Delete
public static function unlockOutIP($ip) {
[1098] Fix | Delete
global $wpdb;
[1099] Fix | Delete
$blocksTable = wfBlock::blocksTable();
[1100] Fix | Delete
$ipHex = wfDB::binaryValueToSQLHex(wfUtils::inet_pton($ip));
[1101] Fix | Delete
$wpdb->query($wpdb->prepare("DELETE FROM `{$blocksTable}` WHERE `IP` = {$ipHex} AND `type` = %d", self::TYPE_LOCKOUT));
[1102] Fix | Delete
}
[1103] Fix | Delete
[1104] Fix | Delete
/**
[1105] Fix | Delete
* Constructs a wfBlock instance. This _does not_ create a new record in the table, only fetches or updates an existing one.
[1106] Fix | Delete
*
[1107] Fix | Delete
* @param $id
[1108] Fix | Delete
* @param bool $type
[1109] Fix | Delete
* @param bool $ip
[1110] Fix | Delete
* @param bool $blockedTime
[1111] Fix | Delete
* @param bool $reason
[1112] Fix | Delete
* @param bool $lastAttempt
[1113] Fix | Delete
* @param bool $blockedHits
[1114] Fix | Delete
* @param bool $expiration
[1115] Fix | Delete
* @param bool $parameters
[1116] Fix | Delete
*/
[1117] Fix | Delete
public function __construct($id, $type = false, $ip = false, $blockedTime = false, $reason = false, $lastAttempt = false, $blockedHits = false, $expiration = false, $parameters = false) {
[1118] Fix | Delete
$this->_id = $id;
[1119] Fix | Delete
$this->_type = $type;
[1120] Fix | Delete
$this->_ip = $ip;
[1121] Fix | Delete
$this->_blockedTime = $blockedTime;
[1122] Fix | Delete
$this->_reason = $reason;
[1123] Fix | Delete
$this->_lastAttempt = $lastAttempt;
[1124] Fix | Delete
$this->_blockedHits = $blockedHits;
[1125] Fix | Delete
$this->_expiration = $expiration;
[1126] Fix | Delete
$this->_parameters = $parameters;
[1127] Fix | Delete
}
[1128] Fix | Delete
[1129] Fix | Delete
public function __get($key) {
[1130] Fix | Delete
switch ($key) {
[1131] Fix | Delete
case 'id':
[1132] Fix | Delete
return $this->_id;
[1133] Fix | Delete
case 'type':
[1134] Fix | Delete
if ($this->_type === false) { $this->_fetch(); }
[1135] Fix | Delete
return $this->_type;
[1136] Fix | Delete
case 'ip':
[1137] Fix | Delete
if ($this->_type === false) { $this->_fetch(); }
[1138] Fix | Delete
return $this->_ip;
[1139] Fix | Delete
case 'blockedTime':
[1140] Fix | Delete
if ($this->_type === false) { $this->_fetch(); }
[1141] Fix | Delete
return $this->_blockedTime;
[1142] Fix | Delete
case 'reason':
[1143] Fix | Delete
if ($this->_type === false) { $this->_fetch(); }
[1144] Fix | Delete
return $this->_reason;
[1145] Fix | Delete
case 'lastAttempt':
[1146] Fix | Delete
if ($this->_type === false) { $this->_fetch(); }
[1147] Fix | Delete
return $this->_lastAttempt;
[1148] Fix | Delete
case 'blockedHits':
[1149] Fix | Delete
if ($this->_type === false) { $this->_fetch(); }
[1150] Fix | Delete
return $this->_blockedHits;
[1151] Fix | Delete
case 'expiration':
[1152] Fix | Delete
if ($this->_type === false) { $this->_fetch(); }
[1153] Fix | Delete
return $this->_expiration;
[1154] Fix | Delete
case 'parameters':
[1155] Fix | Delete
if ($this->_type === false) { $this->_fetch(); }
[1156] Fix | Delete
return $this->_parameters;
[1157] Fix | Delete
[1158] Fix | Delete
//Country
[1159] Fix | Delete
case 'blockLogin':
[1160] Fix | Delete
if ($this->type != self::TYPE_COUNTRY) { throw new OutOfBoundsException("{$key} is not a valid property for this block type"); }
[1161] Fix | Delete
return $this->parameters['blockLogin'];
[1162] Fix | Delete
case 'blockSite':
[1163] Fix | Delete
if ($this->type != self::TYPE_COUNTRY) { throw new OutOfBoundsException("{$key} is not a valid property for this block type"); }
[1164] Fix | Delete
return $this->parameters['blockSite'];
[1165] Fix | Delete
case 'countries':
[1166] Fix | Delete
if ($this->type != self::TYPE_COUNTRY) { throw new OutOfBoundsException("{$key} is not a valid property for this block type"); }
[1167] Fix | Delete
return $this->parameters['countries'];
[1168] Fix | Delete
[1169] Fix | Delete
//Pattern
[1170] Fix | Delete
case 'ipRange':
[1171] Fix | Delete
if ($this->type != self::TYPE_PATTERN) { throw new OutOfBoundsException("{$key} is not a valid property for this block type"); }
[1172] Fix | Delete
return $this->parameters['ipRange'];
[1173] Fix | Delete
case 'hostname':
[1174] Fix | Delete
if ($this->type != self::TYPE_PATTERN) { throw new OutOfBoundsException("{$key} is not a valid property for this block type"); }
[1175] Fix | Delete
return $this->parameters['hostname'];
[1176] Fix | Delete
case 'userAgent':
[1177] Fix | Delete
if ($this->type != self::TYPE_PATTERN) { throw new OutOfBoundsException("{$key} is not a valid property for this block type"); }
[1178] Fix | Delete
return $this->parameters['userAgent'];
[1179] Fix | Delete
case 'referrer':
[1180] Fix | Delete
if ($this->type != self::TYPE_PATTERN) { throw new OutOfBoundsException("{$key} is not a valid property for this block type"); }
[1181] Fix | Delete
return $this->parameters['referrer'];
[1182] Fix | Delete
}
[1183] Fix | Delete
[1184] Fix | Delete
throw new OutOfBoundsException("{$key} is not a valid property");
[1185] Fix | Delete
}
[1186] Fix | Delete
[1187] Fix | Delete
public function __isset($key) {
[1188] Fix | Delete
switch ($key) {
[1189] Fix | Delete
case 'id':
[1190] Fix | Delete
case 'type':
[1191] Fix | Delete
case 'ip':
[1192] Fix | Delete
case 'blockedTime':
[1193] Fix | Delete
case 'reason':
[1194] Fix | Delete
case 'lastAttempt':
[1195] Fix | Delete
case 'blockedHits':
[1196] Fix | Delete
case 'expiration':
[1197] Fix | Delete
return true;
[1198] Fix | Delete
case 'parameters':
[1199] Fix | Delete
if ($this->_type === false) { $this->_fetch(); }
[1200] Fix | Delete
return !empty($this->_parameters);
[1201] Fix | Delete
[1202] Fix | Delete
//Country
[1203] Fix | Delete
case 'blockLogin':
[1204] Fix | Delete
if ($this->type != self::TYPE_COUNTRY) { return false; }
[1205] Fix | Delete
return !empty($this->parameters['blockLogin']);
[1206] Fix | Delete
case 'blockSite':
[1207] Fix | Delete
if ($this->type != self::TYPE_COUNTRY) { return false; }
[1208] Fix | Delete
return !empty($this->parameters['blockSite']);
[1209] Fix | Delete
case 'countries':
[1210] Fix | Delete
if ($this->type != self::TYPE_COUNTRY) { return false; }
[1211] Fix | Delete
return !empty($this->parameters['countries']);
[1212] Fix | Delete
[1213] Fix | Delete
//Pattern
[1214] Fix | Delete
case 'ipRange':
[1215] Fix | Delete
if ($this->type != self::TYPE_PATTERN) { return false; }
[1216] Fix | Delete
return !empty($this->parameters['ipRange']);
[1217] Fix | Delete
case 'hostname':
[1218] Fix | Delete
if ($this->type != self::TYPE_PATTERN) { return false; }
[1219] Fix | Delete
return !empty($this->parameters['hostname']);
[1220] Fix | Delete
case 'userAgent':
[1221] Fix | Delete
if ($this->type != self::TYPE_PATTERN) { return false; }
[1222] Fix | Delete
return !empty($this->parameters['userAgent']);
[1223] Fix | Delete
case 'referrer':
[1224] Fix | Delete
if ($this->type != self::TYPE_PATTERN) { return false; }
[1225] Fix | Delete
return !empty($this->parameters['referrer']);
[1226] Fix | Delete
}
[1227] Fix | Delete
[1228] Fix | Delete
return false;
[1229] Fix | Delete
}
[1230] Fix | Delete
[1231] Fix | Delete
/**
[1232] Fix | Delete
* Fetches the record for the block from the database and populates the instance variables.
[1233] Fix | Delete
*/
[1234] Fix | Delete
private function _fetch() {
[1235] Fix | Delete
global $wpdb;
[1236] Fix | Delete
$blocksTable = wfBlock::blocksTable();
[1237] Fix | Delete
$row = $wpdb->get_row($wpdb->prepare("SELECT * FROM `{$blocksTable}` WHERE `id` = %d", $this->id), ARRAY_A);
[1238] Fix | Delete
if ($row !== null) {
[1239] Fix | Delete
$this->_type = $row['type'];
[1240] Fix | Delete
[1241] Fix | Delete
$ip = $row['IP'];
[1242] Fix | Delete
if ($ip == self::MARKER_COUNTRY || $ip == self::MARKER_PATTERN) {
[1243] Fix | Delete
$this->_ip = null;
[1244] Fix | Delete
}
[1245] Fix | Delete
else {
[1246] Fix | Delete
$this->_ip = wfUtils::inet_ntop($ip);
[1247] Fix | Delete
}
[1248] Fix | Delete
[1249] Fix | Delete
$this->_blockedTime = $row['blockedTime'];
[1250] Fix | Delete
$this->_reason = $row['reason'];
[1251] Fix | Delete
$this->_lastAttempt = $row['lastAttempt'];
[1252] Fix | Delete
$this->_blockedHits = $row['blockedHits'];
[1253] Fix | Delete
$this->_expiration = $row['expiration'];
[1254] Fix | Delete
[1255] Fix | Delete
$parameters = $row['parameters'];
[1256] Fix | Delete
if ($parameters === null) {
[1257] Fix | Delete
$this->_parameters = null;
[1258] Fix | Delete
}
[1259] Fix | Delete
else {
[1260] Fix | Delete
$this->_parameters = @json_decode($parameters, true);
[1261] Fix | Delete
}
[1262] Fix | Delete
}
[1263] Fix | Delete
}
[1264] Fix | Delete
[1265] Fix | Delete
/**
[1266] Fix | Delete
* Tests the block parameters against the given request. If matched, this will return the corresponding wfBlock::MATCH_
[1267] Fix | Delete
* constant. If not, it will return wfBlock::MATCH_NONE.
[1268] Fix | Delete
*
[1269] Fix | Delete
* @param $ip
[1270] Fix | Delete
* @param $userAgent
[1271] Fix | Delete
* @param $referrer
[1272] Fix | Delete
* @return int
[1273] Fix | Delete
*/
[1274] Fix | Delete
public function matchRequest($ip, $userAgent, $referrer) {
[1275] Fix | Delete
switch ($this->type) {
[1276] Fix | Delete
case self::TYPE_IP_MANUAL:
[1277] Fix | Delete
case self::TYPE_IP_AUTOMATIC_TEMPORARY:
[1278] Fix | Delete
case self::TYPE_IP_AUTOMATIC_PERMANENT:
[1279] Fix | Delete
case self::TYPE_WFSN_TEMPORARY:
[1280] Fix | Delete
case self::TYPE_RATE_BLOCK:
[1281] Fix | Delete
case self::TYPE_RATE_THROTTLE:
[1282] Fix | Delete
if (wfUtils::inet_pton($ip) == wfUtils::inet_pton($this->ip))
[1283] Fix | Delete
{
[1284] Fix | Delete
return self::MATCH_IP;
[1285] Fix | Delete
}
[1286] Fix | Delete
break;
[1287] Fix | Delete
case self::TYPE_PATTERN:
[1288] Fix | Delete
$match = (!empty($this->ipRange) || !empty($this->hostname) || !empty($this->userAgent) || !empty($this->referrer));
[1289] Fix | Delete
if (!empty($this->ipRange)) {
[1290] Fix | Delete
$range = new wfUserIPRange($this->ipRange);
[1291] Fix | Delete
$match = $match && $range->isIPInRange($ip);
[1292] Fix | Delete
}
[1293] Fix | Delete
if (!empty($this->hostname)) {
[1294] Fix | Delete
$hostname = wfUtils::reverseLookup($ip);
[1295] Fix | Delete
$match = $match && preg_match(wfUtils::patternToRegex($this->hostname), $hostname);
[1296] Fix | Delete
}
[1297] Fix | Delete
if (!empty($this->userAgent)) {
[1298] Fix | Delete
$match = $match && fnmatch($this->userAgent, $userAgent, FNM_CASEFOLD);
[1299] Fix | Delete
}
[1300] Fix | Delete
if (!empty($this->referrer)) {
[1301] Fix | Delete
$match = $match && fnmatch($this->referrer, $referrer, FNM_CASEFOLD);
[1302] Fix | Delete
}
[1303] Fix | Delete
[1304] Fix | Delete
if ($match) {
[1305] Fix | Delete
return self::MATCH_PATTERN;
[1306] Fix | Delete
}
[1307] Fix | Delete
[1308] Fix | Delete
break;
[1309] Fix | Delete
case self::TYPE_COUNTRY:
[1310] Fix | Delete
if (!wfConfig::get('isPaid')) {
[1311] Fix | Delete
return self::MATCH_NONE;
[1312] Fix | Delete
}
[1313] Fix | Delete
[1314] Fix | Delete
//Bypass Redirect URL Hit
[1315] Fix | Delete
$bareRequestURI = wfUtils::extractBareURI($_SERVER['REQUEST_URI']);
[1316] Fix | Delete
$bareBypassRedirURI = wfUtils::extractBareURI(wfConfig::get('cbl_bypassRedirURL', ''));
[1317] Fix | Delete
if ($bareBypassRedirURI && $bareRequestURI == $bareBypassRedirURI) {
[1318] Fix | Delete
$bypassRedirDest = wfConfig::get('cbl_bypassRedirDest', '');
[1319] Fix | Delete
if ($bypassRedirDest) {
[1320] Fix | Delete
wfUtils::setcookie('wfCBLBypass', wfBlock::countryBlockingBypassCookieValue(), time() + (86400 * 365), '/', null, wfUtils::isFullSSL(), true);
[1321] Fix | Delete
return self::MATCH_COUNTRY_REDIR_BYPASS;
[1322] Fix | Delete
}
[1323] Fix | Delete
}
[1324] Fix | Delete
[1325] Fix | Delete
//Bypass View URL Hit
[1326] Fix | Delete
$bareBypassViewURI = wfUtils::extractBareURI(wfConfig::get('cbl_bypassViewURL', ''));
[1327] Fix | Delete
if ($bareBypassViewURI && $bareBypassViewURI == $bareRequestURI) {
[1328] Fix | Delete
wfUtils::setcookie('wfCBLBypass', wfBlock::countryBlockingBypassCookieValue(), time() + (86400 * 365), '/', null, wfUtils::isFullSSL(), true);
[1329] Fix | Delete
return self::MATCH_NONE;
[1330] Fix | Delete
}
[1331] Fix | Delete
[1332] Fix | Delete
//Early exit checks
[1333] Fix | Delete
if ($this->_shouldBypassCountryBlocking()) { //Has valid bypass cookie
[1334] Fix | Delete
return self::MATCH_NONE;
[1335] Fix | Delete
}
[1336] Fix | Delete
[1337] Fix | Delete
if ($this->blockLogin) {
[1338] Fix | Delete
add_filter('authenticate', array($this, '_checkForBlockedCountryFilter'), 1, 1);
[1339] Fix | Delete
}
[1340] Fix | Delete
[1341] Fix | Delete
if (!$this->blockLogin && $this->_isAuthRequest()) { //Not blocking login and this is a login request
[1342] Fix | Delete
return self::MATCH_NONE;
[1343] Fix | Delete
}
[1344] Fix | Delete
else if (!$this->blockSite && !$this->_isAuthRequest()) { //Not blocking site and this may be a site request
[1345] Fix | Delete
return self::MATCH_NONE;
[1346] Fix | Delete
}
[1347] Fix | Delete
else if (is_user_logged_in() && !wfConfig::get('cbl_loggedInBlocked', false)) { //Not blocking logged in users and a login session exists
[1348] Fix | Delete
return self::MATCH_NONE;
[1349] Fix | Delete
}
[1350] Fix | Delete
[1351] Fix | Delete
//Block everything
[1352] Fix | Delete
if ($this->blockSite && $this->blockLogin) {
[1353] Fix | Delete
return $this->_checkForBlockedCountry();
[1354] Fix | Delete
}
[1355] Fix | Delete
[1356] Fix | Delete
//Block the login form itself and any attempt to authenticate
[1357] Fix | Delete
if ($this->blockLogin && $this->_isAuthRequest()) {
[1358] Fix | Delete
return $this->_checkForBlockedCountry();
[1359] Fix | Delete
}
[1360] Fix | Delete
[1361] Fix | Delete
//Block requests that aren't to the login page, xmlrpc.php, or a user already logged in
[1362] Fix | Delete
if ($this->blockSite && !$this->_isAuthRequest() && !defined('XMLRPC_REQUEST')) {
[1363] Fix | Delete
return $this->_checkForBlockedCountry();
[1364] Fix | Delete
}
[1365] Fix | Delete
[1366] Fix | Delete
//XMLRPC is inaccesible when public portion of the site and auth is disabled
[1367] Fix | Delete
if ($this->blockLogin && $this->blockSite && defined('XMLRPC_REQUEST')) {
[1368] Fix | Delete
return $this->_checkForBlockedCountry();
[1369] Fix | Delete
}
[1370] Fix | Delete
[1371] Fix | Delete
break;
[1372] Fix | Delete
}
[1373] Fix | Delete
[1374] Fix | Delete
return self::MATCH_NONE;
[1375] Fix | Delete
}
[1376] Fix | Delete
[1377] Fix | Delete
/**
[1378] Fix | Delete
* Returns whether or not the current request should be treated as an auth request.
[1379] Fix | Delete
*
[1380] Fix | Delete
* @return bool
[1381] Fix | Delete
*/
[1382] Fix | Delete
private function _isAuthRequest() {
[1383] Fix | Delete
if ((strpos($_SERVER['REQUEST_URI'], '/wp-login.php') !== false)) {
[1384] Fix | Delete
return true;
[1385] Fix | Delete
}
[1386] Fix | Delete
return false;
[1387] Fix | Delete
}
[1388] Fix | Delete
[1389] Fix | Delete
/**
[1390] Fix | Delete
* Tests whether or not the country blocking bypass cookie is set and valid.
[1391] Fix | Delete
*
[1392] Fix | Delete
* @return bool
[1393] Fix | Delete
*/
[1394] Fix | Delete
private function _shouldBypassCountryBlocking() {
[1395] Fix | Delete
if (isset($_COOKIE['wfCBLBypass']) && $_COOKIE['wfCBLBypass'] == wfBlock::countryBlockingBypassCookieValue()) {
[1396] Fix | Delete
return true;
[1397] Fix | Delete
}
[1398] Fix | Delete
return false;
[1399] Fix | Delete
}
[1400] Fix | Delete
[1401] Fix | Delete
/**
[1402] Fix | Delete
* Checks the country block against the requesting IP, returning the action to take.
[1403] Fix | Delete
*
[1404] Fix | Delete
* @return int
[1405] Fix | Delete
*/
[1406] Fix | Delete
private function _checkForBlockedCountry() {
[1407] Fix | Delete
$blockedCountries = $this->countries;
[1408] Fix | Delete
$bareRequestURI = untrailingslashit(wfUtils::extractBareURI($_SERVER['REQUEST_URI']));
[1409] Fix | Delete
$IP = wfUtils::getIP();
[1410] Fix | Delete
if ($country = wfUtils::IP2Country($IP)) {
[1411] Fix | Delete
foreach ($blockedCountries as $blocked) {
[1412] Fix | Delete
if (strtoupper($blocked) == strtoupper($country)) { //At this point we know the user has been blocked
[1413] Fix | Delete
if (wfConfig::get('cbl_action') == 'redir') {
[1414] Fix | Delete
$redirURL = wfConfig::get('cbl_redirURL');
[1415] Fix | Delete
$eRedirHost = wfUtils::extractHostname($redirURL);
[1416] Fix | Delete
$isExternalRedir = false;
[1417] Fix | Delete
if ($eRedirHost && $eRedirHost != wfUtils::extractHostname(home_url())) { //It's an external redirect...
[1418] Fix | Delete
$isExternalRedir = true;
[1419] Fix | Delete
}
[1420] Fix | Delete
[1421] Fix | Delete
if ((!$isExternalRedir) && untrailingslashit(wfUtils::extractBareURI($redirURL)) == $bareRequestURI) { //Is this the URI we want to redirect to, then don't block it
[1422] Fix | Delete
return self::MATCH_NONE;
[1423] Fix | Delete
}
[1424] Fix | Delete
else {
[1425] Fix | Delete
return self::MATCH_COUNTRY_REDIR;
[1426] Fix | Delete
}
[1427] Fix | Delete
}
[1428] Fix | Delete
else {
[1429] Fix | Delete
return self::MATCH_COUNTRY_BLOCK;
[1430] Fix | Delete
}
[1431] Fix | Delete
}
[1432] Fix | Delete
}
[1433] Fix | Delete
}
[1434] Fix | Delete
[1435] Fix | Delete
return self::MATCH_NONE;
[1436] Fix | Delete
}
[1437] Fix | Delete
[1438] Fix | Delete
/**
[1439] Fix | Delete
* Filter hook for the country blocking check. Does nothing if not blocked, otherwise presents the block page and exits.
[1440] Fix | Delete
*
[1441] Fix | Delete
* Note: Must remain `public` for callback to work.
[1442] Fix | Delete
*/
[1443] Fix | Delete
public function _checkForBlockedCountryFilter($user) {
[1444] Fix | Delete
$block = $this->_checkForBlockedCountry();
[1445] Fix | Delete
if ($block == self::MATCH_NONE) {
[1446] Fix | Delete
return $user;
[1447] Fix | Delete
}
[1448] Fix | Delete
[1449] Fix | Delete
$log = wfLog::shared();
[1450] Fix | Delete
$log->getCurrentRequest()->actionDescription = __('blocked access via country blocking', 'wordfence');
[1451] Fix | Delete
wfConfig::inc('totalCountryBlocked');
[1452] Fix | Delete
wfActivityReport::logBlockedIP(wfUtils::getIP(), null, 'country');
[1453] Fix | Delete
$log->do503(3600, __('Access from your area has been temporarily limited for security reasons', 'wordfence')); //exits
[1454] Fix | Delete
}
[1455] Fix | Delete
[1456] Fix | Delete
/**
[1457] Fix | Delete
* Adds $quantity to the blocked count and sets the timestamp for lastAttempt.
[1458] Fix | Delete
*
[1459] Fix | Delete
* @param int $quantity
[1460] Fix | Delete
* @param bool|int $timestamp
[1461] Fix | Delete
*/
[1462] Fix | Delete
public function recordBlock($quantity = 1, $timestamp = false) {
[1463] Fix | Delete
if ($timestamp === false) {
[1464] Fix | Delete
$timestamp = time();
[1465] Fix | Delete
}
[1466] Fix | Delete
[1467] Fix | Delete
global $wpdb;
[1468] Fix | Delete
$blocksTable = wfBlock::blocksTable();
[1469] Fix | Delete
$wpdb->query($wpdb->prepare("UPDATE `{$blocksTable}` SET `blockedHits` = `blockedHits` + %d, `lastAttempt` = GREATEST(`lastAttempt`, %d) WHERE `id` = %d", $quantity, $timestamp, $this->id));
[1470] Fix | Delete
$this->_type = false; //Trigger a re-fetch next access
[1471] Fix | Delete
}
[1472] Fix | Delete
[1473] Fix | Delete
/**
[1474] Fix | Delete
* Returns an array suitable for JSON of the values needed to edit the block.
[1475] Fix | Delete
*
[1476] Fix | Delete
* @return array
[1477] Fix | Delete
*/
[1478] Fix | Delete
public function editValues() {
[1479] Fix | Delete
switch ($this->type) {
[1480] Fix | Delete
case self::TYPE_COUNTRY:
[1481] Fix | Delete
return array(
[1482] Fix | Delete
'blockLogin' => wfUtils::truthyToInt($this->blockLogin),
[1483] Fix | Delete
'blockSite' => wfUtils::truthyToInt($this->blockSite),
[1484] Fix | Delete
'countries' => $this->countries,
[1485] Fix | Delete
'reason' => $this->reason,
[1486] Fix | Delete
'expiration' => $this->expiration,
[1487] Fix | Delete
);
[1488] Fix | Delete
}
[1489] Fix | Delete
[1490] Fix | Delete
return array();
[1491] Fix | Delete
}
[1492] Fix | Delete
}
[1493] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function