Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/litespee.../src
File: htaccess.cls.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* The htaccess rewrite rule operation class.
[2] Fix | Delete
*
[3] Fix | Delete
* Responsible for reading, writing, and generating .htaccess rules used by LiteSpeed Cache.
[4] Fix | Delete
*
[5] Fix | Delete
* @package LiteSpeed
[6] Fix | Delete
* @since 1.0.0
[7] Fix | Delete
*/
[8] Fix | Delete
[9] Fix | Delete
namespace LiteSpeed;
[10] Fix | Delete
[11] Fix | Delete
defined( 'WPINC' ) || exit();
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* Class Htaccess
[15] Fix | Delete
*
[16] Fix | Delete
* Provides utilities to locate, read, backup, and write .htaccess files for both frontend and backend,
[17] Fix | Delete
* as well as generate and manage LiteSpeed-specific rule blocks.
[18] Fix | Delete
*/
[19] Fix | Delete
class Htaccess extends Root {
[20] Fix | Delete
[21] Fix | Delete
/**
[22] Fix | Delete
* Absolute path to the frontend `.htaccess`.
[23] Fix | Delete
*
[24] Fix | Delete
* @var string|null
[25] Fix | Delete
*/
[26] Fix | Delete
private $frontend_htaccess = null;
[27] Fix | Delete
[28] Fix | Delete
/**
[29] Fix | Delete
* Default/auto-detected frontend `.htaccess` path before filters/overrides.
[30] Fix | Delete
*
[31] Fix | Delete
* @var string|null
[32] Fix | Delete
*/
[33] Fix | Delete
private $_default_frontend_htaccess = null;
[34] Fix | Delete
[35] Fix | Delete
/**
[36] Fix | Delete
* Absolute path to the backend `.htaccess`.
[37] Fix | Delete
*
[38] Fix | Delete
* @var string|null
[39] Fix | Delete
*/
[40] Fix | Delete
private $backend_htaccess = null;
[41] Fix | Delete
[42] Fix | Delete
/**
[43] Fix | Delete
* Default/auto-detected backend `.htaccess` path before filters/overrides.
[44] Fix | Delete
*
[45] Fix | Delete
* @var string|null
[46] Fix | Delete
*/
[47] Fix | Delete
private $_default_backend_htaccess = null;
[48] Fix | Delete
[49] Fix | Delete
/**
[50] Fix | Delete
* Whether the frontend `.htaccess` (or its directory) is readable.
[51] Fix | Delete
*
[52] Fix | Delete
* @var bool
[53] Fix | Delete
*/
[54] Fix | Delete
private $frontend_htaccess_readable = false;
[55] Fix | Delete
[56] Fix | Delete
/**
[57] Fix | Delete
* Whether the frontend `.htaccess` (or its directory) is writable.
[58] Fix | Delete
*
[59] Fix | Delete
* @var bool
[60] Fix | Delete
*/
[61] Fix | Delete
private $frontend_htaccess_writable = false;
[62] Fix | Delete
[63] Fix | Delete
/**
[64] Fix | Delete
* Whether the backend `.htaccess` (or its directory) is readable.
[65] Fix | Delete
*
[66] Fix | Delete
* @var bool
[67] Fix | Delete
*/
[68] Fix | Delete
private $backend_htaccess_readable = false;
[69] Fix | Delete
[70] Fix | Delete
/**
[71] Fix | Delete
* Whether the backend `.htaccess` (or its directory) is writable.
[72] Fix | Delete
*
[73] Fix | Delete
* @var bool
[74] Fix | Delete
*/
[75] Fix | Delete
private $backend_htaccess_writable = false;
[76] Fix | Delete
[77] Fix | Delete
/**
[78] Fix | Delete
* Lines that turn on and guard rewrite/module blocks.
[79] Fix | Delete
*
[80] Fix | Delete
* @var array<int,string>
[81] Fix | Delete
*/
[82] Fix | Delete
private $__rewrite_on;
[83] Fix | Delete
[84] Fix | Delete
/**
[85] Fix | Delete
* Lines that turn on and guard general rewrite/module blocks.
[86] Fix | Delete
*
[87] Fix | Delete
* @var array<int,string>
[88] Fix | Delete
*/
[89] Fix | Delete
private $__rewrite_general;
[90] Fix | Delete
[91] Fix | Delete
const LS_MODULE_START = '<IfModule LiteSpeed>';
[92] Fix | Delete
const EXPIRES_MODULE_START = '<IfModule mod_expires.c>';
[93] Fix | Delete
const LS_MODULE_END = '</IfModule>';
[94] Fix | Delete
const LS_MODULE_REWRITE_START = '<IfModule mod_rewrite.c>';
[95] Fix | Delete
const REWRITE_ON = 'RewriteEngine on';
[96] Fix | Delete
const LS_MODULE_DONOTEDIT = '## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##';
[97] Fix | Delete
const MARKER = 'LSCACHE';
[98] Fix | Delete
const MARKER_NONLS = 'NON_LSCACHE';
[99] Fix | Delete
const MARKER_LOGIN_COOKIE = '### marker LOGIN COOKIE';
[100] Fix | Delete
const MARKER_ASYNC = '### marker ASYNC';
[101] Fix | Delete
const MARKER_CRAWLER = '### marker CRAWLER';
[102] Fix | Delete
const MARKER_MOBILE = '### marker MOBILE';
[103] Fix | Delete
const MARKER_NOCACHE_COOKIES = '### marker NOCACHE COOKIES';
[104] Fix | Delete
const MARKER_NOCACHE_USER_AGENTS = '### marker NOCACHE USER AGENTS';
[105] Fix | Delete
const MARKER_CACHE_RESOURCE = '### marker CACHE RESOURCE';
[106] Fix | Delete
const MARKER_BROWSER_CACHE = '### marker BROWSER CACHE';
[107] Fix | Delete
const MARKER_MINIFY = '### marker MINIFY';
[108] Fix | Delete
const MARKER_CORS = '### marker CORS';
[109] Fix | Delete
const MARKER_WEBP = '### marker WEBP';
[110] Fix | Delete
const MARKER_DROPQS = '### marker DROPQS';
[111] Fix | Delete
const MARKER_START = ' start ###';
[112] Fix | Delete
const MARKER_END = ' end ###';
[113] Fix | Delete
[114] Fix | Delete
/**
[115] Fix | Delete
* Initialize the class and set its properties.
[116] Fix | Delete
*
[117] Fix | Delete
* @since 1.0.7
[118] Fix | Delete
*/
[119] Fix | Delete
public function __construct() {
[120] Fix | Delete
$this->_path_set();
[121] Fix | Delete
$this->_default_frontend_htaccess = $this->frontend_htaccess;
[122] Fix | Delete
$this->_default_backend_htaccess = $this->backend_htaccess;
[123] Fix | Delete
[124] Fix | Delete
$frontend_htaccess = defined( 'LITESPEED_CFG_HTACCESS' ) ? constant( 'LITESPEED_CFG_HTACCESS' ) : false;
[125] Fix | Delete
if ( $frontend_htaccess && substr( $frontend_htaccess, -10 ) === '/.htaccess' ) {
[126] Fix | Delete
$this->frontend_htaccess = $frontend_htaccess;
[127] Fix | Delete
}
[128] Fix | Delete
$backend_htaccess = defined( 'LITESPEED_CFG_HTACCESS_BACKEND' ) ? constant( 'LITESPEED_CFG_HTACCESS_BACKEND' ) : false;
[129] Fix | Delete
if ( $backend_htaccess && substr( $backend_htaccess, -10 ) === '/.htaccess' ) {
[130] Fix | Delete
$this->backend_htaccess = $backend_htaccess;
[131] Fix | Delete
}
[132] Fix | Delete
[133] Fix | Delete
// Filter for frontend & backend htaccess path.
[134] Fix | Delete
$this->frontend_htaccess = apply_filters( 'litespeed_frontend_htaccess', $this->frontend_htaccess );
[135] Fix | Delete
$this->backend_htaccess = apply_filters( 'litespeed_backend_htaccess', $this->backend_htaccess );
[136] Fix | Delete
[137] Fix | Delete
clearstatcache();
[138] Fix | Delete
[139] Fix | Delete
// Frontend .htaccess privilege.
[140] Fix | Delete
$test_permissions = file_exists( $this->frontend_htaccess ) ? $this->frontend_htaccess : dirname( $this->frontend_htaccess );
[141] Fix | Delete
if ( is_readable( $test_permissions ) ) {
[142] Fix | Delete
$this->frontend_htaccess_readable = true;
[143] Fix | Delete
}
[144] Fix | Delete
if ( is_writable( $test_permissions ) ) { // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_is_writable -- Checking permissions, not file operations.
[145] Fix | Delete
$this->frontend_htaccess_writable = true;
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
// General Rewrite Rules (Files/Logs protection)
[149] Fix | Delete
$this->__rewrite_general = [
[150] Fix | Delete
self::LS_MODULE_REWRITE_START, // <IfModule mod_rewrite.c>
[151] Fix | Delete
self::REWRITE_ON, // RewriteEngine on
[152] Fix | Delete
'RewriteRule ' . preg_quote(LITESPEED_DATA_FOLDER) . '/debug/.*\.log$ - [F,L]', // phpcs:ignore WordPress.PHP.PregQuoteDelimiter.Missing
[153] Fix | Delete
'RewriteRule ' . preg_quote(self::CONF_FILE) . ' - [F,L]', // phpcs:ignore WordPress.PHP.PregQuoteDelimiter.Missing
[154] Fix | Delete
self::LS_MODULE_END, // </IfModule>
[155] Fix | Delete
];
[156] Fix | Delete
[157] Fix | Delete
$this->__rewrite_on = [
[158] Fix | Delete
'CacheLookup on',
[159] Fix | Delete
'RewriteRule .* - [E=Cache-Control:no-autoflush]',
[160] Fix | Delete
];
[161] Fix | Delete
[162] Fix | Delete
// Backend .htaccess privilege.
[163] Fix | Delete
if ( $this->frontend_htaccess === $this->backend_htaccess ) {
[164] Fix | Delete
$this->backend_htaccess_readable = $this->frontend_htaccess_readable;
[165] Fix | Delete
$this->backend_htaccess_writable = $this->frontend_htaccess_writable;
[166] Fix | Delete
} else {
[167] Fix | Delete
$test_permissions = file_exists( $this->backend_htaccess ) ? $this->backend_htaccess : dirname( $this->backend_htaccess );
[168] Fix | Delete
if ( is_readable( $test_permissions ) ) {
[169] Fix | Delete
$this->backend_htaccess_readable = true;
[170] Fix | Delete
}
[171] Fix | Delete
if ( is_writable( $test_permissions ) ) { // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_is_writable -- Checking permissions, not file operations.
[172] Fix | Delete
$this->backend_htaccess_writable = true;
[173] Fix | Delete
}
[174] Fix | Delete
}
[175] Fix | Delete
}
[176] Fix | Delete
[177] Fix | Delete
/**
[178] Fix | Delete
* Get if htaccess file is readable.
[179] Fix | Delete
*
[180] Fix | Delete
* @since 1.1.0
[181] Fix | Delete
*
[182] Fix | Delete
* @param string $kind 'frontend' or 'backend'.
[183] Fix | Delete
* @return bool
[184] Fix | Delete
*/
[185] Fix | Delete
private function _readable( $kind = 'frontend' ) {
[186] Fix | Delete
if ( 'frontend' === $kind ) {
[187] Fix | Delete
return $this->frontend_htaccess_readable;
[188] Fix | Delete
}
[189] Fix | Delete
if ( 'backend' === $kind ) {
[190] Fix | Delete
return $this->backend_htaccess_readable;
[191] Fix | Delete
}
[192] Fix | Delete
return false;
[193] Fix | Delete
}
[194] Fix | Delete
[195] Fix | Delete
/**
[196] Fix | Delete
* Get if htaccess file is writable.
[197] Fix | Delete
*
[198] Fix | Delete
* @since 1.1.0
[199] Fix | Delete
*
[200] Fix | Delete
* @param string $kind 'frontend' or 'backend'.
[201] Fix | Delete
* @return bool
[202] Fix | Delete
*/
[203] Fix | Delete
public function writable( $kind = 'frontend' ) {
[204] Fix | Delete
if ( 'frontend' === $kind ) {
[205] Fix | Delete
return $this->frontend_htaccess_writable;
[206] Fix | Delete
}
[207] Fix | Delete
if ( 'backend' === $kind ) {
[208] Fix | Delete
return $this->backend_htaccess_writable;
[209] Fix | Delete
}
[210] Fix | Delete
return false;
[211] Fix | Delete
}
[212] Fix | Delete
[213] Fix | Delete
/**
[214] Fix | Delete
* Get frontend htaccess path.
[215] Fix | Delete
*
[216] Fix | Delete
* @since 1.1.0
[217] Fix | Delete
*
[218] Fix | Delete
* @param bool $show_default Whether to return the default/auto-detected path.
[219] Fix | Delete
* @return string
[220] Fix | Delete
*/
[221] Fix | Delete
public static function get_frontend_htaccess( $show_default = false ) {
[222] Fix | Delete
if ( $show_default ) {
[223] Fix | Delete
return self::cls()->_default_frontend_htaccess;
[224] Fix | Delete
}
[225] Fix | Delete
return self::cls()->frontend_htaccess;
[226] Fix | Delete
}
[227] Fix | Delete
[228] Fix | Delete
/**
[229] Fix | Delete
* Get backend htaccess path.
[230] Fix | Delete
*
[231] Fix | Delete
* @since 1.1.0
[232] Fix | Delete
*
[233] Fix | Delete
* @param bool $show_default Whether to return the default/auto-detected path.
[234] Fix | Delete
* @return string
[235] Fix | Delete
*/
[236] Fix | Delete
public static function get_backend_htaccess( $show_default = false ) {
[237] Fix | Delete
if ( $show_default ) {
[238] Fix | Delete
return self::cls()->_default_backend_htaccess;
[239] Fix | Delete
}
[240] Fix | Delete
return self::cls()->backend_htaccess;
[241] Fix | Delete
}
[242] Fix | Delete
[243] Fix | Delete
/**
[244] Fix | Delete
* Check to see if .htaccess exists starting at $start_path and going up directories until it hits DOCUMENT_ROOT.
[245] Fix | Delete
*
[246] Fix | Delete
* As dirname() strips the ending '/', paths passed in must exclude the final '/'.
[247] Fix | Delete
*
[248] Fix | Delete
* @since 1.0.11
[249] Fix | Delete
* @access private
[250] Fix | Delete
*
[251] Fix | Delete
* @param string $start_path Absolute path to begin searching from (without trailing slash).
[252] Fix | Delete
* @return string|false The directory containing .htaccess, or false if not found.
[253] Fix | Delete
*/
[254] Fix | Delete
private function _htaccess_search( $start_path ) {
[255] Fix | Delete
while ( ! file_exists( $start_path . '/.htaccess' ) ) {
[256] Fix | Delete
if ( '/' === $start_path || ! $start_path ) {
[257] Fix | Delete
return false;
[258] Fix | Delete
}
[259] Fix | Delete
[260] Fix | Delete
$doc_root = ! empty( $_SERVER['DOCUMENT_ROOT'] ) ? sanitize_text_field( wp_unslash( $_SERVER['DOCUMENT_ROOT'] ) ) : '';
[261] Fix | Delete
if ( $doc_root && wp_normalize_path( $start_path ) === wp_normalize_path( $doc_root ) ) {
[262] Fix | Delete
return false;
[263] Fix | Delete
}
[264] Fix | Delete
[265] Fix | Delete
if ( dirname( $start_path ) === $start_path ) {
[266] Fix | Delete
return false;
[267] Fix | Delete
}
[268] Fix | Delete
[269] Fix | Delete
$start_path = dirname( $start_path );
[270] Fix | Delete
}
[271] Fix | Delete
[272] Fix | Delete
return $start_path;
[273] Fix | Delete
}
[274] Fix | Delete
[275] Fix | Delete
/**
[276] Fix | Delete
* Set the path class variables.
[277] Fix | Delete
*
[278] Fix | Delete
* @since 1.0.11
[279] Fix | Delete
* @access private
[280] Fix | Delete
* @return void
[281] Fix | Delete
*/
[282] Fix | Delete
private function _path_set() {
[283] Fix | Delete
$frontend = Router::frontend_path();
[284] Fix | Delete
$frontend_htaccess_search = $this->_htaccess_search( $frontend ); // The existing .htaccess path to be used for frontend .htaccess.
[285] Fix | Delete
[286] Fix | Delete
$this->frontend_htaccess = $frontend;
[287] Fix | Delete
if ( $frontend_htaccess_search ) {
[288] Fix | Delete
$this->frontend_htaccess = $frontend_htaccess_search;
[289] Fix | Delete
}
[290] Fix | Delete
$this->frontend_htaccess .= '/.htaccess';
[291] Fix | Delete
[292] Fix | Delete
$backend = realpath( ABSPATH ); // /home/user/public_html/backend/
[293] Fix | Delete
if ( $frontend === $backend ) {
[294] Fix | Delete
$this->backend_htaccess = $this->frontend_htaccess;
[295] Fix | Delete
return;
[296] Fix | Delete
}
[297] Fix | Delete
[298] Fix | Delete
// Backend is a different path.
[299] Fix | Delete
$backend_htaccess_search = $this->_htaccess_search( $backend );
[300] Fix | Delete
// Found affected .htaccess.
[301] Fix | Delete
if ( $backend_htaccess_search ) {
[302] Fix | Delete
$this->backend_htaccess = $backend_htaccess_search . '/.htaccess';
[303] Fix | Delete
return;
[304] Fix | Delete
}
[305] Fix | Delete
[306] Fix | Delete
// Frontend path is the parent of backend path.
[307] Fix | Delete
if ( 0 === stripos( (string) $backend, $frontend . '/' ) ) {
[308] Fix | Delete
// Backend uses frontend htaccess.
[309] Fix | Delete
$this->backend_htaccess = $this->frontend_htaccess;
[310] Fix | Delete
return;
[311] Fix | Delete
}
[312] Fix | Delete
[313] Fix | Delete
$this->backend_htaccess = $backend . '/.htaccess';
[314] Fix | Delete
}
[315] Fix | Delete
[316] Fix | Delete
/**
[317] Fix | Delete
* Get corresponding htaccess path.
[318] Fix | Delete
*
[319] Fix | Delete
* @since 1.1.0
[320] Fix | Delete
*
[321] Fix | Delete
* @param string $kind Frontend or backend.
[322] Fix | Delete
* @return string Path.
[323] Fix | Delete
*/
[324] Fix | Delete
public function htaccess_path( $kind = 'frontend' ) {
[325] Fix | Delete
switch ( $kind ) {
[326] Fix | Delete
case 'backend':
[327] Fix | Delete
$path = $this->backend_htaccess;
[328] Fix | Delete
break;
[329] Fix | Delete
[330] Fix | Delete
case 'frontend':
[331] Fix | Delete
default:
[332] Fix | Delete
$path = $this->frontend_htaccess;
[333] Fix | Delete
break;
[334] Fix | Delete
}
[335] Fix | Delete
return $path;
[336] Fix | Delete
}
[337] Fix | Delete
[338] Fix | Delete
/**
[339] Fix | Delete
* Get the content of the rules file.
[340] Fix | Delete
*
[341] Fix | Delete
* NOTE: will throw error if failed.
[342] Fix | Delete
*
[343] Fix | Delete
* @since 1.0.4
[344] Fix | Delete
* @since 2.9 Used exception for failed reading.
[345] Fix | Delete
* @access public
[346] Fix | Delete
*
[347] Fix | Delete
* @param string $kind 'frontend' or 'backend'.
[348] Fix | Delete
* @return string The file content.
[349] Fix | Delete
* @throws \Exception If the file is not readable or cannot be retrieved.
[350] Fix | Delete
*/
[351] Fix | Delete
public function htaccess_read( $kind = 'frontend' ) {
[352] Fix | Delete
$path = $this->htaccess_path( $kind );
[353] Fix | Delete
[354] Fix | Delete
if ( ! $path || ! file_exists( $path ) ) {
[355] Fix | Delete
return "\n";
[356] Fix | Delete
}
[357] Fix | Delete
[358] Fix | Delete
if ( ! $this->_readable( $kind ) ) {
[359] Fix | Delete
Error::t( 'HTA_R' );
[360] Fix | Delete
}
[361] Fix | Delete
[362] Fix | Delete
$content = File::read( $path );
[363] Fix | Delete
if ( false === $content ) {
[364] Fix | Delete
Error::t( 'HTA_GET' );
[365] Fix | Delete
}
[366] Fix | Delete
[367] Fix | Delete
// Remove ^M characters.
[368] Fix | Delete
$content = str_ireplace( "\x0D", '', $content );
[369] Fix | Delete
return $content;
[370] Fix | Delete
}
[371] Fix | Delete
[372] Fix | Delete
/**
[373] Fix | Delete
* Try to backup the .htaccess file if we didn't save one before.
[374] Fix | Delete
*
[375] Fix | Delete
* NOTE: will throw error if failed.
[376] Fix | Delete
*
[377] Fix | Delete
* @since 1.0.10
[378] Fix | Delete
* @access private
[379] Fix | Delete
*
[380] Fix | Delete
* @param string $kind 'frontend' or 'backend'.
[381] Fix | Delete
* @return void
[382] Fix | Delete
* @throws \Exception If backup fails.
[383] Fix | Delete
*/
[384] Fix | Delete
private function _htaccess_backup( $kind = 'frontend' ) {
[385] Fix | Delete
$path = $this->htaccess_path( $kind );
[386] Fix | Delete
[387] Fix | Delete
if ( ! file_exists( $path ) ) {
[388] Fix | Delete
return;
[389] Fix | Delete
}
[390] Fix | Delete
[391] Fix | Delete
if ( file_exists( $path . '.bk' ) ) {
[392] Fix | Delete
return;
[393] Fix | Delete
}
[394] Fix | Delete
[395] Fix | Delete
$res = copy( $path, $path . '.bk' );
[396] Fix | Delete
[397] Fix | Delete
// Failed to backup, abort.
[398] Fix | Delete
if ( ! $res ) {
[399] Fix | Delete
Error::t( 'HTA_BK' );
[400] Fix | Delete
}
[401] Fix | Delete
}
[402] Fix | Delete
[403] Fix | Delete
/**
[404] Fix | Delete
* Get mobile view rule from htaccess file.
[405] Fix | Delete
*
[406] Fix | Delete
* NOTE: will throw error if failed.
[407] Fix | Delete
*
[408] Fix | Delete
* @since 1.1.0
[409] Fix | Delete
*
[410] Fix | Delete
* @return string The user agent regex for mobile detection.
[411] Fix | Delete
* @throws \Exception If the rule cannot be found.
[412] Fix | Delete
*/
[413] Fix | Delete
public function current_mobile_agents() {
[414] Fix | Delete
$rules = $this->_get_rule_by( self::MARKER_MOBILE );
[415] Fix | Delete
if ( ! isset( $rules[0] ) ) {
[416] Fix | Delete
Error::t( 'HTA_DNF', self::MARKER_MOBILE );
[417] Fix | Delete
}
[418] Fix | Delete
[419] Fix | Delete
$rule = trim( $rules[0] );
[420] Fix | Delete
$match = substr( $rule, strlen( 'RewriteCond %{HTTP_USER_AGENT} ' ), -strlen( ' [NC]' ) );
[421] Fix | Delete
[422] Fix | Delete
if ( ! $match ) {
[423] Fix | Delete
Error::t( 'HTA_DNF', __( 'Mobile Agent Rules', 'litespeed-cache' ) );
[424] Fix | Delete
}
[425] Fix | Delete
[426] Fix | Delete
return $match;
[427] Fix | Delete
}
[428] Fix | Delete
[429] Fix | Delete
/**
[430] Fix | Delete
* Parse rewrites rule from the .htaccess file.
[431] Fix | Delete
*
[432] Fix | Delete
* NOTE: will throw error if failed.
[433] Fix | Delete
*
[434] Fix | Delete
* @since 1.1.0
[435] Fix | Delete
* @access public
[436] Fix | Delete
*
[437] Fix | Delete
* @param string $kind 'frontend' or 'backend'.
[438] Fix | Delete
* @return string The parsed login-cookie vary rule.
[439] Fix | Delete
* @throws \Exception If the rule cannot be found or is invalid.
[440] Fix | Delete
*/
[441] Fix | Delete
public function current_login_cookie( $kind = 'frontend' ) {
[442] Fix | Delete
$rule = $this->_get_rule_by( self::MARKER_LOGIN_COOKIE, $kind );
[443] Fix | Delete
[444] Fix | Delete
if ( ! $rule ) {
[445] Fix | Delete
Error::t( 'HTA_DNF', self::MARKER_LOGIN_COOKIE );
[446] Fix | Delete
}
[447] Fix | Delete
[448] Fix | Delete
if ( 0 !== strpos( $rule, 'RewriteRule .? - [E=' ) ) {
[449] Fix | Delete
Error::t( 'HTA_LOGIN_COOKIE_INVALID' );
[450] Fix | Delete
}
[451] Fix | Delete
[452] Fix | Delete
$rule_cookie = substr( $rule, strlen( 'RewriteRule .? - [E=' ), -1 );
[453] Fix | Delete
[454] Fix | Delete
if ( LITESPEED_SERVER_TYPE === 'LITESPEED_SERVER_OLS' ) {
[455] Fix | Delete
$rule_cookie = trim( $rule_cookie, '"' );
[456] Fix | Delete
}
[457] Fix | Delete
[458] Fix | Delete
// Drop `Cache-Vary:`.
[459] Fix | Delete
$rule_cookie = substr( $rule_cookie, strlen( 'Cache-Vary:' ) );
[460] Fix | Delete
[461] Fix | Delete
return $rule_cookie;
[462] Fix | Delete
}
[463] Fix | Delete
[464] Fix | Delete
/**
[465] Fix | Delete
* Get rewrite rules based on the marker.
[466] Fix | Delete
*
[467] Fix | Delete
* @since 2.0
[468] Fix | Delete
* @access private
[469] Fix | Delete
*
[470] Fix | Delete
* @param string $cond Marker constant (e.g. self::MARKER_MOBILE).
[471] Fix | Delete
* @param string $kind 'frontend' or 'backend'.
[472] Fix | Delete
* @return string|array<int,string>|false Rule(s) or false if not found.
[473] Fix | Delete
*/
[474] Fix | Delete
private function _get_rule_by( $cond, $kind = 'frontend' ) {
[475] Fix | Delete
clearstatcache();
[476] Fix | Delete
$path = $this->htaccess_path( $kind );
[477] Fix | Delete
if ( ! $this->_readable( $kind ) ) {
[478] Fix | Delete
return false;
[479] Fix | Delete
}
[480] Fix | Delete
[481] Fix | Delete
$rules = File::extract_from_markers( $path, self::MARKER );
[482] Fix | Delete
if ( ! in_array( $cond . self::MARKER_START, $rules, true ) || ! in_array( $cond . self::MARKER_END, $rules, true ) ) {
[483] Fix | Delete
return false;
[484] Fix | Delete
}
[485] Fix | Delete
[486] Fix | Delete
$key_start = array_search( $cond . self::MARKER_START, $rules, true );
[487] Fix | Delete
$key_end = array_search( $cond . self::MARKER_END, $rules, true );
[488] Fix | Delete
if ( false === $key_start || false === $key_end ) {
[489] Fix | Delete
return false;
[490] Fix | Delete
}
[491] Fix | Delete
[492] Fix | Delete
$results = array_slice( $rules, $key_start + 1, $key_end - $key_start - 1 );
[493] Fix | Delete
if ( ! $results ) {
[494] Fix | Delete
return false;
[495] Fix | Delete
}
[496] Fix | Delete
[497] Fix | Delete
if ( count( $results ) === 1 ) {
[498] Fix | Delete
return trim( $results[0] );
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function