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
/home/sportsfe.../httpdocs/wp-conte.../plugins/wordfenc.../modules/login-se.../classes/controll...
File: settings.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace WordfenceLS;
[2] Fix | Delete
[3] Fix | Delete
use WordfenceLS\Settings\Model_DB;
[4] Fix | Delete
use WordfenceLS\Settings\Model_WPOptions;
[5] Fix | Delete
[6] Fix | Delete
class Controller_Settings {
[7] Fix | Delete
//Configurable
[8] Fix | Delete
const OPTION_XMLRPC_ENABLED = 'xmlrpc-enabled';
[9] Fix | Delete
const OPTION_2FA_WHITELISTED = 'whitelisted';
[10] Fix | Delete
const OPTION_IP_SOURCE = 'ip-source';
[11] Fix | Delete
const OPTION_IP_TRUSTED_PROXIES = 'ip-trusted-proxies';
[12] Fix | Delete
const OPTION_REQUIRE_2FA_ADMIN = 'require-2fa.administrator';
[13] Fix | Delete
const OPTION_REQUIRE_2FA_GRACE_PERIOD_ENABLED = 'require-2fa-grace-period-enabled';
[14] Fix | Delete
const OPTION_REQUIRE_2FA_GRACE_PERIOD = 'require-2fa-grace-period';
[15] Fix | Delete
const OPTION_REQUIRE_2FA_USER_GRACE_PERIOD = '2fa-user-grace-period';
[16] Fix | Delete
const OPTION_REMEMBER_DEVICE_ENABLED = 'remember-device';
[17] Fix | Delete
const OPTION_REMEMBER_DEVICE_DURATION = 'remember-device-duration';
[18] Fix | Delete
const OPTION_ALLOW_XML_RPC = 'allow-xml-rpc';
[19] Fix | Delete
const OPTION_ENABLE_AUTH_CAPTCHA = 'enable-auth-captcha';
[20] Fix | Delete
const OPTION_CAPTCHA_TEST_MODE = 'recaptcha-test-mode';
[21] Fix | Delete
const OPTION_RECAPTCHA_SITE_KEY = 'recaptcha-site-key';
[22] Fix | Delete
const OPTION_RECAPTCHA_SECRET = 'recaptcha-secret';
[23] Fix | Delete
const OPTION_RECAPTCHA_THRESHOLD = 'recaptcha-threshold';
[24] Fix | Delete
const OPTION_DELETE_ON_DEACTIVATION = 'delete-deactivation';
[25] Fix | Delete
const OPTION_PREFIX_REQUIRED_2FA_ROLE = 'required-2fa-role';
[26] Fix | Delete
const OPTION_ENABLE_WOOCOMMERCE_INTEGRATION = 'enable-woocommerce-integration';
[27] Fix | Delete
const OPTION_ENABLE_WOOCOMMERCE_ACCOUNT_INTEGRATION = 'enable-woocommerce-account-integration';
[28] Fix | Delete
const OPTION_ENABLE_SHORTCODE = 'enable-shortcode';
[29] Fix | Delete
const OPTION_ENABLE_LOGIN_HISTORY_COLUMNS = 'enable-login-history-columns';
[30] Fix | Delete
const OPTION_STACK_UI_COLUMNS = 'stack-ui-columns';
[31] Fix | Delete
[32] Fix | Delete
//Internal
[33] Fix | Delete
const OPTION_GLOBAL_NOTICES = 'global-notices';
[34] Fix | Delete
const OPTION_LAST_SECRET_REFRESH = 'last-secret-refresh';
[35] Fix | Delete
const OPTION_USE_NTP = 'use-ntp';
[36] Fix | Delete
const OPTION_ALLOW_DISABLING_NTP = 'allow-disabling-ntp';
[37] Fix | Delete
const OPTION_NTP_FAILURE_COUNT = 'ntp-failure-count';
[38] Fix | Delete
const OPTION_NTP_OFFSET = 'ntp-offset';
[39] Fix | Delete
const OPTION_SHARED_HASH_SECRET_KEY = 'shared-hash-secret';
[40] Fix | Delete
const OPTION_SHARED_SYMMETRIC_SECRET_KEY = 'shared-symmetric-secret';
[41] Fix | Delete
const OPTION_DISMISSED_FRESH_INSTALL_MODAL = 'dismissed-fresh-install-modal';
[42] Fix | Delete
const OPTION_CAPTCHA_STATS = 'captcha-stats';
[43] Fix | Delete
const OPTION_SCHEMA_VERSION = 'schema-version';
[44] Fix | Delete
const OPTION_USER_COUNT_QUERY_STATE = 'user-count-query-state';
[45] Fix | Delete
const OPTION_DISABLE_TEMPORARY_TABLES = 'disable-temporary-tables';
[46] Fix | Delete
[47] Fix | Delete
const DEFAULT_REQUIRE_2FA_USER_GRACE_PERIOD = 10;
[48] Fix | Delete
const MAX_REQUIRE_2FA_USER_GRACE_PERIOD = 99;
[49] Fix | Delete
[50] Fix | Delete
const STATE_2FA_DISABLED = 'disabled';
[51] Fix | Delete
const STATE_2FA_OPTIONAL = 'optional';
[52] Fix | Delete
const STATE_2FA_REQUIRED = 'required';
[53] Fix | Delete
[54] Fix | Delete
protected $_settingsStorage;
[55] Fix | Delete
[56] Fix | Delete
/**
[57] Fix | Delete
* Returns the singleton Controller_Settings.
[58] Fix | Delete
*
[59] Fix | Delete
* @return Controller_Settings
[60] Fix | Delete
*/
[61] Fix | Delete
public static function shared() {
[62] Fix | Delete
static $_shared = null;
[63] Fix | Delete
if ($_shared === null) {
[64] Fix | Delete
$_shared = new Controller_Settings();
[65] Fix | Delete
}
[66] Fix | Delete
return $_shared;
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
public function __construct($settingsStorage = false) {
[70] Fix | Delete
if (!$settingsStorage) {
[71] Fix | Delete
$settingsStorage = new Model_DB();
[72] Fix | Delete
}
[73] Fix | Delete
$this->_settingsStorage = $settingsStorage;
[74] Fix | Delete
$this->_migrate_admin_2fa_requirements_to_roles();
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
public function set_defaults() {
[78] Fix | Delete
$this->_settingsStorage->set_multiple(array(
[79] Fix | Delete
self::OPTION_XMLRPC_ENABLED => array('value' => true, 'autoload' => Model_Settings::AUTOLOAD_YES, 'allowOverwrite' => false),
[80] Fix | Delete
self::OPTION_2FA_WHITELISTED => array('value' => '', 'autoload' => Model_Settings::AUTOLOAD_YES, 'allowOverwrite' => false),
[81] Fix | Delete
self::OPTION_IP_SOURCE => array('value' => Model_Request::IP_SOURCE_AUTOMATIC, 'autoload' => Model_Settings::AUTOLOAD_YES, 'allowOverwrite' => false),
[82] Fix | Delete
self::OPTION_IP_TRUSTED_PROXIES => array('value' => '', 'autoload' => Model_Settings::AUTOLOAD_YES, 'allowOverwrite' => false),
[83] Fix | Delete
self::OPTION_REQUIRE_2FA_ADMIN => array('value' => false, 'autoload' => Model_Settings::AUTOLOAD_YES, 'allowOverwrite' => false),
[84] Fix | Delete
self::OPTION_REQUIRE_2FA_GRACE_PERIOD_ENABLED => array('value' => false, 'autoload' => Model_Settings::AUTOLOAD_YES, 'allowOverwrite' => false),
[85] Fix | Delete
self::OPTION_REQUIRE_2FA_USER_GRACE_PERIOD => array('value' => self::DEFAULT_REQUIRE_2FA_USER_GRACE_PERIOD, 'autoload' => Model_Settings::AUTOLOAD_YES, 'allowOverwrite' => false),
[86] Fix | Delete
self::OPTION_GLOBAL_NOTICES => array('value' => '[]', 'autoload' => Model_Settings::AUTOLOAD_YES, 'allowOverwrite' => false),
[87] Fix | Delete
self::OPTION_REMEMBER_DEVICE_ENABLED => array('value' => false, 'autoload' => Model_Settings::AUTOLOAD_YES, 'allowOverwrite' => false),
[88] Fix | Delete
self::OPTION_REMEMBER_DEVICE_DURATION => array('value' => (30 * 86400), 'autoload' => Model_Settings::AUTOLOAD_YES, 'allowOverwrite' => false),
[89] Fix | Delete
self::OPTION_ALLOW_XML_RPC => array('value' => true, 'autoload' => Model_Settings::AUTOLOAD_YES, 'allowOverwrite' => false),
[90] Fix | Delete
self::OPTION_ENABLE_AUTH_CAPTCHA => array('value' => false, 'autoload' => Model_Settings::AUTOLOAD_YES, 'allowOverwrite' => false),
[91] Fix | Delete
self::OPTION_CAPTCHA_STATS => array('value' => '{"counts":[0,0,0,0,0,0,0,0,0,0,0],"avg":0}', 'autoload' => Model_Settings::AUTOLOAD_YES, 'allowOverwrite' => false),
[92] Fix | Delete
self::OPTION_RECAPTCHA_THRESHOLD => array('value' => 0.5, 'autoload' => Model_Settings::AUTOLOAD_YES, 'allowOverwrite' => false),
[93] Fix | Delete
self::OPTION_LAST_SECRET_REFRESH => array('value' => 0, 'autoload' => Model_Settings::AUTOLOAD_YES, 'allowOverwrite' => false),
[94] Fix | Delete
self::OPTION_DELETE_ON_DEACTIVATION => array('value' => false, 'autoload' => Model_Settings::AUTOLOAD_YES, 'allowOverwrite' => false),
[95] Fix | Delete
self::OPTION_ENABLE_WOOCOMMERCE_INTEGRATION => array('value' => false, 'autoload' => Model_Settings::AUTOLOAD_YES, 'allowOverwrite' => false),
[96] Fix | Delete
self::OPTION_ENABLE_WOOCOMMERCE_ACCOUNT_INTEGRATION => array('value' => false, 'autoload' => Model_Settings::AUTOLOAD_YES, 'allowOverwrite' => false),
[97] Fix | Delete
self::OPTION_ENABLE_SHORTCODE => array('value' => false, 'autoload' => Model_Settings::AUTOLOAD_YES, 'allowOverwrite' => false),
[98] Fix | Delete
self::OPTION_ENABLE_LOGIN_HISTORY_COLUMNS => array('value' => true, 'autoload' => Model_Settings::AUTOLOAD_YES, 'allowOverwrite' => false),
[99] Fix | Delete
self::OPTION_STACK_UI_COLUMNS => array('value' => true, 'autoload' => Model_Settings::AUTOLOAD_YES, 'allowOverwrite' => false),
[100] Fix | Delete
self::OPTION_SCHEMA_VERSION => array('value' => 0, 'autoload' => Model_Settings::AUTOLOAD_YES, 'allowOverwrite' => false),
[101] Fix | Delete
self::OPTION_USER_COUNT_QUERY_STATE => array('value' => 0, 'autoload' => Model_Settings::AUTOLOAD_YES, 'allowOverwrite' => false),
[102] Fix | Delete
self::OPTION_DISABLE_TEMPORARY_TABLES => array('value' => 0, 'autoload' => Model_Settings::AUTOLOAD_YES, 'allowOverwrite' => false)
[103] Fix | Delete
));
[104] Fix | Delete
}
[105] Fix | Delete
[106] Fix | Delete
public function set($key, $value, $already_validated = false) {
[107] Fix | Delete
return $this->set_multiple(array($key => $value), $already_validated);
[108] Fix | Delete
}
[109] Fix | Delete
[110] Fix | Delete
public function set_array($key, $value, $already_validated = false) {
[111] Fix | Delete
return $this->set_multiple(array($key => json_encode($value)), $already_validated);
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
public function set_multiple($changes, $already_validated = false) {
[115] Fix | Delete
if (!$already_validated && $this->validate_multiple($changes) !== true) {
[116] Fix | Delete
return false;
[117] Fix | Delete
}
[118] Fix | Delete
$changes = $this->clean_multiple($changes);
[119] Fix | Delete
$changes = $this->preprocess_multiple($changes);
[120] Fix | Delete
$this->_settingsStorage->set_multiple($changes);
[121] Fix | Delete
return true;
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
public function get($key, $default = false) {
[125] Fix | Delete
return $this->_settingsStorage->get($key, $default);
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
public function get_bool($key, $default = false) {
[129] Fix | Delete
return $this->_truthy_to_bool($this->get($key, $default));
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
public function get_int($key, $default = 0) {
[133] Fix | Delete
return intval($this->get($key, $default));
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
public function get_float($key, $default = 0.0) {
[137] Fix | Delete
return (float) $this->get($key, $default);
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
public function get_array($key, $default = array()) {
[141] Fix | Delete
$value = $this->get($key, null);
[142] Fix | Delete
if (is_string($value)) {
[143] Fix | Delete
$value = @json_decode($value, true);
[144] Fix | Delete
}
[145] Fix | Delete
else {
[146] Fix | Delete
$value = null;
[147] Fix | Delete
}
[148] Fix | Delete
return is_array($value) ? $value : $default;
[149] Fix | Delete
}
[150] Fix | Delete
[151] Fix | Delete
public function remove($key) {
[152] Fix | Delete
$this->_settingsStorage->remove($key);
[153] Fix | Delete
}
[154] Fix | Delete
[155] Fix | Delete
/**
[156] Fix | Delete
* Validates whether a user-entered setting value is acceptable. Returns true if valid or an error message if not.
[157] Fix | Delete
*
[158] Fix | Delete
* @param string $key
[159] Fix | Delete
* @param mixed $value
[160] Fix | Delete
* @return bool|string
[161] Fix | Delete
*/
[162] Fix | Delete
public function validate($key, $value) {
[163] Fix | Delete
switch ($key) {
[164] Fix | Delete
//Boolean
[165] Fix | Delete
case self::OPTION_XMLRPC_ENABLED:
[166] Fix | Delete
case self::OPTION_REQUIRE_2FA_ADMIN:
[167] Fix | Delete
case self::OPTION_REQUIRE_2FA_GRACE_PERIOD_ENABLED:
[168] Fix | Delete
case self::OPTION_REMEMBER_DEVICE_ENABLED:
[169] Fix | Delete
case self::OPTION_ALLOW_XML_RPC:
[170] Fix | Delete
case self::OPTION_ENABLE_AUTH_CAPTCHA:
[171] Fix | Delete
case self::OPTION_CAPTCHA_TEST_MODE:
[172] Fix | Delete
case self::OPTION_DISMISSED_FRESH_INSTALL_MODAL:
[173] Fix | Delete
case self::OPTION_DELETE_ON_DEACTIVATION:
[174] Fix | Delete
case self::OPTION_ENABLE_WOOCOMMERCE_INTEGRATION:
[175] Fix | Delete
case self::OPTION_ENABLE_WOOCOMMERCE_ACCOUNT_INTEGRATION:
[176] Fix | Delete
case self::OPTION_ENABLE_SHORTCODE:
[177] Fix | Delete
case self::OPTION_ENABLE_LOGIN_HISTORY_COLUMNS:
[178] Fix | Delete
case self::OPTION_STACK_UI_COLUMNS:
[179] Fix | Delete
case self::OPTION_USER_COUNT_QUERY_STATE:
[180] Fix | Delete
case self::OPTION_DISABLE_TEMPORARY_TABLES:
[181] Fix | Delete
return true;
[182] Fix | Delete
[183] Fix | Delete
//Int
[184] Fix | Delete
case self::OPTION_LAST_SECRET_REFRESH:
[185] Fix | Delete
return is_numeric($value); //Left using is_numeric to prevent issues with existing values
[186] Fix | Delete
case self::OPTION_SCHEMA_VERSION:
[187] Fix | Delete
return Utility_Number::isInteger($value, 0);
[188] Fix | Delete
[189] Fix | Delete
//Array
[190] Fix | Delete
case self::OPTION_GLOBAL_NOTICES:
[191] Fix | Delete
case self::OPTION_CAPTCHA_STATS:
[192] Fix | Delete
return preg_match('/^\[.*\]$/', $value) || preg_match('/^\{.*\}$/', $value); //Only a rough JSON validation
[193] Fix | Delete
[194] Fix | Delete
//Special
[195] Fix | Delete
case self::OPTION_IP_TRUSTED_PROXIES:
[196] Fix | Delete
case self::OPTION_2FA_WHITELISTED:
[197] Fix | Delete
$parsed = array_filter(array_map(function($s) { return trim($s); }, preg_split('/[\r\n]/', $value)));
[198] Fix | Delete
foreach ($parsed as $entry) {
[199] Fix | Delete
if (!Controller_Whitelist::shared()->is_valid_range($entry)) {
[200] Fix | Delete
return sprintf(__('The IP/range %s is invalid.', 'wordfence'), esc_html($entry));
[201] Fix | Delete
}
[202] Fix | Delete
}
[203] Fix | Delete
return true;
[204] Fix | Delete
case self::OPTION_IP_SOURCE:
[205] Fix | Delete
if (!in_array($value, array(Model_Request::IP_SOURCE_AUTOMATIC, Model_Request::IP_SOURCE_REMOTE_ADDR, Model_Request::IP_SOURCE_X_FORWARDED_FOR, Model_Request::IP_SOURCE_X_REAL_IP))) {
[206] Fix | Delete
return __('An invalid IP source was provided.', 'wordfence');
[207] Fix | Delete
}
[208] Fix | Delete
return true;
[209] Fix | Delete
case self::OPTION_REQUIRE_2FA_GRACE_PERIOD:
[210] Fix | Delete
$gracePeriodEnd = strtotime($value);
[211] Fix | Delete
if ($gracePeriodEnd <= \WordfenceLS\Controller_Time::time()) {
[212] Fix | Delete
return __('The grace period end time must be in the future.', 'wordfence');
[213] Fix | Delete
}
[214] Fix | Delete
return true;
[215] Fix | Delete
case self::OPTION_REMEMBER_DEVICE_DURATION:
[216] Fix | Delete
return is_numeric($value) && $value > 0;
[217] Fix | Delete
case self::OPTION_RECAPTCHA_THRESHOLD:
[218] Fix | Delete
return is_numeric($value) && $value > 0 && $value <= 1;
[219] Fix | Delete
case self::OPTION_RECAPTCHA_SITE_KEY:
[220] Fix | Delete
if (empty($value)) {
[221] Fix | Delete
return true;
[222] Fix | Delete
}
[223] Fix | Delete
[224] Fix | Delete
$response = wp_remote_get('https://www.google.com/recaptcha/api.js?render=' . urlencode($value));
[225] Fix | Delete
[226] Fix | Delete
if (!is_wp_error($response)) {
[227] Fix | Delete
$status = wp_remote_retrieve_response_code($response);
[228] Fix | Delete
if ($status == 200) {
[229] Fix | Delete
return true;
[230] Fix | Delete
}
[231] Fix | Delete
[232] Fix | Delete
$data = wp_remote_retrieve_body($response);
[233] Fix | Delete
if (strpos($data, 'grecaptcha') === false) {
[234] Fix | Delete
return __('Unable to validate the reCAPTCHA site key. Please check the key and try again.', 'wordfence');
[235] Fix | Delete
}
[236] Fix | Delete
return true;
[237] Fix | Delete
}
[238] Fix | Delete
return sprintf(__('An error was encountered while validating the reCAPTCHA site key: %s', 'wordfence'), $response->get_error_message());
[239] Fix | Delete
case self::OPTION_REQUIRE_2FA_USER_GRACE_PERIOD:
[240] Fix | Delete
return is_numeric($value) && $value >= 0 && $value <= self::MAX_REQUIRE_2FA_USER_GRACE_PERIOD;
[241] Fix | Delete
}
[242] Fix | Delete
return true;
[243] Fix | Delete
}
[244] Fix | Delete
[245] Fix | Delete
public function validate_multiple($values) {
[246] Fix | Delete
$errors = array();
[247] Fix | Delete
foreach ($values as $key => $value) {
[248] Fix | Delete
$status = $this->validate($key, $value);
[249] Fix | Delete
if ($status !== true) {
[250] Fix | Delete
$errors[$key] = $status;
[251] Fix | Delete
}
[252] Fix | Delete
}
[253] Fix | Delete
[254] Fix | Delete
if (!empty($errors)) {
[255] Fix | Delete
return $errors;
[256] Fix | Delete
}
[257] Fix | Delete
[258] Fix | Delete
return true;
[259] Fix | Delete
}
[260] Fix | Delete
[261] Fix | Delete
/**
[262] Fix | Delete
* Cleans and normalizes a setting value for use in saving.
[263] Fix | Delete
*
[264] Fix | Delete
* @param string $key
[265] Fix | Delete
* @param mixed $value
[266] Fix | Delete
* @return mixed
[267] Fix | Delete
*/
[268] Fix | Delete
public function clean($key, $value) {
[269] Fix | Delete
switch ($key) {
[270] Fix | Delete
//Boolean
[271] Fix | Delete
case self::OPTION_XMLRPC_ENABLED:
[272] Fix | Delete
case self::OPTION_REQUIRE_2FA_ADMIN:
[273] Fix | Delete
case self::OPTION_REQUIRE_2FA_GRACE_PERIOD_ENABLED:
[274] Fix | Delete
case self::OPTION_REMEMBER_DEVICE_ENABLED:
[275] Fix | Delete
case self::OPTION_ALLOW_XML_RPC:
[276] Fix | Delete
case self::OPTION_ENABLE_AUTH_CAPTCHA:
[277] Fix | Delete
case self::OPTION_CAPTCHA_TEST_MODE:
[278] Fix | Delete
case self::OPTION_DISMISSED_FRESH_INSTALL_MODAL:
[279] Fix | Delete
case self::OPTION_DELETE_ON_DEACTIVATION:
[280] Fix | Delete
case self::OPTION_ENABLE_WOOCOMMERCE_INTEGRATION:
[281] Fix | Delete
case self::OPTION_ENABLE_WOOCOMMERCE_ACCOUNT_INTEGRATION:
[282] Fix | Delete
case self::OPTION_ENABLE_SHORTCODE;
[283] Fix | Delete
case self::OPTION_ENABLE_LOGIN_HISTORY_COLUMNS:
[284] Fix | Delete
case self::OPTION_STACK_UI_COLUMNS:
[285] Fix | Delete
case self::OPTION_USER_COUNT_QUERY_STATE:
[286] Fix | Delete
case self::OPTION_DISABLE_TEMPORARY_TABLES:
[287] Fix | Delete
return $this->_truthy_to_bool($value);
[288] Fix | Delete
[289] Fix | Delete
//Int
[290] Fix | Delete
case self::OPTION_REMEMBER_DEVICE_DURATION:
[291] Fix | Delete
case self::OPTION_LAST_SECRET_REFRESH:
[292] Fix | Delete
case self::OPTION_REQUIRE_2FA_USER_GRACE_PERIOD:
[293] Fix | Delete
case self::OPTION_SCHEMA_VERSION:
[294] Fix | Delete
return (int) $value;
[295] Fix | Delete
[296] Fix | Delete
//Float
[297] Fix | Delete
case self::OPTION_RECAPTCHA_THRESHOLD:
[298] Fix | Delete
return (float) $value;
[299] Fix | Delete
[300] Fix | Delete
//Special
[301] Fix | Delete
case self::OPTION_IP_TRUSTED_PROXIES:
[302] Fix | Delete
case self::OPTION_2FA_WHITELISTED:
[303] Fix | Delete
$parsed = array_filter(array_map(function($s) { return trim($s); }, preg_split('/[\r\n]/', $value)));
[304] Fix | Delete
$cleaned = array();
[305] Fix | Delete
foreach ($parsed as $item) {
[306] Fix | Delete
$cleaned[] = $this->_sanitize_ip_range($item);
[307] Fix | Delete
}
[308] Fix | Delete
return implode("\n", $cleaned);
[309] Fix | Delete
case self::OPTION_REQUIRE_2FA_GRACE_PERIOD:
[310] Fix | Delete
$dt = $this->_parse_local_time($value);
[311] Fix | Delete
return $dt->format('U');
[312] Fix | Delete
case self::OPTION_RECAPTCHA_SITE_KEY:
[313] Fix | Delete
case self::OPTION_RECAPTCHA_SECRET:
[314] Fix | Delete
return trim($value);
[315] Fix | Delete
}
[316] Fix | Delete
return $value;
[317] Fix | Delete
}
[318] Fix | Delete
[319] Fix | Delete
public function clean_multiple($changes) {
[320] Fix | Delete
$cleaned = array();
[321] Fix | Delete
foreach ($changes as $key => $value) {
[322] Fix | Delete
$cleaned[$key] = $this->clean($key, $value);
[323] Fix | Delete
}
[324] Fix | Delete
return $cleaned;
[325] Fix | Delete
}
[326] Fix | Delete
[327] Fix | Delete
private function get_required_2fa_role_key($role) {
[328] Fix | Delete
return implode('.', array(self::OPTION_PREFIX_REQUIRED_2FA_ROLE, $role));
[329] Fix | Delete
}
[330] Fix | Delete
[331] Fix | Delete
public function get_required_2fa_role_activation_time($role) {
[332] Fix | Delete
$time = $this->get_int($this->get_required_2fa_role_key($role), -1);
[333] Fix | Delete
if ($time < 0)
[334] Fix | Delete
return false;
[335] Fix | Delete
return $time;
[336] Fix | Delete
}
[337] Fix | Delete
[338] Fix | Delete
public function get_user_2fa_grace_period() {
[339] Fix | Delete
return $this->get_int(self::OPTION_REQUIRE_2FA_USER_GRACE_PERIOD, self::DEFAULT_REQUIRE_2FA_USER_GRACE_PERIOD);
[340] Fix | Delete
}
[341] Fix | Delete
[342] Fix | Delete
/**
[343] Fix | Delete
* Preprocesses the value, returning true if it was saved here (e.g., saved 2fa enabled by assigning a role
[344] Fix | Delete
* capability) or false if it is to be saved by the backing storage.
[345] Fix | Delete
*
[346] Fix | Delete
* @param string $key
[347] Fix | Delete
* @param mixed $value
[348] Fix | Delete
* @param array &$settings the array of settings to process, this function may append additional values from preprocessing
[349] Fix | Delete
* @return bool
[350] Fix | Delete
*/
[351] Fix | Delete
public function preprocess($key, $value, &$settings) {
[352] Fix | Delete
if (preg_match('/^enabled-roles\.(.+)$/', $key, $matches)) { //Enabled roles are stored as capabilities rather than in the settings storage
[353] Fix | Delete
$role = $matches[1];
[354] Fix | Delete
if ($role === 'super-admin') {
[355] Fix | Delete
$roleValid = true;
[356] Fix | Delete
}
[357] Fix | Delete
elseif (in_array($value, array(self::STATE_2FA_OPTIONAL, self::STATE_2FA_REQUIRED))) {
[358] Fix | Delete
$roleValid = Controller_Permissions::shared()->allow_2fa_self($role);
[359] Fix | Delete
}
[360] Fix | Delete
else {
[361] Fix | Delete
$roleValid = Controller_Permissions::shared()->disallow_2fa_self($role);
[362] Fix | Delete
}
[363] Fix | Delete
if ($roleValid)
[364] Fix | Delete
$settings[$this->get_required_2fa_role_key($role)] = ($value === self::STATE_2FA_REQUIRED ? time() : -1);
[365] Fix | Delete
return true;
[366] Fix | Delete
}
[367] Fix | Delete
return false;
[368] Fix | Delete
}
[369] Fix | Delete
[370] Fix | Delete
public function preprocess_multiple($changes) {
[371] Fix | Delete
$remaining = array();
[372] Fix | Delete
foreach ($changes as $key => $value) {
[373] Fix | Delete
if (!$this->preprocess($key, $value, $remaining)) {
[374] Fix | Delete
$remaining[$key] = $value;
[375] Fix | Delete
}
[376] Fix | Delete
}
[377] Fix | Delete
return $remaining;
[378] Fix | Delete
}
[379] Fix | Delete
[380] Fix | Delete
/**
[381] Fix | Delete
* Convenience
[382] Fix | Delete
*/
[383] Fix | Delete
[384] Fix | Delete
/**
[385] Fix | Delete
* Returns a cleaned array containing the whitelist entries.
[386] Fix | Delete
*
[387] Fix | Delete
* @return array
[388] Fix | Delete
*/
[389] Fix | Delete
public function whitelisted_ips() {
[390] Fix | Delete
return array_filter(array_map(function($s) { return trim($s); }, preg_split('/[\r\n]/', $this->get(self::OPTION_2FA_WHITELISTED, ''))));
[391] Fix | Delete
}
[392] Fix | Delete
[393] Fix | Delete
/**
[394] Fix | Delete
* Returns a cleaned array containing the trusted proxy entries.
[395] Fix | Delete
*
[396] Fix | Delete
* @return array
[397] Fix | Delete
*/
[398] Fix | Delete
public function trusted_proxies() {
[399] Fix | Delete
return array_filter(array_map(function($s) { return trim($s); }, preg_split('/[\r\n]/', $this->get(self::OPTION_IP_TRUSTED_PROXIES, ''))));
[400] Fix | Delete
}
[401] Fix | Delete
[402] Fix | Delete
public function get_ntp_failure_count() {
[403] Fix | Delete
return $this->get_int(self::OPTION_NTP_FAILURE_COUNT, 0);
[404] Fix | Delete
}
[405] Fix | Delete
[406] Fix | Delete
public function reset_ntp_failure_count() {
[407] Fix | Delete
$this->set(self::OPTION_NTP_FAILURE_COUNT, 0);
[408] Fix | Delete
}
[409] Fix | Delete
[410] Fix | Delete
public function increment_ntp_failure_count() {
[411] Fix | Delete
$count = $this->get_ntp_failure_count();
[412] Fix | Delete
if ($count < 0)
[413] Fix | Delete
return false;
[414] Fix | Delete
$count++;
[415] Fix | Delete
$this->set(self::OPTION_NTP_FAILURE_COUNT, $count);
[416] Fix | Delete
return $count;
[417] Fix | Delete
}
[418] Fix | Delete
[419] Fix | Delete
public function is_ntp_disabled_via_constant() {
[420] Fix | Delete
return defined('WORDFENCE_LS_DISABLE_NTP') && WORDFENCE_LS_DISABLE_NTP;
[421] Fix | Delete
}
[422] Fix | Delete
[423] Fix | Delete
public function is_ntp_enabled($requireOffset = true) {
[424] Fix | Delete
if ($this->is_ntp_cron_disabled())
[425] Fix | Delete
return false;
[426] Fix | Delete
if ($this->get_bool(self::OPTION_USE_NTP, true)) {
[427] Fix | Delete
if ($requireOffset) {
[428] Fix | Delete
$offset = $this->get(self::OPTION_NTP_OFFSET, null);
[429] Fix | Delete
return $offset !== null && abs((int)$offset) <= Controller_TOTP::TIME_WINDOW_LENGTH;
[430] Fix | Delete
}
[431] Fix | Delete
else {
[432] Fix | Delete
return true;
[433] Fix | Delete
}
[434] Fix | Delete
}
[435] Fix | Delete
return false;
[436] Fix | Delete
}
[437] Fix | Delete
[438] Fix | Delete
public function is_ntp_cron_disabled(&$failureCount = null) {
[439] Fix | Delete
if ($this->is_ntp_disabled_via_constant())
[440] Fix | Delete
return true;
[441] Fix | Delete
$failureCount = $this->get_ntp_failure_count();
[442] Fix | Delete
if ($failureCount >= Controller_Time::FAILURE_LIMIT) {
[443] Fix | Delete
return true;
[444] Fix | Delete
}
[445] Fix | Delete
else if ($failureCount < 0) {
[446] Fix | Delete
$failureCount = 0;
[447] Fix | Delete
return true;
[448] Fix | Delete
}
[449] Fix | Delete
return false;
[450] Fix | Delete
}
[451] Fix | Delete
[452] Fix | Delete
public function disable_ntp_cron() {
[453] Fix | Delete
$this->set(self::OPTION_NTP_FAILURE_COUNT, -1);
[454] Fix | Delete
}
[455] Fix | Delete
[456] Fix | Delete
public function are_login_history_columns_enabled() {
[457] Fix | Delete
return Controller_Settings::shared()->get_bool(Controller_Settings::OPTION_ENABLE_LOGIN_HISTORY_COLUMNS, true);
[458] Fix | Delete
}
[459] Fix | Delete
[460] Fix | Delete
public function should_stack_ui_columns() {
[461] Fix | Delete
return self::shared()->get_bool(Controller_Settings::OPTION_STACK_UI_COLUMNS, true);
[462] Fix | Delete
}
[463] Fix | Delete
[464] Fix | Delete
/**
[465] Fix | Delete
* Utility
[466] Fix | Delete
*/
[467] Fix | Delete
[468] Fix | Delete
/**
[469] Fix | Delete
* Translates a value to a boolean, correctly interpreting various textual representations.
[470] Fix | Delete
*
[471] Fix | Delete
* @param $value
[472] Fix | Delete
* @return bool
[473] Fix | Delete
*/
[474] Fix | Delete
protected function _truthy_to_bool($value) {
[475] Fix | Delete
if ($value === true || $value === false) {
[476] Fix | Delete
return $value;
[477] Fix | Delete
}
[478] Fix | Delete
[479] Fix | Delete
if (is_numeric($value)) {
[480] Fix | Delete
return !!$value;
[481] Fix | Delete
}
[482] Fix | Delete
[483] Fix | Delete
if (preg_match('/^(?:f(?:alse)?|no?|off)$/i', $value)) {
[484] Fix | Delete
return false;
[485] Fix | Delete
}
[486] Fix | Delete
else if (preg_match('/^(?:t(?:rue)?|y(?:es)?|on)$/i', $value)) {
[487] Fix | Delete
return true;
[488] Fix | Delete
}
[489] Fix | Delete
[490] Fix | Delete
return !empty($value);
[491] Fix | Delete
}
[492] Fix | Delete
[493] Fix | Delete
/**
[494] Fix | Delete
* Parses the given time string and returns its DateTime with the server's configured time zone.
[495] Fix | Delete
*
[496] Fix | Delete
* @param string $timestring
[497] Fix | Delete
* @return \DateTime
[498] Fix | Delete
*/
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function