REDROOM
PHP 8.2.31
Path:
Logout
Edit File
Size: 2.64 KB
Close
/opt/imunify360/venv/lib64/python3.11/site-packages/defence360agent/feature_management/hooks.py
Text
Base64
""" This module contains hook, which are called on feature management permission changes. Note that hooks are not executed automatically, developer is responsible to obtain specific hook using get_hook() function and call it. To add hook, create function with name equal to feature name """ import functools import logging from typing import Any, Callable, Optional from defence360agent.contracts.config import ConfigFile from defence360agent.feature_management.constants import ( AV, FULL, LOG, PROACTIVE, ) logger = logging.getLogger(__name__) def _hook_stub(*_): return True def _result_warn(callback): @functools.wraps(callback) def wrap(user, value): result = callback(user, value) result or logger.warning( "Hook '%s(%s)' failed for user '%s'.", callback.__name__, value, user, ) return result return wrap @_result_warn def antivirus(user: Optional[str], value: Any) -> bool: """Called when 'av' feature is changed""" if not user: return True config = ConfigFile() config_value = config.get("MALWARE_SCANNING", "default_action") user_config = ConfigFile(user) user_config_value = user_config.get("MALWARE_SCANNING", "default_action") if value == FULL: user_config_value = None elif ( user_config_value and user_config_value.startswith("cleanup") and config_value and config_value.startswith("cleanup") ): user_config_value = "notify" try: user_config.set( "MALWARE_SCANNING", "default_action", user_config_value ) except Exception: return False return True _PROACTIVE_MODE_BY_PERMISSION = { FULL: None, # inherit global PROACTIVE_DEFENCE.mode LOG: "LOG", # observe only, no enforcement # any other value (NA, legacy entries) maps to DISABLED below } @_result_warn def proactive(user: Optional[str], value: Any) -> bool: """Called when 'proactive' feature is changed""" if not user: return True # do nothing if no user specified config_value = _PROACTIVE_MODE_BY_PERMISSION.get(value, "DISABLED") try: ConfigFile(user).set("PROACTIVE_DEFENCE", "mode", config_value) except Exception: return False return True HOOKS = { AV: antivirus, PROACTIVE: proactive, } def get_hook(feature: str) -> Callable[[Optional[str], Any], bool]: """ Get hook for specific feature. If no hook is implemented for this feature, return stub function :param feature: feature name :return: callable hook """ return HOOKS.get(feature, _hook_stub)
Save
Close
Exit & Reset
Text mode: syntax highlighting auto-detects file type.
Directory Contents
Dirs: 3 × Files: 9
Delete Selected
Select All
Select None
Sort:
Name
Size
Modified
Enable drag-to-move
Name
Size
Perms
Modified
Actions
plugins
DIR
-
drwxr-xr-x
2026-06-08 20:24:30
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
rpc
DIR
-
drwxr-xr-x
2026-06-08 20:24:30
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
__pycache__
DIR
-
drwxr-xr-x
2026-06-08 20:24:30
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
checkers.py
2.45 KB
lrw-r--r--
2026-05-26 21:20:44
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
constants.py
1.05 KB
lrw-r--r--
2026-05-26 21:20:44
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
control.py
2.50 KB
lrw-r--r--
2026-05-26 21:20:44
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
exceptions.py
306 B
lrw-r--r--
2026-05-26 21:20:44
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
hooks.py
2.64 KB
lrw-r--r--
2026-05-26 21:20:44
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
lookup.py
2.76 KB
lrw-r--r--
2026-05-26 21:20:44
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
model.py
2.37 KB
lrw-r--r--
2026-05-26 21:20:44
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
utils.py
3.48 KB
lrw-r--r--
2026-05-26 21:20:44
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
__init__.py
0 B
lrw-r--r--
2026-05-26 21:20:44
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Zip Selected
If ZipArchive is unavailable, a
.tar
will be created (no compression).