Mini Shell

Direktori : /proc/self/root/opt/imh-python/lib/python3.9/site-packages/fpmstatus/
Upload File :
Current File : //proc/self/root/opt/imh-python/lib/python3.9/site-packages/fpmstatus/cwp_fpm.py

"""
Module for ensuring php-fpm fpmstatus support
"""
from pathlib import Path

def is_cwp():
    return Path("/usr/local/cwpsrv").exists()

def check_if_patched(file: Path):
    if "\npm.status_path = /status" in file.read_text():
        return True
    else:
        return False

def update_conf(file: Path):
    """
    Add pm.status_path = /status to php fpm conf
    """
    if file.name != "nobody.conf":
        lines = file.read_text().splitlines()
        # Check if the exact line is present and not commented
        status_line = "pm.status_path = /status"
        if not any(
            line.strip() == status_line
            for line in lines
            if not line.strip().startswith(("#", ";"))
        ):
            lines.append(
                status_line + "\n"
            )  # Append with a newline character
            file.write_text("\n".join(lines))
            return True
    return False

def check_full_support():
    """
    Check if environment is fully patched up
    """
    for file in Path("/opt/alt/").glob("./php-fpm*/usr/etc/php-fpm.d/users/*.conf"):
        if file.name == "nobody.conf":
            continue

        if not check_if_patched(file):
            return False

    template_dir = Path(
        "/usr/local/cwpsrv/htdocs/resources/conf/web_servers/vhosts/php-fpm/"
    )
    for template_file in template_dir.glob("*.tpl"):
        if not check_if_patched(template_file):
            return False
    return True


def deploy_support():
    # Define the directory and pattern to search for .conf files
    changed = False
    for file in Path("/opt/alt/").glob("./php-fpm*/usr/etc/php-fpm.d/users/*.conf"):
        # Check if the file does not end with 'nobody.conf'
        if update_conf(file):
            print(f"{file} file updated.")
            changed = True

    template_dir = Path(
        "/usr/local/cwpsrv/htdocs/resources/conf/web_servers/vhosts/php-fpm/"
    )
    for template_file in template_dir.glob("*.tpl"):
        if update_conf(template_file):
            changed = True
            print(f"PHP-FPM template file {template_file.name} updated.")

    if changed:
        print(
            "PHP-FPM status page enabled. You must restart php-fpm to apply the changes."
        )

Zerion Mini Shell 1.0