Server : LiteSpeed
System : Linux server51.dnsbootclub.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
User : nandedex ( 1060)
PHP Version : 8.1.33
Disable Function : NONE
Directory :  /opt/imunify360/venv/lib/python3.11/site-packages/im360/simple_rpc/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]


Current File : //opt/imunify360/venv/lib/python3.11/site-packages/im360/simple_rpc/middleware.py
from functools import wraps

from im360.internals.strategy import Strategy
from im360.model.firewall import IPList


def add_strategy(f):
    @wraps(f)
    async def wrapper(*args, **kwargs):
        result = await f(*args, **kwargs)
        assert isinstance(result, dict), (
            "Result should be a dictionary %s" % result
        )
        result["strategy"] = Strategy.get()

        return result

    return wrapper


def replace_gray_splashscreen_with_gray(f):
    """
    Replaces 'GRAY_SPLASHSCREEN' value
    for *listname* field for queries like `graylist ip list`
    for compatibility with UI
    """

    @wraps(f)
    async def wrapper(*args, **kwargs):
        result = await f(*args, **kwargs)
        if not isinstance(result.get("items"), list):
            return result
        gray_splashscreen = IPList.GRAY_SPLASHSCREEN.lower()
        for item in result.get("items", []):
            if (
                isinstance(item, dict)
                and item.get("listname")
                and item["listname"].lower() == gray_splashscreen
            ):
                # use same case as it is
                item["listname"] = (
                    IPList.GRAY
                    if item["listname"].isupper()
                    else IPList.GRAY.lower()
                )
        return result

    return wrapper

F1le Man4ger