!C99Shell v. 2.0 [PHP 7 Update] [25.02.2019]!

Software: Apache. PHP/7.3.33 

uname -a: Linux acloudg.aryanict.com 4.18.0-513.9.1.lve.el8.x86_64 #1 SMP Mon Dec 4 15:01:22 UTC
2023 x86_64
 

uid=1095(katebhospital) gid=1098(katebhospital) groups=1098(katebhospital) 

Safe-mode: OFF (not secure)

/opt/cloudlinux/venv/lib/python3.11/site-packages/clwpos/user/   drwxr-xr-x
Free 290.85 GB of 429.69 GB (67.69%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Feedback    Self remove    Logout    


Viewing file:     cache.py (2.57 KB)      -rw-r--r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
import hashlib
import logging
import os
import pwd
from contextlib import contextmanager
from dataclasses import dataclass
from typing import ContextManager, Optional

from clwpos import constants, scoped_cache


def _get_cache_directory():
    user = pwd.getpwuid(os.geteuid())
    cache_dir = os.path.join(user.pw_dir, constants.USER_WPOS_DIR, '.cache')
    os.makedirs(cache_dir, exist_ok=True)

    return cache_dir


def _get_wp_config_modification_ts(wp_path):
    try:
        return os.path.getmtime(os.path.join(wp_path, 'wp-config.php'))
    except FileNotFoundError:
        return os.path.getmtime(os.path.join(wp_path, '../wp-config.php'))


@dataclass
class CacheRecord:
    # any data that we would like to save
    # important! do not use pickle or any other serializable
    # data format that might be loaded in root environment
    data: Optional[str]
    # marker which becomes true whenever we change our data
    is_dirty: bool = False
    
    def __setattr__(self, key, value):
        super().__setattr__('is_dirty', True)
        super().__setattr__(key, value)


@contextmanager
def wp_config_cache(key, path) -> ContextManager[CacheRecord]:
    # there is no need to cache these values
    # in not actively requested places
    if not scoped_cache.CACHING_ENABLED:
        yield CacheRecord(data=None)
        return

    ts = _get_wp_config_modification_ts(wp_path=path)

    record = CacheRecord(
        data=get(key, path, valid_after_ts=ts))
    try:
        yield record
    finally:
        if record.is_dirty:
            set(key, path, record.data)

def get(key: str, path: str, valid_after_ts: float) -> Optional[str]:
    cache_file = os.path.join(
        _get_cache_directory(), f'{key}.{hashlib.md5(path.encode()).hexdigest()}.cache')

    try:
        # if file was modified earlier than timestamp,
        # we assume that cache is expired
        if os.path.getmtime(cache_file) < valid_after_ts:
            logging.info('Cache "%s" assumed to be outdated', key)
            return None

        with open(cache_file, 'r') as f:
            cache_info_raw = f.read()
    except (IOError, OSError):
        # assume that file does not exist
        # or we don't have access
        logging.info('Cache "%s" is not existing or malformed', key)
        return None

    return cache_info_raw

def set(key: str, path:str, value: str) -> None:
    cache_file = os.path.join(
        _get_cache_directory(), f'{key}.{hashlib.md5(path.encode()).hexdigest()}.cache')

    try:
        with open(cache_file, 'w') as f:
            f.write(value)
    except (IOError, OSError):
        return None

:: Command execute ::

Enter:
 
Select:
 

:: Search ::
  - regexp 

:: Upload ::
 
[ Read-Only ]

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

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

--[ c99shell v. 2.0 [PHP 7 Update] [25.02.2019] maintained by KaizenLouie | C99Shell Github | Generation time: 0.0041 ]--