%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /opt/imunify360/venv/lib64/python3.8/site-packages/defence360agent/secure_site/
Upload File :
Create Path :
Current File : //opt/imunify360/venv/lib64/python3.8/site-packages/defence360agent/secure_site/control.py

"""
This program is free software: you can redistribute it and/or modify it under 
the terms of the GNU General Public License as published by 
the Free Software Foundation, either version 3 of the License, 
or (at your option) any later version.


This program is distributed in the hope that it will be useful, 
but WITHOUT ANY WARRANTY; without even the implied warranty of 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
See the GNU General Public License for more details.


You should have received a copy of the GNU General Public License
 along with this program.  If not, see <https://www.gnu.org/licenses/>.

Copyright © 2019 Cloud Linux Software Inc.

This software is also available under ImunifyAV commercial license,
see <https://www.imunify360.com/legal/eula>
"""
import functools
import logging
from distutils.version import StrictVersion

import blinker

from defence360agent.secure_site.constants import (
    BASIC,
    PRO,
    SECURE_SITE_EXTENSION_NAME,
    SECURE_SITE_PACKAGE_EXTENSION_FILES,
)
from defence360agent.secure_site.model import SecureSite
from defence360agent.subsys.panels.cpanel import cPanel
from defence360agent.subsys.panels.hosting_panel import HostingPanel

logger = logging.getLogger(__name__)


class Signals:
    updated = blinker.Signal()


def supported(func):
    """Do not run a function on an unsupported panel"""

    @functools.wraps(func)
    async def wrapper(*args, **kwargs):
        if await is_secure_site_supported():
            return await func(*args, **kwargs)
        logger.info("SecureSite is not supported")

    return wrapper


async def is_secure_site_supported():
    """Whether we support Secure Site on the panel."""

    hosting_panel = HostingPanel()
    if hosting_panel.NAME == cPanel.NAME:
        try:
            return StrictVersion(
                await hosting_panel.version()
            ) >= StrictVersion("68.0")
        except ValueError:
            return False

    return False


@supported
async def is_secure_site_extension_enabled():
    """Whether the Secure Site feature is enabled."""

    hp = HostingPanel()
    return (
        hp.is_extension_installed(SECURE_SITE_PACKAGE_EXTENSION_FILES)
        and await hp.is_hook_installed()
    )


@supported
async def enable_secure_site_extension():
    """Enable Secure Site."""

    hp = HostingPanel()
    if await is_secure_site_extension_enabled():
        logger.info("Imunify360 package extension had already been enabled.")
        return

    # reset secure site values for all existing users
    for secure_site_entry in SecureSite.select().where(
        SecureSite.subscription_type == PRO
    ):
        secure_site_entry.subscription_type = BASIC
        secure_site_entry.save()

    await hp.install_extension(
        SECURE_SITE_EXTENSION_NAME,
        SECURE_SITE_PACKAGE_EXTENSION_FILES,
        imunify360_secure_site=BASIC,
    )

    logger.info("Imunify360 Secure Site feature enabled.")
    return True


@supported
async def disable_secure_site_extension():
    """Disable Secure Site."""

    hp = HostingPanel()

    if not await is_secure_site_extension_enabled():
        logger.info("No Imunify360 package extensions to disable.")
        return True

    await hp.uninstall_extension(
        SECURE_SITE_EXTENSION_NAME,
        SECURE_SITE_PACKAGE_EXTENSION_FILES,
    )

    logger.info("Imunify360 Secure Site feature disabled.")
    return True  # disabled successfully

Zerion Mini Shell 1.0