ok

Mini Shell

Direktori : /proc/self/root/opt/imunify360/venv/lib/python3.11/site-packages/im360/simple_rpc/
Upload File :
Current File : //proc/self/root/opt/imunify360/venv/lib/python3.11/site-packages/im360/simple_rpc/smart_advice.py

import logging
from defence360agent.api.server.events import EventsAPI
from defence360agent.rpc_tools import lookup
from defence360agent.utils import Scope
from defence360agent.contracts import config
from defence360agent.contracts.config import ControlPanelConfig
from defence360agent.contracts.myimunify_id import get_myimunify_users
from defence360agent.utils.whmcs import get_upgrade_url_link


class SmartAdviceEndpoints(lookup.RootEndpoints):
    SCOPE = Scope.IM360

    @lookup.bind("smart-advice", "notifications")
    async def smart_advice_notifications(self):
        if not ControlPanelConfig.SMART_ADVICE_ALLOWED:
            return []
        users_to_report = set(
            [
                item["username"]
                for item in await get_myimunify_users()
                if not item["protection"]
            ]
        )
        users_to_pop = set()
        for user in users_to_report:
            conf = config.ConfigFile(user)
            if not conf.get("CONTROL_PANEL", "smart_advice_allowed"):
                users_to_pop.add(user)
        users_to_report = users_to_report - users_to_pop
        response = await EventsAPI.smart_advices()
        logging.info(
            "Smart Advice events API response "
            "with notifications: %s, users to report: %s",
            str(response),
            str(users_to_report),
        )
        data = [
            event
            for event in response
            if event.get("smartadvice_user") in users_to_report
        ]

        for item in data:
            item["upgrade_url"] = get_upgrade_url_link(
                item.get("smartadvice_user"), item.get("smartadvice_domain")
            )
        return data

    @lookup.bind("smart-advice", "get-options")
    async def smart_advice_get_options(self):
        return {
            "mu_plugin_installation": ControlPanelConfig.SMART_ADVICE_ALLOWED,
            "advice_email_notification": ControlPanelConfig.ADVICE_EMAIL_NOTIFICATION,
        }

Zerion Mini Shell 1.0