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/subsys/panels/directadmin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]


Current File : //opt/imunify360/venv/lib/python3.11/site-packages/im360/subsys/panels/directadmin/custombuild.py
import asyncio
import logging
import functools
import os

from defence360agent.subsys.panels.base import PanelException
from defence360agent.subsys.panels.directadmin.config import ConfigOptions
from defence360agent.utils import check_run, CheckRunError

logger = logging.getLogger(__name__)


BASEDIR = "/usr/local/directadmin/custombuild"
BUILD = os.path.join(BASEDIR, "build")


class CustomBuildOptions(ConfigOptions):
    DEFAULT_FILENAME = os.path.join(BASEDIR, "options.conf")


async def build(option):
    MAX_RETRIES = 3
    for attempt in range(MAX_RETRIES + 1):
        try:
            return await check_run([BUILD, option], cwd=BASEDIR)
        except CheckRunError as e:
            if attempt == MAX_RETRIES:
                raise PanelException(
                    "Failed to run custombuild command '{} {}' after {}"
                    " attempts: {}".format(BUILD, option, MAX_RETRIES, e)
                )
            if "Another instance of custombuild" in str(e):
                logger.warning(
                    "Failed to run custombuild command '%s %s': %s",
                    BUILD,
                    option,
                    e,
                )
                logger.info("Retrying custombuild command after delay...")
                await asyncio.sleep(5)
            else:
                raise PanelException(
                    "Failed to run custombuild command '{} {}': {}".format(
                        BUILD, option, e
                    )
                )


def custombuild2_only(fun):
    @functools.wraps(fun)
    async def wrapper(*args, **kwargs):
        try:
            out = await build("version")
        except (CheckRunError, FileNotFoundError, PermissionError):
            pass
        else:
            if out.startswith(b"2."):
                return await fun(*args, **kwargs)
        raise PanelException(
            "{} is only supported on installations "
            "with Custombuild 2.0".format(fun.__name__)
        )

    return wrapper

F1le Man4ger