HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //opt/imunify360/venv/share/imunify360/scripts/migrate_csf/csf_conf.py
import re
from logger_config import get_logger


def get_csf_config_value(
    var_name: str, config_file="/etc/csf/csf.conf"
) -> str | None:
    logger = get_logger()
    try:
        with open(config_file, "r") as f:
            for line in f:
                # Strip whitespace and skip empty lines and comments
                line = line.strip()
                if not line or line.startswith("#"):
                    continue

                # Match pattern: VAR_NAME = "value" (with flexible whitespace)
                # This regex handles:
                # - Optional whitespace around = (e.g. VAR_NAME="value" or VAR_NAME= "value")
                # - Quoted values (double quotes, single quotes are not valid in CSF config)
                # - Captures the value inside quotes (e.g. "value")
                pattern = rf'^{re.escape(var_name)}\s*=\s*["]([^"]*)["]'
                match = re.match(pattern, line)

                if match:
                    return match.group(1)

        # Variable not found
        return None

    except FileNotFoundError:
        logger.error(f"Config file {config_file} not found")
        return None
    except PermissionError:
        logger.error(f"Permission denied reading {config_file}")
        return None
    except Exception as e:
        logger.error(f"Error reading config file: {e}")
        return None