%PDF- %PDF-
Direktori : /opt/imunify360/venv/lib64/python3.8/site-packages/defence360agent/secure_site/ |
Current File : //opt/imunify360/venv/lib64/python3.8/site-packages/defence360agent/secure_site/plugin.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> """ from typing import Dict from defence360agent.contracts.permissions import logger from defence360agent.contracts.secure_site_id import add_secure_site_user from defence360agent.plugins.event_monitor_message_processor import ( SettingsChangeBase, ) from defence360agent.secure_site.constants import ( BASIC, SECURE_SITE, SECURE_SITE_EXTENSION_NAME, ) from defence360agent.secure_site.control import ( is_secure_site_extension_enabled, Signals, ) from defence360agent.secure_site.model import SecureSite from defence360agent.subsys.panels.cpanel import packages class SecureSiteSettingsChange(SettingsChangeBase): async def _get_settings_from_message(self, message): return {SECURE_SITE: message.data.get(SECURE_SITE_EXTENSION_NAME)} @classmethod async def _get_package_settings( cls, package_name: str, _: bool ) -> Dict[str, str]: logger.info("Getting package settings %s", package_name) pkg_info = await packages.get_package_info(package_name) secure_site_value = pkg_info.get(SECURE_SITE_EXTENSION_NAME) if secure_site_value: return {SECURE_SITE: secure_site_value} return cls._default_settings() async def _process_account_removed(self, message): await super()._process_account_removed(message) user = message.get("user") or message.get("username") if user: logger.info("Removing SecureSite settings for %s", user) SecureSite.delete().where(SecureSite.user == user).execute() async def _process_modify(self, message): # Change username in DB before processing the message further if "old_username" in message.data: # User renamed old_username = message.data["old_username"] SecureSite.update(user=message.username).where( SecureSite.user == old_username ).execute() await super()._process_modify(message) @staticmethod def _default_settings() -> Dict[str, str]: return { SECURE_SITE: BASIC, } async def on_settings_change(self, user, _, value): add_secure_site_user(user, value) Signals.updated.send(user) def _message_is_relatable(self, message): return ( SECURE_SITE_EXTENSION_NAME in message.data or message.get("hook") == "Create" or message.get("hook") == "Remove" or message.get("hook") == "change_package" ) async def is_enabled(self): return await is_secure_site_extension_enabled()