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.../lib
File: wfUtils.php
$ip_printable = $IP;
[1500] Fix | Delete
$ip_bin = wfUtils::inet_pton($IP);
[1501] Fix | Delete
}
[1502] Fix | Delete
[1503] Fix | Delete
$ipHex = wfDB::binaryValueToSQLHex($ip_bin);
[1504] Fix | Delete
$row = $db->querySingleRec("select IP, ctime, failed, city, region, countryName, countryCode, lat, lon, unix_timestamp() - ctime as age from " . $locsTable . " where IP={$ipHex}");
[1505] Fix | Delete
if($row){
[1506] Fix | Delete
if($row['age'] > WORDFENCE_MAX_IPLOC_AGE){
[1507] Fix | Delete
$ipHex = wfDB::binaryValueToSQLHex($row['IP']);
[1508] Fix | Delete
$db->queryWrite("delete from " . $locsTable . " where IP={$ipHex}");
[1509] Fix | Delete
} else {
[1510] Fix | Delete
if($row['failed'] == 1){
[1511] Fix | Delete
$IPLocs[$ip_printable] = false;
[1512] Fix | Delete
} else {
[1513] Fix | Delete
$row['IP'] = self::inet_ntop($row['IP']);
[1514] Fix | Delete
$row['region'] = wfUtils::shouldDisplayRegion($row['countryName']) ? $row['region'] : '';
[1515] Fix | Delete
$IPLocs[$ip_printable] = $row;
[1516] Fix | Delete
}
[1517] Fix | Delete
}
[1518] Fix | Delete
}
[1519] Fix | Delete
if(! isset($IPLocs[$ip_printable])){
[1520] Fix | Delete
$toResolve[] = $ip_printable;
[1521] Fix | Delete
}
[1522] Fix | Delete
}
[1523] Fix | Delete
if(sizeof($toResolve) > 0){
[1524] Fix | Delete
if (wfConfig::get('enableRemoteIpLookup', true)) {
[1525] Fix | Delete
$api = new wfAPI(wfConfig::get('apiKey'), wfUtils::getWPVersion());
[1526] Fix | Delete
try {
[1527] Fix | Delete
$freshIPs = $api->call('resolve_ips', array(), array(
[1528] Fix | Delete
'ips' => implode(',', $toResolve)
[1529] Fix | Delete
));
[1530] Fix | Delete
} catch(Exception $e){
[1531] Fix | Delete
wordfence::status(2, 'error', sprintf(/* translators: Error message. */ __("Call to Wordfence API to resolve IPs failed: %s", 'wordfence'), $e->getMessage()));
[1532] Fix | Delete
return array();
[1533] Fix | Delete
}
[1534] Fix | Delete
}
[1535] Fix | Delete
else {
[1536] Fix | Delete
require_once(__DIR__ . '/wfIpLocator.php');
[1537] Fix | Delete
$locator = wfIpLocator::getInstance();
[1538] Fix | Delete
$freshIPs = array();
[1539] Fix | Delete
$locale = get_locale();
[1540] Fix | Delete
foreach ($toResolve as $ip) {
[1541] Fix | Delete
$record = $locator->locate($ip);
[1542] Fix | Delete
if ($record !== null) {
[1543] Fix | Delete
$countryCode = $record->getCountryCode();
[1544] Fix | Delete
if ($countryCode !== null) {
[1545] Fix | Delete
$countryName = $record->getCountryName($locale);
[1546] Fix | Delete
if ($countryName === null)
[1547] Fix | Delete
$countryName = $countryCode;
[1548] Fix | Delete
$freshIPs[$ip] = array($countryCode, $countryName);
[1549] Fix | Delete
continue;
[1550] Fix | Delete
}
[1551] Fix | Delete
}
[1552] Fix | Delete
$freshIPs[$ip] = 'failed';
[1553] Fix | Delete
}
[1554] Fix | Delete
}
[1555] Fix | Delete
if(is_array($freshIPs)){
[1556] Fix | Delete
foreach($freshIPs as $IP => $value){
[1557] Fix | Delete
$IP_bin = wfUtils::inet_pton($IP);
[1558] Fix | Delete
$ipHex = wfDB::binaryValueToSQLHex($IP_bin);
[1559] Fix | Delete
if($value == 'failed'){
[1560] Fix | Delete
$db->queryWrite("insert IGNORE into " . $locsTable . " (IP, ctime, failed) values ({$ipHex}, unix_timestamp(), 1)");
[1561] Fix | Delete
$IPLocs[$IP] = false;
[1562] Fix | Delete
} else if(is_array($value)){
[1563] Fix | Delete
for($i = 0; $i <= 5; $i++){
[1564] Fix | Delete
//Prevent warnings in debug mode about uninitialized values
[1565] Fix | Delete
if(! isset($value[$i])){ $value[$i] = ''; }
[1566] Fix | Delete
}
[1567] Fix | Delete
$db->queryWrite("insert IGNORE into " . $locsTable . " (IP, ctime, failed, city, region, countryName, countryCode, lat, lon) values ({$ipHex}, unix_timestamp(), 0, '%s', '%s', '%s', '%s', %s, %s)",
[1568] Fix | Delete
$value[3], //city
[1569] Fix | Delete
$value[2], //region
[1570] Fix | Delete
$value[1], //countryName
[1571] Fix | Delete
$value[0],//countryCode
[1572] Fix | Delete
$value[4],//lat
[1573] Fix | Delete
$value[5]//lon
[1574] Fix | Delete
);
[1575] Fix | Delete
$IPLocs[$IP] = array(
[1576] Fix | Delete
'IP' => $IP,
[1577] Fix | Delete
'city' => $value[3],
[1578] Fix | Delete
'region' => wfUtils::shouldDisplayRegion($value[1]) ? $value[2] : '',
[1579] Fix | Delete
'countryName' => $value[1],
[1580] Fix | Delete
'countryCode' => $value[0],
[1581] Fix | Delete
'lat' => $value[4],
[1582] Fix | Delete
'lon' => $value[5]
[1583] Fix | Delete
);
[1584] Fix | Delete
}
[1585] Fix | Delete
}
[1586] Fix | Delete
}
[1587] Fix | Delete
}
[1588] Fix | Delete
return $IPLocs;
[1589] Fix | Delete
}
[1590] Fix | Delete
[1591] Fix | Delete
public static function reverseLookup($IP) {
[1592] Fix | Delete
static $_memoryCache = array();
[1593] Fix | Delete
if (isset($_memoryCache[$IP])) {
[1594] Fix | Delete
return $_memoryCache[$IP];
[1595] Fix | Delete
}
[1596] Fix | Delete
[1597] Fix | Delete
$db = new wfDB();
[1598] Fix | Delete
$reverseTable = wfDB::networkTable('wfReverseCache');
[1599] Fix | Delete
$IPn = wfUtils::inet_pton($IP);
[1600] Fix | Delete
$ipHex = wfDB::binaryValueToSQLHex($IPn);
[1601] Fix | Delete
$host = $db->querySingle("select host from " . $reverseTable . " where IP={$ipHex} and unix_timestamp() - lastUpdate < %d", WORDFENCE_REVERSE_LOOKUP_CACHE_TIME);
[1602] Fix | Delete
if (!$host) {
[1603] Fix | Delete
// This function works for IPv4 or IPv6
[1604] Fix | Delete
if (function_exists('gethostbyaddr')) {
[1605] Fix | Delete
$host = @gethostbyaddr($IP);
[1606] Fix | Delete
}
[1607] Fix | Delete
if (!$host) {
[1608] Fix | Delete
$ptr = false;
[1609] Fix | Delete
if (filter_var($IP, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false) {
[1610] Fix | Delete
$ptr = implode(".", array_reverse(explode(".", $IP))) . ".in-addr.arpa";
[1611] Fix | Delete
} else if (filter_var($IP, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false) {
[1612] Fix | Delete
$ptr = implode(".", array_reverse(str_split(bin2hex($IPn)))) . ".ip6.arpa";
[1613] Fix | Delete
}
[1614] Fix | Delete
[1615] Fix | Delete
if ($ptr && function_exists('dns_get_record')) {
[1616] Fix | Delete
$host = @dns_get_record($ptr, DNS_PTR);
[1617] Fix | Delete
if ($host) {
[1618] Fix | Delete
$host = $host[0]['target'];
[1619] Fix | Delete
}
[1620] Fix | Delete
}
[1621] Fix | Delete
}
[1622] Fix | Delete
$_memoryCache[$IP] = $host;
[1623] Fix | Delete
if (!$host) {
[1624] Fix | Delete
$host = 'NONE';
[1625] Fix | Delete
}
[1626] Fix | Delete
$db->queryWrite("insert into " . $reverseTable . " (IP, host, lastUpdate) values ({$ipHex}, '%s', unix_timestamp()) ON DUPLICATE KEY UPDATE host='%s', lastUpdate=unix_timestamp()", $host, $host);
[1627] Fix | Delete
}
[1628] Fix | Delete
if ($host == 'NONE') {
[1629] Fix | Delete
$_memoryCache[$IP] = '';
[1630] Fix | Delete
return '';
[1631] Fix | Delete
} else {
[1632] Fix | Delete
$_memoryCache[$IP] = $host;
[1633] Fix | Delete
return $host;
[1634] Fix | Delete
}
[1635] Fix | Delete
}
[1636] Fix | Delete
public static function errorsOff(){
[1637] Fix | Delete
self::$lastErrorReporting = @ini_get('error_reporting');
[1638] Fix | Delete
@error_reporting(0);
[1639] Fix | Delete
self::$lastDisplayErrors = @ini_get('display_errors');
[1640] Fix | Delete
self::iniSet('display_errors', 0);
[1641] Fix | Delete
if(class_exists('wfScan')){ wfScan::$errorHandlingOn = false; }
[1642] Fix | Delete
}
[1643] Fix | Delete
public static function errorsOn(){
[1644] Fix | Delete
@error_reporting(self::$lastErrorReporting);
[1645] Fix | Delete
self::iniSet('display_errors', self::$lastDisplayErrors);
[1646] Fix | Delete
if(class_exists('wfScan')){ wfScan::$errorHandlingOn = true; }
[1647] Fix | Delete
}
[1648] Fix | Delete
//Note this function may report files that are too big which actually are not too big but are unseekable and throw an error on fseek(). But that's intentional
[1649] Fix | Delete
public static function fileTooBig($file, &$size = false, &$handle = false){ //Deals with files > 2 gigs on 32 bit systems which are reported with the wrong size due to integer overflow
[1650] Fix | Delete
if (!@is_file($file) || !@is_readable($file)) { return false; } //Only apply to readable files
[1651] Fix | Delete
wfUtils::errorsOff();
[1652] Fix | Delete
$fh = @fopen($file, 'rb');
[1653] Fix | Delete
wfUtils::errorsOn();
[1654] Fix | Delete
if(! $fh){ return false; }
[1655] Fix | Delete
try {
[1656] Fix | Delete
if(@fseek($fh, WORDFENCE_MAX_FILE_SIZE_OFFSET, SEEK_SET) === 0 && !empty(fread($fh, 1))){
[1657] Fix | Delete
return true;
[1658] Fix | Delete
} //Otherwise we couldn't seek there so it must be smaller
[1659] Fix | Delete
if ($size !== false && @fseek($fh, 0, SEEK_END) === 0) {
[1660] Fix | Delete
$size = @ftell($fh);
[1661] Fix | Delete
if ($size === false)
[1662] Fix | Delete
$size = 0; // Assume 0 if unable to determine file size
[1663] Fix | Delete
}
[1664] Fix | Delete
return false;
[1665] Fix | Delete
} catch(Exception $e){
[1666] Fix | Delete
return true; //If we get an error don't scan this file, report it's too big.
[1667] Fix | Delete
} finally {
[1668] Fix | Delete
if ($handle === false) {
[1669] Fix | Delete
fclose($fh);
[1670] Fix | Delete
}
[1671] Fix | Delete
else {
[1672] Fix | Delete
$handle = $fh;
[1673] Fix | Delete
}
[1674] Fix | Delete
}
[1675] Fix | Delete
}
[1676] Fix | Delete
public static function fileOver2Gigs($file){ //Surround calls to this func with try/catch because fseek may throw error.
[1677] Fix | Delete
$fh = @fopen($file, 'rb');
[1678] Fix | Delete
if(! $fh){ return false; }
[1679] Fix | Delete
$offset = 2147483647;
[1680] Fix | Delete
$tooBig = false;
[1681] Fix | Delete
//My throw an error so surround calls to this func with try/catch
[1682] Fix | Delete
if(@fseek($fh, $offset, SEEK_SET) === 0){
[1683] Fix | Delete
if(strlen(fread($fh, 1)) === 1){
[1684] Fix | Delete
$tooBig = true;
[1685] Fix | Delete
}
[1686] Fix | Delete
} //Otherwise we couldn't seek there so it must be smaller
[1687] Fix | Delete
@fclose($fh);
[1688] Fix | Delete
return $tooBig;
[1689] Fix | Delete
}
[1690] Fix | Delete
public static function countryCode2Name($code){
[1691] Fix | Delete
require(dirname(__FILE__) . '/wfBulkCountries.php'); /** @var array $wfBulkCountries */
[1692] Fix | Delete
if(isset($wfBulkCountries[$code])){
[1693] Fix | Delete
return $wfBulkCountries[$code];
[1694] Fix | Delete
} else {
[1695] Fix | Delete
return '';
[1696] Fix | Delete
}
[1697] Fix | Delete
}
[1698] Fix | Delete
public static function shouldDisplayRegion($country) {
[1699] Fix | Delete
$countries_to_show_for = array('united states', 'canada', 'australia');
[1700] Fix | Delete
return in_array(strtolower($country), $countries_to_show_for);
[1701] Fix | Delete
}
[1702] Fix | Delete
public static function extractBareURI($URL){
[1703] Fix | Delete
$URL = preg_replace('/^https?:\/\/[^\/]+/i', '', $URL); //strip of method and host
[1704] Fix | Delete
$URL = preg_replace('/\#.*$/', '', $URL); //strip off fragment
[1705] Fix | Delete
$URL = preg_replace('/\?.*$/', '', $URL); //strip off query string
[1706] Fix | Delete
return $URL;
[1707] Fix | Delete
}
[1708] Fix | Delete
public static function requireIpLocator() {
[1709] Fix | Delete
/**
[1710] Fix | Delete
* This is also used in the WAF so in certain site setups (i.e. nested sites in subdirectories)
[1711] Fix | Delete
* it's possible for this to already have been loaded from a different installation of the
[1712] Fix | Delete
* plugin and hence require_once doesn't help as it's a different file path. There is no guarantee
[1713] Fix | Delete
* that the two plugin installations are the same version, so should the wfIpLocator class or any
[1714] Fix | Delete
* of its dependencies change in a manner that is not backwards compatible, this may need to be
[1715] Fix | Delete
* handled differently.
[1716] Fix | Delete
*/
[1717] Fix | Delete
if (!class_exists('wfIpLocator'))
[1718] Fix | Delete
require_once(__DIR__ . '/wfIpLocator.php');
[1719] Fix | Delete
}
[1720] Fix | Delete
public static function IP2Country($ip){
[1721] Fix | Delete
self::requireIpLocator();
[1722] Fix | Delete
return wfIpLocator::getInstance()->getCountryCode($ip);
[1723] Fix | Delete
}
[1724] Fix | Delete
public static function geoIPVersion() {
[1725] Fix | Delete
self::requireIpLocator();
[1726] Fix | Delete
$version = wfIpLocator::getInstance()->getDatabaseVersion();
[1727] Fix | Delete
return $version === null ? 0 : $version;
[1728] Fix | Delete
}
[1729] Fix | Delete
public static function siteURLRelative(){
[1730] Fix | Delete
if(is_multisite()){
[1731] Fix | Delete
$URL = network_site_url();
[1732] Fix | Delete
} else {
[1733] Fix | Delete
$URL = site_url();
[1734] Fix | Delete
}
[1735] Fix | Delete
$URL = preg_replace('/^https?:\/\/[^\/]+/i', '', $URL);
[1736] Fix | Delete
$URL = rtrim($URL, '/') . '/';
[1737] Fix | Delete
return $URL;
[1738] Fix | Delete
}
[1739] Fix | Delete
public static function localHumanDate(){
[1740] Fix | Delete
return date('l jS \of F Y \a\t h:i:s A', time() + (3600 * get_option('gmt_offset')));
[1741] Fix | Delete
}
[1742] Fix | Delete
public static function localHumanDateShort(){
[1743] Fix | Delete
return date('D jS F \@ h:i:sA', time() + (3600 * get_option('gmt_offset')));
[1744] Fix | Delete
}
[1745] Fix | Delete
public static function funcEnabled($func){
[1746] Fix | Delete
if (!function_exists($func)){ return false; }
[1747] Fix | Delete
if (!is_callable($func)) { return false; }
[1748] Fix | Delete
$disabled = explode(',', ini_get('disable_functions'));
[1749] Fix | Delete
if (in_array($func, $disabled)) {
[1750] Fix | Delete
return false;
[1751] Fix | Delete
}
[1752] Fix | Delete
return true;
[1753] Fix | Delete
}
[1754] Fix | Delete
public static function iniSet($key, $val){
[1755] Fix | Delete
if(self::funcEnabled('ini_set')){
[1756] Fix | Delete
@ini_set($key, $val);
[1757] Fix | Delete
}
[1758] Fix | Delete
}
[1759] Fix | Delete
public static function doNotCache(){
[1760] Fix | Delete
header("Pragma: no-cache");
[1761] Fix | Delete
header("Cache-Control: no-cache, must-revalidate, private, max-age=0");
[1762] Fix | Delete
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); //In the past
[1763] Fix | Delete
if(! defined('DONOTCACHEPAGE')){ define('DONOTCACHEPAGE', true); }
[1764] Fix | Delete
if(! defined('DONOTCACHEDB')){ define('DONOTCACHEDB', true); }
[1765] Fix | Delete
if(! defined('DONOTCDN')){ define('DONOTCDN', true); }
[1766] Fix | Delete
if(! defined('DONOTCACHEOBJECT')){ define('DONOTCACHEOBJECT', true); }
[1767] Fix | Delete
wfCache::doNotCache();
[1768] Fix | Delete
}
[1769] Fix | Delete
public static function isUABlocked($uaPattern){ // takes a pattern using asterisks as wildcards, turns it into regex and checks it against the visitor UA returning true if blocked
[1770] Fix | Delete
return fnmatch($uaPattern, !empty($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '', FNM_CASEFOLD);
[1771] Fix | Delete
}
[1772] Fix | Delete
public static function isRefererBlocked($refPattern){
[1773] Fix | Delete
return fnmatch($refPattern, !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '', FNM_CASEFOLD);
[1774] Fix | Delete
}
[1775] Fix | Delete
[1776] Fix | Delete
public static function error_clear_last() {
[1777] Fix | Delete
if (function_exists('error_clear_last')) {
[1778] Fix | Delete
error_clear_last();
[1779] Fix | Delete
}
[1780] Fix | Delete
else {
[1781] Fix | Delete
// set error_get_last() to defined state by forcing an undefined variable error
[1782] Fix | Delete
set_error_handler('wfUtils::_resetErrorsHandler', 0);
[1783] Fix | Delete
@$undefinedVariable;
[1784] Fix | Delete
restore_error_handler();
[1785] Fix | Delete
}
[1786] Fix | Delete
}
[1787] Fix | Delete
[1788] Fix | Delete
/**
[1789] Fix | Delete
* Logs the error given or the last PHP error to our log, rate limiting if needed.
[1790] Fix | Delete
*
[1791] Fix | Delete
* @param string $limiter_key
[1792] Fix | Delete
* @param string $label
[1793] Fix | Delete
* @param null|string $error The error to log. If null, it will be the result of error_get_last
[1794] Fix | Delete
* @param int $rate Logging will only occur once per $rate seconds.
[1795] Fix | Delete
*/
[1796] Fix | Delete
public static function check_and_log_last_error($limiter_key, $label, $error = null, $rate = 3600 /* 1 hour */) {
[1797] Fix | Delete
if ($error === null) {
[1798] Fix | Delete
$error = error_get_last();
[1799] Fix | Delete
if ($error === null) {
[1800] Fix | Delete
return;
[1801] Fix | Delete
}
[1802] Fix | Delete
else if ($error['file'] === __FILE__) {
[1803] Fix | Delete
return;
[1804] Fix | Delete
}
[1805] Fix | Delete
$error = $error['message'];
[1806] Fix | Delete
}
[1807] Fix | Delete
[1808] Fix | Delete
$rateKey = 'lastError_rate_' . $limiter_key;
[1809] Fix | Delete
$previousKey = 'lastError_prev_' . $limiter_key;
[1810] Fix | Delete
$previousError = wfConfig::getJSON($previousKey, array(0, false));
[1811] Fix | Delete
if ($previousError[1] != $error) {
[1812] Fix | Delete
if (wfConfig::getInt($rateKey) < time() - $rate) {
[1813] Fix | Delete
wfConfig::set($rateKey, time());
[1814] Fix | Delete
wfConfig::setJSON($previousKey, array(time(), $error));
[1815] Fix | Delete
wordfence::status(2, 'error', $label . ' ' . $error);
[1816] Fix | Delete
}
[1817] Fix | Delete
}
[1818] Fix | Delete
}
[1819] Fix | Delete
[1820] Fix | Delete
public static function last_error($limiter_key) {
[1821] Fix | Delete
$previousKey = 'lastError_prev_' . $limiter_key;
[1822] Fix | Delete
$previousError = wfConfig::getJSON($previousKey, array(0, false));
[1823] Fix | Delete
if ($previousError[1]) {
[1824] Fix | Delete
return wfUtils::formatLocalTime(get_option('date_format') . ' ' . get_option('time_format'), $previousError[0]) . ': ' . $previousError[1];
[1825] Fix | Delete
}
[1826] Fix | Delete
return false;
[1827] Fix | Delete
}
[1828] Fix | Delete
[1829] Fix | Delete
public static function _resetErrorsHandler($errno, $errstr, $errfile, $errline) {
[1830] Fix | Delete
//Do nothing
[1831] Fix | Delete
}
[1832] Fix | Delete
[1833] Fix | Delete
/**
[1834] Fix | Delete
* @param $startIP
[1835] Fix | Delete
* @param $endIP
[1836] Fix | Delete
* @return array
[1837] Fix | Delete
*/
[1838] Fix | Delete
public static function rangeToCIDRs($startIP, $endIP){
[1839] Fix | Delete
$start_ip_printable = wfUtils::inet_ntop($startIP);
[1840] Fix | Delete
if (filter_var($start_ip_printable, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
[1841] Fix | Delete
return self::rangeToCIDRsIPv4(current(unpack('N', substr($startIP, 12, 4))), current(unpack('N', substr($endIP, 12, 4))));
[1842] Fix | Delete
}
[1843] Fix | Delete
$startIPBin = str_pad(wfHelperBin::bin2str($startIP), 128, '0', STR_PAD_LEFT);
[1844] Fix | Delete
$endIPBin = str_pad(wfHelperBin::bin2str($endIP), 128, '0', STR_PAD_LEFT);
[1845] Fix | Delete
$IPIncBin = $startIPBin;
[1846] Fix | Delete
$CIDRs = array();
[1847] Fix | Delete
while (strcmp($IPIncBin, $endIPBin) <= 0) {
[1848] Fix | Delete
$longNetwork = 128;
[1849] Fix | Delete
$IPNetBin = $IPIncBin;
[1850] Fix | Delete
while (($IPIncBin[$longNetwork - 1] == '0') && (strcmp(substr_replace($IPNetBin, '1', $longNetwork - 1, 1), $endIPBin) <= 0)) {
[1851] Fix | Delete
$IPNetBin[$longNetwork - 1] = '1';
[1852] Fix | Delete
$longNetwork--;
[1853] Fix | Delete
}
[1854] Fix | Delete
$CIDRs[] = self::inet_ntop(str_pad(wfHelperBin::str2bin($IPIncBin), 16, "\x00", STR_PAD_LEFT)) . ($longNetwork < 128 ? '/' . $longNetwork : '');
[1855] Fix | Delete
$IPIncBin = str_pad(wfHelperBin::bin2str(wfHelperBin::addbin2bin(chr(1), wfHelperBin::str2bin($IPNetBin))), 128, '0', STR_PAD_LEFT);
[1856] Fix | Delete
}
[1857] Fix | Delete
return $CIDRs;
[1858] Fix | Delete
}
[1859] Fix | Delete
[1860] Fix | Delete
public static function rangeToCIDRsIPv4($startIP, $endIP){
[1861] Fix | Delete
$startIPBin = sprintf('%032b', $startIP);
[1862] Fix | Delete
$endIPBin = sprintf('%032b', $endIP);
[1863] Fix | Delete
$IPIncBin = $startIPBin;
[1864] Fix | Delete
$CIDRs = array();
[1865] Fix | Delete
while(strcmp($IPIncBin, $endIPBin) <= 0){
[1866] Fix | Delete
$longNetwork = 32;
[1867] Fix | Delete
$IPNetBin = $IPIncBin;
[1868] Fix | Delete
while(($IPIncBin[$longNetwork - 1] == '0') && (strcmp(substr_replace($IPNetBin, '1', $longNetwork - 1, 1), $endIPBin) <= 0)){
[1869] Fix | Delete
$IPNetBin[$longNetwork - 1] = '1';
[1870] Fix | Delete
$longNetwork--;
[1871] Fix | Delete
}
[1872] Fix | Delete
$CIDRs[] = long2ip(bindec($IPIncBin)) . ($longNetwork < 32 ? '/' . $longNetwork : '');
[1873] Fix | Delete
$IPIncBin = sprintf('%032b', bindec($IPNetBin) + 1);
[1874] Fix | Delete
}
[1875] Fix | Delete
return $CIDRs;
[1876] Fix | Delete
}
[1877] Fix | Delete
[1878] Fix | Delete
/**
[1879] Fix | Delete
* This is a convenience function for sending a JSON response and ensuring that execution stops after sending
[1880] Fix | Delete
* since wp_die() can be interrupted.
[1881] Fix | Delete
*
[1882] Fix | Delete
* @param $response
[1883] Fix | Delete
* @param int|null $status_code
[1884] Fix | Delete
*/
[1885] Fix | Delete
public static function send_json($response, $status_code = null) {
[1886] Fix | Delete
wp_send_json($response, $status_code);
[1887] Fix | Delete
die();
[1888] Fix | Delete
}
[1889] Fix | Delete
[1890] Fix | Delete
public static function setcookie($name, $value, $expire, $path, $domain, $secure, $httpOnly){
[1891] Fix | Delete
if(version_compare(PHP_VERSION, '5.2.0') >= 0){
[1892] Fix | Delete
@setcookie($name, $value, $expire, $path, $domain, $secure, $httpOnly);
[1893] Fix | Delete
} else {
[1894] Fix | Delete
@setcookie($name, $value, $expire, $path);
[1895] Fix | Delete
}
[1896] Fix | Delete
}
[1897] Fix | Delete
public static function isNginx(){
[1898] Fix | Delete
$sapi = php_sapi_name();
[1899] Fix | Delete
$serverSoft = $_SERVER['SERVER_SOFTWARE'];
[1900] Fix | Delete
if($sapi == 'fpm-fcgi' && stripos($serverSoft, 'nginx') !== false){
[1901] Fix | Delete
return true;
[1902] Fix | Delete
}
[1903] Fix | Delete
}
[1904] Fix | Delete
public static function getLastError(){
[1905] Fix | Delete
$err = error_get_last();
[1906] Fix | Delete
if(is_array($err)){
[1907] Fix | Delete
return $err['message'];
[1908] Fix | Delete
}
[1909] Fix | Delete
return '';
[1910] Fix | Delete
}
[1911] Fix | Delete
public static function hostNotExcludedFromProxy($url){
[1912] Fix | Delete
if(! defined('WP_PROXY_BYPASS_HOSTS')){
[1913] Fix | Delete
return true; //No hosts are excluded
[1914] Fix | Delete
}
[1915] Fix | Delete
$hosts = explode(',', WP_PROXY_BYPASS_HOSTS);
[1916] Fix | Delete
$url = preg_replace('/^https?:\/\//i', '', $url);
[1917] Fix | Delete
$url = preg_replace('/\/.*$/', '', $url);
[1918] Fix | Delete
$url = strtolower($url);
[1919] Fix | Delete
foreach($hosts as $h){
[1920] Fix | Delete
if(strtolower(trim($h)) == $url){
[1921] Fix | Delete
return false;
[1922] Fix | Delete
}
[1923] Fix | Delete
}
[1924] Fix | Delete
return true;
[1925] Fix | Delete
}
[1926] Fix | Delete
public static function hasXSS($URL){
[1927] Fix | Delete
if(! preg_match('/^https?:\/\/[a-z0-9\.\-]+\/[^\':<>\"\\\]*$/i', $URL)){
[1928] Fix | Delete
return true;
[1929] Fix | Delete
} else {
[1930] Fix | Delete
return false;
[1931] Fix | Delete
}
[1932] Fix | Delete
}
[1933] Fix | Delete
[1934] Fix | Delete
/**
[1935] Fix | Delete
* @param string $host
[1936] Fix | Delete
* @return array
[1937] Fix | Delete
*/
[1938] Fix | Delete
public static function resolveDomainName($host, $ipVersion = null) {
[1939] Fix | Delete
if (!function_exists('dns_get_record')) {
[1940] Fix | Delete
if ($ipVersion === 4 || $ipVersion === null) {
[1941] Fix | Delete
$ips = gethostbynamel($host);
[1942] Fix | Delete
if ($ips !== false)
[1943] Fix | Delete
return $ips;
[1944] Fix | Delete
}
[1945] Fix | Delete
return array();
[1946] Fix | Delete
}
[1947] Fix | Delete
$recordTypes = array();
[1948] Fix | Delete
if ($ipVersion === 4 || $ipVersion === null)
[1949] Fix | Delete
$recordTypes[DNS_A] = 'ip';
[1950] Fix | Delete
if ($ipVersion === 6 || $ipVersion === null)
[1951] Fix | Delete
$recordTypes[DNS_AAAA] = 'ipv6';
[1952] Fix | Delete
$ips = array();
[1953] Fix | Delete
foreach ($recordTypes as $type => $key) {
[1954] Fix | Delete
$records = @dns_get_record($host, $type);
[1955] Fix | Delete
if ($records !== false) {
[1956] Fix | Delete
foreach ($records as $record) {
[1957] Fix | Delete
$ips[] = $record[$key];
[1958] Fix | Delete
}
[1959] Fix | Delete
}
[1960] Fix | Delete
}
[1961] Fix | Delete
return $ips;
[1962] Fix | Delete
}
[1963] Fix | Delete
[1964] Fix | Delete
/**
[1965] Fix | Delete
* Expand a compressed printable representation of an IPv6 address.
[1966] Fix | Delete
*
[1967] Fix | Delete
* @param string $ip
[1968] Fix | Delete
* @return string
[1969] Fix | Delete
*/
[1970] Fix | Delete
public static function expandIPv6Address($ip) {
[1971] Fix | Delete
$hex = bin2hex(self::inet_pton($ip));
[1972] Fix | Delete
$ip = substr(preg_replace("/([a-f0-9]{4})/i", "$1:", $hex), 0, -1);
[1973] Fix | Delete
return $ip;
[1974] Fix | Delete
}
[1975] Fix | Delete
[1976] Fix | Delete
public static function set_html_content_type() {
[1977] Fix | Delete
return 'text/html';
[1978] Fix | Delete
}
[1979] Fix | Delete
[1980] Fix | Delete
public static function htmlEmail($to, $subject, $body) {
[1981] Fix | Delete
add_filter( 'wp_mail_content_type', 'wfUtils::set_html_content_type' );
[1982] Fix | Delete
$result = wp_mail($to, $subject, $body);
[1983] Fix | Delete
remove_filter( 'wp_mail_content_type', 'wfUtils::set_html_content_type' );
[1984] Fix | Delete
return $result;
[1985] Fix | Delete
}
[1986] Fix | Delete
[1987] Fix | Delete
/**
[1988] Fix | Delete
* @param string $readmePath
[1989] Fix | Delete
* @return bool
[1990] Fix | Delete
*/
[1991] Fix | Delete
public static function hideReadme($readmePath = null) {
[1992] Fix | Delete
if ($readmePath === null) {
[1993] Fix | Delete
$readmePath = ABSPATH . 'readme.html';
[1994] Fix | Delete
}
[1995] Fix | Delete
[1996] Fix | Delete
if (file_exists($readmePath)) {
[1997] Fix | Delete
$readmePathInfo = pathinfo($readmePath);
[1998] Fix | Delete
require_once(ABSPATH . WPINC . '/pluggable.php');
[1999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function