MOON
Server: Apache
System: Linux server30c.hostingraja.org 3.10.0-962.3.2.lve1.5.63.el7.x86_64 #1 SMP Fri Oct 8 12:03:35 UTC 2021 x86_64
User: jibhires (1887)
PHP: 8.1.30
Disabled: show_source, system, shell_exec, passthru, exec, popen, proc_open, allow_url_fopen, symlink, escapeshellcmd, pcntl_exec
Upload Files
File: //opt/imunify360/venv/lib/python3.11/site-packages/im360/plugins/remoteip_install.py
import logging

from pathlib import Path

from defence360agent.contracts.plugins import MessageSink
from defence360agent.subsys.persistent_state import PERSISTENT_STATE_DIR
from defence360agent.utils import RecurringCheckStop, recurring_check

from im360.subsys.remoteip import ModRemoteIp
from im360.utils.check_lock import check_lock

logger = logging.getLogger(__name__)

_CHECK_PERIOD = 3600
LOCK_FILE = PERSISTENT_STATE_DIR / ".remote-ip-check.lock"


class RemoteIpInstall(MessageSink):
    async def create_sink(self, loop):
        self._loop = loop
        self._task = self._loop.create_task(self._check_remoteip())

    async def shutdown(self):
        self._task.cancel()
        await self._task

    @recurring_check(
        check_lock,
        check_period_first=True,
        check_lock_period=_CHECK_PERIOD,
        lock_file=LOCK_FILE,
    )
    async def _check_remoteip(self):
        remoteip = ModRemoteIp()
        if not remoteip.is_supported():
            logger.error(
                "Automatic mod_remoteip installation is not supported"
                " on this server"
            )
            raise RecurringCheckStop()
        if not await remoteip.is_installed():
            await remoteip.install()
            logger.info("mod_remoteip successfully installed")
        await remoteip.customize_logging()