ok

Mini Shell

Direktori : /opt/imunify360/venv/lib64/python3.11/site-packages/im360/subsys/
Upload File :
Current File : //opt/imunify360/venv/lib64/python3.11/site-packages/im360/subsys/webshield_mode.py

from pathlib import Path
from enum import StrEnum, unique

from im360.contracts.config import Webshield


_CONF_PATH = Path("/usr/share/imunify360-webshield/modularity_mode")


@unique
class Mode(StrEnum):
    STANDALONE = "standalone"
    APACHE = "apache"
    NGINX = "nginx"

    @classmethod
    def get(cls):
        try:
            mode = _CONF_PATH.read_text().strip()
            if mode == "apache":
                return cls.APACHE
            if mode == "nginx":
                return cls.NGINX
            if mode == "standalone":
                return cls.STANDALONE
            raise TypeError(f"Unknown mode: {mode}")
        except FileNotFoundError:
            return cls.STANDALONE

    @classmethod
    def wants_redirect(cls, mode) -> bool:
        if mode is cls.STANDALONE or mode is cls.APACHE:
            return True
        return False

    @classmethod
    def mode_is_correct(cls) -> bool:
        conf_mode = Webshield.MODE
        file_mode = cls.get()

        if conf_mode == "module" and file_mode in (cls.APACHE, cls.NGINX):
            return True
        if conf_mode == "proxy" and file_mode == cls.STANDALONE:
            return True
        return False


def get_module_based_ports() -> set[int]:
    # For now - hardcoded values. In the future maybe remake to a config file.
    return {80, 443}

Zerion Mini Shell 1.0