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: wordfenceClass.php
* @param string $homePath
[9500] Fix | Delete
* @param bool $relaxedFileOwnership
[9501] Fix | Delete
* @param bool $output Whether or not to output the credentials collection form. If false, this function only returns the status.
[9502] Fix | Delete
* @return bool Returns true if the path is writable, otherwise false.
[9503] Fix | Delete
*/
[9504] Fix | Delete
public static function requestFilesystemCredentials($adminURL, $homePath = null, $relaxedFileOwnership = true, $output = true) {
[9505] Fix | Delete
if ($homePath === null) {
[9506] Fix | Delete
$homePath = wfUtils::getHomePath();
[9507] Fix | Delete
}
[9508] Fix | Delete
[9509] Fix | Delete
if (!$output) { ob_start(); }
[9510] Fix | Delete
if (false === ($credentials = request_filesystem_credentials($adminURL, '', false, $homePath, array('version', 'locale'), $relaxedFileOwnership))) {
[9511] Fix | Delete
if (!$output) { ob_end_clean(); }
[9512] Fix | Delete
return false;
[9513] Fix | Delete
}
[9514] Fix | Delete
[9515] Fix | Delete
if (!WP_Filesystem($credentials, $homePath, $relaxedFileOwnership)) { // Failed to connect, Error and request again
[9516] Fix | Delete
request_filesystem_credentials($adminURL, '', true, ABSPATH, array('version', 'locale'), $relaxedFileOwnership);
[9517] Fix | Delete
if (!$output) { ob_end_clean(); }
[9518] Fix | Delete
return false;
[9519] Fix | Delete
}
[9520] Fix | Delete
[9521] Fix | Delete
global $wp_filesystem;
[9522] Fix | Delete
if ($wp_filesystem->errors->get_error_code()) {
[9523] Fix | Delete
if (!$output) { ob_end_clean(); }
[9524] Fix | Delete
return false;
[9525] Fix | Delete
}
[9526] Fix | Delete
[9527] Fix | Delete
if (!$output) { ob_end_clean(); }
[9528] Fix | Delete
return true;
[9529] Fix | Delete
}
[9530] Fix | Delete
[9531] Fix | Delete
public static function initRestAPI() {
[9532] Fix | Delete
if (wfCentral::isSupported()) {
[9533] Fix | Delete
$auth = new wfRESTAuthenticationController();
[9534] Fix | Delete
$auth->registerRoutes();
[9535] Fix | Delete
[9536] Fix | Delete
$config = new wfRESTConfigController();
[9537] Fix | Delete
$config->registerRoutes();
[9538] Fix | Delete
[9539] Fix | Delete
$scan = new wfRESTScanController();
[9540] Fix | Delete
$scan->registerRoutes();
[9541] Fix | Delete
}
[9542] Fix | Delete
}
[9543] Fix | Delete
[9544] Fix | Delete
public static function ajax_wfcentral_step1_callback() {
[9545] Fix | Delete
// Step 1: Makes GET request to `/central/api/site/access-token` endpoint authenticated with the auth grant supplied by the user.
[9546] Fix | Delete
// - Receives site GUID, public key, short lived JWT.
[9547] Fix | Delete
[9548] Fix | Delete
$authGrant = isset($_REQUEST['auth-grant']) ? $_REQUEST['auth-grant'] : null;
[9549] Fix | Delete
if (!$authGrant) {
[9550] Fix | Delete
return array(
[9551] Fix | Delete
'err' => 1,
[9552] Fix | Delete
'errorMsg' => __("Auth grant is invalid.", 'wordfence'),
[9553] Fix | Delete
);
[9554] Fix | Delete
}
[9555] Fix | Delete
[9556] Fix | Delete
$request = new wfCentralAPIRequest('/site/access-token', 'GET', $authGrant);
[9557] Fix | Delete
try {
[9558] Fix | Delete
$response = $request->execute();
[9559] Fix | Delete
}
[9560] Fix | Delete
catch (Exception $e) {
[9561] Fix | Delete
wfCentralAPIRequest::handleInternalCentralAPIError($e);
[9562] Fix | Delete
}
[9563] Fix | Delete
catch (Throwable $t) {
[9564] Fix | Delete
wfCentralAPIRequest::handleInternalCentralAPIError($t);
[9565] Fix | Delete
}
[9566] Fix | Delete
[9567] Fix | Delete
if (!isset($response)) {
[9568] Fix | Delete
return array(
[9569] Fix | Delete
'err' => 1,
[9570] Fix | Delete
'errorMsg' => __('Internal error when connecting to Wordfence Central (see server error log)', 'wordfence'),
[9571] Fix | Delete
);
[9572] Fix | Delete
}
[9573] Fix | Delete
else if ($response->isError()) {
[9574] Fix | Delete
return $response->returnErrorArray();
[9575] Fix | Delete
}
[9576] Fix | Delete
[9577] Fix | Delete
$body = $response->getJSONBody();
[9578] Fix | Delete
if (!is_array($body) || !isset($body['data']['attributes'])) {
[9579] Fix | Delete
return array(
[9580] Fix | Delete
'err' => 1,
[9581] Fix | Delete
'errorMsg' => sprintf(/* translators: Error message. */ __("Invalid response from Wordfence Central: %s", 'wordfence'), $response->getBody()),
[9582] Fix | Delete
);
[9583] Fix | Delete
}
[9584] Fix | Delete
if (!array_key_exists('id', $body['data'])) {
[9585] Fix | Delete
return array(
[9586] Fix | Delete
'err' => 1,
[9587] Fix | Delete
'errorMsg' => sprintf(/* translators: JSON property. */ __("Invalid response from Wordfence Central. Parameter %s not found in response.", 'wordfence'), 'id'),
[9588] Fix | Delete
);
[9589] Fix | Delete
}
[9590] Fix | Delete
[9591] Fix | Delete
$data = $body['data']['attributes'];
[9592] Fix | Delete
$expected = array(
[9593] Fix | Delete
'public-key',
[9594] Fix | Delete
'access-token',
[9595] Fix | Delete
);
[9596] Fix | Delete
foreach ($expected as $key) {
[9597] Fix | Delete
if (!array_key_exists($key, $data)) {
[9598] Fix | Delete
return array(
[9599] Fix | Delete
'err' => 1,
[9600] Fix | Delete
'errorMsg' => sprintf(/* translators: JSON property. */ __("Invalid response from Wordfence Central. Parameter %s not found in response.", 'wordfence'), $key),
[9601] Fix | Delete
);
[9602] Fix | Delete
}
[9603] Fix | Delete
}
[9604] Fix | Delete
[9605] Fix | Delete
wfConfig::set('wordfenceCentralSiteID', $body['data']['id']);
[9606] Fix | Delete
wfConfig::set('wordfenceCentralPK', pack("H*", $data['public-key']));
[9607] Fix | Delete
wfConfig::set('wordfenceCentralAccessToken', $data['access-token']);
[9608] Fix | Delete
wfConfig::set('wordfenceCentralCurrentStep', 2);
[9609] Fix | Delete
[9610] Fix | Delete
wfConfig::set('wordfenceCentralDisconnected', false);
[9611] Fix | Delete
wfConfig::set('wordfenceCentralDisconnectTime', null);
[9612] Fix | Delete
wfConfig::set('wordfenceCentralDisconnectEmail', null);
[9613] Fix | Delete
[9614] Fix | Delete
return array(
[9615] Fix | Delete
'success' => 1,
[9616] Fix | Delete
);
[9617] Fix | Delete
}
[9618] Fix | Delete
[9619] Fix | Delete
public static function ajax_wfcentral_step2_callback() {
[9620] Fix | Delete
// Step 2: Makes POST request to `/central/api/wf/site/<guid>` endpoint passing in the new public key.
[9621] Fix | Delete
// Uses JWT from auth grant endpoint as auth.
[9622] Fix | Delete
[9623] Fix | Delete
require_once(WORDFENCE_PATH . '/lib/sodium_compat_fast.php');
[9624] Fix | Delete
[9625] Fix | Delete
$accessToken = wfConfig::get('wordfenceCentralAccessToken');
[9626] Fix | Delete
if (!$accessToken) {
[9627] Fix | Delete
return array(
[9628] Fix | Delete
'err' => 1,
[9629] Fix | Delete
'errorMsg' => __("Access token not found.", 'wordfence'),
[9630] Fix | Delete
);
[9631] Fix | Delete
}
[9632] Fix | Delete
[9633] Fix | Delete
$keypair = ParagonIE_Sodium_Compat::crypto_sign_keypair();
[9634] Fix | Delete
$publicKey = ParagonIE_Sodium_Compat::crypto_sign_publickey($keypair);
[9635] Fix | Delete
$secretKey = ParagonIE_Sodium_Compat::crypto_sign_secretkey($keypair);
[9636] Fix | Delete
wfConfig::set('wordfenceCentralSecretKey', $secretKey);
[9637] Fix | Delete
[9638] Fix | Delete
$request = new wfCentralAPIRequest('/site/' . wfConfig::get('wordfenceCentralSiteID'), 'POST',
[9639] Fix | Delete
$accessToken, array(
[9640] Fix | Delete
'data' => array(
[9641] Fix | Delete
'attributes' => array(
[9642] Fix | Delete
'public-key' => ParagonIE_Sodium_Compat::bin2hex($publicKey),
[9643] Fix | Delete
),
[9644] Fix | Delete
),
[9645] Fix | Delete
));
[9646] Fix | Delete
try {
[9647] Fix | Delete
$response = $request->execute();
[9648] Fix | Delete
}
[9649] Fix | Delete
catch (Exception $e) {
[9650] Fix | Delete
wfCentralAPIRequest::handleInternalCentralAPIError($e);
[9651] Fix | Delete
}
[9652] Fix | Delete
catch (Throwable $t) {
[9653] Fix | Delete
wfCentralAPIRequest::handleInternalCentralAPIError($t);
[9654] Fix | Delete
}
[9655] Fix | Delete
[9656] Fix | Delete
if (!isset($response)) {
[9657] Fix | Delete
return array(
[9658] Fix | Delete
'err' => 1,
[9659] Fix | Delete
'errorMsg' => __('Internal error when connecting to Wordfence Central (see server error log)', 'wordfence'),
[9660] Fix | Delete
);
[9661] Fix | Delete
}
[9662] Fix | Delete
else if ($response->isError()) {
[9663] Fix | Delete
return $response->returnErrorArray();
[9664] Fix | Delete
}
[9665] Fix | Delete
[9666] Fix | Delete
wfConfig::set('wordfenceCentralCurrentStep', 3);
[9667] Fix | Delete
[9668] Fix | Delete
return array(
[9669] Fix | Delete
'success' => 1,
[9670] Fix | Delete
);
[9671] Fix | Delete
}
[9672] Fix | Delete
[9673] Fix | Delete
public static function ajax_wfcentral_step3_callback() {
[9674] Fix | Delete
// Step 3: Makes GET request to `/central/api/wf/site/<guid>` endpoint signed using Wordfence plugin private key.
[9675] Fix | Delete
// - Expects 200 response with site data.
[9676] Fix | Delete
[9677] Fix | Delete
try {
[9678] Fix | Delete
$request = new wfCentralAuthenticatedAPIRequest('/site/' . wfConfig::get('wordfenceCentralSiteID'));
[9679] Fix | Delete
$response = $request->execute();
[9680] Fix | Delete
if ($response->isError()) {
[9681] Fix | Delete
return $response->returnErrorArray();
[9682] Fix | Delete
}
[9683] Fix | Delete
[9684] Fix | Delete
$body = $response->getJSONBody();
[9685] Fix | Delete
if (!is_array($body) || !isset($body['data']['attributes'])) {
[9686] Fix | Delete
return array(
[9687] Fix | Delete
'error' => 1,
[9688] Fix | Delete
'errorMsg' => __('Invalid response from Wordfence Central.', 'wordfence'),
[9689] Fix | Delete
);
[9690] Fix | Delete
}
[9691] Fix | Delete
wfConfig::set('wordfenceCentralSiteData', json_encode($body['data']['attributes']));
[9692] Fix | Delete
wfConfig::set('wordfenceCentralCurrentStep', 4);
[9693] Fix | Delete
[9694] Fix | Delete
return array(
[9695] Fix | Delete
'success' => 1,
[9696] Fix | Delete
);
[9697] Fix | Delete
[9698] Fix | Delete
}
[9699] Fix | Delete
catch (wfCentralAPIException $e) {
[9700] Fix | Delete
return array(
[9701] Fix | Delete
'error' => 1,
[9702] Fix | Delete
'errorMsg' => $e->getMessage(),
[9703] Fix | Delete
);
[9704] Fix | Delete
}
[9705] Fix | Delete
catch (Exception $e) {
[9706] Fix | Delete
wfCentralAPIRequest::handleInternalCentralAPIError($e);
[9707] Fix | Delete
return array(
[9708] Fix | Delete
'error' => 1,
[9709] Fix | Delete
'errorMsg' => $e->getMessage(),
[9710] Fix | Delete
);
[9711] Fix | Delete
}
[9712] Fix | Delete
catch (Throwable $t) {
[9713] Fix | Delete
wfCentralAPIRequest::handleInternalCentralAPIError($t);
[9714] Fix | Delete
return array(
[9715] Fix | Delete
'error' => 1,
[9716] Fix | Delete
'errorMsg' => $t->getMessage(),
[9717] Fix | Delete
);
[9718] Fix | Delete
}
[9719] Fix | Delete
}
[9720] Fix | Delete
[9721] Fix | Delete
public static function ajax_wfcentral_step4_callback() {
[9722] Fix | Delete
// Step 4: Poll for PUT request at `/wp-json/wp/v2/wordfence-auth-grant/` endpoint signed using Wordfence Central private key with short lived JWT.
[9723] Fix | Delete
// - Expects verifiable signature of incoming request from Wordfence Central.
[9724] Fix | Delete
// - Stores auth grant JWT.
[9725] Fix | Delete
[9726] Fix | Delete
$wfCentralAuthGrant = wfConfig::get('wordfenceCentralUserSiteAuthGrant');
[9727] Fix | Delete
if ($wfCentralAuthGrant) {
[9728] Fix | Delete
wfConfig::set('wordfenceCentralCurrentStep', 5);
[9729] Fix | Delete
return array(
[9730] Fix | Delete
'success' => 1,
[9731] Fix | Delete
);
[9732] Fix | Delete
}
[9733] Fix | Delete
return array(
[9734] Fix | Delete
'success' => 0,
[9735] Fix | Delete
);
[9736] Fix | Delete
}
[9737] Fix | Delete
[9738] Fix | Delete
public static function ajax_wfcentral_step5_callback() {
[9739] Fix | Delete
// Step 5: Makes POST request to `/central/api/site/<guid>/access-token` endpoint signed using Wordfence plugin private key with auth grant JWT.
[9740] Fix | Delete
// - Expects 200 response with access token.
[9741] Fix | Delete
[9742] Fix | Delete
$wfCentralAuthGrant = wfConfig::get('wordfenceCentralUserSiteAuthGrant');
[9743] Fix | Delete
if (!$wfCentralAuthGrant) {
[9744] Fix | Delete
return array(
[9745] Fix | Delete
'error' => 1,
[9746] Fix | Delete
'errorMsg' => __('Auth grant not found.', 'wordfence'),
[9747] Fix | Delete
);
[9748] Fix | Delete
}
[9749] Fix | Delete
[9750] Fix | Delete
try {
[9751] Fix | Delete
$request = new wfCentralAuthenticatedAPIRequest(
[9752] Fix | Delete
sprintf('/site/%s/access-token', wfConfig::get('wordfenceCentralSiteID')),
[9753] Fix | Delete
'POST',
[9754] Fix | Delete
array(
[9755] Fix | Delete
'data' => array(
[9756] Fix | Delete
'attributes' => array(
[9757] Fix | Delete
'auth-grant' => $wfCentralAuthGrant,
[9758] Fix | Delete
),
[9759] Fix | Delete
),
[9760] Fix | Delete
));
[9761] Fix | Delete
$response = $request->execute();
[9762] Fix | Delete
if ($response->isError()) {
[9763] Fix | Delete
return $response->returnErrorArray();
[9764] Fix | Delete
}
[9765] Fix | Delete
[9766] Fix | Delete
$body = $response->getJSONBody();
[9767] Fix | Delete
if (!is_array($body) || !isset($body['access-token'])) {
[9768] Fix | Delete
return array(
[9769] Fix | Delete
'error' => 1,
[9770] Fix | Delete
'errorMsg' => __('Invalid response from Wordfence Central.', 'wordfence'),
[9771] Fix | Delete
);
[9772] Fix | Delete
}
[9773] Fix | Delete
wfConfig::set('wordfenceCentralUserSiteAccessToken', $body['access-token']);
[9774] Fix | Delete
wfConfig::set('wordfenceCentralCurrentStep', 6);
[9775] Fix | Delete
[9776] Fix | Delete
return array(
[9777] Fix | Delete
'success' => 1,
[9778] Fix | Delete
'access-token' => $body['access-token'],
[9779] Fix | Delete
'redirect-url' => sprintf(WORDFENCE_CENTRAL_URL_SEC . '/sites/%s?access-token=%s',
[9780] Fix | Delete
rawurlencode(wfConfig::get('wordfenceCentralSiteID')), rawurlencode($body['access-token'])),
[9781] Fix | Delete
);
[9782] Fix | Delete
[9783] Fix | Delete
}
[9784] Fix | Delete
catch (wfCentralAPIException $e) {
[9785] Fix | Delete
return array(
[9786] Fix | Delete
'error' => 1,
[9787] Fix | Delete
'errorMsg' => $e->getMessage(),
[9788] Fix | Delete
);
[9789] Fix | Delete
}
[9790] Fix | Delete
catch (Exception $e) {
[9791] Fix | Delete
wfCentralAPIRequest::handleInternalCentralAPIError($e);
[9792] Fix | Delete
return array(
[9793] Fix | Delete
'error' => 1,
[9794] Fix | Delete
'errorMsg' => $e->getMessage(),
[9795] Fix | Delete
);
[9796] Fix | Delete
}
[9797] Fix | Delete
catch (Throwable $t) {
[9798] Fix | Delete
wfCentralAPIRequest::handleInternalCentralAPIError($t);
[9799] Fix | Delete
return array(
[9800] Fix | Delete
'error' => 1,
[9801] Fix | Delete
'errorMsg' => $t->getMessage(),
[9802] Fix | Delete
);
[9803] Fix | Delete
}
[9804] Fix | Delete
}
[9805] Fix | Delete
public static function ajax_wfcentral_step6_callback() {
[9806] Fix | Delete
$wfCentralUserSiteAccessToken = wfConfig::get('wordfenceCentralUserSiteAccessToken');
[9807] Fix | Delete
if (!$wfCentralUserSiteAccessToken) {
[9808] Fix | Delete
return array(
[9809] Fix | Delete
'error' => 1,
[9810] Fix | Delete
'errorMsg' => __('Access token not found.', 'wordfence'),
[9811] Fix | Delete
);
[9812] Fix | Delete
}
[9813] Fix | Delete
[9814] Fix | Delete
$status = wfConfig::get('scanStageStatuses');
[9815] Fix | Delete
wfCentral::updateScanStatus($status);
[9816] Fix | Delete
[9817] Fix | Delete
wfConfig::set('wordfenceCentralConnectTime', time());
[9818] Fix | Delete
wfConfig::set('wordfenceCentralConnectEmail', wp_get_current_user()->user_email);
[9819] Fix | Delete
[9820] Fix | Delete
return array(
[9821] Fix | Delete
'success' => 1,
[9822] Fix | Delete
'access-token' => $wfCentralUserSiteAccessToken,
[9823] Fix | Delete
'redirect-url' => sprintf(WORDFENCE_CENTRAL_URL_SEC . '/sites/%s?access-token=%s',
[9824] Fix | Delete
rawurlencode(wfConfig::get('wordfenceCentralSiteID')), rawurlencode($wfCentralUserSiteAccessToken)),
[9825] Fix | Delete
);
[9826] Fix | Delete
}
[9827] Fix | Delete
[9828] Fix | Delete
public static function ajax_wfcentral_disconnect_callback() {
[9829] Fix | Delete
$dismiss = array_key_exists('dismiss', $_POST) && wfUtils::truthyToBoolean($_POST['dismiss']);
[9830] Fix | Delete
if ($dismiss) {
[9831] Fix | Delete
wfConfig::set('centralUrlMismatchChoice', '1');
[9832] Fix | Delete
return array(
[9833] Fix | Delete
'success' => true,
[9834] Fix | Delete
);
[9835] Fix | Delete
}
[9836] Fix | Delete
[9837] Fix | Delete
$force = array_key_exists('force', $_POST) && $_POST['force'] === 'true';
[9838] Fix | Delete
$localOnly = array_key_exists('local', $_POST) && $_POST['local'] === 'true';
[9839] Fix | Delete
$message = null;
[9840] Fix | Delete
if (!$localOnly) {
[9841] Fix | Delete
try {
[9842] Fix | Delete
if ($force || !wfCentral::isCentralSiteUrlMismatched()) {
[9843] Fix | Delete
$request = new wfCentralAuthenticatedAPIRequest(
[9844] Fix | Delete
sprintf('/site/%s', wfConfig::get('wordfenceCentralSiteID')),
[9845] Fix | Delete
'DELETE');
[9846] Fix | Delete
$response = $request->execute();
[9847] Fix | Delete
if ($response->isError()) {
[9848] Fix | Delete
return $response->returnErrorArray();
[9849] Fix | Delete
}
[9850] Fix | Delete
}
[9851] Fix | Delete
else {
[9852] Fix | Delete
$message = sprintf(__('The current site URL does not match the Wordfence Central connection information. Local connection information has been removed, but %s is still registered in Wordfence Central.', 'wordfence'), wfCentral::getCentralSiteUrl());
[9853] Fix | Delete
}
[9854] Fix | Delete
}
[9855] Fix | Delete
catch (wfCentralAPIException $e) {
[9856] Fix | Delete
return array(
[9857] Fix | Delete
'success' => false,
[9858] Fix | Delete
'errorMsg' => __('Unable to communicate with Wordfence Central', 'wordfence')
[9859] Fix | Delete
);
[9860] Fix | Delete
}
[9861] Fix | Delete
catch (Exception $e) {
[9862] Fix | Delete
wfCentralAPIRequest::handleInternalCentralAPIError($e);
[9863] Fix | Delete
}
[9864] Fix | Delete
catch (Throwable $t) {
[9865] Fix | Delete
wfCentralAPIRequest::handleInternalCentralAPIError($t);
[9866] Fix | Delete
}
[9867] Fix | Delete
}
[9868] Fix | Delete
[9869] Fix | Delete
wfRESTConfigController::disconnectConfig();
[9870] Fix | Delete
[9871] Fix | Delete
return array(
[9872] Fix | Delete
'success' => true,
[9873] Fix | Delete
'message' => $message,
[9874] Fix | Delete
'title' => __('Disconnected from Wordfence Central')
[9875] Fix | Delete
);
[9876] Fix | Delete
}
[9877] Fix | Delete
[9878] Fix | Delete
public static function queueCentralConfigurationSync($key, $value) {
[9879] Fix | Delete
static $hasRun;
[9880] Fix | Delete
if ($hasRun) {
[9881] Fix | Delete
return;
[9882] Fix | Delete
}
[9883] Fix | Delete
[9884] Fix | Delete
$ignored = array(
[9885] Fix | Delete
\WordfenceLS\Controller_Settings::OPTION_USE_NTP,
[9886] Fix | Delete
\WordfenceLS\Controller_Settings::OPTION_NTP_OFFSET,
[9887] Fix | Delete
\WordfenceLS\Controller_Settings::OPTION_ALLOW_DISABLING_NTP,
[9888] Fix | Delete
\WordfenceLS\Controller_Settings::OPTION_NTP_FAILURE_COUNT,
[9889] Fix | Delete
\WordfenceLS\Controller_Settings::OPTION_CAPTCHA_STATS,
[9890] Fix | Delete
);
[9891] Fix | Delete
if (in_array($key, $ignored)) {
[9892] Fix | Delete
return;
[9893] Fix | Delete
}
[9894] Fix | Delete
[9895] Fix | Delete
$hasRun = true;
[9896] Fix | Delete
add_action('shutdown', 'wfCentral::requestConfigurationSync');
[9897] Fix | Delete
}
[9898] Fix | Delete
[9899] Fix | Delete
public static function hasWoocommerce() {
[9900] Fix | Delete
return class_exists('woocommerce');
[9901] Fix | Delete
}
[9902] Fix | Delete
}
[9903] Fix | Delete
[9904] Fix | Delete
[9905] Fix | Delete
class wfWAFAutoPrependHelper {
[9906] Fix | Delete
[9907] Fix | Delete
private $serverConfig;
[9908] Fix | Delete
/**
[9909] Fix | Delete
* @var string
[9910] Fix | Delete
*/
[9911] Fix | Delete
private $currentAutoPrependedFile;
[9912] Fix | Delete
[9913] Fix | Delete
public static function helper($serverConfig = null, $currentAutoPrependedFile = null) {
[9914] Fix | Delete
return new wfWAFAutoPrependHelper($serverConfig, $currentAutoPrependedFile);
[9915] Fix | Delete
}
[9916] Fix | Delete
[9917] Fix | Delete
public static function isValidServerConfig($serverConfig) {
[9918] Fix | Delete
$validValues = array(
[9919] Fix | Delete
"apache-mod_php",
[9920] Fix | Delete
"apache-suphp",
[9921] Fix | Delete
"cgi",
[9922] Fix | Delete
"litespeed",
[9923] Fix | Delete
"nginx",
[9924] Fix | Delete
"iis",
[9925] Fix | Delete
'manual',
[9926] Fix | Delete
);
[9927] Fix | Delete
return in_array($serverConfig, $validValues);
[9928] Fix | Delete
}
[9929] Fix | Delete
[9930] Fix | Delete
/**
[9931] Fix | Delete
* Verifies the .htaccess block for mod_php if present, returning true if no changes need to happen, false
[9932] Fix | Delete
* if something needs to update.
[9933] Fix | Delete
*
[9934] Fix | Delete
* @return bool
[9935] Fix | Delete
*/
[9936] Fix | Delete
public static function verifyHtaccessMod_php() {
[9937] Fix | Delete
if (WFWAF_AUTO_PREPEND && PHP_MAJOR_VERSION > 5) {
[9938] Fix | Delete
return true;
[9939] Fix | Delete
}
[9940] Fix | Delete
[9941] Fix | Delete
$serverInfo = wfWebServerInfo::createFromEnvironment();
[9942] Fix | Delete
if (!$serverInfo->isApacheModPHP()) {
[9943] Fix | Delete
return true;
[9944] Fix | Delete
}
[9945] Fix | Delete
[9946] Fix | Delete
$htaccessPath = wfUtils::getHomePath() . '.htaccess';
[9947] Fix | Delete
if (file_exists($htaccessPath)) {
[9948] Fix | Delete
$htaccessContent = file_get_contents($htaccessPath);
[9949] Fix | Delete
$regex = '/# Wordfence WAF.*?# END Wordfence WAF/is';
[9950] Fix | Delete
if (preg_match($regex, $htaccessContent, $matches)) {
[9951] Fix | Delete
$wafBlock = $matches[0];
[9952] Fix | Delete
$hasPHP5 = preg_match('/<IfModule mod_php5\.c>\s*php_value auto_prepend_file \'.*?\'\s*<\/IfModule>/is', $wafBlock);
[9953] Fix | Delete
$hasPHP7 = preg_match('/<IfModule mod_php7\.c>\s*php_value auto_prepend_file \'.*?\'\s*<\/IfModule>/is', $wafBlock);
[9954] Fix | Delete
$hasPHP8 = preg_match('/<IfModule mod_php\.c>\s*php_value auto_prepend_file \'.*?\'\s*<\/IfModule>/is', $wafBlock);
[9955] Fix | Delete
if ($hasPHP5 && (!$hasPHP7 || !$hasPHP8)) { //Check if PHP 5 is configured, but not 7 or 8.
[9956] Fix | Delete
return false;
[9957] Fix | Delete
}
[9958] Fix | Delete
}
[9959] Fix | Delete
}
[9960] Fix | Delete
[9961] Fix | Delete
return true;
[9962] Fix | Delete
}
[9963] Fix | Delete
[9964] Fix | Delete
/**
[9965] Fix | Delete
* Updates the mod_php block of the .htaccess if needed to include PHP 7. Returns whether or not this was performed successfully.
[9966] Fix | Delete
*
[9967] Fix | Delete
* @return bool
[9968] Fix | Delete
*/
[9969] Fix | Delete
public static function fixHtaccessMod_php() {
[9970] Fix | Delete
$htaccessPath = wfUtils::getHomePath() . '.htaccess';
[9971] Fix | Delete
if (file_exists($htaccessPath)) {
[9972] Fix | Delete
$htaccessContent = file_get_contents($htaccessPath);
[9973] Fix | Delete
$regex = '/# Wordfence WAF.*?# END Wordfence WAF/is';
[9974] Fix | Delete
if (preg_match($regex, $htaccessContent, $matches, PREG_OFFSET_CAPTURE)) {
[9975] Fix | Delete
$wafBlock = $matches[0][0];
[9976] Fix | Delete
$hasPHP5 = preg_match('/<IfModule mod_php5\.c>\s*php_value auto_prepend_file \'(.*?)\'\s*<\/IfModule>/is', $wafBlock, $php5Matches, PREG_OFFSET_CAPTURE);
[9977] Fix | Delete
$hasPHP7 = preg_match('/<IfModule mod_php7\.c>\s*php_value auto_prepend_file \'.*?\'\s*<\/IfModule>/is', $wafBlock, $php7Matches, PREG_OFFSET_CAPTURE);
[9978] Fix | Delete
$hasPHP8 = preg_match('/<IfModule mod_php\.c>\s*php_value auto_prepend_file \'.*?\'\s*<\/IfModule>/is', $wafBlock);
[9979] Fix | Delete
if ($hasPHP5 && !$hasPHP7) {
[9980] Fix | Delete
$beforeWAFBlock = substr($htaccessContent, 0, $matches[0][1]);
[9981] Fix | Delete
$afterWAFBlock = substr($htaccessContent, $matches[0][1] + strlen($wafBlock));
[9982] Fix | Delete
$beforeMod_php = substr($wafBlock, 0, $php5Matches[0][1]);
[9983] Fix | Delete
$afterMod_php = substr($wafBlock, $php5Matches[0][1] + strlen($php5Matches[0][0]));
[9984] Fix | Delete
$updatedHtaccessContent = $beforeWAFBlock . $beforeMod_php . $php5Matches[0][0] . "\n" . sprintf("<IfModule mod_php7.c>\n\tphp_value auto_prepend_file '%1\$s'\n</IfModule>\n<IfModule mod_php.c>\n\tphp_value auto_prepend_file '%1\$s'\n</IfModule>", $php5Matches[1][0] /* already escaped */) . $afterMod_php . $afterWAFBlock;
[9985] Fix | Delete
return file_put_contents($htaccessPath, $updatedHtaccessContent) !== false;
[9986] Fix | Delete
}
[9987] Fix | Delete
if ($hasPHP5 && $hasPHP7 && !$hasPHP8) {
[9988] Fix | Delete
$beforeWAFBlock = substr($htaccessContent, 0, $matches[0][1]);
[9989] Fix | Delete
$afterWAFBlock = substr($htaccessContent, $matches[0][1] + strlen($wafBlock));
[9990] Fix | Delete
$beforeMod_php = substr($wafBlock, 0, $php5Matches[0][1]);
[9991] Fix | Delete
$afterMod_php = substr($wafBlock, $php7Matches[0][1] + strlen($php7Matches[0][0]));
[9992] Fix | Delete
$updatedHtaccessContent = $beforeWAFBlock . $beforeMod_php . $php5Matches[0][0] . "\n" . $php7Matches[0][0] . "\n" . sprintf("<IfModule mod_php.c>\n\tphp_value auto_prepend_file '%s'\n</IfModule>", $php5Matches[1][0] /* already escaped */) . $afterMod_php . $afterWAFBlock;
[9993] Fix | Delete
return file_put_contents($htaccessPath, $updatedHtaccessContent) !== false;
[9994] Fix | Delete
}
[9995] Fix | Delete
}
[9996] Fix | Delete
}
[9997] Fix | Delete
return false;
[9998] Fix | Delete
}
[9999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function