HEX
Server: LiteSpeed
System: Linux s3604.bom1.stableserver.net 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64
User: dmstechonline (1480)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: //opt/imunify360/venv/lib64/python3.11/site-packages/im360/plugins/remoteip_install.py
import logging

from defence360agent.contracts.plugins import MessageSink

from defence360agent.subsys.web_server import NotRunningError

from im360.subsys.remoteip import ModRemoteIp

logger = logging.getLogger(__name__)


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

    async def _check_remoteip(self):
        remoteip = ModRemoteIp()
        if not remoteip.is_supported():
            logger.warning(
                "Automatic mod_remoteip installation is not supported"
                " on this server"
            )
        try:
            if not await remoteip.is_installed():
                await remoteip.install()
                logger.info("mod_remoteip successfully installed")
        except NotRunningError:
            logger.warning(
                "skipping installation due to apache server not running"
            )